def FirstFetch(self): try: last_domain = DarkNet_Domain.select().order_by(DarkNet_Domain.datetime).limit(1) self.domain = self.domain if not last_domain else last_domain[0].domain self.warn(f"[{self.domain}]Getting PHPSESSID") self.session.cookies.clear() self.info(f"Already Cleaned Session Cookies.") self.RefreshNewDomain(self.session.get(f"http://{self.domain}")) resp = self.session.get(f"http://{self.domain}/index.php") self.info(f"Current Cookie Nums: {len(self.session.cookies)}") user = ( DarkNet_User.select() .where(DarkNet_User.useful == True) .order_by(fn.Rand()) .limit(1) ) if not bool(user): self.Reg() else: self.usr = user[0].user self.pwd = user[0].pwd if random.choice([1, 0, 0]): # 佛系注册堆积账号池 self.Reg() return True except KeyboardInterrupt: pass except Exception as e: raise
def ban_user(usr): warning(f"ban user: {usr}") return ( DarkNet_User.update({"useful": False}) .where(DarkNet_User.user == usr) .execute() )
def FirstFetch(self): targets = DarkNetWebSites.select().where( DarkNetWebSites.ismaster == self.usemaster) if not targets: return target = targets[0] try: self.warn(f'[{target.domain}]Getting PHPSESSID') resp = self.session.get(f'http://{target.domain}') target.ismaster = True target.title = jq(resp.text)('title').text() self.usemaster = True self.master = target self.domain = target.domain user = DarkNet_User.select().where( DarkNet_User.useful == True).order_by(fn.Rand()).limit(1) if not bool(user): self.Reg() else: self.usr = user[0].user self.pwd = user[0].pwd if random.choice([1, 0]): # 佛系注册堆积账号池 self.Reg() return True except KeyboardInterrupt: pass except requests.Timeout: target.alive = False target.ismaster = False self.usemaster = False except Exception as e: raise finally: target.save()
def get_random_user(last_days=30): try: return (DarkNet_User.select().where( DarkNet_User.useful == True, DarkNet_User.intime >= moment.now().add( days=-last_days).format("YYYY-MM-DD HH:mm:ss"), ).order_by(fn.Rand()).limit(10)[0]) except Exception as e: error(f"[Cursor->get_random_user]: {e}")
def get_random_user(): try: return ( DarkNet_User.select() .where(DarkNet_User.useful == True) .order_by(fn.Rand()) .limit(1)[0] ) except Exception as e: error(f"[Cursor->get_random_user]: {e}")
def Login(self): """ ### 再次尝试 1.因为网络问题重试 ### 重新注册 2.因为账户被封重试 3.因为账户认证错误重试 """ self.warn("Login...") url = f"http://{self.domain}/ucp.php?mode=login" data = { "username": self.usr, "password": self.pwd, "login": "******", "redirect": f"./index.php&sid={self.sid}", } resp = self.session.post(url, data=data, verify=False, timeout=120) self.sid = "".join(re.findall("sid=(.*?)'", resp.text)[:1]) if self.usr not in resp.text and "暗网欢迎您" not in resp.text: self.error("Auth faild") self.SaveError("Autherror.html", resp) if "已被封禁" in resp.text: DarkNet_User.update({"useful": False}).where( DarkNet_User.user == self.usr ).execute() self.Reg() raise ValueError else: self.report("Auth Success") self.types = { item(".index_list_title") .attr("href") .split("=")[1] .split("&")[0]: item("tr:nth-child(1) > td") .text() .split()[0] for item in jq(resp.text)(".ad_table_b").items() } self.report(self.types)
def Login(self): """ ### 再次尝试 1.因为网络问题重试 ### 重新注册 2.因为账户被封重试 3.因为账户认证错误重试 """ self.warn('Login...') url = f'http://{self.domain}/ucp.php?mode=login' data = { "username": self.usr, "password": self.pwd, "login": "******", "redirect": f"./index.php&sid={self.sid}" } resp = self.session.post(url, data=data, verify=False, timeout=120) self.sid = ''.join(re.findall("sid=(.*?)'", resp.text)[:1]) self.info(f"SID: {self.sid}") if self.usr not in resp.text: self.error('Auth faild') self.SaveError('Autherror.html', resp) if "已被封禁" in resp.text: DarkNet_User.update({ "useful": False }).where(DarkNet_User.user == self.usr).execute() self.Reg() raise ValueError else: self.report('Auth Success') self.types = { item('.index_list_title').attr('href').split('=')[1].split('&') [0]: item('tr:nth-child(1) > td').text().split()[0] for item in jq(resp.text)('.ad_table_b').items() } self.report(self.types)
def FirstFetch(self): targets = DarkNetWebSites.select().where( DarkNetWebSites.ismaster == self.usemaster) if not targets: return target = targets[0] try: self.warn(f"[{target.domain}]Getting PHPSESSID") self.session.cookies.clear() self.info(f"Already Cleaned Session Cookies.") resp = self.session.get(f"http://{target.domain}") resp = self.session.get(f"http://{target.domain}/index.php") self.info(f"Current Cookie Nums: {len(self.session.cookies)}") target.ismaster = True target.title = jq(resp.text)("title").text() self.usemaster = True self.master = target self.domain = target.domain user = (DarkNet_User.select().where( DarkNet_User.useful == True).order_by(fn.Rand()).limit(1)) if not bool(user): self.Reg() else: self.usr = user[0].user self.pwd = user[0].pwd if random.choice([1, 0, 0]): # 佛系注册堆积账号池 self.Reg() return True except KeyboardInterrupt: pass except requests.Timeout: target.alive = False target.ismaster = False self.usemaster = False except Exception as e: raise finally: target.save()
def create_new_user(datas): return DarkNet_User.create(**datas)
def ban_user(usr): return ( DarkNet_User.update({"useful": False}) .where(DarkNet_User.user == usr) .execute() )
def Reg(self): self.warn("Start Regging") headers = { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", "Accept-Encoding": "gzip, deflate", "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8", "Cache-Control": "no-cache", "Connection": "keep-alive", "Content-Type": "application/x-www-form-urlencoded", "Origin": f"http://{self.domain}", "Pragma": "no-cache", "Referer": f"http://{self.domain}/ucp.php?mode=register&sid={self.sid}", "Upgrade-Insecure-Requests": "1", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36", } step1resp = self.session.get( f"http://{self.domain}/ucp.php?mode=register").text step1 = jq(step1resp) self.info(f'RegPage Confirmed. {"sid" in step1resp}') token = step1('input[name="form_token"]').attr("value") self.report(f"Got Token: {token}") creation_time = step1('input[name="creation_time"]').attr("value") self.report(f"Got Create_time: {creation_time}") url = f"http://{self.domain}/ucp.php?mode=register" step2resp = self.session.post( url, data={ "agreed": "===好的,我已明白,请跳转到下一页继续注册====", "change_lang": "", "creation_time": creation_time, "form_token": token, }, headers=headers, ) self.SaveError("step2.html", step2resp) step2 = jq(step2resp.text) token = step2('input[name="form_token"]').attr("value") creation_time = step2('input[name="creation_time"]').attr("value") qa_answer = re.findall("请在右边框中输入: (.*?):</label>", step2resp.text)[0] self.report(f"Got answer: {qa_answer}") qa_confirm_id = step2("#qa_confirm_id").attr("value") self.usr = self.RandomKey(12) self.pwd = self.RandomKey() self.info(f"set Usr: {self.usr} ,Pwd: {self.pwd}") data = { "username": self.usr, "new_password": self.pwd, "password_confirm": self.pwd, "email": "*****@*****.**", "lang": "zh_cmn_hans", "tz_date": "UTC+08:00+-+Asia/Brunei+-+" + moment.now().format("DD+MM月+YYYY,+HH:mm"), "tz": "Asia/Hong_Kong", "agreed": "true", "change_lang": "0", "qa_answer": qa_answer, "qa_confirm_id": qa_confirm_id, "submit": " 用户名与密码已填好,+点此提交 ", "creation_time": creation_time, "form_token": token, } resp = self.session.post(url, data=data, headers=headers) try: assert "感谢注册" in resp.text self.report("Reg success!") DarkNet_User.create(**{"user": self.usr, "pwd": self.pwd}) except AssertionError: self.error(jq(resp.text).text()) self.SaveError("reg.html", resp)