Skip to content
Snippets Groups Projects
Commit 64395ac6 authored by shadow's avatar shadow
Browse files

small refactorings and keeping up

parent 917b6c43
No related branches found
No related tags found
No related merge requests found
......@@ -13,4 +13,4 @@ COPY shared /shared
RUN chmod +x /run.sh
ENTRYPOINT ["/run.sh"]
ENTRYPOINT ["/run.sh"]
\ No newline at end of file
......@@ -29,10 +29,9 @@ class Vuln:
"""
if severity < 4:
return 'Low'
elif severity < 7:
if severity < 7:
return 'Medium'
else:
return 'High'
return 'High'
@property
def severity_str(self) -> str:
......
......@@ -43,6 +43,9 @@ class FlanXmlParser:
Parse xmltodict output and fill internal collections
:param data: xmltodict output
"""
if 'host' not in data['nmaprun']:
return
hosts = data['nmaprun']['host']
if isinstance(hosts, list):
......@@ -65,7 +68,11 @@ class FlanXmlParser:
self.results[app_name].vulns.append(Vuln(vuln_name, vuln_type, severity))
def parse_script(self, app_name: str, script: Dict[str, Any]):
def parse_script(self, ip_addr: str, port: str, app_name: str, script: Dict[str, Any]):
if 'table' not in script:
print('ERROR in script: ' + script['@output'] + " at location: " + ip_addr + " port: " + port + " app: " +
app_name)
return
self.vulnerable_services.append(app_name)
script_table = script['table']['table']
if isinstance(script_table, list):
......@@ -88,13 +95,24 @@ class FlanXmlParser:
if isinstance(scripts, list):
for s in scripts:
if s['@id'] == 'vulners':
self.parse_script(app_name, s)
self.parse_script(ip_addr, port_num, app_name, s)
else:
if scripts['@id'] == 'vulners':
self.parse_script(app_name, scripts)
self.parse_script(ip_addr, port_num, app_name, scripts)
def parse_host(self, host: Dict[str, Any]):
ip_addr = host['address']['@addr']
addresses = host['address']
ip_addr = ''
if isinstance(addresses, list):
for addr in addresses:
if "ip" in addr['@addrtype']:
ip_addr = addr['@addr']
else:
ip_addr = addresses['@addr']
if not ip_addr:
return
if host['status']['@state'] == 'up' and 'port' in host['ports']:
ports = host['ports']['port']
if isinstance(ports, list):
......
#!/bin/sh
current_time=$(date "+%Y.%m.%d-%H.%M")
if [[ -z $upload ]]
then
root_dir=/shared/
else
root_dir=/
mkdir /xml_files
mkdir /reports
fi
xml_dir=xml_files/$current_time
report_file=reports/report_$current_time.tex
function upload {
if [[ -z $upload ]]
then
return
elif [ $upload = "aws" ]
then
python /aws_push.py $1
elif [ $upload = "gcp" ]
then
python /gcp_push.py $1
fi
}
function get_filename(){
echo $1 | tr / -
}
mkdir $root_dir$xml_dir
while IFS= read -r line
do
current_time=$(date "+%Y.%m.%d-%H.%M.%S")
filename=$(get_filename $line)".xml"
nmap -sV -oX $root_dir$xml_dir/$filename -oN - -v1 $@ --script=vulners/vulners.nse $line
upload $xml_dir/$filename
done < /shared/ips.txt
python /output_report.py $root_dir$xml_dir $root_dir$report_file /shared/ips.txt
sed -i 's/_/\\_/g' $root_dir$report_file
sed -i 's/\$/\\\$/g' $root_dir$report_file
sed -i 's/#/\\#/g' $root_dir$report_file
sed -i 's/%/\\%/g' $root_dir$report_file
upload $report_file
1.1.1.1
8.8.8.8
8.17.207.0/24
198.41.138.128/25
198.41.138.0/25
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment