forked from inAudible-NG/audible-activator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
audible-activator.py
executable file
·179 lines (155 loc) · 6.86 KB
/
audible-activator.py
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/env python2
import os
import sys
import time
import base64
import common
import hashlib
import binascii
import requests
from getpass import getpass
from selenium import webdriver
from optparse import OptionParser
PY3 = sys.version_info[0] == 3
if PY3:
from urllib.parse import urlencode
from urllib.parse import urlparse, parse_qsl
else:
from urllib import urlencode
from urlparse import urlparse, parse_qsl
def fetch_activation_bytes(username, password, options):
base_url = 'https://www.audible.com/'
base_url_license = 'https://www.audible.com/'
lang = options.lang
# Step 0
opts = webdriver.ChromeOptions()
opts.add_argument("user-agent=Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko")
# Step 1
if '@' in username: # Amazon login using email address
login_url = "https://www.amazon.com/ap/signin?"
else: # Audible member login using username (untested!)
login_url = "https://www.audible.com/sign-in/ref=ap_to_private?forcePrivateSignIn=true&rdPath=https%3A%2F%2Fwww.audible.com%2F%3F"
if lang == "uk":
login_url = login_url.replace('.com', ".co.uk")
base_url = base_url.replace('.com', ".co.uk")
elif lang == "jp":
login_url = login_url.replace('.com', ".co.jp")
base_url = base_url.replace('.com', ".co.jp")
elif lang != "us": # something more clever might be needed
login_url = login_url.replace('.com', "." + lang)
base_url = base_url.replace('.com', "." + lang)
player_id = base64.encodestring(hashlib.sha1(b"").digest()).rstrip() # keep this same to avoid hogging activation slots
if PY3:
player_id = player_id.decode("ascii")
if options.player_id:
player_id = base64.encodestring(binascii.unhexlify(options.player_id)).rstrip()
print("[*] Player ID is %s" % player_id)
payload = {
'openid.ns': 'http://specs.openid.net/auth/2.0',
'openid.identity': 'http://specs.openid.net/auth/2.0/identifier_select',
'openid.claimed_id': 'http://specs.openid.net/auth/2.0/identifier_select',
'openid.mode': 'logout',
'openid.assoc_handle': 'amzn_audible_' + lang,
'openid.return_to': base_url + 'player-auth-token?playerType=software&playerId=%s=&bp_ua=y&playerModel=Desktop&playerManufacturer=Audible' % (player_id)
}
if options.firefox:
driver = webdriver.Firefox()
else:
if sys.platform == 'win32':
chromedriver_path = "chromedriver.exe"
elif os.path.isfile("/usr/lib/chromium-browser/chromedriver"): # Ubuntu package chromedriver path
chromedriver_path = "/usr/lib/chromium-browser/chromedriver"
elif os.path.isfile("/usr/local/bin/chromedriver"): # macOS + Homebrew
chromedriver_path = "/usr/local/bin/chromedriver"
else:
chromedriver_path = "./chromedriver"
driver = webdriver.Chrome(chrome_options=opts,
executable_path=chromedriver_path)
query_string = urlencode(payload)
url = login_url + query_string
driver.get(base_url + '?ipRedirectOverride=true')
driver.get(url)
if os.getenv("DEBUG") or options.debug: # enable if you hit CAPTCHA or 2FA or other "security" screens
print("[!] Running in DEBUG mode. You will need to login in a semi-automatic way, wait for the login screen to show up ;)")
time.sleep(32)
else:
search_box = driver.find_element_by_id('ap_email')
search_box.send_keys(username)
search_box = driver.find_element_by_id('ap_password')
search_box.send_keys(password)
search_box.submit()
time.sleep(2) # give the page some time to load
# Step 2
driver.get(base_url + 'player-auth-token?playerType=software&bp_ua=y&playerModel=Desktop&playerId=%s&playerManufacturer=Audible&serial=' % (player_id))
current_url = driver.current_url
o = urlparse(current_url)
data = dict(parse_qsl(o.query))
# Step 2.5, switch User-Agent to "Audible Download Manager"
headers = {
'User-Agent': "Audible Download Manager",
}
cookies = driver.get_cookies()
s = requests.Session()
for cookie in cookies:
s.cookies.set(cookie['name'], cookie['value'])
# Step 3, de-register first, in order to stop hogging all activation slots
# (there are 8 of them!)
durl = base_url_license + 'license/licenseForCustomerToken?' \
+ 'customer_token=' + data["playerToken"] + "&action=de-register"
s.get(durl, headers=headers)
# Step 4
url = base_url_license + 'license/licenseForCustomerToken?' \
+ 'customer_token=' + data["playerToken"]
response = s.get(url, headers=headers)
with open("activation.blob", "wb") as f:
f.write(response.content)
activation_bytes, _ = common.extract_activation_bytes(response.content)
print("activation_bytes: " + activation_bytes)
# Step 5 (de-register again to stop filling activation slots)
s.get(durl, headers=headers)
# driver.get(url)
time.sleep(8)
driver.quit()
if __name__ == "__main__":
parser = OptionParser(usage="Usage: %prog [options]", version="%prog 0.2")
parser.add_option("-d", "--debug",
action="store_true",
dest="debug",
default=False,
help="run program in debug mode, enable this for 2FA enabled accounts or for authentication debugging")
parser.add_option("-f", "--firefox",
action="store_true",
dest="firefox",
default=False,
help="use this option to use firefox instead of chrome",)
parser.add_option("-l", "--lang",
action="store",
dest="lang",
default="us",
help="us (default) / de / fr / jp / uk (untested)",)
parser.add_option("-p",
action="store",
dest="player_id",
default=None,
help="Player ID in hex (for debugging, not for end users)",)
parser.add_option("--username",
action="store",
dest="username",
default=False,
help="Audible username, use along with the --password option")
parser.add_option("--password",
action="store",
dest="password",
default=False,
help="Audible password")
(options, args) = parser.parse_args()
if options.username and options.password:
username = options.username
password = options.password
else:
if PY3:
username = input("Username: ")
else:
username = raw_input("Username: ")
password = getpass("Password: ")
fetch_activation_bytes(username, password, options)