<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by g2f1 on Medium]]></title>
        <description><![CDATA[Stories by g2f1 on Medium]]></description>
        <link>https://medium.com/@g2f1?source=rss-06540587a611------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*TDAn8NvTwxSjxcLf</url>
            <title>Stories by g2f1 on Medium</title>
            <link>https://medium.com/@g2f1?source=rss-06540587a611------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 16:30:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@g2f1/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A method to recover potential plaintexts when bad RSA keys were used.]]></title>
            <link>https://medium.com/@g2f1/bad-rsa-keys-3157bc57528e?source=rss-06540587a611------2</link>
            <guid isPermaLink="false">https://medium.com/p/3157bc57528e</guid>
            <category><![CDATA[rsa-keys]]></category>
            <category><![CDATA[rsa-algorithm]]></category>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[group-theory]]></category>
            <dc:creator><![CDATA[g2f1]]></dc:creator>
            <pubDate>Fri, 16 Aug 2024 06:50:58 GMT</pubDate>
            <atom:updated>2024-08-16T17:59:15.709Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*ne9s22ToFlZAkQw-ZGWSYw.png" /></figure><h3><strong>Introduction</strong></h3><p>Hello everyone,</p><p>I hope you are all doing well. In this post, I will explain a method to recover possible plaintexts when incorrect RSA keys are used. Specifically, we will discuss a situation where d (the private key) cannot be calculated because the public exponent e is not coprime with phi(n), where phi(n) is the Euler’s totient function of the modulus n. For brevity, I won’t introduce the RSA algorithm here, but I invite you to check this Wikipedia page for more information: <a href="https://fr.wikipedia.org/wiki/Chiffrement_RSA">RSA (cryptosystem)</a>.</p><p>When gcd(e,phi(n)) &gt; 1, we cannot compute the modular inverse of e, which is the private key used for decryption. As a result, decryption of the ciphertext is not straightforward. Fortunately, there is a method to recover all potential plaintexts. Indeed, there are multiple solutions, and we will attempt to recover them all so you can manually determine the correct plaintext. This method works well but comes with some restrictions that I will detail in the following sections.</p><blockquote>I recently read a <a href="https://www.google.com/url?sa=t&amp;source=web&amp;rct=j&amp;opi=89978449&amp;url=https://eprint.iacr.org/2020/1059&amp;ved=2ahUKEwjTs9K26viHAxUIQUEAHU22BfkQFnoECBQQAQ&amp;usg=AOvVaw1xEJuBSjpA6-mDm_8aMi0P">paper</a> by <strong>Daniel Shumow </strong>in which he describes a method for recovering potential plaintexts when incorrect RSA keys are used. However, his method is specifically applicable only when e is a prime number, e divides phi(n), and e² does not divide phi(n). When I encountered a case in a CTF challenge where e was not prime and e did not divide phi(n), i start thinking about a way to extend Shumow’s method to address this scenario (even though the challenge itself had a simpler solution).</blockquote><h3>Mathematical Preliminary Concepts</h3><p>Since the last paper of RSA , the group of units of the integers modolu n (Z/nZ)* noted Zn* is where all the calculation is performed ,although RSA works well for any integer betwen 1 and n. |G| represent the order of the finite group G ;it’s the number of elements in G, and we we have this important result about finite abelian groups</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*-Fxr3iVusRrQW3Oum8BsMA.png" /></figure><p>In our case Zn* can be decompose as :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*L-hOnP26HQISaqeodb33pg.png" /></figure><p>We can calculate k explicitly by :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*XhwZS3ATAiZa25mjHScevA.png" /></figure><p>But there is a simpler way to calculate k as you will see in the two algoritms below .</p><h3>Restrictions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*PBbbNSDHp7p9Dp_5iXe9Vw.png" /></figure><h3>Why decryption is not a one to one function?</h3><p>By (1), any element of Zn* can be decoposed as the product of two elements from E x G</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/1*G2XiJyT0wbUpx8ZZoFryJw.png" /></figure><p>So after the encryption we lost a part of our plaintext , it’s about l , indeed there is k potential plaintext (k possible value for l , because |E|=k)</p><h3>How can we recover all the potential plaintexts?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*boAd9LcQgdqQIURK3M5WOw.png" /></figure><p>An algorithm to collect roots in the range of 1 to max ,after calculating k</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*C7Al0mCrojhlpa4RMPH0Lw.png" /></figure><p>After we move to determin the other part(statical part) of the potential plaintexts ,which is g</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*hTXNf6ae4qP0UgzWwolg7w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*Q2YPNXgibmpsMZeUynWuNQ.png" /></figure><h3>Conclusion</h3><p>What I have presented in this post is not a complete method for recovering the plaintext in real-world scenarios. The lack of information about the group <strong>E</strong> limits us to searching for <strong>l </strong>only as <strong>e-th</strong> roots of unity modulo <strong>n</strong>, which leaves some uncertainty about whether we have collected all possible values of <strong>l</strong> in <strong>E </strong>and, consequently, all possible plaintexts. This method may only be useful if the plaintext is in a readable format or the user of the algorithm has additional information about the original plaintext; by increasing the value of the variable <strong>max</strong> and checking each time for a match within the set <strong>P</strong> of potential plaintexts, there is a high probability that the original plaintext can successfully be recovered.I shared this method because it work well for me in the CTF challenge i already mention and because the math behind it is quite beautiful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3157bc57528e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[BYUCTF 2024 Write-up for Netstat challenge]]></title>
            <link>https://medium.com/@g2f1/write-up-9231061042e4?source=rss-06540587a611------2</link>
            <guid isPermaLink="false">https://medium.com/p/9231061042e4</guid>
            <category><![CDATA[misc]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <dc:creator><![CDATA[g2f1]]></dc:creator>
            <pubDate>Fri, 24 May 2024 02:40:38 GMT</pubDate>
            <atom:updated>2024-08-16T18:00:14.927Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello everyone,</p><p>In this post, I will explain my method for solving a challenge from BYUCTF 2024. The task is to determine which Python program is running on a specific port of a machine that we connected to remotely using SSH.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*xh8D_uZ3449pPn9F65A-cA.png" /></figure><p>We start by connecting to the machine using ssh :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*5W1kEflKEL7JokDIijZGFA.png" /><figcaption>sshing into the machine</figcaption></figure><p>Connecting to the machine we use now the SHELL vriable environement to print our shell name .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/138/1*iMXF2U0Y60KqrdvBHaLjiA.png" /></figure><p>I chose to switch my shell to BASH because I feel more comfortable using it. Then I run the ‘<strong>ps’</strong> command to print a list of running processes on the machine, and I found out that there are several Python programs running on the machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/957/1*knaBSeczfmuiR5cxxi-1NA.png" /><figcaption>A partial list of running program in the machine</figcaption></figure><p>The traditional method for identifying which program is running on each port is by using the ‘netstat’ command; unfortunately, this command does not exist.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/309/1*RVGZ1EPat_IA3rf8u2zDNQ.png" /><figcaption>netsat not found</figcaption></figure><p>I then moved to plan B, where I attempted to gather information from files in the /proc directory. These files contain valuable information about the processes currently running.</p><p>To start, I searched for the inode of the program in the file /proc/net/tcp. Using the grep command, I looked for any line containing the port number 2694 (9876 in hexadecimal).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aPd_w6Qw0xA88394smGkmg.png" /></figure><p>What we’re interested in is the first line, as it provides the inode of the program running on port <strong>9876</strong>, which is <strong>3490694</strong>.</p><p>After that, we try to determine the PID of the program using its inode. To do this, we search for the pattern ‘<strong><em>3490694</em></strong>’ in the <strong>/proc/&lt;pid&gt;/fd</strong> directory of each process. The following command helps me find the number of lines where the inode is mentioned, which is <strong>764</strong>. Now, I need to locate the exact line that contains the PID of the program.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*id5eBOxwSZ6b55ycdtXPqA.png" /></figure><p>I tried line <strong>760</strong>, but it only provided information about the size. Therefore, the <strong>PID </strong>is most likely on line <strong>759</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*P1xZXY1b3jyHIIyBrxSCzA.png" /></figure><p>So, the <strong>PID</strong> of the program is <strong>72</strong>.</p><p>The final step is straightforward: we just need to use the <strong><em>ps</em></strong> command or print the contents of the file <strong><em>/proc/72/cmdline</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*QCSGejWnbTKq5KjhN_NwMA.png" /></figure><blockquote>And finally, the flag is <strong>byuctf{5065fc12633a9f1fd28f0b9d27467537.py}</strong>.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9231061042e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>