YY 2015 Reverse Analysis (1) Underlying Communication Mechanism

Foreword

Having previously studied the protocol of YY version 6.2, I recently revisited it and found that the current version, 8.3.0.0, has undergone significant changes. Key exchange no longer utilizes ZLIB compression, and all command words have been completely revised. However, the communication algorithm remains unchanged, utilizing RSA + RC4.

Underlying Communication Process

  1. YY’s packet structure consists of a 4-byte length field, a 4-byte command word, and the remaining data. This structure allows for packet segmentation based on the initial 4 bytes. However, other situations exist, such as nested packets. These occur when a command word packet contains one or more sub-command packets. These sub-command packets may be processed independently or require data from the parent packet.

  2. Initially, the client transmits UDP packets to several servers (four, in this case) to request IP addresses. The server then provides a list of servers and corresponding lists that support the received client version number.

1
2
3
4
5
6
7
61 00 00 00 1E 73 00 00 C8 00 FF FF FF FF FF FF   a....s..?.......
FF FF 03 01 00 00 00 00 00 00 20 00 35 34 64 37 ........ .54d7
63 62 39 31 35 38 31 38 32 30 39 38 65 38 36 32 cb9158182098e862
66 66 38 39 30 64 62 66 61 33 63 30 00 00 30 80 ff890dbfa3c0..0.
07 00 38 2E 33 2E 30 2E 30 02 00 79 79 00 00 00 ..8.3.0.0..yy...
00 00 00 00 00 00 00 04 08 00 00 00 00 00 00 00 ................
00†††††††††††††††††††††† .

One of these servers responds with 0x741E, providing the requested IP list. (Other servers may also respond, but the client ceases listening after receiving the first valid response). Note that the byte offset +4 within each packet represents the command word (this convention applies throughout the analysis), as exemplified by 0x731E in this instance.

  1. From the received IP list, the client randomly selects several servers (six in this example) and sends login requests. Five of these requests utilize UDP, while one uses TCP. The data payload of these packets is identical.
1
2
3
4
34 00 00 00 01 14 00 00 C8 00 00 00 00 00 30 80   4.......?.....0.
FF FF FF FF 08 00 62 75 67 73 74 65 73 74 00 00 ..bugstest..
04 08 00 00 01 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00†††††††††††††††††† ....
  1. The fastest-responding server replies with the 0x1501 command. The byte at offset +0C contains the feedback result. A value of 0xC8 indicates success, with the subsequent data containing the IP address and port of the designated login server. Other values, such as 97 01 00 00, signify an outdated client version requiring an upgrade.
1
2
3
4
5
6
54 00 00 00 01 15 00 00 C8 00 00 00 C8 00 00 00   T.......?...?...
02 00 00 00 70 75 DC EB DA 85 3B 14 00 00 03 00 ....pu????;.....
00 00 91 1F 39 04 51 00 6F B2 91 8A 4D E6 3B 14 ..? 9.Q.o???M?;.
00 00 03 00 00 00 94 1F 39 04 54 00 00 00 00 00 ......? 9.T.....
01 00 11 00 AB 5B 54 76 00 00 00 00 00 00 00 00 ....?[Tv........
F4 01 00 00†††††††††††††††††† ?...
  1. The actual login process commences at this point. The client randomly selects one server from the received login IP list and establishes a connection. Upon successful connection, the client initiates a key exchange by sending a packet to the server. The command word for this packet is 0x1104 or 0x3204, varying depending on the target server type, as multiple server types are involved in the login process, including verification, channel, and friend servers.
1
2
3
4
5
6
53 00 00 00 04 11 00 00 C8 00 40 00 E9 03 40 F2   S...  ..?@.?@?
4D ED C4 86 32 9B 25 F1 7A D8 94 70 D5 E2 20 6C M砟??駔財p这 l
F0 B7 AF FD 5A DD A4 A6 F3 CA F5 8C CE 7B 9B CB 鸱Z荬术屛{浰
2D AB 49 45 04 61 93 9C 4F 7D 40 DE E1 E4 8B 19 -獻E a摐O}@掎鋴
BC 89 C2 E0 76 29 58 2E 2F BB A6 51 01 00 03 00 級锣v)X./沪Q . .
00 00 00 ...

or

1
2
3
4
5
6
7
66 00 00 00 04 32 00 00 C8 00 40 00 E9 03 40 F2  f... 2..?@.?@?
4D ED C4 86 32 9B 25 F1 7A D8 94 70 D5 E2 20 6C M砟??駔財p这 l
F0 B7 AF FD 5A DD A4 A6 F3 CA F5 8C CE 7B 9B CB 鸱Z荬术屛{浰
2D AB 49 45 04 61 93 9C 4F 7D 40 DE E1 E4 8B 19 -獻E a摐O}@掎鋴
BC 89 C2 E0 76 29 58 2E 2F BB A6 51 01 00 03 13 級锣v)X./沪Q .
00 00 00 13 00 00 00 04 E8 0B 00 C8 00 00 00 05 ... ... ?.?..
00 6C 6F 67 69 6E .login

