Skip to content

Commit

Permalink
Made handler less-complex
Browse files Browse the repository at this point in the history
Made handler less-complex
  • Loading branch information
enty8080 authored Oct 29, 2023
2 parents fc1b239 + 4c98f90 commit 3954dfb
Show file tree
Hide file tree
Showing 135 changed files with 493 additions and 472 deletions.
6 changes: 6 additions & 0 deletions hatsploit/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,12 @@ def cli(self) -> None:
scripts=[self.path_config['startup_path'], args.script],
rpc=rpc
)
else:
self.launch(
shell=args.no_exit,
scripts=[args.script],
rpc=rpc
)

sys.exit(0)

Expand Down
2 changes: 1 addition & 1 deletion hatsploit/commands/unset.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self):
'Authors': [
'Ivan Nikolsky (enty8080) - command developer',
],
'Description': "Unset an option / Set to nil.",
'Description': "Unset an option / Set to None.",
'Usage': "unset <option>",
'MinArgs': 1,
})
Expand Down
2 changes: 1 addition & 1 deletion hatsploit/config/storage.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"history": true,
"history": false,
"log": false,
"auto_interaction": true
}
10 changes: 4 additions & 6 deletions hatsploit/core/base/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
SOFTWARE.
"""

try:
import gnureadline as readline
except Exception:
import readline
import readline

import os
import sys
Expand Down Expand Up @@ -192,7 +189,7 @@ def show_header(self) -> None:
if self.config.core_config['console']['tip']:
self.tip.print_random_tip()

def script(self, input_files: list, shell: bool = False) -> None:
def script(self, input_files: list, shell: bool = True) -> None:
""" Execute HatSploit script(s).
:param list input_files: list of filenames of files
Expand All @@ -214,7 +211,8 @@ def script(self, input_files: list, shell: bool = False) -> None:
commands = self.fmt.format_commands(line)

self.runtime.update()
self.execute.execute_command(commands)
self.runtime.catch(
self.execute.execute_command(commands))
self.runtime.update()

if shell:
Expand Down
17 changes: 3 additions & 14 deletions hatsploit/core/base/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@
from hatsploit.core.cli.fmt import FMT
from hatsploit.lib.storage import LocalStorage

patch = False

try:
import gnureadline as readline

except Exception:
import readline
patch = True
import readline


class IO(object):
Expand All @@ -64,7 +57,7 @@ def print(self, message: str = '', start: str = '%remove', end: str = '%newline'
:return None: None
"""

line = self.color_script.parse(start + message + end)
line = self.color_script.parse(str(start) + str(message) + str(end))
use_log = self.local_storage.get("log")

sys.stdout.write(line)
Expand All @@ -89,11 +82,7 @@ def input(self, message: str = '', start: str = '%remove%end', end: str = '%end'
:return list: read string separated by space and commas
"""

message = start + message + end

if patch:
message = self.color_script.libreadline(message)

message = str(start) + str(message) + str(end)
line = self.color_script.parse(message)

use_log = self.local_storage.get("log")
Expand Down
8 changes: 4 additions & 4 deletions hatsploit/core/db/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def build_encoder_database(self, input_path: str, output_path: str) -> None:
"Encoder": encoder_object.details['Encoder'],
"Authors": encoder_object.details['Authors'],
"Description": encoder_object.details['Description'],
"Arch": encoder_object.details['Arch'],
"Arch": str(encoder_object.details['Arch']),
}
})

Expand Down Expand Up @@ -178,8 +178,8 @@ def build_payload_database(self, input_path: str, output_path: str) -> None:
"Payload": payload_object.details['Payload'],
"Authors": payload_object.details['Authors'],
"Description": payload_object.details['Description'],
"Arch": payload_object.details['Arch'],
"Platform": payload_object.details['Platform'],
"Arch": str(payload_object.details['Arch']),
"Platform": str(payload_object.details['Platform']),
"Rank": payload_object.details['Rank'],
"Type": payload_object.details['Type'],
}
Expand Down Expand Up @@ -223,7 +223,7 @@ def build_module_database(self, input_path: str, output_path: str) -> None:
"Module": module_object.details['Module'],
"Authors": module_object.details['Authors'],
"Description": module_object.details['Description'],
"Platform": module_object.details['Platform'],
"Platform": str(module_object.details['Platform']),
"Rank": module_object.details['Rank'],
}
})
Expand Down
5 changes: 1 addition & 4 deletions hatsploit/core/utils/ui/completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
SOFTWARE.
"""

try:
import gnureadline as readline
except Exception:
import readline
import readline

from hatsploit.core.cli.fmt import FMT
from hatsploit.lib.commands import Commands
Expand Down
2 changes: 1 addition & 1 deletion hatsploit/encoders/generic/base64.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self):
'Ivan Nikolsky (enty8080) - encoder developer',
],
'Description': "Encode command with base64.",
'Arch': "generic",
'Arch': ARCH_GENERIC,
})

self.shell = Option("$SHELL", "Shell to execute.", True)
Expand Down
2 changes: 1 addition & 1 deletion hatsploit/encoders/x64/xor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self):
'Ivan Nikolsky (enty8080) - encoder developer',
],
'Description': "Simple XOR encoder for x64.",
'Arch': "x64",
'Arch': ARCH_X64,
})

self.key = Option("hatspl64", "8-byte key to encode.", True)
Expand Down
12 changes: 6 additions & 6 deletions hatsploit/lib/complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
SOFTWARE.
"""

