-
Notifications
You must be signed in to change notification settings - Fork 8
/
kippo-scan.py
executable file
·214 lines (178 loc) · 5.98 KB
/
kippo-scan.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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/bin/env python
import argparse
import socket
import pexpect
import sys
import time
import re
import os
def banner():
print "--== Kippo Scanner ==--"
print " By: Metacortex"
print " DC801"
def args():
parser = argparse.ArgumentParser(description="--== Kippo Scanner ==--", usage="./kipposcan.py [options]")
parser.add_argument('-f', '--file', help='Specify a list of IPs and Ports in a file. Needs to be a single line consisiting of \"IP:Port\"', action='store', dest='file')
parser.add_argument('-i', '--ip', help='IP Address of a suspected Kippo Honeypot', action='store', dest='ip')
parser.add_argument('-p', '--port', help='Port of the suspected Kippo Honeypot', action='store', dest='port', default=22)
parser.add_argument('-v', '--verbose', help='Turns on verbose mode', action='store_true', dest='verbose')
parser.add_argument('-w', '--write', help='Write the sucessful results to file', action='store', dest='writefile')
global args
args = parser.parse_args()
if not args.ip and not args.file:
parser.print_help()
print "\n[!] You must specifiy either IP address or file of IP addresses"
sys.exit(0)
if args.ip and args.file:
parser.print_help()
print "\n[!] Can not specify both filename and IP address. Its one or the other"
sys.exit(0)
def parsefile(ipfile):
f = open(ipfile, "r")
for line in f:
if ":" in line:
ip = line.split(":", 1)[0]
portstr = line.split(":", 1)[1]
port = int(portstr)
if args.verbose == True:
print "[+] Checking: " + ip + ":" + str(port)
tests(ip, port)
if not ":" in line:
ip = line.strip()
if args.verbose == True:
print "[+] Checking: " + ip + ":22"
tests(ip, 22)
f.close()
def tests(ip, port):
global score
score = 0
if args.verbose == True:
print "[+] Test 1: Banner Grab"
bannergrab(ip, port)
if args.verbose == True:
print "[+] Test 2: Protocol mismatch"
test_protocolmismatch(ip,port)
if args.verbose == True:
print " [+] Score after Test 1: " + str(score)
# if args.verbose == True:
# print "[+] Test 3: Attempting login"
# login(ip,port)
report(ip, port)
def bannergrab(ip, port):
global score
if args.verbose == True:
print " [+] Making raw socket connect to " + ip + ":" + str(port)
s = socket.socket()
s.settimeout(10)
try:
s.connect((ip, port))
reply = s.recv(30)
print " [+] Banner we got was: "
print " " + reply.strip()
s.close()
if "SSH-2.0-OpenSSH_5.1p1 Debian-5" in reply:
print " [+] Banner was consistent with Kippo"
score += 50
else:
print " [-] Banner was not consistent with Kippo"
except Exception, e:
print e
def test_protocolmismatch(ip, port):
global score
command = "DC801"
if args.verbose == True:
print " [+] Making raw socket connect to " + ip + ":" + str(port)
s = socket.socket()
try:
s.connect((ip, port))
s.settimeout(10)
reply = s.recv(512)
if reply:
if args.verbose == True:
print " [+] Banner we got was: "
print " " + str(reply).strip()
if args.verbose == True:
print " [+] Sending non SSH traffic"
s.send(command*50)
s.send("\n")
reply = s.recv(512)
if "Protocol mismatch" not in reply:
if args.verbose == True:
print " [+] Did not give us \"protocol mismatch\" error"
print " [+] This is irregular"
score += 100
if "Protocol mismatch" in reply or len(reply) == 0:
if args.verbose == True:
print " [-] Gave us \"protocol mismatch\" error or nothing back."
print " [-] Seems to be a real SSH daemon"
except Exception, e:
print e
def login(ip,port):
global score
spawncmd = "ssh -p " + str(port) + " root@" + ip
p = pexpect.spawn(spawncmd)
log = file('pexpect.log','wb')
p.logfile = log
i = p.expect(['Are you sure you want to continue connecting', '.*[Pp]assword.*', pexpect.EOF])
if i == 0:
p.sendline('yes')
i = p.expect(['Are you sure you want to continue connecting', '.*[Pp]assword.*', pexpect.EOF])
if i == 1:
p.sendline("123456")
p.expect(".*")
if i == 2:
if arg.verbose == True:
print "[!] Error connecting"
sys.exit(0)
p.expect(".*")
p.sendline('\003')
p.sendline('\003')
p.sendline('\003')
time.sleep(3)
p.sendline("hostname")
hostnamefile = file('kippo-hostname', 'w+b')
p.expect(".*")
os.popen("rm -f kippo-hostname")
time.sleep(3)
p.sendline("ifconfig")
time.sleep(3)
p.expect(".*")
p.sendline("ifconfig")
time.sleep(3)
p.expect(".*")
p.sendline("cat /etc/passwd")
time.sleep(3)
p.expect(".*")
def parsepexpect():
global score
f = open('pexpect.txt', 'r')
hostname = re.compile('.*nas3:~#.*')
def report(ip, port):
global score
print "\n[REPORT]"
print "Current score is " + str(score)
if score >= 150:
print ip + ":" + str(port) + " is a Kippo Honeypot"
if args.writefile:
log = ip + ":" + str(port) + "\n"
with open(args.writefile, "a+") as f:
f.write(log)
f.close()
if score < 100:
print ip + ":" + str(port) + " is NOT a Kippo Honeypot"
if 100 < score < 150:
print ip + ":" + str(port) + " might be a Kippo Honeypot. Not 100%"
print "\n"
def main():
args()
banner()
global score
score = 0
if args.file:
parsefile(args.file)
else:
ip = args.ip
port = int(args.port)
print "[+] Checking: " + ip + ":" + str(port)
tests(ip, port)
main()