附件给了一个名为flag
的文件,不知道是什么类型文件
放进kali,file flag
查看文件类型
发现是文本,于是cat
命令查看
可以看到,不同于传统的RSA解密,这里给出了一个参数dp
首先了解一下什么是dp:
dp=d%(p-1)
与之对应的还有dq:
dq=d%(q-1)
这种参数是为了让解密的时候更快速而产生的
根据原理可以写出解密脚本:
import gmpy2
import binascii
def getd(n,e,dp):
for i in range(1,e):
if (dp*e-1)%i == 0:
if n%(((dp*e-1)/i)+1)==0:
p=((dp*e-1)/i)+1
q=n/(((dp*e-1)/i)+1)
phi = (p-1)*(q-1)
d = gmpy2.invert(e,phi)%phi
return d
e = 65537
n = 156808343598578774957375696815188980682166740609302831099696492068246337198792510898818496239166339015207305102101431634283168544492984586566799996471150252382144148257236707247267506165670877506370253127695314163987084076462560095456635833650720606337852199362362120808707925913897956527780930423574343287847
c = 108542078809057774666748066235473292495343753790443966020636060807418393737258696352569345621488958094856305865603100885838672591764072157183336139243588435583104423268921439473113244493821692560960443688048994557463526099985303667243623711454841573922233051289561865599722004107134302070301237345400354257869
dp = 734763139918837027274765680404546851353356952885439663987181004382601658386317353877499122276686150509151221546249750373865024485652349719427182780275825
d=getd(n,e,dp)
m=pow(c,d,n)
print binascii.unhexlify(hex(m)[2:])
运行得到flag:wctf2020{dp_leaking_1s_very_d@angerous}
gmpy2这个库在Linux中安装时需要3个依赖库 gmp
mpfr
mpc
gmp 库安装
apt-get install libgmp-dev
mpfr 库安装
apt-get install libmpfr-dev
mpc 库安装
apt-get install libmpc-dev
gmpy2 安装
sudo pip3 install gmpy2
#或者
sudo pip install gmpy2
分界线
**************************
Date:2020/03/30
Category:CRYPTO
Author:Ver.
**************************