Kali Linux Penetration Testing Bible. Gus Khawaja

Читать онлайн книгу.

Kali Linux Penetration Testing Bible - Gus Khawaja


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

      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):

      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 the permissions, the same principle applies to a file or a directory. To simplify it, the permissions are divided into three categories:

       Read ( r ): 4

       Write ( w ): 2

       Execute ( x ): 1

      The permissions template applies the following pattern:

      Figure 1.6 Kali Linux – Files and Folders Commands

      Let's look at a practical example. Lat's say you created a simple shell script that prints “test” (using the echo command) and that you wanted display its permissions (take note that this example uses the root user inside the terminal window):

      root@kali:~# echo 'echo test'> test.sh root@kali:~# ls -la | grep 'test.sh' -rw-r--r-- 1 root root 10 Sep 22 11:25 test.sh root@kali:~#

      From the previous output results, we can see the following:

       For the root user, you can read and write because of rw at the beginning.

       For the root group, they can only read this file.

       For everyone else on the system, they can only read as well.

      Let's say you want to execute this file, since you're the one who created it and you're the master root. Do you think you'll be able to do it (according to the previous permissions for the root user)?

      root@kali:~# ./test.sh bash: ./test.sh: Permission denied

      TIP

       The dot in the previous example means the current directory.

      Indeed, the root has no permission to execute it, right? To change the permissions of the previous file based on the formula ( r =4, w =2, and x =1), use this:

       User:4+2+1=7; Group:4+2+1=7; Everyone:4

      Then, use the chmod command to get the job done (this time, you should be able to execute the shell script):

      $chmod [permissions numbers] [file name] root@kali:~# chmod 774 test.sh root@kali:~# ls -la | grep 'test.sh' -rwxrwxr-- 1 root root 10 Sep 22 11:25 test.sh root@kali:~# ./test.sh test root@kali:~#

      There is another shortcut for this, which allows the execution of a file instead of calculating the numbers of each. We just need to add +x to the chmod command (but be careful because when you execute this one, you will be giving the execution permission to everyone as well):

      $chmod +x [file name] root@kali:~# chmod +x test.sh root@kali:~# ls -la | grep 'test.sh' -rwxrwxr-x 1 root root 10 Sep 22 11:25 test.sh

      Manipulating Files in Kali

      $touch [new file]

      To insert text quickly into a file, you can use the echo command. Later in this chapter, you will learn how to edit text files with a text editor:

      $echo 'text to add'> [file name]

      To know a file type in a Linux system, you must use the file command:

      $file [file name]

      Let's assemble all the commands together in the terminal window:

      root@kali:~# touch test.txt root@kali:~# echo test> test.txt root@kali:~# file test.txt test.txt: ASCII text

      To copy a file in Kali, you must use the cp command to get the job done:

      $ cp [source file path] [destination file path] root@kali:~# cp test.txt /home/kali root@kali:~# ls /home/kali Desktop Downloads Music Public test.sh Videos Documents ls_file.txt Pictures Templates test.txt

      To move a file that is equivalent to cut in Windows OS, you must use the mv command:

      $mv [source file path] [destination file path] root@kali:~# mv test.txt Documents/ root@kali:~# ls Documents/ test.txt

      To delete the file that we just copied earlier in the kali home directory, use the rm command:

      To rename the previous file, we use the same mv command that we used to move a file:

      $mv [original file name] [new file name] root@kali:~/Documents# mv test.txt hello.txt root@kali:~/Documents# ls hello.txt

      Searching for Files

      There are multiple ways to search for files in Kali; the three common ones are the locate , find , and which commands.

      You can use the locate command to locate a file that you're looking for quickly. You need to know that the locate command stores its data in a database, so when you search, you will find your results faster.

      First, you will need to update the database for the locate command using the updatedb command:

      $updatedb

      Now, we can start searching using the locate command:

      $locate [file name] root@kali:/# locate test.sh /home/kali/test.sh /usr/share/doc/socat/examples/readline-test.sh /usr/share/doc/socat/examples/test.sh


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