- Hacking/OSCP Cheatsheet
- Enumeration
- Network discoverie
- Ports discovery (without nmap)
- Banner grabbing (without nmap)
- Web directorie/file scanner
- Samba
- Exfiltration
- Samba
- HTTP
- Pivoting
- sshuttle
- Reverse shells
- Privilege escalation
- Windows
- Linux
- Good to know (either Windows and/or Linux)
- Simple Buffer Overflow (32 bits, NO ASLR and NO DEP)
- Usefull tools (on Kali Linux)
- Enumeration
Well, just finished my 90 days journey of OSCP labs, so now here is my cheatsheet of it (and of hacking itself), I will be adding stuff in an incremental way as I go having time and/or learning new stuff.But this is basically the tools I tend to relie and use in this way the most.Hope is helpfull for you!
Enumeration
Nikto Cheat Sheet Introduction To Networks V6 Packet Tracer Activities Alien Skin Bokeh 2.0.1.493 (32 How Far Back To Mount Bosch Dishwasher Hyster H80c Parts Pvp Tag Plugin Ampli Fener Numero Deserie How To Train Your Dragon 3 Torrent Hitman: Sniper Challenge Video Card Requirements The Novo Group. Tools Cheat Sheet. Bug Bounty & Pen-Test Templates. Powered by GitBook. Nikto # To scan a particular host. Nikto -host host IP/name # To scan a host on multiple ports (default = 80) nikto -host host IP/name -port port number 1, port number 2, port number 3.
Network discoverie
Nmap
I tend to run 3 nmaps, an initial one, a full one and an UDP one, all of them in parallel:
Is also possible to specify scripts or ports:
If there are servers that could be not answering (ping), then add the flag -Pn (example of initial one):
Ports discovery (without nmap)
nc + bash
If you get in a machine that doesn't have nmap installed, you can do a basic discovery of (for example), top 10 ports open in 192.168.30 by doing:
/dev/tcp/ip/port or /dev/udp/ip/port
Alternatively, is possible to do the same than above but by using the special dev files /dev/tcp/ip/port
or /dev/udp/ip/port
(for example nc is not found):
Taking these last examples, is straightforward to create a dummy script for scan a hole /24 net (for example):
Banner grabbing (without nmap)
If nmap didn't grab banners (or is not installed), you can do it with /dev/tcp/ip/port
/dev/udp/ip/port
or by using telnet.
/dev/tcp/ip/port or /dev/udp/ip/port
For doing it with udp ports is the same, but changing tcp for udp
telnet
Web directorie/file scanner
Gobuster
Scan all the directories/files by extension:
For scanning without extensions, just take out the -x
Nikto
Sometimes Nikto shows juicy information, I tend to run it like:
fuff
Web fuzzer, you can get fuff here, it basically bruteforces the dirs.
Most usefull dictionaries (OSCP/HTB)
Samba
smbclient
Check if there is anonymous login enabled:
impacket
Is also possible to use impacket in the same way than smbclient to check for anonymous login (and a lot more as browse the shares) in case of incompatible versions.
smbmap
Check which permissions we have in those shares (if there are):
Version (nmap didn't detect it)
Sometimes nmap doesn't show the version of Samba in the remote host, if this happens, a good way to know which version the remote host is running, is to capture traffic with wireshark against the remote host on 445/139 and in parallel run an smbclient -L, do a follow tcp stream and with this we might see which version the server is running.
Exfiltration
Samba
Generate a samba server with Impacket:
Mount in Windows
Mounting it in Windows with Powershell:
Mounting it without Powershell:
On windows, to list mounted shares, either Powershell or without it:
Mount in Linux
Is needed to have installed cifs-utils, to install it (in debian based):
To mount it:
To list mounted shares:
HTTP
From your local attacker machine, create a http server with:
Sentinel loop c++. It's also possible to specify which path to share, for example:
Windows
Linux
Nikto Cheat Sheet Github
FTP
If there is an ftp server which we have access, we can upload files there through it, the ' is the same for both, windows or linux:
Sockets
Using nc/ncat is possible to create as a listener to upload/download stuff through them, the syntax for nc and ncat is basically the same.Create the socket with:
RDP
If we have access to a windows machine with a valid user/credentials and this user is in the 'Remote Desktop Users', we can share a local directorie as a mount volume through rdp itself once we connect to the machine:
Pivoting
It's possible to do pivoting by using proxychains, pure nc's or in case of linux just some fifo files (I will write them down this another methods down maybe in a future), I have used during all the OSCP an awesome tool called (sshuttle)[https://github.com/sshuttle/sshuttle] (it's a transparent proxy server that works like 'a vpn', and doesn't require with super rights, only thing needed is that the bastion server you will use, needs to have installed python) and sometimes some SSH Forwarding. Something worth to mention nmap doesn't work through sshuttle.
sshuttle
One hop
Let's say we are in an intranet and we have compromised a firewall that gives us access to the management net (fw.example.mgmt - ips 192.168.20.35 and 192.168.30.253 as the management ip), by using sshuttle we can create a 'vpn' to talk directly to those servers, for that, we use:
Multi-hops
Now imagine that after we broke up into the management net after some some enumeration, we ended to compromise a machine that has also access to a production environment (foreman.example.mgmt - ips 192.168.30.40 and 192.168.25.87), we can take advantage of sshuttle + ProxyCommand of ssh to create a 'vpn' through this multiple hops, so…putting it down, this will be kind of as follow (the diagram is extremly simplified and just for the sake of illustrate this visually, so it doesn't intend to provide a 100% precise network diagram):
To have that working, is needed to put the next conf in your ssh conf file (normally ~/.ssh/config. It's based on the example above, but is easy to extrapolate to different scenarios):
And now to setup the 'multiple hop vpn', run:
Reverse shells
php
bash
sh + nc
Perl (example deploy as cgi-bin)
Java (example to deploy on tomcat)
Windows HTPP download reverse shell
Windows staged reverse TCP
Windows stageless reverse TCP
Linux staged reverse TCP
Linux staged reverse TCP
Privilege escalation
Windows
Run-As
Incorrect permisions in services (sc config binpath)
Binpath is set as running cmd.exe
passing a commad to execute to it (so once the process dies, the one executed by it so the command to cmd.exe
remains):
SAM + SYSTEM + Security
If those 3 files are in your hands (you could download to your attacker machine), you can dump hashes and crack them:
Linux
/home/user/openssl =ep (empty capabilities)
Make 2 copies of passwd, one as backup of the original, and one that will be used as custom:
Now, a custom user will be created and added to /tmp/passwd.custom
with customPassword
and as root user (UID = GID = 0):
Now, create a custom key.pem
and cert.pem
with openssl:
Encrypt the new custom passwd:
Now, decrypt the custom passwd overwritting in the process the real one (/etc/passwd
):
And finally, just login with the user created with root privileges by using customPassword
:
Command web injection: add user
NFS; no_root_squash,insecure,rw
If /etc/exports
has a line like:
NFS is being exported and you and you have ssh access to the machine.From your attacker machine while logged as root user run:
Now from inside a SSH session on the victim machine (in this example 192.168.42.32
):
Good to know (either Windows and/or Linux)
Nikto Cheat Sheet Excel
Arch cross compile exploit (and diff glibc version)
IP restriction at application level, bypass
Try to send a request modifying the HTTP header by adding:
Windows - check OS information
Windows - check architecture
Powershell running as 32 or 64 bits
Linux LFI - intesresting files to look after
Simple Buffer Overflow (32 bits, NO ASLR and NO DEP)
Summarized steps
- 0 - Crash the application
- 1 - Fuzzing (find aprox number of bytes where the crash took place)
- 2 - Find offset
- 3 - EIP control
- 4 - Check for enough space on buffer
- 5 - Badchars counting
- 6 - Find return address (JMP ESP)
- 7 - Create payload
Fuzzing: example with vulnserver + spike on TRUN command
Now, start wireshark filtering on the target IP/PORT below and run the trun.spk
:
Once a crash takes place, go to wireshark to locate the crash.
Badchars
From the block below, the next ones were not included (most common badchars):
So…actual list of badchars:
Nmap
I tend to run 3 nmaps, an initial one, a full one and an UDP one, all of them in parallel:
Is also possible to specify scripts or ports:
If there are servers that could be not answering (ping), then add the flag -Pn (example of initial one):
Ports discovery (without nmap)
nc + bash
If you get in a machine that doesn't have nmap installed, you can do a basic discovery of (for example), top 10 ports open in 192.168.30 by doing:
/dev/tcp/ip/port or /dev/udp/ip/port
Alternatively, is possible to do the same than above but by using the special dev files /dev/tcp/ip/port
or /dev/udp/ip/port
(for example nc is not found):
Taking these last examples, is straightforward to create a dummy script for scan a hole /24 net (for example):
Banner grabbing (without nmap)
If nmap didn't grab banners (or is not installed), you can do it with /dev/tcp/ip/port
/dev/udp/ip/port
or by using telnet.
/dev/tcp/ip/port or /dev/udp/ip/port
For doing it with udp ports is the same, but changing tcp for udp
telnet
Web directorie/file scanner
Gobuster
Scan all the directories/files by extension:
For scanning without extensions, just take out the -x
Nikto
Sometimes Nikto shows juicy information, I tend to run it like:
fuff
Web fuzzer, you can get fuff here, it basically bruteforces the dirs.
Most usefull dictionaries (OSCP/HTB)
Samba
smbclient
Check if there is anonymous login enabled:
impacket
Is also possible to use impacket in the same way than smbclient to check for anonymous login (and a lot more as browse the shares) in case of incompatible versions.
smbmap
Check which permissions we have in those shares (if there are):
Version (nmap didn't detect it)
Sometimes nmap doesn't show the version of Samba in the remote host, if this happens, a good way to know which version the remote host is running, is to capture traffic with wireshark against the remote host on 445/139 and in parallel run an smbclient -L, do a follow tcp stream and with this we might see which version the server is running.
Exfiltration
Samba
Generate a samba server with Impacket:
Mount in Windows
Mounting it in Windows with Powershell:
Mounting it without Powershell:
On windows, to list mounted shares, either Powershell or without it:
Mount in Linux
Is needed to have installed cifs-utils, to install it (in debian based):
To mount it:
To list mounted shares:
HTTP
From your local attacker machine, create a http server with:
Sentinel loop c++. It's also possible to specify which path to share, for example:
Windows
Linux
Nikto Cheat Sheet Github
FTP
If there is an ftp server which we have access, we can upload files there through it, the ' is the same for both, windows or linux:
Sockets
Using nc/ncat is possible to create as a listener to upload/download stuff through them, the syntax for nc and ncat is basically the same.Create the socket with:
RDP
If we have access to a windows machine with a valid user/credentials and this user is in the 'Remote Desktop Users', we can share a local directorie as a mount volume through rdp itself once we connect to the machine:
Pivoting
It's possible to do pivoting by using proxychains, pure nc's or in case of linux just some fifo files (I will write them down this another methods down maybe in a future), I have used during all the OSCP an awesome tool called (sshuttle)[https://github.com/sshuttle/sshuttle] (it's a transparent proxy server that works like 'a vpn', and doesn't require with super rights, only thing needed is that the bastion server you will use, needs to have installed python) and sometimes some SSH Forwarding. Something worth to mention nmap doesn't work through sshuttle.
sshuttle
One hop
Let's say we are in an intranet and we have compromised a firewall that gives us access to the management net (fw.example.mgmt - ips 192.168.20.35 and 192.168.30.253 as the management ip), by using sshuttle we can create a 'vpn' to talk directly to those servers, for that, we use:
Multi-hops
Now imagine that after we broke up into the management net after some some enumeration, we ended to compromise a machine that has also access to a production environment (foreman.example.mgmt - ips 192.168.30.40 and 192.168.25.87), we can take advantage of sshuttle + ProxyCommand of ssh to create a 'vpn' through this multiple hops, so…putting it down, this will be kind of as follow (the diagram is extremly simplified and just for the sake of illustrate this visually, so it doesn't intend to provide a 100% precise network diagram):
To have that working, is needed to put the next conf in your ssh conf file (normally ~/.ssh/config. It's based on the example above, but is easy to extrapolate to different scenarios):
And now to setup the 'multiple hop vpn', run:
Reverse shells
php
bash
sh + nc
Perl (example deploy as cgi-bin)
Java (example to deploy on tomcat)
Windows HTPP download reverse shell
Windows staged reverse TCP
Windows stageless reverse TCP
Linux staged reverse TCP
Linux staged reverse TCP
Privilege escalation
Windows
Run-As
Incorrect permisions in services (sc config binpath)
Binpath is set as running cmd.exe
passing a commad to execute to it (so once the process dies, the one executed by it so the command to cmd.exe
remains):
SAM + SYSTEM + Security
If those 3 files are in your hands (you could download to your attacker machine), you can dump hashes and crack them:
Linux
/home/user/openssl =ep (empty capabilities)
Make 2 copies of passwd, one as backup of the original, and one that will be used as custom:
Now, a custom user will be created and added to /tmp/passwd.custom
with customPassword
and as root user (UID = GID = 0):
Now, create a custom key.pem
and cert.pem
with openssl:
Encrypt the new custom passwd:
Now, decrypt the custom passwd overwritting in the process the real one (/etc/passwd
):
And finally, just login with the user created with root privileges by using customPassword
:
Command web injection: add user
NFS; no_root_squash,insecure,rw
If /etc/exports
has a line like:
NFS is being exported and you and you have ssh access to the machine.From your attacker machine while logged as root user run:
Now from inside a SSH session on the victim machine (in this example 192.168.42.32
):
Good to know (either Windows and/or Linux)
Nikto Cheat Sheet Excel
Arch cross compile exploit (and diff glibc version)
IP restriction at application level, bypass
Try to send a request modifying the HTTP header by adding:
Windows - check OS information
Windows - check architecture
Powershell running as 32 or 64 bits
Linux LFI - intesresting files to look after
Simple Buffer Overflow (32 bits, NO ASLR and NO DEP)
Summarized steps
- 0 - Crash the application
- 1 - Fuzzing (find aprox number of bytes where the crash took place)
- 2 - Find offset
- 3 - EIP control
- 4 - Check for enough space on buffer
- 5 - Badchars counting
- 6 - Find return address (JMP ESP)
- 7 - Create payload
Fuzzing: example with vulnserver + spike on TRUN command
Now, start wireshark filtering on the target IP/PORT below and run the trun.spk
:
Once a crash takes place, go to wireshark to locate the crash.
Badchars
From the block below, the next ones were not included (most common badchars):
So…actual list of badchars: