usr bin env python -coding utf8- username password hostport login icq

 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
#! /usr/bin/env python
#-*-coding:utf8-*-
username = ''
password = ''
hostport = ('login.icq.com', 5238)
import struct, socket
class Icq():
def __init__(self, uin, password, hostport):
self.uin = uin
self.password = self.encryptPassword(password)
self.hostport = hostport
self.seq = 0
def run(self):
self.login()
def login(self):
self.sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
self.sock.connect(self.hostport)
loginstring = '\x00\x00\x00\x01'
loginstring += self.tlv(1, self.uin)
loginstring += self.tlv(2, self.password)
loginstring += self.tlv(3, 'testclent')
loginstring += self.tlv(16, '\x01\x0a')
loginstring += self.tlv(17, '\x00\x00')
loginstring += self.tlv(18, '\x00\x01')
loginstring += self.tlv(19, "\000\001")
loginstring += self.tlv(0x1a, "\x0eK")
loginstring += self.tlv(0x14, "\x00\x00\x00U")
loginstring += self.tlv(0x0f, "en")
loginstring += self.tlv(0x0e, "us")
self.sendFlap(1, loginstring)
self.read()
d = self.read()
self.sock.close()
resp = self.detlv(d)
host, port = resp[5].split(':')
hostport = (host, int(port))
cookie = resp[6]
self.sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
self.sock.connect(hostport)
loginstring = '\x00\x00\x00\x01'
loginstring += self.tlv(6, resp[6])
self.sock.send(loginstring)
print self.read()
def read(self):
head = self.sock.recv(6)
pid, ch, seq, length = struct.unpack('!bbhh', head)
data = self.sock.recv(length)
return data
def tlv(self, typ, val):
return struct.pack("!HH", typ, len(val)) + val
def detlv(self, data,count=None):
header="!HH"
dict={}
while data and len(dict) != count:
head = struct.unpack(header,data[:4])
dict[head[0]]=data[4:4+head[1]]
data=data[4+head[1]:]
if not count:
return dict
return dict,data
def sendFlap(self,channel, data):
header="!cBHH"
self.seq=(self.seq + 1) % 0xFFFF
head=struct.pack(header,'*', channel, self.seq, len(data))
self.sock.send(head + str(data))
def encryptPassword(self, password): return (lambda key, bytes: ''.join([chr(bytes[i] ^ key[i % len(key)]) for i in range(len(bytes))]))([0xf3, 0x26, 0x81, 0xc4, 0x39, 0x86, 0xdb, 0x92, 0x71, 0xa3, 0xb9, 0xe6, 0x53, 0x7a, 0x95, 0x7c], map(ord, password))
def main():
icq = Icq(username, password, hostport)
icq.run()
if __name__=='__main__':
main()
exit()