攻防世界 ——crypto

目录

新手区部分题解:

1,easy_RSA

2,Normal_RSA

3, 幂数加密

4,easy_ECC

高手进阶区部分题题解

5, ENC

6,告诉你个秘密

7,Easy-one

8,说我作弊需要证据

9.x_xor_md5

10,easy_crypto

11,cr2-many-time-secrets

12,oldDevier

13,wtc_rsa_bbq

14,cr4-poor-rsa

15,flag_in_your_hand1

16,cr3-what-is-this-encryption

17,safer_than_rot13

18,flag_in_your_hand

19,Decode_The_File


新手区部分题解:

1,easy_RSA

摘别人的图

或者用 脚本  python2:(装了 gmpy2库的可以用)

import gmpy2
p = 473398607161
q = 4511491
e = 17
s = (p-1)*(q-1)

d = gmpy2.invert(e,s)

print d 

2,Normal_RSA

解压出来两个文件:flag.enc  和 pubkey.pem 

pem文件:以前是利用公钥加密进行邮件安全的一个协议,而现在PEM这个协议仅仅在使用的就是.pem这种文件
格式,这种文件里面保存了keys和X.509证书,看到了吗数字证书和key都能保存。 
而现在一般表示用Base64 encoded DER编码的证书,
这种证书的内容打开能够看到在”—–BEGIN CERTIFICATE—–” and “—–END CERTIFICATE—–”之间
enc文件:该.enc文件扩展用于通过在UUenconded格式文件,它们是加密的文件。
这也意味着这些ENC文件包含受保护的数据和保存在该格式中,所以未经授权的收视数据和复制可以被防止

本题考查  两个工具的使用  openssl (linux自带) 和 rsatool

这两个工具我是在 windows 下 安装使用的,当然可以在 linux中使用,个人喜好

分享:openssl: https://pan.baidu.com/s/1wP73GPJZo-HITH50UA61YQ 提取码: v2ti

          rsatools : https://pan.baidu.com/s/16Hl_p1zv_ajZadkW5GFnzQ 提取码: 8qqr

其中 openssl 是exe文件 直接执行安装,默认安装到:C:\Program Files\OpenSSL-Win64

然后把  C:\Program Files\OpenSSL-Win64\bin  添加到 环境变量中

我的电脑 右键 》 属性 》高级系统设置 》环境变量 》系统变量  中  双击  path  》 新建  》把复制的路径添加进去 确定

 

一个是加密过的的flag.enc,另一个是公钥pubkey.pem。我们需要用四个步骤拿到flag

把 flag.enc  和 pubkey.pem  复制到 rsatools 文件夹中, 打开cmd

1,提取 pubkey.pem 中的 参数:

openssl rsa -pubin -text -modulus -in warmup -in pubkey.pem

对得到的Modulus(16)进制的转化为十进制:

87924348264132406875276140514499937145050893665602592992418171647042491658461

然后把 这个数分解 为两个 互质数  就是 q和 p

这里需要用到 yafu 中的 factor (kali自带),我偏向于在windows中 玩

分享 源码,python脚本  linux也可以用,

 https://pan.baidu.com/s/1TQqM8naEyVKhh101kz_igQ 提取码: rcb9 

275127860351348928173285174381581152299 
319576316814478949870590164193048041239

知道两个素数,随机定义大素数e,求出密钥文件 private.pem                    (python2)

python rsatool.py -o private.pem -e 65537 -p 275127860351348928173285174381581152299 -q 319576316814478949870590164193048041239

最后解密:

openssl rsautl -decrypt -in flag.enc -inkey private.pem

 

openssl是一个功能强大的工具,https://www.cnblogs.com/yangxiaolan/p/6256838.html

3, 幂数加密

提示是 幂函数解密:

幂函数加密的密文 只有 01234  不可能有 8,所以表层不是 幂函数加密,

是 云影密码 :

4,easy_ECC

直接上脚本:

import collections
import random

EllipticCurve = collections.namedtuple('EllipticCurve', 'name p a b g n h')

