Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
enty8080 committed May 18, 2024
1 parent 4df6af0 commit 2aa6c35
Show file tree
Hide file tree
Showing 26 changed files with 476 additions and 489 deletions.
8 changes: 6 additions & 2 deletions hatsploit/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from hatsploit.lib.jobs import Jobs
from hatsploit.lib.runtime import Runtime
from hatsploit.lib.payloads import Payloads
from hatsploit.lib.encoders import Encoders
from hatsploit.lib.show import Show


Expand Down Expand Up @@ -326,6 +327,7 @@ def __init__(self) -> None:

self.hatasm = HatAsm()
self.payloads = Payloads()
self.encoders = Encoders()

self.show = Show()

Expand Down Expand Up @@ -462,9 +464,11 @@ def cli(self) -> None:
query += '/' + args.arch

if args.payloads:
self.show.show_search_payloads(query)
self.show.show_search_payloads(
self.payloads.get_payloads(), query)
elif args.encoders:
self.show.show_search_encoders(query)
self.show.show_search_encoders(
self.encoders.get_encoders(), query)

elif args.formats:
if not args.platform:
Expand Down
2 changes: 1 addition & 1 deletion hatsploit/commands/advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ def rpc(self, *args):
return self.modules.get_current_advanced()

def run(self, argc, argv):
self.show.show_advanced()
self.show.show_advanced(self.modules.get_current_module())
6 changes: 5 additions & 1 deletion hatsploit/commands/encoder_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,14 @@ def run(self, argc, argv):
choice = argv[1]

if choice == '-l':
self.show.show_encoder_databases()
self.show.show_encoder_databases(
self.db.get_encoder_databases())

elif choice == '-d':
self.db.disconnect_encoder_database(argv[2])

elif choice == '-b':
self.builder.build_encoder_database(argv[2], argv[3])

elif choice == '-c':
self.db.connect_encoder_database(argv[2], argv[3])
2 changes: 1 addition & 1 deletion hatsploit/commands/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ def rpc(self, *args):
return self.encoders.get_encoders()

def run(self, argc, argv):
self.show.show_encoders()
self.show.show_encoders(self.encoders.get_encoders())
2 changes: 1 addition & 1 deletion hatsploit/commands/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def run(self, argc, argv):
choice = argv[1]

if choice == '-l':
self.show.show_jobs()
self.show.show_jobs(self.jobs.get_jobs())

elif choice == '-k':
self.jobs.delete_job(argv[2])
2 changes: 1 addition & 1 deletion hatsploit/commands/loot.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def run(self, argc, argv):
choice = argv[1]

if choice == '-l':
self.show.show_loot()
self.show.show_loot(self.loot.list_loot())

elif choice == '-r':
self.loot.remove_loot(argv[2])
6 changes: 5 additions & 1 deletion hatsploit/commands/module_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ def run(self, argc, argv):
choice = argv[1]

if choice == '-l':
self.show.show_module_databases()
self.show.show_module_databases(
self.db.get_module_databases())

elif choice == '-d':
self.db.disconnect_module_database(argv[2])

elif choice == '-b':
self.builder.build_module_database(argv[2], argv[3])

elif choice == '-c':
self.db.connect_module_database(argv[2], argv[3])
4 changes: 2 additions & 2 deletions hatsploit/commands/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def run(self, argc, argv):

if argc > 1:
if argv[1] in categories:
self.show.show_modules(argv[1])
self.show.show_modules(self.modules.get_modules(), argv[1])
else:
self.print_error("Invalid module category!")
self.print_information(f"Available categories: {str(categories)}")
else:
self.show.show_modules()
self.show.show_modules(self.modules.get_modules())
2 changes: 1 addition & 1 deletion hatsploit/commands/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ def rpc(self, *args):
return self.modules.get_current_options()

def run(self, argc, argv):
self.show.show_options()
self.show.show_options(self.modules.get_current_module())
6 changes: 5 additions & 1 deletion hatsploit/commands/payload_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,14 @@ def run(self, argc, argv):
choice = argv[1]

if choice == '-l':
self.show.show_payload_databases()
self.show.show_payload_databases(
self.db.get_payload_databases())

elif choice == '-d':
self.db.disconnect_payload_database(argv[2])

elif choice == '-b':
self.builder.build_payload_database(argv[2], argv[3])

elif choice == '-c':
self.db.connect_payload_database(argv[2], argv[3])
2 changes: 1 addition & 1 deletion hatsploit/commands/payloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ def rpc(self, *args):
return self.payloads.get_payloads()

def run(self, argc, argv):
self.show.show_payloads()
self.show.show_payloads(self.payloads.get_payloads())
6 changes: 5 additions & 1 deletion hatsploit/commands/plugin_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ def run(self, argc, argv):
choice = argv[1]

if choice == '-l':
self.show.show_plugin_databases()
self.show.show_plugin_databases(
self.db.get_plugin_databases())

elif choice == '-d':
self.db.disconnect_plugin_database(argv[2])

elif choice == '-b':
self.builder.build_plugin_database(argv[2], argv[3])

elif choice == '-c':
self.db.connect_plugin_database(argv[2], argv[3])
4 changes: 2 additions & 2 deletions hatsploit/commands/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self):
super().__init__()

self.show = Show()
self.plguins = Plugins()
self.plugins = Plugins()

