Exemple #1
0
def import_shared_secret(mafile, notest=False):  # mafile
    mafile = json.loads(mafile)
    Sid = str(mafile["Session"]["SteamID"])
    acc = get_account_list(False, True)
    if (Sid not in acc):
        return "acc_not_found"

    user_conf = acc[Sid]

    if (notest == False):
        try:
            user_login = wa.MobileWebAuth(user_conf["name"])
            sa = guard.SteamAuthenticator(mafile)
            code = sa.get_code()
            user_login.login(user_conf["password"], twofactor_code=code)
        except:
            return "login_error"

    user_path = path + "user_config/" + user_conf["name"] + ".json"
    with open(user_path, "r") as file:
        user_conf = json.load(file)

    user_conf["guard"] = mafile

    with open(user_path, "w") as file:
        json.dump(user_conf, file)
    return True
Exemple #2
0
def test_login(Sid, get_API=False):
    try:
        conf = user_conf(Sid)
        sa = wa.MobileWebAuth(conf["name"])
        se = sa.oauth_login(conf["oauth"], str(conf["steam_id"]), "tchinese")
    except:
        return "account"
    if (get_API):
        try:
            req = se.get("https://steamcommunity.com/dev/apikey")
            regex = r"(?<=<p>序號:\ ).{32}(?=<\/p>)"
            matches = re.search(regex, req.text)
            if matches:  #無API
                return matches.group()
            raise Warning("")
        except Warning:  #
            se.post(
                "https://steamcommunity.com/dev/registerkey", {
                    "domain": "generate.by.BSteam",
                    "agreeToTerms": "agreed",
                    "sessionid": sa.session_id
                })
            req = se.get("https://steamcommunity.com/dev/apikey")
            regex = r"(?<=<p>序號:\ ).{32}(?=<\/p>)"
            matches = re.search(regex, req.text)
            if matches:  #無API
                return matches.group()
            return "api_error"
    return sa.session_id
Exemple #3
0
 def __init__(self, name: str, oauth: str, steamid: str) -> None:  #創建驗證器
     self.name = name
     self.oauth = oauth
     self.steamid = steamid
     self.wa = wa.MobileWebAuth(name)
     try:
         self.wa.oauth_login(oauth, steamid)
     except:
         return print("oauth_error")
     self.sa = guard.SteamAuthenticator(backend=self.wa)
Exemple #4
0
 def remove_guard(self, twofactor, activeSecrets):
     #Query username and password
     self.exec_query(
         "SELECT steamuser, steampass FROM Secrets WHERE isactive ='1'")
     username, password = self.response[0][0], self.response[0][1]
     #Login like a mobile phone
     medium = wa.MobileWebAuth(username, password)
     medium.login(twofactor_code=twofactor)
     sa = SteamAuthenticator(secrets=activeSecrets, medium=medium)
     #Remove Steam Guard from the account and from the database
     sa.remove()
     self.exec_query("DELETE FROM Secrets WHERE isactive = '1'")
 def __init__(self, username, password, secrets=None, deviceId=None):
     self.user = wa.WebAuth(username, password)
     if secrets is not None:
         self.mobile = wa.MobileWebAuth(username, password)
         self.sa = SteamAuthenticator(secrets)
     else:
         self.mobile = None
         self.sa = None
     self.deviceId = deviceId
     self.login()
     self.baseURL = 'https://steamcommunity.com'
     self.urlToId = {}
     self.SIDDB = requests.Session()
     print(f'Steam User: {self.user.steam_id.as_64} Logged.')
