0

MT4客户端225通讯协议分析。

通过对send下断,找到第一个发送的数据包,即登录内容,通过调用栈往上找到关键的函数调用,登录函数接收以下4个参数 
(1) 用户ID(int) (2) 密码(pchar) (3) 0 (4) 0 
相关代码如下

_text:00434AD0                 sub     esp, 0A8h
_text:00434AD6                 push    ebx
_text:00434AD7                 push    ebp
_text:00434AD8                 push    esi
_text:00434AD9                 mov     esi, ecx
_text:00434ADB                 push    edi
_text:00434ADC                 xor     ebx, ebx
_text:00434ADE                 mov     ecx, 6
_text:00434AE3                 xor     eax, eax
_text:00434AE5                 lea     edi, [esp+0B8h+var_A7] ; 指向Buf的第二字节
_text:00434AE9                 mov     [esp+0B8h+buf], bl ; Buf的第一字节赋0
_text:00434AED                 rep stosd
_text:00434AEF                 mov     ebp, [esp+0B8h+arg_4] ; 参数密码
_text:00434AF6                 stosw
_text:00434AF8                 cmp     ebp, ebx
_text:00434AFA                 stosb
_text:00434AFB                 jz      loc_0_434CFA    ; 密码为空则退出
_text:00434B01                 cmp     dword ptr [esp+0B8h+ArgList], 1 ; 用户ID为1则退出
                    (1是MT4的默认管理员, 不能用于客户端登录)
