usr bin python coding utf-8 from sys import exit import pycurl threadi

  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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
#!/usr/bin/python
# -*- coding: utf-8 -*-
from sys import exit
import pycurl, threading, config
from cStringIO import StringIO
from random import choice, randint
from time import sleep
from urllib import urlencode
import re, Acaptcha
def load_emails():
global emails
try:
file = open(config.emails, 'r')
except IOError, err:
exit(err)
else:
emails = map(str.rstrip, file.xreadlines())
file.close()
proxy = []
def load_proxy():
global proxy
print 'LOAD PROXY'
try:
file = open(config.proxy, 'r')
except IOError, err:
exit(err)
else:
proxy = map(str.rstrip, file.xreadlines())
file.close()
def get_proxy():
lock.acquire()
try:
pp = proxy.pop(0)
except IndexError:
load_proxy()
pp = proxy.pop(0)
lock.release()
return pp.split(':')
def load_base():
global base
try:
file = open(config.base, 'r')
except IOError, err:
exit(err)
else:
base = map(str.rstrip, file.xreadlines())
file.close()
for x in xrange(0, len(base), 100):
base.insert(x, config.test_mail)
def load_subj():
global subject
try:
subject = open(config.subj, 'r').read()
except IOError, err:
exit(err)
def load_mess():
global message
try:
message = open(config.message, 'r').read()
except IOError, err:
exit(err)
def load_links():
global links
try:
file = open(config.links, 'r')
except IOError, err:
exit(err)
else:
links = map(str.rstrip, file.xreadlines())
file.close()
def log(str):
lock.acquire()
print str
flog.write(str + '\n')
flog.flush()
lock.release()
def append_emails(scalar):
lock.acquire()
emails.append(scalar)
lock.release()
def append_base(scalar):
lock.acquire()
base.append(scalar)
lock.release()
def rand_gen(range):
alf = (['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q',
'r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8',
'9','0'])
word = ''
for x in xrange(range):
word += choice(alf)
return word
def get_adressat(to_num, cc_num, bcc_num):
dump = []
lock.acquire()
to = ''
for x in xrange(to_num):
try:
mail = base.pop(0)
to += mail + ', '
dump.append(mail)
except IndexError:
pass
cc = ''
for x in xrange(cc_num):
try:
mail = base.pop(0)
cc += mail + ', '
dump.append(mail)
except IndexError:
pass
bcc = ''
for x in xrange(bcc_num):
try:
mail = base.pop(0)
bcc += mail + ', '
dump.append(mail)
except IndexError:
pass
lock.release()
return to, cc, bcc, dump
class Send:
def __init__(self, login, passwd, proxy_host, proxy_port, acap):
self.proxy_host = proxy_host
self.proxy_port = proxy_port
self.login = login
self.passwd = passwd
self.acap = acap
self.cookies = ''
self.ua = choice([
'Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.18)',
'Mozilla/2.0 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.19)',
'Mozilla/3.0 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.11)',
'Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.12)',
'Mozilla/4.7 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.13)',
'Opera/9.15 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.11)',
'Opera/9.20 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.19)',
'Opera/9.40 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.18)',
'Opera/8.2beta (Windows; U; Windows NT 5.1; ru; rv:1.8.2.44)',
'Opera/9.16 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.10)',
'Opera/7.15 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.28)',
'Opera/8.92 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.38)',
'Opera/8.95 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.48)',
'Opera/9.33 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.58)',
'Opera/9.45 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.68)',
'Opera/9.55 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.78)',
'Opera/9.62 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.88)',
'IE 4.0 (Windows; U; Windows NT 5.1; ru; rv:1.8.2.18)',
'IE 5.0 (Windows; U; Windows NT 5.1; ru; rv:1.8.3.18)',
'IE 6.0 (Windows; U; Windows NT 5.1; ru; rv:1.8.4.18)',
'IE 7.0 (Windows; U; Windows NT 5.1; ru; rv:1.8.5.18)',
'IE 5.5 (Windows; U; Windows NT 5.1; ru; rv:1.8.6.18)'])
def _curlini(self):
curl = pycurl.Curl()
curl.setopt(curl.COOKIELIST, '')
curl.setopt(curl.ENCODING, 'gzip,deflate')
curl.setopt(curl.NOSIGNAL, 1)
curl.setopt(curl.USERAGENT, self.ua)
curl.setopt(curl.CONNECTTIMEOUT, int(config.timeout))
curl.setopt(curl.TIMEOUT, 20)
#if config.proxy_type == 'socks4':
# curl.setopt(curl.PROXYTYPE, curl.PROXYTYPE_SOCKS4)
#elif config.proxy_type == 'socks5':
# curl.setopt(curl.PROXYTYPE, curl.PROXYTYPE_SOCKS5)
#else:
# curl.setopt(curl.PROXYTYPE, curl.PROXYTYPE_HTTP)
#curl.setopt(curl.PROXY, self.proxy_host)
#curl.setopt(curl.PROXYPORT, int(self.proxy_port))
for c in self.cookies:
curl.setopt(curl.COOKIELIST, c)
return curl
def _curl_perform(self, curl):
curl.perform()
self.cookies = curl.getinfo(curl.INFO_COOKIELIST)
def step_one_login(self):
curl = self._curlini()
sio = StringIO()
curl.setopt(curl.URL, 'http://passport.yandex.ru/passport?mode=auth&retpath=http://mail.yandex.ru')
curl.setopt(curl.WRITEFUNCTION, sio.write)
curl.setopt(curl.POST, 1)
curl.setopt(curl.POSTFIELDS, urlencode({'login' : self.login,
'passwd' : self.passwd}))
self._curl_perform(curl)
login = sio.getvalue()
if 'b-captcha-complex' in login:
login = Send.cap_login(self, login)
if '302 Found' in login:
log('[ + ] Login %s:%s' % (self.login, self.passwd))
return True
elif 'b-error b-error_dark' in login:
log('[ - ] Mismatch login or passwd %s:%s' % (self.login, self.passwd))
return False
elif login == 'cant_get_tid' or login == 'cant_get_captcha' or login == 'ac_error':
append_emails(self.login + ':' + self.passwd)
return False
else:
log('[ - ] Unknown error in login %s:%s' % (self.login, self.passwd))
append_emails(self.login + ':' + self.passwd)
return False
def step_two_check(self):
curl = self._curlini()
sio = StringIO()
curl.setopt(curl.URL, 'http://mail.yandex.ru/classic/compose/')
curl.setopt(curl.WRITEFUNCTION, sio.write)
self._curl_perform(curl)
try:
compose_check = re.search('name="compose_check" value="([a-f0-9]{32})"', sio.getvalue()).group(1)
except AttributeError:
log('[ - ] Cant get compose_check for %s:%s (bad regexp)' % (self.login, self.passwd))
append_emails(self.login + ':' + self.passwd)
return False, False
else:
log('[ + ] Get compose_check for %s:%s' % (self.login, self.passwd))
return True, compose_check
def step_three_send(self, compose_check, to, cc, bcc):
curl = self._curlini()
sio = StringIO()
curl.setopt(curl.WRITEFUNCTION, sio.write)
curl.setopt(curl.POST, 1)
curl.setopt(curl.FOLLOWLOCATION, 1)
curl.setopt(curl.URL, 'http://mail.yandex.ru/mail_send')
curl.setopt(curl.HTTPPOST,
[('compose_check', compose_check),
('ttype', ''),
('style', 'classic'),
('fid', ''),
('overwrite', ''),
('ign_overwrite', 'yes'),
('from_mailbox', choice(config.from_mailbox)),
('to', to),
('cc', cc),
('bcc', bcc),
('subj', eval(subject)),
('send', eval(message))])
self._curl_perform(curl)
sendm = sio.getvalue()
if 'captcha' in sendm:
sendm = Send.cap_send(self, sendm, compose_check, to, cc, bcc)
if 'send-message' in sendm:
return 'send'
elif sendm == 'cid_error' or sendm == 'cant_get_captcha' or sendm == 'ac_error':
log('ac cid error')
append_emails(self.login + ':' + self.passwd)
return False
else:
log('[ - ] Cant send message to %s %s %s from %s:%s' % (to, cc, bcc, self.login, self.passwd))
return False
def cap_login(self, login):
try:
idkey = re.search('name="idkey" value="(.+?)"', login).group(1)
except AttributeError:
log('[ - ] Cant get captcha idkey for %s:%s' % (self.login, self.passwd))
return 'cant_get_tid'
curl = self._curlini()
sio = StringIO()
curl.setopt(curl.URL, 'http://passport.yandex.ru/digits?idkey=' + idkey)
curl.setopt(curl.WRITEFUNCTION, sio.write)
self._curl_perform(curl)
image = sio.getvalue()
if curl.getinfo(curl.HTTP_CODE) == 200:
log('[ + ] Get captcha image for login %s:%s' % (self.login, self.passwd))
else:
log('[ - ] Cant get captcha image for login %s:%s' % (self.login, self.passwd))
return 'cant_get_captcha'
try:
captcha_code, captcha_id = self.acap.resolve(image)
except (Acaptcha.AcaptchaError, Acaptcha.Error), err:
log(str(err))
return 'ac_error'
else:
log('[ + ] Get captcha code (%s:%s) for login %s:%s' % (captcha_code, captcha_id, self.login, self.passwd))
curl = self._curlini()
sio = StringIO()
curl.setopt(curl.URL, 'http://passport.yandex.ru/passport?mode=auth')
curl.setopt(curl.WRITEFUNCTION, sio.write)
curl.setopt(curl.POST, 1)
curl.setopt(curl.POSTFIELDS, urlencode({'retpath' : 'http://mail.yandex.ru',
'idkey' : idkey,
'login' : self.login,
'passwd' : self.passwd,
'code' : captcha_code,
'In' : 'Войти'}))
self._curl_perform(curl)
return sio.getvalue()
def cap_send(self, sendm, compose_check, to, cc, bcc):
try:
cid = re.search('src="/captcha\?id=(\d+)"', sendm).group(1)
except AttributeError:
log('[ - ] Cant parse cid (bad regexp) for %s:%s' % (self.login, self.passwd))
return 'cid_error'
curl = self._curlini()
sio = StringIO()
curl.setopt(curl.URL, 'http://mail.yandex.ru/captcha?id=' + cid)
curl.setopt(curl.WRITEFUNCTION, sio.write)
self._curl_perform(curl)
image = sio.getvalue()
if curl.getinfo(curl.HTTP_CODE) == 200:
log('[ + ] Get captcha image for send message %s:%s' % (self.login, self.passwd))
else:
log('[ - ] Cant get captcha image for send message %s:%s' % (self.login, self.passwd))
return 'cant_get_captcha'
try:
captcha_code, captcha_id = self.acap.resolve(image)
except (Acaptcha.AcaptchaError, Acaptcha.Error), err:
log(str(err))
return 'ac_error'
else:
log('[ + ] Get captcha code (%s:%s) for send %s:%s' % (captcha_code, captcha_id, self.login, self.passwd))
curl = self._curlini()
sio = StringIO()
curl.setopt(curl.WRITEFUNCTION, sio.write)
curl.setopt(curl.POST, 1)
curl.setopt(curl.FOLLOWLOCATION, 1)
curl.setopt(curl.URL, 'http://mail.yandex.ru/mail_send')
curl.setopt(curl.HTTPPOST,
[('compose_check', compose_check),
('ttype', ''),
('style', 'classic'),
('fid', ''),
('overwrite', cid),
('ign_overwrite', 'no'),
('captcha_entered', captcha_code),
('from_mailbox', choice(config.from_mailbox)),
('to', to),
('cc', cc),
('bcc', bcc),
('subj', eval(subject)),
('send', eval(message))])
self._curl_perform(curl)
return sio.getvalue()
sended = 0
def work():
global sended
acap = Acaptcha.Acaptcha(config.api_key, config.ac_delay)
while True:
try:
ep = emails.pop(0)
except IndexError:
return
login, passwd = ep.split(':')
proxy_host, proxy_port = get_proxy()
send = Send(login, passwd, proxy_host, int(proxy_port), acap)
rez = False
try:
rez = send.step_one_login()
except pycurl.error, err:
log(str(err))
append_emails(ep)
if not rez:
continue
sleep(3)
try:
rez, compose_check = send.step_two_check()
except pycurl.error, err:
log(str(err))
append_emails(ep)
if not rez:
continue
sleep(5)
send_count = 0
to = cc = bcc = ''
while send_count < config.max_send:
if not base:
log('[ ! ] Memory of base is over')
return
to_num = choice(config.to)
cc_num = choice(config.cc)
bcc_num = choice(config.bcc)
if to == cc == bcc == '':
to, cc, bcc, dump = get_adressat(to_num, cc_num, bcc_num)
if len(dump) == 0:
log('[ ! ] Memory of base is over')
return
try:
rez = send.step_three_send(compose_check, to, cc, bcc)
except pycurl.error, err:
log(str(err))
append_emails(ep)
base.append(dump)
break
if rez == 'send':
sended += len(dump)
send_count += len(dump)
log('[ + ] Send message to %s %s %s from %s:%s \n (%s)' % (to, cc, bcc, login, passwd, sended))
to = cc = bcc = ''
else:
pass
sleep(5)
load_emails()
load_proxy()
load_base()
load_subj()
load_mess()
load_links()
lock = threading.Lock()
flog = open('_log/log.txt', 'w')
threads = []
for x in xrange(config.threads):
t = threading.Thread(target=work)
t.start()
threads.append(t)
for t in threads:
t.join()