Beispiel #1
0
 def update_guard(self):
     #Update active guard secrets, Steam name and reset our progress bar
     self.activeSecrets = json.loads(self.conn.get_active_secrets())
     self.apiKey = self.conn.get_api_key()
     self.apiController = api(self.apiKey)
     self.steamGuardController = SteamAuthenticator(
         secrets=self.activeSecrets, medium=self.client)
     self.steamName = self.activeSecrets["account_name"]
     self.steamNameLabel.configure(text=self.steamName)
     if self.progressBar["value"] <= 18:
         self.barStyle.configure(
             "blue.Horizontal.TProgressbar",
             troughcolor=self.colorDic["progressBarBackground"],
             background=self.colorDic["progressBarForeground"])
         self.guardLabel.configure(fg=self.colorDic["guardCodeForeground"],
                                   bg=self.colorDic["guardCodeBackground"])
         self.steamNameLabel.config(fg=self.colorDic["steamNameForeground"],
                                    bg=self.colorDic["guardCodeBackground"])
         self.guardCodeHolder.config(
             bg=self.colorDic["guardCodeBackground"])
     #Cancel wait for updating progress bar. This way we don't call the same function twice doubling our speed.
     if self.updateProgressBarID:
         self.parent.after_cancel(self.updateProgressBarID)
         self.progressBar["value"] = 0
     self.update_progress_bar()
Beispiel #2
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.')
Beispiel #4
0
def cmd_authenticator_status(args):
    account = args.account.lower().strip()
    secrets_file = UserDataFile('authenticator/{}.json'.format(account))
    sa = None

    wa = BetterMWA(account)

    if secrets_file.exists():
        sa = SteamAuthenticator(secrets_file.read_json(), backend=wa)

    try:
        wa.bcli_login(sa_instance=sa)
    except (KeyboardInterrupt, EOFError):
        print("Login interrupted")
        return 1  # error

    if sa is None:
        sa = SteamAuthenticator(backend=wa)

    status = sa.status()

    print("----- Status ------------")
    mode = status['steamguard_scheme']

    if mode == 0:
        print("Steam Guard mode: disabled/insecure")
    elif mode == 1:
        print("Steam Guard mode: enabled (email)")
    elif mode == 2:
        print("Steam Guard mode: enabled (authenticator)")
    else:
        print("Steam Guard mode: unknown ({})".format(mode))

    print("Authenticator enabled:", "Yes" if status['state'] == 1 else "No")
    print("Authenticator allowed:", "Yes" if status['state'] else "No")
    print("Email verified:", "Yes" if status['email_validated'] else "No")
    print("External allowed:",
          "Yes" if status['allow_external_authenticator'] else "No")

    if status['state'] == 1:
        print("----- Token details -----")
        print("Token GID:", status['token_gid'])
        print("Created at:", fmt_datetime(status['time_created']))
        print("Device identifier:", status['device_identifier'])
        print("Classified agent:", status['classified_agent'])
        print("Revocation attempts remaining:",
              status['revocation_attempts_remaining'])
Beispiel #5
0
def cmd_authenticator_remove(args):
    account = args.account.lower().strip()
    secrets_file = UserDataFile('authenticator/{}.json'.format(account))
    secrets = secrets_file.read_json()

    if not secrets:
        print("No authenticator found for %r" % account)
        return 1  #error

    if args.force:
        secrets_file.remove()
        print("Forceful removal of %r successful" % account)
        return

    print("To remove an authenticator, first we need to login to Steam")
    print("Account name:", account)

    wa = BetterMWA(account)
    sa = SteamAuthenticator(secrets, backend=wa)

    try:
        wa.bcli_login(sa_instance=sa)
    except (KeyboardInterrupt, EOFError):
        print("Login interrupted")
        return 1  # error

    print("Login successful.")
    print("Steam Guard will be set to email, after removal.")

    while True:
        if not pmt_confirmation("Proceed with removing Steam Authenticator?"):
            break
        else:
            try:
                sa.remove()
            except SteamAuthenticatorError as exp:
                print("Removal error: %s" % exp)
                continue
            except (EOFError, KeyboardInterrupt):
                break
            else:
                secrets_file.remove()
                print("Removal successful!")
                return

    print("Removal cancelled.")
Beispiel #6
0
def cmd_authenticator_code(args):
    account = args.account.lower().strip()
    secrets = UserDataFile('authenticator/{}.json'.format(account)).read_json()

    if not secrets:
        print("No authenticator for %r" % account)
        return 1  # error

    print(SteamAuthenticator(secrets).get_code())
