├── requirements.txt ├── README.md ├── .gitignore └── unauthorized-check.py /requirements.txt: -------------------------------------------------------------------------------- 1 | pymongo -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # unauthorized-check 2 | 3 | 扫描以下常见未授权访问 4 | 5 | ``` 6 | redis、mongodb、memcached、elasticsearch、zookeeper、ftp、CouchDB、docker、Hadoop 7 | ``` 8 | 9 | 安装 10 | 11 | ``` 12 | pip3 install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ 13 | ``` 14 | 15 | 使用说明 16 | 17 | ``` 18 | python3 unauthorized-check.py url.txt 19 | ``` -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /unauthorized-check.py: -------------------------------------------------------------------------------- 1 | import socket 2 | import pymongo 3 | import requests 4 | import ftplib 5 | from tqdm import tqdm 6 | import sys 7 | from concurrent.futures import ThreadPoolExecutor 8 | 9 | 10 | def redis(ip): 11 | try: 12 | socket.setdefaulttimeout(5) 13 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 14 | s.connect((ip, 6379)) 15 | s.send(bytes("INFO\r\n", 'UTF-8')) 16 | result = s.recv(1024).decode() 17 | if "redis_version" in result: 18 | print(ip + ":6379 redis未授权") 19 | s.close() 20 | except Exception as e: 21 | pass 22 | finally: 23 | bar.update(1) 24 | 25 | def mongodb(ip): 26 | try: 27 | conn = pymongo.MongoClient(ip, 27017, socketTimeoutMS=4000) 28 | dbname = conn.list_database_names() 29 | print(ip + ":27017 mongodb未授权") 30 | conn.close() 31 | except Exception as e: 32 | pass 33 | finally: 34 | bar.update(1) 35 | 36 | def memcached(ip): 37 | try: 38 | socket.setdefaulttimeout(5) 39 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 40 | s.connect((ip, 11211)) 41 | s.send(bytes('stats\r\n', 'UTF-8')) 42 | if 'version' in s.recv(1024).decode(): 43 | print(ip + ":11211 memcached未授权") 44 | s.close() 45 | except Exception as e: 46 | pass 47 | finally: 48 | bar.update(1) 49 | 50 | def elasticsearch(ip): 51 | try: 52 | url = 'http://' + ip + ':9200/_cat' 53 | r = requests.get(url, timeout=5) 54 | if '/_cat/master' in r.content.decode(): 55 | print(ip + ":9200 elasticsearch未授权") 56 | except Exception as e: 57 | pass 58 | finally: 59 | bar.update(1) 60 | 61 | def zookeeper(ip): 62 | try: 63 | socket.setdefaulttimeout(5) 64 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 65 | s.connect((ip, 2181)) 66 | s.send(bytes('envi', 'UTF-8')) 67 | data = s.recv(1024).decode() 68 | s.close() 69 | if 'Environment' in data: 70 | print(ip + ":2181 zookeeper未授权") 71 | except: 72 | pass 73 | finally: 74 | bar.update(1) 75 | 76 | def ftp(ip): 77 | try: 78 | ftp = ftplib.FTP.connect(ip,21,timeout=5) 79 | ftp.login('anonymous', 'Aa@12345678') 80 | print(ip + ":21 FTP未授权") 81 | except Exception as e: 82 | pass 83 | finally: 84 | bar.update(1) 85 | 86 | def CouchDB(ip): 87 | try: 88 | url = 'http://' + ip + ':5984'+'/_utils/' 89 | r = requests.get(url, timeout=5) 90 | if 'couchdb-logo' in r.content.decode(): 91 | print(ip + ":5984 CouchDB未授权") 92 | except Exception as e: 93 | pass 94 | finally: 95 | bar.update(1) 96 | 97 | def docker(ip): 98 | try: 99 | url = 'http://' + ip + ':2375'+'/version' 100 | r = requests.get(url, timeout=5) 101 | if 'ApiVersion' in r.content.decode(): 102 | print(ip + ":2375 docker api未授权") 103 | except Exception as e: 104 | pass 105 | finally: 106 | bar.update(1) 107 | 108 | def Hadoop(ip): 109 | try: 110 | url = 'http://' + ip + ':50070'+'/dfshealth.html' 111 | r = requests.get(url, timeout=5) 112 | if 'hadoop.css' in r.content.decode(): 113 | print(ip + ":50070 Hadoop未授权") 114 | except Exception as e: 115 | pass 116 | finally: 117 | bar.update(1) 118 | 119 | if __name__ == '__main__': 120 | if len(sys.argv) == 1: 121 | print("Usage:python3 unauthorized-check.py url.txt") 122 | file = sys.argv[1] 123 | with open(file, "r", encoding='UTF-8') as f: 124 | line = [i for i in f.readlines()] 125 | bar = tqdm(total=len(line)*9) 126 | with ThreadPoolExecutor(1000) as pool: 127 | for target in line: 128 | target=target.strip() 129 | pool.submit(redis, target) 130 | pool.submit(Hadoop, target) 131 | pool.submit(docker, target) 132 | pool.submit(CouchDB, target) 133 | pool.submit(ftp, target) 134 | pool.submit(zookeeper, target) 135 | pool.submit(elasticsearch, target) 136 | pool.submit(memcached, target) 137 | pool.submit(mongodb, target) --------------------------------------------------------------------------------