<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" 
  xmlns:content="http://purl.org/rss/1.0/modules/content/" 
  xmlns:dc="http://purl.org/dc/elements/1.1/" 
  xmlns:atom="http://www.w3.org/2005/Atom" 
  xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" 
  xmlns:media="http://search.yahoo.com/mrss/">
  <channel>
    <title>Crypto on Mal Breaks Things</title>
    <link>https://sec.gd/blog/en/tags/crypto/</link>
    <description>Recent content in Crypto on Mal Breaks Things</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <managingEditor>mal@sec.gd (mal)</managingEditor>
    <webMaster>mal@sec.gd (mal)</webMaster>
    <copyright>&amp;copy;{year}. [License and Info](/blog/about/)</copyright>
    <lastBuildDate>Tue, 27 Sep 2022 04:00:00 +0000</lastBuildDate>
    <sy:updatePeriod>daily</sy:updatePeriod>
    
        <atom:link href="https://sec.gd/blog/en/tags/crypto/index.xml" rel="self" type="application/rss+xml" />
    
    
    
      <item>
        <title>Hacker&#39;s Playground: Legonigma</title>
        <link>https://sec.gd/blog/en/posts/legonigma/</link>
        <pubDate>Tue, 27 Sep 2022 04:00:00 +0000</pubDate>
        <author>mal@sec.gd (mal)</author>
        <atom:modified>Tue, 27 Sep 2022 04:00:00 +0000</atom:modified>
        <guid>https://sec.gd/blog/en/posts/legonigma/</guid>
        <description>&lt;p&gt;I recently participated in Samsung&amp;rsquo;s &lt;a href=&#34;https://ctftime.org/event/1715/&#34;&gt;Hacker&amp;rsquo;s Playground CTF&lt;/a&gt; with &lt;a href=&#34;https://wrecktheline.com/&#34;&gt;Wreck The Line&lt;/a&gt;. We finished with 1592 points, in 26th place of 1075 teams. Most of my time was spent on Legonigma, an interesting 500 point challenge based on two renders of a Lego cryptography gadget.&lt;/p&gt;</description>
        <content:encoded>&lt;![CDATA[&lt;p&gt;I recently participated in Samsung&amp;rsquo;s &lt;a href=&#34;https://ctftime.org/event/1715/&#34;&gt;Hacker&amp;rsquo;s Playground CTF&lt;/a&gt; with &lt;a href=&#34;https://wrecktheline.com/&#34;&gt;Wreck The Line&lt;/a&gt;. We finished with 1592 points, in 26th place of 1075 teams. Most of my time was spent on Legonigma, an interesting 500 point challenge based on two renders of a Lego cryptography gadget.&lt;/p&gt;
&lt;h2 id=&#34;the-challenge&#34;&gt;The Challenge&lt;/h2&gt;
&lt;p&gt;&lt;img src=&#34;../../../images/legonigma/Legonigma_Front.jpg&#34; alt=&#34;Front image of Lego gadget&#34;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../../../images/legonigma/Legonigma_Back.jpg&#34; alt=&#34;Rear image of Lego gadget&#34;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../../../images/legonigma/Legonigma_Instructions.jpg&#34; alt=&#34;Instruction image, showing that the 36 gear teeth are A-Z then 0-9 clockwise, green gears are input, and yellow are output&#34;&gt;&lt;/p&gt;
&lt;p&gt;Decipher ciphertext:
&lt;code&gt;59x8wl9pjsava3grn0il79aoq307f20a6huc3xnos289cd8xv1fn2znuoa2bq8959chbktwfow8c3azpvo3c59jz4&lt;/code&gt;&lt;/p&gt;
&lt;h2 id=&#34;first-impressions&#34;&gt;First Impressions&lt;/h2&gt;
&lt;p&gt;Cool!&lt;/p&gt;
&lt;p&gt;I had a limited selection of possible parts, assuming it was built with production Lego pieces. The only moving parts were gears and a differential, so I suspected the relationships between input and outputs were just a series of ratios.&lt;/p&gt;
&lt;p&gt;Why were there three outputs? Maybe it produced 3 ciphertext characters per plaintext character? No, the ciphertext was 89 characters total, which isn&amp;rsquo;t divisible by 3&amp;hellip; I must need to guess the order?&lt;/p&gt;
&lt;h2 id=&#34;pieces-in-play&#34;&gt;Pieces in Play&lt;/h2&gt;
&lt;p&gt;Using the images and information from a &lt;a href=&#34;https://themomentmakers.org/2019/09/26/gears-types-of-gears/&#34;&gt;blog post&lt;/a&gt; about Lego gears I listed the pieces I might face, by type, tooth count, and features:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Regular gears (no bevel)
&lt;ul&gt;
&lt;li&gt;8 (axle)&lt;/li&gt;
&lt;li&gt;16 (axle and small spaces)&lt;/li&gt;
&lt;li&gt;24 (axle and four round post holes)&lt;/li&gt;
&lt;li&gt;40 (axle and a bunch of axle and post holes)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Double Bevel
&lt;ul&gt;
&lt;li&gt;12 (axle)&lt;/li&gt;
&lt;li&gt;20 (axle, spaces)&lt;/li&gt;
&lt;li&gt;28 (axle and four post holes)&lt;/li&gt;
&lt;li&gt;36 (axle plus two posts and two axles)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Differential
&lt;ul&gt;
&lt;li&gt;Three identical single-bevel inside, so ratios don&amp;rsquo;t matter&lt;/li&gt;
&lt;li&gt;Outside: 16 and 24 tooth&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;attempt-one-procedural&#34;&gt;Attempt One: Procedural&lt;/h2&gt;
&lt;p&gt;My first instinct was to follow the gearing through, noting each number of teeth:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;36 (input, green)
hard link to 20 (grey)
rotates 12 (blue)
rotates 20 (grey)
splits to A

A1:
rotates 12 (blue)
hard link to 36 (grey)
rotates 12 (blue)
hard link to 36 (yellow, out1)

A2:
hard link to 28 (blue)
...
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I intended to turn this into a simple procedure that would just do the math for each step, keeping track of the angle of each gear, but I realized there&amp;rsquo;s a much easier way to simplify it&amp;hellip;&lt;/p&gt;
&lt;h2 id=&#34;attempt-two-mathematical&#34;&gt;Attempt Two: Mathematical&lt;/h2&gt;
&lt;p&gt;If I pretend I&amp;rsquo;ve turned the input one full rotation clockwise, how does each gear – and therefore each output – behave?&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;input 1 CW
grey 1 CW
blue (irrelevant) CCW
grey 1 CW (split A)

A1 (left):
blue 20/12=5/3 CCW
grey 5/3 CCW
blue 5 CW
yellow 5 CW (out1)

A2:
blue (irrelevant) CCW
grey 1 CW
blue 20/12=5/3 CCW (split B)

...
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Following this through, I arrived at the following ratios between input and output:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;1:5 for the front left output&lt;/li&gt;
&lt;li&gt;1:5/3 for the front right output&lt;/li&gt;
&lt;li&gt;1:38/9 for the rear output&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Having made up simple ciphers in the past, after finding the 1:5 output I was kind of expecting the others to also be prime numbers. Oh well, the math doesn&amp;rsquo;t lie&amp;hellip; Right?&lt;/p&gt;
&lt;p&gt;But after writing some python code to show outputs for every possible first couple characters of input, I couldn&amp;rsquo;t get the outputs to match the ciphertext. Notably, for lots of valid inputs, the rear and right-side outputs sat between letters. Unless this machine would be provided to users with specific instructions, that seemed odd.&lt;/p&gt;
&lt;p&gt;I spent a long time chasing guesses about what those instructions might be - &amp;ldquo;Keep turning until the outputs are all exactly at a tooth/letter&amp;rdquo;? &amp;ldquo;Keep turning until the one output for this step is exactly at a tooth/letter&amp;rdquo;? After some rubber duck debugging and a gentle nudge from the challenge author, I re-examined my understanding of the machine, but still couldn&amp;rsquo;t find anything wrong.&lt;/p&gt;
&lt;h2 id=&#34;the-nuclear-option&#34;&gt;The Nuclear Option&lt;/h2&gt;
&lt;p&gt;If I couldn&amp;rsquo;t logic it out, I&amp;rsquo;d try to rebuild the device&amp;rsquo;s mechanics using a tool.&lt;/p&gt;
&lt;p&gt;There were several relatively simple tools for Lego gear ratios, but besides them being a bit difficult to build a complex machine in, it didn&amp;rsquo;t seem they would be able to handle the differential, or possibly even the splits.&lt;/p&gt;
&lt;p&gt;I ended up finding the Technic Brick Power &lt;a href=&#34;https://technicbrickpower.com/tools/gearing_ratio_calculator&#34;&gt;Gearing Ratio Calculator&lt;/a&gt;, which seemed to do exactly what I needed! &amp;hellip;when provided with a &amp;ldquo;Lego Technic .ldr file&amp;rdquo;. Okay, it seems I need to use something like &lt;a href=&#34;https://www.leocad.org/&#34;&gt;LeoCAD&lt;/a&gt; to build that&amp;hellip;&lt;/p&gt;
&lt;p&gt;A lot of twiddling and building later, I had reproduced the machine:
&lt;img src=&#34;../../../images/legonigma/sim-wrong.jpg&#34; alt=&#34;Image of the machine in LeoCAD&#34;&gt;&lt;/p&gt;
&lt;p&gt;But when I loaded it into the gearing ratio tool, attaching a motor, and running it, the entire model turned red, indicating a jammed motor.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../../../images/legonigma/sim-angry.png&#34; alt=&#34;Screenshot of the ratio calculator with all parts colored red&#34;&gt;&lt;/p&gt;
&lt;p&gt;I assumed the tool just didn&amp;rsquo;t know how to handle the differential, and removed the gear before the rear output to let both sides of that branch run separately, then combined the adjacent gears&amp;rsquo; motion myself. The results matched my original calculations perfectly, and I was lost again.&lt;/p&gt;
&lt;p&gt;After many more lines of code and attempts to figure out how the machine would be used, I eventually arrived at a realization: In a row of three gears, turning the first clockwise at 1 RPM and the third clockwise at 2 RPM does not cause the middle one to rotate counterclockwise at 3 RPM. Don&amp;rsquo;t ask how I had arrived at my original understanding – I do not know, and it is as obviously wrong in retrospect as it is to you. The resulting conclusion was that the branch through the front-right output and the differential was not modifying the ratio of the rear output. The simulation was correct. My understanding of the machine actually &lt;em&gt;was&lt;/em&gt; a deadlock.&lt;/p&gt;
&lt;p&gt;I stared at the challenge&amp;rsquo;s renders more, and eventually found the problem: There was in fact no motion going &lt;em&gt;through&lt;/em&gt; the front-right output&amp;rsquo;s axle, and the direction of control through the differential is the opposite of what I thought.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../../../images/legonigma/Legonigma_Front.jpg&#34; alt=&#34;Front view of Lego gadget&#34;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../../../images/legonigma/sim-wrong.jpg&#34; alt=&#34;Front view of incorrect recreation&#34;&gt;&lt;/p&gt;
&lt;p&gt;See it? I sure didn&amp;rsquo;t.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../../../images/legonigma/Legonigma_Front-line.jpg&#34; alt=&#34;Front view of Lego gadget with a line highlighting the difference&#34;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../../../images/legonigma/sim-wrong-line.jpg&#34; alt=&#34;Front view of incorrect recreation with a line highlighting the difference&#34;&gt;&lt;/p&gt;
&lt;p&gt;After some logic, some trial-and error, and a lot of staring at close-ups of small details in the original render, I moved a few elements around. Here&amp;rsquo;s a bottom view of the change, with the front-right output gear at the top center:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../../../images/legonigma/sim-wrong-bottom.jpg&#34; alt=&#34;Bottom view of incorrect recreation&#34;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../../../images/legonigma/sim-bottom.jpg&#34; alt=&#34;Bottom view of corrected recreation&#34;&gt;&lt;/p&gt;
&lt;p&gt;Then I loaded the amended model into the simulator:&lt;/p&gt;
&lt;video class=&#34;video-animation&#34; autoplay loop muted playsinline aria-label=&#34;Corrected model in the gearing ratio calculator&#34;&gt;
    &lt;source src=&#34;../../../images/legonigma/sim-fixed.mp4&#34; type=&#34;video/mp4&#34;&gt;
    
    Your browser does not seem to support this video.
&lt;/video&gt;

&lt;p&gt;And got some much nicer ratios for the outputs&amp;hellip;&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../../../images/legonigma/sim-ratios.png&#34; alt=&#34;Screenshot of sim info panel for output gears, showing ratios of 1:5, 1:-7, and 1:13&#34;&gt;&lt;/p&gt;
&lt;p&gt;So I updated my code to use these much more reasonable ratios, aaaaand&amp;hellip; No valid input produced an output matching the first three characters of ciphertext.&lt;/p&gt;
&lt;h2 id=&#34;reaching-further&#34;&gt;Reaching further&lt;/h2&gt;
&lt;p&gt;Lacking any idea how the outputs were meant to be read, I figured it was time to investigate the challenge name&amp;rsquo;s call-out to the German Enigma machine to look for hints.&lt;/p&gt;
&lt;p&gt;Enigma&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Known-plaintext attack&lt;/li&gt;
&lt;li&gt;Not ECB (advances rotors by each character)&lt;/li&gt;
&lt;li&gt;Random mapping in each code wheel and on plugboard&lt;/li&gt;
&lt;li&gt;Never encrypted a letter to itself&lt;/li&gt;
&lt;li&gt;Decryption == encryption (if a-&amp;gt;r, r-&amp;gt;a)&lt;/li&gt;
&lt;li&gt;Key is rotor selection, rotor position, reflector position, plugboard config&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This machine&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;No known-plaintext available&lt;/li&gt;
&lt;li&gt;ECB (all rotors end up back at A when input is rotated back to A)&lt;/li&gt;
&lt;li&gt;Probably not enough ciphertext to do statistics for random mappings&lt;/li&gt;
&lt;li&gt;Encrypts A to A,A,A&lt;/li&gt;
&lt;li&gt;How to decrypt, besides &amp;ldquo;turn input til all three outputs match your ciphertext block&amp;rdquo;?&lt;/li&gt;
&lt;li&gt;If there&amp;rsquo;s a key, how is it configured? 4 pointer positions * 4 rotors * 6 output rotor orders = 96 possibilities?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Maybe I was missing an instruction like &amp;ldquo;Advance the input by n teeth, where n is the index of the next plaintext character&amp;rdquo;? I couldn&amp;rsquo;t figure out how to turn the three outputs into a ciphertext.&lt;/p&gt;
&lt;h2 id=&#34;feeling-dumb-again&#34;&gt;Feeling Dumb (Again)&lt;/h2&gt;
&lt;p&gt;There&amp;rsquo;s no galaxy brain instructions, I just needed read the outputs in a particular order, trivially discovered. 1:13 first, then 1:5, then 1:7.&lt;/p&gt;
&lt;p&gt;I achieved the second solve for Legonigma, for 460 points, 17 minutes after the first team.
&lt;code&gt;SCTF{th3w0rld1sadang3rou5placeno7becau5e0fth0sewh0do3v1lbutbecau5eofth053wh0l00konandd0n0th1ng}&lt;/code&gt;
(&amp;ldquo;The world is a dangerous place, not because of those who do evil, but because of those who look on and do nothing&amp;rdquo;)&lt;/p&gt;
&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;I wish the ratios hadn&amp;rsquo;t been whole numbers, so the &amp;ldquo;no reversing&amp;rdquo; instruction meant something!&lt;/p&gt;
&lt;p&gt;Thanks to &amp;ldquo;Your expectations are reasonable&amp;rdquo; Cybrosis for a really neat challenge and a couple nudges, rebuilding the machine was fun.
Thanks also to Samsung for organizing this event, and my teammates at WreckTheLine for all of their work and for putting up with my rubber ducking.&lt;/p&gt;
&lt;h2 id=&#34;downloads&#34;&gt;Downloads&lt;/h2&gt;
&lt;p&gt;My Python code, including a lot of commented-out wrong attempts, and overbuilt since I originally expected one full input rotation to not return to the starting state: &lt;a href=&#34;https://sec.gd/blog/en/posts/legonigma/legonigma.py&#34;&gt;legonigma.py&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The .ldr model of the machine I built in LeoCAD: &lt;a href=&#34;https://sec.gd/blog/en/posts/legonigma/legonigma.ldr&#34;&gt;legonigma.ldr&lt;/a&gt;&lt;/p&gt;]]></content:encoded>
        <dc:creator>mal</dc:creator>
        <media:content url="https://sec.gd/blog/images/legonigma/Legonigma_Front.jpg" medium="image"><media:title type="html">featured image</media:title></media:content>
        
        <media:content url="https://sec.gd/blog/images/legonigma/Legonigma_Front.jpg" medium="image"><media:title type="html">meta image</media:title></media:content>
        
          
            
              <category>hacker&#39;s playground</category>
            
          
            
              <category>crypto</category>
            
          
            
              <category>misc</category>
            
          
        
        
          
            
              <category>ctf</category>
            
          
        
        
      </item>
    
      <item>
        <title>ImaginaryCTF 2021</title>
        <link>https://sec.gd/blog/en/posts/imaginaryctf-2021/</link>
        <pubDate>Tue, 27 Jul 2021 04:00:00 +0000</pubDate>
        <author>mal@sec.gd (mal)</author>
        <atom:modified>Tue, 27 Jul 2021 04:00:00 +0000</atom:modified>
        <guid>https://sec.gd/blog/en/posts/imaginaryctf-2021/</guid>
        <description>This weekend I participated in &lt;a href=&#34;https://2021.imaginaryctf.org/&#34;&gt;ImaginaryCTF 2021&lt;/a&gt; with &lt;a href=&#34;https://wrecktheline.com/&#34;&gt;WreckTheLine&lt;/a&gt;. We finished third out of 1018 entrants, the final team to complete all 55 challenges and hit 11330 points, missing second place by 3.5 minutes. Here are my writeups for System Hardening 5 and New Technology.</description>
        <content:encoded>&lt;![CDATA[&lt;p&gt;&lt;img src=&#34;../../../images/imaginaryctf-2021/ictf-2021-banner.jpg&#34; alt=&#34;ImaginaryCTF 2021 Banner&#34;&gt;&lt;/p&gt;
&lt;p&gt;This weekend I participated in &lt;a href=&#34;https://2021.imaginaryctf.org/&#34;&gt;ImaginaryCTF 2021&lt;/a&gt;
with &lt;a href=&#34;https://wrecktheline.com/&#34;&gt;WreckTheLine&lt;/a&gt;. We finished third out of 1018
entrants, the final team to complete all 55 challenges and hit 11330 points,
missing second place by 3.5 minutes.&lt;/p&gt;
&lt;h2 id=&#34;system-hardening-5&#34;&gt;System Hardening 5&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;&amp;ldquo;CyberPatriot but run by roo fanatics&amp;hellip; What could go wrong&amp;hellip;&amp;rdquo;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;At 450 points, System Hardening 5 was in the highest value category of
challenges. It was in the pattern of CyberPatriot, where teams download and
run a VM, find and fix all of the vulnerabilities. A scoring engine checks the
scored items every minute or so and reports to the scoreboard.&lt;/p&gt;
&lt;p&gt;As with CyberPatriot, we start with the &lt;a href=&#34;https://system-hardening-5.chal.imaginaryctf.org/readme&#34;&gt;readme&lt;/a&gt;.
The major constrants today are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;No updates at all. Makes sense, that&amp;rsquo;s time-consuming and uninteresting.&lt;/li&gt;
&lt;li&gt;Critical services: Remote desktop, print spooler.&lt;/li&gt;
&lt;li&gt;Don&amp;rsquo;t disable SMB or the scoring engine may break&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;forensics&#34;&gt;Forensics&lt;/h3&gt;
&lt;p&gt;Let&amp;rsquo;s start&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt; with the Forensics questions, as the readme says, so we don&amp;rsquo;t
accidentally destroy artifacts we&amp;rsquo;ll need to answer them.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;An [sic] user on this system was compromised, allowing rooReaper to break in. What is
the username of this user?&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Well, let&amp;rsquo;s look around. Event log? Exploit artifacts? Let&amp;rsquo;s check this other
file on the desktop first, &lt;code&gt;text-messages-from-mom.txt.txt&lt;/code&gt; [sic].&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;MOMtotallynotrooreaper:&lt;/strong&gt; hi roo! this is definitely mom here&lt;br&gt;
&lt;strong&gt;rooYay:&lt;/strong&gt; oh hi mom didnt see you there all too well&lt;br&gt;
&lt;strong&gt;MOMtotallynotrooreaper:&lt;/strong&gt; ?&lt;br&gt;
&lt;strong&gt;rooYay:&lt;/strong&gt; nvm, what did you text me for&lt;br&gt;
&lt;strong&gt;rooYay:&lt;/strong&gt; and is this a new number? i dont see the message history&lt;br&gt;
&lt;strong&gt;MOMtotallynotrooreaper:&lt;/strong&gt; uhh yea this is a new number&lt;br&gt;
&lt;strong&gt;rooYay:&lt;/strong&gt; oh ok&lt;br&gt;
&lt;strong&gt;MOMtotallynotrooreaper:&lt;/strong&gt; can you disable your firewall? and enable smb pls and disable your antivirus&lt;br&gt;
&lt;strong&gt;rooYay:&lt;/strong&gt; ok whatever you say mom&amp;hellip;&lt;br&gt;
&lt;strong&gt;rooYay:&lt;/strong&gt; ill look up some tutorials&lt;br&gt;
&lt;strong&gt;MOMtotallynotrooreaper:&lt;/strong&gt; NO DONT LOOK AT TUTORIALS&lt;br&gt;
&lt;strong&gt;rooYay:&lt;/strong&gt; ok i wont what do i do&lt;br&gt;
&lt;strong&gt;MOMtotallynotrooreaper:&lt;/strong&gt; ill show you&lt;br&gt;
&lt;strong&gt;MOMtotallynotrooreaper:&lt;/strong&gt; btw what is rooPOG&amp;rsquo;s password&lt;br&gt;
&lt;strong&gt;MOMtotallynotrooreaper:&lt;/strong&gt; i heard he loves sharing&lt;br&gt;
&lt;strong&gt;rooYay:&lt;/strong&gt; its just password1337 nothing fancy&lt;br&gt;
&lt;strong&gt;MOMtotallynotrooreaper:&lt;/strong&gt; thanks!&lt;br&gt;
&amp;hellip;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Looks like rooYay fell for the classic &amp;ldquo;hi this is your mother&amp;rdquo; phish, and gave
out &lt;strong&gt;rooPOG&lt;/strong&gt;&amp;rsquo;s password.&lt;/p&gt;
&lt;div class=&#34;alert alert-info&#34; role=&#34;alert&#34; data-dir=&#34;ltr&#34;&gt;Forensics Question 1 correct - 7 points&lt;/div&gt;
&lt;p&gt;That also gives us the answer to the next forensics question:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;What is the password of the compromised user from the previous question?&lt;/p&gt;&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;password1337&lt;/strong&gt; nothing fancy&lt;/p&gt;&lt;/blockquote&gt;
&lt;div class=&#34;alert alert-info&#34; role=&#34;alert&#34; data-dir=&#34;ltr&#34;&gt;Forensics Question 2 correct - 7 points&lt;/div&gt;
&lt;p&gt;The other forensics questions require some research.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;What is the CVE ID of the vulnerability that allowed rooReaper to escalate
privileges?&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;I poked around in rooPOG&amp;rsquo;s home directory for a bit, finding &lt;code&gt;xconsole.exe&lt;/code&gt; and
&lt;code&gt;vlib.dll&lt;/code&gt; in &lt;code&gt;Downloads\foobar&lt;/code&gt;. The latter was detected as Win32/Mamson.A!ac,
which doesn&amp;rsquo;t obviously use any exploits. I enabled Windows Defender and
started a scan, and before I had found anything in the event viewer, it had
found &lt;code&gt;C:\temp\PrintNightmareLPE.exe&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Print Nightmare, &lt;a href=&#34;https://msrc.microsoft.com/update-guide/vulnerability/CVE-2021-34527&#34;&gt;CVE-2021-34527&lt;/a&gt;,
is a recent vulnerability that allows a remote attacker to install a malicious
printer driver configuration DLL to gain arbitrary code execution as SYSTEM. A
variant, &lt;a href=&#34;https://msrc.microsoft.com/update-guide/vulnerability/CVE-2021-1675&#34;&gt;&lt;strong&gt;CVE-2021-1675&lt;/strong&gt;&lt;/a&gt;,
is useful for local exploitation, and was accepted as the answer.&lt;/p&gt;
&lt;p&gt;Both of these drop the payload, in this case &lt;code&gt;vlib.dll&lt;/code&gt;, in
&lt;code&gt;C:\Windows\System32\spool\drivers\x64\3\&lt;/code&gt;, where Defender found it alongside
&lt;code&gt;reverse_64bit.dll&lt;/code&gt; which it detected as Win64/Meterpreter.B. I removed the
whole folder, along with &lt;code&gt;C:\temp\&lt;/code&gt; and the contents of rooPOG&amp;rsquo;s Downloads
folder.&lt;/p&gt;
&lt;div class=&#34;alert alert-info&#34; role=&#34;alert&#34; data-dir=&#34;ltr&#34;&gt;Forensics Question 3 correct - 7 points&lt;br&gt;
Removed privilege escalation payload - 5 points&lt;/div&gt;
&lt;p&gt;The final forensics question seemed like a steganography problem, but referred
to another challenge in the CTF:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The background image on the Desktop contains a secret message. What is it?&lt;br&gt;
HINT: It&amp;rsquo;s related to another challenge in this CTF, a reversing challenge.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;The wallpaper was &lt;code&gt;background.png&lt;/code&gt; in rooYay&amp;rsquo;s Pictures folder. It consisted of
a grid of tiles, in a repeating pattern &lt;code&gt;Axxxx&lt;/code&gt;, where there were 3 options for
&lt;code&gt;x&lt;/code&gt;. No obvious pattern was shown by &lt;code&gt;stegsolve&lt;/code&gt;, and it wasn&amp;rsquo;t clear how to
decode information in the tile pattern. I put it aside until a teammate,
JaGoTu, solved &lt;code&gt;roolang&lt;/code&gt;, which seemed potentially-related. Sure enough:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;JaGoTu: roolang was just a vm that was calculating fibonacii very slowly&lt;br&gt;
JaGoTu: can you send the raw png somewhere?&lt;br&gt;
JaGoTu: cause the roolang basically runs png files&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;They ran their roolang solution on the PNG, and sent back the output:
&lt;strong&gt;Hello, and welcome to the roos&amp;rsquo; server!&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&#34;alert alert-info&#34; role=&#34;alert&#34; data-dir=&#34;ltr&#34;&gt;Forensics Question 4 correct - 7 points&lt;/div&gt;
&lt;h3 id=&#34;pups-not-the-fun-kind&#34;&gt;PUPs (Not the Fun Kind)&lt;/h3&gt;
&lt;p&gt;With the forensics questions out of the way, let&amp;rsquo;s continue through the readme.
We have a list of needed services and software, so let&amp;rsquo;s remove anything that&amp;rsquo;s
not on it, starting with the faux-Clippy in the corner of the screen.&lt;/p&gt;
&lt;p&gt;First, the Startup folder for All Users in
&lt;code&gt;C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\&lt;/code&gt;.
Two shortcuts:\&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;chksec - Shortcut.lnk&lt;/code&gt; to &lt;code&gt;C:\Windows\System32\chksec.exe&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;essential - Shortcut.lnk&lt;/code&gt; to &lt;code&gt;C:\Windows\System32\essential.bat&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Delete the shortcuts, kill the processes, delete the Clippy executable.
&lt;code&gt;essential.bat&lt;/code&gt; printed some ascii art text, copied itself to the current
user&amp;rsquo;s start menu Startup folder, opened a
&lt;a href=&#34;https://www.youtube.com/watch?v=xvFZjo5PgG0&#34;&gt;video&lt;/a&gt;, and then &lt;code&gt;pause&lt;/code&gt;d.
Delete the batch file from System32 and from rooYay&amp;rsquo;s
&lt;code&gt;%AppData%\Microsoft\Windows\Start Menu\Programs\Startup\&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;alert alert-info&#34; role=&#34;alert&#34; data-dir=&#34;ltr&#34;&gt;Removed PUP Clippy - 3 points&lt;br&gt;
Removed rickroll malware - 4 points&lt;/div&gt;
&lt;h3 id=&#34;installed-programs&#34;&gt;Installed Programs&lt;/h3&gt;
&lt;p&gt;There&amp;rsquo;s a couple shortcuts on the desktop to software that wasn&amp;rsquo;t mentioned as
required in the readme, so let&amp;rsquo;s remove those. I replaced Chrome with Firefox
portable, since the roos prefer IE and I very much do not. Nothing else in
add/remove programs looked relevant.&lt;/p&gt;
&lt;div class=&#34;alert alert-info&#34; role=&#34;alert&#34; data-dir=&#34;ltr&#34;&gt;Removed unauthorized program Minecraft Launcher - 3 points&lt;br&gt;
Removed unauthorized program SuperAntiSpyware - 3 points&lt;/div&gt;
&lt;p&gt;I also looked through the running processes, but nothing else there raised
suspicion.&lt;/p&gt;
&lt;h3 id=&#34;users&#34;&gt;Users&lt;/h3&gt;
&lt;p&gt;Next, let&amp;rsquo;s deal with users, which is easiest from
&lt;code&gt;compmgmt.msc&lt;/code&gt;/&lt;code&gt;lusrmgr.msc&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create &lt;code&gt;roocursion&lt;/code&gt; as requested in the readme&lt;/li&gt;
&lt;li&gt;Rename the local administrator account as requested (can be done here or in
group policy)&lt;/li&gt;
&lt;li&gt;Make sure nobody unauthorized is in Administrators or other privileged groups&lt;/li&gt;
&lt;li&gt;Make sure no non-builtin users exist who aren&amp;rsquo;t mentioned, poking through
their home folders before deleting&lt;/li&gt;
&lt;li&gt;Disable the Guest account, and rename for good measure&lt;/li&gt;
&lt;li&gt;Change the password for all users&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I&amp;rsquo;ll mention here that CyberPatriot often uses significantly outdated best
practices and ignores how things would be done in the real world, and we also
don&amp;rsquo;t know what this challenge will score on, so a lot of the things I check
and changes I make to this machine are excessive, paranoid, annoying, or
otherwise just weird. If we lose points for something we can easily undo the
change.&lt;/p&gt;
&lt;div class=&#34;alert alert-info&#34; role=&#34;alert&#34; data-dir=&#34;ltr&#34;&gt;Removed unauthorized user rooReaper - 3 points&lt;br&gt;
Removed unauthorized user rooDevil - 3 points&lt;br&gt;
Removed unauthorized user rooRage - 3 points&lt;br&gt;
User rooFrozen is not an administrator - 3 points&lt;br&gt;
User roocursion has been created - 3 points&lt;br&gt;
Administrator account renamed - 3 points&lt;br&gt;
Guest account is disabled - 4 points&lt;/div&gt;
&lt;h3 id=&#34;services-and-firewall&#34;&gt;Services and Firewall&lt;/h3&gt;
&lt;p&gt;Interspersed with everything else, I poke around &lt;code&gt;services.msc&lt;/code&gt; and the control
panel to make sure everything is sane. Enable the firewall
MOMtotallynotrooreaper told us to disable, then make sure there&amp;rsquo;s no
nonstandard or scary rules enabled. Enable cloud protection and sample
sumbission for Defender, make sure the scan finished. Right click My Computer
and click Properties, check $PATH and other environment variables for anything
weird, make sure Data Execution Prevention is enabled for all applications, and
disable NetBIOS.&lt;/p&gt;
&lt;div class=&#34;alert alert-info&#34; role=&#34;alert&#34; data-dir=&#34;ltr&#34;&gt;Windows Firewall is enabled - 5 points&lt;/div&gt;
&lt;h3 id=&#34;group-policy&#34;&gt;Group Policy&lt;/h3&gt;
&lt;p&gt;Before I forget, let&amp;rsquo;s make sure we&amp;rsquo;ve mitigated Print Nightmare. The
&lt;a href=&#34;https://msrc.microsoft.com/update-guide/vulnerability/CVE-2021-34527&#34;&gt;MSRC post&lt;/a&gt;
about it recommends updating (oops, can&amp;rsquo;t), disabling the print spooler (oops,
can&amp;rsquo;t), or disabling inbound remote printing with Group Policy.&lt;/p&gt;
&lt;p&gt;I fire up &lt;code&gt;gpedit.msc&lt;/code&gt;, open Computer Configuration -&amp;gt;
Windows Settings -&amp;gt; &amp;hellip; Where&amp;rsquo;s Security Settings?&lt;/p&gt;
&lt;p&gt;This is where I spent about half my time on this challenge. When launching
&lt;code&gt;gpedit.msc&lt;/code&gt;, Security Settings was missing. &lt;code&gt;secpol.msc&lt;/code&gt; would show the tree
starting at Windows Settings instead of Security Settings, and also omit the
latter. Many answers on the internet offered a simple &lt;code&gt;regsvr32 wsecedit.dll&lt;/code&gt;,
which doesn&amp;rsquo;t work as the DLL doesn&amp;rsquo;t have the correct entrypoints for that.
This is where I ran &lt;code&gt;dism /online /cleanup-image /restorehealth&lt;/code&gt; and
&lt;code&gt;sfc /scannow&lt;/code&gt;, which didn&amp;rsquo;t find any problems.&lt;/p&gt;
&lt;p&gt;I never did figure out what was done to break that, as I eventually gave up and
tried importing an exported policy, and later started setting the policy
registry entries by hand. After a while, I opened the mmc snapin again, and
Security Settings was there!&lt;/p&gt;
&lt;p&gt;It seems that it&amp;rsquo;s only broken for the rooYay user, and after setting UAC to
require a password, I was unintentionally elevating as rooAstro, for whom it
worked correctly. Something in my profile was breaking it. Some windows
LD_LIBRARY_PATH type thing? Something in HKEY_CURRENT_USER? It didn&amp;rsquo;t directly
affect security, so I put it aside again.&lt;/p&gt;
&lt;p&gt;From there, I could much more easily continue with group policy, basically just
going through every option in Security Settings -&amp;gt; Account Policies and Local
Policies and some folders in Administrative Templates -&amp;gt; Windows Settings,
setting everything to the most paranoid sane option.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Remember 24 passwords&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;60 day maximum password age&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;10 day minimum password age&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;14 character minimum length&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Must meet complexity requirements&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;No reversible encryption&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;15 minute account lockout duration&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;10 attempt lockout threshold&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;15 minute counter reset timer&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Enable all auditing&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Go through User Rights Assignment and restrict everything as much as possible&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Hey, why is &lt;code&gt;Everyone&lt;/code&gt; allowed to take ownership of files??&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You know what, let&amp;rsquo;s just disable the Administrator account&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;I don&amp;rsquo;t like Microsoft account signin&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;More audit everything&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Prevent users from installing printer drivers (well&amp;hellip; try to)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Restrict CD-ROM access to locally logged-on users&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Require CTRL+ALT+DEL, force inactivity limit, require strong encryption&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You get the idea.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;alert alert-info&#34; role=&#34;alert&#34; data-dir=&#34;ltr&#34;&gt;Everyone is not allowed to take ownership of files and other objects - 5 points&lt;/div&gt;
&lt;h3 id=&#34;critical-services&#34;&gt;Critical Services&lt;/h3&gt;
&lt;p&gt;And let&amp;rsquo;s not forget to secure our critical services. The MSRC Print Nightmare
article points me to Administrative Templates -&amp;gt; Printers to disable &amp;ldquo;Allow
Print Spooler to accept client connections&amp;rdquo;. There have been a few RDP
vulnerabilities, but none with straightforward workarounds besides patching, so
let&amp;rsquo;s just be sure to flip on all of the RDP server security policies. Lastly,
we weren&amp;rsquo;t disallowed from disabling old versions of SMB, so use the powershell
command in the
&lt;a href=&#34;https://docs.microsoft.com/en-us/windows-server/storage/file-server/troubleshoot/detect-enable-and-disable-smbv1-v2-v3&#34;&gt;docs&lt;/a&gt;,
to check for SMBv1 and see it&amp;rsquo;s already disabled.&lt;/p&gt;
&lt;div class=&#34;alert alert-info&#34; role=&#34;alert&#34; data-dir=&#34;ltr&#34;&gt;Inbound remote printing is disabled (PrintNightmare mitigation) - 9 points&lt;br&gt;
Remote Desktop uses network level authentication - 4 points&lt;/div&gt;
&lt;h3 id=&#34;other-stuff&#34;&gt;Other Stuff&lt;/h3&gt;
&lt;p&gt;In an advanced challenge, in addition to &lt;code&gt;sfc&lt;/code&gt; and &lt;code&gt;dism&lt;/code&gt; to look for
&amp;ldquo;creatively modified&amp;rdquo; system files, &lt;code&gt;hijackthis&lt;/code&gt; can be helpful. In case
of a well-disguised network backdoor, it&amp;rsquo;s also good to check open sockets.&lt;/p&gt;
&lt;h3 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;And with that, I had 91 points, 20/21 items, and the flag appeared in the score
report. There was one scored item I never found, worth 9 points. I&amp;rsquo;ll be
waiting for a writeup from tirefire, the only person with 100 points, to see
what I missed!&lt;/p&gt;
&lt;div class=&#34;alert alert-success&#34; role=&#34;alert&#34; data-dir=&#34;ltr&#34;&gt;Unique ID: &lt;code&gt;8edd464b&lt;/code&gt;&lt;br&gt;
Flag: &lt;code&gt;ictf{th4nks_s0_much_f0r_s3cur1ng_0ur_s3rver!_h3r3s_4_fl4g!!!}&lt;/code&gt;&lt;/div&gt;
&lt;h3 id=&#34;update&#34;&gt;Update&lt;/h3&gt;
&lt;p&gt;First, Eth007, one of the challenge authors, let me know that the last scored
item I couldn&amp;rsquo;t find was
&lt;a href=&#34;https://docs.microsoft.com/en-us/windows-server/security/credentials-protection-and-management/configuring-additional-lsa-protection&#34;&gt;LSA protection&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Second, thank you to the iCTF team for selecting this as a prize-winning writeup!&lt;/p&gt;
&lt;h2 id=&#34;new-technology&#34;&gt;New Technology&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;&amp;ldquo;If it&amp;rsquo;s not Windows New Technology, what else could NT stand for?&amp;rdquo;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This was a 300pt cryptography challenge in the form of a &lt;a href=&#34;https://imaginaryctf.org/r/3204-new_technology.py&#34;&gt;python
script&lt;/a&gt;.
It generates a random key consisting of 5 tuples, each a 512-bit prime &lt;code&gt;p&lt;/code&gt; and
an integer exponent $1 \le e &amp;lt; 4$.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;gen&lt;/span&gt;():
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    private &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; []
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; _ &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; range(&lt;span style=&#34;color:#ae81ff&#34;&gt;5&lt;/span&gt;):
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        p &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; getPrime(&lt;span style=&#34;color:#ae81ff&#34;&gt;512&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        e &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; getRandomRange(&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;4&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        private&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;append((p, e))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; private, normalize(private)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The public key is derived by the &lt;code&gt;normalize()&lt;/code&gt; function, which multiplies
together &lt;code&gt;p**e&lt;/code&gt; for each private key component.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;normalize&lt;/span&gt;(fac):
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    n &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; p, e &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; fac:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        n &lt;span style=&#34;color:#f92672&#34;&gt;*=&lt;/span&gt; p&lt;span style=&#34;color:#f92672&#34;&gt;**&lt;/span&gt;e
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; n
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Since these are 512-bit primes, the resulting public key isn&amp;rsquo;t easy to factor.&lt;/p&gt;
&lt;p&gt;The private key is put through the &lt;code&gt;deriv()&lt;/code&gt; function, which has a nested
loop based on &lt;code&gt;divs()&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;deriv&lt;/span&gt;(priv):
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    res &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; d1 &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; divs(priv):
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; d2 &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; divs(d1):
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            res &lt;span style=&#34;color:#f92672&#34;&gt;+=&lt;/span&gt; normalize(d2) &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; phi(d2) &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; phi(div(d1, d2))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; res
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;divs()&lt;/code&gt; takes the same &lt;code&gt;List[Set[prime: int, exponent: int], ...]&lt;/code&gt; private key
format and yields the cartesian product of them based on the range 0..e of
their exponents:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;divs&lt;/span&gt;(fac, pre&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;None&lt;/span&gt;):
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; pre &lt;span style=&#34;color:#f92672&#34;&gt;is&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;None&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        pre &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; []
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;not&lt;/span&gt; fac:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;yield&lt;/span&gt; pre
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;else&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        p, e &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; fac[&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;]
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; i &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; range(&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;, e &lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;):
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;yield from&lt;/span&gt; divs(fac[&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;:], pre &lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt; [(p, i)]
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; priv &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; [(&lt;span style=&#34;color:#ae81ff&#34;&gt;167&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;), (&lt;span style=&#34;color:#ae81ff&#34;&gt;149&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;)]
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; pprint(list(divs(priv)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;[[(&lt;span style=&#34;color:#ae81ff&#34;&gt;167&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;), (&lt;span style=&#34;color:#ae81ff&#34;&gt;149&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;)],
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; [(&lt;span style=&#34;color:#ae81ff&#34;&gt;167&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;), (&lt;span style=&#34;color:#ae81ff&#34;&gt;149&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;)],
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; [(&lt;span style=&#34;color:#ae81ff&#34;&gt;167&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;), (&lt;span style=&#34;color:#ae81ff&#34;&gt;149&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;)],
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; [(&lt;span style=&#34;color:#ae81ff&#34;&gt;167&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;), (&lt;span style=&#34;color:#ae81ff&#34;&gt;149&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;)],
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; [(&lt;span style=&#34;color:#ae81ff&#34;&gt;167&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;), (&lt;span style=&#34;color:#ae81ff&#34;&gt;149&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;)],
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; [(&lt;span style=&#34;color:#ae81ff&#34;&gt;167&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;), (&lt;span style=&#34;color:#ae81ff&#34;&gt;149&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;)]]
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;For each entry in this list, &lt;code&gt;d1&lt;/code&gt;, &lt;code&gt;deriv()&lt;/code&gt; again calls &lt;code&gt;divs()&lt;/code&gt;, and loops on
that &lt;code&gt;d2&lt;/code&gt;, adding &lt;code&gt;normalize(d2) * phi(d2) * phi(div(d1, d2))&lt;/code&gt; to a running
total.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;phi&lt;/span&gt;(fac):
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    res &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; p, e &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; fac:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;not&lt;/span&gt; e: &lt;span style=&#34;color:#66d9ef&#34;&gt;continue&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        res &lt;span style=&#34;color:#f92672&#34;&gt;*=&lt;/span&gt; (p&lt;span style=&#34;color:#f92672&#34;&gt;**&lt;/span&gt;(e &lt;span style=&#34;color:#f92672&#34;&gt;-&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;)) &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; (p &lt;span style=&#34;color:#f92672&#34;&gt;-&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; res
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;div&lt;/span&gt;(a, b):  &lt;span style=&#34;color:#75715e&#34;&gt;# a=d1, b=d2&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    b &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; dict(b)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    res &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; []
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; p, e &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; a:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;assert&lt;/span&gt; e &lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;=&lt;/span&gt; b[p]
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        res&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;append((p, e &lt;span style=&#34;color:#f92672&#34;&gt;-&lt;/span&gt; b[p]))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; res
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;At some point here things started to smell funny - we&amp;rsquo;re collecting the sum of
some math done on every divisor of every divisor&amp;hellip; Just for fun, let&amp;rsquo;s see how
this behaves when run all the way through with more manageable numbers, maybe
12 bits.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;gen_custom&lt;/span&gt;(count&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;5&lt;/span&gt;, size&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;512&lt;/span&gt;, max_exp&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt;):
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    private &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; []
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; _ &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; range(count):
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        p &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; getPrime(size)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        e &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; getRandomRange(&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;, max_exp&lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        private&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;append((p, e))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; private, normalize(private)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; priv, pub &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; gen_custom(&lt;span style=&#34;color:#ae81ff&#34;&gt;5&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;12&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; priv
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;[(&lt;span style=&#34;color:#ae81ff&#34;&gt;3251&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;), (&lt;span style=&#34;color:#ae81ff&#34;&gt;3863&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;), (&lt;span style=&#34;color:#ae81ff&#34;&gt;2917&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;), (&lt;span style=&#34;color:#ae81ff&#34;&gt;3761&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt;), (&lt;span style=&#34;color:#ae81ff&#34;&gt;3989&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;)]
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; pub
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;90459172118968888949999762493557&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; key &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; deriv(priv)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; key
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;8182861820449238390507452368725018700352715647046709310466512249&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; sage.all &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; factor(pub)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2917&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;^&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;3251&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;3761&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;^&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;3863&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;3989&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;^&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; factor(key)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2917&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;^&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;4&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;3251&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;^&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;3761&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;^&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;6&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;3863&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;^&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;3989&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;^&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;4&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you don&amp;rsquo;t have &lt;a href=&#34;https://sagemath.org/&#34;&gt;sagemath&lt;/a&gt; installed, you can also use
a handy dandy &lt;a href=&#34;https://www.alpertron.com.ar/ECM.HTM&#34;&gt;webassembly ECM factorization tool&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The factors of the public key aren&amp;rsquo;t surprising, that&amp;rsquo;s the exact math we used
to derive it from the private key, but possible to reverse since we used small
numbers. On the other hand, what&amp;rsquo;s up with the private key? Each factor
just has double the exponent? And since $x^2 * y^2 = (xy)^2$, and
$(x^3)^2 = x^6$&amp;hellip; Our private key is just the square of the public key??&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; key &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; pub&lt;span style=&#34;color:#f92672&#34;&gt;**&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;True&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Well then! Let&amp;rsquo;s assign those commented output values to variables, square the
public key, get a new AES instance for decrypting, and&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;pub &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;0x281ab467e16cdedb97a298249bdd334f0cc7d54177ed0946c04ec26da111&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;ciphertext &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; bytes&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;fromhex(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;d2463ccc52075674effbad1b1ea5ae9a9c8106f1...&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;key &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; pub&lt;span style=&#34;color:#f92672&#34;&gt;**&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;cipher &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; AES&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;new(
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    hashlib&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;sha256(str(key)&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;encode(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;utf-8&amp;#34;&lt;/span&gt;))&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;digest(),
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    AES&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;MODE_CBC,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    iv&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;b&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;\0&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;16&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;plaintext &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; cipher&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;decrypt(ciphertext)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;print(plaintext)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And, drumroll&amp;hellip;
&lt;code&gt;b&#39;ictf{Would_number_theory_be_new_technology?}\x04\x04\x04\x04&#39;&lt;/code&gt;!
For good practice, let&amp;rsquo;s clean that up a bit by removing the padding and
turning it back into a unicode string:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; Crypto.Util.Padding &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; unpad
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;print(unpad(plaintext, &lt;span style=&#34;color:#ae81ff&#34;&gt;16&lt;/span&gt;)&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;decode(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;utf-8&amp;#34;&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And there we have it!&lt;/p&gt;
&lt;div class=&#34;alert alert-success&#34; role=&#34;alert&#34; data-dir=&#34;ltr&#34;&gt;Flag: &lt;code&gt;ictf{Would_number_theory_be_new_technology?}&lt;/code&gt;&lt;/div&gt;
&lt;h2 id=&#34;thanks&#34;&gt;Thanks&lt;/h2&gt;
&lt;p&gt;Thank you to my team for a friendly place to be the dumbest person in the room,
and to the ImaginaryCTF platform folks and challenge developers for the
interesting and challenging &amp;hellip; challenges.&lt;/p&gt;
&lt;p&gt;The header image is from the ImaginaryCTF 2021 site (&lt;a href=&#34;https://github.com/et3rnos/imaginaryctf&#34;&gt;repo&lt;/a&gt;),
used with permission from Astro.&lt;/p&gt;
&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;I&amp;rsquo;ve taken some liberties with the order I present objectives here,
since a writeup that followed my actual path would be impossible to follow.&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
]]></content:encoded>
        <dc:creator>mal</dc:creator>
        <media:content url="https://sec.gd/blog/images/imaginaryctf-2021/ictf-2021-banner.jpg" medium="image"><media:title type="html">featured image</media:title></media:content>
        
        <media:content url="https://sec.gd/blog/images/imaginaryctf-2021/ictf-2021-banner.jpg" medium="image"><media:title type="html">meta image</media:title></media:content>
        
          
            
              <category>imaginaryctf</category>
            
          
            
              <category>crypto</category>
            
          
            
              <category>misc</category>
            
          
            
              <category>sysadmin</category>
            
          
        
        
          
            
              <category>ctf</category>
            
          
        
        
      </item>
    
  </channel>
</rss>