Beispiel #7
0
class mainWindow(Frame):
    #Initialize
    def __init__(self, parent, colorDic):
        #Declare class variables
        self.activeSecrets = None
        self.client = SteamClient()
        self.colorDic = colorDic
        self.conn = dataBase()
        self.apiKey = self.conn.get_api_key()
        self.apiController = api(self.apiKey)
        self.parent = parent
        self.guiControl = guiController(self.parent, self.colorDic)
        self.steamGuardController = None
        self.steamName = ""
        self.updateProgressBarID = None
        #Initialize window's frame
        Frame.__init__(self, self.parent)
        #Everything below is created in order from top of application to the bottom
        #Menu bar
        self.menuBar = Menu(self.parent, border=0)
        self.menuBar.config(bg=self.colorDic["menuBarBackground"],
                            fg=self.colorDic["menuBarForeground"])
        self.accountMenu = Menu(self.menuBar, tearoff=0)
        #New account and Import account button
        self.accountMenu.add_command(label="New Steam Guard",
                                     command=self.new_account_window)
        self.accountMenu.add_command(label="Delete Steam Guard",
                                     command=self.delete_steam_guard)
        #Seperator makes it look fabulous
        self.accountMenu.add_separator()
        self.accountMenu.add_command(label="Import Steam Guard")
        self.menuBar.add_cascade(label="Guard", menu=self.accountMenu)
        self.accountMenu.config(bg=self.colorDic["menuBarBackground"],
                                fg=self.colorDic["menuBarForeground"])
        self.editMenu = Menu(self.menuBar, tearoff=0)
        #Security preferences and color scheme button
        self.editMenu.add_command(label="Security Preferences")
        self.editMenu.add_command(label="Color Scheme")
        self.menuBar.add_cascade(label="Edit", menu=self.editMenu)
        self.editMenu.config(bg=self.colorDic["menuBarBackground"],
                             fg=self.colorDic["menuBarForeground"])
        #Window Title
        self.windowTitle = Label(self.parent, text="Steam Guard")
        self.windowTitle.configure(font=("Segoe UI", 12),
                                   bg=self.colorDic["windowTitleBackground"],
                                   fg=self.colorDic["windowTitleForeground"],
                                   width="350",
                                   pady=10)
        self.windowTitle.pack()
        #Guard codes and Steam name frame
        self.guardCodeHolder = Frame(self.parent,
                                     bg=self.colorDic["guardCodeBackground"])
        self.guardCodeHolder.pack()
        #Generated Steam Guard text
        self.guardLabel = Label(self.guardCodeHolder, text="...")
        self.guardLabel.configure(font=("Segoe UI", 30),
                                  bg=self.colorDic["guardCodeBackground"],
                                  fg=self.colorDic["guardCodeForeground"],
                                  width="350",
                                  pady=15)
        self.guardLabel.pack()
        #Styling for progress bar
        self.barStyle = ttk.Style()
        self.barStyle.theme_use('alt')
        self.barStyle.configure(
            "blue.Horizontal.TProgressbar",
            troughrelief="flat",
            troughcolor=self.colorDic["progressBarBackground"],
            background=self.colorDic["progressBarForeground"],
            relief="flat")
        #Progress bar
        self.progressBar = ttk.Progressbar(
            self.guardCodeHolder,
            style="blue.Horizontal.TProgressbar",
            orient="horizontal",
            length=250,
            mode="determinate")
        self.progressBar.pack()
        self.progressBar["maximum"] = 58
        #Steam name text
        self.steamNameLabel = Label(self.guardCodeHolder, text=self.steamName)
        self.steamNameLabel.configure(font=("Segoe UI", 10),
                                      bg=self.colorDic["guardCodeBackground"],
                                      fg=self.colorDic["steamNameForeground"],
                                      width="350",
                                      pady=5)
        self.steamNameLabel.pack()
        #Special buttons frame
        self.specialButtonsHolder = Frame(
            self.parent, bg=self.colorDic["specialButtonBackground"])
        self.specialButtonsHolder.pack(side="top", expand=True, fill="y")
        self.specialButtonsBackground = Frame(self.specialButtonsHolder,
                                              bg=self.colorDic["hrColor"],
                                              width="350",
                                              height="241")
        self.specialButtonsBackground.pack()
        self.specialButtonsBackground.pack_propagate(0)
        #"Confirmations" button frame
        self.confirmationHolder = Frame(
            self.specialButtonsBackground,
            bg=self.colorDic["specialButtonBackground"],
            width="350",
            height="79",
            cursor="hand2")
        self.confirmationHolder.pack(pady="1")
        self.confirmationLabel = Label(
            self.confirmationHolder,
            text="Confirmations",
            font=("Segoe UI", 15),
            bg=self.colorDic["specialButtonBackground"],
            fg=self.colorDic["specialButtonForeground"],
            cursor="hand2")
        self.confirmationLabel.pack(side="left", pady="15", padx="20")
        self.confirmationHolder.pack_propagate(0)
        self.confirmationHolder.bind("<Enter>",
                                     self.guiControl.special_button_hover)
        self.confirmationHolder.bind("<Leave>",
                                     self.guiControl.special_button_leave)
        self.confirmationHolder.bind("<Button-1>", self.confirmations_window)
        self.confirmationLabel.bind("<Button-1>", self.confirmations_window)
        #"Revocation" button frame
        self.revocationCodeHolder = Frame(
            self.specialButtonsBackground,
            bg=self.colorDic["specialButtonBackground"],
            width="350",
            height="79",
            cursor="hand2")
        self.revocationCodeLabel = Label(
            self.revocationCodeHolder,
            text="Revocation Code",
            font=("Segoe UI", 15),
            bg=self.colorDic["specialButtonBackground"],
            fg=self.colorDic["specialButtonForeground"],
            cursor="hand2")
        self.revocationCodeLabel.pack(side="left", pady="15", padx="20")
        self.revocationCodeHolder.pack()
        self.revocationCodeHolder.pack_propagate(0)
        self.revocationCodeHolder.bind("<Enter>",
                                       self.guiControl.special_button_hover)
        self.revocationCodeHolder.bind("<Leave>",
                                       self.guiControl.special_button_leave)
        self.revocationCodeHolder.bind("<Button-1>",
                                       self.revocation_code_window)
        self.revocationCodeLabel.bind("<Button-1>",
                                      self.revocation_code_window)
        #"Switch Account" button frame
        self.switchAccountHolder = Frame(
            self.specialButtonsBackground,
            bg=self.colorDic["specialButtonBackground"],
            width="350",
            height="79",
            cursor="hand2")
        self.switchAccountLabel = Label(
            self.switchAccountHolder,
            text="Switch Accounts",
            font=("Segoe UI", 15),
            bg=self.colorDic["specialButtonBackground"],
            fg=self.colorDic["specialButtonForeground"],
            cursor="hand2")
        self.switchAccountLabel.pack(side="left", pady="15", padx="20")
        self.switchAccountHolder.pack(pady="1")
        self.switchAccountHolder.pack_propagate(0)
        self.switchAccountHolder.bind("<Enter>",
                                      self.guiControl.special_button_hover)
        self.switchAccountHolder.bind("<Leave>",
                                      self.guiControl.special_button_leave)
        self.switchAccountHolder.bind("<Button-1>", self.switch_account_window)
        self.switchAccountLabel.bind("<Button-1>", self.switch_account_window)
        #Copy button frame
        self.buttonHolder = Frame(self.parent,
                                  bg=self.colorDic["appBackground"])
        self.copyCodeButton = Button(
            self.buttonHolder,
            text="Copy Code",
            command=lambda: self.guiControl.copy_label_text(self.guardLabel),
            font=("Segoe UI", 12),
            relief="flat",
            cursor="hand2")
        self.copyCodeButton.configure(
            fg=self.colorDic["actionButtonForeground"],
            bg=self.colorDic["actionButtonBackground"])
        self.copyCodeButton.pack(padx=30, pady=20, ipady=10, ipadx=10)
        self.buttonHolder.pack(side="bottom")
        #Set our window properties
        self.parent.geometry("350x500")
        self.parent.resizable(0, 0)
        self.parent.configure(bg=self.colorDic["appBackground"])
        self.parent.title("Steam Guardian")
        self.parent.config(menu=self.menuBar)
        self.guiControl.center()

        if self.conn.has_active_user():
            self.update_guard()

    #API key window method
    def api_key_window(self):
        #Start API key window
        self.clientLogin = apiKeyWindow(self.parent, self.colorDic, self.conn,
                                        self)
        self.clientLogin.geometry("500x300")
        self.clientLogin.resizable(0, 0)
        self.clientLogin.configure(bg=self.colorDic["appBackground"])
        self.clientLogin.title("Steam Guardian - Api Key")
        guiController(self.clientLogin).center()

    #Check for active account method
    def check_active_secrets(self):
        if self.activeSecrets:
            return True
        else:
            self.show_message(
                None, "error",
                "No active account! This is required to do this action.\nGo to 'Guard -> New Steam Guard' to add one."
            )

    #Check for active api key
    def check_active_api(self):
        if self.check_active_secrets():
            if self.apiKey:
                if self.apiController.check_api_key():
                    return True
                else:
                    self.show_message(
                        None, "error",
                        "API key is invalid! Taking you to the\nAPI window to update your key."
                    )
                    self.api_key_window()
            else:
                self.show_message(
                    None, "error",
                    "No API key is set! This is required to do this action.\nTaking you to the API window to add a key."
                )
                self.api_key_window()

    #Confirmations window method
    def confirmations_window(self, event):
        if self.check_active_api():
            #Everything's good, get our confirmations
            print("Feature not yet added!")

    #Delete Steam Guard method
    def delete_steam_guard(self):
        #If active secrets set
        if self.check_active_secrets():
            #Ask user if it's okay to remove Steam Guard
            userApproves = self.show_message(
                None, "warning",
                "This will remove steam guard from your {} account.\nYou cannot undo this action, would yo like to continue?"
                .format(self.steamName), True)
            #If user approves
            if userApproves:
                self.conn.remove_guard(self.guardLabel["text"],
                                       self.activeSecrets)
                #Reset Steam Guard in GUI
                self.steamName = ''
                self.activeSecrets = None
                self.steamGuardController = None
                self.guardLabel.config({"text": "..."})
                self.progressBar["value"] = 0
                self.steamName = ''
                self.steamNameLabel.configure(text=self.steamName)
                self.barStyle.configure(
                    "blue.Horizontal.TProgressbar",
                    troughcolor=self.colorDic["progressBarBackground"],
                    background=self.colorDic["progressBarForeground"])
                self.guardLabel.configure(
                    fg=self.colorDic["guardCodeForeground"],
                    bg=self.colorDic["guardCodeBackground"])
                self.steamNameLabel.config(
                    fg=self.colorDic["steamNameForeground"],
                    bg=self.colorDic["guardCodeBackground"])
                self.guardCodeHolder.config(
                    bg=self.colorDic["guardCodeBackground"])
                #Tell user we're done
                self.show_message(
                    None, "success",
                    "Steam Guard has been successfully removed.")
        else:
            #No active secrets set
            self.show_message(None, "error", "No account to delete!")

    #New account window method
    def new_account_window(self):
        #Start login window
        self.clientLogin = clientLoginWindow(self.parent, self.colorDic,
                                             self.conn, self)
        self.clientLogin.geometry("500x350")
        self.clientLogin.resizable(0, 0)
        self.clientLogin.configure(bg=self.colorDic["appBackground"])
        self.clientLogin.title("Steam Guardian - New Account")
        guiController(self.clientLogin).center()

    #Revocation code window method
    def revocation_code_window(self, event):
        if self.check_active_secrets():
            #Start revocation code window
            self.revocationCode = revocationCodeWindow(self.parent,
                                                       self.colorDic, self)
            self.revocationCode.geometry("350x300")
            self.revocationCode.resizable(0, 0)
            self.revocationCode.configure(bg=self.colorDic["appBackground"])
            self.revocationCode.title("Steam Guardian - Revocation Code")
            guiController(self.revocationCode).center()

    #Message window method
    def show_message(self, event, messageType, text, yesNo=False):
        #Start message window
        self.messageWindow = showMessage(self.parent, self.colorDic,
                                         messageType, text, yesNo)
        self.messageWindow.title("Steam Guardian - {}".format(messageType))
        guiController(self.messageWindow).center()
        self.messageWindow.wait_window()
        return self.messageWindow.response

    #Switch account window method
    def switch_account_window(self, event):
        #If there's more than 1 user to select
        if self.conn.count_users() > 1:
            #Start switch account window
            self.switchGui = clientSwitchWindow(self.parent, self.colorDic,
                                                self.conn, self)
            self.switchGui.geometry("400x450")
            self.switchGui.resizable(0, 0)
            self.switchGui.configure(bg=self.colorDic["appBackground"])
            self.switchGui.title("Steam Guardian - Accounts")
            guiController(self.switchGui).center()
        else:
            #If no accounts were found to switch to show an error
            self.rootClassRef.show_message(
                None, "warning",
                "You have no accounts to switch to.\n'Click Account-> New Account' to add a new one."
            )

    #Update secrets and reset progress bar method
    def update_guard(self):
        #Update active guard secrets, Steam name and reset our progress bar
        self.activeSecrets = json.loads(self.conn.get_active_secrets())
        self.apiKey = self.conn.get_api_key()
        self.apiController = api(self.apiKey)
        self.steamGuardController = SteamAuthenticator(
            secrets=self.activeSecrets, medium=self.client)
        self.steamName = self.activeSecrets["account_name"]
        self.steamNameLabel.configure(text=self.steamName)
        if self.progressBar["value"] <= 18:
            self.barStyle.configure(
                "blue.Horizontal.TProgressbar",
                troughcolor=self.colorDic["progressBarBackground"],
                background=self.colorDic["progressBarForeground"])
            self.guardLabel.configure(fg=self.colorDic["guardCodeForeground"],
                                      bg=self.colorDic["guardCodeBackground"])
            self.steamNameLabel.config(fg=self.colorDic["steamNameForeground"],
                                       bg=self.colorDic["guardCodeBackground"])
            self.guardCodeHolder.config(
                bg=self.colorDic["guardCodeBackground"])
        #Cancel wait for updating progress bar. This way we don't call the same function twice doubling our speed.
        if self.updateProgressBarID:
            self.parent.after_cancel(self.updateProgressBarID)
            self.progressBar["value"] = 0
        self.update_progress_bar()

    #Progress bar timer and color changing method
    def update_progress_bar(self):
        #If our Steam guard controller object is set
        if self.steamGuardController:
            #Update progress bar and reset when value is 0. Set background to "warn" color when low on time or under 18
            if self.progressBar["value"] == 0:
                self.guardLabel.config({
                    "text":
                    str(
                        self.steamGuardController.get_code(
                            timestamp=self.steamGuardController.get_time()))
                })
                self.progressBar["value"] = 58
                self.barStyle.configure(
                    "blue.Horizontal.TProgressbar",
                    troughcolor=self.colorDic["progressBarBackground"],
                    background=self.colorDic["progressBarForeground"])
                self.guardLabel.configure(
                    fg=self.colorDic["guardCodeForeground"],
                    bg=self.colorDic["guardCodeBackground"])
                self.steamNameLabel.config(
                    fg=self.colorDic["steamNameForeground"],
                    bg=self.colorDic["guardCodeBackground"])
                self.guardCodeHolder.config(
                    bg=self.colorDic["guardCodeBackground"])
            elif self.progressBar["value"] <= 18:
                self.barStyle.configure(
                    "blue.Horizontal.TProgressbar",
                    troughcolor=self.colorDic["progressBarBackgroundWarn"],
                    background=self.colorDic["progressBarForegroundWarn"])
                self.guardLabel.configure(
                    fg=self.colorDic["guardCodeForeground"],
                    bg=self.colorDic["guardCodeBackgroundWarn"])
                self.steamNameLabel.config(
                    fg=self.colorDic["steamNameForegroundWarn"],
                    bg=self.colorDic["guardCodeBackgroundWarn"])
                self.guardCodeHolder.config(
                    bg=self.colorDic["guardCodeBackgroundWarn"])
            self.progressBar["value"] = self.progressBar["value"] - 1
            self.updateProgressBarID = self.parent.after(
                500, self.update_progress_bar)
