├── LICENSE ├── README.md ├── qq.py └── tea.py /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 手机号查扣扣号(Python3版) 2 | 3 | 通过手机号获取QQ号(需开启手机号登录),代码有点乱,凑合看吧! 4 | 5 | ## 使用 6 | 7 | 请自行修改相应代码 8 | 9 | ``` 10 | python3 qq.py 11 | ``` 12 | 13 | 参考: 14 | 15 | - [【手机号2QQ号】](http://www.52pojie.cn/thread-385527-1-1.html) C#版 16 | - [【QQLib for Python】](https://github.com/JetLua/qqlib) TEA算法(解密函数有小改动) 17 | 18 | 19 | > 注:该方法可能已经失效,2016.04.14 -------------------------------------------------------------------------------- /qq.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | ''' https://github.com/zrools/phone2qq ''' 5 | 6 | import tea 7 | import socket 8 | import hashlib 9 | from random import randint 10 | from binascii import a2b_hex, b2a_hex 11 | 12 | def md5(cstr): 13 | m = hashlib.md5() 14 | m.update(cstr.encode()) 15 | return m.hexdigest().lower() 16 | 17 | class QQLogin(): 18 | 19 | def __init__(self): 20 | self.num = '10000000000' # 手机号 21 | self.address = ('183.60.56.100', 8000) # 企鹅服务器 22 | self.fixedData = '0000044b0000000100001509' # 填充数据 23 | self.hdKey = '0251ca4aab66e80ae4d279921ace3c3dfee23788151f45368d' 24 | self.serverIP = '' 25 | self.serverTime = '' 26 | self.token0825 = '' 27 | 28 | def str2hex(self, mStr): 29 | text = '' 30 | for x in mStr: 31 | text += '3%s' % x 32 | return text 33 | 34 | def getSequence(self, length): 35 | text = '' 36 | for l in range(length): 37 | text += '%02x' % randint(0,0xff) 38 | return text 39 | 40 | def login0825(self): 41 | key0825 = '7792394f1afd3bbfa9006bc807bcf23b' 42 | 43 | data = '0235550825' # head 44 | data += self.getSequence(2) 45 | data += '00000000' # QQ Hex 46 | data += '030000000101010000674200000000' 47 | data += key0825 48 | 49 | txt = '001800160001' 50 | txt += self.fixedData 51 | txt += '0000000000000000' 52 | txt += '0004000f0000000b' 53 | txt += self.str2hex(self.num) 54 | txt += '0309' 55 | txt += '0008' 56 | txt += '0001000000000004' 57 | txt += '00360012' 58 | txt += '000200010000000000000000000000000000' 59 | txt += '0114001d01020019' 60 | txt += self.hdKey 61 | 62 | data += b2a_hex(tea.encrypt(bytes.fromhex(txt), bytes.fromhex(key0825))).decode() 63 | data += '03' 64 | data = a2b_hex(data) 65 | 66 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 67 | sock.sendto(data, self.address) 68 | recvPack = sock.recv(1024) 69 | sock.close() 70 | 71 | recvData = b2a_hex(tea.decrypt(recvPack[14:-1], bytes.fromhex(key0825))).decode() 72 | 73 | if(recvData[:2]!='00'): 74 | recvData = recvData[16:] 75 | 76 | if(recvData[:2]=='00'): 77 | self.token0825 = recvData[10:122] 78 | self.serverTime = recvData[134:142] 79 | self.serverIP = recvData[166:174] 80 | return self.login0826() 81 | else: 82 | print('0825 error!') 83 | return False 84 | 85 | def login0826(self): 86 | key0826 = '6d47535a5a573d4872772c2d36717a76' 87 | keyCode = '13d924ca5e0469d284effea87a5a5f1c' 88 | 89 | data = '02355508366848' # head 90 | data += '00000000' 91 | data += '0300000001010100006742' 92 | data += '00000000' 93 | data += '000101020019' 94 | data += self.hdKey 95 | data += '00000010' 96 | data += self.getSequence(16) 97 | 98 | txt = '01120038' 99 | txt += self.token0825 100 | txt += '030f0008000657494e444f57' # WINDOWS 101 | txt += '0004000f0000000b' 102 | txt += self.str2hex(self.num) 103 | txt += '00060078' 104 | 105 | md5p = md5('123456') 106 | # 密码加密 107 | pwd = md5p 108 | pwd += '00000000' 109 | pwd += '00000000' # QQ Hex 110 | 111 | # 密匙加密 112 | key = 'F36251810002' 113 | key += '00000000' # QQ Hex 114 | key += self.fixedData 115 | key += '000001' 116 | key += md5p 117 | key += self.serverTime 118 | key += '00000000000000000000000000' 119 | key += self.serverIP 120 | key += '000000000000000600101ba49e165fe954251eb9619f7b1bdf31' 121 | key += key0826 122 | 123 | txt += b2a_hex(tea.encrypt(bytes.fromhex(key), bytes.fromhex(pwd))).decode() 124 | 125 | # region CRC 126 | txt += '001500300000' 127 | txt += '01' 128 | txt += '1c26e960' 129 | txt += '0010' 130 | txt += '028d5f75cbcf4c898ca43a3410b85788' 131 | txt += '02' 132 | txt += 'b3e8163c' 133 | txt += '0010' 134 | txt += '1ba49e165fe954251eb9619f7b1bdf31' 135 | txt += '001a' 136 | txt += '0040' 137 | 138 | mcrc = '001500300000' 139 | mcrc += '01' 140 | mcrc += '1c26e960' 141 | mcrc += '0010' 142 | mcrc += '028d5f75cbcf4c898ca43a3410b85788' 143 | mcrc += '02' 144 | mcrc += 'b3e8163c' 145 | mcrc += '0010' 146 | mcrc += '1ba49e165fe954251eb9619f7b1bdf31' 147 | 148 | txt += b2a_hex(tea.encrypt(bytes.fromhex(mcrc), bytes.fromhex(key0826))).decode() 149 | 150 | txt += '001800160001' 151 | txt += self.fixedData 152 | txt += '00000000' # QQ Hex 153 | txt += '00010000010300140001' 154 | txt += '0010' 155 | txt += 'bd41fd502a59f4863ccde044bb41f728' 156 | txt += '0312000501000000' 157 | txt += '00' # 是否记住密码 158 | txt += '010200620001' 159 | txt += '1169a81f699f52de71ef65e9b42d2d8a' 160 | txt += '0038' 161 | txt += '78b94e76767efdab4dd3b2b0144063f48b57ee27aef152a28aba1f03' 162 | txt += '50f02b17a86787fe47d1b189c43c0be7a7dc8c81c40bb622c78ec85b' 163 | txt += '0014' 164 | txt += '62e172e61421fe8c850c62891efcf7f93a19b892' 165 | 166 | data += b2a_hex(tea.encrypt(bytes.fromhex(txt), bytes.fromhex(keyCode))).decode() 167 | data += '03' 168 | data = a2b_hex(data) 169 | 170 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 171 | sock.sendto(data, self.address) 172 | recvPack = sock.recv(1024) 173 | sock.close() 174 | 175 | recvData = b2a_hex(tea.decrypt(recvPack[14:-1],bytes.fromhex(keyCode))).decode() 176 | 177 | if recvData[:2]=='06': 178 | qq = str(int(recvData[6:14], 16)) 179 | else: 180 | recvData = recvData[8:] 181 | if recvData[:2].lower()=='fc': 182 | qq = str(int(recvData[14:22], 16)) 183 | else: 184 | qq = False 185 | 186 | return qq 187 | 188 | def getQQ(self, phone): 189 | self.num = phone 190 | return self.login0825() 191 | 192 | 193 | if __name__=='__main__': 194 | login = QQLogin() 195 | 196 | print(login.getQQ('10000000000')) # 单个手机号码测试 197 | 198 | ''' 199 | # 小许批量测试,号段随便找的 200 | for i in range(10000): 201 | num = '1360106%04d' % i 202 | qq = login.getQQ(num) 203 | if qq: print('%s >> %s'% (num, qq)) 204 | ''' -------------------------------------------------------------------------------- /tea.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import struct, ctypes 4 | from random import randint 5 | 6 | __all__ = ['encrypt', 'decrypt'] 7 | 8 | def xor(a, b): 9 | a1,a2 = struct.unpack('!LL', a[0:8]) 10 | b1,b2 = struct.unpack('!LL', b[0:8]) 11 | r = struct.pack('!LL', a1 ^ b1, a2 ^ b2) 12 | return r 13 | 14 | def encipher(v, k): 15 | n=16 16 | delta = 0x9e3779b9 17 | k = struct.unpack('!LLLL', k[0:16]) 18 | y, z = map(ctypes.c_uint32, struct.unpack('!LL', v[0:8])) 19 | s = ctypes.c_uint32(0) 20 | for i in range(n): 21 | s.value += delta 22 | y.value += (z.value << 4) + k[0] ^ z.value+ s.value ^ (z.value >> 5) + k[1] 23 | z.value += (y.value << 4) + k[2] ^ y.value+ s.value ^ (y.value >> 5) + k[3] 24 | r = struct.pack('!LL', y.value, z.value) 25 | return r 26 | 27 | def encrypt(v, k): 28 | vl = len(v) 29 | filln = (6 - vl) % 8 30 | v_arr = [ 31 | bytes(bytearray([filln | 0xf8])), 32 | b'\xad' * (filln + 2), 33 | v, 34 | b'\0' * 7, 35 | ] 36 | v = b''.join(v_arr) 37 | tr = b'\0'*8 38 | to = b'\0'*8 39 | r = [] 40 | o = b'\0' * 8 41 | for i in range(0, len(v), 8): 42 | o = xor(v[i:i+8], tr) 43 | tr = xor(encipher(o, k), to) 44 | to = o 45 | r.append(tr) 46 | r = b''.join(r) 47 | return r 48 | 49 | def decrypt(v, k): 50 | l = len(v) 51 | prePlain = decipher(v, k) 52 | pos = ord(prePlain[0].to_bytes(1, 'big')) & 0x07 + 2 53 | r = prePlain 54 | preCrypt = v[0:8] 55 | for i in range(8, l, 8): 56 | x = xor(decipher(xor(v[i:i+8], prePlain), k), preCrypt) 57 | prePlain = xor(x, preCrypt) 58 | preCrypt = v[i:i+8] 59 | r += x 60 | if r[-7:] == b'\0'*7: 61 | return r[pos+1:-7] 62 | 63 | 64 | def decipher(v, k): 65 | n = 16 66 | y, z = map(ctypes.c_uint32, struct.unpack('!LL', v[0:8])) 67 | a, b, c, d = map(ctypes.c_uint32, struct.unpack('!LLLL', k[0:16])) 68 | delta = 0x9E3779B9 69 | s = ctypes.c_uint32(delta << 4) 70 | for i in range(n): 71 | z.value -= ((y.value << 4) + c.value) ^ (y.value + s.value) ^ ((y.value >> 5) + d.value) 72 | y.value -= ((z.value << 4) + a.value) ^ (z.value + s.value) ^ ((z.value >> 5) + b.value) 73 | s.value -= delta 74 | return struct.pack('!LL', y.value, z.value) --------------------------------------------------------------------------------