Last active
May 10, 2019 12:01
-
-
Save kovalbogdan95/590f67a7bee7020f233ec12940e914a5 to your computer and use it in GitHub Desktop.
Yggdrasil network scanning for active hosts with 80 open port
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python3 | |
# -*- coding: utf-8 -*- | |
from urllib.request import urlopen | |
import re | |
import os | |
import subprocess | |
#ipv6 | |
regex = r"(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-" \ | |
r"fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4})" \ | |
r"{1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|" \ | |
r"[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%" \ | |
r"[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]" \ | |
r"|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]" \ | |
r"|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))" | |
def hhelo(): | |
print ('\r') | |
print ('Active Host Scanner Yggdrasil by Hooko') | |
print ('Contact: [email protected]') | |
print ('\r') | |
def checkrun_ygg(): | |
print ('Condition check Yggdrasil/Nmap') | |
p = subprocess.Popen('ps cax | grep yggdrasil1', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
for line in p.stdout.readlines(): | |
if len(line) == 0: | |
print ('Yggdrasil is not running! Output...\r\n') | |
exit(0) | |
print ('Ok... Yggdrasil launched.') | |
p = subprocess.Popen('dpkg --get-selections | grep nmap', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
for line in p.stdout.readlines(): | |
if len(line) == 0: | |
print ('Nmap not installed! Output...\r\n') | |
exit(0) | |
print ('Ok... Nmap is installed.') | |
print ('\r') | |
def getmap(): | |
print ('Geting active host list from http://[301:4541:2f84:1188:216:3eff:feb6:65a3]:3000/static/map.svg') | |
page = urlopen('http://[301:4541:2f84:1188:216:3eff:feb6:65a3]:3000/static/map.svg') | |
with open("map.svg", "wb") as fh: | |
fh.write(page.read()) | |
print ('Ok... Temp file map.svg save. \r\n') | |
def ppars(): | |
print ('Parsing started. File generation - ygg_act_ip.txt') | |
f = open('map.svg') | |
fi = open('ygg_act_ip.txt', 'w') | |
num_line = 0 | |
for line in f.readlines(): | |
matches = re.finditer(regex, line, re.MULTILINE) | |
for matchNum, match in enumerate(matches, start=1): | |
fi.write(match.group() + '\n') | |
num_line = num_line + 1 | |
f.close() | |
fi.close() | |
os.remove('map.svg') | |
print ('Ok... Parsing completed. Number of addresses - ' + str(num_line)) | |
print ('Ok... Temp file map.svg delete. \r\n') | |
def scaner(): | |
# Somewhat this command does not start normally. So you can run this command manualy | |
# sudo nmap -6 --open -p 80 -sS -iL ygg_act_ip.txt -oN result_scan.txt | |
print('Scaning list on port 80. Wait') | |
p = subprocess.Popen('sudo nmap -6 --open -p 80 -sS -iL ygg_act_ip.txt -oN result_scan.txt', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
print('Ok... Results saved to file result_scan.txt \r\n') | |
def main(): | |
hhelo() | |
checkrun_ygg() | |
getmap() | |
ppars() | |
scaner() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO:
Wrap all this to server with background job for searching new servers