Beispiel #8
0
 def login_account(self):
     #Login to steam with provided credentials
     self.userObject = clientData(self.userNameEntry.get(),
                                  self.passwordEntry.get(), None, None)
     self.userObject.login()
     #If password is invalid
     if self.userObject.loginResult == EResult.InvalidPassword:
         #Show error stating password is incorrect
         self.rootClassRef.show_message(
             None, "error", "Your password is incorrect. Please try again.")
     else:
         #If email code is required
         if self.userObject.loginResult in (EResult.AccountLogonDenied,
                                            EResult.InvalidLoginAuthCode):
             self.authWindow = promptFor2FA(self.parent, self.colorDic,
                                            True, self.rootClassRef)
         #If 2FA code is required
         elif self.userObject.loginResult in (
                 EResult.AccountLoginDeniedNeedTwoFactor,
                 EResult.TwoFactorCodeMismatch):
             self.authWindow = promptFor2FA(self.parent, self.colorDic,
                                            False, self.rootClassRef)
         #If email or 2FA code was required
         if self.authWindow:
             #Start 2FA prompt window
             self.authWindow.geometry("400x250")
             self.authWindow.resizable(0, 0)
             self.authWindow.configure(bg=self.colorDic["appBackground"])
             guiController(self.authWindow).center()
             self.authWindow.wait_window()
             #If auth code was set
             if self.authWindow.guardCode:
                 #If auth code was sent to email
                 if self.authWindow.isEmail:
                     self.userObject = clientData(self.userNameEntry.get(),
                                                  self.passwordEntry.get(),
                                                  self.authWindow.guardCode,
                                                  None)
                 else:
                     #If auth code was sent to mobile
                     self.userObject = clientData(self.userNameEntry.get(),
                                                  self.passwordEntry.get(),
                                                  None,
                                                  self.authWindow.guardCode)
                 self.userObject.login()
         #If login and code is correct
         if self.userObject.loginResult == EResult.OK:
             self.steamGuardController = SteamAuthenticator(
                 medium=self.userObject.client)
             if self.steamGuardController.status(
             )['steamguard_scheme'] != 2:
                 #If account has a phone number
                 if self.steamGuardController.has_phone_number():
                     #Add steam guard
                     self.steamGuardController.add()
                     #Start 2FA prompt window to get phone confirmation
                     self.authWindow = promptFor2FA(self.parent,
                                                    self.colorDic, False,
                                                    self.rootClassRef)
                     self.authWindow.geometry("400x250")
                     self.authWindow.resizable(0, 0)
                     self.authWindow.configure(
                         bg=self.colorDic["appBackground"])
                     guiController(self.authWindow).center()
                     self.authWindow.title("Steam Guardian - Mobile")
                     self.authWindow.windowTitle.configure(
                         text="Enter Text Sent to Phone")
                     self.authWindow.wait_window()
                     #If phone code is set
                     if self.authWindow.guardCode:
                         try:
                             self.steamGuardController.finalize(
                                 self.authWindow.guardCode)
                         except:
                             #If phone code is incorrect show an error
                             self.rootClassRef.show_message(
                                 None, "error",
                                 "Couldn't confirm your phone. Code is incorrect!"
                             )
                         else:
                             #Update data and gui
                             self.conn.create_user(
                                 str(
                                     json.dumps(self.steamGuardController.
                                                secrets)),
                                 str(self.userObject.client.user.steam_id),
                                 self.userNameEntry.get(),
                                 self.passwordEntry.get())
                             self.rootClassRef.update_guard()
                     #We destroy our window here because Steam loves to rate limit if you retry too fast
                     self.destroy()
                 else:
                     #If account doesn't have phone number show an error
                     self.rootClassRef.show_message(
                         None, "error",
                         "Your account is missing a phone number to confirm.\nPlease add one and try again!"
                     )
                     webbrowser.open(
                         "https://store.steampowered.com/phone/manage")
             else:
                 #If account already has 2FA (email is fine) show an error
                 self.rootClassRef.show_message(
                     None, "error",
                     "Your account already has Steam Guard Mobile.\nPlease disable it and try again."
                 )
         else:
             #If steam guard code was incorrect.
             self.rootClassRef.show_message(None, "error",
                                            "Login or code was incorrect.")
