-
Notifications
You must be signed in to change notification settings - Fork 14
/
listener.py
executable file
·28 lines (24 loc) · 1.24 KB
/
listener.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/python3
from socket import *
HOST = '' # '' means bind to all interfaces.
PORT = 4444 # Port.
s = socket(AF_INET, SOCK_STREAM) # Create our socket handler.
s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) # Set is so that when we cancel out we can reuse port.
try:
s.bind((HOST, PORT)) # Bind to interface.
print("[*] Listening on 0.0.0.0:%s" % str(PORT)) # Print we are accepting connections.
s.listen(10) # Listen for only 10 unaccepted connections.
conn, addr = s.accept() # Accept connections.
print("[+] Connected by", addr) # Print connected by ipaddress.
data = conn.recv(1024).decode("UTF-8") # Receive initial connection.
while 1: # Start loop.
command = input("arm0red> ") # Enter shell command.
conn.send(bytes(command, "UTF-8")) # Send shell command.
if command == "quit" or "exit":
break # If we specify 'quit' or 'exit', then break out of loop and close socket.
data = conn.recv(1024).decode("UTF-8") # Receive output from command.
print(data) # Print the output of the command.
except KeyboardInterrupt:
print("...listener terminated using [ctrl+c], Shutting down!")
exit() # Using [ctrl+c] will terminate the listener.
conn.close() # Close socket.