From 5eb10029e420b5047ed04c6c440367c0193d6aa8 Mon Sep 17 00:00:00 2001 From: Karim Rahal Date: Fri, 16 Aug 2019 16:47:56 +0300 Subject: [PATCH 1/5] Fix arguments.output bug introduced in #57 --- Interlace/lib/core/input.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Interlace/lib/core/input.py b/Interlace/lib/core/input.py index 4921ddd..935eb33 100644 --- a/Interlace/lib/core/input.py +++ b/Interlace/lib/core/input.py @@ -103,8 +103,9 @@ class InputHelper(object): output = OutputHelper(arguments) # removing the trailing slash if any - if arguments.output[-1] == "/": - arguments.output = arguments.output[:-1] + if arguments.output: + if arguments.output[-1] == "/": + arguments.output = arguments.output[:-1] if arguments.port: if "," in arguments.port: From 7c15dcf0b426c4d91f6315924dec133b720596bb Mon Sep 17 00:00:00 2001 From: karimpwnz Date: Fri, 16 Aug 2019 16:52:24 +0300 Subject: [PATCH 2/5] Introduce _random_ feature as per #50 --- Interlace/lib/core/input.py | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/Interlace/lib/core/input.py b/Interlace/lib/core/input.py index 4921ddd..ca3cfec 100644 --- a/Interlace/lib/core/input.py +++ b/Interlace/lib/core/input.py @@ -7,16 +7,22 @@ import sys from re import compile from random import sample from math import ceil +import random class InputHelper(object): @staticmethod - def readable_file(parser, arg): + def check_path(parser, arg): if not os.path.exists(arg): - parser.error("The file %s does not exist!" % arg) + parser.error("The path %s does not exist!" % arg) else: - return open(arg, 'r') # return an open file handle + return arg + @staticmethod + def readable_file(parser, arg): + if InputHelper.check_path(parser, arg): + return open(arg, 'r') # return an open file handle + @staticmethod def check_positive(parser, arg): ivalue = int(arg) @@ -25,6 +31,17 @@ class InputHelper(object): return arg + @staticmethod + def _get_files_from_directory(arg): + files = list() + + for file in os.listdir(arg): + location = os.path.join(arg, file) + if os.path.isfile(location): + files.append(location) + + return files + @staticmethod def _get_ips_from_range(ip_range): ips = set() @@ -128,7 +145,6 @@ class InputHelper(object): else: real_ports = [arguments.realport] - # process targets first if arguments.target: ranges.add(arguments.target) @@ -197,6 +213,10 @@ class InputHelper(object): if len(targets) == 0: raise Exception("No target provided, or empty target list") + if arguments.random: + files = InputHelper._get_files_from_directory(arguments.random) + random_file = random.choice(files) + if arguments.command: commands.add(arguments.command.rstrip('\n')) else: @@ -211,6 +231,9 @@ class InputHelper(object): if arguments.realport: final_commands = InputHelper._replace_variable_for_commands(final_commands, "_realport_", real_ports) + + if arguments.random: + final_commands = InputHelper._replace_variable_for_commands(final_commands, "_random_", [random_file]) if arguments.output: final_commands = InputHelper._replace_variable_for_commands(final_commands, "_output_", [arguments.output]) @@ -338,6 +361,12 @@ class InputParser(object): help='Specify a real port variable that can be used in commands as _realport_' ) + parser.add_argument( + '-random', dest='random', + help='Specify a directory of files that can be randomly used in commands as _random_', + type=lambda x: InputHelper.check_path(parser, x) + ) + parser.add_argument( '--no-cidr', dest='nocidr', action='store_true', default=False, help='If set then CIDR notation in a target file will not be automatically ' From 9a31a0b8105d2226c6a2e08a663db9742e59b197 Mon Sep 17 00:00:00 2001 From: Karim Rahal Date: Fri, 16 Aug 2019 17:16:08 +0300 Subject: [PATCH 3/5] Update README.md --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0886b4d..e12eb9e 100644 --- a/README.md +++ b/README.md @@ -30,12 +30,13 @@ Dependencies will then be installed and Interlace will be added to your path as | -o | Specify an output folder variable that can be used in commands as \_output\_ | | -p | Specify a list of port variable that can be used in commands as \_port\_. This can be a single port, a comma delimited list, or use dash notation | | -pL | Specify a list of proxies | -| --proto | Specify protocols that can be used in commands as \_proto\_ | +| --proto | Specify protocols that can be used in commands as \_proto\_ | | -rp | Specify a real port variable that can be used in commands as \_realport\_ | -| --no-bar / --sober | If set then progress bar be stripped out | +| -random | Specify a directory of files that can be randomly used in commands as _random_ | +| --no-bar / --sober | If set then progress bar be stripped out | | --no-cidr | If set then CIDR notation in a target file will not be automatically be expanded into individual hosts | | --no-color | If set then any foreground or background colours will be stripped out | -| --silent | If set then only important information will be displayed and banners and other information will be redacted | +| --silent | If set then only important information will be displayed and banners and other information will be redacted | | -v | If set then verbose output will be displayed in the terminal | ## Further information regarding ports (-p) @@ -62,6 +63,7 @@ The following variables will be replaced in commands at runtime: | \_port\_ | Replaced with the expanded port variable from interlace | | \_realport\_ | Replaced with the real port variable from interlace | | \_proxy\_ | Replaced with the proxy list from interlace | +| \_random\_ | Replaced with the randomly-chosen file from interlace | # Usage Examples ## Run Nikto Over Multiple Sites From 3e47a3b3e5a463566d8dba5f72ec3e54cd1305f8 Mon Sep 17 00:00:00 2001 From: karimpwnz Date: Fri, 16 Aug 2019 20:15:04 +0300 Subject: [PATCH 4/5] Bundle imports --- Interlace/lib/core/input.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Interlace/lib/core/input.py b/Interlace/lib/core/input.py index 20b3cc5..440e513 100644 --- a/Interlace/lib/core/input.py +++ b/Interlace/lib/core/input.py @@ -5,9 +5,8 @@ import os.path from os import access, W_OK import sys from re import compile -from random import sample +from random import sample, choice from math import ceil -import random class InputHelper(object): @@ -216,7 +215,7 @@ class InputHelper(object): if arguments.random: files = InputHelper._get_files_from_directory(arguments.random) - random_file = random.choice(files) + random_file = choice(files) if arguments.command: commands.add(arguments.command.rstrip('\n')) From a4c0e84ee411edac635b4b305309ab246d96558b Mon Sep 17 00:00:00 2001 From: Karim Rahal Date: Sat, 17 Aug 2019 02:25:46 +0300 Subject: [PATCH 5/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e12eb9e..f383e50 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Dependencies will then be installed and Interlace will be added to your path as | -pL | Specify a list of proxies | | --proto | Specify protocols that can be used in commands as \_proto\_ | | -rp | Specify a real port variable that can be used in commands as \_realport\_ | -| -random | Specify a directory of files that can be randomly used in commands as _random_ | +| -random | Specify a directory of files that can be randomly used in commands as \_random\_ | | --no-bar / --sober | If set then progress bar be stripped out | | --no-cidr | If set then CIDR notation in a target file will not be automatically be expanded into individual hosts | | --no-color | If set then any foreground or background colours will be stripped out |