~sircmpwn/pass-rotate

ref: 7a0f1572c61de44c5ceed81c5d65c6830bc45865 pass-rotate/passrotate/providers/twitter.py -rw-r--r-- 2.7 KiB
7a0f1572 — Matthias Gabriel add option to override the pass name to be used when rotating the password 4 years ago
                                                                                
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
from passrotate.provider import Provider, ProviderOption, PromptType, register_provider
from passrotate.forms import get_form
import requests
from urllib.parse import urlparse

class Twitter(Provider):
    """
    [twitter.com]
    username=Your Twitter username
    """
    name = "Twitter"
    domains = [
        "twitter.com",
        "m.twitter.com"
    ]
    options = {
        "username": ProviderOption(str, "Your Twitter username")
    }

    def __init__(self, options):
        self.username = options["username"]

    def prepare(self, old_password):
        self._session = requests.Session()
        r = self._session.get("https://mobile.twitter.com/login")
        tk = self._session.cookies.get("_mb_tk")
        if not tk or r.status_code != 200:
            return False
        r = self._session.post("https://mobile.twitter.com/sessions", data={
            "authenticity_token": tk,
            "session[username_or_email]": self.username,
            "session[password]": old_password,
            "remember_me": 0,
            "wfa": 1,
            "redirect_after_login": "/home"
        })
        url = urlparse(r.url)
        if url.path == "/login/error":
            raise Exception("Current password for Twitter is incorrect")
        if url.path == "/account/locked":
            raise Exception("Twitter has locked us out of further login attempts. Wait 60 minutes and try again.")
        while url.path == "/account/login_verification":
            data = get_form(r.text)
            challenge_type = data.get("challenge_type")
            if challenge_type == "Sms":
                response = self.prompt("Enter your SMS authorization code", PromptType.sms)
            else:
                raise Exception("Unsupported two-factor method '{}'".format(challenge_type))
            data.update({ "challenge_response": response })
            r = self._session.post(
                    "https://mobile.twitter.com/account/login_verification",
                    data=data)
            url = urlparse(r.url)
        r = self._session.get("https://twitter.com")
        r = self._session.get("https://twitter.com/settings/password")
        self._form = get_form(r.text, id="password-form")

    def execute(self, old_password, new_password):
        self._form.update({
            "current_password": old_password,
            "user_password": new_password,
            "user_password_confirmation": new_password,
        })
        r = self._session.post("https://twitter.com/settings/passwords/update",
            data=self._form, headers={
                "origin": "https://twitter.com",
                "referer": "https://twitter.com/settings/password"
            })

register_provider(Twitter)