class AG: def __init__(self): self.gate = AntiGate(config.ag_key) self.answer = '' def captcha_solve(self, url): with open('image.jpg', 'wb') as image: image.write(urlopen(url).read()) self.answer = self.gate.send('image.jpg') return self.gate.get(self.answer) def abuse(self): self.gate.abuse()
def crack(self, num): # pick a random number print "trying number", num response = requests.get(URL) result = next(self.site.finditer(response.text), None).group(0) response = requests.get(result) challenge = next(self.challenge.finditer(response.text), None).group(1) file = NamedTemporaryFile(prefix="captcha_") response = requests.get(IMAGE + challenge, stream=True) for chunk in response.iter_content(1024): file.write(chunk) file.flush() print "waiting for asians" decaptched = AntiGate(self.ui.antigateid, file.name) print "asians completed, here is your captcha", decaptched username = ( "*****@*****.**" % (self.ui.firstname[0].lower(), self.ui.lastname[0].lower(), num) ) response = requests.post(RESETPASS, { "action": "resetpass2", "ime": self.ui.firstname, "priimek": self.ui.lastname, "dan": self.ui.date.day, "mesec": self.ui.date.month, "leto": self.ui.date.year, "vpisna": self.ui.studentid, "clanica": self.ui.faculty, "upn": username, "recaptcha_challenge_field": challenge, "recaptcha_response_field": str(decaptched) }) if "nastavljeno na" in response.text: print "username found" return username if "podatkov ne najdemo" in response.text: print "Wrong username" if "Izziva niste" in response.text: print "Wrong captcha" decaptched.abuse() raise Exception("Wrong captcha")
def test_abuse(self): gate = AntiGate(API_KEY, IMAGE1) if str(gate) != 'qwerty': self.assertTrue(gate.abuse())
class ChinaPostAirMail(tk.Tk): rowIndex = 0 rows = [] is_refreshing = False def _initDataBase(self): home = os.path.expanduser('~') self.db = shelve.open('%s/.air_mail.db' % home) def _createRow(self, data, j=0): row = [] for j in range(len(data)): width = j == 2 and 50 or 20 e = tk.Entry(self.fm, relief=tk.RIDGE, width=width, borderwidth=0) e.grid(row=self.rowIndex, column=j, sticky=tk.NSEW) e.insert(tk.END, data[j]) row.append(e) tk.Button( self.fm, text='x', command=lambda: self.onDelete(data[1])).grid( row=self.rowIndex, column=(j + 1)) self.rows.append(row) self.rowIndex += 1 def _createTable(self): self.fm = tk.Frame(self, bg="white") self.fm.pack(side=tk.TOP, expand=tk.YES, fill=tk.NONE) keys = self.db.keys() keys.sort() for key in keys: if isinstance(self.db[key], list): self._createRow(self.db[key] + ['not sync']) def _addButtons(self): fm = tk.Frame(self, bg="white") fm.pack(side=tk.BOTTOM, expand=tk.YES, fill=tk.NONE) tk.Button(fm, text='Add', command=self.onAdd).grid(row=0, column=0) tk.Button(fm, text='Save', command=self.onSave).grid(row=0, column=1) tk.Button(fm, text='Refresh', command=self.onRefresh).grid(row=0, column=2) tk.Button(fm, text='Settings', command=self.onSettings).grid(row=0, column=3) tk.Button(fm, text='Clean', command=self.onClean).grid(row=0, column=4) tk.Button(fm, text='Close', command=self.onClose).grid(row=0, column=5) def _initStatusBar(self): label = tk.Label(text='Product') label.grid(row=0) def _addToDb(self, product, number): self._createRow([product, number, 'not sync']) self.db[number] = [product, number] self.db.sync() def _getText(self, element): return tools.text.normalize_space(tools.lxml_tools.get_node_text( element )) def __getCaptcha(self, image_file='/tmp/.air_mail.jpeg'): if hasattr(self, 'code'): return self.g.go('http://track-chinapost.com/startairmail.php') self.image = self.g.xpath('//img[@id="verifyimg"]').get('src') self.cookie = self.g.xpath('//input[@name="cookie"]').get('value') self.g.download(self.image, image_file) self.gate = AntiGate(self.db['api_key'], image_file) self.code = str(self.gate) def __getPage(self): self.g.setup(post={ 'code': self.code, 'num': self.number, 'cookie': self.cookie, 'submit': '' }) self.g.go('http://track-chinapost.com/track_chinapost.php') return self._getText(self.g.xpath('//div[@class="info"]/p')) def __getStatus(self): data = self.g.xpath_list('//table[@id="main_tab"]/tr')[-1] status = self._getText(data.xpath('td[3]')[0]) date = self._getText(data.xpath('td[6]')[0]) message = '%s / %s' % (status, date) if message == 'Status / Date': return 'no tracking info' return message def _getMailStatus(self): self.__getCaptcha() for i in range(3): info = self.__getPage() if 'verification code is wrong' in info: self.gate.abuse() del self.code self.__getCaptcha() continue return self.__getStatus() return 'error' def _setMessage(self, e, message): e.delete(0, tk.END) e.insert(tk.END, message) def _onRefresh(self): for row in self.rows: self._setMessage(row[STATUS], 'updating ...') self.number = row[KEY].get() try: status = self._getMailStatus() except: status = 'can not get info' self._setMessage(row[STATUS], status) time.sleep(5) del self.code self.is_refreshing = False def onRefresh(self): if self.is_refreshing: box.showinfo("Information", "Is running ...") return elif 'api_key' not in self.db.keys(): box.showerror("Error", "API key is not set!") return else: self.is_refreshing = True thread.start_new_thread(self._onRefresh, ()) def onAdd(self): TrackAddDialog(self, self._addToDb) def onClose(self): self.destroy() def onDelete(self, key): del self.db[key] self.db.sync() for row in self.rows: if row[KEY].get() == key: for e in row: e.grid_forget() def onClean(self): for row in self.rows: for e in row: e.grid_forget() self.db.clear() self.db.sync() def onSave(self): for row in self.rows: key = row[KEY].get() if key in self.db.keys(): self.db[key] = [row[NAME].get(), key] self.db.sync() def _saveSettings(self, api_key): self.db['api_key'] = api_key self.db.sync() def onSettings(self): SettingsDialog(self, self._saveSettings, self.db.get('api_key', '')) def _initGrab(self, cookie_file='/tmp/.airmail.cookie'): self.g = Grab() self.g.setup( hammer_mode=True, hammer_timeouts=((60, 70), (80, 90), (100, 110)), reuse_cookies=True, cookiefile=cookie_file ) open(cookie_file, 'w').close() def main(self): self.title('ChinaPost / AirMail tracking') self._initGrab() self._initDataBase() self._addButtons() self._createTable() center(self) self.mainloop() def __del__(self): self.db.sync() self.db.close()
from antigate import AntiGate config = {'min_len': '3', 'max_len': '4', 'phrase': '1'} img_path = '/Users/jason/Downloads/image.jpeg' gate = AntiGate('64192b381a6a42883ee6af1c21bcfa7a', img_path, send_config=config, domain='eve.cm') print gate if str(gate) != '210': gate.abuse() print gate.balance()