Linux commands form the foundation of penetration testing, allowing security professionals to navigate systems, gather information, and execute tests effectively.
This quick guide covers essential Linux commands that every pentester should know.
System Navigation & Information Gathering
pwd
– Shows current directory locationls -la
– Lists all files including hidden ones with permissionscd
– Changes directorieswhoami
– Displays current useruname -a
– Shows system information
File Operations
cat
– Reads file contentsgrep
– Searches text patterns in filestouch
– Creates empty filescp
– Copies filesmv
– Moves or renames files
Network Commands
ifconfig
/ip addr
– Shows network interfacesnetstat -tuln
– Lists open portsping
– Tests network connectivitytraceroute
– Traces packet routenmap
– Scans network ports
Process Management
ps aux
– Lists running processestop
– Shows real-time process activitykill
– Terminates processes
File Permissions
chmod
– Changes file permissionschown
– Changes file ownershipsudo
– Executes commands with elevated privileges
Text Processing
nano
/vim
– Text editorshead
– Shows first lines of filetail
– Shows last lines of filesort
– Sorts text files
Practical Tips
- Use tab completion to speed up command typing
- Press Ctrl+R to search command history
- Create aliases for frequently used commands
- Use man pages (
man command
) for detailed information
Learn these commands in a test environment before using them in actual penetration tests.
Additional Resources
Advanced Command Usage
Command Chaining
&&
– Executes next command if previous succeeds||
– Executes next command if previous fails;
– Executes commands sequentially|
– Pipes output of one command to another
Data Collection
tcpdump
– Captures network trafficwireshark
– Analyzes network packetsstrings
– Extracts readable characters from filesdd
– Converts and copies files
Remote Access
ssh
– Secure shell connectionscp
– Secure file copync
– Netcat for networking utilityrsync
– Remote file synchronization
Automation and Scripting
Bash Scripting Basics
#!/bin/bash
– Shebang for bash scriptschmod +x script.sh
– Makes script executable./script.sh
– Executes scriptsource script.sh
– Runs script in current shell
Conclusion
Mastering Linux commands is crucial for effective penetration testing. Start with basic commands and gradually progress to more advanced operations. Regular practice in controlled environments helps build confidence and proficiency. Remember to always follow ethical guidelines and obtain proper authorization before conducting security tests.
Keep documentation of commonly used commands and create custom scripts to automate routine tasks. Stay updated with new tools and techniques through continuous learning and community engagement.
FAQs
- What is the command to list files with hidden items in Linux?
The ls -la command shows all files including hidden ones, with detailed information including permissions, owner, size, and timestamps. - How do you search for files containing specific text in Linux?
Use grep -r “search_text” /path/ to recursively search for text in files, or find /path/ -type f -exec grep “search_text” {} ; - What command displays real-time system processes?
The top command shows real-time system processes, while htop provides an enhanced interactive process viewer with color and additional features. - How do you check network connections in Linux?
Use netstat -tuln to display active network connections, listening ports, and network statistics. Additionally, ss -tuln provides similar information with newer syntax. - What command captures network traffic?
tcpdump -i interface_name captures and analyzes network traffic. For example, tcpdump -i eth0 captures traffic on the eth0 interface. - How do you check system users and their privileges?
cat /etc/passwd shows all system users, while sudo -l displays current user’s sudo privileges. The id command shows user and group IDs. - What command shows disk usage and available space?
df -h displays disk space usage in human-readable format, while du -sh /path/ shows directory size. - How do you find files with specific permissions?
find /path/ -perm mode searches for files with specific permissions. For example, find / -perm -4000 locates SUID files. - What command helps monitor system logs in real-time?
tail -f /var/log/filename continuously monitors log files in real-time. For system logs, tail -f /var/log/syslog is commonly used. - How do you check running services and their status?
systemctl list-units –type=service shows all services, while service servicename status displays specific service status.