Guest User

emag challenge boot

a guest
Oct 25th, 2011
923
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # code by : tdxev
  2. # my blog : tdxev.com
  3. # teams   : insecurity.ro
  4. #         : rstcenter.com
  5. # version : 2011.10.19
  6.  
  7. import json
  8. import random
  9. import shelve
  10. import socket
  11. import codecs
  12. import threading
  13. import time
  14. import os.path
  15. import urllib2
  16. from urllib2            import URLError, HTTPError
  17.  
  18.  
  19. #-- [ USER CONFIG ]
  20. #-- browser-ul folosit (Firefox/7.0.1)
  21. appUserAgent                  = 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1'
  22. #-- copy/paste la pajiturile din browser
  23. user_cookies                  = ''
  24. #-- ataca doar useri care au level in intervalul specificat ( interval 1-10 )
  25. attack_level              = [8, 10]
  26. #-- timpul maxim care va astepta inainte sa trimita raspunsul in cazul in care exita in baza de date (interval 0 - 5)
  27. wait_before_send_answer       = 1
  28.  
  29.  
  30. #-- id-ul utilizatorului luat din sursa pagini html (Y=user_id)
  31. #ex. showMarker(map,41.58630217651367,21.89090592529297,146696,'personal','on','7',false,'personala', 'Y',23424234); | user_id = 23424234
  32. user_id = ''
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39. #-- [ SYS CONFIG ]
  40. page_get_users_online         = "http://reteaua.emag.ro/show_more_markers"
  41. page_get_users_online_params  = "zoom_level=%s"
  42. page_get_user_info            = "http://reteaua.emag.ro/show_antenna_info"
  43. page_get_user_info_params     = "antenna_id=%s"
  44. db_file                       = "file.db"
  45.  
  46. #-- [ SYS BLOBAL VARIABLES ]
  47. go_attack = None
  48. s = None
  49. db = None
  50. antennas = None
  51.  
  52. class database():
  53.   def __init__(self, database_file):
  54.     if not os.path.isfile(database_file) :
  55.       self.create_db_file(database_file)
  56.     self.load_database(database_file)
  57.  
  58.   def create_db_file(database_file):
  59.     self.tables = shelve.open(db_file, "n")
  60.     self.tables["intrebari"] = {}
  61.     self.tables.close()
  62.    
  63.   def load_database(self, database_file):
  64.     self.tables = shelve.open(db_file, "w", writeback=1)
  65.     print "[INFO] Load database file, Questions loaded:", len(self.tables["intrebari"])
  66.  
  67.   def close_db(self, data):
  68.     self.tables.close()
  69.    
  70.   def get_rasp(self, intr_id):
  71.     if intr_id in self.tables["intrebari"].keys():
  72.       return self.tables["intrebari"][int(intr_id)]["rasp"]
  73.     else :
  74.       return False
  75.  
  76.   def add_intr(self, intr_id,intr,rasp,v1,v2,v3,v4,rc):
  77.     print "[INFO] Add question to database :", intr_id
  78.     self.tables["intrebari"][int(intr_id)] = {"intr":intr,"rasp":rasp,"v1":v1,"v2":v2,"v3":v3,"v4":v4,"rc":rc}
  79.     self.tables.sync()
  80.  
  81.   def add_rasp(self, intr_id, rasp_id, rasp_corect):
  82.     print "[INFO] Add answers to databse :", rasp_id, "for question :", intr_id
  83.     self.tables["intrebari"][int(intr_id)]["rasp"] = rasp_id
  84.     self.tables["intrebari"][int(intr_id)]["rc"]   = rasp_corect
  85.     self.tables.sync()
  86.  
  87. def getPage(url, params):
  88.   global user_cookies
  89.   global appUserAgent
  90.   headers = {}
  91.   headers['Cookie'] = user_cookies
  92.   headers['User-Agent'] = appUserAgent
  93.   req = urllib2.Request(url,params, headers)
  94.   try:
  95.     page = urllib2.urlopen(req)
  96.   except HTTPError, e :
  97.     print "[ERROR]:", str(e.code)
  98.   except URLError, e :
  99.     print "[ERROR]", str(e.reason)
  100.   else:
  101.     return page.read()
  102.  
  103. class gameAntennas():
  104.   def __init__(self):
  105.     self.onlineAntennas = {}
  106.     self.attackedAntennas = []
  107.     self.lastAttackAntennaID = -1
  108.  
  109.   def addAntenna(self, user_id, user_data):
  110.     if not (user_id in self.attackedAntennas) :
  111.       self.onlineAntennas[user_id] = user_data
  112.  
  113.   def delAntenna(self, user_id):
  114.     if user_id in self.onlineAntennas.keys():
  115.       del self.onlineAntennas[user_id]
  116.  
  117.   def addAntennaAsAttacked(self, user_id):
  118.     self.attackedAntennas.append(user_id)
  119.  
  120.   def getRandomUserID(self):
  121.     rand_user_id =  random.randrange(0,self.countOnlineUsers() - 1)
  122.     return self.onlineAntennas.keys()[rand_user_id]
  123.  
  124.   def getAntennaToAttack(self):
  125.     self.lastAttackAntennaID = self.getRandomUserID()
  126.     while self.lastAttackAntennaID in self.attackedAntennas :
  127.       self.lastAttackAntennaID = self.getRandomUserID()
  128.     return self.lastAttackAntennaID
  129.  
  130.   def countOnlineUsers(self):
  131.     return len(self.onlineAntennas)
  132.  
  133. class usersAutoUpdate(threading.Thread):
  134.   def __init__(self):
  135.     threading.Thread.__init__(self)
  136.     self.getUsers()
  137.     self.waitTime = 60
  138.  
  139.   def run(self):
  140.     timeS = time.time()
  141.     while True:
  142.       if  time.time() - timeS > (self.waitTime + random.randrange(30,60)) :
  143.         timeS = time.time()
  144.         self.getUsers()
  145.  
  146.   def getUsers(self) :
  147.     global antennas
  148.     global attack_max_level
  149.     print "[INFO] Update Online Users"
  150.     data = getPage(page_get_users_online,page_get_users_online_params % str(random.randrange(1,8)))
  151.     uList = json.loads(data);
  152.     for user in uList :
  153.       if user['tip'] == 'oponent' and  int(user['level']) in range(attack_level[0], attack_level[1]+1) :
  154.         antennas.addAntenna(user['id'],{'nume':user['nume'], 'level':user['level'],'customer_id':user['customer_id']})
  155.     print "[INFO] Users online:", antennas.countOnlineUsers()
  156.  
  157. class gameClient(threading.Thread):
  158.   def __init__(self):
  159.     threading.Thread.__init__(self)
  160.     self.HOST = '188.215.38.73'
  161.     self.PORT = 8080
  162.     self.last_question_id = -1
  163.     self.last_question_answers = -1
  164.     self.last_question_answer = False
  165.  
  166.   def sendData(self, data):
  167.     global s
  168.     send_data = data + chr(00)
  169.     s.send(send_data)
  170.     print data
  171.    
  172.   def escape(self, data):
  173.     return data.replace("'",'\\\'')
  174.    
  175.   def run(self):
  176.     global db
  177.     global antennas
  178.     global go_attack
  179.     global last_atack_id
  180.     global wait_before_send_answer
  181.     global s
  182.     global user_id
  183.     s.connect((self.HOST, self.PORT))
  184.     self.sendData('<policy-file-request/>')
  185.     data = s.recv(4096)
  186.     print data
  187.     self.sendData('{"id":' + user_id + ',"action":"login","avatar":"http://static.emag.ro/images/login/avatar.png","name":"scio"}')
  188.     while True :
  189.       rdata = s.recv(4096)
  190.       if rdata :
  191.         print "raw:",rdata
  192.         cmds = rdata.split("\x00")
  193.         for data in cmds :
  194.           if len(data) > 1 :
  195.                         #print data
  196.                         if data.find("\x00") != -1 :
  197.                           data = data[:data.find("\x00")]
  198.                          
  199.                         try:
  200.                           data = unicode(data.strip(codecs.BOM_UTF8), 'latin-1').encode("latin-1", "xmlcharrefreplace")
  201.                         except UnicodeDecodeError,e:
  202.                             print "ERROR", data
  203.  
  204.                         jData = json.loads(data)
  205.                        
  206.                         if jData['action'] == 'error':
  207.                           print "ERROR",jData['error']
  208.                           print jData
  209.                           s.close()
  210.                           exit()
  211.  
  212.                         if jData['action'] == 'ping':
  213.                           self.sendData('{"action":"pong"}')
  214.                          
  215.                          
  216.                         if jData['action'] == 'logout':
  217.                           antennas.delAntenna(jData['id'])
  218.                            
  219.                        
  220.                         # challenge DATA
  221.                         if jData['action'] == 'challenge':
  222.  
  223.                           # challenge propus / acceptat
  224.                           if 'from' in jData:
  225.                             if jData['credits'] < 101 and go_attack :
  226.                               self.sendData('{"action":"challenge","accept":true}')
  227.                              
  228.                           if 'response' in jData:
  229.                             if jData['response'] == "challenge_already":
  230.                               go_attack = True
  231.                               print "[INFO] Partenerul este angajat in alta confruntare."
  232.                              
  233.                             if jData['response'] == "challenge_denied":
  234.                               go_attack = True
  235.                               print "[INFO] Partenerul a refuzat provocarea."
  236.                              
  237.                             if jData['response'] == "challenge_accepted":
  238.                               go_attack = False
  239.                               print "[INFO] Provocarea a fost acceptata, pregatiti-va de duel!"
  240.  
  241.                             if jData['response'] == "challenge_waiting":
  242.                               go_attack = True
  243.                               print "[INFO] Se asteapta raspunsul partenerului..."
  244.  
  245.                             if jData['response'] == "challenge_timeout":
  246.                               go_attack = True
  247.                               print "[INFO] Partenerul nu a raspuns in timp util."
  248.                              
  249.                             if jData['response'] == "challenge_yourself":
  250.                               go_attack = True
  251.                               print "[INFO] Te-ai provocat pe tine."                              
  252.  
  253.                             if jData['response'] == "challenge_not_logged":
  254.                               antennas.delAntenna(antennas.lastAttackAntennaID)
  255.                               go_attack = True
  256.                               print "[INFO] Partenerul nu este online."    
  257.                              
  258.                             if jData['response'] == "partner_disconnected":
  259.                               antennas.delAntenna(antennas.lastAttackAntennaID)
  260.                               go_attack = True
  261.                               print "[INFO] Partenerul s-a deconectat."    
  262.                              
  263.                              
  264.                           if 'winner' in jData:
  265.                             antennas.addAntennaAsAttacked(antennas.lastAttackAntennaID)
  266.                             go_attack = True
  267.                          
  268.                           # intrebarea trimisa de server
  269.                           if 'question' in jData:
  270.                             self.last_question = jData['question']['question'].encode("latin-1", "xmlcharrefreplace")
  271.                             self.last_question_id = jData['question']['id']
  272.                             self.last_question_answers = jData['question']['answers']
  273.                             if not (isinstance(self.last_question_answers[0], int) or isinstance(self.last_question_answers[0], float)) :
  274.                                 self.last_question_answers[0] = self.last_question_answers[0].encode("latin-1", "xmlcharrefreplace")
  275.                             if not (isinstance(self.last_question_answers[1], int) or isinstance(self.last_question_answers[1], float)) :
  276.                                 self.last_question_answers[1] = self.last_question_answers[1].encode("latin-1", "xmlcharrefreplace")
  277.                             if not (isinstance(self.last_question_answers[2], int) or isinstance(self.last_question_answers[2], float)) :
  278.                                 self.last_question_answers[2] = self.last_question_answers[2].encode("latin-1", "xmlcharrefreplace")
  279.                             if not (isinstance(self.last_question_answers[3], int) or isinstance(self.last_question_answers[3], float)) :
  280.                                 self.last_question_answers[3] = self.last_question_answers[3].encode("latin-1", "xmlcharrefreplace")
  281.  
  282.                             raspuns = db.get_rasp(self.last_question_id)
  283.                             if raspuns == False :
  284.                               self.last_question_answer = False
  285.                               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], '')
  286.                               self.sendData('{"answer":0,"action":"challenge"}')
  287.                             else:
  288.                               self.last_question_answer = True
  289.                               print "[INFO] Raspunsul a fost trimis din baza de date"
  290.                               time.sleep(random.randrange(0,wait_before_send_answer))
  291.                               self.sendData('{"answer":' + str(raspuns) + ',"action":"challenge"}')
  292.                              
  293.                              
  294.                        
  295.                           if 'correct_answer' in jData:
  296.                             self.last_correct_answer = jData['correct_answer'] # int
  297.                             if self.last_question_answer == False :
  298.                               db.add_rasp(self.last_question_id, self.last_correct_answer,self.last_question_answers[int(self.last_correct_answer)])
  299.                         #end challenge DATA
  300.     s.close()
  301.  
  302. class usersAtackAI(threading.Thread):
  303.   def __init__(self):
  304.     threading.Thread.__init__(self)
  305.     self.attackedUsers = []
  306.     self.waitTime = 10 # odata la 10 de secunde + random
  307.    
  308.   def getAntennaInfo(self, id):
  309.     global antennas
  310.     print "[INFO] Check antenna id :", id
  311.     data = getPage(page_get_user_info, page_get_user_info_params % (id))
  312.     if data.find('class="ataca"') != -1 :
  313.       s_pos = data.find('showBattleScreen(') + len('showBattleScreen(')
  314.       e_pos = data.find(')" class="ataca"')
  315.       uid, aid, credit = data[s_pos:e_pos].split(',')
  316.       return {'user_id':uid.encode('ascii', 'replace'), 'antena_id':aid.encode('ascii', 'replace'), 'credit':credit.encode('ascii', 'replace')}
  317.     elif data.find("Ai fost deja in duel cu acest utilizator.") != -1:
  318.       antennas.addAntennaAsAttacked(antennas.lastAttackAntennaID)
  319.       return False
  320.     else :
  321.       antennas.delAntenna(antennas.lastAttackAntennaID)
  322.       return False
  323.    
  324.  
  325.   def run(self):
  326.     global antennas
  327.     global s
  328.     global go_attack
  329.     timeS = time.time()
  330.     while True:
  331.       if  time.time() - timeS > (self.waitTime + random.randrange(0,10)) :
  332.         timeS = time.time()
  333.         if antennas.countOnlineUsers() > 1 and go_attack:
  334.           antennas.getAntennaToAttack()
  335.           if not go_attack : break
  336.           u_data = self.getAntennaInfo(antennas.lastAttackAntennaID)
  337.           if u_data :
  338.             print "[INFO] Attack user:", antennas.onlineAntennas[antennas.lastAttackAntennaID]['nume']
  339.             go_attack = False
  340.             send_data = '{"id":' + u_data['user_id'] + ',"action":"challenge","antenna_id":' + u_data['antena_id'] + ',"credits":' + u_data['credit'] + '}'+ chr(00)
  341.             print send_data
  342.             s.send(send_data)
  343.           else :
  344.             print "[INFO] No Data"
  345.  
  346. def main():
  347.   global s
  348.   global go_attack
  349.   global db
  350.   global antennas
  351.  
  352.   s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  353.   go_attack = True
  354.   db = database(db_file)  
  355.   antennas = gameAntennas()
  356.  
  357.   uAU = usersAutoUpdate()
  358.   uAU.setDaemon(True)
  359.   uAU.start()
  360.  
  361.   gC = gameClient()
  362.   gC.setDaemon(True)
  363.   gC.start()
  364.  
  365.   uAAI = usersAtackAI()
  366.   uAAI.setDaemon(True)
  367.   uAAI.start()
  368.  
  369.   while True:
  370.     pass
  371.  
  372.  
  373. if __name__ == "__main__" :
  374.   main()
  375.  
  376.  
  377.  
  378.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×