Название: Kali Linux Penetration Testing Bible
Автор: Gus Khawaja
Издательство: John Wiley & Sons Limited
Жанр: Зарубежная компьютерная литература
isbn: 9781119719076
isbn:
To clear the terminal window text, execute the clear
command or press Ctrl+L to get the job done.
To open a new terminal window tab, from your current terminal session press Ctrl+Shift+T.
To complete the input (e.g., a filename or a command name) automatically, I use the Tab key. What if multiple files start with the same text? Then, if you hit Tab twice, the terminal window will display all the options in place. (The best way to understand this chapter is to open the terminal window and practice while reading the instructions.)
Let's look at an example. In my home directory, I have two files, test.sh
and test.txt
. Once I start typing cat tes
, I hit Tab once, and it shows me cat test.
. This means I have multiple files with the same name. Then I hit Tab twice, and it shows me the list of files in the current directory. Finally, I can open the desired file, which is test.txt
:
root@kali:~# cat test. Test.sh test.txt root@kali:~ cat test.txt test
To stop the execution of any tool while it's running, you can use the Ctrl+C shortcut to stop it.
To exit the terminal window and close it, use the exit
command or press Ctrl+D to get the job done.
To restart Kali Linux from the terminal window, you must use the reboot
command, and to shut it down, you must use the poweroff
command.
Now, to get the list of executed recent commands, you'll have to use the history
command.
In Linux, you must understand that we use a lot of redirection in the terminal window. For example, to save the output of the ls
command into a file, I can redirect the output from the terminal window to a text file using the >
(greater than) character:
kali@kali:~$ ls> ls_file.txt kali@kali:~$ cat ls_file.txt Desktop Documents Downloads ls_file.txt Music Pictures Public Templates Videos
Now, you can do the opposite by redirecting (printing) the text file contents into the terminal window using the <
(less than) character:
kali@kali:~$ cat < ls_file.txt Desktop Documents Downloads ls_file.txt Music Pictures Public Templates Videos
Another redirection that you need to be aware of is the commands pipe. In summary, you can combine the output of each command and send it to the next one using the |
character:
$command 1 | command2 | command3 …
For example, I will read a file, then sort the results, and finally use the grep
command to filter out some text strings (the goal is to extract the files that start with the word test):
kali@kali:~$ cat ls_file.txt | sort | grep test test.sh test.txt
Tmux Terminal Window
Tmux is a particular terminal window that allows you to manage multiple windows in your current terminal session. The best way to explain it is through examples.
Starting Tmux
To start Tmux, you just type Tmux
in your terminal window. At the bottom of your terminal window, you'll notice that a number and a name have been assigned to your opened window tab, as shown in Figure 1.1.
Figure 1.1 Tmux New Window
So what? Let's say you're in an engagement and you want to run Nmap in one window, plus run Metasploit in another one, and so on. This is where Tmux is handy, because you can work on multiple windows/sessions at the same time.
Tmux Key Bindings
In Tmux, you must use Ctrl+B to instruct it that you want to execute a Tmux action (command). In fact, the key combination Ctrl+B is the default one. You can always change the default configurations of Tmux in the configuration file. To change this behavior and assign Ctrl+A instead of Ctrl+B, then you must create the config file yourself for the first time. To get the job done, you have two options for creating a config file in Tmux. The first way is to add a user‐specific file called ~/.tmux.conf
, and the second way is to add a global file (to all users) under /etc/tmux.conf
. In my case (for this example), I will add the configuration file under /etc/tmux.conf
(and I will add the configurations for the key bindings in it):
root@kali:/# touch /etc/tmux.conf root@kali:/# echo unbind C-b>> /etc/tmux.conf root@kali:/# echo set -g prefix C-a>> /etc/tmux.conf root@kali:/# echo bind C-a send-prefix>> /etc/tmux.conf
Tmux Session Management
In Figure 1.1, you can see that the name bash
has been assigned automatically to your current session.
Window Rename
To rename the session, press Ctrl+B first (or Ctrl+A if you made the changes in the config files that we did previously). Then remove your fingers from the keyboard and press the comma (,) key on your keyboard. You should see that the prompt has changed to allow you to rename it. I will call it Window1; then press Enter after finishing the task:
(rename-window) Window1
Window Creation
At this stage, we have only one window, so let's create a second one by pressing Ctrl+B and then pressing the C key. Looking at the bottom, you'll see you have a new bash window, and Tmux has already highlighted the current tab with an asterisk (*), as shown in Figure 1.2.
Figure 1.2 New Tmux Highlighted Tab
Splitting Windows
To split the selected tab into two subwindows side by side, as shown in Figure 1.3, you must press Ctrl+B and then enter the % character on your keyboard (remember that you need to press Shift+% or else it will be considered 5 on your keyboard).