from Crypto.Util.number import getPrime,bytes_to_long
p,q = getPrime(2048),getPrime(2048) e = 7 n = p*q m = bytes_to_long(open('flag.txt','rb').read().strip()) c = pow(m,e,n) print("c = ",c) print("n = ",n)
# c = 147693154873835354725007152781732424355869776162377337823960431913672366269917723916891506269449726723757821517328874729037838600793748824028829185409932536014732765063216715033843955453706710187792772702199448156372644163429786386035008302836467605094954587157232829525150652611067567669525072625329634860065850520051628272535479197120008981979404760445193750864902244921407742155742716289495581989134730376783828846663464819337418977287363028738701414486788851136608957124505485242331701209645216580641917007780811842757125048746184068597664780265422321550909392419865169775282217442331295071069272774722564587602419768461231775480847018941840911357926330143045826277813722919121117172763493242590521245640828462665947672485094793188432098216701511715232654611338293295459889814699850788048985878279440740712956248569068077253790198036918598519191892836075254345518967666166925163908185663991353344555402397055977817370082929420443034626201745027965444069777059760865359310439815816749939498993014457995041394803598825093836045546578310632172636478575946653375857640993393714607308326474003446154152048840071034349831168612740218034679021240949747357214453636633636662650940968576792518622437627529244515229173 # n = 553409369582823237678532685244026647155180191225879439432235077135813123637186465008813830373646133388592395760175777499266561095087891764348044063111935877931069321764391883899483374576303169645488542398590564148654412004383012178107972880058460460806768779452529433458826925606225797078653905380530651390617109384086518728626571028089036812787671647095695947167204428442727185744172445701874820612799168887428075695751162763647868386879374037826876671079326544820609721731078985096813307183878793033824330869698508952853770794414757655681370862323768018291030331209143189638496644361618184164228294031490537429556439588954274708598530042700988138862000054458742762198052079867259365645914383561162796796952346445529346145323567650621600171442575319262718389389870407629339714751583360252884338116164466349449862781112019462555743429653595045695696967783338371470032332852204294900011651434678829104876529439166176589508898757122660322523937330848536715937381297551894198974459004139082562228022412335520195652419375915216074658463954339332593244483927157329404652516225481116614815221154229491846087288087715884363786672244655901308480290011237244562251084095684531716327141154558809471185132979704992609461470501119328696999713829
t = gmpy2.iroot(c,e) if t[1]: print(long_to_bytes(t[0])) else: while1: m = gmpy2.iroot(k*n+c,e) if m[1]: print(m[0]) print(long_to_bytes(m[0])) break else: k += 1
bad_E
1 2 3 4 5 6 7 8 9 10 11 12 13 14
from Crypto.Util.number import * p = getPrime(512) q = getPrime(512) e = 65537
withopen("flag.txt","r") as fs: flag = fs.read().strip()
m = bytes_to_long(flag.encode()) c = pow(m,e,p*q) print(c) # 63388263723813143290256836284084914544524440253054612802424934400854921660916379284754467427040180660945667733359330988361620691457570947823206385692232584893511398038141442606303536260023122774682805630913037113541880875125504376791939861734613177272270414287306054553288162010873808058776206524782351475805
from Crypto.Util.number import * import gmpy2 import time import random from tqdm import tqdm e = 65537 p = q = c = n = p * q
defAMM(o, r, q): start = time.time() print('\n----------------------------------------------------------------------------------') print('Start to run Adleman-Manders-Miller Root Extraction Method') print('Try to find one {:#x}th root of {} modulo {}'.format(r, o, q)) g = GF(q) o = g(o) p = g(random.randint(1, q)) while p ^ ((q-1) // r) == 1: p = g(random.randint(1, q)) print('[+] Find p:{}'.format(p)) t = 0 s = q - 1 while s % r == 0: t += 1 s = s // r print('[+] Find s:{}, t:{}'.format(s, t)) k = 1 while (k * s + 1) % r != 0: k += 1 alp = (k * s + 1) // r print('[+] Find alp:{}'.format(alp)) a = p ^ (r**(t-1) * s) b = o ^ (r*alp - 1) c = p ^ s h = 1 for i inrange(1, t): d = b ^ (r^(t-1-i)) if d == 1: j = 0 else: print('[+] Calculating DLP...') j = - discrete_log(d, a) print('[+] Finish DLP...') b = b * (c^r)^j h = h * c^j c = c^r result = o^alp * h end = time.time() print("Finished in {} seconds.".format(end - start)) print('Find one solution: {}'.format(result)) return result
defonemod(p,r): t=p-2 whilepow(t,(p-1) // r,p)==1: t -= 1 returnpow(t,(p-1) // r,p) defsolution(p,root,e): g = onemod(p,e) may = set() for i inrange(e): may.add(root * pow(g,i,p)%p) return may
cp = c % p
mp = AMM(cp,e,p)
mps = solution(p,mp,e)
for i in mps: flag = long_to_bytes(int(i)) ifb'moectf'in flag: print(flag)
t = gmpy2.gcd(e1,e2) if t == 1: s,x,y = gmpy2.gcdext(e1,e2) m = (pow(c1,x,n)*pow(c2,y,n))%n print(long_to_bytes(m)) else: s,x,y = gmpy2.gcdext(e1,e2) k = 0 while1: m = gmpy2.iroot((pow(c1,x,n)*pow(c2,y,n)+k*n)%n,t) if m[1]: print(long_to_bytes(m[0])) break else: k += 1
withopen("flag.txt","rb") as fs: flag = fs.read().strip() assertlen(flag) == 72
m = int.from_bytes(flag,"big")
from Crypto.Util.number import getPrime, isPrime
defnext_prime(p): whileTrue: p += 2 if isPrime(p): return p
p = getPrime(2048) q = next_prime(p) n = p * q e = 65537 c = pow(m,e,n) print("n =",n) print("c =",c)
# n = 329960318345010350458589325571454799968957932130539403944044204698872359769449414256378111233592533561892402020955736786563103586897940757198920737583107357264433730515123570697570757034221232010688796344257587359198400915567115397034901247038275403825404094129637119512164953012131445747740645183682571690806238508035172474685818036517880994658466362305677430221344381425792427288500814551334928982040579744048907401043058567486871621293983772331951723963911377839286050368715384227640638031857101612517441295926821712605955984000617738833973829140899288164786111118033301974794123637285172303688427806450817155786233788027512244397952849209700013205803489334055814513866650854230478124920442832221946442593769555237909177172933634236392800414176981780444770542047378630756636857018730168151824307814244094763132088236333995807013617801783919113541391133267230410179444855465611792191833319172887852945902960736744468250550722314565805440432977225703650102517531531476188269635151281661081058374242768608270563131619806585194608795817118466680430500830137335634289617464844004904410907221482919453859885955054140320857757297655475489972268282336250384384926216818756762307686391740965586168590784252524275489515352125321398406426217 # c = 307746143297103281117512771170735061509547958991947416701685589829711285274762039205145422734327595082350457374530975854337055433998982493020603245187129916580627539476324521854057990929173492940833073106540441902619425074887573232779899379436737429823569006431370954961865581168635086246592539153824456681688944066925973182272443586463636373955966146029489121226571408532284480270826510961605206483011204059402338926815599691009406841471142048842308786000059979977645988396524814553253493672729395573658564825709547262230219183672493306100392069182994445509803952976016630731417479238769736432223194249245020320183199001774879893442186017555682902409661647546547835345461056900610391514595370600575845979413984555709077635397717741521573798309855584473259503981955303774208127361309229536010653615696850725905168242705387575720694946072789441481191449772933265705810128547553027708513478130258801233619669699177901566688737559102165508239876805822898509541232565766265491283807922473440397456701500524925191214292669986798631732639221198138026031561329502985577205314190565609214349344303324429408234237832110076900414483795318189628198913032900272406887003325858236057373096880675754802725017537119549989304878960436575670784578550
根据题目意思,$p,q$很相近,先把$n$开根,再求下一个素数得到$p$
exp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
from Crypto.Util.number import * import gmpy2
n = c = e = 65537
t = gmpy2.iroot(n,2)[0]
p = gmpy2.next_prime(t) q = n // p d = gmpy2.invert(e,(p-1)*(q-1)) m = pow(c,d,n) print(long_to_bytes(m))
withopen("flag.txt","rb") as f: flag = f.read().strip()
m = int.from_bytes(flag, "big") e = 65537
from Crypto.Util.number import getPrime
for x inrange(10): p = getPrime(1024) q = getPrime(1024) n = p * q c = pow(m, e, n)
print("n =", n) print("c =", c)
''' n = 17524722204224696445172535263975543817720644608816706978363749891469511686943372362091928951563219068859089058278944528021615923888948698587206920445508493551162845371086030869059282352535451058203615402089133135136481314666971507135484450966505425514285114192275051972496161810571035753943880190780759479521486741046704043699838021850105638224212696697865987677760179564370167062037563913329993433080123575434871852732981112883423565015771421868680113407260917902892944119552200927337996135278491046562185003012971570532979090484837684759828977460570826320870379601193678304983534424368152743368343335213808684523217 c = 6870605439714128574950893771863182370595667973241984289208050776870220326525943524507319708560433091378319367164606150977103661770065561661544375425887970907060665421562712515902428061727268441585629591525591001533188276465911918724808701356962871139957343861919730086334623932624184172272488406793955068827527130338853980609365042071290967556159598511667974987218999253443575482949258292953639729393456515185185102248985930422080581185292420347510600574229080211050520146551505605537486989306457793451086767402197128573781597156939709237045132856159368959981648969874765462190363842275826077556314448408825308218451 n = 24974121071274650888046048586598797033399902532613815354986756278905133499432183463847175542164798764762683121930786715931063152122056911933710481566265603626437742951648885379847799327315791800670175616973945640322985175516271373004547752061826574576722667907302681961850865961386200909397231865804894418194711076667760169256682834206788730947602211228930301853348503098156592000286467190760378847541148772869356389938999094673945092387627113807899212568399028514283219850734634544982646070106811651490010946670117927664594365986238107951837041859682547029079035013475238052160645871718246031144694712586073789250183 c = 10324627733161143472233272675096997859064721978612320424254305978486200326061730105384511258706433940176741256952824288120499229240005823611541292676234913505775165761543820764046537413943393325463602612485849366939102550336256797820440347815027443410399157963547486098366749815425187247171697678576246606105486928212486117878157055321965270364583625270716186820068538749425299073309429589410882809098930213978117176627031795312102177342499674234163614021182116065492884880492891668658240362567156235958605768725892407536211503981819707919444725863397622629226309480836486427388484176463279384813974310500625102568341 n = 14215826065753265334521416948225868542990756976323308408298887797364519400310818641526401662106853573185085731682502059761982246604277475488691297554851873224516934619888327644352138127883043558424300092247604877819821625587944308487310522092440517150600171819145803937177931473336108429889165189521078678397694303305705260759351843006130968234071638035667854938070597400634242396852782331461576526836227336952718230741560369621645218729592233657856104560425642219241082727756696967324334634822771842625681505869025740662258929200756109704988223034840699133778958569054445520305361142302393767439478256174414187983763 c = 415916446053083522663299405080903121619846594209033663622616979372099135281363175464579440520262612010099820951944229484417996994283898028928384268216113118778734726335389504987546718739928112684600918108591759061734340607527889972020273454098314620790710425294297542021830654957828983606433731988998097351888879368160881316237557097381718444193741788664735559392675419489952796677690968481917700683813252460912749931286739585465657312416977086336732056497161860235343155953578618273940135486362350057858779130960380833359506761436212727289297656191243565734621757889931250689354508999144817518599291078968866323093 n = 12221355905532691305226996552124162033756814028292708728711809229588190407700199452617060657420166395065565154239801465361510672853972152857415394695376825120759202857555325904640144375262531345320714166285999668052224661520834318497234299585219832943519644095197479639328120838919035625832361810964127485907587199925564724081163804724975965691571850962714258888527902920462746795712011579424322515292865504642938090200503979483095345893697972170153990274670257331483858538617460680462369680572833191232126527727222302641204529110948993583190295067970240051042000918629138767209918572311469915774910003970381965123241 c = 2248834602646305164283014556051672824689884721514190813323189875541899566338153534858709617544459297836048770439230174669883719627734394673012731609952869246171300132019334542245094425654362711870373095782083791160029789553806741967408922001051006100049326921742208757147339981269528740944842177729701945606827918253016001436218891580980192743564642120923356793292885805519110411357830040053435569937296612987581482128241218218550319154933831743819546558930918761162723110000328532730751591375727881221199739397698390594797621758011191224528339478784930214820615602510460640307707682865125229937141010351138099874025 n = 18152103454920389919231636321286527841833809319334215885641536161086810144890443857211776387914779781628740172079478910188540146498426564211851629962338413488555121865779016981727229209606498886170396500155102635962395243364899026418106378234307821492609778555173516000309435730752571818439328803899462791834490025768785383592935046996428331508608555503567191807692523852530836008436655164751054189301721070209363416058642811329040202582026786024825518381761299547703962502636888833428457116986351812252188468878701301184044948733274488264320930936362549028124581962244201377136969591119942276742760215403738913067567 c = 2797812094994121597295362327809389195134238119144547570610194659000554967367804835006774413888965325870488368112707535584687083342412367127561646136089638402907513075405746055834487062923240856950047936297155455745928810738711368950139327254040579266046642851362228893522740216519732851152162928545416236075387903789535000820423985522550638100049857678600662008021574841083416323980817348573062083159710189689337626277009675683473560325178417766400002763719953723259300977655801234386662217462862844994462505601804422871991694828697337752697234180117437785537788728412520613916334045368736691714704501962513954509705 n = 22877887459293720334652698748191453972019668578065068224653972884599636421200068659750242304040301306798039254241668648594556654589309801728248683586229288074709849246660525799452637187132633064172425677552176203292787732404537215347782229753837476655088638984496409603054524994383358547132112778403912563916886533181616856401929346567686400616307916690806467019665390260267596320840786982457521423178851498130935577260638269429250197050326097193841333205073650802709022947551398142692735680419453533128176592587955634333425401930362881423044363132586170013458300714163531162544301477356808388416864173949089028317961 c = 12271947322974809255127222556723394446467844330408506340843897575503534175121932185624776713618037572593449207329510171212097269297133492090526270770286000839978630002819714376964416081198925899119135271459404333829811516667576167576916805217016117373027245648473458331936273975110163065432285322832123169216976420362833557809289561705091817949915218278430834098156335989014645979633658818904753942786129126233956314517292746008579152368541316795082120147520597254020266752859205131887527661767589367756335766220841483940854397440079467053684289006956034944336788288196391829411432383541473132962783883758561108297747 n = 19844333358004073542783728196775487079202832688982038135532362073659058674903791697765527614270399097276261983744620537925712167578187109058145015032736796457938148615396547198728652435169126585595701228287449135664667959433491335769206692390262797325133960778920452511673878233190120432257482339068405290918739453464061987163074129048150451046315248186376609350095502130018696275764450248681787926130463463923862832714969425813770847493135627599129546112143050369344208092649256659330284904392961574494907186727388685504929586018639846040474616307662546605623294842316524163106100888851228858194942825157286544846177 c = 9531264751315473345056673937611382755236533664089452852716992791452558274873158812669513178040971923528201631609089069182049526587423864397527252061341857426422965190913745048414029690931254119437249218321954899956104589066479231204536856131403590472063496956452030342299863907499976917750846369802185896519725837163530049157920978007252920334447236842959033879772444475877613295594785710745889554296655932909212643500877218304116451889820444820534937901427158918411546484157737612926382420354101675658160847653151539420222526999426483473829341628599881460824765758346670633385844187252696874025582747177333702736465 n = 16956880944655068255446705024149899655327230949463546092744762226005904114738078692036960935391303255804754787864713189658290361949509917704853428701870609882427423574672772606814823959758208695540116440342488334213300943604780971422918744381486937517952553797134323570131582724393100092308466968491068503301604506186521656059375518680612292667310641047190088814753025794048591445267711939066523165042651430468971452726568222388482323097260496415484997546126185688914792795834046855221759289007609518312601640548469651358391745947588643697900883634533872314566389446271647587564348026861264979727062157272541149018781 c = 16110326928338602237561005337578085623028116490564329920738844771341250444164294693848130674347672763073995755532723894042946521372321947507527854966013459795492930736187058535665041545095683801386814190612817128504426590828954205050425979880047802547011117626354405687170961272200066258220699329112978151044633994329352673342582175349200008181837211288847301836681860817044391028992501763375849046751094019224570802498414368189170656992427042010362385494565216988561215657424755648213390551881450141899860811844684546992754530755092358644968088017107313907435586729574798046187046145596726569637758312033849476689378 n = 16472195897077185060734002588086375750797253422014472876266294484788862733424113898147596402056889527985731623940969291811284437034420929030659419753779530635563455664549165618528767491631867637613948406196511848103083967995689432928779805192695209899686072900265108597626632371718430059561807147486376536203800038054012500244392964187780217667805308512187849789773573138494622201856638931435423778275004491853486855300574479177472267767506041000072575623287557610576406578525902565241580838652860552046216587141709709405062150243990097835181557208274750462554811004137033087430556692966525170882625891516050207318491 c = 11867731823522211833301190385669833752050387304375114576570892885641949969365352586215693183003550684262313893105989683214739695968039039944442567581277252581988489020834299896625977474857889570528169919064941042132119301236852358823696947330423679033138054012027878783478922023431469564210485180679933264749281963405243082505688901662659030897104957499953192201440290084373968716271056483463909282407034181891901928790601973222643210525000717355062752079302291729448234374709852429885984987094307177760741403086538949190424454337896501402430653783597070178968921411867485584517214777073301007918941216316241784521708 n = 13890749889361612188368868998653029697326614782260719535555306236512452110708495623964530174188871342332417484996749651846510646453983388637377706674890018646246874688969342600780781646175634455109757266442675502522791531161284420286435654971819525519296719668701529481662071464145515727217108362496784024871976015116522898184301395037566514980846499856316532479656908169681719288258287756566886281183699239684997698487409138330229321935477734921670373632304542254938831218652340699024011371979519574576890581492623709896310465567043899767342676912434857372520308852745792360420376574037705943820090308501053778144141 c = 6250115196713939477947942995075509357173312813431601073354390451609559579925704891503987992181988654989477525811826607070378476102616752398280691012244301950194800995432882828020405062344160270290542566163969692748126314259624623341922057435728127596172871894887055305291345372720594481096374310285437492746765510292863238933163142677773310305789984897974266961231555124787205980411992251387207335655129551950825339766848166539671565212408741432649813058363660321480995187545006718837863674527475323414266732366507905974800565463011676462244368010182725161416783875646259625352308599198614681446394427674340328493047 n = 21457499145521259498911107987303777576783467581104197687610588208126845121702391694574491025398113729462454256070437978257494064504146718372095872819969887408622112906108590961892923178192792218161103488204912792358327748493857104191029765218471874759376809136402361582721860433355338373725980783308091544879562698835405262108188595630215081260699112737457564998798692048522706388318528370551365364702529068656665853097899157141017378975007689790000067275142731212069030175682911154288533716549782283859340452266837760560153014200605378914071410125895494331253564598702942990036163269043699029806343766286247742865671 c = 6269656777204332618433779865483197625538144405832409880710764183039800286008967127279281167109250083159801218370191973055663058165456565194979210256278526713608759141588082614531352489547674696723140599892318118960648862531538435596775798128845789504910467783731144808685373807716609662688064728614003904579841055786083326311313295311152563668422289435606771091246147867715987583149743032723028324394173498623642539175178996531881058274717907066845565199058931743481410454382746158558886667761300257488769795092777021292335562818583719708133179974425584610403335487082478848975656282384575767178925517257692365828720 '''
n = [n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10] c = [c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10]
for i inrange(len(n)): for j inrange(len(n)): if (i!=j): t = gmpy2.gcd(n[i],n[j]) if t != 1: p = t q = n[i] // p d = gmpy2.invert(e,(p-1)*(q-1)) m = pow(c[i],d,n[i]) print(long_to_bytes(m))
#sage import gmpy2 from Crypto.Util.number import *
# 构造一个很光滑的p,即p可以分解成许多小素数之积 p = 1 i = 2 while isPrime(p+1) ==Falseor p.bit_length()<1024 : p *= i i = gmpy2.next_prime(i)
#print(p+1)
g = 7 p = 20404068993016374194542464172774607695659797117423121913227131032339026169175929902244453757410468728842929862271605567818821685490676661985389839958622802465986881376139404138376153096103140834665563646740160279755212317501356863003638612390661668406235422311783742390510526587257026500302696834793248526734305801634165948702506367176701233298064616663553716975429048751575597150417381063934255689124486029492908966644747931 A = 20336091449271352050000450320351597189353592062279377142884247684088072216754371140723688503847322269500056016823378486967669507529408071986247421480538070427020298314420596325895121922786822444746298488308935254197730980462214370281102952073051791017954008911348128021296665124600273965642418702110947948173149809724203543773244607616601110670126605337319276524135448598308833199821995622969372761107826550795621362415457182 B = 3016038452071464751422492594184606815201979377859418872430468328543181786920301668755954977729921559697635702877324759319811639923934643618711315555467453055288843246623654939387741368313873206560664229687375070952935800932126812264287402142801364732994539469801252414404987968911552061069354407508916590343552775560281691608737262245571829068155383159065889848197300894149747651679644288337413872066182471443965426404626423 c = 8101058129734054038632640353434785588447342802920921913999474154497466343094694993166042668700504613189281291125022077749043805204765309971981658929422844998392130190493145455241084775180221325627765838099393607299071835294706132501949635214088146102721237571159346281928107966372652823580266088579392328383545323322931789769149936581855383571990955947284354676448353798975087410774586309247023597516943906734455833918792577
a = discrete_log(mod(A,p),mod(g,p))
b = discrete_log(mod(B,p),mod(g,p))
superkey = pow(B, a, p)
p = gmpy2.mpz(p) superkey = gmpy2.mpz(superkey)
d = gmpy2.invert(superkey,p) % p m = c*d % p print(long_to_bytes(int(m)))
defchall(input:Callable[[str],None], print:Callable[[str],None]): from hashlib import md5 from string import ascii_letters s = "".join(random.choices(ascii_letters, k=16)) h = md5(s.encode()).hexdigest() print(f"<!> md5(XXXXXXXX+{s[8:]}) == {h}") i = input("Give me XXXXXXXX: ") if md5((i + s[8:]).encode()).hexdigest() != h: print("<!> ACCESS DENIED <!>") return inst = LCG() print("Let's play a simple game! If you can guess the right number, I will give your the flag! You have 10 tries") for tries inrange(10): i = input(f"Give me a number, you have failed for {tries} times: ") ifint(i) == (right := inst()): print(f"Congurations! You win the game! Your flag is here: {flag}") else: print(f"Oh, you are wrong! The right number is {right}")
print("未知数:",Xnum) print("tail:",tail) print("hash:",hash) print("开始爆破") for i in product(table,repeat=4): head = ''.join(i) t = hashlib.md5((head + tail).encode()).hexdigest() if t == hash: print('爆破成功!结果是:', end='') print(head) sh.send(head.encode()) break
print("以下是提交完XXXX之后的流程\n") output = [] d = sh.recvline() print(d.decode()) for _ inrange(9): sh.send("1".encode()) data = sh.recvline() print(data.decode()) output.append(int(data.decode().split(' ')[-1])) print(output)
t = [] for i inrange(1,len(output)): t.append(output[i]-output[i-1])
T = [] for i inrange(1,len(t)-1): T.append(t[i+1]*t[i-1] - t[i]**2)
m = [] for i inrange(len(T)-1): mm = gmpy2.gcd(T[i],T[i+1]) if isPrime(mm): m.append(int(mm)) else: for i inrange(1,100): if isPrime(mm // i): mm = mm // i m.append(int(mm)) break print("m的可能取值",m) for i in m: global flag flag = False if10000 < i < 20000and isPrime(i): print("m=",i) a = gmpy2.invert(t[0],i) * t[1] % i if10000 < a < 20000: print("a=",a) b = output[1] - a*output[0] % i a_ = gmpy2.invert(a,i)
seed = (a * output[-1] + b) % i print("下一个值是:",seed) sh.send(str(seed).encode()) data = sh.recvline() print(data.decode()) flag = data.decode().split(":")[-1].strip() break else: continue else: continue if flag != False: print(flag) break
withopen("flag.txt","rb") as fs: flag = fs.read().strip()
p = getPrime(1024) q = getPrime(1024) n = p * q e = 0x609778981bfbb26bb93398cb6d96984616a6ab08ade090c1c0d4fedb00f44f0552a1555efec5cc66e7960b61e94e80e7483b9f906a6c8155a91cdc3e4917fa5347c58a2bc85bb160fcf7fe98e3645cfea8458ea209e565e4eb72ee7cbb232331a862d8a84d91a0ff6d74aa3c779b2b129c3d8148b090c4193234764f2e5d9b2170a9b4859501d07c0601cdd18616a0ab2cf713a7c785fd06f27d68dff24446d884644e08f31bd37ecf48750e4324f959a8d37c5bef25e1580851646d57b3d4f525bc04c7ddafdf146539a84703df2161a0da7a368675f473065d2cb661907d990ba4a8451b15e054bfc4dd73e134f3bf7d8fa4716125d8e21f946d16b7b0fc43 m = int.from_bytes(flag,"big") c = pow(m,e,n)
defcontinuedFra(x, y): """计算连分数 :param x: 分子 :param y: 分母 :return: 连分数列表 """ cf = [] while y: cf.append(x // y) x, y = y, x % y return cf
defgradualFra(cf): """计算传入列表最后的渐进分数 :param cf: 连分数列表 :return: 该列表最后的渐近分数 """ numerator = 0 denominator = 1 for x in cf[::-1]: # 这里的渐进分数分子分母要分开 numerator, denominator = denominator, x * denominator + numerator return numerator, denominator
defsolve_pq(a, b, c): """使用韦达定理解出pq,x^2−(p+q)∗x+pq=0 :param a:x^2的系数 :param b:x的系数 :param c:pq :return:p,q """ par = gmpy2.isqrt(b * b - 4 * a * c) return (-b + par) // (2 * a), (-b - par) // (2 * a)
defgetGradualFra(cf): """计算列表所有的渐近分数 :param cf: 连分数列表 :return: 该列表所有的渐近分数 """ gf = [] for i inrange(1, len(cf) + 1): gf.append(gradualFra(cf[:i])) return gf
defwienerAttack(e, n): """ :param e: :param n: :return: 私钥d """ cf = continuedFra(e, n) gf = getGradualFra(cf) for d, k in gf: if k == 0: continue if (e * d - 1) % k != 0: continue phi = (e * d - 1) // k p, q = solve_pq(1, n - phi + 1, n) if p * q == n: return d
n= e= c=
d = wienerAttack(e, n) print("d =",d) m = pow(c, d, n) print(libnum.n2s(m).decode())
from math import gcd from math import isqrt from random import randrange from gmpy2 import is_prime # from sage.all import is_prime
deffactorize(N, phi): """ Recovers the prime factors from a modulus if Euler's totient is known. This method only works for a modulus consisting of 2 primes! :param N: the modulus :param phi: Euler's totient, the order of the multiplicative group modulo N :return: a tuple containing the prime factors, or None if the factors were not found """ s = N + 1 - phi d = s ** 2 - 4 * N p = int(s - isqrt(d)) // 2 q = int(s + isqrt(d)) // 2 return p, q
deffactorize_multi_prime(N, phi): """ Recovers the prime factors from a modulus if Euler's totient is known. This method works for a modulus consisting of any number of primes, but is considerably be slower than factorize. More information: Hinek M. J., Low M. K., Teske E., "On Some Attacks on Multi-prime RSA" (Section 3) :param N: the modulus :param phi: Euler's totient, the order of the multiplicative group modulo N :return: a tuple containing the prime factors """ prime_factors = set() factors = [N] whilelen(factors) > 0: # Element to factorize. N = factors[0]
w = randrange(2, N - 1) i = 1 while phi % (2 ** i) == 0: sqrt_1 = pow(w, phi // (2 ** i), N) if sqrt_1 > 1and sqrt_1 != N - 1: # We can remove the element to factorize now, because we have a factorization. factors = factors[1:]
p = gcd(N, sqrt_1 + 1) q = N // p
if is_prime(p): prime_factors.add(p) elif p > 1: factors.append(p)
if is_prime(q): prime_factors.add(q) elif q > 1: factors.append(q)
# Continue in the outer loop break
i += 1
returntuple(prime_factors) N = phi = prime = factorize_multi_prime(N,phi) #print(prime)
import gmpy2 from random import choices from Crypto.Util.number import *
while1: primes2 = [gmpy2.next_prime(p) for p in choices(prime, k=3)] n = c = if prod(primes2) == n: phi = 1 for i in primes2: phi *= (i-1) d = gmpy2.invert(65537,phi) m = pow(c,d,n) flag = long_to_bytes(int(m)) ifb'moectf'in flag: print(flag) break
难
xorrrrrrrrr
这道题算是长见识了,在lingfeng师傅指导下学了新东西
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
flag = open('flag.txt','rb').read() assert flag.startswith(b'moectf{') and flag.endswith(b'}') article = open('article.txt','rb').read()
import random
strxor = lambda x,y: bytes([a^b for a,b inzip(x,y)])
result = []
for i inrange(100): range_start = random.randint(0, len(article) - len(flag)) mask = article[range_start:range_start + len(flag)] result.append(strxor(flag,mask))
withopen("result.log","w") as fs: fs.writelines([str(i)+"\n"for i in result])
from Crypto.Util.number import * from tqdm import * from collections import Counter
strxor = lambda x,y: bytes([a^b for a,b inzip(x,y)])
withopen("result.log",'r') as f: f = f.readlines()
cipher = [eval(i) for i in f]
head = b'moectf{'
article = [] for i in cipher: article.append(bytes(strxor(head,i[:7]))) print(article) re=[] for x in tqdm(article): for i in cipher: for j inrange(0,len(i)-7): tmp=strxor(i[j:j+7],x) iflen(str(tmp))==10: re.append(tmp.decode())
flag = "moectf{" for _ in trange(72-8): col=[] for i in re: if flag[-6:] ==i[:6]: col.append(i[-1]) K=Counter(col) flag=flag+K.most_common()[0][0] print(flag+'}')
def_block_hash(a, b, c, d): x, y, z, w = F(a, b, c), F(b, c, d), F(c, d, a), F(d, a, b) return (a ^ b ^ c ^ d ^ x ^ y ^ z ^ w) ^ 0xFFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF
from typing importCallable from random import randbytes from base64 import b64decode,b64encode from hashlib import md5 from string import ascii_letters from random import choices
withopen("flag.txt", "r") as f: flag = f.read().strip()
s = "".join(choices(ascii_letters, k=16)) h = md5(s.encode()).hexdigest() print(f"<!> md5(XXXXXXXX+{s[8:]}) == {h}") i = input("Give me XXXXXXXX: ") return md5((i + s[8:]).encode()).hexdigest() == h ifnot proof_of_work(): print("<!> ACCESS DENIED <!>") return
b = randbytes(256) print(f"this is a random bytes: {b64encode(b).decode()}") i = input("give me another bytes with the same hash: ") try: d = b64decode(i) except: print("invaild input") ifhash(b) == hash(d) and d!=b: print(f"congurations! and your flag is {flag}")
def_block_hash(a, b, c, d): x, y, z, w = F(a, b, c), F(b, c, d), F(c, d, a), F(d, a, b) return (a ^ b ^ c ^ d ^ x ^ y ^ z ^ w) ^ 0xFFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF
print("未知数:",Xnum) print("tail:",tail) print("hash:",hash) print("开始爆破") for i in product(table,repeat=Xnum): head = ''.join(i) t = hashlib.md5((head + tail).encode()).hexdigest() if t == hash: print('爆破成功!结果是:', end='') print(head) sh.send(head.encode()) break
data2 = sh.recvuntil(b':').decode() print(data2) deftrans(c): length = len(c) C = [c[i:i+length//4] for i inrange(0,length,length//4)] C[0],C[1],C[2],C[3] = C[2],C[3],C[0],C[1]
returnb"".join(C)
tmp = trans(cipher) length = len(tmp) tmpp = [tmp[i:i+length//4] for i inrange(0,length,length//4)]
anser = b"" for i in tmpp: anser += trans(i) print(anser) sh.send(base64.b64encode(anser)) #要进行base64加密后再传给靶机 sh.interactive() #base64后就是byte数据,不需要encode
round = 2 flag = open("./secret", "rb").read().strip()
deff(m, key): m = m ^ (m >> 4) m = m ^ (m << 5) m = m ^ (m >> 8) m ^= key m = (m * 1145 + 14) % 2**64 m = (m * 1919 + 810) % 2**64 m = (m * key) % 2**64 return m
defenc(m, key, round): key = bytes_to_long(key) left = bytes_to_long(m[:8]) right = bytes_to_long(m[8:]) for i inrange(round): left, right = right, f(right, key) ^ left left, right = right, left return long_to_bytes(left).rjust(8, b"\x00") + long_to_bytes(right).rjust(8, b"\x00")
defpadding(m): mlen = len(m) pad = 16 - mlen % 16 return m + pad * bytes([pad])
defecb_enc(m, key): m = padding(m) mlen = len(m) c = b"" for i inrange(mlen // 16): c += enc(m[i * 16 : i * 16 + 16], key, round) return c
deff(m, key): m = m ^ (m >> 4) m = m ^ (m << 5) m = m ^ (m >> 8) m ^= key m = (m * 1145 + 14) % 2**64 m = (m * 1919 + 810) % 2**64 m = (m * key) % 2**64 return m
defdec(c,key): key = bytes_to_long(key) left = bytes_to_long(c[:8]) right = bytes_to_long(c[8:]) m_right = f(right,key) ^ left m_left = f(m_right,key) ^ right return long_to_bytes(m_left) + long_to_bytes(m_right)
defecb_dec(c, key): clen = len(c) m = b"" for i inrange(clen // 16): m += dec(c[i * 16 : i * 16 + 16], key) return m
c = b'\x0b\xa7\xc6J\xf6\x80T\xc6\xfbq\xaa\xd8\xcc\x95\xad[\x1e\'W5\xce\x92Y\xd3\xa0\x1fL\xe8\xe1"^\xad' key = b"wulidego" flag = ecb_dec(c,key) print(flag)
from Crypto.Util.number import * from os import urandom
round = 2 flag = open("./secret", "rb").read().strip()
deff(m, key): m = m ^ (m >> 4) m = m ^ (m << 5) m = m ^ (m >> 8) m ^= key m = (m * 1145 + 14) % 2**64 m = (m * 1919 + 810) % 2**64 m = (m * key) % 2**64 return m
defenc(m, key, round): key = bytes_to_long(key) left = bytes_to_long(m[:8]) right = bytes_to_long(m[8:]) for i inrange(round): left, right = right, f(right, key) ^ left left, right = right, left return long_to_bytes(left).rjust(8, b"\x00") + long_to_bytes(right).rjust(8, b"\x00")
defpadding(m): mlen = len(m) pad = 16 - mlen % 16 return m + pad * bytes([pad])
defecb_enc(m, key): m = padding(m) mlen = len(m) c = b"" for i inrange(mlen // 16): c += enc(m[i * 16 : i * 16 + 16], key, round) return c
deff(m, key): m = m ^ (m >> 4) m = m ^ (m << 5) m = m ^ (m >> 8) m ^= key m = (m * 1145 + 14) % 2**64 m = (m * 1919 + 810) % 2**64 m = (m * key) % 2**64 return m
defdec(c,key): key = bytes_to_long(key) left = bytes_to_long(c[:8]) right = bytes_to_long(c[8:]) m_right = f(right,key) ^ left m_left = f(m_right,key) ^ right return long_to_bytes(m_left) + long_to_bytes(m_right)
defecb_dec(c, key): clen = len(c) m = b"" for i inrange(clen // 16): m += dec(c[i * 16 : i * 16 + 16], key) return m
m = b'\x10\x10\x10\x10\x10\x10\x10\x10' ct = b'B\xf5\xd8gy\x0f\xaf\xc7\xdf\xabn9\xbb\xd0\xe3\x1e0\x9eR\xa9\x1c\xb7\xad\xe5H\x8cC\x07\xd5w9Ms\x03\x06\xec\xb4\x8d\x80\xcb}\xa9\x8a\xcc\xd1W\x82[\xd3\xdc\xb4\x83P\xda5\xac\x9e\xb0)\x98R\x1c\xb3h' c = bytes_to_long(ct[-8:]) ^ bytes_to_long(m) bin_c = bin(c)[2:].rjust(64,'0')
k1 = [b''] for i inrange(1,5): k2 = [] for KEY in k1: for j inrange(2**16): key1 = long_to_bytes(j) + KEY cc = f(bytes_to_long(m),bytes_to_long(key1)) bin_cc = bin(cc)[2:].rjust(64,'0') if bin_cc[-16*i:] == bin_c[-16*i:]: k2.append(key1) k1 = k2 # print(k2)
key = [b'4t*zFD\xac\xb4', b'\xb4t*zFD\xac\xb4', b'\\q\x0f\x00w\xeb\xc1"', b'\xdcq\x0f\x00w\xeb\xc1"'] for KEY in key: flag = ecb_dec(ct,KEY) print(flag)
print("Welcome to the MoeCTF2023 Jail challenge.It's time to work on this calc challenge.") print("Enter your expression and I will evaluate it for you.") user_input_data = input("> ") print('calc Answer: {}'.format(eval(user_input_data)))
利用eval()函数的特性。输入print(open('flag','r').read())
这个文件名是猜的,尝试各种可能,总能弄出来。
Jail level 1
1 2 3 4 5 6 7
print("Welcome to the MoeCTF2023 Jail challenge level1.It's time to work on this calc challenge.") print("Enter your expression and I will evaluate it for you.") user_input_data = input("> ") iflen(user_input_data)>12: print("Oh hacker! Bye~") exit(0) print('calc Answer: {}'.format(eval(user_input_data)))
print("Welcome to the MoeCTF2023 Jail challenge level1.It's time to work on this calc challenge.") print("Enter your expression and I will evaluate it for you.") user_input_data = input("> ") iflen(user_input_data)>6: print("Oh hacker! Bye~") exit(0) print('calc Answer: {}'.format(eval(user_input_data)))
长度限制在6,只能用help()了
这题倒是成功了。不知道为啥
Jail level 3
1 2 3 4 5 6 7 8 9 10 11 12
import re BANLIST = ['breakpoint'] BANLIST_WORDS = '|'.join(f'({WORD})'for WORD in BANLIST) print("Welcome to the MoeCTF2023 Jail challenge.It's time to work on this calc challenge.") print("Enter your expression and I will evaluate it for you.") user_input_data = input("> ") iflen(user_input_data)>12: print("Oh hacker! Bye~") exit(0) if re.findall(BANLIST_WORDS, user_input_data, re.I): raise Exception('Blacklisted word detected! you are hacker!') print('Answer result: {}'.format(eval(user_input_data)))
c = "0A08020413011C570F381E5712382C095710382F571038130838350211541514023832373F4646461A0000000000000000000000000000000000000000000000" c = bytes.fromhex(c)
m = "" for i in c: mm = chr(i ^ 0x67) m += mm print(m) #moectf{0h_y0u_Kn0w_H0w_to_Rev3rse_UPX!!!}