- Linux Penetration Testing Commands
A collection of hopefully useful Linux Commands for pen testers, this is not a complete list but a collection of commonly used commands + syntax as a sort of “cheatsheet”, this content will be constantly updated as I discover new awesomeness.
Linux Penetration Testing Commands
The commands listed below are designed for local enumeration, typical commands a penetration tester would use during post exploitation or when performing command injection etc. See our pen test cheat sheet for an in depth list of pen testing tool commands and example usage.
Linux Network Commands
Command | Description |
---|---|
|
Show Linux network ports with process ID's (PIDs) |
|
Watch TCP, UDP open ports in real time with socket summary. |
|
Show established connections. |
|
Change MAC address on KALI Linux. |
|
Set IP address in Linux. |
|
Add IP address to existing network interface in Linux. |
|
Change MAC address in Linux using ifconfig. |
|
Change MTU size Linux using ifconfig, change 1500 to your desired MTU. |
|
Dig reverse lookup on an IP address. |
|
Reverse lookup on an IP address, in case dig is not installed. |
|
Perform a DNS zone transfer using dig. |
|
Perform a DNS zone transfer using host. |
|
Get hostname for IP address. |
|
Adds a hidden IP address to Linux, does not show up when performing an ifconfig. |
|
Blocks access to google.com from the host machine. |
|
Enables IP forwarding, turns Linux box into a router - handy for routing traffic through a box. |
|
Use Google DNS. |
System Information Commands
Useful for local enumeration.
Command | Description |
---|---|
|
Shows currently logged in user on Linux. |
|
Shows currently logged in user and groups for the user. |
|
Shows last logged in users. |
|
Show mounted drives. |
|
Shows disk usage in human readable output. |
|
Reset password in one line. |
|
List users on Linux. |
|
Shows contents of none text files, e.g. whats in a binary. |
|
Shows running kernel version. |
|
Add a new PATH, handy for local FS manipulation. |
|
Show bash history, commands the user has entered previously. |
Redhat / CentOS / RPM Based Distros
Command | Description |
---|---|
|
Shows Redhat / CentOS version number. |
|
List all installed RPM's on an RPM based Linux distro. |
|
Check installed RPM is patched against CVE, grep the output for CVE. |
YUM Commands
Package manager used by RPM based systems, you can pull some usefull information about installed packages and or install additional tools.
Command | Description |
---|---|
|
Update all RPM packages with YUM, also shows whats out of date. |
|
Update individual packages, in this example HTTPD (Apache). |
|
Install a package using YUM. |
|
Exclude a package from being updates with YUM. |
|
Remove package with YUM. |
|
Remove package with YUM. |
|
Lists info about yum package. |
|
What a packages does, e.g Apache HTTPD Server. |
|
Shows package info, architecture, version etc. |
|
Use YUM to install local RPM, settles deps from repo. |
|
Shows deps for a package. |
|
List all installed packages. |
|
Show all YUM groups. |
|
Install YUM group. |
Debian / Ubuntu / .deb Based Distros
Command | Description |
---|---|
|
Shows Debian version number. |
|
Shows Ubuntu version number. |
|
List all installed packages on Debian / .deb based Linux distro. |
Linux User Management
Command | Description |
---|---|
|
Creates a new Linux user. |
|
Reset Linux user password, enter just |
|
Remove a Linux user. |
Linux Decompression Commands
How to extract various archives (tar, zip, gzip, bzip2 etc) on Linux and some other tricks for searching inside of archives etc.
Command | Description |
---|---|
|
Extracts zip file on Linux. |
|
Search inside a .zip archive. |
|
Extract tar file Linux. |
|
Extract a tar.gz file Linux. |
|
Extract a tar.bz2 file Linux. |
|
Search inside a tar.gz file. |
|
Extract a gzip file Linux. |
|
Read a gz file Linux without decompressing. |
|
Same function as the |
|
Search inside .gz archives on Linux, search inside of compressed log files. |
|
Use vim to read .txt.gz files (my personal favorite). |
|
UPX compress .exe file Linux. |
Linux Compression Commands
Command | Description |
---|---|
|
Creates a .zip file on Linux. |
|
Creates a tar file on Linux. |
|
Creates a tar.gz file on Linux. |
|
Creates a tar.bz2 file on Linux. |
|
Creates a file.gz file on Linux. |
Linux File Commands
Command | Description |
---|---|
|
Display size of file / dir Linux. |
|
Compare / Show differences between two files on Linux. |
|
Generate MD5SUM Linux. |
|
Check file against MD5SUM on Linux, assuming both file and .md5 are in the same dir. |
|
Find out the type of file on Linux, also displays if file is 32 or 64 bit. |
|
Convert Windows line endings to Unix / Linux. |
|
Base64 encodes input file and outputs a Base64 encoded file called output-file. |
|
Base64 decodes input file and outputs a Base64 decoded file called output-file. |
|
Creates a new file using the timestamp data from the reference file, drop the -r to simply create a file. |
|
Remove files and directories without prompting for confirmation. |
Samba Commands
Connect to a Samba share from Linux.
Breaking Out of Limited Shells
Credit to G0tmi1k for these (or wherever he stole them from!).
The Python trick:
Misc Commands
Command | Description |
---|---|
|
Reboot Linux from the command line. |
|
Compile C code. |
|
Cross compile C code, compile 32 bit binary on 64 bit Linux. |
|
Disable bash history logging. |
|
Connect to RDP server from Linux. |
|
Kill current session. |
|
Change owner of file or dir. |
|
Change owner of file or dir and all underlying files / dirs - recersive chown. |
|
Change file / dir permissions, see [Linux File System Permissons](#linux-file-system-permissions) for details. |
Clear bash history:
Linux File System Permissions
Value | Meaning |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Linux File System
Directory | Description |
---|---|
|
/ also know as "slash" or the root. |
|
Common programs, shared by the system, the system administrator and the users. |
|
Boot files, boot loader (grub), kernels, vmlinuz |
|
Contains references to system devices, files with special properties. |
|
Important system config files. |
|
Home directories for system users. |
|
Library files, includes files for all kinds of programs needed by the system and the users. |
|
Files that were saved during failures are here. |
|
Standard mount point for external file systems. |
|
Mount point for external file systems (on some distros). |
|
Standard mount point for entire remote file systems - nfs. |
|
Typically contains extra and third party software. |
|
A virtual file system containing information about system resources. |
|
root users home dir. |
|
Programs for use by the system and the system administrator. |
|
Temporary space for use by the system, cleaned upon reboot. |
|
Programs, libraries, documentation etc. for all user-related programs. |
|
Storage for all variable files and temporary files created by users, such as log files, mail queue, print spooler. Web servers, Databases etc. |
Linux Interesting Files / Dir’s
Places that are worth a look if you are attempting to privilege escalate / perform post exploitation.
Directory | Description |
---|---|
|
Contains local Linux users. |
|
Contains local account password hashes. |
|
Contains local account groups. |
|
Contains service init script - worth a look to see whats installed. |
|
System hostname. |
|
Network interfaces. |
|
System DNS servers. |
|
System environment variables. |
|
SSH keys. |
|
Users bash history log. |
|
Linux system log files are typically stored here. |
|
UNIX system log files are typically stored here. |
|
Apache access log file typical path. |
|
File system mounts. |