Skip to content

Commit

Permalink
New Error System, Better API, Vars, auto_set_vars
Browse files Browse the repository at this point in the history
  • Loading branch information
Skiller9090 committed Aug 18, 2020
1 parent c9c7f2a commit 2d90660
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 23 deletions.
6 changes: 6 additions & 0 deletions libs/LuciferArgParse.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ def check_gui(self):
self.luciferManager.main_shell = Shell(self.luciferManager.next_shell_id, self.luciferManager)
self.luciferManager.next_shell_id += 1
self.luciferManager.main_shell.spawn()

def check_autoset(self):
if self.args.auto_set_vars:
self.luciferManager.auto_vars = True
print("Auto Set Variables Enabled")

19 changes: 18 additions & 1 deletion libs/LuciferErrors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,21 @@ def __init__(self, message):
self.message = message

def __str__(self):
return "Incompatible System Error: " + str(self.message)
return "Incompatible System Error: " + str(self.message)


class NoShellError(Exception):
def __init__(self, message):
self.message = message

def __str__(self):
return "No Shell Error Error: " + str(self.message)


def checkErrors(e):
try:
raise e
except IncompatibleSystemError:
print(e)
except NoShellError:
print(e)
4 changes: 3 additions & 1 deletion libs/LuciferManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@


class LuciferManager:
def __init__(self):
def __init__(self, auto_vars=False):
self.main_shell = None
self.alternative_shells = []
self.gui = False
self.next_shell_id = 0
self.shell_recur = 0
self.colorama = colorama
self.termcolor = termcolor
self.current_shell_id = 0
self.auto_vars = auto_vars

