forked from jullrich/dshieldhoneypot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtelnetHP-withSMTP.py
More file actions
121 lines (112 loc) · 3.16 KB
/
telnetHP-withSMTP.py
File metadata and controls
121 lines (112 loc) · 3.16 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import socket, time
def writelog(client, data=''):
separator = '='*40
fopen = open('potlog.txt', 'a')
fopen.write('Time:%s,IP Address:%s,Port:%d,%s'%(time.ctime(), client[0], client[1], data))
fopen.close()
def smtphp():
ListenPort = 25
serversocket = socket.socket(
socket.AF_INET, socket.SOCK_STREAM)
serversocket.bind((socket.gethostname(), ListenPort))
serversocket.listen(5)
while 1:
print "\n[*] Listening on port ", ListenPort
conn, address = serversocket.accept()
print "\n[*] Connection from ", address
data = ""
try:
conn.send("220 computer ESMTP Server (Microsoft Exchange Internet Mail Service 4.0.994.63) ready\r\n")
except:
conn.close()
while 1: #While the connection's open, accept commands and respond appropriately
try:
temp = conn.recv(1000000)
data = data + temp
except KeyboardInterrupt:
print '\n\n[+] Exiting...'
exit(0)
break
except socket.error, e:
writelog(address)
except:
writelog(address, data)
conn.close()
if temp.count("HELO"):
conn.send("250 computer\r\n")
elif temp.count("EHLO"):
conn.send("250 computer\r\n")
elif temp.count("MAIL"):
conn.send("250 Sender OK\r\n")
elif temp.count("RCPT"):
conn.send("250 Recipient OK.\r\n")
elif temp.count("RSET"):
conn.send("250 Ok resetting state\r\n")
elif temp.count("DATA"):
conn.send("354 Ok Send data ending with <CRLF>.<CRLF>\r\n")
elif temp.count("."):
conn.send("250 Message received\r\n")
elif temp.count("QUIT"):
conn.send("221 computer ESMTP server closing connection\r\n")
writelog(address, data)
break
elif temp.count("HELP"):
conn.send("""
214-Commands:\r
214- HELO EHLO MAIL RCPT DATA\r
214- RSET NOOP QUIT HELP VRFY\r
214- EXPN\r """)
elif temp.count("VRFY"):
conn.send("250\r\n")
elif temp.count("NOOP"):
conn.send("250\r\n")
elif temp.count("EXPN"):
conn.send("250\r\n")
elif temp == "":
break
def getstuff():
banner = raw_input('\nEnter banner information: ')
host = raw_input('Enter IP Address: ')
while True or hp != null:
try:
port = int(raw_input('Enter Port Number: '))
except TypeError:
print '\n[-] Error: invalid port number\n'
continue
else:
if (port < 1) or (port > 65535):
print '\n[-] Error: invalid port number\n'
continue
else:
return (banner, host, port)
def main(host, port, banner):
if port == 25:
hp = raw_input('Port 25 selected - do you want to initiate SMTP-Honeypot?')
if hp in ("Y","y", "Yes", "Yea", "Si", "go", "Aye", "Sure"):
smtphp()
else:
print '\n[*] Initating telnet honeypot .... \n[*] Listening ...\n'
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))
s.listen(100)
while True:
(insock, address) = s.accept()
print '[*] Connection from: %s:%d' % (address[0], address[1])
try:
insock.send('%s\n'%(banner))
data = insock.recv(1024)
insock.close()
except socket.error, e:
writelog(address)
else:
writelog(address, data)
if __name__=='__main__':
try:
stuff = getstuff()
main(stuff[1], stuff[2], stuff[0])
except KeyboardInterrupt:
print '\n\n[+] Exiting...'
exit(0)
except BaseException, e:
print '\n[-] Error: %s' % (e)
exit(1)