This repository has been archived by the owner on Apr 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
ddos.py
213 lines (189 loc) · 11.1 KB
/
ddos.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
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
import config
import json
import sqlite3
import re
import operator
import os
import time
import console
import logging
logger = logging.getLogger(__name__)
class Ddos:
def __init__(self, player):
self.ddos_cluster = config.ddos_cluster
self.database = config.database
self.Max_point_tournament = config.Max_point_tournament
self.username = player.username
self.password = player.password
self.uhash = player.uhash
self.c = console.Console(player)
def run_ddos(self):
if self.ddos_cluster:
checkcluster = json.loads(self.c.check_Cluster())
TournamentPosition = json.loads(self.c.GetTournamentPosition())
try:
# determine and attack cluster tournament
db = sqlite3.connect(self.database)
cursor = db.cursor()
try:
cursor.execute("""CREATE TABLE Cluster (ID TEXT, cluster_name TEXT, cluster_point TEXT) """)
except sqlite3.OperationalError:
pass
tournament_left = re.findall('\d+', TournamentPosition["tleft"])
logger.info("Tournament star finish in {}".format(TournamentPosition["tleft"]))
try:
tournament_hour = tournament_left[0]
tournament_minute = tournament_left[1]
except IndexError:
tournament_hour = 0
try:
tournament_minute = tournament_left[0]
except IndexError:
tournament_minute = 0
if int(tournament_hour) == 0 and int(tournament_minute) < 60:
cluster_name = {}
for row in cursor.execute(
"SELECT * FROM (SELECT cluster_point, cluster_name FROM Cluster ORDER BY cluster_point ASC)"):
cluster_name[row[0]] = row[1]
newA = sorted(cluster_name.iteritems(), key=operator.itemgetter(1), reverse=True)[0:len(cluster_name)]
for i in range(0, len(newA)):
Cluster_name = newA[i][1]
Cluster_point = newA[i][0]
checkcluster = json.loads(self.c.check_Cluster())
if "DDoS not ready" in checkcluster["ddosready"]:
logger.info(checkcluster["ddosready"])
break
else:
try:
scan_cluster = json.loads(self.c.ScanCluster(Cluster_name.decode("utf-8")))
except UnicodeEncodeError:
scan_cluster = json.loads(self.c.ScanCluster(Cluster_name.encode("utf-8")))
if scan_cluster["result"] == "0":
scan_cluster["ddoschance"] = scan_cluster["ddoschance"].split("%")
ddoschance = re.findall('\d+', scan_cluster["ddoschance"][0])
if int(ddoschance[0]) > 50:
logger.info("attack {}({}) Your chance is {}%".format(Cluster_name, Cluster_point, scan_cluster["ddoschance"][0]))
result = json.loads(self.c.AttackCluster(Cluster_name))
os.remove(self.database)
if result['result'] == 6:
pass
else:
break
else:
# Analyse Cluster in tournament
db = sqlite3.connect(self.database)
cursor = db.cursor()
try:
cursor.execute("""CREATE TABLE Cluster (ID TEXT, cluster_name TEXT, cluster_point TEXT) """)
except sqlite3.OperationalError:
pass
count = 0
data = []
point = {}
nb = len(TournamentPosition['data'])
for i in range(1, nb):
getCluster = TournamentPosition['data'][i]['user'].split("|")
data.append(getCluster[0])
point[getCluster[0].strip()] = point.get(getCluster[0].strip(), 0) + i
data2 = {}
for i in data:
data2[str(i.encode("utf-8")).strip()] = int(data.count(i))
newA = sorted(data2.iteritems(), key=operator.itemgetter(1), reverse=True)[0:nb]
logger.info("best list for tournament :")
final_data = {}
for i in range(0, len(newA)):
Cluster_name = newA[i][0]
Cluster_pepole = newA[i][1]
logger.info(" cluster : {} | people on cluster : {} | Points in clusters = {}".format(
Cluster_name.decode("utf-8"), Cluster_pepole, point[Cluster_name.decode("utf-8")] / Cluster_pepole))
final_data[Cluster_name.decode("utf-8")] = int(point[Cluster_name.decode("utf-8")] * Cluster_pepole)
newA = sorted(final_data.iteritems(), key=operator.itemgetter(1), reverse=True)[0:len(newA)]
for i in range(0, len(newA)):
Cluster_name = newA[i][0]
Cluster_point = newA[i][1]
if Cluster_point < self.Max_point_tournament:
# try:
# scan_cluster = json.loads(self.c.ScanCluster(Cluster_name.decode("utf-8")))
# except UnicodeEncodeError:
# scan_cluster = json.loads(self.c.ScanCluster(Cluster_name.encode("utf-8")))
count = count + 1
logger.info("if attack {}({})".format(Cluster_name, Cluster_point))
Cluster = [(0, Cluster_name, str(Cluster_point))]
cursor.executemany("INSERT INTO Cluster VALUES (?,?,?)", Cluster)
db.commit()
else:
count = 0
for i in range(0, len(newA)):
Cluster_name = newA[i][0]
Cluster_point = newA[i][1]
if Cluster_point < self.Max_point_tournament and count < 5:
# try:
# scan_cluster = json.loads(self.c.ScanCluster(Cluster_name.decode("utf-8")))
# except UnicodeEncodeError:
# scan_cluster = json.loads(self.c.ScanCluster(Cluster_name.encode("utf-8")))
count = count + 1
logger.info("if attack {}({})".format(Cluster_name, Cluster_point))
Cluster = [(0, Cluster_name, str(Cluster_point))]
cursor.executemany("INSERT INTO Cluster VALUES (?,?,?)", Cluster)
db.commit()
time.sleep(5)
except KeyError:
# attack cluster for not in tournament
tournament_next = re.findall('\d+', TournamentPosition['nexttournament'])
try:
tournament_hour = tournament_next[0]
tournament_minute = tournament_next[1]
except IndexError:
tournament_hour = 0
try:
tournament_minute = tournament_next[0]
except:
tournament_minute = 0
if int(tournament_hour) > 4:
data = []
point = {}
nb = len(TournamentPosition['data'])
for i in range(1, nb):
getCluster = TournamentPosition['data'][i]['user'].split("|")
data.append(getCluster[0])
point[getCluster[0].strip()] = point.get(getCluster[0].strip(), 0) + i
data2 = {}
for i in data:
data2[str(i.encode("utf-8")).strip()] = int(data.count(i))
newA = sorted(data2.iteritems(), key=operator.itemgetter(1), reverse=True)[0:nb]
logger.info("best list for tournament :")
final_data = {}
for i in range(0, len(newA)):
Cluster_name = newA[i][0]
Cluster_pepole = newA[i][1]
# print " cluster : "+ Cluster_name.decode("utf-8") + " people on cluster : " + str(Cluster_pepole) + " Points in clusters = " + str(point[Cluster_name.decode("utf-8")]/Cluster_pepole)
final_data[Cluster_name.decode("utf-8")] = int(point[Cluster_name.decode("utf-8")] * Cluster_pepole)
newA = sorted(final_data.iteritems(), key=operator.itemgetter(1), reverse=True)[0:len(newA)]
for i in range(0, len(newA)):
Cluster_name = newA[i][0]
Cluster_point = newA[i][1]
if Cluster_point < self.Max_point_tournament:
checkcluster = json.loads(self.c.check_Cluster())
test = "no"
if "DDoS not ready" in checkcluster["ddosready"] and test == "no":
logger.info(checkcluster["ddosready"])
break
else:
try:
scan_cluster = json.loads(self.c.ScanCluster(Cluster_name.decode("utf-8")))
except UnicodeEncodeError:
scan_cluster = json.loads(self.c.ScanCluster(Cluster_name.encode("utf-8")))
if scan_cluster["result"] == "0":
scan_cluster["ddoschance"] = scan_cluster["ddoschance"].split("%")
ddoschance = re.findall('\d+', scan_cluster["ddoschance"][0])
if int(ddoschance[0]) > 50:
logger.info("attack {}({}) Your chance is {}%".format(Cluster_name, Cluster_point, scan_cluster["ddoschance"][0]))
result = json.loads(self.c.AttackCluster(Cluster_name))
if result['result'] == 6:
pass
else:
break
else:
logger.info("no attack possible to {}({}) Your chance is {}%".format(Cluster_name, Cluster_point, scan_cluster["ddoschance"][0]))
else:
logger.info("next tournament in ".format(TournamentPosition['nexttournament']))