Kali Linux Penetration Testing Bible. Gus Khawaja
Чтение книги онлайн.
Читать онлайн книгу Kali Linux Penetration Testing Bible - Gus Khawaja страница 16
root@kali:/# $PATH bash: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin: No such file or directory
Let's look at a practical example; I saved the test.sh
file in my home directory. Since the home folder is not in the $PATH
variable, this means that I can execute it only if I specify the path or else it will fail:
root@kali:~# test.sh bash: test.sh: command not found root@kali:~# ./test.sh test
Another useful command to find files with more flexible options is the find
command. The advantage of using the find
tool is that it allows adding more granular filters to find what you're looking for. For example, to find file1.txt
under the root home directory, use this:
root@kali:~# find /root -name "file1.txt" /root/temp/file1.txt
Let's say you want to list the large files (1GB+) in your system:
root@kali:~# find / -size +1G 2> /dev/null /proc/kcore
TIP
Appending 2> /dev/null
to your command will clean the output results and filter out errors.
The following is a convenient find filter that searches for setuid
files in Linux for privilege escalation (you will learn all the details in Chapter 10, “Linux Privilege Escalation”):
$ find / -perm -u=s -type f 2>/dev/null
Files Compression
There are multiple ways (compression algorithms) to compress files; the ones that I will cover in this section are the .tar
, .gz
, .bz2
, and .zip
extensions.
Here's the list of commands to compress and extract different types of archives:
Tar Archive
To compress using tar extension:$tar cf compressed.tar files
To extract a tar compressed file:$tar xf compressed.tar
Gz Archive
To create compressed.tar.gz from files:$tar cfz compressed.tar.gz files
To extract compressed.tar.gz:$tar xfz compressed.tar.gz
To create a compressed.txt.gz file:$gzip file.txt> compressed.txt.gz
To extract compressed.txt.gz:$gzip -d compressed.txt.gz
Let's extract the rockyou.txt.gz
file that comes initially compressed in Kali:
root@kali:~# gzip -d /usr/share/wordlists/rockyou.txt.gz
Bz2 Archive
To create compressed.tar.bz2 from files:$tar cfj compressed.tar.bz2 files
To extract compressed.tar.bz2:$tar xfj compressed.tar.bz2
Zip Archive
To create compressed.zip from files:$zip compressed.zip files
To extract compressed.zip files:$unzip compressed.zip
Manipulating Directories in Kali
To print the current working directory, you must use the pwd
command to get the job done (don't mix up the pwd
command with passwd
command; they're two different things):
$pwd
To change the current working directory, you must use the cd
command:
$cd [new directory path]
You can use ..
to traverse one upward directory. In fact, you can add as much as you want until you get to the system root folder, /
:
root@kali:~/Documents# pwd /root/Documents root@kali:~/Documents# cd ../../ root@kali:/# pwd /
As a final hint, for the cd
command, you can use the ~
character to go directly to your current user home directory:
$cd ~
To create a directory called test
in the root home folder, use the mkdir
command:
$mkdir [new directory name]
To copy, move, and rename a directory, use the same command for the file commands. Sometimes you must add the ‐r
(which stands for recursive) switch to involve the subdirectories as well:
$cp -r [source directory path] [destination directory path] $mv -r [source directory path] [destination directory path] $mv -r [original directory name] [new directory name]
To delete a folder, you must add the ‐r
switch to the rm
command to get the job done:
$rm -r [folder to delete path]
Mounting a Directory
Let's see a practical example of how to mount a directory inside Kali Linux. Let's suppose you inserted a USB key; then mounting a directory is necessary to access your USB drive contents. This is applicable if you disabled the auto‐mount feature in your settings (which is on by default in the Kali 2020.1 release).
Figure 1.7 USB Mount
To mount a USB drive, follow these steps:
1 Display the disk list using the lsblk command.
2 Create a new directory to be mounted (this is where you will access the USB stick drive).
3 Mount the USB drive using the mount command.
Figure 1.8 Mount Using the Command Line
Now, to eject the USB drive, use the umount
command to unmount the directory:
root@kali-laptop-hp:~# umount /mnt/usb
Managing Text Files in Kali Linux
Knowing how to handle files in Kali Linux is something that you'll often encounter during your engagements. In this section, you will learn about