-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoprahproxy.py
executable file
·153 lines (132 loc) · 5.99 KB
/
oprahproxy.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
#!/usr/bin/env python3
import base64
import hashlib
import urllib.parse
import uuid
import os.path
try:
import requests
except ImportError:
print('ERROR: Cannot import requests')
print('DEBUG: Please install Requests for Python 3, see '
'http://docs.python-requests.org/en/master/user/install/ or use your '
'favorite package manager (e.g. apt-get install python3-requests)')
exit(2)
class OprahProxy:
""" Everybody gets a proxy! """
client_type = ''
client_key = ''
session = None
device_id = ''
device_id_hash = ''
device_password = ''
example_proxy = None
def __init__(self, client_type, client_key):
self.client_type = client_type
self.client_key = client_key
self.session = requests.Session()
def post(self, url, data):
headers = {'SE-Client-Type': self.client_type,
'SE-Client-API-Key': self.client_key}
result = self.session.post('https://api.surfeasy.com%s' % url, data,
headers=headers).json()
code = list(result['return_code'].keys())[0]
if code != '0':
print('ERROR: %s' % result['return_code'][code])
exit(1)
return result
def register_subscriber(self):
#print('DEBUG: Call register_subscriber')
email_user = uuid.uuid4()
email = '%[email protected]' % email_user
password = uuid.uuid4()
password_hash = hashlib.sha1(
str(password).encode('ascii')).hexdigest().upper()
#print('DEBUG: Your SurfEasy email: %s' % email)
#print('DEBUG: Your SurfEasy password: %s' % password)
#print('DEBUG: Your SurfEasy password hash: %s' % password_hash)
#print('DEBUG: Your mailbox: https://mailinator.com/inbox2.jsp?%s' %
# urllib.parse.urlencode({'public_to': email_user}))
#print("DEBUG: These are not the credentials you are looking for "
# "(you won't probably need these, ever)")
data = {'email': email,
'password': password_hash}
result = self.post('/v2/register_subscriber', data)
#print('DEBUG: Subscriber registered')
with open('creds', 'w') as f:
f.write(email + ' ' + password_hash)
@staticmethod
def you_get_a_proxy():
pass
def register_device(self):
#print('DEBUG: Call register_device')
data = {'client_type': self.client_type,
'device_hash': '4BE7D6F1BD040DE45A371FD831167BC108554111',
'device_name': 'Opera-Browser-Client'}
result = self.post('/v2/register_device', data)
self.device_id = result['data']['device_id']
#print('DEBUG: Device id: %s' % self.device_id)
self.device_id_hash = hashlib.sha1(
str(self.device_id).encode('ascii')).hexdigest().upper()
self.device_password = result['data']['device_password']
#print('DEBUG: Device registered')
with open('secret', 'w') as f:
f.write(self.device_id_hash + ' ' + self.device_password)
def geo_list(self):
#print('DEBUG: Call geo_list')
data = {'device_id': self.device_id_hash}
result = self.post('/v2/geo_list', data)
codes = []
for geo in result['data']['geos']:
codes.append(geo['country_code'])
#print('INFO: Supported country: %s %s' %
# (geo['country_code'], geo['country']))
#print('DEBUG: Geo list fetched')
return codes
def discover(self, country_code):
#print('DEBUG: Call discover %s' % country_code)
data = {'serial_no': self.device_id_hash,
'requested_geo': '"%s"' % country_code}
result = self.post('/v2/discover', data)
#print('INFO: Your location is %s%s%s' %
# (result['data']['requester_geo']['country_code'],
# '/' if result['data']['requester_geo']['state_code'] else '',
# result['data']['requester_geo']['state_code']))
if not os.path.isfile('proxylist.csv'):
for country in country_code:
for ip in result['data']['ips']:
for port in ip['ports']:
if port == 443 and self.example_proxy is None:
self.example_proxy = '%s:%s' % (ip['ip'], port)
#print('INFO: Proxy in %s/%s %s:%s' %
# (ip['geo']['country_code'], ip['geo']['state_code'],
# ip['ip'], port))
#
with open('proxylist.csv', 'a') as f:
f.write(country + ',' + str(ip['ip']) + ',' + str(port) + '\n' )
#print('DEBUG: Proxies discovered')
def everybody_gets_a_proxy(self):
self.register_subscriber()
self.register_device()
country_codes = self.geo_list()
self.discover(country_codes)
#print(
# 'INFO: Pick a proxy from the list above and use these credentials:')
#print('INFO: Username: %s' % self.device_id_hash)
#print('INFO: Password: %s' % self.device_password)
creds = ('%s:%s' % (self.device_id_hash, self.device_password)).encode(
'ascii')
header = 'Proxy-Authorization: Basic %s' % base64.b64encode(
creds).decode('ascii')
#print('INFO: HTTP header %s' % header)
#print('DEBUG: Example bash command: URL="http://www.opera.com" PROXY=%s '
# 'HEADER="%s"; echo -e "GET $URL HTTP/1.0\\n$HEADER\\n\\n" | '
# 'openssl s_client -connect $PROXY -ign_eof' % (
# self.example_proxy, header))
#print('DEBUG: For PAC-file for other browsers see '
# 'https://github.com/spaze/oprah-proxy#usage-with-other-browsers')
#you_get_a_proxy = OprahProxy('se0306',
# '7502E43F3381C82E571733A350099BB5D449DD48311839C099ADC4631BA0CC04')
#you_get_a_proxy.you_get_a_proxy()
#you_get_a_proxy.everybody_gets_a_proxy()
#print(you_get_a_proxy.deviceid)