-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple-telnet-deception.py
54 lines (52 loc) · 2.01 KB
/
simple-telnet-deception.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
48
49
50
51
52
53
54
#!/usr/bin/env python3
# purpose: Mimics a simple telnet daemon login prompts and records output
# starts a tcp listener on port and address with variables defined below
# author: Raresteak
# date: 6 October 2021
# version: 3
import datetime
import socket
HOST = '127.0.0.1'
PORT = 2323
FILE = "stn-results.json"
fh = open(FILE, "a")
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((HOST, PORT))
s.listen()
while True:
conn, addr = s.accept()
with conn:
timeNow = datetime.datetime.now()
conn.send(b'Warning: Telnet is not a secure protocol, and it is recommended to use Stelnet.\n\nLogin authentication\n\n\nUsername: ')
username = ""
while True:
data = conn.recv(1024)
if not data:
break
else:
try:
username = data.decode("utf-8").rstrip()
except UnicodeDecodeError:
username = "cancelledInput"
conn.send(b'Password: ')
password = ""
while True:
data = conn.recv(1024)
if not data:
break
else:
try:
password = data.decode("utf-8").rstrip()
except UnicodeDecodeError:
password = "cancelledInput"
conn.sendall(b'\b \b')
break
break
output = str("{ \"time\": \""
+ timeNow.strftime('%Y-%m-%dT%H:%M:%S')
+ "\", \"src.ip\": \"" + addr[0]
+ "\", \"username\": \"" + username
+ "\", \"password\": \"" + password + "\" }")
print(output)
fh.write(output + "\n")