Beispiel #9
0
class clientLoginWindow(Toplevel):
    #Initialize
    def __init__(self, parent, colorDic, conn, rootClassRef):
        #Declare class variables
        self.authWindow = None
        self.colorDic = colorDic
        self.conn = conn
        self.parent = parent
        self.rootClassRef = rootClassRef
        #Initialize window's frame
        Toplevel.__init__(self)
        #Window title
        self.windowTitle = Label(self, text="New Account")
        self.windowTitle.configure(font=("Segoe UI", 12),
                                   bg=self.colorDic["windowTitleBackground"],
                                   fg=self.colorDic["windowTitleForeground"],
                                   width="350",
                                   pady=10)
        self.windowTitle.pack()
        #Steam logo image
        self.img = ImageTk.PhotoImage(file="images/gui/steam_logo.png")
        self.steamLogo = Label(self,
                               bg=self.colorDic["appBackground"],
                               image=self.img)
        self.steamLogo.pack(anchor="w", padx=35, pady=25)
        #Login item's frame
        self.loginHolder = Frame(self, bg=self.colorDic["appBackground"])
        self.loginHolder.pack(anchor="w", padx=45, pady=25)
        self.labelHolder = Frame(self.loginHolder,
                                 bg=self.colorDic["appBackground"])
        self.labelHolder.pack(side="left")
        self.entryHolder = Frame(self.loginHolder,
                                 bg=self.colorDic["appBackground"])
        self.entryHolder.pack(side="left")
        #Account name and password text
        self.userNameLabel = Label(self.labelHolder,
                                   text="Account Name",
                                   bg=self.colorDic["appBackground"],
                                   fg=self.colorDic["infoLabelForeground"],
                                   font=("Segoe UI", 12))
        self.userNameLabel.pack(padx=5, pady=5, anchor="e")
        self.passwordLabel = Label(self.labelHolder,
                                   text="Password",
                                   bg=self.colorDic["appBackground"],
                                   fg=self.colorDic["infoLabelForeground"],
                                   font=("Segoe UI", 12))
        self.passwordLabel.pack(padx=5, pady=5, anchor="e")
        #Account name and password entry boxes
        self.userNameEntry = Entry(self.entryHolder, width=45)
        self.userNameEntry.pack(padx=5, pady=5)
        self.userNameEntry.focus()
        self.passwordEntry = Entry(self.entryHolder, width=45, show="*")
        self.passwordEntry.pack(padx=5, pady=5)
        #Button holding frame, login button and cancel button
        self.buttonHolder = Frame(self, bg=self.colorDic["appBackground"])
        self.buttonHolder.pack(pady=15)
        self.loginButton = Button(self.buttonHolder,
                                  text="Login to Steam",
                                  font=("Segoe UI", 12),
                                  relief="flat",
                                  cursor="hand2",
                                  command=self.login_account)
        self.loginButton.configure(fg=self.colorDic["actionButtonForeground"],
                                   bg=self.colorDic["actionButtonBackground"])
        self.loginButton.pack(padx=30, ipady=10, ipadx=10, side="left")
        self.cancelButton = Button(self.buttonHolder,
                                   text="Cancel",
                                   font=("Segoe UI", 12),
                                   relief="flat",
                                   cursor="hand2",
                                   command=self.destroy)
        self.cancelButton.configure(fg=self.colorDic["cancelButtonForeground"],
                                    bg=self.colorDic["cancelButtonBackground"])
        self.cancelButton.pack(padx=30, ipady=10, ipadx=10, side="left")

    #Login and add guard method
    def login_account(self):
        #Login to steam with provided credentials
        self.userObject = clientData(self.userNameEntry.get(),
                                     self.passwordEntry.get(), None, None)
        self.userObject.login()
        #If password is invalid
        if self.userObject.loginResult == EResult.InvalidPassword:
            #Show error stating password is incorrect
            self.rootClassRef.show_message(
                None, "error", "Your password is incorrect. Please try again.")
        else:
            #If email code is required
            if self.userObject.loginResult in (EResult.AccountLogonDenied,
                                               EResult.InvalidLoginAuthCode):
                self.authWindow = promptFor2FA(self.parent, self.colorDic,
                                               True, self.rootClassRef)
            #If 2FA code is required
            elif self.userObject.loginResult in (
                    EResult.AccountLoginDeniedNeedTwoFactor,
                    EResult.TwoFactorCodeMismatch):
                self.authWindow = promptFor2FA(self.parent, self.colorDic,
                                               False, self.rootClassRef)
            #If email or 2FA code was required
            if self.authWindow:
                #Start 2FA prompt window
                self.authWindow.geometry("400x250")
                self.authWindow.resizable(0, 0)
                self.authWindow.configure(bg=self.colorDic["appBackground"])
                guiController(self.authWindow).center()
                self.authWindow.wait_window()
                #If auth code was set
                if self.authWindow.guardCode:
                    #If auth code was sent to email
                    if self.authWindow.isEmail:
                        self.userObject = clientData(self.userNameEntry.get(),
                                                     self.passwordEntry.get(),
                                                     self.authWindow.guardCode,
                                                     None)
                    else:
                        #If auth code was sent to mobile
                        self.userObject = clientData(self.userNameEntry.get(),
                                                     self.passwordEntry.get(),
                                                     None,
                                                     self.authWindow.guardCode)
                    self.userObject.login()
            #If login and code is correct
            if self.userObject.loginResult == EResult.OK:
                self.steamGuardController = SteamAuthenticator(
                    medium=self.userObject.client)
                if self.steamGuardController.status(
                )['steamguard_scheme'] != 2:
                    #If account has a phone number
                    if self.steamGuardController.has_phone_number():
                        #Add steam guard
                        self.steamGuardController.add()
                        #Start 2FA prompt window to get phone confirmation
                        self.authWindow = promptFor2FA(self.parent,
                                                       self.colorDic, False,
                                                       self.rootClassRef)
                        self.authWindow.geometry("400x250")
                        self.authWindow.resizable(0, 0)
                        self.authWindow.configure(
                            bg=self.colorDic["appBackground"])
                        guiController(self.authWindow).center()
                        self.authWindow.title("Steam Guardian - Mobile")
                        self.authWindow.windowTitle.configure(
                            text="Enter Text Sent to Phone")
                        self.authWindow.wait_window()
                        #If phone code is set
                        if self.authWindow.guardCode:
                            try:
                                self.steamGuardController.finalize(
                                    self.authWindow.guardCode)
                            except:
                                #If phone code is incorrect show an error
                                self.rootClassRef.show_message(
                                    None, "error",
                                    "Couldn't confirm your phone. Code is incorrect!"
                                )
                            else:
                                #Update data and gui
                                self.conn.create_user(
                                    str(
                                        json.dumps(self.steamGuardController.
                                                   secrets)),
                                    str(self.userObject.client.user.steam_id),
                                    self.userNameEntry.get(),
                                    self.passwordEntry.get())
                                self.rootClassRef.update_guard()
                        #We destroy our window here because Steam loves to rate limit if you retry too fast
                        self.destroy()
                    else:
                        #If account doesn't have phone number show an error
                        self.rootClassRef.show_message(
                            None, "error",
                            "Your account is missing a phone number to confirm.\nPlease add one and try again!"
                        )
                        webbrowser.open(
                            "https://store.steampowered.com/phone/manage")
                else:
                    #If account already has 2FA (email is fine) show an error
                    self.rootClassRef.show_message(
                        None, "error",
                        "Your account already has Steam Guard Mobile.\nPlease disable it and try again."
                    )
            else:
                #If steam guard code was incorrect.
                self.rootClassRef.show_message(None, "error",
                                               "Login or code was incorrect.")
