Skip to content

Commit 6aa0396

Browse files
committed
Added libs
1 parent f119f2d commit 6aa0396

File tree

6 files changed

+168
-1
lines changed

6 files changed

+168
-1
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ dist/
1515
downloads/
1616
eggs/
1717
.eggs/
18-
lib/
1918
lib64/
2019
parts/
2120
sdist/

Interlace/lib/__init__.py

Whitespace-only changes.

Interlace/lib/core/__init__.py

Whitespace-only changes.

Interlace/lib/core/__version__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
__version__ = '0.01'
2+

Interlace/lib/core/input.py

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
from argparse import ArgumentParser
2+
import os.path
3+
4+
5+
class InputHelper(object):
6+
@staticmethod
7+
def readable_file(parser, arg):
8+
if not os.path.exists(arg):
9+
parser.error("The file %s does not exist!" % arg)
10+
else:
11+
return open(arg, 'r') # return an open file handle
12+
13+
@staticmethod
14+
def process_targets(arguments):
15+
targets = set()
16+
17+
if arguments.target:
18+
targets.add(arguments.target)
19+
else:
20+
for target in arguments.target_list:
21+
targets.add(target.strip())
22+
23+
return targets
24+
25+
@staticmethod
26+
def process_commands(arguments):
27+
commands = set()
28+
29+
if arguments.command:
30+
commands.add(arguments.target)
31+
else:
32+
for command in arguments.command_list:
33+
commands.add(command.strip())
34+
35+
return commands
36+
37+
class InputParser(object):
38+
def __init__(self):
39+
self._parser = self.setup_parser()
40+
41+
def parse(self, argv):
42+
return self._parser.parse_args(argv)
43+
44+
@staticmethod
45+
def setup_parser():
46+
parser = ArgumentParser()
47+
48+
targets = parser.add_mutually_exclusive_group(required=True)
49+
50+
targets.add_argument(
51+
'-t', dest='target', required=False,
52+
help='Specify a target or domain name.'
53+
)
54+
55+
targets.add_argument(
56+
'-tL', dest='target_list', required=False,
57+
help='Specify a list of targets or domain names.',
58+
metavar="FILE",
59+
type=lambda x: InputHelper.readable_file(parser, x)
60+
)
61+
62+
commands = parser.add_mutually_exclusive_group(required=True)
63+
commands.add_argument(
64+
'-c', dest='command',
65+
help='Specify a single command to execute.'
66+
)
67+
68+
commands.add_argument(
69+
'-cL', dest='command_list', required=False,
70+
help='Specify a list of commands to execute',
71+
metavar="FILE",
72+
type=lambda x: InputHelper.readable_file(parser, x)
73+
)
74+
75+
output = parser.add_mutually_exclusive_group()
76+
output.add_argument(
77+
'-oN', dest='output_normal',
78+
help='Normal output printed to a file when the -oN option is '
79+
'specified with a filename argument.'
80+
)
81+
82+
output.add_argument(
83+
'-oJ', dest='output_json',
84+
help='JSON output printed to a file when the -oJ option is '
85+
'specified with a filename argument.'
86+
)
87+
88+
output.add_argument(
89+
'-oG', dest='output_grepable',
90+
help='Grepable output printed to a file when the -oG option is '
91+
'specified with a filename argument.'
92+
)
93+
94+
95+
parser.add_argument(
96+
'--no-color', dest='nocolor', action='store_true', default=False,
97+
help='If set then any foreground or background colours will be '
98+
'stripped out.'
99+
)
100+
101+
output_types = parser.add_mutually_exclusive_group()
102+
output_types.add_argument(
103+
'-v', '--verbose', dest='verbose', action='store_true', default=False,
104+
help='If set then verbose output will be displayed in the terminal.'
105+
)
106+
output_types.add_argument(
107+
'--silent', dest='silent', action='store_true', default=False,
108+
help='If set only findings will be displayed and banners '
109+
'and other information will be redacted.'
110+
)
111+
112+
return parser

Interlace/lib/core/output.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from colorclass import Color
2+
from colorclass import disable_all_colors, enable_all_colors, is_enabled
3+
from time import localtime, strftime
4+
from lib.core.__version__ import __version__
5+
from enum import IntEnum
6+
7+
class OutputHelper(object):
8+
def __init__(self, arguments):
9+
if arguments.nocolor:
10+
disable_all_colors()
11+
12+
self.verbose = arguments.verbose
13+
self.silent = arguments.silent
14+
self.seperator = "=============================================="
15+
16+
def print_banner(self):
17+
if self.silent:
18+
return
19+
20+
print(self.seperator)
21+
print("Interlace v%s\tby Michael Skelton (@codingo_)" % __version__)
22+
print(self.seperator)
23+
24+
def terminal(self, level, target, command, message=""):
25+
if level == 0 and not self.verbose:
26+
return
27+
28+
formatting = {
29+
0: Color('{autoblue}[VERBOSE]{/autoblue}'),
30+
1: Color('{autogreen}[THREAD]{/autogreen}'),
31+
3: Color('{autobgyellow}{autored}[ERROR]{/autobgyellow}{/autored}')
32+
}
33+
34+
leader = formatting.get(level, '[#]')
35+
36+
format_args = {
37+
'time': strftime("%H:%M:%S", localtime()),
38+
'target': target,
39+
'command': command,
40+
'message': message,
41+
'leader':leader
42+
}
43+
44+
if level == 1:
45+
template = '[{time}] {leader} [{target}] {command} {message}'
46+
else:
47+
template = '[{time}] {leader} [{target}] {command} {message}'
48+
49+
print(template.format(**format_args))
50+
51+
class Level(IntEnum):
52+
VERBOSE = 0
53+
THREAD = 1
54+
ERROR = 3

0 commit comments

Comments
 (0)