_text:00434B09                 jl      loc_0_434CFA
_text:00434B0F                 mov     edi, ebp        ; 计算密码的长度存于ECX
_text:00434B11                 or      ecx, 0FFFFFFFFh
_text:00434B14                 xor     eax, eax
_text:00434B16                 repne scasb
_text:00434B18                 not     ecx
_text:00434B1A                 dec     ecx
_text:00434B1B                 cmp     ecx, 1          ; 密码最小长度1
_text:00434B1E                 jb      loc_0_434CFA
_text:00434B24                 cmp     dword ptr [esi+4], 0FFFFFFFFh
_text:00434B28                 jnz     short loc_0_434B3C ; ECX=271BBDC 一个空的Buffer
_text:00434B2A                 pop     edi
_text:00434B2B                 pop     esi
_text:00434B2C                 pop     ebp
_text:00434B2D                 mov     eax, 6
_text:00434B32                 pop     ebx
_text:00434B33                 add     esp, 0A8h
_text:00434B39                 retn    10h
_text:00434B3C ; ---------------------------------------------------------------------------
_text:00434B3C
_text:00434B3C loc_0_434B3C:                           ; CODE XREF: UserLogin+58j
_text:00434B3C                 lea     ecx, [esp+0B8h+var_6C] ; ECX=271BBDC 一个空的Buffer
_text:00434B40                 call    sub_0_433A10    ; SetMagicBufferTo ECX
_text:00434B45                 mov     edi, ebp        ; EDI = PSW
_text:00434B47                 or      ecx, 0FFFFFFFFh ; EXC = LEN(PSW)
_text:00434B4A                 xor     eax, eax
_text:00434B4C                 repne scasb
_text:00434B4E                 not     ecx
_text:00434B50                 dec     ecx
_text:00434B51                 push    ecx
_text:00434B52                 push    ebp
_text:00434B53                 lea     ecx, [esp+0C0h+var_6C]
_text:00434B57                 call    sub_0_433A40    ; FormatPswToECX
_text:00434B5C                 lea     ecx, [esp+0B8h+var_6C] ; 指向271BBDC
_text:00434B60                 call    sub_0_433B20    ; MD5
_text:00434B65                 lea     edi, [esi+18Ch] ; 120D6E0
_text:00434B6B                 lea     ecx, [esp+0B8h+var_6C] ; MD5(PSW)271BBDC
_text:00434B6F                 push    edi
_text:00434B70                 call    sub_0_433BA0    ; COPY到120D6E0
_text:00434B75                 mov     eax, edi        ; COPY 到 271BBBC
_text:00434B77                 mov     ecx, [eax]
_text:00434B79                 mov     [esp+0B8h+var_8C], ecx
_text:00434B7D                 mov     edx, [eax+4]
_text:00434B80                 mov     [esp+0B8h+var_88], edx
_text:00434B84                 mov     ecx, [eax+8]
_text:00434B87                 mov     [esp+0B8h+var_84], ecx
_text:00434B8B                 mov     edx, [eax+0Ch]
_text:00434B8E                 xor     eax, eax
_text:00434B90                 mov     [esp+0B8h+var_80], edx
_text:00434B94
_text:00434B94 loc_0_434B94:                           ; CODE XREF: UserLogin+DCj
_text:00434B94                 mov     dl, [edi+eax]   ; 对MD5进行变换, 结果(暂且称为EnMD5)存在271BBBC
_text:00434B97                 mov     cl, byte ptr [esp+eax+0B8h+var_8C]
_text:00434B9B                 add     dl, bl
_text:00434B9D                 xor     dl, cl
_text:00434B9F                 movsx   ebp, cl
_text:00434BA2                 mov     byte ptr [esp+eax+0B8h+var_8C], dl
_text:00434BA6                 inc     eax
_text:00434BA7                 cmp     eax, 10h
_text:00434BAA                 mov     ebx, ebp
_text:00434BAC                 jl      short loc_0_434B94 ; 对MD5进行变换, 结果(暂且称为EnMD5)存在271BBBC
_text:00434BAE                 mov     edi, [esp+0B8h+arg_8]
_text:00434BB5                 mov     eax, edi
_text:00434BB7                 dec     eax
_text:00434BB8                 neg     eax
_text:00434BBA                 sbb     al, al
_text:00434BBC                 xor     ebx, ebx
_text:00434BBE                 and     al, 0F5h
_text:00434BC0                 push    ebx             ; Time
_text:00434BC1                 add     al, 0Bh
_text:00434BC3                 mov     [esp+0BCh+buf], al
_text:00434BC7                 call    ds:time         ; 用时间取一个随机数
_text:00434BCD                 mov     ecx, [esp+0BCh+var_8C]
_text:00434BD1                 mov     edx, [esp+0BCh+var_88]
_text:00434BD5                 mov     ebp, dword ptr [esp+0BCh+ArgList] ; Login
_text:00434BDC                 add     esp, 4
_text:00434BDF                 cmp     edi, 2
_text:00434BE2                 mov     [esp+0B8h+var_A5], ecx ; EnMD5(0)
_text:00434BE6                 mov     ecx, [esp+0B8h+var_80]
_text:00434BEA                 mov     [esp+0B8h+var_A1], edx ; EnMD5(1)
_text:00434BEE                 setz    dl
_text:00434BF1                 mov     [esp+0B8h+var_A7], al ; 随机数存到Buf的01字节
_text:00434BF5                 mov     eax, [esp+0B8h+var_84]
_text:00434BF9                 mov     [esp+0B8h+var_99], ecx ; MD5(3)
_text:00434BFD                 mov     [esp+0B8h+var_8D], dl
_text:00434C01                 mov     edx, 1Bh        ; Buf的长度-1
_text:00434C06                 lea     ecx, [esp+0B8h+var_A7]
_text:00434C0A                 mov     [esp+0B8h+var_A6], bl
_text:00434C0E                 mov     [esp+0B8h+var_95], ebp ; Login
_text:00434C12                 mov     [esp+0B8h+var_9D], eax ; MD5(2)
_text:00434C16                 mov     [esp+0B8h+var_91], 190h ; Ver
_text:00434C1D                 mov     [esp+0B8h+var_8F], 0E1h ; Build
_text:00434C24                 call    sub_0_433990    ; 转换Buf
_text:00434C29                 lea     eax, [esp+0B8h+buf]
_text:00434C2D                 push    1Ch             ; len
_text:00434C2F                 push    eax             ; buf
_text:00434C30                 mov     ecx, esi
_text:00434C32                 call    sub_0_50AD60
_text:00434C37                 cmp     eax, 1
_text:00434C3A                 jz      short loc_0_434C55 ; 发送成功, ECX=120D51C
_text:00434C3C                 mov     ecx, esi
_text:00434C3E                 call    sub_0_508240
_text:00434C43                 pop     edi
_text:00434C44                 pop     esi
_text:00434C45                 pop     ebp
_text:00434C46                 mov     eax, 2
_text:00434C4B                 pop     ebx
_text:00434C4C                 add     esp, 0A8h
_text:00434C52                 retn    10h
_text:00434C55 ; ---------------------------------------------------------------------------
_text:00434C55
_text:00434C55 loc_0_434C55:                           ; CODE XREF: UserLogin+16Aj
_text:00434C55                 mov     ecx, esi        ; 发送成功, ECX=120D51C
_text:00434C57                 mov     [esi+1BCh], ebp
_text:00434C5D                 call    sub_0_50B710    ; 从Socket读1字节
_text:00434C62                 mov     edi, eax
_text:00434C64                 cmp     edi, ebx        ; 返回值=0,则登录成功
_text:00434C66                 jz      short loc_0_434C88 ; ECX<-271BBBC, EnMD5
_text:00434C68                 cmp     edi, 0Ah
_text:00434C6B                 jz      short loc_0_434C79
_text:00434C6D                 cmp     edi, 0Bh
_text:00434C70                 jz      short loc_0_434C79
_text:00434C72                 mov     ecx, esi
_text:00434C74                 call    sub_0_508240
_text:00434C79
_text:00434C79 loc_0_434C79:                           ; CODE XREF: UserLogin+19Bj
_text:00434C79                                         ; UserLogin+1A0j
_text:00434C79                 mov     eax, edi
_text:00434C7B                 pop     edi
_text:00434C7C                 pop     esi
_text:00434C7D                 pop     ebp
_text:00434C7E                 pop     ebx
_text:00434C7F                 add     esp, 0A8h
_text:00434C85                 retn    10h
_text:00434C88 ; ---------------------------------------------------------------------------
_text:00434C88
_text:00434C88 loc_0_434C88:                           ; CODE XREF: UserLogin+196j
_text:00434C88                 lea     ecx, [esp+0B8h+var_8C] ; ECX<-271BBBC, EnMD5
_text:00434C8C                 push    1               ; len
_text:00434C8E                 push    ecx             ; buf
_text:00434C8F                 mov     ecx, esi
_text:00434C91                 mov     [esi+1ACh], ebx ; 清空Buf
_text:00434C97                 mov     [esi+1B0h], ebx
_text:00434C9D                 mov     [esi+1B4h], ebx
_text:00434CA3                 mov     [esi+1B8h], ebx
_text:00434CA9                 call    sub_0_50AE20    ; 接收数据并解密
_text:00434CAE                 lea     edx, [esi+1C0h]
_text:00434CB4                 push    2               ; len
_text:00434CB6                 push    edx             ; buf
_text:00434CB7                 mov     ecx, esi
_text:00434CB9                 call    sub_0_50AE20    ; 接收数据并解密
_text:00434CBE                 lea     eax, [esi+1C4h]
_text:00434CC4                 push    4               ; len
_text:00434CC6                 push    eax             ; buf
_text:00434CC7                 mov     ecx, esi
_text:00434CC9                 call    sub_0_50AE20    ; 接收数据并解密
_text:00434CCE                 cmp     [esp+0B8h+arg_C], ebx
_text:00434CD5                 jnz     short loc_0_434CEB
_text:00434CD7                 push    ebp             ; ArgList
_text:00434CD8                 push    offset aDLogin  ; "'%d': login"
_text:00434CDD                 push    ebx             ; __int16
_text:00434CDE                 push    offset stru_0_596558 ; lpCriticalSection
_text:00434CE3                 call    sub_0_4AA400
_text:00434CE8                 add     esp, 10h
_text:00434CEB
_text:00434CEB loc_0_434CEB:                           ; CODE XREF: UserLogin+205j
_text:00434CEB                 pop     edi
_text:00434CEC                 pop     esi
_text:00434CED                 pop     ebp
_text:00434CEE                 xor     eax, eax
_text:00434CF0                 pop     ebx
_text:00434CF1                 add     esp, 0A8h
_text:00434CF7                 retn    10h
_text:00434CFA ; ---------------------------------------------------------------------------
_text:00434CFA
_text:00434CFA loc_0_434CFA:                           ; CODE XREF: UserLogin+2Bj
_text:00434CFA                                         ; UserLogin+39j ...
_text:00434CFA                 pop     edi
_text:00434CFB                 pop     esi
_text:00434CFC                 pop     ebp
_text:00434CFD                 mov     eax, 3
_text:00434D02                 pop     ebx
_text:00434D03                 add     esp, 0A8h
_text:00434D09                 retn    10h
_text:00434D09 UserLogin       endp
_text:00434D09
_text:00434D09 ; ---------------------------------------------------------------------------
_text:00434D0C                 align 10h
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207

