mirror of
https://github.com/codingo/Interlace.git
synced 2025-12-17 23:04:24 +01:00
Introduce _random_ feature as per #50
This commit is contained in:
@@ -7,14 +7,20 @@ import sys
|
|||||||
from re import compile
|
from re import compile
|
||||||
from random import sample
|
from random import sample
|
||||||
from math import ceil
|
from math import ceil
|
||||||
|
import random
|
||||||
|
|
||||||
|
|
||||||
class InputHelper(object):
|
class InputHelper(object):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def readable_file(parser, arg):
|
def check_path(parser, arg):
|
||||||
if not os.path.exists(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:
|
else:
|
||||||
|
return arg
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def readable_file(parser, arg):
|
||||||
|
if InputHelper.check_path(parser, arg):
|
||||||
return open(arg, 'r') # return an open file handle
|
return open(arg, 'r') # return an open file handle
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -25,6 +31,17 @@ class InputHelper(object):
|
|||||||
|
|
||||||
return arg
|
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
|
@staticmethod
|
||||||
def _get_ips_from_range(ip_range):
|
def _get_ips_from_range(ip_range):
|
||||||
ips = set()
|
ips = set()
|
||||||
@@ -128,7 +145,6 @@ class InputHelper(object):
|
|||||||
else:
|
else:
|
||||||
real_ports = [arguments.realport]
|
real_ports = [arguments.realport]
|
||||||
|
|
||||||
|
|
||||||
# process targets first
|
# process targets first
|
||||||
if arguments.target:
|
if arguments.target:
|
||||||
ranges.add(arguments.target)
|
ranges.add(arguments.target)
|
||||||
@@ -197,6 +213,10 @@ class InputHelper(object):
|
|||||||
if len(targets) == 0:
|
if len(targets) == 0:
|
||||||
raise Exception("No target provided, or empty target list")
|
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:
|
if arguments.command:
|
||||||
commands.add(arguments.command.rstrip('\n'))
|
commands.add(arguments.command.rstrip('\n'))
|
||||||
else:
|
else:
|
||||||
@@ -212,6 +232,9 @@ class InputHelper(object):
|
|||||||
if arguments.realport:
|
if arguments.realport:
|
||||||
final_commands = InputHelper._replace_variable_for_commands(final_commands, "_realport_", real_ports)
|
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:
|
if arguments.output:
|
||||||
final_commands = InputHelper._replace_variable_for_commands(final_commands, "_output_", [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_'
|
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(
|
parser.add_argument(
|
||||||
'--no-cidr', dest='nocidr', action='store_true', default=False,
|
'--no-cidr', dest='nocidr', action='store_true', default=False,
|
||||||
help='If set then CIDR notation in a target file will not be automatically '
|
help='If set then CIDR notation in a target file will not be automatically '
|
||||||
|
|||||||
Reference in New Issue
Block a user