Implemented sequential command processing

This commit is contained in:
Joshua Ogunyinka
2019-08-16 09:39:10 +01:00
parent 24d529291e
commit 20af7466db
2 changed files with 20 additions and 16 deletions

View File

@@ -1,5 +1,6 @@
#!/usr/bin/python3 #!/usr/bin/python3
import sys import sys
from Interlace.lib.core.input import InputParser, InputHelper from Interlace.lib.core.input import InputParser, InputHelper
from Interlace.lib.core.output import OutputHelper, Level from Interlace.lib.core.output import OutputHelper, Level
from Interlace.lib.threader import Pool, TaskBlock from Interlace.lib.threader import Pool, TaskBlock
@@ -14,11 +15,9 @@ def print_command(level, command, message, output):
def build_queue(arguments, output): def build_queue(arguments, output):
task_queue = InputHelper.process_commands(arguments) task_list = InputHelper.process_commands(arguments)
task_list = [] for task in task_list:
for task in task_queue:
print_command(Level.THREAD, task, "Added to Queue", output) print_command(Level.THREAD, task, "Added to Queue", output)
task_list.append(task)
return task_list return task_list

View File

@@ -121,23 +121,28 @@ class InputHelper(object):
@staticmethod @staticmethod
def _replace_variable_with_commands(commands, variable, replacements): def _replace_variable_with_commands(commands, variable, replacements):
data = set() foo = []
def add_task(t):
if t not in set(foo):
foo.append(t)
for command in commands: for command in commands:
is_task = not isinstance(command, TaskBlock) is_task = not isinstance(command, TaskBlock)
for replacement in replacements: for replacement in replacements:
if is_task and command.name().find(variable) != -1: if is_task and command.name().find(variable) != -1:
new_task = command.clone() new_task = command.clone()
new_task.replace(variable, replacement) new_task.replace(variable, replacement)
data.add(new_task) add_task(new_task)
elif is_task and command not in data: elif is_task and command not in set(foo):
data.add(command) add_task(command)
elif not is_task: elif not is_task:
tasks = [task for task in command.get_tasks()] tasks = [task for task in command.get_tasks()]
command.clear_tasks() command.clear_tasks()
for r in InputHelper._replace_variable_with_commands(tasks, variable, replacements): for r in InputHelper._replace_variable_with_commands(tasks, variable, replacements):
command.add_task(r) command.add_task(r)
data.add(command) add_task(command)
return set(data) return foo
@staticmethod @staticmethod
def _replace_variable_array(commands, variable, replacement): def _replace_variable_array(commands, variable, replacement):
@@ -153,13 +158,13 @@ class InputHelper(object):
@staticmethod @staticmethod
def process_commands(arguments): def process_commands(arguments):
commands = set() commands = list()
ranges = set() ranges = set()
targets = set() targets = set()
exclusions_ranges = set() exclusions_ranges = set()
exclusions = set() exclusions = set()
if arguments.output[-1] == "/": if arguments.output and arguments.output[-1] == "/":
arguments.output = arguments.output[:-1] arguments.output = arguments.output[:-1]
if arguments.port: if arguments.port:
@@ -173,8 +178,8 @@ class InputHelper(object):
ranges.add(arguments.target) ranges.add(arguments.target)
else: else:
target_file = arguments.target_list target_file = arguments.target_list
# if not sys.stdin.isatty(): if not sys.stdin.isatty():
# target_file = sys.stdin target_file = sys.stdin
ranges.update([target.strip() for target in target_file if target.strip()]) ranges.update([target.strip() for target in target_file if target.strip()])
# process exclusions first # process exclusions first
@@ -198,10 +203,10 @@ class InputHelper(object):
raise Exception("No target provided, or empty target list") raise Exception("No target provided, or empty target list")
if arguments.command: if arguments.command:
commands.add(arguments.command.rstrip('\n')) commands.append(arguments.command.rstrip('\n'))
else: else:
tasks = InputHelper._pre_process_commands(arguments.command_list, '') tasks = InputHelper._pre_process_commands(arguments.command_list, '')
commands.update(tasks.get_tasks()) commands = tasks.get_tasks()
commands = InputHelper._replace_variable_with_commands(commands, "_target_", targets) commands = InputHelper._replace_variable_with_commands(commands, "_target_", targets)
commands = InputHelper._replace_variable_with_commands(commands, "_host_", targets) commands = InputHelper._replace_variable_with_commands(commands, "_host_", targets)