-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathftpscanner.py
63 lines (53 loc) · 1.26 KB
/
ftpscanner.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
#!/usr/bin/env python
"""
-------------------------------------------------------------------------------
Name: ftpscanner.py
Purpose: Threaded anonymous ftp scanner
Author: Justin Kennedy (@jstnkndy)
-------------------------------------------------------------------------------
"""
import Queue
import threading
import iptools
import sys
import os
from ftplib import FTP
# Constant Variables
MAX_THREADS = 100
TIMEOUT = 2
class ThreadFTP(threading.Thread):
def __init__(self, queue):
threading.Thread.__init__(self)
self.queue = queue
def run(self):
while True:
host = self.queue.get()
try:
ftp = FTP(host, timeout=TIMEOUT)
if ftp:
if ftp.login("anonymous", "[email protected]"):
ls = ftp.nlst()
print "Success: %s %s" % (host, ls)
except:
pass
self.queue.task_done()
def usage():
print 'Usage: python %s <range or file>' % sys.argv[0]
def main():
if len(sys.argv) != 2:
usage()
sys.exit()
queue = Queue.Queue()
if os.path.exists(sys.argv[1]):
hosts = [line.strip() for line in open(sys.argv[1])]
else:
hosts = iptools.IpRangeList(sys.argv[1])
for host in hosts:
queue.put(host)
for thr in range(MAX_THREADS):
t = ThreadFTP(queue)
t.setDaemon(True)
t.start()
queue.join()
if __name__ == '__main__':
main()