Kali Linux Penetration Testing Bible. Gus Khawaja
Чтение книги онлайн.
Читать онлайн книгу Kali Linux Penetration Testing Bible - Gus Khawaja страница 14
To view the current user information, use the id
command:
Gus@kali:~$ id uid=1001(Gus) gid=1001(Gus) groups=1001(Gus),27(sudo)
To list the currently logged on users, use w
or who
(with fewer details):
Gus@kali:~$ w 10:44:06 up 19 min, 1 user, load average: 0.00, 0.00, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root tty7 :0 10:24 19:55 2.36s 2.36s /usr/lib/x Gus@kali:~$ who root tty7 2020-09-22 10:24 (:0)
To remove a user (the user that we will remove in this example is test
), execute the userdel
command:
$userdel [user name – that you want to delete] Gus@kali:~$ sudo userdel test
To list the last logged in users in the Kali system, use the last
command:
Gus@kali:~$ last root tty7 :0 Tue Sep 22 10:24 still logged in reboot system boot 5.7.0-kali1-amd6 Tue Sep 22 10:24 still running root tty8 :1 Tue Sep 22 10:21 - 10:23 (00:02) kali pts/1 tmux(1793).%0 Mon Sep 21 12:16 - 10:23 (22:07) kali pts/2 tmux(1584).%0 Mon Sep 21 11:48 - 11:48 (00:00) kali tty7 :0 Mon Sep 21 10:50 - 10:23 (23:33) reboot system boot 5.7.0-kali1-amd6 Mon Sep 21 10:50 - 10:23 (23:33) kali tty7 :0 Mon Jul 27 13:36 - 15:56 (02:20) reboot system boot 5.7.0-kali1-amd6 Mon Jul 27 13:36 - 15:57 (02:20) kali tty7 :0 Mon Jul 27 13:31 - crash (00:05) reboot system boot 5.7.0-kali1-amd6 Mon Jul 27 13:30 - 15:57 (02:26) kali tty7 :0 Mon Jul 27 13:28 - crash (00:02) reboot system boot 5.7.0-kali1-amd6 Mon Jul 27 13:28 - 15:57 (02:28) wtmp begins Mon Jul 27 13:28:09 2020
Finally, take note that all the users in Kali are stored in a configuration file, /etc/passwd
. Use the cat
command to reveal its contents:
Gus@kali:~$ cat /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin
The previous command will list all the users, even the system ones (the example just shows the first three). To filter the contents and limit the results for the human users, pipe the output using |
in the grep
command:
Gus@kali:~$ cat /etc/passwd | grep "/bin/bash" root:x:0:0:root:/root:/bin/bash postgres:x:119:124:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash kali:x:1000:1000:kali,,,:/home/kali:/bin/bash Gus:x:1001:1001::/home/Gus:/bin/bash
Groups Commands
To add a new group in Kali Linux, use the groupadd
command:
$groupadd [new group name] Gus@kali:~$ sudo groupadd hackers
To join a user (which is Gus for this example) to the hackers
group that we created earlier, execute the usermod
command:
$usermod -aG [group name] [user name] Gus@kali:~$ sudo usermod -aG hackers Gus
To list all the groups created in Kali Linux, open the file /etc/group
. Again, use the cat
command to get the job done (the following example shows only the first three):
Gus@kali:~$ cat /etc/group root:x:0: daemon:x:1: bin:x:2: […] hackers:x:1002:Gus
Managing Passwords in Kali
You probably want your root user back like in the old days. To get this account back, you will need to set its password first. To change a user password, you have to use the passwd
command:
Gus@kali:~$ sudo passwd root New password: Retype new password: passwd: password updated successfully
Now to use the powerful root account, you have to use the su
command to switch user:
Gus@kali:~$ sudo su root root@kali:/home/Gus#
From now on, on the login screen, you can choose your root account instead of your nonroot user.
Finally, to list all the user's credentials in Kali Linux, you can reveal them in the file /etc/shadow
. Use the grep
command to get the user credentials for Gus:
root@kali:/# cat /etc/shadow | grep "Gus" Gus:$6$Hb.QBfIoaCBTiqK$EUJ4ZdWmbsFqHMsPbMEz2df6FtWVf4J/tMulxCoLQmfMlVWyqpMUHBGmHFulRknYHgSrFIF.hQTANgzJ6CQM8/:18527:0:99999:7:::
Let's simplify what you need to understand from the string. The delimiter that separates each section is the colon character (:).
Second, the $6$
means that the password is hashed using SHA‐512. Finally, the hashed password starts after $6$
and right before the : delimiter:
Hb.QBfIoaCBTiqK$EUJ4ZdWmbsFqHMsPbMEz2df6FtWVf4J/tMulxCoLQmfMlVWyqpMUHBGmHFulRknYHgSrFIF.hQTANgzJ6CQM8/
Files and Folders Management in Kali Linux
Your next challenge in the Linux operating system is to learn how to manage files and folders. By the end of this section, you will start using the files and directories on Kali like the pros.
Displaying Files and Folders
To list the files and subfolders inside any directory, use the ls
command to get the job done (I use it a lot to get simpler output). But sometimes, the ls
command by itself is not enough, so you may need to add a couple of options to get better output clarity. The first option that you can use is the ‐a
command (all contents including hidden files), and the second option is the ‐l
command (formatted list):
root@kali:~# ls Desktop Documents Downloads Music Pictures Public Templates Videos root@kali:~# ls -la total 144 drwx------ 14 root root 4096 Sep 22 10:24 . drwxr-xr-x 19 root root 36864 Jul 27 15:41 .. -rw------- 1 root root 155 Sep 22 10:23 .bash_history -rw-r--r-- 1 root root 570 Jul 18 17:08 .bashrc drwx------ 6 root root 4096 Sep 22 11:21 .cache drwxr-xr-x 8 root root 4096 Sep 22 10:22 .config drwxr-xr-x 2 root root 4096 Sep 22 10:21 Desktop -rw-r--r-- 1 root root 55 Sep 22 10:21 .dmrc drwxr-xr-x 2 root root 4096 Sep 22 10:21 Documents drwxr-xr-x 2 root root 4096 Sep 22 10:21 Downloads -rw-r--r-- 1 root root 11656 Jul 27 13:22 .face lrwxrwxrwx 1 root root 11 Jul 27 13:22 .face.icon -> /root/.face drwx------ 3 root root 4096 Sep 22 10:24 .gnupg -rw------- 1 root root 306 Sep 22 10:24 .ICEauthority drwxr-xr-x 3 root root 4096 Sep 22 10:21 .local drwxr-xr-x 2 root root 4096 Sep 22 10:21 Music drwxr-xr-x 2 root root 4096 Sep 22 10:21 Pictures -rw-r--r-- 1 root root 148 Jul 18 17:08 .profile drwxr-xr-x 2 root root 4096 Sep 22 10:21 Public drwxr-xr-x 2 root root 4096 Sep 22 10:21 Templates drwxr-xr-x 2 root root 4096 Sep 22 10:21 Videos -rw------- 1 root root 98 Sep 22 10:24 .Xauthority -rw------- 1 root root 5961 Sep 22 10:24 .xsession-errors -rw------- 1 root root 6590 Sep 22 10:23 .xsession-errors.old root@kali:~#
Take note that filenames that start with a dot character before their names mean that they are hidden (e.g., .bash_history
). Also, at the far left before the permissions, the letter d
means it's a directory and not a file. Finally, you can list another directory's contents differently than the current one by specifying the path of the destination folder:
$ls -la [destination directory path]
Permissions
For