| name | Linux Penetration Testing Fundamentals |
| description | This skill should be used when the user asks to "learn Linux for pentesting", "use Linux commands for hacking", "manage Linux processes", "manipulate text in Linux", "write bash scripts", or "configure Linux networking". It provides comprehensive Linux fundamentals for penetration testing. |
| version | 1.0.0 |
| tags | ["linux","pentesting","bash","networking","commands","scripting"] |
Linux Penetration Testing Fundamentals
Purpose
Master essential Linux skills for penetration testing including navigation, file manipulation, text processing, networking, process management, permissions, and bash scripting. Linux is the preferred platform for security professionals due to its flexibility, transparency, and extensive tool support.
Prerequisites
Required Environment
- Linux-based system (Kali Linux recommended)
- Terminal access
- Basic understanding of operating systems
Required Knowledge
- Basic command-line concepts
- File system understanding
- Networking fundamentals
Outputs and Deliverables
- System Navigation - Efficient directory and file operations
- Text Processing - Data extraction and manipulation
- Network Configuration - Interface and DNS management
- Automation Scripts - Custom bash tools
Core Workflow
Phase 1: Basic Navigation Commands
Essential commands for system navigation:
pwd
whoami
id
cd /path/to/directory
cd ..
cd ~
cd -
ls
ls -l
ls -la
ls -lah
man <command>
<command> --help
<command> -h
Phase 2: File Operations
Create, copy, move, and delete files:
touch newfile.txt
mkdir new_directory
mkdir -p path/to/dir
cp file.txt copy.txt
cp -r dir1 dir2
cp file.txt /dest/
mv file.txt newname.txt
mv file.txt /dest/
mv dir1 dir2
rm file.txt
rm -r directory/
rm -rf directory/
rmdir empty_directory/
cat file.txt
less file.txt
more file.txt
head -n 20 file.txt
tail -n 20 file.txt
tail -f logfile.log
Phase 3: Searching and Finding
Locate files and search content:
find / -name "filename" 2>/dev/null
find / -type f -name "*.txt" 2>/dev/null
find / -type d -name "logs" 2>/dev/null
find / -size +100M 2>/dev/null
find / -mtime -7 2>/dev/null
find / -perm -4000 2>/dev/null
find / -user root -perm -4000 2>/dev/null
locate filename
updatedb
which nmap
whereis nmap
grep "pattern" file.txt
grep -r "pattern" /path/
grep -i "pattern" file.txt
grep -v "pattern" file.txt
grep -n "pattern" file.txt
grep -E "regex|pattern" file.txt
Phase 4: Text Manipulation
Process and transform text:
nl file.txt
cat -n file.txt
cut -d':' -f1 /etc/passwd
cut -d',' -f1,3 file.csv
awk '{print $1}' file.txt
awk -F: '{print $1}' /etc/passwd
sort file.txt
sort -r file.txt
sort -n file.txt
uniq file.txt
sort file.txt | uniq
sort file.txt | uniq -c
sed 's/old/new/g' file.txt
sed -i 's/old/new/g' file.txt
sed -n '5,10p' file.txt
sed '1,5d' file.txt
wc file.txt
wc -l file.txt
wc -w file.txt
command1 | command2
command > file.txt
command >> file.txt
command 2>/dev/null
command 2>&1
Phase 5: Permissions and Ownership
Manage file access control:
ls -l file.txt
chmod 755 file.txt
chmod 644 file.txt
chmod 777 file.txt
chmod 600 file.txt
chmod +x file.txt
chmod u+x file.txt
chmod g+w file.txt
chmod o-r file.txt
chmod u=rw,g=r file.txt
chown user file.txt
chown user:group file.txt
chown -R user directory/
chgrp group file.txt
chmod 4755 file.txt
chmod 2755 directory
chmod 1755 directory
Permission values:
- 4 = Read (r)
- 2 = Write (w)
- 1 = Execute (x)
Phase 6: Network Management
Configure and analyze network settings:
ifconfig
ip addr
ip link
ifconfig eth0 192.168.1.100 netmask 255.255.255.0
ip addr add 192.168.1.100/24 dev eth0
ifconfig eth0 down
ifconfig eth0 hw ether 00:11:22:33:44:55
ifconfig eth0 up
dhclient eth0
dig example.com
dig example.com mx
dig example.com ns
nslookup example.com
echo "nameserver 8.8.8.8" > /etc/resolv.conf
nano /etc/hosts
ping -c 4 target.com
traceroute target.com
netstat -tuln
ss -tuln
Phase 7: Process Management
Control running processes:
ps
ps aux
ps aux | grep nmap
top
htop
kill <PID>
kill -9 <PID>
killall processname
pkill -f pattern
command &
jobs
fg %1
bg %1
Ctrl+Z
nice -n 10 command
nice -n -10 command
renice 10 -p <PID>
Phase 8: Software Management
Install and manage packages:
apt update
apt upgrade
apt install <package>
apt remove <package>
apt purge <package>
apt search <keyword>
apt-cache show <package>
yum update
yum install <package>
yum remove <package>
dnf install <package>
git clone https://github.com/user/repo.git
cd repo
pip install -r requirements.txt
python setup.py install
Phase 9: Bash Scripting Basics
Create automation scripts:
#!/bin/bash
name="World"
echo "Hello, $name"
echo "Enter target IP:"
read target
echo "Scanning $target"
current_date=$(date)
ip_address=$(hostname -I)
if [ -f /etc/passwd ]; then
echo "File exists"
else
echo "File not found"
fi
for i in 1 2 3 4 5; do
echo "Number: $i"
done
for file in *.txt; do
echo "Processing: $file"
done
while [ $count -lt 10 ]; do
echo $count
count=$((count + 1))
done
Example scanner script:
#!/bin/bash
echo "Enter target network (e.g., 192.168.1):"
read network
echo "Scanning $network.0/24..."
for ip in {1..254}; do
ping -c 1 -W 1 $network.$ip > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "[+] Host alive: $network.$ip"
fi
done &
echo "Scan running in background"
Phase 10: Environment Variables
Manage system environment:
env
echo $PATH
set | more
export MYVAR="value"
PATH=$PATH:/new/path
echo 'export MYVAR="value"' >> ~/.bashrc
source ~/.bashrc
$HOME
$PATH
$USER
$SHELL
$PWD
$HISTSIZE
Quick Reference
Essential Commands
| Command | Purpose |
|---|
pwd | Print working directory |
ls -la | List all files detailed |
cd | Change directory |
cat | Display file contents |
grep | Search text |
find | Find files |
chmod | Change permissions |
ps aux | List processes |
kill | Terminate process |
File Permissions
| Value | Permission |
|---|
| 7 | rwx |
| 6 | rw- |
| 5 | r-x |
| 4 | r-- |
| 0 | --- |
Network Commands
| Command | Purpose |
|---|
ifconfig | Interface config |
ip addr | Show IP addresses |
netstat -tuln | Listening ports |
dig | DNS lookup |
ping | Test connectivity |
Constraints and Limitations
Permission Requirements
- Many commands require root/sudo
- File access depends on permissions
- Network operations may need elevated privileges
Best Practices
- Always backup before modifying system files
- Use test environments for learning
- Document changes made to systems
- Understand commands before executing
Troubleshooting
Permission Denied
Solutions:
- Use sudo for elevated privileges
- Check file permissions:
ls -la
- Verify user group membership
- Check for immutable attributes
Command Not Found
Solutions:
- Check if package is installed
- Verify PATH includes command location
- Use full path to binary
- Install missing package