Command Line
BASH Environment
Environment Variables
kali@kali:-$ echo $PATH
/usr/local/sbi n:/usr/local/bin:/usr/sbin:/usr/bin :/sbin:/bin
kali@kali:-$ echo $USER
kali
kali@kali:~$ echo $PWD
/home/kali
kali@kali:-$ echo $HOME
/home/kali
kali@kali:~$ export b=10.11.1.220
kali@ka1i:~$ ping -c 2 $b
PING 10.11.1.220 (10.11.1.220) 56(84) bytes of data.
64 bytes from 10.11.1.220: icmp_seq=l ttl=62 time=2.23 ms
64 bytes from 10.11.1.220: icmp_seq=2 ttl=62 time=l.56 ms
```
The export command makes the variable accessible to any subprocesses we might spawn
from our current Bash instance. If we set an environment variable without export
it will only be available in the current shell
```
kali @kali:~$ echo"$$"
1827
kali@ka1 i: ~$ var="My Var"
kali@kali:~$ echo $var
My Var
kali@kal i:~$ bash
kali@kali:-$ echo"$$"
1908
kali@kali:-$ echo $var
kali@kali: - $ exit
exit
kali@kali:~$ echo $var
My Var
kali@kali:~$ export othervar="Global Var"
kali@ka1i:~$ echo $othervar
Global Var
kali@kali:~$ bash
kali@kali:~$ echo $othervar
Global Var
kali@kali:-$ exit
exit
kali@kali:~$
#There are many other environment variables defined by default in Kali Linux.
#We can view these by running env at the command line:
kali@kali:~$ env
SHELL=/bin/bash
PWD=/home/kali
XDG_SESSION_DESKTOP=lightdm-xsession
LOGNAME=kali
XDG_SESSION_TYPE=xll
XAUTHORITY=/home/kal i/.Xauthority
XDG_GREETER_DATA_DIR=/var/lib/lightdm/data/kali
HOME= /home/kali
...
TERM=xterm-256color
USER=kali
...
History
kali@kali:~$ history
1 cat /etc/lsb-release
2 clear
3 history
kali@kali: ~$ !1
cat /etc/\sb-re\ease
DISTRIB_ID=Kali
DISTRIB_RELEASE=kali -rolling
DISTRIB_CODENAME=kali-rolling
DISTRIB_DESCRIPTION="Kali GNU/ Linux Rolling"
kali@kali:~$ sudo systemct restart apache2
kali@kal i :~$ !!
sudo systemctl restart apache2
kali@kali:~$
grep
#switches include -r for recursive searching and -i to ignore text case
kali@kali:-$ ls - la /usr/bin I grep zip
-rwxr-xr-x 3 root root 34480 Jan 29 2017 bunzip2
-rwxr-xr-x 3 root root 34480 Jan 29 2017 bzip2
-rwxr-xr-x 1 root root 13864 Jan 29 2017 bzip2recover
-rwxr-xr-x 2 root root 2301 Mar 14 2016 gunzip
-rwxr-xr-x 1 root root 105172 Mar 14 2016 gzip
sed
kali@kali:-$ echo "I need to try hard" I sed 's/hard/harder/'
I need to try harder
cut
kali@kali:-$ echo "I hack binades,web apps,mobile apps, and just about anything else"
|cut - f 2 - d ","
web apps
kali@kali:-$ cut -d ":" -f 1 /etc/passwd
root
daemon
bin
awk
kali@kali:~$ echo "hetto::there::friend" I awk -F "::" '{print $1, $3}'
hello friend
vi Editor
To disable insert-text mode and go back to command mode, press the IEscl key. While in command mode, use dd to delete the current line, yy to copy the current line, p to paste the clipboard contents, x to delete the current character, : w to write the current file to disk and stay in vi, : q ! to quit without writing the file to disk, and finally :wq to save and quit.
comm
The comm command66 compares two text files, displaying the lines that are unique to each one, as well as the lines they have in common. It outputs three space-off set columns: the first contains lines that are unique to the first file or argument; the second contains lines that are unique to the second file or argument; and the third column contains lines that are shared by both files. The -n switch, where «n• is either 1, 2, or 3, can be used to suppress one or more columns, depending on the need. Let's take a look at an example:
kali @kali:~$ cat s can-a.txt
192.168.1.l
192 .168 .1. 2
192.168.1.3
192.168.1.4
192 .168 .1. 5
kali@kali:~$ cat scan-b.txt
192.168.1.l
192 .168.1.3
192.168.1.4
192.168.1.5
192.168.1.6
kali@kali:~$ comm scan-a.txt scan-b.txt
192.168.l.l
192.168.l.2
192 .168. l. 6
192.168.l.3
192.168.l.4
192.168.l.5
kali@kali:~$ comm -12 scan-a.txt scan-b.txt
192.168.1.1
192.168.1.3
192 .168 .1.4
192.168 .1.5
diff
kali@kali:~$ diff -c scan-a.txt scan-b.txt
*** scan-a.txt 2018-02-07 14:46:21.557861848 -0700
--- scan-b.txt 2018-02-07 14:46:44.275002421 -0700
***************
*** 1,5 ****
192.168.l.l
- 192.168.l.2
192.168.l.3
192.168.l.4
192 .168. l. 5
--- 1,5 ----
192.168.l.1
192.168.l.3
192.168.l.4
Managing Process
#Backgrounding Processes (bg)
kali@kali:~$ ping -c 488 tocalhost > ping_resutts.txt &
OR
kali @kali:~$ ping -c 488 tocalhost > ping_resutts.txt
"Z
[1]+ Stopped ping -c 400 localhost > ping_results.txt
kali@kal i :~$ bg
[1]+ ping -c 400 localhost > ping_results.txt
kali @kali:~$
#Jobs Control:jobs and fg
kali@kali:-$ ping - c 488 tocathost > pi ng_res utts .txt
"Z
[l]+ Stopped ping -c 400 localhost > ping_results.txt
kali@kali:-$ find / -name s bd.exe
"Z
[2]+ Stopped find/ -name sbd.exe
kali@ka1i:-$ jobs
(1)- Stopped
[2]+ Stopped
kali@kali:~$ fg %1
ping -c 400 localhost > ping_results.txt
find/ -name sbd.exe
ping -c 400 localhost > ping_results.txt
"C
kali@ka1i:~$ jobs
[2]+ Stopped
kali@kali:-$ fg
find/ -name sbd.exe
find/ -name sbd.exe
/usr/share/windows-resources/sbd/sbd.exe
ps and kill
kali @kali:-$ ps -ef
UID PIO PPID C STIME TTY TIME CMD
root 1 0 0 10:18 ? 00:00:02 /sbin/init
root 2 0 0 10:18 ? 00:00:00 [kthreadd]
root 3 2 0 10:18 ? 00:00:00 [rcu_gp]
root 4 2 0 10:18 ? 00:00:00 [rcu_par_gp]
root s 2 0 10:18 ? 00:00:00 [kworker/0:0-events)
root 6 2 0 10:18 ? 00:00:00 [kworker/0:0H-kblockd]
root 7 2 0 10:18 ? 00:00:00 [kworker/u256:0-events_unbound
root 8 2 0 10:18 ? 00:00:00 [mm_percpu_wq]
root 9 2 0 10:18 ? 00:00:00 [ksofti rqd/0]
root 10 2 0 10:18 ? 00:00:00 [rcu_sched]
The -ef73 options we used above stand for: e: select all processes f: display full format listing (UID, PID, PPID, etc.)
kali @kali:-$ ps -fc \eafpad
UID PIO PPID C STIME TTY
kali 1307 938 0 10:57?
TIME CMD
00:00:00 leafpad
kali@kali:-~ kill 1387
kali@kali:-$ ps aux I grep leafpad
kali 1313 0.0 0.0 6144 888 pts/0 S+ 10:59 0:00 grep leafpad
File and Command Monitoring
tail
kali@kali:-$ sudo tail -f /var/ log/ apache2/ access .log
127.0.0.1 - - [02/Feb/2018:12:18:14 -0500) "GET / HTTP/1.1" 200 3380 "-" "Mozilla/5.0
(Xll; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.011
127.0.0.1 - - [02/ Feb/2018:12:18:14 -0500] "GET /icons/openlogo-75.png HTTP/1.l" 200 6
040 "http://127.0.0. l /" "Mozilla/5.0 (Xll; Linux x86_64; rv:52.0) Gecko/20100101 Firef
ox/52.0"
127.0.0.1 - - [02/Feb/2018:12:18:15 -0500) "GET /favicon.ico HTTP/1.l" 404 500 "-" "Mo
zilla/5.0 (Xll; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.011
watch
kali@kali:-$ watch -n 5 w
Every 5.0s: w kali: Tue Jan 23 21:06:03 2018
21:06:03 up 7 days, 3:54, 1 user, load average: 0.18, 0.09, 0.03
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
kali tty2 :0 16Jan18 7days 16:29 2.51s /usr/bin/python
Downloading Files
#WGET
kali@kali :~$ wget -o report_wget.pdf https:// www.offensive-security.com/reports/penetration-testing-sampte-report-2813.pdf
#CURL
kali@kali:-$ curl -o report.pdf https://www.offensive-security.com/reports/penetration-testing-sampte-report-2813.pdf
#axel
kali@kali :~$ axet -a -n 28 -o report_axel.pdf https://www.offensive-security.com/reports/penetration-testing-sample-report-2813.pdf
Last updated