def get_mobilewebauth(sa=None, force_login=True):
    if sa and isinstance(sa.backend, webauth.MobileWebAuth) and sa.backend.logged_on:
        return sa.backend
    endfunc = Empty()
    endfunc.endfunc = False
    login_dialog = QtWidgets.QDialog()
    login_ui = PyUIs.LogInDialog.Ui_Dialog()
    login_ui.setupUi(login_dialog)
    login_ui.buttonBox.rejected.connect(lambda: setattr(endfunc, 'endfunc', True))
    login_ui.usernameBox.setDisabled((force_login and (sa is not None)))
    if sa:
        login_ui.usernameBox.setText(sa.secrets['account_name'])
    # noinspection PyUnusedLocal
    required = None
    while True:
        login_dialog.exec_()
        if endfunc.endfunc:
            return
        user = webauth.MobileWebAuth(username=login_ui.usernameBox.text(), password=login_ui.passwordBox.text())
        username = login_ui.usernameBox.text()
        try:
            user.login()
        except webauth.HTTPError:
            Common.error_popup('Connection Error')
            return
        except KeyError:
            login_ui.msgBox.setText('Username and password required.')
        except webauth.LoginIncorrect as e:
            if 'is incorrect' in str(e):
                login_ui.msgBox.setText('Incorrect username and/or password.')
            else:
                login_ui.msgBox.setText('Incorrect username and/or password,\n or too many attempts.')
        except webauth.CaptchaRequired:
            required = 'captcha'
            break
        except webauth.EmailCodeRequired:
            required = 'email'
            break
        except webauth.TwoFactorCodeRequired:
            required = '2FA'
            break
    captcha = ''
    twofactor_code = ''
    email_code = ''
    while True:
        if required == 'captcha':
            captcha_dialog = QtWidgets.QDialog()
            captcha_ui = PyUIs.CaptchaDialog.Ui_Dialog()
            captcha_ui.setupUi(captcha_dialog)
            captcha_ui.buttonBox.rejected.connect(lambda: setattr(endfunc, 'endfunc', True))
            pixmap = QtGui.QPixmap()
            pixmap.loadFromData(requests.get(user.captcha_url).text)
            captcha_ui.captchaLabel.setPixmap(pixmap)
            while True:
                captcha_dialog.exec_()
                if endfunc.endfunc:
                    return
                captcha = captcha_ui.captchaInputBox.text()
                try:
                    user.login(captcha=captcha, email_code=email_code, twofactor_code=twofactor_code)
                    break
                except webauth.CaptchaRequired:
                    captcha_ui.label_3.setText('Incorrect')
                except webauth.LoginIncorrect as e:
                    captcha_ui.label_3.setText(str(e))
                except webauth.EmailCodeRequired:
                    required = 'email'
                    break
                except webauth.TwoFactorCodeRequired:
                    required = '2FA'
                    break
        elif required == 'email':
            code_dialog = QtWidgets.QDialog()
            code_ui = PyUIs.PhoneDialog.Ui_Dialog()
            code_ui.setupUi(code_dialog)
            code_ui.buttonBox.rejected.connect(lambda: setattr(endfunc, 'endfunc', True))
            code_dialog.setWindowTitle('Email code')
            code_ui.actionBox.setText('Enter the email code you have received:')
            while True:
                code_dialog.exec_()
                if endfunc.endfunc:
                    return
                email_code = code_ui.codeBox.text()
                try:
                    user.login(email_code=email_code, captcha=captcha)
                    break
                except webauth.EmailCodeRequired:
                    code_ui.msgBox.setText('Invalid code')
                except webauth.LoginIncorrect as e:
                    code_ui.msgBox.setText(str(e))
                except webauth.CaptchaRequired:
                    required = 'captcha'
                    break
        elif required == '2FA':
            code_dialog = QtWidgets.QDialog()
            code_ui = PyUIs.PhoneDialog.Ui_Dialog()
            code_ui.setupUi(code_dialog)
            code_ui.buttonBox.rejected.connect(lambda: setattr(endfunc, 'endfunc', True))
            code_dialog.setWindowTitle('2FA code')
            code_ui.actionBox.setText('Enter a two-factor code for Steam:')
            while True:
                if sa and username == sa.secrets['account_name']:
                    twofactor_code = sa.get_code()
                else:
                    code_dialog.exec_()
                    if endfunc.endfunc:
                        return
                    twofactor_code = code_ui.codeBox.text()
                try:
                    user.login(twofactor_code=twofactor_code, captcha=captcha)
                    break
                except webauth.TwoFactorCodeRequired:
                    code_ui.msgBox.setText('Invalid Code')
                except webauth.LoginIncorrect as e:
                    code_ui.msgBox.setText(str(e))
                except webauth.CaptchaRequired:
                    required = 'captcha'
                    break
        if user.logged_on:
            break
    if sa:
        sa.backend = user
    return user