def end(self, *args, **kwargs):
print("Thank you for using Lucifer, see you next time!")
Expand Down
118 changes: 102 additions & 16 deletions libs/LuciferShell.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .utils import check_int
from .LuciferErrors import IncompatibleSystemError
from .LuciferErrors import checkErrors
import re
import os
import importlib
Expand All @@ -17,6 +17,7 @@ def __init__(self, ID, lucifer_manager):
self.program_name = "Lucifer"
self.shell_in = ""
self.vars = {}
self.auto_vars = lucifer_manager.auto_vars
self.help_menu = """help - Displays This Menu
show - Shows options or modules based on input, EX: show <options/modules>
use - Move into a module, EX: use <module>
Expand Down Expand Up @@ -51,8 +52,15 @@ def __init__(self, ID, lucifer_manager):
"clear": self.clear_shell,
"use": self.use,
"run": self.run_module,
"exploit": self.run_module

"exploit": self.run_module,
"set_vars": self.set_vars,
"options": self.show_options,
"description": self.describe_module,
"describe": self.describe_module,
"auto_vars": self.print_auto_vars,
"change_auto_vars": self.change_auto_set_vars,
"auto_var": self.print_auto_vars,
"change_auto_var": self.change_auto_set_vars
}
self.luciferManager.shell_recur += 1

Expand All @@ -61,10 +69,10 @@ def getIn(self):
f"{self.module if '.py' not in self.module else self.module.replace('.py', '')}" +
f"|{self.id}> ")

def print_id(self, com_args: list):
def print_id(self, *args, **kwargs):
print(f"Shell ID: {self.id}")

def print_name(self, com_args: list):
def print_name(self, *args, **kwargs):
print(f"Shell Name: {self.name}")

def parseShellIn(self):
Expand All @@ -79,7 +87,7 @@ def parseShellIn(self):
return return_value
return

def help(self, com_args):
def help(self, *args, **kwargs):
print(self.help_menu)

def spawn(self):
Expand All @@ -101,7 +109,7 @@ def command_set(self, com_args: list):
else:
print("Please specify a variable to set")

def spawn_shell(self, com_args: list):
def spawn_shell(self, *args, **kwargs):
self.luciferManager.alternative_shells.append(Shell(self.luciferManager.next_shell_id, self.luciferManager))
self.luciferManager.next_shell_id += 1
self.luciferManager.alternative_shells[-1].name += str(self.luciferManager.next_shell_id - 1)
Expand All @@ -113,19 +121,31 @@ def show(self, com_args: list):
self.show_options()
return
else:
print("Please enter a valid argument: options or modules")
print("Please enter a valid argument: options/vars or modules")
else:
print("Please specify options or modules to show!")
return

def show_options(self):
print(self.vars)
def show_options(self, *args, **kwargs):
max_l = 0
for k, v in zip(self.vars.keys(), self.vars.values()):
if len(k) + 2 > max_l:
max_l = len(k) + 2
if len(v) > max_l:
max_l = len(v)
if (2 * max_l - 3) % 2 != 0:
max_l += 1
title_padding = int((2 * max_l - 3) / 2)
print(f"{' ' * title_padding}" +
f"{self.luciferManager.termcolor.colored('Vars', 'green', attrs=['bold', 'underline'])}")
print("=" * (2 * title_padding + 5))
for k, v in zip(self.vars.keys(), self.vars.values()):
print(f"{k}{' ' * (max_l - len(k))}| {v}")
return

def use_module(self, mod_path: list):
if self.module_obj is not None:
self.loaded_modules[self.module] = self.module_obj
print(mod_path)
ori_path = mod_path.copy()
file = mod_path.pop(-1)
path = "modules"
Expand Down Expand Up @@ -162,31 +182,57 @@ def use_module(self, mod_path: list):
imported_module = importlib.import_module(to_import + "." + pkg)
self.module_obj = imported_module.Module(self.luciferManager, ShellRun=True)
self.loaded_modules[self.module] = self.module_obj
if self.auto_vars:
self.set_vars()
return

def run_module(self, com_args: list):
def run_module(self, *args, **kwargs):
try:
if self.module_obj is not None:
self.module_obj.run()
return
else:
print("Please Select A Module First!")
return
except IncompatibleSystemError as e:
print(e)
except Exception as e:
checkErrors(e)

def describe_module(self, *args, **kwargs):
try:
if self.module_obj is not None:
print(self.module_obj.get_description())
return
else:
print("Please Select A Module First!")
return
except Exception as e:
checkErrors(e)

def set_vars(self, *args, **kwargs):
try:
if self.module_obj is not None:
self.vars.update(self.module_obj.set_vars())
return
else:
print("Please Select A Module First!")
return
except Exception as e:
checkErrors(e)

def open_shell(self, com_args: list):
if len(com_args) > 1:
openid = com_args[1].rstrip()
if check_int(openid):
openid = int(openid)
if openid == 0:
self.luciferManager.current_shell_id = 0
self.luciferManager.main_shell.spawn()
return
else:
found = False
for index, shell in enumerate(self.luciferManager.alternative_shells):
if shell.id == openid:
self.luciferManager.current_shell_id = openid
self.luciferManager.alternative_shells[index].spawn()
return
else:
Expand All @@ -199,7 +245,7 @@ def open_shell(self, com_args: list):
print("Please specify a valid ID")
return

def show_shells(self, com_args: list):
def show_shells(self, *args, **kwargs):
print(f"{self.luciferManager.main_shell.name} => {self.luciferManager.main_shell.id}")
for shell in self.luciferManager.alternative_shells:
print(f"{shell.name} => {shell.id}")
Expand Down Expand Up @@ -239,7 +285,7 @@ def set_name_id(self, com_args: list):
print("Please add a valid ID")
return

def clear_shell(self, com_args: list):
def clear_shell(self, *args, **kwargs):
print(self.luciferManager.colorama.ansi.clear_screen())

def use(self, com_args: list):
Expand All @@ -263,3 +309,43 @@ def background_shell(self, com_args: list):
else:
self.luciferManager.shell_recur -= 1
return 7

def change_auto_set_vars(self, com_args: list):
com_args.pop(0)
if len(com_args) > 0:
to_set = None
set_global = False
set_for_new = False
inclusive = False
for argument in com_args:
argument = argument.rstrip()
if argument.lower() == "true" or argument.lower() == "t" or argument.lower() == "-t":
to_set = True
elif argument.lower() == "false" or argument.lower() == "f" or argument.lower() == "-f":
to_set = False
elif argument.lower() == "-g":
set_global = True
elif argument.lower() == "-n":
set_for_new = True
elif argument.lower() == "-i":
inclusive = True
if to_set is None:
print("Please Add An Argument!")
return
if set_global:
self.luciferManager.main_shell.auto_vars = to_set
for shell in self.luciferManager.alternative_shells:
shell.auto_vars = to_set
print(f"Auto Variable On All Shells => {to_set}")
if (not set_for_new and not set_global) or inclusive:
self.auto_vars = to_set
print(f"This Shell Auto Vars => {to_set}")
if set_for_new:
self.luciferManager.auto_vars = to_set
print(f"Future Shells Will Have Auto Vars => {to_set}")
return
else:
print("Please Add Arguments!")

def print_auto_vars(self, *args, **kwargs):
print(f"Auto Var => {self.auto_vars}")
Binary file modified libs/__pycache__/LuciferArgParse.cpython-38.pyc
Binary file not shown.
Binary file modified libs/__pycache__/LuciferErrors.cpython-38.pyc
Binary file not shown.
Binary file modified libs/__pycache__/LuciferManager.cpython-38.pyc
Binary file not shown.
Binary file modified libs/__pycache__/LuciferShell.cpython-38.pyc
Binary file not shown.
7 changes: 6 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
parser = VAAETParser(luciferManager, description="Lucifer")
parser.add_argument("-g", "--gui", help="Enables The Gui Mode",
action="store_true", required=False)
parser.add_argument("-a", "--auto_set_vars", help="Enables Auto Setting of Vars On Module Load",
action="store_true", required=False)
parser.args = parser.parse_args()
# parser.check_args()


parser.check_autoset()
parser.check_gui()


luciferManager.end()
20 changes: 20 additions & 0 deletions modules/Module.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
from libs.LuciferErrors import NoShellError


class BaseModule:
def __init__(self, luciferManager, ShellRun=False):
self.luciferManager = luciferManager
self.actions = []
self.isShellRun = ShellRun
self.shell = self.luciferManager.main_shell if self.luciferManager.current_shell_id == 0 else None
if self.shell is None:
for shell in self.luciferManager.alternative_shells:
if shell.id == self.luciferManager.current_shell_id:
self.shell = shell
break
else:
raise NoShellError("Couldn't Find Shell With ID: "+str(self.luciferManager.current_shell_id))

def run(self):
for action in self.actions:
action()

def set_vars(self):
new_vars = {
}
return new_vars

def get_description(self):
desc = """This Module Has No Description!"""
return desc
Binary file modified modules/__pycache__/Module.cpython-38.pyc
Binary file not shown.
Binary file modified modules/auxiliary/gather/linux/__pycache__/uname.cpython-38.pyc
Binary file not shown.
22 changes: 18 additions & 4 deletions modules/auxiliary/gather/linux/uname.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,29 @@
import os


def get_uname():
return check_output(["uname", "-a"]).decode()
def get_uname(arg):
arg.insert(0, "uname")
return check_output(arg).decode()


class Module(BaseModule):
def run(self):
args = ["-a"]
if os.name == "nt":
raise IncompatibleSystemError("Not Unix")
if "args" in self.shell.vars.keys():
args = self.shell.vars["args"].split(" ")
if self.isShellRun:
print(get_uname())
print(get_uname(args))
else:
return get_uname()
return get_uname(args)

def set_vars(self):
new_vars = {
"args": "-a"
}
return new_vars

def get_description(self):
desc = """Gets the output of uname on a unix system with any arguments supplied in the args variable"""
return desc

0 comments on commit 2d90660

Please sign in to comment.