Kali Linux Penetration Testing Bible. Gus Khawaja

Читать онлайн.
Название Kali Linux Penetration Testing Bible
Автор произведения Gus Khawaja
Жанр Зарубежная компьютерная литература
Серия
Издательство Зарубежная компьютерная литература
Год выпуска 0
isbn 9781119719076



Скачать книгу

can use the ‐n switch for the locate command to filter out the number of output results. This option is handy if you know that the results will be enormous:

      $locate -n [i] [search file criteria] root@kali:/# locate *.conf -n 3 /etc/adduser.conf /etc/ca-certificates.conf /etc/debconf.conf

      TIP

      Use the grep command to get more granular results.

      To find an application path, use the which command. This command will use the $PATH environment variable to find the results that you're looking for. As an example, to find where Python is installed, you can do the following:

      It's important to understand that a Linux system will use $PATH to execute binaries. If you run it in the terminal window, it will display all the directories where you should save your programs/scripts (if you want to execute them without specifying their path):

      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.

      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

Snapshot of USB Mount.

      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.

Snapshot of 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