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
/
botnet.py
252 lines (212 loc) · 9.37 KB
/
botnet.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
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
#!/usr/bin/python2.7
# -*- coding: utf-8
from utils import Utils
import json
import logging
import random
import config
logger = logging.getLogger(__name__)
class Botnet:
ut = Utils()
def __init__(self, player):
self.username = player.username
self.password = player.password
self.uhash = player.uhash
self.botNetServers = 3
self.botnet = []
self.p = player
self.ofwhat = config.BotNet_updates
self.energy = 0
self._initbot()
def _initbot(self):
"""
Grab the amount of bots in the botnet
and populate and array of Bot class
:return: none
"""
if(self.ofwhat == "ALL"):
self.ofwhat = ["fw", "av", "smash", "mwk"]
data = self._botnetInfo()
bots = json.loads(data)
self.botnet = []
if int(bots['count']) > 0:
for i in bots['data']:
bot = Bot(i['running'], self.ofwhat[random.randint(0,len(self.ofwhat)-1)], self.energy, i['hostname'], self.username, self.password, self.uhash)
self.botnet.append(bot)
def printbots(self):
"""
Print a list of player PCs in the botnet
:return: None
"""
for bot in self.botnet:
logger.info(bot)
def getbotnetdata(self):
"""
Return an array of bot class.
Contains all the bots in the botnet.
:return: list of bot class
"""
return self.botnet
def getInfo(self):
"""
Get info about the entire botnet.
Including if you can attack bot net servers etc.
Also botnet PC info.
:return: list of vHack serves that can be hacked.
['1','2','1']. '1' = can be hacked, '2' time not elapsed.
"""
response = self.ut.requestString(self.username, self.password, self.uhash, "vh_botnetInfo.php")
response = json.loads(response)
return response
def attack(self):
"""
Check if vHack server botnet is attackable,
then attack if can.
:return: none
"""
self._initbot()
logger.info("Trying Bot Net")
cinfo = self.getInfo()
for i in range(1, self.botNetServers + 1):
if cinfo[i - 1] == '1':
logger.debug('I am attacking #{}'.format(i))
if i == 1:
response = self.ut.requestString(self.username, self.password, self.uhash, "vh_attackCompany.php", company=str(i))
else:
response = self.ut.requestString(self.username, self.password, self.uhash, "vh_attackCompany" + str(i) + ".php", company=str(i))
logger.debug('I attacked #{} with response {}'.format(i, response))
if response == '0':
logger.info('#{} Netcoins gained'.format(i))
else:
logger.info('#{} Failed! No netcoins...'.format(i))
else:
logger.info("Botnet #{} not hackable yet".format(i))
def upgradebotnet(self, hostname, running, count):
"""
Check if there is enough money to upgrade a botnet PC.
Cycle through and upgrade until no money.
:return: None
"""
ofwhat = self.ofwhat[random.randint(0,len(self.ofwhat)-1)]
logger.info("Prepare attempting to upgrade bot net PC '"+ hostname +"'")
get_infobot = self.getInfo()
if (int(get_infobot['data'][count]['strength']) == 1120 and int(get_infobot['data'][count]['stars']) == 4):
logger.info("Bot '"+hostname+"' has max strength [1120] for level " + str(get_infobot['data'][count]['stars']))
return False
elif (int(get_infobot['data'][count]['strength']) == 840 and int(get_infobot['data'][count]['stars']) == 3):
logger.info("Bot '"+hostname+"' has max strength [840] for level " + str(get_infobot['data'][count]['stars']))
return False
elif (int(get_infobot['data'][count]['strength']) == 600 and int(get_infobot['data'][count]['stars']) == 2):
logger.info("Bot '"+hostname+"' has max strength [600] for level " + str(get_infobot['data'][count]['stars']))
return False
elif (int(get_infobot['data'][count]['strength']) == 400 and int(get_infobot['data'][count]['stars']) == 1):
logger.info("Bot '"+hostname+"' has max strength [400] for level " + str(get_infobot['data'][count]['stars']))
return False
elif (int(get_infobot['data'][count]['strength']) == 3000 and int(get_infobot['data'][count]['stars']) == 0):
logger.info("Bot '"+hostname+"' has max strength [3000] for level " + str(get_infobot['data'][count]['stars']))
return False
if (int(get_infobot['data'][count]['running']) == 0 and int(get_infobot['energy']) > 0):
if int(get_infobot['data'][count]['stars']) > 0:
maxofwhat = 20 + (5*int(get_infobot['data'][count]['stars']))
elif int(get_infobot['data'][count]['stars']) == 0:
maxofwhat = 250
remove = 0
for a, i in enumerate(xrange(0, len(self.ofwhat)-1)):
if int(get_infobot['data'][count][unicode(self.ofwhat[i-remove])]) == int(maxofwhat):
self.ofwhat.remove(self.ofwhat[i-remove])
remove = remove + 1
if i == 3:
break
ofwhat = self.ofwhat[random.randint(0,(len(self.ofwhat)-1))]
new_bal = self.upgradesinglebot(hostname, ofwhat)
if new_bal:
logger.info("Waiting! Doing updates for bot '" + hostname + "', [" + ofwhat + "]")
return True
elif (int(get_infobot['energy']) == 0):
logger.info("You don't have enough energy to upgrade '" + hostname + "'! :(")
return False
elif (int(get_infobot['data'][count]['running']) == 1):
logger.info("Waiting! Doing updates for bot '" + hostname + "', [" + ofwhat + "]")
return False
logger.debug("The bot '{}' is not upgradeable".format(hostname))
return False
def _botnetInfo(self):
"""
Get the botnet information including vHack servers and PC data.
:return: string
'{"count":"14",
"data":[{"bID":"1","bLVL":"100","bSTR":"100","bPRICE":"10000000"},
{"bID":"2","bLVL":"100","bSTR":"100","bPRICE":"10000000"}],
"strength":23,"resethours1":"","resetminutes1":"14","resethours2":"4","resetminutes2":"15",
"resethours3":"3","resetminutes3":"15",
"canAtt1":"2","canAtt2":"2","canAtt3":"2"}'
"""
temp = self.ut.requestString(self.username, self.password, self.uhash, "vh_botnetInfo.php")
return temp
def upgradesinglebot(self, hostname, ofwhat):
"""
Pass in bot class object and call upgrade function based on bot ID.
details :
{u'strength': u'22', u'old': u'30', u'mm': u'68359859',
u'money': u'66259859', u'costs': u'2100000',
u'lvl': u'21', u'new': u'22'}
current lvl, bot number, x, x, upgrade cost, lvl, next lvl
:return: None
"""
response = self.ut.requestString(self.username, self.password, self.uhash, "vh_upgradePC.php", hostname=hostname, ofwhat=ofwhat, inst="0", much="1")
jsons = json.loads(response)
if int(jsons['result']) == 0:
return True
else:
logger.error("Upgrades on " + hostname + " Failed !")
return False
def __repr__(self):
return "Botnet details: vHackServers: {0}, Bot Net PC's: {1}".format(self.botNetServers, self.botnet)
class Bot:
ut = Utils()
def __init__(self, running, ofwhat, energy, hostname, username, password, uhash):
self.username = username
self.uhash = uhash
self.password = password
self.running = int(running)
self.ofwhat = ofwhat
self.energy = energy
self.hostname = hostname
def botupgradable(self, running):
"""
Determine if botnet PC is at max level or not.
:return: Bool
"""
if running == 0:
return True
else:
return False
def nextlevelcostenergy(self):
"""
Return the cost of upgrading bot to the next level
:return:int
"""
return self.energy
def parse_json_stream(self, stream):
decoder = json.JSONDecoder()
while stream:
obj, idx = decoder.raw_decode(stream)
yield obj
stream = stream[idx:].lstrip()
def upgradesinglebot(self, hostname, ofwhat):
"""
Pass in bot class object and call upgrade function based on bot ID.
details :
{u'strength': u'22', u'old': u'30', u'mm': u'68359859',
u'money': u'66259859', u'costs': u'2100000',
u'lvl': u'21', u'new': u'22'}
current lvl, bot number, x, x, upgrade cost, lvl, next lvl
:return: None
"""
response = self.ut.requestString(self.username, self.password, self.uhash, "vh_upgradePC.php", hostname=hostname, ofwhat=ofwhat)
#response = response.split('}{')[0] + '}'
#jsons = json.loads(response)
#logger.info(jsons)
return True
def __repr__(self):
return "Bot details: running: {0}, energy: {1}, upgrade: {2}, botname: {3}".format(self.running, self.energy, self.ofwhat, self.hostname)