The byte at offset +4 represents the 0x40 byte, which corresponds to the client-generated public key, specifically the N component of the RSA key pair. The byte at offset +0x4E represents the E component of the RSA key pair. This packet serves to inform the server that the subsequently issued RC4 key is encrypted using this RSA public key.

  1. Upon receiving the client’s key, the server responds with either 0x3304 or 0x1504. Previously, the key within this packet was compressed using zlib; however, this compression has been removed, likely for server-side performance optimization.
1
2
3
4
5
50 00 00 00 04 15 00 00 C8 00 40 00 7B 89 12 1B  P.........@.{...
FE 8F AC 7A BF 02 D4 34 42 D9 52 29 21 EA 0D 13 ...z...4B.R)!...
27 EC C0 11 BB 59 A8 7F 9C 95 AE B7 9C 09 5A 3C '....Y........Z<
43 A1 55 8E DA A0 2D F6 CA E9 EB F4 DC D3 DC C5 C.U...-.........
64 8E 75 91 AE 32 A4 28 04 88 CA 79 00 00 00 00 d.u..2.(...y....

or

1
2
3
4
5
6
7
8
9
10
11
18 09 00 00 04 33 00 00  C8 00 40 00 22 79 01 D6 .....3....@."y..
58 E0 86 9C A2 57 37 21 89 4B BF 7F C2 F2 BE 64 X....W7!.K.....d
48 00 8B E6 14 82 C3 0E D0 FF 80 3C 2C 60 F2 DD H..........<,`..
7F BA A4 67 17 C1 DA CA F4 D6 C0 4E B2 EE A7 90 ...g.......N....
23 3E 46 1D D4 A4 B4 E5 91 14 FE F5 C8 08 00 00 #>F.............
C8 08 00 00 04 E9 0B 00 C8 00 00 00 BA 08 B6 08 ................
00 00 06 00 04 00 00 00 FF FF 00 00 17 27 54 08 .............'T.
00 00 78 DA 8D 57 4D 6C 1B C7 15 7E 43 AD 4D 49 ..x..WMl...~C.MI
D6 8F AD C6 86 64 BB 8E 9A BA 46 0E 75 10 5B 76 .....d....F.u.[v
E5 9C 32 4B 8A 22 F5 47 D2 22 25 45 69 22 7B 45 ..2K.".G."%Ei"{E
...omitted later

Notably, in addition to the key, the 0x3304 packet also delivers a bytecode module to the client, responsible for initializing the dynamic environment. Numerous subsequent packets follow this pattern, containing dynamic detection code issued by the server.

The 0x40 bytes starting at offset 0C within these two packets contain the RC4 key encrypted with the server’s RSA private key. After decryption, the resulting RC4 key is duplicated, with one copy designated for encryption and the other for decryption. This marks the completion of the YY key negotiation process. All subsequent data exchanged between the client and server will be encrypted using the established RC4 session key.

The algorithm implementations reside within exported functions of the dwUtility.dll library. The table below provides translations for several relevant functions:

Exported Function Name Function
DwUtility::dwBaseFunc::dwUtilityrgk Initialize RSA structure
DwUtility::dwBaseFunc::dwUtilityrpd RSA decryption algorithm
DwUtility::dwBaseFunc::dwUtilitybb Convert large numbers to binary
DwUtility::dwBaseFunc::dwUtilityrsk Initialize RC4 structure
DwUtility::dwBaseFunc::dwUtilityr RC4 encryption\decryption algorithm

These represent a few key algorithms within the dwUtility.dll library, which contains numerous other basic functions available for further exploration.

Analyzing the communication flow solely with a debugger like OllyDbg (OD) proves challenging due to the mixture of encrypted and unencrypted data, coupled with the multitude of connected sockets. To facilitate analysis, a custom tool was developed to display both the raw and decrypted packet data, differentiating packets based on their associated socket.

Picture lost

End

YY employs a parallel login approach, simultaneously sending requests to multiple (N) servers and utilizing the fastest response. This strategy places demanding performance requirements on the login server cluster, as each server must be equipped to handle a potentially large volume of requests. The key establishment process highlights YY’s emphasis on load balancing and efficient resource utilization.

This concludes the present analysis of YY’s underlying communication mechanism. A future analysis will delve into the specific content and structure of YY login packets.

For inquiries or feedback, please contact bughoho[at]gmail.com.