-
Notifications
You must be signed in to change notification settings - Fork 55
/
sheepl.py
182 lines (143 loc) · 7.04 KB
/
sheepl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/env python3
"""
The Core Sheepl Program
"""
__author__ = "Matt Lorentzen @lorentzenman"
__license__ = "MIT"
__version__ = "2.3"
import sys
import logging
import json
import random
import signal
import os
import argparse
# Sheepl Class Imports
from utils.tasks import Tasks
from utils.colours import ColourText
from utils.console import ConsoleContext
from utils.console import SheeplConsole
from profiles.profile import Profile
from template.template import CreateTemplate
def banner(version):
banner = """
███████╗██╗ ██╗███████╗███████╗██████╗ ██╗
██╔════╝██║ ██║██╔════╝██╔════╝██╔══██╗██║
███████╗███████║█████╗ █████╗ ██████╔╝██║
╚════██║██╔══██║██╔══╝ ██╔══╝ ██╔═══╝ ██║
███████║██║ ██║███████╗███████╗██║ ███████╗
╚══════╝╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚══════╝
version : %s
author : @lorentzenman
------------------------------------------------
""" %version
print(banner)
def signal_handler(sig, frame):
"""
Catches Control + C
"""
print("[!] You pressed Ctrl+C")
print("[!] Exiting Sheepl")
print("[<] ------------------------------------------ [>]")
print("""
/\___
@@@@@@@@@@@ O \\
@@@@@@@@@@@@@@@____/--[ later ]
@@@@@@@@@@@@@@@
|| ||
~~ ~~
---------------------------------------------
""")
sys.exit(0)
#######################################################################
# Commandline Arguments
#######################################################################
def parse_arguments():
# Below are the core arguments
parser = argparse.ArgumentParser(description="Creating realistic user behaviour for tradecraft emulation.")
main_parser = parser.add_argument_group('Main Program', 'Core Program Settings')
main_parser.add_argument("--interactive", action="store_true", default=False, help="Launches an interactive console making it easier to create complex sequences")
main_parser.add_argument("--loop", action="store_false", help="Loops the program based around the total_time, will create actions and then repeat", default=True)
main_parser.add_argument("--no_colour", action="store_false", help="Colours the output in the terminal <boolean> : defaults to True", default=True)
main_parser.add_argument("--no_tray", action="store_true", help="Removes compiled script tray icon", default=False)
# Profiles Options
profile_group = parser.add_argument_group('Profiles', 'Creates Sheepl files from JSON format files')
profile_group.add_argument("--profile", type=argparse.FileType('r', encoding='UTF-8'), help="Specifies a profile and will import commands based on the JSON file")
# Template Engine
#template_engine = parser.add_argument_group('Template Engine', 'Used to create a "task" template with boiler plate code and CMD module')
#template_engine.add_argument("--template", help="Name of the template")
#template_engine.add_argument("--category", help="Path category for module : all base tasks start within 'tasks' automatically")
# counts the supplied number of arguments and prints help if they are missing
if len(sys.argv)==1:
#parser.print_help()
print("[≤≥] Creating realistic user behaviour for tradecraft emulation.")
print("[>:] Either specify a profile file path for input or use interactive mode")
print("[>:] Example 'python3 sheepl.py --interactive' mode")
print("[oo] See 'python3 sheepl.py -h' for full list of switches")
# OCD line break
print()
sys.exit(1)
args = parser.parse_args()
return args
def main():
banner("2.3")
# hr = "------------------------------------"
# counter below needs to be added as part of the Sheepl Object
# this should get automatically incremented either based on the
# length of the task list or a counter tracker
# Main Parser Setup
args = parse_arguments()
# create project root
#ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
# assign colour output
colour_output = args.no_colour
print("[!] Colour output is set to : {}".format(str(colour_output).upper()))
cl = ColourText(colour_output)
tasks = Tasks()
# gets global header declarations for autoIT script
# >> Global Calls
# manual check for Interactive
if args.interactive:
interactive = True
context = ConsoleContext()
con = SheeplConsole(context, cl, tasks)
con.cmdloop()
# template functions need updating for the stub code so commenting out this feature for now.
# will fix in next push
# Check if creating template stub file and category.
# this should be replaced with pathlib functions
#if args.template and not args.category:
# print(cl.red("[!] You must specify a category eg 'network'"))
# print("[>] If this path does not exist, then it will be created")
#elif args.template:
# if not os.path.isdir('tasks/' + args.category.lower()):
# print(cl.yellow("[!] Couldn't find this category : " + args.category.lower()))
# print(cl.green("[!] Creating {} category path now.".format(args.category.lower())))
# os.mkdir('tasks/' + args.category.lower())
# else:
# print("[>] Category already Exists : " + cl.red("tasks/" + args.category.lower()))
# os.chdir('tasks/' + args.category.lower())
# if not os.path.isfile(args.template + '.py'):
# print("[!] Creating task template: {}".format(cl.green(args.template)))
# CreateTemplate(args.template)
# if os.path.isfile(args.template + '.py'):
# print(cl.red("[!] Task template already exists : " + args.template))
# # spam loop until yes or no is answered
# while 1:
# replace_template = input("[?] Do you want to replace this file? <yes> <no> : ")
# if replace_template.lower() == "yes" or replace_template.lower() == "no":
# break
# if replace_template.lower() == "yes":
# print("[!] Creating new task template : " + cl.green(args.template + '.py'))
# CreateTemplate(args.template)
# else:
# print(cl.green("[!] Leaving orginal template intact"))
# create from JSON profile
if args.profile:
print("[!] Create a sheepl from the profile file : {}".format(cl.green(args.profile.name)))
# Set Interactive to False
interactive = False
Profile(cl, args.profile.name, tasks)
if __name__ == '__main__':
signal.signal(signal.SIGINT, signal_handler)
main()