self.details.update({
'Category': "plugins",
Expand All @@ -30,4 +30,4 @@ def rpc(self, *args):
return self.plugins.get_plugins()

def run(self, argc, argv):
self.show.show_plugins()
self.show.show_plugins(self.plugins.get_plugins())
57 changes: 37 additions & 20 deletions hatsploit/commands/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@
from hatsploit.lib.command import Command
from hatsploit.lib.show import Show

from hatsploit.lib.modules import Modules
from hatsploit.lib.payloads import Payloads
from hatsploit.lib.encoders import Encoders
from hatsploit.lib.plugins import Plugins


class HatSploitCommand(Command):
def __init__(self):
super().__init__()

self.show = Show()
self.modules = Modules()
self.payloads = Payloads()
self.encoders = Encoders()
self.plugins = Plugins()

self.details.update({
'Category': "core",
Expand All @@ -20,26 +29,34 @@ def __init__(self):
'Ivan Nikolskiy (enty8080) - command developer',
],
'Description': "Search payloads, modules and plugins.",
'Usage': "search <option> <keyword>",
'MinArgs': 2,
'Options': {
'-w': ['[payloads|encoders|modules|plugins]', "Select where to search."],
'-e': ['', "Search everywhere."],
},
'Usage': "search [where] <keyword>",
'MinArgs': 1,
})

def run(self, argc, argv):
if argv[1] not in ['-w', '--where']:
self.show.show_search_modules(argv[2])
self.show.show_search_payloads(argv[2])
self.show.show_search_encoders(argv[2])
self.show.show_search_plugins(argv[2])
else:
if argv[2] == 'modules':
self.show.show_search_modules(argv[3])
elif argv[2] == 'payloads':
self.show.show_search_payloads(argv[3])
elif argv[2] == 'encoders':
self.show.show_search_encoders(argv[3])
elif argv[2] == 'plugins':
self.show.show_search_plugins(argv[3])
if argc > 2:
if argv[1] == 'modules':
self.show.show_search_modules(
self.modules.get_modules(), argv[2])

elif argv[1] == 'payloads':
self.show.show_search_payloads(
self.payloads.get_payloads(), argv[2])

elif argv[1] == 'encoders':
self.show.show_search_encoders(
self.encoders.get_encoders(), argv[2])

elif argv[1] == 'plugins':
self.show.show_search_plugins(
self.plugins.get_plugins(), argv[2])
return

self.show.show_search_modules(
self.modules.get_modules(), argv[1])
self.show.show_search_payloads(
self.payloads.get_payloads(), argv[1])
self.show.show_search_encoders(
self.encoders.get_encoders(), argv[1])
self.show.show_search_plugins(
self.plugins.get_plugins(), argv[1])
8 changes: 7 additions & 1 deletion hatsploit/commands/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,23 @@ def __init__(self):

def run(self, argc, argv):
if argv[1] == '-l':
self.show.show_sessions()
self.show.show_sessions(self.sessions.get_sessions())

elif argv[1] == '-c':
self.sessions.close_session(argv[2])

elif argv[1] == '-i':
self.sessions.interact_with_session(argv[2])

elif argv[1] == '-d':
self.sessions.session_download(argv[2], argv[3], argv[4])

elif argv[1] == '-u':
self.sessions.session_upload(argv[2], argv[3], argv[4])

elif argv[1] == '--auto-interaction':
if argv[2] == 'on':
self.sessions.enable_auto_interaction()

elif argv[2] == 'off':
self.sessions.disable_auto_interaction()
10 changes: 5 additions & 5 deletions hatsploit/core/base/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@
import sys

from badges import Badges
from pex.string import String

from hatsploit.core.base.execute import Execute

from hatsploit.core.cli.fmt import FMT

from hatsploit.core.utils.ui.banner import Banner
from hatsploit.core.utils.ui.completer import Completer
from hatsploit.core.utils.ui.tip import Tip
Expand All @@ -54,7 +53,7 @@ def __init__(self) -> None:

self.execute = Execute()

self.fmt = FMT()
self.string = String()
self.badges = Badges()

self.completer = Completer()
Expand Down Expand Up @@ -91,7 +90,8 @@ def shell_execute(self) -> None:
commands = self.badges.input_empty(prompt)

self.runtime.update()
self.execute.execute_command(self.fmt.format_commands(commands))
self.badges.print_function(self.execute.execute_command,
self.string.split_args(commands))
self.runtime.update()

if self.local_storage.get("history"):
Expand Down Expand Up @@ -211,7 +211,7 @@ def script(self, input_files: list, shell: bool = True) -> None:
file.close()

for line in file_text:
commands = self.fmt.format_commands(line)
commands = self.string.split_args(line)

self.runtime.update()
self.runtime.catch(
Expand Down
3 changes: 0 additions & 3 deletions hatsploit/core/base/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
from typing import Any, Tuple, Union
from badges import Badges, Tables

from hatsploit.core.cli.fmt import FMT

from hatsploit.lib.jobs import Jobs
from hatsploit.lib.modules import Modules
from hatsploit.lib.show import Show
Expand All @@ -48,7 +46,6 @@ def __init__(self) -> None:
super().__init__()

self.jobs = Jobs()
self.fmt = FMT()
self.badges = Badges()
self.tables = Tables()
self.local_storage = LocalStorage()
Expand Down
23 changes: 0 additions & 23 deletions hatsploit/core/cli/__init__.py

This file was deleted.

Loading

0 comments on commit 2aa6c35

Please sign in to comment.