class SAPDiagDP(Packet): """SAP Diag DP Header packet This packet is used for initialization of Diag connections. Usually there's no need to change any value more that the terminal. """ name = "SAP Diag DP Header" fields_desc = [ # DP Header SignedIntField("request_id", -1), ByteField("retcode", 0x0a), ByteField("sender_id", 0), ByteField("action_type", 0), IntField("req_info", 0), SignedIntField("tid", -1), SignedShortField("uid", -1), ByteField("mode", 0xff), SignedIntField("wp_id", -1), SignedIntField("wp_ca_blk", -1), SignedIntField("appc_ca_blk", -1), LenField( "length", None, fmt="<I" ), # The length in the DP Header is the length of the Diag Header (8 bytes) # plus the Diag Message (54 bytes for user_connect+support_data). As the # DP Header is the layer after NI during initialization, a LenField works # fine. ByteField("new_stat", 0), SignedIntField("unused1", -1), SignedShortField("rq_id", -1), StrFixedLenField("unused2", "\x20" * 40, 40), StrFixedLenField("terminal", "\x00" * 15, 15), StrFixedLenField("unused3", "\x00" * 10, 10), StrFixedLenField("unused4", "\x20" * 20, 20), IntField("unused5", 0), IntField("unused6", 0), SignedIntField("unused7", -1), IntField("unused8", 0), ByteField("unused9", 0x01), StrFixedLenField("unused10", "\x00" * 57, 57) ]
class SAPRFC(Packet): """SAP Remote Function Call packet This packet is used for the Remote Function Call (RFC) protocol. """ name = "SAP Remote Function Call" fields_desc = [ ByteField( "version", 3 ), # If the version is 3, the packet has a size > 88h, versions 1 and 2 are 40h ByteEnumKeysField("req_type", 0, rfc_req_type_values), # Normal client fields (GW_NORMAL_CLIENT) ConditionalField(IPField("address", "0.0.0.0"), lambda pkt: pkt.req_type == 0x03), ConditionalField(IntField("padd1", 0), lambda pkt: pkt.req_type == 0x03), ConditionalField(StrFixedLenPaddedField("service", "", length=10), lambda pkt: pkt.req_type == 0x03), ConditionalField(StrFixedLenField("codepage", "1100", length=4), lambda pkt: pkt.req_type == 0x03), ConditionalField(StrFixedLenField("padd2", "\x00" * 6, length=6), lambda pkt: pkt.req_type == 0x03), ConditionalField(StrFixedLenPaddedField("lu", "", length=8), lambda pkt: pkt.req_type == 0x03), ConditionalField(StrFixedLenPaddedField("tp", "", length=8), lambda pkt: pkt.req_type == 0x03), ConditionalField( StrFixedLenPaddedField("conversation_id", "", length=8), lambda pkt: pkt.req_type == 0x03), ConditionalField(ByteField("appc_header_version", 6), lambda pkt: pkt.req_type == 0x03), ConditionalField(ByteField("accept_info", 0xcb), lambda pkt: pkt.req_type == 0x03), ConditionalField(SignedShortField("idx", -1), lambda pkt: pkt.req_type == 0x03), ConditionalField( IP6Field("address6", "::"), lambda pkt: pkt.req_type == 0x03 and pkt.version == 3), ConditionalField(IntField("rc", 0), lambda pkt: pkt.req_type == 0x03), ConditionalField(ByteField("echo_data", 0), lambda pkt: pkt.req_type == 0x03), ConditionalField(ByteField("filler", 0), lambda pkt: pkt.req_type == 0x03), # Monitor Command fields (GW_SEND_CMD) ConditionalField(ByteEnumKeysField("cmd", 0, rfc_monitor_cmd_values), lambda pkt: pkt.req_type == 0x09), ]
def form_ipp_packet(self, op_type, version=1.0, **kwargs): """ Method to form ipp packets """ logger = get_logger("IPP Packet Forming") logger.info("Initiating IPP Packet Crafting") ver = str(version).split(".") ver = "".join(ver) ver = SignedShortField("Version", int(ver)) self.ipp_field.append(ver) data = "" operation_type = op_type if operation_type in self.ipp_operations.keys(): self.ipp_field.append( SignedShortField("Operation-ID", self.ipp_operations[operation_type])) self.ipp_field.append( SignedIntField("Request-ID", self.ipp_operations[operation_type])) else: logger.critical(f"Invalid operation tag : {operation_type}") print('Supported Operations') for op_rst in list(self.ipp_operations.keys()): print(f"* {op_rst}") sys.exit() delete_key = list() for delimiter_key, delimiter_value in kwargs.items(): if type(delimiter_value) != dict: data = delimiter_value delete_key.append(delimiter_key) if len(delete_key) > 0: for del_key in delete_key: del kwargs[del_key] for delimiter_key, delimiter_value in kwargs.items(): if type(delimiter_value) == dict: if delimiter_key in self.ipp_attr_group_tags.keys(): self.ipp_field.append( XByteField(delimiter_key, self.ipp_attr_group_tags[delimiter_key])) count = 0 for attr_key, attr_val in delimiter_value.items(): if attr_key in self.ipp_attrs.keys(): self.ipp_field.append( XByteField(f"key_{attr_key}_{count}", self.ipp_attrs[attr_key][1])) self.ipp_field.append( ShortField(f"Attribute_Name_Length_{count}", len(attr_key))) self.ipp_field.append( StrField( f"Attribute_Name_Value_{attr_key}_{count}", bytes(attr_key, encoding='utf8'))) self.ipp_field.append( ShortField(f"Attribute_Value_Length_{count}", len(attr_val))) self.ipp_field.append( StrField( f"Attribute_Value_Value_{attr_val}_{count}", bytes(attr_val, encoding='utf8'))) count += 1 else: logger.critical( f"Invalid Attribute tag : {attr_key}") sys.exit() else: logger.critical(f"Invalid Delimiter tag : {delimiter_key}") print("Supported Tags") for del_tag in list(self.ipp_attr_group_tags.keys()): print(f"* {del_tag}") sys.exit() else: logger.critical(f"Invalid tag : {delimiter_key}") sys.exit() self.ipp_field.append( XByteField("end-of-attributes-tag", self.ipp_attr_group_tags["end-of-attributes-tag"])) if data != "": self.ipp_field.append(StrField("Data", data)) logger.info("IPP Packet forming completed")