|
1 | 1 | import argparse
|
| 2 | +from queue import Queue |
2 | 3 | from lib.cmd2 import Cmd, with_category, with_argparser
|
3 | 4 | from art import text2art, art
|
4 | 5 | from utils import module
|
@@ -74,18 +75,31 @@ def complete_set(self, text, line, begidx, endidx):
|
74 | 75 |
|
75 | 76 | set_parser = argparse.ArgumentParser()
|
76 | 77 | set_parser.add_argument("name", help="The name of the field you want to set")
|
| 78 | + set_parser.add_argument("-f", "--file", action="store_true", help="Specify multiple targets") |
77 | 79 | set_parser.add_argument("value", help="The value of the field you want to set")
|
78 | 80 |
|
79 | 81 | @with_argparser(set_parser)
|
80 | 82 | @with_category(CMD_MODULE)
|
81 | 83 | def do_set(self, args):
|
82 |
| - if args.value == 'debug': |
| 84 | + if args.name == 'debug': |
83 | 85 | self.debug = args.value
|
84 | 86 | return None
|
85 | 87 |
|
86 | 88 | if not self.module_instance:
|
87 | 89 | raise ModuleNotUseException()
|
88 | 90 |
|
| 91 | + # 使用 -f/--file 指定多个目标 |
| 92 | + if args.file and args.name in ["HOST", "TARGET"]: |
| 93 | + try: |
| 94 | + open(args.value, 'r') |
| 95 | + self.module_instance.multi_target = True |
| 96 | + except IOError as e: |
| 97 | + self._print_item(e, color=Fore.RED) |
| 98 | + return False |
| 99 | + elif not args.file and args.name in ["HOST", "TARGET"]: |
| 100 | + self.module_instance.multi_target = False |
| 101 | + self.module_instance.targets = None |
| 102 | + |
89 | 103 | self.module_instance.options.set_option(args.name, args.value)
|
90 | 104 |
|
91 | 105 | def complete_use(self, text, line, begidx, endidx):
|
@@ -193,6 +207,57 @@ def do_exploit(self, args):
|
193 | 207 | self._print_item(error, color=Fore.RED)
|
194 | 208 | return False
|
195 | 209 |
|
| 210 | + # 处理指定多个目标的情况 |
| 211 | + if self.module_instance.multi_target: |
| 212 | + # 读取多个目标 |
| 213 | + target_type = self.module_instance.target_type |
| 214 | + target_field = None |
| 215 | + |
| 216 | + if target_type == "tcp": |
| 217 | + target_field = "HOST" |
| 218 | + elif target_type == "http": |
| 219 | + target_field = "URL" |
| 220 | + |
| 221 | + target_filename = self.module_instance.options.get_option(target_field) |
| 222 | + |
| 223 | + try: |
| 224 | + target_file = open(target_filename, 'r') |
| 225 | + self.module_instance.targets = [] |
| 226 | + for line in target_file.readlines(): |
| 227 | + self.module_instance.targets.append(line.strip()) |
| 228 | + self.module_instance.multi_target = True |
| 229 | + except IOError as e: |
| 230 | + self._print_item(e, color=Fore.RED) |
| 231 | + return False |
| 232 | + |
| 233 | + # 将targets数组中的目标写到队列中 |
| 234 | + targets = self.module_instance.targets |
| 235 | + targets_queue = Queue() |
| 236 | + for target in targets: |
| 237 | + targets_queue.put(target) |
| 238 | + |
| 239 | + while not targets_queue.empty(): |
| 240 | + [target, port] = module.parse_ip_port(targets_queue.get()) |
| 241 | + |
| 242 | + exp = self.module_class.Exploit() |
| 243 | + exp.options.set_option(target_field, target) |
| 244 | + exp.options.set_option("TIMEOUT", self.module_instance.options.get_option("TIMEOUT")) |
| 245 | + if port: |
| 246 | + exp.options.set_option("PORT", port) |
| 247 | + else: |
| 248 | + exp.options.set_option("PORT", self.module_instance.options.get_option("PORT")) |
| 249 | + |
| 250 | + exploit_result = exp.exploit() |
| 251 | + if exploit_result.status: |
| 252 | + self._print_item(exploit_result.success_message) |
| 253 | + else: |
| 254 | + self._print_item(exploit_result.error_message, color=Fore.RED) |
| 255 | + self.poutput("{style}[*]{style_end} module execution completed".format( |
| 256 | + style=Fore.BLUE + Style.BRIGHT, |
| 257 | + style_end=Style.RESET_ALL |
| 258 | + )) |
| 259 | + return False |
| 260 | + |
196 | 261 | exploit_result = self.module_instance.exploit()
|
197 | 262 | if exploit_result.status:
|
198 | 263 | self._print_item("Exploit success!")
|
|
0 commit comments