Beispiel #10
0
def getSteamKey():
    mnjson = app.config['STEAM_KEY']
    mjson = json.loads(mnjson)
    authbean = SteamAuthenticator(mjson)
    steamcode = authbean.get_code()
    return steamcode
Beispiel #11
0
def cmd_authenticator_add(args):
    account = args.account.lower().strip()
    secrets_file = UserDataFile('authenticator/{}.json'.format(account))
    sa = None

    if secrets_file.exists():
        if not args.force:
            print(
                "There is already an authenticator for that account. Use --force to overwrite"
            )
            return 1  # error
        sa = SteamAuthenticator(secrets_file.read_json())

    print("To add an authenticator, first we need to login to Steam")
    print("Account name:", account)

    wa = BetterMWA(account)
    try:
        wa.bcli_login(sa_instance=sa)
    except (KeyboardInterrupt, EOFError):
        print("Login interrupted")
        return 1  # error

    print("Login successful. Checking pre-conditions...")

    sa = SteamAuthenticator(backend=wa)

    status = sa.status()
    _LOG.debug("Authenticator status: %s", status)

    if not status['email_validated']:
        print("Account needs a verified email address")
        return 1  # error

    if status['state'] == 1:
        print("This account already has an authenticator.")
        print("You need to remove it first, before proceeding")
        return 1  # error

    if not status['authenticator_allowed']:
        print("This account is now allowed to have authenticator")
        return 1  # error

    # check phone number, and add one if its missing
    if not sa.has_phone_number():
        print("No phone number on this account. This is required.")

        if pmt_confirmation("Do you want to add a phone number?",
                            default_yes=True):
            print("Phone number need to include country code and no spaces.")

            while True:
                phnum = pmt_input("Enter phone number:",
                                  regex=r'^(\+|00)[0-9]+$')

                resp = sa.validate_phone_number(phnum)
                _LOG.debug("Phone number validation for %r: %s", phnum, resp)

                if not resp.get('is_valid', False):
                    print("That number is not valid for Steam.")
                    continue

                if not sa.add_phone_number(phnum):
                    print("Failed to add phone number!")
                    continue

                print("Phone number added. Confirmation SMS sent.")

                while not sa.confirm_phone_number(
                        pmt_input("Enter SMS code:", regex='^[0-9]+$')):
                    print("Code was incorrect. Try again.")

                break
        else:
            # user declined adding a phone number, we cant proceed
            return 1  # error

    # being adding authenticator setup
    sa.add()

    _LOG.debug("Authenticator secrets obtained. Saving to disk")

    secrets_file.write_json(sa.secrets)

    # Setup Steam app in conjuction
    if pmt_confirmation("Do you want to use Steam app too?",
                        default_yes=False):
        print("Great! Go and setup Steam Guard in your app.")
        print("Once completed, generate a code and enter it below.")

        showed_fail_info = False
        fail_counter = 0

        while True:
            code = pmt_input(
                "Steam Guard code:",
                regex='^[23456789BCDFGHJKMNPQRTVWXYbcdfghjkmnpqrtvwxy]{5}$')

            # code match
            if sa.get_code() == code.upper():
                break  # success
            # code do not match
            else:
                fail_counter += 1

                if fail_counter >= 3 and not showed_fail_info:
                    showed_fail_info = True
                    print("The codes do not match. This can be caused by:")
                    print("* The code was not entered correctly")
                    print("* Your system time is not synchronized")
                    print("* Steam has made changes to their backend")

                if not pmt_confirmation("Code mismatch. Try again?",
                                        default_yes=True):
                    _LOG.debug("Removing secrets file")
                    secrets_file.remove()
                    return 1  # failed, exit

    # only setup steamctl 2fa
    else:
        print(
            "Authenticator secrets obtained. SMS code for finalization sent.")

        while True:
            code = pmt_input("Enter SMS code:", regex='^[0-9]+$')
            try:
                sa.finalize(code)
            except SteamAuthenticatorError as exp:
                print("Finalization error: %s", exp)
                continue
            else:
                break

    # finish line
    print("Authenticator added successfully!")
    print("Get a code: {} authenticator code {}".format(__appname__, account))
    print("Or QR code: {} authenticator qrcode {}".format(
        __appname__, account))
