Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # code by : tdxev
- # my blog : tdxev.com
- # teams : insecurity.ro
- # : rstcenter.com
- # version : 2011.10.19
- import json
- import random
- import shelve
- import socket
- import codecs
- import threading
- import time
- import os.path
- import urllib2
- from urllib2 import URLError, HTTPError
- #-- [ USER CONFIG ]
- #-- browser-ul folosit (Firefox/7.0.1)
- appUserAgent = 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1'
- #-- copy/paste la pajiturile din browser
- user_cookies = ''
- #-- ataca doar useri care au level in intervalul specificat ( interval 1-10 )
- attack_level = [8, 10]
- #-- timpul maxim care va astepta inainte sa trimita raspunsul in cazul in care exita in baza de date (interval 0 - 5)
- wait_before_send_answer = 1
- #-- id-ul utilizatorului luat din sursa pagini html (Y=user_id)
- #ex. showMarker(map,41.58630217651367,21.89090592529297,146696,'personal','on','7',false,'personala', 'Y',23424234); | user_id = 23424234
- user_id = ''
- #-- [ SYS CONFIG ]
- page_get_users_online = "http://reteaua.emag.ro/show_more_markers"
- page_get_users_online_params = "zoom_level=%s"
- page_get_user_info = "http://reteaua.emag.ro/show_antenna_info"
- page_get_user_info_params = "antenna_id=%s"
- db_file = "file.db"
- #-- [ SYS BLOBAL VARIABLES ]
- go_attack = None
- s = None
- db = None
- antennas = None
- class database():
- def __init__(self, database_file):
- if not os.path.isfile(database_file) :
- self.create_db_file(database_file)
- self.load_database(database_file)
- def create_db_file(database_file):
- self.tables = shelve.open(db_file, "n")
- self.tables["intrebari"] = {}
- self.tables.close()
- def load_database(self, database_file):
- self.tables = shelve.open(db_file, "w", writeback=1)
- print "[INFO] Load database file, Questions loaded:", len(self.tables["intrebari"])
- def close_db(self, data):
- self.tables.close()
- def get_rasp(self, intr_id):
- if intr_id in self.tables["intrebari"].keys():
- return self.tables["intrebari"][int(intr_id)]["rasp"]
- else :
- return False
- def add_intr(self, intr_id,intr,rasp,v1,v2,v3,v4,rc):
- print "[INFO] Add question to database :", intr_id
- self.tables["intrebari"][int(intr_id)] = {"intr":intr,"rasp":rasp,"v1":v1,"v2":v2,"v3":v3,"v4":v4,"rc":rc}
- self.tables.sync()
- def add_rasp(self, intr_id, rasp_id, rasp_corect):
- print "[INFO] Add answers to databse :", rasp_id, "for question :", intr_id
- self.tables["intrebari"][int(intr_id)]["rasp"] = rasp_id
- self.tables["intrebari"][int(intr_id)]["rc"] = rasp_corect
- self.tables.sync()
- def getPage(url, params):
- global user_cookies
- global appUserAgent
- headers = {}
- headers['Cookie'] = user_cookies
- headers['User-Agent'] = appUserAgent
- req = urllib2.Request(url,params, headers)
- try:
- page = urllib2.urlopen(req)
- except HTTPError, e :
- print "[ERROR]:", str(e.code)
- except URLError, e :
- print "[ERROR]", str(e.reason)
- else:
- return page.read()
- class gameAntennas():
- def __init__(self):
- self.onlineAntennas = {}
- self.attackedAntennas = []
- self.lastAttackAntennaID = -1
- def addAntenna(self, user_id, user_data):
- if not (user_id in self.attackedAntennas) :
- self.onlineAntennas[user_id] = user_data
- def delAntenna(self, user_id):
- if user_id in self.onlineAntennas.keys():
- del self.onlineAntennas[user_id]
- def addAntennaAsAttacked(self, user_id):
- self.attackedAntennas.append(user_id)
- def getRandomUserID(self):
- rand_user_id = random.randrange(0,self.countOnlineUsers() - 1)
- return self.onlineAntennas.keys()[rand_user_id]
- def getAntennaToAttack(self):
- self.lastAttackAntennaID = self.getRandomUserID()
- while self.lastAttackAntennaID in self.attackedAntennas :
- self.lastAttackAntennaID = self.getRandomUserID()
- return self.lastAttackAntennaID
- def countOnlineUsers(self):
- return len(self.onlineAntennas)
- class usersAutoUpdate(threading.Thread):
- def __init__(self):
- threading.Thread.__init__(self)
- self.getUsers()
- self.waitTime = 60
- def run(self):
- timeS = time.time()
- while True:
- if time.time() - timeS > (self.waitTime + random.randrange(30,60)) :
- timeS = time.time()
- self.getUsers()
- def getUsers(self) :
- global antennas
- global attack_max_level
- print "[INFO] Update Online Users"
- data = getPage(page_get_users_online,page_get_users_online_params % str(random.randrange(1,8)))
- uList = json.loads(data);
- for user in uList :
- if user['tip'] == 'oponent' and int(user['level']) in range(attack_level[0], attack_level[1]+1) :
- antennas.addAntenna(user['id'],{'nume':user['nume'], 'level':user['level'],'customer_id':user['customer_id']})
- print "[INFO] Users online:", antennas.countOnlineUsers()
- class gameClient(threading.Thread):
- def __init__(self):
- threading.Thread.__init__(self)
- self.HOST = '188.215.38.73'
- self.PORT = 8080
- self.last_question_id = -1
- self.last_question_answers = -1
- self.last_question_answer = False
- def sendData(self, data):
- global s
- send_data = data + chr(00)
- s.send(send_data)
- print data
- def escape(self, data):
- return data.replace("'",'\\\'')
- def run(self):
- global db
- global antennas
- global go_attack
- global last_atack_id
- global wait_before_send_answer
- global s
- global user_id
- s.connect((self.HOST, self.PORT))
- self.sendData('<policy-file-request/>')
- data = s.recv(4096)
- print data
- self.sendData('{"id":' + user_id + ',"action":"login","avatar":"http://static.emag.ro/images/login/avatar.png","name":"scio"}')
- while True :
- rdata = s.recv(4096)
- if rdata :
- print "raw:",rdata
- cmds = rdata.split("\x00")
- for data in cmds :
- if len(data) > 1 :
- #print data
- if data.find("\x00") != -1 :
- data = data[:data.find("\x00")]
- try:
- data = unicode(data.strip(codecs.BOM_UTF8), 'latin-1').encode("latin-1", "xmlcharrefreplace")
- except UnicodeDecodeError,e:
- print "ERROR", data
- jData = json.loads(data)
- if jData['action'] == 'error':
- print "ERROR",jData['error']
- print jData
- s.close()
- exit()
- if jData['action'] == 'ping':
- self.sendData('{"action":"pong"}')
- if jData['action'] == 'logout':
- antennas.delAntenna(jData['id'])
- # challenge DATA
- if jData['action'] == 'challenge':
- # challenge propus / acceptat
- if 'from' in jData:
- if jData['credits'] < 101 and go_attack :
- self.sendData('{"action":"challenge","accept":true}')
- if 'response' in jData:
- if jData['response'] == "challenge_already":
- go_attack = True
- print "[INFO] Partenerul este angajat in alta confruntare."
- if jData['response'] == "challenge_denied":
- go_attack = True
- print "[INFO] Partenerul a refuzat provocarea."
- if jData['response'] == "challenge_accepted":
- go_attack = False
- print "[INFO] Provocarea a fost acceptata, pregatiti-va de duel!"
- if jData['response'] == "challenge_waiting":
- go_attack = True
- print "[INFO] Se asteapta raspunsul partenerului..."
- if jData['response'] == "challenge_timeout":
- go_attack = True
- print "[INFO] Partenerul nu a raspuns in timp util."
- if jData['response'] == "challenge_yourself":
- go_attack = True
- print "[INFO] Te-ai provocat pe tine."
- if jData['response'] == "challenge_not_logged":
- antennas.delAntenna(antennas.lastAttackAntennaID)
- go_attack = True
- print "[INFO] Partenerul nu este online."
- if jData['response'] == "partner_disconnected":
- antennas.delAntenna(antennas.lastAttackAntennaID)
- go_attack = True
- print "[INFO] Partenerul s-a deconectat."
- if 'winner' in jData:
- antennas.addAntennaAsAttacked(antennas.lastAttackAntennaID)
- go_attack = True
- # intrebarea trimisa de server
- if 'question' in jData:
- self.last_question = jData['question']['question'].encode("latin-1", "xmlcharrefreplace")
- self.last_question_id = jData['question']['id']
- self.last_question_answers = jData['question']['answers']
- if not (isinstance(self.last_question_answers[0], int) or isinstance(self.last_question_answers[0], float)) :
- self.last_question_answers[0] = self.last_question_answers[0].encode("latin-1", "xmlcharrefreplace")
- if not (isinstance(self.last_question_answers[1], int) or isinstance(self.last_question_answers[1], float)) :
- self.last_question_answers[1] = self.last_question_answers[1].encode("latin-1", "xmlcharrefreplace")
- if not (isinstance(self.last_question_answers[2], int) or isinstance(self.last_question_answers[2], float)) :
- self.last_question_answers[2] = self.last_question_answers[2].encode("latin-1", "xmlcharrefreplace")
- if not (isinstance(self.last_question_answers[3], int) or isinstance(self.last_question_answers[3], float)) :
- self.last_question_answers[3] = self.last_question_answers[3].encode("latin-1", "xmlcharrefreplace")
- raspuns = db.get_rasp(self.last_question_id)
- if raspuns == False :
- self.last_question_answer = False
- db.add_intr(self.last_question_id, self.last_question, -1, self.last_question_answers[0], self.last_question_answers[1], self.last_question_answers[2], self.last_question_answers[3], '')
- self.sendData('{"answer":0,"action":"challenge"}')
- else:
- self.last_question_answer = True
- print "[INFO] Raspunsul a fost trimis din baza de date"
- time.sleep(random.randrange(0,wait_before_send_answer))
- self.sendData('{"answer":' + str(raspuns) + ',"action":"challenge"}')
- if 'correct_answer' in jData:
- self.last_correct_answer = jData['correct_answer'] # int
- if self.last_question_answer == False :
- db.add_rasp(self.last_question_id, self.last_correct_answer,self.last_question_answers[int(self.last_correct_answer)])
- #end challenge DATA
- s.close()
- class usersAtackAI(threading.Thread):
- def __init__(self):
- threading.Thread.__init__(self)
- self.attackedUsers = []
- self.waitTime = 10 # odata la 10 de secunde + random
- def getAntennaInfo(self, id):
- global antennas
- print "[INFO] Check antenna id :", id
- data = getPage(page_get_user_info, page_get_user_info_params % (id))
- if data.find('class="ataca"') != -1 :
- s_pos = data.find('showBattleScreen(') + len('showBattleScreen(')
- e_pos = data.find(')" class="ataca"')
- uid, aid, credit = data[s_pos:e_pos].split(',')
- return {'user_id':uid.encode('ascii', 'replace'), 'antena_id':aid.encode('ascii', 'replace'), 'credit':credit.encode('ascii', 'replace')}
- elif data.find("Ai fost deja in duel cu acest utilizator.") != -1:
- antennas.addAntennaAsAttacked(antennas.lastAttackAntennaID)
- return False
- else :
- antennas.delAntenna(antennas.lastAttackAntennaID)
- return False
- def run(self):
- global antennas
- global s
- global go_attack
- timeS = time.time()
- while True:
- if time.time() - timeS > (self.waitTime + random.randrange(0,10)) :
- timeS = time.time()
- if antennas.countOnlineUsers() > 1 and go_attack:
- antennas.getAntennaToAttack()
- if not go_attack : break
- u_data = self.getAntennaInfo(antennas.lastAttackAntennaID)
- if u_data :
- print "[INFO] Attack user:", antennas.onlineAntennas[antennas.lastAttackAntennaID]['nume']
- go_attack = False
- send_data = '{"id":' + u_data['user_id'] + ',"action":"challenge","antenna_id":' + u_data['antena_id'] + ',"credits":' + u_data['credit'] + '}'+ chr(00)
- print send_data
- s.send(send_data)
- else :
- print "[INFO] No Data"
- def main():
- global s
- global go_attack
- global db
- global antennas
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- go_attack = True
- db = database(db_file)
- antennas = gameAntennas()
- uAU = usersAutoUpdate()
- uAU.setDaemon(True)
- uAU.start()
- gC = gameClient()
- gC.setDaemon(True)
- gC.start()
- uAAI = usersAtackAI()
- uAAI.setDaemon(True)
- uAAI.start()
- while True:
- pass
- if __name__ == "__main__" :
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement