再看右边 所有元素都已知 就可求出c。
连接靶机后得到
Hello,let s play rsa~ Now,I make some numbers,wait a second Ok,i will send two numbers to you,one of them was encoded. Encode n1:8376791106482697829711147586692200645635184453040045083271123167200707038248236396536348140340518796059731874971878526224777862300117802953920357747143070687810386450866536158065770762570650777242160269100694490279188695780815776485119413634359709949150518964977449880837775970609411574837512895309365643688926709933140442311944479849113437719589286285950764842970198696290790449130233994554934908238744835735002465329706260591844313367329424800475241661867799451485833014927407681144636335846114414025304957405121091582935931103028775776569357522336330242950425986315856197537276112626301293445718699724196297682185, And n2:817883629056426050889438610854875115586179937771656074400107. Information that can now be made public:the public key (n,e):(13475893246019200526091823650015055343164746229114982225382998718395258496493335819701532437931495199933283208899632902172717042195817220122646531409471061579781043978874356877015075531305060207031649158677550815089443281555745462081575684649933055598782621405102035073547847532774639601550099126107397178418161551833236207136664494575827542000472294724331914970722717280831228386528286268380664940136556717152461282937806690036827024679335088085174810766659221367543805959223074889847255035741245716207232342358634860906871835975384224274661257971415414381791941757056816757602556453057153431925455762662343516721367,65537) ok,now,tell me the value of the number (encode it for safe):
输入正确答案后
Hello,let s play rsa~
Now,I make some numbers,wait a second
Ok,i will send two numbers to you,one of them was encoded.
Encode n1:8376791106482697829711147586692200645635184453040045083271123167200707038248236396536348140340518796059731874971878526224777862300117802953920357747143070687810386450866536158065770762570650777242160269100694490279188695780815776485119413634359709949150518964977449880837775970609411574837512895309365643688926709933140442311944479849113437719589286285950764842970198696290790449130233994554934908238744835735002465329706260591844313367329424800475241661867799451485833014927407681144636335846114414025304957405121091582935931103028775776569357522336330242950425986315856197537276112626301293445718699724196297682185,
And n2:817883629056426050889438610854875115586179937771656074400107.
Information that can now be made public:the public key (n,e):(13475893246019200526091823650015055343164746229114982225382998718395258496493335819701532437931495199933283208899632902172717042195817220122646531409471061579781043978874356877015075531305060207031649158677550815089443281555745462081575684649933055598782621405102035073547847532774639601550099126107397178418161551833236207136664494575827542000472294724331914970722717280831228386528286268380664940136556717152461282937806690036827024679335088085174810766659221367543805959223074889847255035741245716207232342358634860906871835975384224274661257971415414381791941757056816757602556453057153431925455762662343516721367,65537)
ok,now,tell me the value of the number (encode it for safe):7481369497397329771618615543492535042492443949142942219865805966049582039102101643321663991800009307651917950428571853510578829741525413947958313785100279146988733501606001554513370663175617575435885090220742017778553038491917205767777664222949010418169039002022379731305760779557787693683338172703429133334057627981161030322439877140649309618654396262076012479739382814264326334087208167316991755811954640734537705378458522211438973062235520352518287955967533790084985716240645176274417277471107449220932722474064093965893815035518447498732021556606359943586552784921784611360739503416306054501304204890559818145327
It s easy and interesting,didn t it?
This is the gift for you :flag{eca6741f-2746-4983-8e33-4c539570b885}Hello,let s play rsa~
Now,I make some numbers,wait a second
Ok,i will send two numbers to you,one of them was encoded.
Encode n1:8376791106482697829711147586692200645635184453040045083271123167200707038248236396536348140340518796059731874971878526224777862300117802953920357747143070687810386450866536158065770762570650777242160269100694490279188695780815776485119413634359709949150518964977449880837775970609411574837512895309365643688926709933140442311944479849113437719589286285950764842970198696290790449130233994554934908238744835735002465329706260591844313367329424800475241661867799451485833014927407681144636335846114414025304957405121091582935931103028775776569357522336330242950425986315856197537276112626301293445718699724196297682185,
And n2:817883629056426050889438610854875115586179937771656074400107.
Information that can now be made public:the public key (n,e):(13475893246019200526091823650015055343164746229114982225382998718395258496493335819701532437931495199933283208899632902172717042195817220122646531409471061579781043978874356877015075531305060207031649158677550815089443281555745462081575684649933055598782621405102035073547847532774639601550099126107397178418161551833236207136664494575827542000472294724331914970722717280831228386528286268380664940136556717152461282937806690036827024679335088085174810766659221367543805959223074889847255035741245716207232342358634860906871835975384224274661257971415414381791941757056816757602556453057153431925455762662343516721367,65537)
ok,now,tell me the value of the number (encode it for safe):7481369497397329771618615543492535042492443949142942219865805966049582039102101643321663991800009307651917950428571853510578829741525413947958313785100279146988733501606001554513370663175617575435885090220742017778553038491917205767777664222949010418169039002022379731305760779557787693683338172703429133334057627981161030322439877140649309618654396262076012479739382814264326334087208167316991755811954640734537705378458522211438973062235520352518287955967533790084985716240645176274417277471107449220932722474064093965893815035518447498732021556606359943586552784921784611360739503416306054501304204890559818145327
It s easy and interesting,didn t it?
This is the gift for you :flag{eca6741f-2746-4983-8e33-4c539570b885}
exp
n2 817883629056426050889438610854875115586179937771656074400107 n 13475893246019200526091823650015055343164746229114982225382998718395258496493335819701532437931495199933283208899632902172717042195817220122646531409471061579781043978874356877015075531305060207031649158677550815089443281555745462081575684649933055598782621405102035073547847532774639601550099126107397178418161551833236207136664494575827542000472294724331914970722717280831228386528286268380664940136556717152461282937806690036827024679335088085174810766659221367543805959223074889847255035741245716207232342358634860906871835975384224274661257971415414381791941757056816757602556453057153431925455762662343516721367 e 65537 c1 8376791106482697829711147586692200645635184453040045083271123167200707038248236396536348140340518796059731874971878526224777862300117802953920357747143070687810386450866536158065770762570650777242160269100694490279188695780815776485119413634359709949150518964977449880837775970609411574837512895309365643688926709933140442311944479849113437719589286285950764842970198696290790449130233994554934908238744835735002465329706260591844313367329424800475241661867799451485833014927407681144636335846114414025304957405121091582935931103028775776569357522336330242950425986315856197537276112626301293445718699724196297682185 c (c1*(n2**e)%n)%n print(c)ezRSA task
from secret import flag
from Crypto.Util.number import *
from random import getrandbits
from hashlib import sha256
class EzRsa:
def __init__(self):
self.E 0x10001
self.P getPrime(1024)
self.Q getPrime(1024)
while GCD((self.P-1)*(self.Q-1), self.E) ! 1:
self.Q getPrime(1024)
self.N self.P*self.Q
def encrypt(self):
f getrandbits(32)
c pow(f, self.E, self.N)
return (f, c)
def encrypt_flag(self, flag):
f bytes_to_long(flag)
c pow(f, self.E, self.N)
return c
def proof():
seed getrandbits(32)
print(seed)
sha sha256(str(seed).encode()).hexdigest()#将seed进行sha256加密
print(f sha256({seed 18}...).hexdigest() {sha} )
sha_i input( plz enter seed: )
if sha256(sha_i.encode()).hexdigest() ! sha:
exit(0)
if __name__ __main__ :
proof()
print( welcome to EzRsa )
print(
1. Get flag
2. Encrypt
3. Insert
4. Exit
A EzRsa()
coin 5
while coin 0:
choose input( )
if choose 1 :
print(
f pow(flag,e,n) {A.encrypt_flag(flag)}ne 0x10001 )
exit(0)
elif choose 2 :
f, c A.encrypt()
print(f plain {f}ncipher {c} )
coin - 1
elif choose 3 :
q getrandbits(1024)
n A.P*q
f getrandbits(32)
c pow(f, 0x10001, n)
print(f plain {f}ncipher {c} )
coin - 1
elif choose 4 :
print( bye~ )
else:
print( wrong input )
print( Now you get the flag right? )
分析
连接靶机
3920672166 sha256(14956...).hexdigest() 4f97152f2314a3267380e3a736c7b83642c665e0b7ce4735aa58f153165c03a8 plz enter seed: 3920672166 welcome to EzRsa 1. Get flag 2. Encrypt 3. Insert 4. Exit plain 246172596 #f1 N P*Q c1 pow(f1, E, N) cipher 10173233764406169095899483354963164571737209784008701622335544928694259063855518018704769921525166009249126681224283840128044370905317577973950303992043749468525570047970338729747081004025643131749570347673777168867709262619232591961400442015821054455787154014989512204495733006844568897192918774690658866146310997606018573720337022125940979650505605308894992728509291235175469398004506434879836506552302171990021309618235906862685991344063877849627585878246567505089830151036166885190902668104134461995296503098876736843810806165642362870222973336497293214313805248517763740264632510733197696485690344651088941929152 plain 1625353687 #f2 N P*Q c2 pow(f2, E, N) cipher 12307584975251008411516787731127057807459606148509564084565235331743959393183926255630699543466181645936984428560120544513772238200891009720751041149318752451164580269097210103342551596366092114461811872647728479216808541966617422679765592022060940058856123807698152639126817576541773740289677169367448433499272854918536954953586829556954898997330873611935553127971629608674277626930145539545752160151113674651634185742437848591314779194625067525110624869286078410977406348316939155625181843174226781998931484808400662628812790184706505753694785130261133992233308165253423676907297761585356002589809511257085134236964 plain 1535865823 #f3 N P*q1 c3 pow(f3, 0x10001, N) cipher 5616148217702256813794782016282980002529311657904079448102815350827300993213449299006217890376411480585190233723226978006569715343730543373265994884145037587800253418834041446705167175279746103443102685952718602721464856421481096427552716126453841320699769465067611503421803643702426542935539828009090722947255684407777585314577198743093794188613266146795749296649916546057006799507388720568391067773154094194812970556251176281392083962949437562134531212873820606542551630047805282566962382807038103089098675388219245954070941558343858135476221921795190935468334759042551978239277293268509286506173756116737043936943 plain 1806634535 #f4 N P*q2 c4 pow(f4, 0x10001, N) cipher 1427709639342522954034253242140207749627023419576583331730127575462062495420567697255676374994381638227840222684605853556198230028477711368795852167093005987576867345915879259532923389327437262878433999411334625993538741920567821778777971634816928563383696587344978185954409805177042287392341975793514392686090415420796326167619282928611766169354655318528679241861479684193583683513186645781523448313877362554888036649202783338675136799061464085846904925026432714698611256763637705540929617439668980881972979779903418025094476825847712169957276029258203376181771818942998146920133314293800851161421416836951302303785 pow(flag,e,n) 7660616915748658759372848886104469196651926239822942076995644477738724166975848721917259876106979567511672242425196380649367137611601528140465592052571663722864145442933465949602304530816238877079912508461818866021771870602248273656899938554330192447982057520436958060107921356390766845123076457239058840505970721528034331057342412446177706634527511924482698967109095424775131001113765235898191627354250140417118522771203515918975157123189261089037479427068251466167776458422443579472966565395255293992193547180546786143992999938350618040069485840155303775801800121282206941241276065528410190257291809049557518583367 e 0x10001 #c pow(flag, E, N) N P*Q化简
1.通过1、2可知 其中只有N未知 所以求N