根据分析整理出登录数据包的结构如下

#pragma pack(push,1)
struct MT4_LOGIN_tag
{
    char  First;         //调试时此值一直为0
    char  Random;        //通过机器时间取的一个随机数 
    char  UnKnow;        //0
    char  MD5Codes[16];     //密码MD5运算后再变换一次的结果
    int   Login;            //用户ID
    short  Version;         //客户端版本
    short  Build;        //客户端版本
    char   ClientType;      //客户端类型
}
#pragma pack(pop)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

对于要发送的数据包, 整个数据包从第2字节开始进行了一次变换, 在00434C24处调用子函数sub_0_433990进行处理, 相关分析如下

_text:00433990                 push    esi
_text:00433991                 mov     esi, ecx        ; Buf指针
_text:00433993                 xor     ecx, ecx
_text:00433995                 push    edi
_text:00433996                 test    esi, esi
_text:00433998                 mov     edi, edx        ; Buf的长度
_text:0043399A                 jz      short loc_0_4339C0
_text:0043399C                 xor     eax, eax
_text:0043399E                 test    edi, edi
_text:004339A0                 jle     short loc_0_4339C0
_text:004339A2
_text:004339A2 loc_0_4339A2:                           ; CODE XREF: sub_0_433990+2Ej
_text:004339A2                 mov     edx, eax
_text:004339A4                 and     edx, 0Fh
_text:004339A7                 mov     dl, ds:byte_0_56B734[edx*4] ; 一个常量MD5数据
_text:004339AE                 add     dl, cl          ; 加上前一字节变换后的值
_text:004339B0                 mov     cl, [eax+esi]   ; 取当前字节
_text:004339B3                 xor     cl, dl          ; 异或的记过即为变换的结果
_text:004339B5                 mov     [eax+esi], cl
_text:004339B8                 inc     eax
_text:004339B9                 cmp     eax, edi
_text:004339BB                 movsx   ecx, cl
_text:004339BE                 jl      short loc_0_4339A2
_text:004339C0
_text:004339C0 loc_0_4339C0:                           ; CODE XREF: sub_0_433990+Aj
_text:004339C0                                         ; sub_0_433990+10j
_text:004339C0                 pop     edi
_text:004339C1                 pop     esi
_text:004339C2                 retn
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

根据以上信息既可以模拟程序去发送登录数据包。

转自:https://blog.csdn.net/mt4develop/article/details/51250318

关闭 返回顶部
联系我们
Copyright © 2011. 聚财吧. All rights reserved.