How to use the smbprotocol.structure.Structure function in smbprotocol

To help you get started, we’ve selected a few smbprotocol examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jborean93 / pypsexec / pypsexec / rpc.py View on Github external
('auth_verifier', BytesField(
                size=lambda s: s['auth_length'].get_value()
            ))
        ])
        super(RequestPDU, self).__init__()

    def _get_stub_data_size(self, structure):
        total_size = structure['frag_length'].get_value()
        fixed_size = 24
        object_size = len(structure['object'])
        auth_size = len(structure['auth_verifier'])

        return total_size - fixed_size - object_size - auth_size


class ResponsePDU(Structure):
    """
    rpcconn_response_hdr_t
    """

    def __init__(self):
        self.fields = OrderedDict([
            ('rpc_vers', IntField(
                size=1,
                default=5
            )),
            ('rpc_vers_minor', IntField(size=1)),
            ('ptype', EnumField(
                size=1,
                enum_type=PType,
                default=PType.RESPONSE
            )),
github jborean93 / pypsexec / pypsexec / rpc.py View on Github external
)
            )),
            ('auth_verifier', BytesField(
                size=lambda s: s['auth_length'].get_value()
            ))
        ])
        super(BindAckPDU, self).__init__()

    def _pad2_size(self, structure):
        sec_addr_size = 2 + len(structure['sec_addr'])

        mod = sec_addr_size % 8
        return 8 - mod if sec_addr_size > 8 else mod


class BindNakPDU(Structure):
    """
    http://pubs.opengroup.org/onlinepubs/9629399/chap12.htm#tagcjh_17_06_03
    rpcconn_bind_nak_hdr_t
    """

    def __init__(self):
        self.fields = OrderedDict([
            ('rpc_vers', IntField(
                size=1,
                default=5
            )),
            ('rpc_vers_minor', IntField(size=1)),
            ('ptype', EnumField(
                size=1,
                enum_type=PType,
                default=PType.BIND_NAK
github jborean93 / pypsexec / pypsexec / rpc.py View on Github external
size=1,
                enum_type=IntegerCharacterRepresentation,
                default=IntegerCharacterRepresentation.ASCII_LITTLE_ENDIAN
            )),
            ('floating_point', EnumField(
                size=1,
                enum_type=FloatingPointRepresentation,
                default=FloatingPointRepresentation.IEEE
            )),
            ('reserved1', IntField(size=1)),
            ('reserved2', IntField(size=1))
        ])
        super(DataRepresentationFormat, self).__init__()


class SyntaxIdElement(Structure):
    """
    http://pubs.opengroup.org/onlinepubs/9629399/chap12.htm#tagcjh_17_06_03
    p_syntax_id_t
    """

    def __init__(self):
        self.fields = OrderedDict([
            ('uuid', UuidField(little_endian=False)),
            ('version', IntField(size=4))
        ])
        super(SyntaxIdElement, self).__init__()


