Level_1
就是一个最简单的共模攻击题 白给
from gongmo import gongmogongji
from Crypto.Util.number import long_to_bytes
n = 22517647586235353449147432825948355885962082318127038138351524894369583539246623545565501496312996556897362735789505076324197072008392656511657262430676945685471397862981216472634785622155317188784494912316440866051402627470561626691472280850273482836308002341429493460677206562201947000047718275995355772707947408688836667011206588727438261189233517003341094758634490421007907582147392858070623641389171229435187248184443645883661560636995548332475573072064240073037558031928639832259001407585962782698021735648128101459118863015844905452823095147248865104102562991382119836061161756978764495337874807458182581421229
c1 = 1432393096266401187029059077791766305797845826173887492889260179348416733820890797101745501984437201566364579129066414005659742104885321270122634155922766503333859812540068278962999824043206496595825886026095484801291802992082454776271149083516187121160475839108002133113254134626407840182541809478892306748590016896975053434021666376203540725254480252049443975835307793528287818262102688334515632062552114342619781840154202525919769192765621085008206581226486157149883898548933475155236509073675387541466324512294079413938239828341890576923100769181401944289365386552139418728492565319685207500539721582552448971814
c2 = 13299679392897297864252207869444022461237574801991239380909482153705185317634241850084078027230394830079554676426505967970943836811048777462696506309466535820372917756458083553031417406403895116557560548183674144457502601887632495739472178857537011190162283185735114683172731936834993707871636782206418680404006299140864001776588991141011500807549645227520128216130966268810165946959810884593793452437010902774726405217517557763322690215690606067996057037379898630878638483268362526985225092000670251641184960698506349245915816808028210142606700394584541282682338561482561343076218115042099753144875658666459825545602
e1 = 155861690390761931560700906834977917646203451142415617638229284868013723431003139974975998354830978765979365632120896717380895021936387027045347260400512396388028781862427862974453223157509702913026222541667006325100878113871620322023188372501930117363623076837619478555007555970810681502521309925774889678793
e2 = 144471983652821947847253052623701746810204736865723159569786739658583884214397562204788127484897909964898113250509653721265240138487697822089282456150238116811225975640330930854549232972314642221382625614304415750165289831040623741828600283778523993251940904896081111235859249916040849697146542311990869696453
print(long_to_bytes(gongmogongji(n,c1, c2, e1, e2)))
gongmo.py
from gmpy2 import invert
def gongmogongji(n, c1, c2, e1, e2):
def egcd(a, b):
if b == 0:
return a, 0
else:
x, y = egcd(b, a % b)
return y, x - (a // b) * y
s = egcd(e1, e2)
s1 = s[0]
s2 = s[1]
# 求模反元素
if s1 < 0:
s1 = - s1
c1 = invert(c1, n)
elif s2 < 0:
s2 = - s2
c2 = invert(c2, n)
m = pow(c1, s1, n) * pow(c2, s2, n) % n
return m
Level_2
给了q和c,和一个ps.txt,里面有1024个p,其中有一个是正确的p
用python读进来然后遍历即可。e的话 常见的e就是65537
from Crypto.Util.number import long_to_bytes
from gmpy2 import invert
q = 145721736470529261146573065574028992352505611489859183763269215489708531333597694809923949026781460438320576519639268582565188719134157402292313959218961804213310847081787824780075530751842057663327444602428455144829447776271394663729996984613471623158126083062443634493708467568220146024273763894704649472957
c = 17441814714407189483380175736850663249578989775568187792928771544069162420510939242665830363276698262009780462912108642025299275146709817979705069095332726251759039923303627023610865046363171692163473939115438686877494878334016463787558794121885354719336139401336137097548305393030069499625065664884238710759260231321106291200849044147840392021931720902340003746946851806025722944795391356835342258387797980787437188976704677008092850181043891802072500430200735973581081228711070923822341261809453662427341958883142789220800541626034573952425948295446202775198692920613709157662831071515700549093766182579873408465779
e = 65537
count = 0
with open('ps.txt', 'r') as f:
while 1:
p = int(f.readline())
n = p * q
phiN = (p - 1) * (q - 1)
d = invert(e, phiN)
print(count)
flag = long_to_bytes(pow(c, d, n))
print(flag)
if 'NSS' in str(flag):
exit()
Level_3
这是一个有靶机的Crypto题,且为动态flag。原题是bestcasscn(余师傅)的
靶机可以用nc连接,然后结合图片,可以知道,这也是一个共模攻击的题,只不过需要连续正确提交666次,直接用pwn库里面的写exp
from pwn import *
from Crypto.Util.number import long_to_bytes
from gongmo import gongmogongji
p = remote("***.***.***.***", *****)#靶机
for i in range(666):
p.recvuntil('n=')
n = int(p.recvline().strip().decode())
p.recvuntil('e1=')
e1 = int(p.recvline().strip().decode())
p.recvuntil('e2=')
e2 = int(p.recvline().strip().decode())
p.recvuntil('c1=')
c1 = int(p.recvline().strip().decode())
p.recvuntil('c2=')
c2 = int(p.recvline().strip().decode())
res = long_to_bytes(gongmogongji(n, c1, c2, e1, e2)).decode()
p.sendlineafter('[+] Pl Give Me flaag :', res)
print("i=" + str(i))
print(p.recvlines(3))
Comments NOTHING