Encryption Algorithm of thunder P2P communication

Source: Internet
Author: User

Share the encryption algorithm of thunder P2P communication to help those who study the thunder P2P communication protocol :)
 
 
The algorithm details are not described in detail. The shared algorithm code is only available in python. the decrypted result is
 
The plaintext protocol is now available. The next step is to analyze the protocol. Sends a piece of protocol communication.
 
192.168.1.103 port 10047 ---> 111.195.202.215 port 10527
 
0000 32 00 00 00 05 10 00 00 30 30 32 32 46 42 38 2 ...... 0022FB8
 
0010 33 41 41 34 38 4e 51 51 00 00 3b b4 3AAA48NQQ ..;.
 
 
 
111.195.202.215 port 10527 ---> 192.168.1.103 port 10047
 
0000 32 00 00 00 06 00 00 00 00 3b b4 00 61 6a 00 2 .......... aj.
 
0010 02 25 e2 60 24 00 00 00 00 00 00 00 00. %. '$ ..........
 
 
 
192.168.1.103 port 10047 ---> 111.195.202.215 port 10527
 
0000 32 00 00 00 06 01 00 00 00 00 00 3b b4 61 57 e1 2.
 
0010 03 63 e1 7a 03 26 e2 60 24 00 00 05 00 00 00. c. z. &. '$ ......
 
 
 
111.195.202.215 port 10527 ---> 192.168.1.103 port 10047
 
0000 32 00 00 00 11 3b b4 00 00 61 6a 00 02 00 00 01 2 ...... aj .....
 
0010 00 26 e2 60 24 64 e1 7a 03 63 e1 7a 03 01 00 00. &. '$ d. z. c. z ....
 
0020 00 00 00 00 .....
 
The algorithm is as follows:
# Created by vessial
Def p2p_udp_encrypt (pkt ):
 
Header = random. randint (0, 0 xffff)
 
T = (header & 0x1fff) + 0x4000) <0x10
 
T + = random. randint (0, 0 xffff)
 
Body = struct. pack ('I', t)
 
Sec2 = random. randint (0, 0xff)
 
Body + = struct. pack ('B', sec2)
 
Length = (sec2 & 0x03) + 9
 
Pos = length
 
For I in range (length-5 ):
 
X = random. randint (0, 0xff)
 
Body + = struct. pack ('B', x)
 

 
L = pos * 7
 
T = struct. unpack ('B', body [pos-3]) [0]
 
T * = 0x0d
 
T & = 0xff
 
K = l ^ t
 
Header = body [: pos-2] + struct. pack ('B', k)
 
T = struct. unpack ('B', header [-1]) [0]
 
T * = 0x0d
 
T & = 0xff
 
K = (l + 7) ^ t
 
Header = header + struct. pack ('B', k)
 
Out =''
 
J = 0
 
T = array. array ('B', header)
 
Buf = array. array ('B', pkt)
 
Body_len = len (pkt)
 
For I in range (body_len ):
 
J + = 1
 
If j = pos:
 
J = 0
 
X = t [j] + 0x5b
 
X & = 0xff
 
X ^ = t [J-1]
 
T [J-1] = x
 
Buf [I] = (buf [I] + x) & 0xff
 

 
Out = header + buf. tostring ()
 
# Print "out buf len is % d" % len (out)
 
# Print hexdump (out)
 
# Print hexdump (p2p_udp_decrypt (out ))
 
Return out
 

 
Def p2p_udp_decrypt (pkt ):
 
If len (pkt) <= 8:
 
Return False
 
Header = struct. unpack ('<I', pkt [: 4]) [0]
 
Header> = 0x1d
 
If header> 3:
 
Return False
 
Elif header = 1:
Pass
 
Elif header = 2:
 
Byte5 = struct. unpack ('B', pkt [4]) [0]
 
Byte5 & = 0x80000003
 
Byte5 + = 9
 
If byte5> len (pkt ):
 
Return False
 
Pos = byte5
 
Head_check = array. array ('B', pkt [: pos])
 
T = struct. unpack ('B', pkt [pos-2]) [0]
 
Mid = pos * 7
 
P = 7 * pos + 7
 
T * = 0x0d
 
T & = 0xff
 
P ^ = t
 
S = struct. unpack ('B', pkt [pos-1]) [0]
 
If p! = S:
 
Return False
 

 
T = struct. unpack ('B', pkt [pos-3]) [0]
 
T * = 0x0d
 
T & = 0xff
 
T ^ = mid
 
If t! = Struct. unpack ('B', pkt [pos-2]) [0]:
 
Return False
 
J = 0
 
Body = array. array ('B', pkt [pos:])
 
Body_len = len (pkt)-pos
 
For I in range (body_len ):
 
J + = 1
 
If j = pos:
 
J = 0
 
X = head_check [j] + 0x5b
 
X & = 0xff
 
X ^ = head_check [J-1]
 
Head_check [J-1] = x
 
Body [I] = (body [I]-x) & 0xff
 

 
X = body. tostring ()
 
# Print hexdump (x)
 
Return x
 

 
Elif header = 3:
 
Pass
 
Return False

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.