class ContextElement(Structure):
    """
    http://pubs.opengroup.org/onlinepubs/9629399/chap12.htm#tagcjh_17_06_03
github jborean93 / pypsexec / pypsexec / rpc.py View on Github external
NCA_S_FAULT_INVALID_TAG = 0x1C000006
    NCA_S_FAULT_PIPE_CLOSED = 0x1C000015
    NCA_S_FAULT_PIPE_COMM_ERROR = 0x1C000018
    NCA_S_FAULT_PIPE_DISCIPLINE = 0x1C000017
    NCA_S_FAULT_PIPE_EMPTY = 0x1C000014
    NCA_S_FAULT_PIPE_MEMORY = 0x1C000019
    NCA_S_FAULT_PIPE_ORDER = 0x1C000016
    NCA_S_FAULT_REMOTE_NO_MEMORY = 0x1C00001B
    NCS_S_FAULT_USER_DEFINED = 0x1C000021
    NCA_S_FAULT_TX_OPEN_FAILED = 0x1C000022
    NCA_S_FAULT_CODESET_CONV_ERROR = 0x1C000023
    NCA_S_FAULT_NO_CLIENT_STUB = 0x1C000025
    NCA_S_FAULT_NDR = 0x000006F7


class DataRepresentationFormat(Structure):
    """
    http://pubs.opengroup.org/onlinepubs/9629399/chap14.htm#tagcjh_19
    """

    def __init__(self):
        self.fields = OrderedDict([
            ('integer_character', EnumField(
                size=1,
                enum_type=IntegerCharacterRepresentation,
                default=IntegerCharacterRepresentation.ASCII_LITTLE_ENDIAN
            )),
            ('floating_point', EnumField(
                size=1,
                enum_type=FloatingPointRepresentation,
                default=FloatingPointRepresentation.IEEE
            )),
github jborean93 / pypsexec / pypsexec / rpc.py View on Github external
size=2,
                enum_type=ContextResult
            )),
            ('reason', EnumField(
                size=2,
                enum_type=ResultReason
            )),
            ('transfer_syntax', StructureField(
                size=20,
                structure_type=SyntaxIdElement
            )),
        ])
        super(Result, self).__init__()


class BindPDU(Structure):
    """
    http://pubs.opengroup.org/onlinepubs/9629399/chap12.htm#tagtcjh_28

    The bind PDU
    A BIND PDU message
    rpcconn_bind_hdr_t
    """

    def __init__(self):
        self.fields = OrderedDict([
            ('rpc_vers', IntField(
                size=1,
                default=5
            )),
            ('rpc_vers_minor', IntField(
                size=1,
github jborean93 / pypsexec / pypsexec / scmr.py View on Github external
ERROR_SERVICE_DISABLED = 1058
    ERROR_CIRCULAR_DEPENDENCY = 1059
    ERROR_SERVICE_DOES_NOT_EXIST = 1060
    ERROR_SERVICE_CANNOT_ACCEPT_CTRL = 1061
    ERROR_SERVICE_NOT_ACTIVE = 1062
    ERROR_DATABASE_DOES_NOT_EXIST = 1065
    ERROR_SERVICE_DEPENDENCY_FAIL = 1068
    ERROR_SERVICE_LOGON_FAILED = 1069
    ERROR_SERVICE_MARKED_FOR_DELETE = 1072
    ERROR_SERVICE_EXISTS = 1073
    ERROR_SERVICE_DEPENDENCY_DELETED = 1075
    ERROR_DUPLICATE_SERVICE_NAME = 1078
    ERROR_SHUTDOWN_IN_PROGRESS = 1115


class ServiceStatus(Structure):
    """
    [MS-SCMR] 2.2.47 SERVICE_STATUS
    https://msdn.microsoft.com/en-us/library/cc245911.aspx

    Defines Information about a service
    """

    def __init__(self):
        self.fields = OrderedDict([
            ('service_type', FlagField(
                size=4,
                flag_type=ServiceType,
                flag_strict=False
            )),
            ('current_state', EnumField(
                size=4,
github jborean93 / pypsexec / pypsexec / paexec.py View on Github external
class ProcessPriority(object):
    """
    https://msdn.microsoft.com/en-us/library/windows/desktop/ms683211(v=vs.85).aspx
    Set's the priority of the thread in the current process
    """
    ABOVE_NORMAL_PRIORITY_CLASS = 0x00008000
    BELOW_NORMAL_PRIORITY_CLASS = 0x00004000
    HIGH_PRIORITY_CLASS = 0x00000080
    IDLE_PRIORITY_CLASS = 0x00000040
    NORMAL_PRIORITY_CLASS = 0x00000020
    REALTIME_PRIORITY_CLASS = 0x00000100


class PAExecMsg(Structure):
    """
    Generic message from PAExec, the first 2 bytes denotes the Msg ID
    that tells the host the type of message it is and the buffer contents
    varies based on the type of message that is being sent of received.

    This is slightly different to the PAExecSettingsMsg as the data in the
    settings msg is xor'd to slightly obfuscate the data. The current buffer
    structures that have been defined are PAStartBuffer, PAReturnBuffer
    """
    def __init__(self):
        self.fields = OrderedDict([
            ('msg_id', EnumField(
                size=2,
                enum_type=PAExecMsgId
            )),
            ('unique_id', IntField(size=4)),
github jborean93 / pypsexec / pypsexec / paexec.py View on Github external
('filename_len', IntField(
                size=4,
                default=lambda s: int(len(s['filename']) / 2)
            )),
            ('filename', BytesField(
                size=lambda s: s['filename_len'].get_value() * 2
            )),
            ('file_last_write', DateTimeField(size=8)),
            ('file_version_ls', IntField(size=4)),
            ('file_version_ms', IntField(size=4)),
            ('copy_file', BoolField(size=1))
        ])
        super(PAExecFileInfo, self).__init__()


class PAExecStartBuffer(Structure):
    """
    Can't find where this is explicitly defined but this is the buffer used in
    the PAExecMsg to start a remote process. On receipt of this message, the
    remote process will match the settings based on the unique_id passed in and
    start the process based on those settings.

    The comp_name is a utf-16-le encoded string of the local hostname and
    should match the host used in the service name.
    """
    def __init__(self):
        self.fields = OrderedDict([
            ('process_id', IntField(size=4)),
            ('comp_name_length', IntField(
                size=4,
                default=lambda s: int(len(s['comp_name']) / 2)
            )),
github jborean93 / pypsexec / pypsexec / paexec.py View on Github external
file_structure, remaining_data = self._get_file(remaining_data)
            files.append(file_structure)
        return files

    def _get_file(self, data):
        min_size = 21
        filename_size = struct.unpack("
github jborean93 / pypsexec / pypsexec / rpc.py View on Github external
size=lambda s: s['auth_length'].get_value()
            ))
        ])
        super(BindPDU, self).__init__()

    def _unpack_context_elems(self, structure, data):
        context_elems = []
        while data != b"":
            context_elem = ContextElement()
            data = context_elem.unpack(data)
            context_elems.append(context_elem)

        return context_elems


class BindAckPDU(Structure):
    """
    http://pubs.opengroup.org/onlinepubs/9629399/chap12.htm#tagtcjh_28

    The bind_ack PDU
    A BIND ACK PDU message
    """

    def __init__(self):
        self.fields = OrderedDict([
            ('rpc_vers', IntField(
                size=1,
                default=5
            )),
            ('rpc_vers_minor', IntField(size=1)),
            ('ptype', EnumField(
                size=1,