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
| from time import sleep import json import requests import logging import ddddocr import re
ocr = ddddocr.DdddOcr()
LOG_FORMAT = '%(asctime)s %(levelname)s\t %(thread)d %(lineno)d %(funcName)s\t\t%(message)s'
logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)
headers = { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36', 'X-Requested-With': 'XMLHttpRequest' }
class bugku(): def __init__(self) -> None: self.session = requests.session() self.session.headers.update(headers) self.num = 10 self.is_login = False
def dingtalk(self, content): """ Send a notification to the DingTalk webhook
Parameters: content (str): The content of the notification
Returns: None """ webhook_url = '' dd_headers = { "Content-Type": "application/json", "Charset": "UTF-8" } dd_message = { "msgtype": "text", "text": { "content": f'BugKu 签到通知\n{content}' } }
r = self.session.post(url=webhook_url, headers=dd_headers, data=json.dumps(dd_message)) def get_captcha(self): if self.num <= 0: logging.warning('验证码重试次数太多') exit(0) url = 'https://ctf.bugku.com/captcha.html0.9004209313422487' res = self.session.get(url) if res.status_code == 200: code = ocr.classification(res.content) c = ''.join(re.findall('\w', code)) if len(c) == 4: logging.info('验证码成功:' + c) return c else: sleep(3) self.num -= 1 self.get_captcha() else: sleep(3) self.num -= 1 self.get_captcha()
def login(self, username, password): if self.num <= 0: logging.warning('登录重试次数太多') exit(0) login_url = 'https://ctf.bugku.com/login/check.html' code = self.get_captcha() data = {'username': username, 'password': password, 'vcode': code, 'autologin': '1'} res = self.session.post(url=login_url, data=data, headers=headers)
if '登录成功' in res.text: logging.info(f'{username} 登录成功:{res.text}') self.is_login = True else: logging.error('登录失败:' + res.text) sleep(3) self.num -= 1 self.login(username, password)
def checkin(self, username, password): if self.is_login: response = self.session.get('https://ctf.bugku.com/user/checkin') print(response.text) if '成功' in response.text: logging.info('签到成功:' + response.text) else: logging.error('失败')
else: self.login(username, password) response = self.session.get('https://ctf.bugku.com/user/checkin') print(response.text) bg = bugku() bg.dingtalk(response.text) if '成功' in response.text: logging.info('签到成功:' + response.text)
else: logging.error('失败')
if __name__ == '__main__': _bk = bugku() _bk.checkin('', '')
|