Exemple #7
0
 def _steamAuth(self,
                account=None,
                password=None,
                steamID=None,
                auth_token=None,
                steamguard_token=None):
     """
 Aliased internal function for steam auth. If used with plain username and password
 returns dict with a status request for 2FA when required. Use <>.postSteam2FA() after
 Possible statuses:
 0 - No 2FA required - Plain login, you can now use session
 1 - Captcha required - Post the captcha code
 2 - Email code required - Post the code received on the email
 3 - Steamguard 2FA required - Post the 2FA code from steamguard
 """
     if account and password:
         if not 'sessionid' in self.session.cookies.get_dict():
             self.steamUser = wa.MobileWebAuth(account, password)
             try:
                 self.steamUser.login()
                 self.session.cookies.update(self.steamUser.session.cookies)
                 self._steamSiteLogin()
                 return {
                     "status": 0,
                     "message": "No 2FA required. Check user session"
                 }
             except wa.CaptchaRequired:
                 self.twofaType = "captcha"
                 return {
                     "status": 1,
                     "message": "Captcha Required",
                     "url": self.steamUser.captcha_url
                 }  # User must .postSteam2FA(code)
             except wa.EmailCodeRequired:
                 self.twofaType = "email"
                 return {
                     "status": 2,
                     "message": "Email code Required"
                 }  # User must .postSteam2FA(code)
             except wa.TwoFactorCodeRequired:
                 self.twofaType = "steamguard"
                 return {
                     "status": 3,
                     "message": "Steamguard 2FA Required"
                 }  # User must .postSteam2FA(code)
     elif steamID and auth_token and steamguard_token:
         steamid = sid.SteamID(steamID)
         try:
             response = self.session.post(
                 'https://api.steampowered.com/IMobileAuthService/GetWGToken/v1/',
                 data={
                     'access_token': auth_token
                 }).json()['response']
         except:
             return self._steamSiteLogin()
         if not 'token' in response or not 'token_secure' in response:
             return False
         cookies = {
             'steamLogin': f"{steamid}||{response['token']}",
             'steamLoginSecure': f"{steamid}||{response['token_secure']}",
             f'steamMachineAuth{steamid}': steamguard_token,
             'sessionid': sweb.generate_session_id()
         }
         jar = requests.cookies.RequestsCookieJar()
         for cookie in cookies:
             jar.set(cookie,
                     cookies[cookie],
                     domain='steamcommunity.com',
                     path='/')
         self.session.cookies.update(jar)
         return self._steamSiteLogin()
     else:
         raise MissingSteamLoginData
