-
Notifications
You must be signed in to change notification settings - Fork 1
/
cyber-sea-game-2017-rsa-8192-200.html
126 lines (116 loc) · 19.6 KB
/
cyber-sea-game-2017-rsa-8192-200.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<html lang="en">
<head>
<title>aufarg:/var/log $ _</title>
<link href='https://fonts.googleapis.com/css?family=Inconsolata' rel='stylesheet' type='text/css'>
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300" rel="stylesheet">
<link rel="stylesheet" href="https://aufarg.github.io/theme/css/main.css" type="text/css" />
<link rel="stylesheet" href="https://aufarg.github.io/theme/css/pygments.css" type="text/css" />
<link rel="stylesheet" href="https://aufarg.github.io/theme/css/font-awesome.min.css" type="text/css" />
<meta charset="utf-8" />
</head>
<body id="index" class="home">
<header id="banner" class="body">
<div class="banner"><a href="https://aufarg.github.io">aufarg:/var/log $ _ <strong></strong></a></div>
<nav>
<ol class="nav">
<li><a href="https://aufarg.github.io/categories.html">categories</a> </li>
<li><a href="https://aufarg.github.io/tags.html">tags</a> </li>
<li><a href="https://aufarg.github.io/archives.html">archive</a></li>
</ol>
<ul>
</ul>
</nav>
</header>
<div class="box">
<section id="content" class="body">
<article class="post-content">
<header class="post">
<h1 class="post-title">
Cyber Sea Game 2017: rsa-8192 (200)
</h1>
</header>
<div class="post-info">
<div class="post-date">
<abbr>Wed 29 November 2017</abbr> ·
< 1 min read </div>
</div> <p>We are given a file, <code>encrypted.txt</code>, which looks as follows.</p>
<div class="highlight"><pre><span class="code-line"><span></span>encrypted = flag^e mod N</span>
<span class="code-line"></span>
<span class="code-line">N=929412161736416785602626791790087761924898902195151595398647919800777946023488971853180598176692598583294061182260536041579346366926172653588840221567273437362595402878942949261351013183228816076787208298761416393920642857987212821185440640229264390419503134199675174977584782229111062529809687171117150001744486594819183472678424697917104835410391461624730889726473874533632011783818612095039231758588125644714046393001791112810853913402405581873909038522129835207451007166051445611924869493431837474285007276641743601868212445343248507996492168302629410158793171095836266438216336450410161777445930018295413880788397817212920901086111768107584700273194248624078825784962833148389339669672770486880797307481695588172832838731072379885756990402094668632885608688308703281839275920814948615941253077843879626529478150269189961487485485588639730236538541375331823636862137530268960752698621771461443704327244021041422495986281380147586211470392418121029373841474934960486004859939618776068437679091746000882065500417603392927878932556252121339876316869065207294672799230304843433288112308586240048684735313520164083326788976779830776801482533953926103609143333554819874985879730182046630820535196380040115825136940584589556785820159343472924511678054586101279599213597041601780382296431834866858061507446104315668473990065085836000677940559666983863740858655209448321924892616633958276590031999377342119486934203280802950550853609192641981061152748812514091191340011124311081998324364749868579702401217654561296975509502208974088057282185982036347055436781944503659441121489871215835821003778237875885585700465817962525400543288824177317817062453958271388228532199292458847881512536878190894921450789438099744648090308652667907702590059579778875658483803814963849425246348271265297992326326941649385344794434378497144236903691683724320406798550633839076630007346411875416248546336032185298058900521975982336237334536607755792300625619630545602773119916582573302060747209289533363253570250473519076096695447047922887567718357635771477087257951066557774977631702031440524698209045937363875790679216746249380353174688379191327766840638039388162445662493445777856792810700198251083685207125399710828301628160312264601730356710220261724123846339093165967118971272821247106002282782902865842552867964918068336459439425481643750939492002728297110520672697512136349144736715821664013325546531282992945883469394942896186838909299361507395054625609900948608639067118377943217351</span>
<span class="code-line">e=65537</span>
<span class="code-line">encrypted=920588809098419925304898815996779959024923992725236480766957762101020068092418642972569896909288446822625160018245995852395637010359546968987469161375560974732331888587499575726726591661288086170102991231536351472553667136912003817645761994113867006023358064959804334508836786614546373318854185561928539181380849135202589436399469446278977853873976388512625983066695071220448389094452382204859072246204132607199499483725325567718766144169704838594296010882715656390868083309425868664311629487870655537301587586264593373623106904074718645449224372238734853263892364592224060906009118410260996474851170094609808378917112241913945371712277407646776651895736210620267993703347840913541477388590431559378925211730392071715903857032396752409447351784452479847357247902830713107054131920974381233928620873147787352397722780557371121588138822734422526916591197108637109219278170352817301806094020568558870258047526598307845757398567950006581582539714075107753798978096510308355532420719999999220855138247162168113460577910905929588333387729891130789423649360964154825883032891254447994769161274294764104742371937868945566163338795266034258979330588673875819190729858101607459440752551327488554472157318363257082223209451608433992248074386159317605908434880514654833712622074369971266584704933749205856068601008066620986626613108276972360189307015131946572931252688986331609366041663453234811061216223134001974803179901785278084643248758399580372104073097458529704426905971473072151381373448553361414418342456280135383419519503028786544292302907897461141075166092520323444990854104372309393440260002551733596011221728567186544196673107818614484776574487330137101004134890658956591489639306529923386792687879390716232617992555567785121188340568023697639047632424964759610425447619800320974777755083401005364154241941027256239760103909197224362499684459388821532418774937557650857921765385859799914470867641296667037230734819015690775890840326939101061216700887599083952915657512483532308094437422732323767769158944259841802993244806549824743056280460644331001819024060314281381987785996895717885719094296415336981352928519848848055894963780262847910621421107636554884980968204334872719316159028387134320156378724268116858255133532724522370999208549105477046537264757515852756867521989580046767357180880003025052171778061564683996167899012373574038101166777008676727628024284803295629377550189159115681868387149280045459828574367106610925183390170585407262031209717446921115630</span>
</pre></div>
<p>Since there's no gimmick in the encryption process, let's try factorize <code>N</code>. Factoring <code>N</code> with
<a href="https://en.wikipedia.org/wiki/Fermat's_factorization_method">Fermat's factorization</a> included
in <a href="https://sourceforge.net/projects/yafu/">Yafu</a> yield <code>p</code> and <code>q</code> used to create <code>N</code>. Next, we
calculate <code>d</code> to decrypt <code>encrypted</code> to get the flag.</p>
<p>Here is the Python script to find the value of flag:</p>
<div class="highlight"><pre><span class="code-line"><span></span><span class="kn">import</span> <span class="nn">gmpy2</span></span>
<span class="code-line"><span class="kn">from</span> <span class="nn">Crypto.PublicKey</span> <span class="kn">import</span> <span class="n">RSA</span></span>
<span class="code-line"></span>
<span class="code-line"></span>
<span class="code-line"><span class="n">N</span><span class="o">=</span><span class="mi">929412161736416785602626791790087761924898902195151595398647919800777946023488971853180598176692598583294061182260536041579346366926172653588840221567273437362595402878942949261351013183228816076787208298761416393920642857987212821185440640229264390419503134199675174977584782229111062529809687171117150001744486594819183472678424697917104835410391461624730889726473874533632011783818612095039231758588125644714046393001791112810853913402405581873909038522129835207451007166051445611924869493431837474285007276641743601868212445343248507996492168302629410158793171095836266438216336450410161777445930018295413880788397817212920901086111768107584700273194248624078825784962833148389339669672770486880797307481695588172832838731072379885756990402094668632885608688308703281839275920814948615941253077843879626529478150269189961487485485588639730236538541375331823636862137530268960752698621771461443704327244021041422495986281380147586211470392418121029373841474934960486004859939618776068437679091746000882065500417603392927878932556252121339876316869065207294672799230304843433288112308586240048684735313520164083326788976779830776801482533953926103609143333554819874985879730182046630820535196380040115825136940584589556785820159343472924511678054586101279599213597041601780382296431834866858061507446104315668473990065085836000677940559666983863740858655209448321924892616633958276590031999377342119486934203280802950550853609192641981061152748812514091191340011124311081998324364749868579702401217654561296975509502208974088057282185982036347055436781944503659441121489871215835821003778237875885585700465817962525400543288824177317817062453958271388228532199292458847881512536878190894921450789438099744648090308652667907702590059579778875658483803814963849425246348271265297992326326941649385344794434378497144236903691683724320406798550633839076630007346411875416248546336032185298058900521975982336237334536607755792300625619630545602773119916582573302060747209289533363253570250473519076096695447047922887567718357635771477087257951066557774977631702031440524698209045937363875790679216746249380353174688379191327766840638039388162445662493445777856792810700198251083685207125399710828301628160312264601730356710220261724123846339093165967118971272821247106002282782902865842552867964918068336459439425481643750939492002728297110520672697512136349144736715821664013325546531282992945883469394942896186838909299361507395054625609900948608639067118377943217351</span></span>
<span class="code-line"><span class="n">e</span><span class="o">=</span><span class="mi">65537</span></span>
<span class="code-line"><span class="n">encrypted</span><span class="o">=</span><span class="mi">920588809098419925304898815996779959024923992725236480766957762101020068092418642972569896909288446822625160018245995852395637010359546968987469161375560974732331888587499575726726591661288086170102991231536351472553667136912003817645761994113867006023358064959804334508836786614546373318854185561928539181380849135202589436399469446278977853873976388512625983066695071220448389094452382204859072246204132607199499483725325567718766144169704838594296010882715656390868083309425868664311629487870655537301587586264593373623106904074718645449224372238734853263892364592224060906009118410260996474851170094609808378917112241913945371712277407646776651895736210620267993703347840913541477388590431559378925211730392071715903857032396752409447351784452479847357247902830713107054131920974381233928620873147787352397722780557371121588138822734422526916591197108637109219278170352817301806094020568558870258047526598307845757398567950006581582539714075107753798978096510308355532420719999999220855138247162168113460577910905929588333387729891130789423649360964154825883032891254447994769161274294764104742371937868945566163338795266034258979330588673875819190729858101607459440752551327488554472157318363257082223209451608433992248074386159317605908434880514654833712622074369971266584704933749205856068601008066620986626613108276972360189307015131946572931252688986331609366041663453234811061216223134001974803179901785278084643248758399580372104073097458529704426905971473072151381373448553361414418342456280135383419519503028786544292302907897461141075166092520323444990854104372309393440260002551733596011221728567186544196673107818614484776574487330137101004134890658956591489639306529923386792687879390716232617992555567785121188340568023697639047632424964759610425447619800320974777755083401005364154241941027256239760103909197224362499684459388821532418774937557650857921765385859799914470867641296667037230734819015690775890840326939101061216700887599083952915657512483532308094437422732323767769158944259841802993244806549824743056280460644331001819024060314281381987785996895717885719094296415336981352928519848848055894963780262847910621421107636554884980968204334872719316159028387134320156378724268116858255133532724522370999208549105477046537264757515852756867521989580046767357180880003025052171778061564683996167899012373574038101166777008676727628024284803295629377550189159115681868387149280045459828574367106610925183390170585407262031209717446921115630</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="n">p</span><span class="o">=</span><span class="mi">964060247980600424882496787833195727906805173732280005717388699725532636521797363463435588993205012433289938421234428830523567311188042611106457883201966470006303750907166838330060823633283013940410306038268983618865370962731589672554633796051045158749482594143853598006994287798115637885084571426988077139398570456962228730497979265368264633941298156842391072806460818198899164554832714295099678972623761858587473415910794196037864220126679203125475070470980238516050617135988853778312660415160985825856597016142751737538790539702106383219749784537130277270505077250236242143062375337876912837058651292173250635844414795220431107951927619945335385909163935856182494652394224867455892608230742728759132339238675864013950407829927122320059412983345995734122145559584275114056377925553861519678675935866880233993227879918627667628528991057936394969319270681701646482791575969482314741658317338674632869247081783805519453497586504670720035143466981322020942310120161301437231350873623616573895773034690044538574819535382682516515760952825571284843678412518009677589389874426349934972956134734107630523744136789086919536735106258805647517395785660362458586587476662926565897869615081930393603652823267638976883852807985706649441360825303</span></span>
<span class="code-line"><span class="n">q</span><span class="o">=</span><span class="mi">964060247980600424882496787833195727906805173732280005717388699725532636521797363463435588993205012433289938421234428830523567311188042611106457883201966470006303750907166838330060823633283013940410306038268983618865370962731589672554633796051045158749482594143853598006994287798115637885084571426988077139398570456962228730497979265368264633941298156842391072806460818198899164554832714295099678972623761858587473415910794196037864220126679203125475070470980238516050617135988853778312660415160985825856597016142751737538790539702106383219749784537130277270505077250236242143062375337876912837058651292173250635844414795220431107951927619945335385909163935856182494652394224867455892608230742728759132339238675864013950407829927122320059412983345995734122145559584275114056377925553861519678675935866880233993227879918627667628528991057936394969319270681701646482791575969482314741658317338674632869247081783805519453497586504670720035143466981322020942310120161301437231350873623616573895773034690044538574819535382682516515760952825571284843678412518009677589389874426349934972956134734107630523744136789086919536735106258805647517395785660362458586587476662926565897869615081930393603652823267638976883852807985706649441360822417</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="k">assert</span><span class="p">(</span><span class="n">N</span> <span class="o">==</span> <span class="n">p</span><span class="o">*</span><span class="n">q</span><span class="p">)</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="n">d</span> <span class="o">=</span> <span class="nb">long</span><span class="p">(</span><span class="n">gmpy2</span><span class="o">.</span><span class="n">invert</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="n">gmpy2</span><span class="o">.</span><span class="n">lcm</span><span class="p">(</span><span class="n">p</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">q</span><span class="o">-</span><span class="mi">1</span><span class="p">)))</span></span>
<span class="code-line"><span class="k">print</span><span class="p">(</span><span class="nb">hex</span><span class="p">(</span><span class="nb">pow</span><span class="p">(</span><span class="n">encrypted</span><span class="p">,</span> <span class="n">d</span><span class="p">,</span> <span class="n">N</span><span class="p">))[</span><span class="mi">2</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s1">'hex'</span><span class="p">))</span></span>
</pre></div>
<p>Flag is: <code>CS2017{Pr0duct_of_clos3_pr1m3_numbers_c4n_be_fact0r1ng}</code></p>
<footer>
<div class="post-share-links">
<a href="http://www.facebook.com/sharer/sharer.php?u=https%3A//aufarg.github.io/cyber-sea-game-2017-rsa-8192-200.html" target="_blank" title="Share on Facebook"><i class="fa fa-facebook-square" aria-hidden="true"></i></a>
<a href="https://twitter.com/intent/tweet?text=Cyber%20Sea%20Game%202017%3A%20rsa-8192%20%28200%29&url=https%3A//aufarg.github.io/cyber-sea-game-2017-rsa-8192-200.html" target="_blank" title="Share on Twitter"><i class="fa fa-twitter-square" aria-hidden="true"></i></a>
<a href="https://plus.google.com/share?url=https%3A//aufarg.github.io/cyber-sea-game-2017-rsa-8192-200.html" target="_blank" title="Share on Google Plus"><i class="fa fa-google-plus-square" aria-hidden="true"></i></a>
<a href="mailto:?subject=Cyber%20Sea%20Game%202017%3A%20rsa-8192%20%28200%29&body=https%3A//aufarg.github.io/cyber-sea-game-2017-rsa-8192-200.html" target="_blank" title="Share via Email"><i class="fa fa-envelope-square" aria-hidden="true"></i></a>
</div>
</footer>
<div class="post-related">
<h3>Related Posts</h3>
<div class="post-summary">
<a href="https://aufarg.github.io/meepwn-ctf-2017-simpler-rsa-100.html">MeePwn CTF 2017: Simpler RSA (100)</a>
</div>
<div class="post-summary">
<a href="https://aufarg.github.io/cyber-sea-game-2017-addcrypto-50.html">Cyber Sea Game 2017: addcrypto (50)</a>
</div>
<div class="post-summary">
<a href="https://aufarg.github.io/tuctf-2017-crypto-clock-300.html">TUCTF 2017: Crypto Clock (300)</a>
</div>
<div class="post-summary">
<a href="https://aufarg.github.io/capture-the-fun-cyber-sea-game-2017.html">Capture The Fun: Cyber Sea Game 2017</a>
</div>
<div class="post-summary">
<a href="https://aufarg.github.io/meepwn-ctf-2017-t-100.html">MeePwn CTF 2017: |\/|/-\T|-| (100)</a>
</div>
</div> </article>
</section>
<hr/>
</div>
<footer id="siteinfo" class="footer">
<div>
<a href="https://aufarg.github.io">Aufar Gilbran</a> (2012)
</div>
<div>
powered by <a href="http://getpelican.com/">Pelican</a>
and <a href="http://python.org">Python</a>.
Theme based on <a href="http://github.com/slok/iris">iris</a>
</div>
<div>
Icons from Font Awesome by <a href="http://fontawesome.io/"> font awesome</a>.
<a href="https://fonts.google.com/specimen/Open+Sans+Condensed">Title & headers</a>, <a href="https://fonts.google.com/specimen/Lato">body</a> and <a href="https://fonts.google.com/specimen/Inconsolata">source code</a> fonts by google fonts
</div>
<div class="social">
<a href="https://github.com/aufarg"><i class="fa fa-github-square"></i></a>
<a href="#"><i class="fa fa-Another social link-square"></i></a>
<a href="mailto:aufargilbran@gmail.com"><i class="fa fa-envelope-square"></i></a>
</div>
</footer>
</body>
</html>