-
Notifications
You must be signed in to change notification settings - Fork 6
/
telnet-listen.py
47 lines (37 loc) · 1.22 KB
/
telnet-listen.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
###############################################################################
### This example script will listhen on the port provided for an incomming ###
### telnet connections. Once a connection is successfully opened it will ###
### open an interactive session. ###
### Author: Conor Richard ###
###############################################################################
import socket
import telnetlib
import sys
import time
def getShell(host, port):
print("Listening for incomming connection on port: {port}".format(port = port))
time.sleep(1)
# Try to configure a socket and bind to the specified host
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('',port))
s.listen(5)
cli = s.accept()[0]
s.closed()
print('[+] Got connection back\n')
t = telnetlib.Telnet()
t.sock = cli
t.interact()
except:
print('Connection closed or something went wrong.')
sys.exit(-1)
def main():
# Host address to listen on, use empty string to
# listen on all addresses.
host = ''
# Port to listen on.
port = 443
getShell(host, port)
if __name__ == "__main__":
sys.exit(main())