Beispiel #12
0
def get_code():
    secrets = json.load(open('./mysecrets.json'))
    sa = SteamAuthenticator(secrets)
    TFAcode = sa.get_code()
    return TFAcode
Beispiel #13
0
def cmd_authenticator_add(args):
    account = args.account.lower().strip()
    secrets_file = UserDataFile('authenticator/{}.json'.format(account))

    if secrets_file.exists():
        print("There is already an authenticator for that account")
        return 1  # error

    print("To add an authenticator, first we need to login to Steam")
    print("Account name:", account)

    wa = BetterMWA(account)
    try:
        wa.bcli_login()
    except (KeyboardInterrupt, EOFError):
        print("Login interrupted")
        return 1  # error

    print("Login successful. Checking pre-conditions...")

    sa = SteamAuthenticator(backend=wa)

    # check phone number, and add one if its missing
    if not sa.has_phone_number():
        print("No phone number on this account. This is required.")

        if pmt_confirmation("Do you want to add a phone number?", default_yes=True):
            print("Phone number need to include country code and no spaces.")

            while True:
                phnum = pmt_input("Enter phone number:", regex=r'^(\+|00)[0-9]+$')

                resp = sa.validate_phone_number(phnum)
                _LOG.debug("Phone number validation for %r: %s", phnum, resp)

                if not resp.get('is_valid', False):
                    print("That number is not valid for Steam.")
                    continue

                if not sa.add_phone_number(phnum):
                    print("Failed to add phone number!")
                    continue

                print("Phone number added. Confirmation SMS sent.")

                while not sa.confirm_phone_number(pmt_input("Enter SMS code:", regex='^[0-9]+$')):
                    print("Code was incorrect. Try again.")

                break
        else:
            # user declined adding a phone number, we cant proceed
            return 1  # error

    # being adding authenticator setup
    sa.add()

    _LOG.debug("Authenticator secrets obtained. Saving to disk")

    secrets_file.write_json(sa.secrets)

    print("Authenticator secrets obtained. SMS code for finalization sent.")

    while True:
        code = pmt_input("Enter SMS code:", regex='^[0-9]+$')
        try:
            sa.finalize(code)
        except SteamAuthenticatorError as exp:
            print("Finalization error: %s", exp)
            continue
        else:
            break

    # finish line
    print("Authenticator added successfully!")
    print("To get a code run: {} authenticator code {}".format(__appname__, account))
