# Copyright 2022 USTC-Hackergame# Copyright 2021 PKU-GeekGamefromseleniumimportwebdriverimportseleniumimportsysimporttimeimporturllib.parseimportos# secret.py will NOT be revealed to playersfromsecretimportFLAG,BOT_SECRETLOGIN_URL=f'http://web/?bot={BOT_SECRET}'print('Please submit your quiz URL:')url=input('> ')# URL replacement# In our environment bot access http://web# If you need to test it yourself locally you should adjust LOGIN_URL and remove the URL replacement source code# and write your own logic to use your own token to "login" with headless browserparsed=urllib.parse.urlparse(url)parsed=parsed._replace(netloc="web",scheme="http")url=urllib.parse.urlunparse(parsed)print(f"Your URL converted to {url}")try:options=webdriver.ChromeOptions()options.add_argument('--no-sandbox')# sandbox not working in dockeroptions.add_argument('--headless')options.add_argument('--disable-gpu')options.add_argument('--user-data-dir=/dev/shm/user-data')os.environ['TMPDIR']="/dev/shm/"options.add_experimental_option('excludeSwitches',['enable-logging'])withwebdriver.Chrome(options=options)asdriver:ua=driver.execute_script('return navigator.userAgent')print(' I am using',ua)print('- Logining...')driver.get(LOGIN_URL)time.sleep(4)print(' Putting secret flag...')driver.execute_script(f'document.cookie="flag={FLAG}"')time.sleep(1)print('- Now browsing your quiz result...')driver.get(url)time.sleep(4)try:greeting=driver.execute_script(f"return document.querySelector('#greeting').textContent")score=driver.execute_script(f"return document.querySelector('#score').textContent")exceptselenium.common.exceptions.JavascriptException:print('JavaScript Error: Did you give me correct URL?')exit(1)print("OK. Now I know that:")print(greeting)print(score)print('- Thank you for joining my quiz!')exceptExceptionase:print('ERROR',type(e))importtracebacktraceback.print_exception(*sys.exc_info(),limit=0,file=None,chain=False)