Skip to content

Commit 2d31637

Browse files
author
Ekultek
committed
pushing for relation to the wrappers
1 parent 14136b4 commit 2d31637

File tree

7 files changed

+295
-4
lines changed

7 files changed

+295
-4
lines changed

autosploit/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
EXPLOIT_FILES_PATH,
2525
START_SERVICES_PATH,
2626
save_error_to_file,
27+
stop_animation
2728
)
2829
from lib.jsonize import (
2930
load_exploits,
@@ -115,6 +116,10 @@ def main():
115116
terminal = AutoSploitTerminal(loaded_tokens, loaded_exploits)
116117
terminal.terminal_main_display(loaded_tokens)
117118
except Exception as e:
119+
global stop_animation
120+
121+
stop_animation = True
122+
118123
import traceback
119124

120125
print(
@@ -128,4 +133,3 @@ def main():
128133
error_class = str(e.__class__).split(" ")[1].split(".")[1].strip(">").strip("'")
129134
error_file = save_error_to_file(str(error_traceback), str(e), error_class)
130135
request_issue_creation(error_file, hide_sensitive(), str(e))
131-

etc/text_files/nmap_options.lst

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
-iL
2+
-iR
3+
--exclude
4+
--excludefile
5+
-sL
6+
-sn
7+
-Pn
8+
-PS
9+
-PA
10+
-PU
11+
-PY
12+
-PE
13+
-PP
14+
-PM
15+
-PO
16+
-n
17+
-R
18+
--dns-servers
19+
--system-dns
20+
--traceroute
21+
-sS
22+
-sT
23+
-sA
24+
-sW
25+
-sM
26+
-sU
27+
-sN
28+
-sF
29+
-sX
30+
--scanflags
31+
-sI
32+
-sY
33+
-sZ
34+
-sO
35+
-b
36+
-p
37+
--exclude-ports
38+
-F
39+
-r
40+
--top-ports
41+
--port-ratio
42+
-sV
43+
--version-intensity
44+
--version-light
45+
--version-all
46+
--version-trace
47+
-sC
48+
--script
49+
--script-args
50+
--script-args-file
51+
--script-trace
52+
--script-updatedb
53+
--script-help
54+
-O
55+
--osscan-limit
56+
--osscan-guess
57+
-T
58+
--min-hostgroup
59+
--max-hostgroup
60+
--min-parallelism
61+
--max-parallelism
62+
--min-rtt-timeout
63+
--max-rtt-timeout
64+
--initial-rtt-timeout
65+
--max-retries
66+
--host-timeout
67+
--scan-delay
68+
--max-scan-delay
69+
--min-rate
70+
--max-rate
71+
-f
72+
--mtu
73+
-D
74+
-S
75+
-e
76+
-g
77+
--source-port
78+
--proxies
79+
--data
80+
--data-string
81+
--data-length
82+
--ip-options
83+
--ttl
84+
--spoof-mac
85+
--badsum
86+
-oN
87+
-oX
88+
-oS
89+
-oG
90+
-oA
91+
-v
92+
-d
93+
--reason
94+
--open
95+
--packet-trace
96+
--iflist
97+
--append-output
98+
--resume
99+
--stylesheet
100+
--webxml
101+
--no-stylesheet
102+
-6
103+
-A
104+
--datadir
105+
--send-eth/--send-ip
106+
--privileged
107+
--unprivileged
108+
-V

lib/errors.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
class AutoSploitAPIConnectionError(Exception): pass
1+
class AutoSploitAPIConnectionError(Exception): pass
2+
3+
4+
class NmapNotFoundException(Exception): pass
5+
6+
7+
class NmapScannerError(Exception): pass

lib/exploitation/exploiter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,14 @@ def start_exploit(self, sep="*" * 10):
110110
if self.check_honey:
111111
lib.output.misc_info("checking if {} is a honeypot".format(host))
112112
honey_score = api_calls.honeyscore_hook.HoneyHook(host, self.shodan_token).make_request()
113-
if honey_score >= self.compare_honey:
113+
if honey_score < self.compare_honey:
114114
lib.output.warning(
115115
"honeypot score ({}) is above (or equal to) requested, skipping target".format(honey_score)
116116
)
117117
skip = True
118118
skip_amount += 1
119119
else:
120+
lib.output.misc_info("{} does not appear to be a honeypot, continuing attack")
120121
skip = False
121122
else:
122123
skip = False

lib/scanner/__init__.py

Whitespace-only changes.

lib/scanner/nmap.py

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
import io
2+
import os
3+
import re
4+
import csv
5+
import sys
6+
import shlex
7+
import subprocess
8+
9+
from xml.etree import ElementTree
10+
from multiprocessing import Process
11+
12+
import lib.jsonize
13+
import lib.errors
14+
import lib.output
15+
import lib.settings
16+
17+
18+
def write_xml_data(host, output):
19+
if not os.path.exists(lib.settings.NMAP_XML_OUTPUT_BACKUP):
20+
os.makedirs(lib.settings.NMAP_XML_OUTPUT_BACKUP)
21+
file_path = "{}/{}_{}.xml".format(
22+
lib.settings.NMAP_XML_OUTPUT_BACKUP, str(host), lib.jsonize.random_file_name(length=10)
23+
)
24+
with open(file_path, 'a+') as results:
25+
results.write(output)
26+
return file_path
27+
28+
29+
def find_nmap(search_paths):
30+
for path in search_paths:
31+
try:
32+
_ = subprocess.Popen([path, '-V'], bufsize=10000, stdout=subprocess.PIPE, close_fds=True)
33+
except OSError:
34+
pass
35+
else:
36+
return path
37+
raise lib.errors.NmapNotFoundException
38+
39+
40+
def do_scan(host, nmap_path, ports=None, arguments=None):
41+
if arguments is None:
42+
arguments = "-sV"
43+
arguments_list = shlex.split(arguments)
44+
launch_arguments = [
45+
nmap_path, '-oX', '-', host,
46+
'-p ' + ports if ports is not None else "",
47+
] + arguments_list
48+
lib.output.info("launching nmap scan against {} ({})".format(host, " ".join(launch_arguments)))
49+
process = subprocess.Popen(
50+
launch_arguments, bufsize=10000, stdin=subprocess.PIPE,
51+
stdout=subprocess.PIPE, stderr=subprocess.PIPE
52+
)
53+
output, error = process.communicate()
54+
output_data = bytes.decode(output)
55+
nmap_error = bytes.decode(error)
56+
nmap_error_tracestack = []
57+
nmap_warn_tracestack = []
58+
if len(nmap_error) > 0:
59+
for line in nmap_error.split(os.linesep):
60+
if len(line) != 0:
61+
if lib.settings.NMAP_ERROR_REGEX_WARNING.search(line) is not None:
62+
nmap_warn_tracestack.append(line + os.linesep)
63+
else:
64+
nmap_error_tracestack.append(line + os.linesep)
65+
path = write_xml_data(host, output_data)
66+
lib.output.misc_info("a copy of the output has been saved to: {}".format(path))
67+
return output_data, "".join(nmap_warn_tracestack), "".join(nmap_error_tracestack)
68+
69+
70+
def parse_xml_output(output, warnings, error):
71+
results = {}
72+
try:
73+
root = ElementTree.fromstring(output)
74+
except Exception:
75+
if len(error) != 0:
76+
raise lib.errors.NmapScannerError(error)
77+
else:
78+
raise lib.errors.NmapScannerError(output)
79+
results['nmap_scan'] = {
80+
'full_command_line': root.get('args'),
81+
'scan_information': {},
82+
'scan_stats': {
83+
'time_string': root.find('runstats/finished').get('timestr'),
84+
'elapsed': root.find('runstats/finished').get('elapsed'),
85+
'hosts_up': root.find('runstats/hosts').get('up'),
86+
'down_hosts': root.find('runstats/hosts').get('down'),
87+
'total_hosts_scanned': root.find('runstats/hosts').get('total')
88+
}
89+
}
90+
if len(error) != 0:
91+
results['nmap_scan']['scan_information']['errors'] = error
92+
if len(warnings) != 0:
93+
results['nmap_scan']['scan_information']['warnings'] = warnings
94+
for info in root.findall('scaninfo'):
95+
results['nmap_scan']['scan_information'][info.get('protocol')] = {
96+
'method': info.get('type'),
97+
'services': info.get('services')
98+
}
99+
for attempted_host in root.findall('host'):
100+
host = None
101+
addresses = {}
102+
vendors = {}
103+
for address in attempted_host.findall("address"):
104+
address_type = address.get('addrtype')
105+
addresses[address_type] = address.get('addr')
106+
if address_type == "ipv4":
107+
host = addresses[address_type]
108+
elif address_type == "mac" and address.get('vendor') is not None:
109+
vendors[addresses[address_type]] = address.get('vendor')
110+
if host is None:
111+
host = attempted_host.find('address').get('addr')
112+
hostnames = []
113+
if len(attempted_host.findall('hostnames/hostname')) != 0:
114+
for current_hostnames in attempted_host.findall('hostnames/hostname'):
115+
hostnames.append({
116+
'hostname': current_hostnames.get('name'),
117+
'host_type': current_hostnames.get('type')
118+
})
119+
else:
120+
hostnames.append({
121+
'hostname': None,
122+
'host_type': None
123+
})
124+
125+
results['nmap_scan'][host] = {}
126+
results['nmap_scan'][host]['hostnames'] = hostnames
127+
results['nmap_scan'][host]['addresses'] = addresses
128+
results['nmap_scan'][host]['vendors'] = vendors
129+
130+
print results;exit(1)
131+
132+
for status in attempted_host.findall('status'):
133+
results['nmap_scan'][attempted_host]['status'] = {
134+
'state': status.get('state'),
135+
'reason': status.get('reason')
136+
}
137+
for uptime in attempted_host.findall('uptime'):
138+
results['nmap_scan'][attempted_host]['uptime'] = {
139+
'seconds': uptime.get('seconds'),
140+
'lastboot': uptime.get('lastboot')
141+
}
142+
for discovered_port in attempted_host.findall('ports/port'):
143+
protocol = discovered_port.get('protocol')
144+
port_number = discovered_port.get('portid')
145+
port_state = discovered_port.find('state').get('reason')
146+
147+
# damn I didn't even know you could do this!
148+
for discovered_name in discovered_port.findall('service'):
149+
name = discovered_name.get('name')
150+
if discovered_name.get('product'):
151+
discovered_product = discovered_name.get('product')
152+
if discovered_name.get('version'):
153+
discovered_version = discovered_name.get('version')
154+
if discovered_name.get('extrainfo'):
155+
extra_information = discovered_name.get('extrainfo')
156+
print results

lib/settings.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import re
23
import sys
34
import time
45
import socket
@@ -71,6 +72,20 @@ def complete_text(self, text, state):
7172
# autosploit command history file path
7273
HISTORY_FILE_PATH = "{}/.history".format(HOME)
7374

75+
# we'll save the scans output for future use
76+
NMAP_XML_OUTPUT_BACKUP = "{}/nmap_scans".format(HOME)
77+
78+
# regex to discover errors or warnings
79+
NMAP_ERROR_REGEX_WARNING = re.compile("^warning: .*", re.IGNORECASE)
80+
81+
# possible options in nmap
82+
NMAP_OPTIONS_PATH = "{}/etc_text_files/nmap_opts.lst".format(CUR_DIR)
83+
84+
# possible paths for nmap
85+
NMAP_POSSIBLE_PATHS = (
86+
'nmap', '/usr/bin/nmap', '/usr/local/bin/nmap', '/sw/bin/nmap', '/opt/local/bin/nmap'
87+
)
88+
7489
# link to the checksums
7590
CHECKSUM_LINK = open("{}/etc/text_files/checksum_link.txt".format(CUR_DIR)).read()
7691

@@ -90,7 +105,8 @@ def complete_text(self, text, state):
90105
# one bash script to rule them all takes an argument via the operating system
91106
START_SERVICES_PATH = "{}/etc/scripts/start_services.sh".format(CUR_DIR)
92107

93-
RC_SCRIPTS_PATH = "{}/autosploit_out/".format(CUR_DIR)
108+
# path where we will keep the rc scripts
109+
RC_SCRIPTS_PATH = "{}/autosploit_out/".format(HOME)
94110

95111
# path to the file that will contain our query
96112
QUERY_FILE_PATH = tempfile.NamedTemporaryFile(delete=False).name

0 commit comments

Comments
 (0)