class SteamClient:
    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 login(self):
        notDone = True
        while notDone:
            try:
                self.user.login()
            except wa.CaptchaRequired:
                print(self.user.captcha_url)
                self.user.login(captcha=input('Captcha: '))
                notDone = False
            except wa.EmailCodeRequired:
                self.user.login(email_code=input('Email Code: '))
                notDone = False
            except wa.TwoFactorCodeRequired:
                if self.sa is None:
                    self.user.login(twofactor_code=input('Two-Factor Code: '))
                else:
                    self.user.login(twofactor_code=self.sa.get_code())
                notDone = False
        self.steamId = self.user.steam_id
        if self.mobile is None:
            return
        timeToSleep = 30 - int(time.time() % 30) + 1
        for i in tqdm(range(timeToSleep), desc='Waiting for next code'):
            time.sleep(1)
        notDone = True
        while notDone:
            try:
                self.mobile.login()
            except wa.CaptchaRequired:
                print(self.mobile.captcha_url)
                self.mobile.login(captcha=input('Captcha: '))
                notDone = False
            except wa.EmailCodeRequired:
                self.mobile.login(email_code=input('Email Code: '))
                notDone = False
            except wa.TwoFactorCodeRequired:
                self.mobile.login(twofactor_code=self.sa.get_code())
                notDone = False
        return
        
    def validateWalletCode(self, code):
        payload = {
            'sessionid': self.user.session.cookies.get_dict()['sessionid'],
            'wallet_code': code
        }
        return self.user.session.post('https://store.steampowered.com/account/validatewalletcode/', data=payload).json()
    
    def redeemWalletCode(self, code):
        payload = {
            'sessionid': self.user.session.cookies.get_dict()['sessionid'],
            'wallet_code': code
        }
        return self.user.session.post('https://store.steampowered.com/account/confirmredeemwalletcode/', data=payload).json()
Beispiel #15
0
from steam import SteamClient
from steam.enums import EResult
from steam.guard import SteamAuthenticator


client = SteamClient()

result = client.cli_login()

if result != EResult.OK:
    print("Failed to login: %s" % repr(result))
    raise SystemExit

print("Logged on as:", client.user.name)

credentials_file = path.expanduser('~/.config/steam-totp/%s.secrets.json' % username)

with open(credentials_file, 'w') as f:
    pass

sa = SteamAuthenticator(medium=client)
sa.add()

code = raw_input("Enter SMS code: ")
sa.finalize(code)

json.dump(sa.secrets, open(credentials_file))

client.logout()
Beispiel #16
0
import json
import sys
from os import path
from steam.guard import SteamAuthenticator

if len(sys.argv) < 2:
    print("Usage: ", sys.argv[0], " username")
    sys.exit(1)

username = sys.argv[1]

data = json.load(
    open(path.expanduser('~/.config/steam-totp/%s.secrets.json' % username)))

sa = SteamAuthenticator(secrets=data)

print(sa.get_code())