from hatsploit.lib.option import OptionResolver
from hatsploit.lib.option import Option

from hatsploit.lib.modules import Modules
from hatsploit.lib.payloads import Payloads
from hatsploit.lib.encoders import Encoders
from hatsploit.lib.sessions import Sessions


class PayloadOption(OptionResolver):
class PayloadOption(Option):
modules = Modules()
payloads = Payloads()

Expand All @@ -57,7 +57,7 @@ def set(self, value):
raise RuntimeError("Invalid option value, expected valid payload!")


class EncoderOption(OptionResolver):
class EncoderOption(Option):
modules = Modules()
payloads = Payloads()
encoders = Encoders()
Expand Down Expand Up @@ -87,9 +87,9 @@ def set(self, value):
raise RuntimeError("Invalid option value, expected valid encoder!")


class SessionOption(OptionResolver):
class SessionOption(Option):
def __init__(self, *args, platforms: list = [], type: str = '', **kwargs):
super(OptionResolver, self).__init__(*args, **kwargs)
Option.__init__(self, *args, **kwargs)

self.sessions = Sessions()
self.modules = Modules()
Expand All @@ -111,7 +111,7 @@ def set(self, value):
session = 0

for platform in self.platforms:
if self.sessions.check_exist(value, platform.strip(), self.type):
if self.sessions.check_exist(value, platform, self.type):
session = 1
break

Expand Down
16 changes: 15 additions & 1 deletion hatsploit/lib/encoder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@
SOFTWARE.
"""

from typing import Any, Optional

from hatsploit.lib.option import *

from hatsploit.core.cli.badges import Badges
from hatsploit.core.cli.tables import Tables
from hatsploit.core.cli.tools import Tools

from hatsploit.lib.options import Options


class Encoder(Badges, Tables, Tools):
""" Subclass of hatsploit.lib module.
Expand All @@ -46,11 +50,21 @@ def __init__(self) -> None:
''
],
'Description': "",
'Arch': ""
'Arch': None
}

self.iterations = IntegerOption(1, "Number of iterations.", False, True)

def set(self, option: str, value: Optional[str] = None) -> bool:
""" Set encoder option.
:param str option: option name
:param Optional[str] value: option value
:return bool: True if success else False
"""

return Options().set_option(self, option, value)

def run(self) -> None:
""" Run this encoder.
Expand Down
2 changes: 2 additions & 0 deletions hatsploit/lib/encoder/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@
"""

from hatsploit.lib.encoder import Encoder

from pex.arch.types import *
from hatsploit.lib.option import *
13 changes: 1 addition & 12 deletions hatsploit/lib/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,17 +269,6 @@ def add_encoder(self, module: str, payload: str, encoder: str) -> None:
if not self.import_encoder(module, payload, encoder):
raise RuntimeError(f"Failed to select encoder from database: {encoder}!")

def set_option_value(self, encoder: Encoder, option: str, value: Optional[str] = None) -> bool:
""" Set encoder option value.
:param Encoder encoder: encoder object
:param str option: option name
:param Optional[str] value: option value
:return bool: True if success else False
"""

return self.options.set_option(encoder, option, value)

@staticmethod
def validate_options(encoder: Encoder) -> list:
""" Validate missed encoder options.
Expand All @@ -294,7 +283,7 @@ def validate_options(encoder: Encoder) -> list:
for option in encoder.options:
validate = encoder.options[option]

if not validate['Value'] and validate['Value'] != 0 and validate['Required']:
if validate['Value'] is None and validate['Required']:
missed.append(option)

return missed
4 changes: 2 additions & 2 deletions hatsploit/lib/handler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ def open_session(self, session: Session,
:return None: None
"""

platform = session.details['Platform']
arch = session.details['Arch']
platform = str(session.details['Platform'])
arch = str(session.details['Arch'])
type = session.details['Type']
host = session.details['Host']
port = session.details['Port']
Expand Down
4 changes: 2 additions & 2 deletions hatsploit/lib/handler/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def download(self, remote_file, local_path):
self.print_process(f"Downloading {remote_file}...")

data = self.pull(
platform=self.details['Platform'],
platform=str(self.details['Platform']),
sender=self.channel.send_command,
location=remote_file,
)
Expand All @@ -77,7 +77,7 @@ def upload(self, local_file, remote_path):

if data:
remote_path = self.push(
platform=self.details['Platform'],
platform=str(self.details['Platform']),
sender=self.send_command,
data=data,
location=remote_path,
Expand Down
Loading

0 comments on commit 3954dfb

Please sign in to comment.