def steam_login():
    # Steam login process by sumfun4WF & Harmdhast
    if 'steam' in CREDS:
        # Relog using saved tokens
        if 'auth_token' in CREDS["steam"] and 'steamguard_token' in CREDS[
                "steam"]:
            authcookies = steam_oAuthLogin(CREDS['steam']['steamguard_token'],
                                           CREDS['steam']['auth_token'])
            s.cookies.update(authcookies)

    if not 'sessionid' in s.cookies.get_dict():
        user = wa.MobileWebAuth(
            email.get(), password.get())  #MobileAuth should keep session alive
        try:
            user.login()
        except wa.CaptchaRequired:
            captcha_code = simpledialog.askstring("Captcha Code",
                                                  "{}".format(
                                                      user.captcha_url),
                                                  parent=login_window)
            user.login(captcha=captcha_code)
        except wa.EmailCodeRequired:
            email_code = simpledialog.askstring("Email Code",
                                                "CODE",
                                                parent=login_window)
            user.login(email_code=email_code)
        except wa.TwoFactorCodeRequired:
            tfa_code = simpledialog.askstring("2 Factor",
                                              "CODE",
                                              parent=login_window)
            user.login(twofactor_code=tfa_code)
        # Save auth token for later session restore
        with open('creds.json', 'w') as json_file:
            CREDS['steam']['auth_token'] = user.oauth_token
            CREDS['steam']['steamguard_token'] = "{id}||{token}".format(
                id=user.steam_id.as_64,
                token=user.session.cookies.get_dict()[
                    "steamMachineAuth{id}".format(id=user.steam_id.as_64)])
            json.dump(CREDS, json_file, indent=4, sort_keys=True)
        # Copy cookies to session
        s.cookies.update(user.session.cookies)

    while True:
        try:
            entrance = s.get(
                'https://auth-ac.my.com/social/steam?continue=https://account.my.com/social_back/?continue=https://wf.my.com/en/&failure=https://account.my.com/social_back/?soc_error=1&continue=https://wf.my.com/en/'
            )
            openid_login = {}
            html = StringIO(entrance.content.decode())
            tree = lxml.html.parse(html)
            root = tree.getroot()
            for form in root.xpath('//form[@name="loginForm"]'):
                for field in form.getchildren():
                    if 'name' in field.keys():
                        openid_login[field.get('name')] = field.get('value')
            s.headers.update({'referer': entrance.url})
            steam_redir = s.post('https://steamcommunity.com/openid/login',
                                 data=openid_login)
            s.get('https://auth-ac.my.com/sdc?from=https%3A%2F%2Fwf.my.com')
            get_token = s.get('https://wf.my.com/minigames/user/info').json()
            s.cookies['mg_token'] = get_token['data']['token']
            s.cookies['cur_language'] = op_lang()
        except:
            continue
        break
    main_app()
Exemple #9
0
def create_account(lvl, data):  # 引入帳號
    if (lvl == "login"):
        global create_acc, acc_setting

        create_acc = wa.MobileWebAuth(data["username"], data["password"])

        try:
            if ("2FA" in data):
                create_acc.login(twofactor_code=data["2FA"])
            else:
                create_acc.login()
        except wa.LoginIncorrect:
            next = 'accpwd'
        except wa.HTTPError:
            next = 'HTTPError'
        except wa.CaptchaRequired:
            next = 'Captcha'
        except wa.EmailCodeRequired:
            next = 'email'
        except wa.TwoFactorCodeRequired:
            next = '2FA'
        except:
            next = sys.exc_info()[0]
        else:
            next = True

        print("try login")
    elif (lvl == "Captcha"):
        try:
            create_acc.login(email_code=data["Captcha"])
        except wa.CaptchaRequired:  # 代碼錯誤
            next = "Captcha"
        except wa.EmailCodeRequired:
            next = 'email'
        except wa.TwoFactorCodeRequired:
            next = '2FA'
        else:
            next = True
    elif (lvl == "email"):
        try:
            create_acc.login(email_code=data["email"])
        except wa.EmailCodeRequired:  # 代碼錯誤
            next = False
        else:
            next = True
    elif (lvl == "2FA"):
        try:
            create_acc.login(twofactor_code=data["2FA"])
        except wa.TwoFactorCodeRequired:  # 代碼錯誤
            next = False
        else:
            next = True

    if (next == True):  # 保存資料
        try:
            with open(path + "user_config/" + data["username"] + ".json",
                      'r') as fcfg:
                org = json.load(fcfg)
        except:
            org = {}

        with open(path + "user_config/" + data["username"] + ".json",
                  "w+") as fcfg:
            user_data = {
                "name": data["username"],
                "password": data["password"],
                "oauth": create_acc.oauth_token,
                "steam_id": create_acc.steam_id,
                "account_id": Sid.SteamID(create_acc.steam_id).id,
                "session_id": create_acc.session_id
            }
            json.dump({**org, **user_data}, fcfg)
            print("create user config [\"" + data["username"] + "\"]")

    return next