curve = EllipticCurve(
   'secp256k1',
   # Field characteristic.
   p=int(input('p=')),
   # Curve coefficients.
   a=int(input('a=')),
   b=int(input('b=')),
   # Base point.
   g=(int(input('Gx=')),
      int(input('Gy='))),
   # Subgroup order.
   n=int(input('k=')),
   # Subgroup cofactor.
   h=1,
)


# Modular arithmetic ##########################################################

def inverse_mod(k, p):
   """Returns the inverse of k modulo p.

  This function returns the only integer x such that (x * k) % p == 1.

  k must be non-zero and p must be a prime.
  """
   if k == 0:
       raise ZeroDivisionError('division by zero')

   if k < 0:
       # k ** -1 = p - (-k) ** -1 (mod p)
       return p - inverse_mod(-k, p)

   # Extended Euclidean algorithm.
   s, old_s = 0, 1
   t, old_t = 1, 0
   r, old_r = p, k

   while r != 0:
       quotient = old_r // r
       old_r, r = r, old_r - quotient * r
       old_s, s = s, old_s - quotient * s
       old_t, t = t, old_t - quotient * t

   gcd, x, y = old_r, old_s, old_t

   assert gcd == 1
   assert (k * x) % p == 1

   return x % p


# Functions that work on curve points #########################################

def is_on_curve(point):
   """Returns True if the given point lies on the elliptic curve."""
   if point is None:
       # None represents the point at infinity.
       return True

   x, y = point

   return (y * y - x * x * x - curve.a * x - curve.b) % curve.p == 0


def point_neg(point):
   """Returns -point."""
   assert is_on_curve(point)

   if point is None:
       # -0 = 0
       return None

   x, y = point
   result = (x, -y % curve.p)

   assert is_on_curve(result)

   return result


def point_add(point1, point2):
   """Returns the result of point1 + point2 according to the group law."""
   assert is_on_curve(point1)
   assert is_on_curve(point2)

   if point1 is None:
       # 0 + point2 = point2
       return point2
   if point2 is None:
       # point1 + 0 = point1
       return point1

   x1, y1 = point1
   x2, y2 = point2

   if x1 == x2 and y1 != y2:
       # point1 + (-point1) = 0
       return None

   if x1 == x2:
       # This is the case point1 == point2.
       m = (3 * x1 * x1 + curve.a) * inverse_mod(2 * y1, curve.p)
   else:
       # This is the case point1 != point2.
       m = (y1 - y2) * inverse_mod(x1 - x2, curve.p)

   x3 = m * m - x1 - x2
   y3 = y1 + m * (x3 - x1)
   result = (x3 % curve.p,
             -y3 % curve.p)

   assert is_on_curve(result)

   return result


def scalar_mult(k, point):
   """Returns k * point computed using the double and point_add algorithm."""
   assert is_on_curve(point)



   if k < 0:
       # k * point = -k * (-point)
       return scalar_mult(-k, point_neg(point))

   result = None
   addend = point

   while k:
       if k & 1:
           # Add.
           result = point_add(result, addend)

       # Double.
       addend = point_add(addend, addend)

       k >>= 1

   assert is_on_curve(result)

   return result


# Keypair generation and ECDHE ################################################

def make_keypair():
   """Generates a random private-public key pair."""
   private_key = curve.n
   public_key = scalar_mult(private_key, curve.g)

   return private_key, public_key



private_key, public_key = make_keypair()
print("private key:", hex(private_key))
print("public key: (0x{:x}, 0x{:x})".format(*public_key))

 

cyberpeace{19477226185390}

高手进阶区部分题题解

5, ENC

是一个没有后缀的文件,用winhex打开,发现 只有两种 字符串  ZERO 和 ONE

复制下来保存为 123.txt,然后用脚本将ZERO 替换为 0  ONE替换为 1:


f = open("123.txt","r")
chars = f.read()
char = chars.split(" ")
string = ""
for c in char:
    if(c == &
  • 9
    点赞
  • 54
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值