Skip to content

Commit

Permalink
Add typing
Browse files Browse the repository at this point in the history
  • Loading branch information
rtpt-romankarwacik committed Nov 26, 2024
1 parent ebcf32f commit 76e5638
Show file tree
Hide file tree
Showing 11 changed files with 375 additions and 293 deletions.
19 changes: 15 additions & 4 deletions smbclientng/core/CommandCompleter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
# Author : Podalirius (@podalirius_)
# Date created : 20 may 2024


from __future__ import annotations
import ntpath
import os
import shlex
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Optional
from smbclientng.core.SMBSession import SMBSession
from smbclientng.core.Config import Config
from smbclientng.core.Logger import Logger


class CommandCompleter(object):
Expand Down Expand Up @@ -334,8 +341,12 @@ class CommandCompleter(object):
"autocomplete": ["share"]
},
}

smbSession: SMBSession
config: Config
logger: Logger

def __init__(self, smbSession, config, logger):
def __init__(self, smbSession: SMBSession, config: Config, logger: Logger):
# Objects
self.smbSession = smbSession
self.config = config
Expand All @@ -344,7 +355,7 @@ def __init__(self, smbSession, config, logger):
self.commands["help"]["subcommands"] = ["format"] + list(self.commands.keys())
self.commands["help"]["subcommands"].remove("help")

def complete(self, text, state):
def complete(self, text: str, state: int) -> str:
"""
Function to handle command completion in the LDAP console.
Expand Down Expand Up @@ -497,7 +508,7 @@ def complete(self, text, state):
except IndexError:
return None

def print_help(self, command=None):
def print_help(self, command: Optional[str] = None):
"""
Prints help information for a specific command or all commands if no command is specified.
Expand Down
6 changes: 4 additions & 2 deletions smbclientng/core/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ class Config(object):
no_colors: Property to get or set the colored output preference.
"""

not_interactive = False
not_interactive: bool = False
startup_script = None
_debug: bool
_no_colors: bool

def __init__(self, debug=False, no_colors=None):
def __init__(self, debug: bool = False, no_colors=None):
self._debug = debug

if no_colors is not None:
Expand Down
41 changes: 21 additions & 20 deletions smbclientng/core/Credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,50 @@
# Author : Podalirius (@podalirius_)
# Date created : 22 June 2024


from __future__ import annotations
from smbclientng.core.utils import parse_lm_nt_hashes
import re
import binascii

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Optional

class Credentials(object):
"""
Documentation for class Credentials
"""

# Identity
domain = None
username = None
password = None
domain: Optional[str]
username: Optional[str]
password: Optional[str]
# Hashes
nt_hex = ""
nt_raw = ""
lm_hex = ""
lm_raw = ""
nt_hex: str
nt_raw: bytes
lm_hex: str
lm_raw: bytes
# Kerberos
use_kerberos = False
aesKey = None
kdcHost = None
use_kerberos: bool = False
aesKey: Optional[str]
kdcHost: Optional[str]

def __init__(self, domain, username, password, hashes=None, use_kerberos=False, aesKey=None, kdcHost=None):
def __init__(self, domain: str, username: str, password: str, hashes: Optional[str] = None, use_kerberos: bool = False, aesKey: Optional[str] = None, kdcHost: Optional[str] = None):
super(Credentials, self).__init__()
# Identity
self.domain = domain
self.username = username
self.password = password

# Hashes
self.nt_hex = ""
self.nt_raw = ""
self.lm_hex = ""
self.lm_raw = ""
self.set_hashes(hashes=hashes)

# Kerberos
self.use_kerberos = use_kerberos
self.kdcHost = kdcHost
self.aesKey = aesKey

def set_hashes(self, hashes):
def set_hashes(self, hashes: Optional[str]):
"""
Sets the LM and NT hashes for the credentials.
Expand All @@ -60,9 +61,9 @@ def set_hashes(self, hashes):
"""

self.nt_hex = ""
self.nt_raw = ""
self.nt_raw = b""
self.lm_hex = ""
self.lm_raw = ""
self.lm_raw = b""

lmhash, nthash = None, None
if hashes is not None:
Expand Down
Loading

0 comments on commit 76e5638

Please sign in to comment.