class TDS_Prelogin_Request(Packet): name = "TDS Prelogin Request" tds_type = TDS_TYPES_PRE_LOGIN fields_desc = [ PacketField("VersionToken", TDS_Value(), TDS_Value), PacketField("EncryptionToken", TDS_Value(), TDS_Value), PacketField("InstanceToken", TDS_Value(), TDS_Value), PacketField("ThreadIDToken", TDS_Value(), TDS_Value), # Multiple Active Result Sets (MARS) has introduced in MSSQL Server 2005 # To determine the existence of MARS TokenType # 0x04 is MARSToken # 0xFF is Terminator XByteField("MARSTokenOrTerminator", 0), ConditionalField(ShortField("MARSOffset", 0), lambda x: x.MARSTokenOrTerminator == 0x04), ConditionalField(ShortField("MARSLen", 0), lambda x: x.MARSTokenOrTerminator == 0x04), ConditionalField(XByteField("Terminator", 0), lambda x: x.MARSTokenOrTerminator == 0x04), LEIntField("Version", 0), LEShortField("SubBuild", 0x0), ByteField("Encryption", 0), StrFixedLenField("InstanceOpt", b'', length_from=lambda x: x.InstanceToken.Len), LEIntField("ThreadID", 0), ConditionalField(ByteField("MARS", 0), lambda x: x.MARSTokenOrTerminator == 0x04), ]
class TDS_Prelogin_Response(Packet): name = "TDS Prelogin Response" tds_type = TDS_TYPES_TABULAR_RESULT fields_desc = [ PacketField("VersionToken", TDS_Value(), TDS_Value), PacketField("EncryptionToken", TDS_Value(), TDS_Value), PacketField("InstanceToken", TDS_Value(), TDS_Value), PacketField("ThreadIDToken", TDS_Value(), TDS_Value), PacketField("MARSToken", TDS_Value(), TDS_Value), XByteField("Terminator", 0xFF), # From the observation, the value for Version field # MS SQLServer 2005: 1996816393 # MS SQLServer 2000: 268566536 LEIntField("Version", 268566536), LEShortField("SubBuild", 0x0), # For Encryption field, value 0x02 mean ENCRPYT_NOT_SUP # value 0x02 is needed as we may skip the SSL authentication # support ByteField("Encryption", 0x02), ByteField("InstanceOpt", 0), #LEIntField("ThreadID",0), ByteField("MARS", 0), ]
class TDS_Token_DoneProc(Packet): name = "TDS Token DONEPROC" fields_desc = [ # ByteField("TokenType",0xfe), FlagsField("Status", 0, -16, TDS_Token_Status), LEShortField("CurCmd", 0xE0), LEIntField("DoneRowCount", 0), ]
class TDS_Token_Row(Packet): name = "TDS Token ROW" fields_desc = [ # ByteField("TokenType",0xd1), # the value obtained with MS SQLServer 2005 client and server LEShortField("Data", 0xFFFF), ]
class TDS_Token_ColMetaData(Packet): name = "TDS Token COLMETADATA" # tds_type = TDS_TYPES_TABULAR_RESULT fields_desc = [ # ByteField("TokenType",0x81), LEShortField("Count", 1), # SQL Server 2005 is LEIntField # SQL Server 2000 is LEShortField LEShortField("UserType", 0), FlagsField("Status", 0x1, -16, TDS_ColMetaData_Flags), # TypeInfo section # the value obtained with MS SQLServer 2005 client and server ByteField("Type", 0x38), # 0x38 = INT4TYPE ByteField("ColNameLength", 0), ]
class MySQL_Result_EOF(Packet): name = "MySQL Result EOF" fields_desc = [ ByteField("ResultMarker", 0xfe), LEShortField("WarningCount", 0), LEShortEnumField("ServerStatus", SERVER_STATUS_AUTOCOMMIT, MySQL_Server_Status), ]
class MySQL_Result_Field(Packet): name = "MySQL Result Field" fields_desc = [ LengthCodedBinaryField("Catalog", None), LengthCodedBinaryField("Database", None), LengthCodedBinaryField("Table", None), LengthCodedBinaryField("ORGTable", None), LengthCodedBinaryField("Name", None), LengthCodedBinaryField("ORGName", None), ByteField("Filler", 0xc), LEShortField("CharSet", 0), LEIntField("Length", 0), XByteEnumField("Type", 0, MySQL_Field_Types), FlagsField("Flags", 0, -16, MySQL_Field_Flags), ByteField("Decimals", 0), LEShortField("Filler2", 0), LengthCodedBinaryField("Default", None), ]
class MySQL_Result_Error(Packet): name = "MySQL Result Error" fields_desc = [ ByteField("ResultMarker", 0xff), LEShortField("Errno", 0), StrFixedLenField("SQLStateMarker", b'#', 1), StrFixedLenField("SQLState", b' ' * 5, 5), StrField("Message", b'') ]
class MySQL_Result_OK(Packet): name = "MySQL Result OK" fields_desc = [ ByteField("ResultMarker", 0x00), LengthCodedIntField("AffectedRows", 0), LengthCodedIntField("InsertID", 0), LEShortEnumField("ServerStatus", SERVER_STATUS_AUTOCOMMIT, MySQL_Server_Status), LEShortField("WarningCount", 0), StrField("Message", b'') ]
class TDS_Header(Packet): name = "TDS Header" fields_desc = [ XByteEnumField("Type", TDS_TYPES_PRE_LOGIN, TDS_HeaderTypes), ByteEnumField("Status", 0, TDS_Status), ShortField("Length", 0), LEShortField("SPID", 0), ByteField("PacketID", 0), ByteField("Window", 0), ConditionalField(PacketListField("Tokens", None, TDS_Token), lambda x: x.Type == TDS_TYPES_TABULAR_RESULT), ]
class TDS_Token_AllHeader(Packet): name = "TDS Token ALLHEADER" fields_desc = [ LEIntField("TotalLength", 0), LEIntField("HeaderLength", 0), # Two HeaderType # 1. Query Notification Header # 2. Transaction Descriptor Header, apply to [MSDN-MARS] LEShortField("HeaderType", 0), # Only support for Transaction Descriptor Header for the moment LELongField("TransactionDescription", 0), LEIntField("OutstandingRequestCount", 0), ]
class TDS_Token_EnvChange(Packet): name = "TDS Token ENVCHANGE" # tds_type = TDS_TYPES_TABULAR_RESULT fields_desc = [ # ByteField("TokenType",0xE3), LEShortField("Length", 27), #FIXME: make a dynamic count? ByteField("Type", 1), # 1 = Database FieldLenField("NewValueLen", 6, fmt='B', length_of="NewValue"), StrLenField("NewValue", "master".encode('utf16')[2:], length_from=lambda x: x.NewValueLen), FieldLenField("OldValueLen", 6, fmt='B', length_of="OldValue"), StrLenField("OldValue", "master".encode('utf16')[2:], length_from=lambda x: x.OldValueLen), ]
class TDS_Token_LoginACK(Packet): name = "TDS Token LOGINACK" # tds_type = TDS_TYPES_TABULAR_RESULT fields_desc = [ # ByteField("TokenType",0xad), LEShortField("Length", 54), #FIXME: make a dynamic count? ByteField("Interface", 1), #IntField("TDSVersion",0x730a0003), IntField("TDSVersion", 0x04020000), FieldLenField("ProgNameLen", 22, fmt='B', length_of="ProgName"), StrLenField("ProgName", "Microsoft SQL Server\0\0".encode('utf16')[2:], length_from=lambda x: x.ProgNameLen), ByteField("MajorVer", 9), ByteField("MinorVer", 0), ByteField("BuildNumHi", 5), ByteField("BuildNumLow", 119), ]
class TDS_Token_Info(Packet): name = "TDS Token INFO" fields_desc = [ # ByteField("TokenType",0xAB), LEShortField("Length", 118), #FIXME: make a dynamic count? LEIntField("Number", 5701), ByteField("State", 2), ByteField("Class", 1), FieldLenField("MessageTextLen", 37, fmt='<H', length_of="MessageText"), StrLenField( "MessageText", "Changed database context to 'master'.".encode('utf16')[2:], length_from=lambda x: x.MessageTextLen), FieldLenField("ServerNameLen", 15, fmt='B', length_of="ServerName"), StrLenField("ServerName", "HOMEUSER-3AF6FE".encode('utf16')[2:], length_from=lambda x: x.ServerNameLen), FieldLenField("ProcNameLen", 0, fmt='B', length_of="ProcName"), #StrLenField("ProName", "", length_from=lambda x:x.ProcName), #LEIntField("LineNumber",1), ]
class TDS_Login7_Request(Packet): name = "TDS Login7 Request" fields_desc = [ LEIntField("Length", 0), LEIntField("TDSVersion", 0), LEIntField("PacketSize", 0), LEIntField("ClientProgVer", 0), LEIntField("ClientPID", 0), LEIntField("PID", 0), FlagsField("OptionFlags1", 0, -8, TDS_OptionFlags1), FlagsField("OptionFlags2", 0, -8, TDS_OptionFlags2), FlagsField("TypesFlags", 0, -8, TDS_TypesFlags), FlagsField("OptionFlags3", 0, -8, TDS_OptionFlags3), LEIntField("ClientTimeZone", 0), # start of ClientLCID field LEShortField("LCID", 0x0), FlagsField("ColFlags", 0, -8, TDS_ColFlags), ByteField("Version", 0x0), # end of ClientLCID field # start of OffsetLength field LEShortField("ibHostName", 0), LEShortField("cchHostName", 0), LEShortField("ibUserName", 0), LEShortField("cchUserName", 0), LEShortField("ibPassword", 0), LEShortField("cchPassword", 0), LEShortField("ibAppName", 0), LEShortField("cchAppName", 0), LEShortField("ibServerName", 0), LEShortField("cchServerName", 0), LEShortField("ibUnused", 0), LEShortField("cbUnused", 0), LEShortField("ibCltIntName", 0), LEShortField("cchCltIntName", 0), LEShortField("ibLanguage", 0), LEShortField("cchLanguage", 0), LEShortField("ibDatabase", 0), LEShortField("cchDatabase", 0), StrFixedLenField("ClientID", "012345", 6), LEShortField("ibSSPI", 0), LEShortField("cbSSPI", 0), LEShortField("ibAtchDBFile", 0), LEShortField("cchAtchDBFile", 0), #LEShortField("ibChangePassword",0), # introduce in TDS 7.2 #LEShortField("ibChangePassword",0), # introduce in TDS 7.2 #LEIntField("cbSSPILong",0), # introduce in TDS 7.2 # end of OffsetLength field StrField("Payload", ""), ]