自动扫描内网常见数据库脚本
如:(mysql、mssql、oracle、postgresql、redis、mongodb、memcached、elasticsearch)
包含未授权访问及常规弱口令检测等功能
主函数如下:
#!/usr/bin/env python
#coding:utf-8
import sys
import IPy
import time
import socket
import gevent
import argparse
from gevent import monkey
from multiprocessing.dummy import Pool as ThreadPool
from lib.config import *
from lib.exploit import *
monkey.patch_all()
class DBScanner(object):
def __init__(self, target, thread):
self.target = target
self.thread = thread
self.ips = []
self.ports = []
self.time = time.time()
self.get_ip()
self.get_port()
self.check = check()
def get_ip(self):
#获取待扫描地址段
for ip in IPy.IP(self.target):
self.ips.append(str(ip))
def get_port(self):
self.ports = list(p for p in service.itervalues())
def scan(self, ip, port):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)#建立socket链接
s.settimeout(0.2)
if s.connect_ex((ip, port)) == 0:
self.handle(ip, port)
except Exception as e:
pass
finally:
s.close()
def handle(self, ip, port):
for v,k in service.iteritems():
if k == str(port):
if v == 'mysql':
self.check.mysql(ip)
elif v == 'mssql':
self.check.mssql(ip)
elif v == 'oracle':
self.check.oracle(ip)
elif v == 'postgresql':
self.check.postgresql(ip)
elif v == 'redis':
self.check.redis(ip)
elif v == 'mongodb':
self.check.mongodb(ip)
elif v == 'memcached':
self.check.memcached(ip)
else:
self.check.elasticsearch(ip)
def start(self, ip):
try:
gevents = []
for port in self.ports:
gevents.append(gevent.spawn(self.scan, ip, int(port)))
gevent.joinall(gevents)
except Exception as e:
pass
def run(self):
try:
pool = ThreadPool(processes=self.thread) #实例一个线程池
pool.map_async(self.start, self.ips).get(0xffff) #进行异步执行
pool.close()
pool.join()
except Exception as e:
pass
except KeyboardInterru