Advertisement
Guest User

Untitled

a guest
Dec 23rd, 2016
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.76 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import base64
  4. import hashlib
  5. import urllib.parse
  6. import uuid
  7.  
  8. try:
  9. import requests
  10. except ImportError:
  11. print('ERROR: Cannot import requests')
  12. print('DEBUG: Please install Requests for Python 3, see '
  13. 'http://docs.python-requests.org/en/master/user/install/ or use your '
  14. 'favorite package manager (e.g. apt-get install python3-requests)')
  15. exit(2)
  16.  
  17.  
  18. class OprahProxy:
  19. """ Everybody gets a proxy! """
  20.  
  21. client_type = ''
  22. client_key = ''
  23. session = None
  24. device_id = ''
  25. device_id_hash = ''
  26. device_password = ''
  27. example_proxy = None
  28.  
  29. def __init__(self, client_type, client_key):
  30. self.client_type = client_type
  31. self.client_key = client_key
  32. self.session = requests.Session()
  33.  
  34. def post(self, url, data):
  35. headers = {'SE-Client-Type': self.client_type,
  36. 'SE-Client-API-Key': self.client_key}
  37.  
  38. result = self.session.post('https://api.surfeasy.com%s' % url, data,
  39. headers=headers).json()
  40. code = list(result['return_code'].keys())[0]
  41. if code != '0':
  42. print('ERROR: %s' % result['return_code'][code])
  43. exit(1)
  44. return result
  45.  
  46. def register_subscriber(self):
  47. print('DEBUG: Call register_subscriber')
  48. email_user = uuid.uuid4()
  49. email = '%s@mailinator.com' % email_user
  50. password = uuid.uuid4()
  51. password_hash = hashlib.sha1(
  52. str(password).encode('ascii')).hexdigest().upper()
  53. print('DEBUG: Your SurfEasy email: %s' % email)
  54. print('DEBUG: Your SurfEasy password: %s' % password)
  55. print('DEBUG: Your SurfEasy password hash: %s' % password_hash)
  56. print('DEBUG: Your mailbox: https://mailinator.com/inbox2.jsp?%s' %
  57. urllib.parse.urlencode({'public_to': email_user}))
  58. print("DEBUG: These are not the credentials you are looking for "
  59. "(you won't probably need these, ever)")
  60.  
  61. data = {'email': email,
  62. 'password': password_hash}
  63. result = self.post('/v2/register_subscriber', data)
  64. print('DEBUG: Subscriber registered')
  65.  
  66. @staticmethod
  67. def you_get_a_proxy():
  68. print('++++++++++++++++++++++++++=======================~~~~~~~::::')
  69. print(',..,,,.,,...,,,.,,,,,,,,,,............,.....,.,,::::~~======')
  70. print(',,,,,:,,,,,,,,,,,,,, ,.,,,,,,,,,,,,,....~')
  71. print('~~~~~~~::::::::::::: YOU GET A PROXY! ,,,,,,,,,,,,,,,,,:~=')
  72. print('~~===~~~~::::::::::. ,,,,,,,,,,,,,,,~~~:~')
  73. print('::~:::::::::::::::,,...,~=::~=~:.....,,,,,,,,,,,,,,,:~:~:,::')
  74. print('??+=..,++++++++++=.....:===I+~=~....,,~~=~~~~~~~:~====~,,::~')
  75. print('::~....,...............~=~~~~:=~,...,.~~~======~==++=~:====+')
  76. print('::~...,:,,,,,,,,.......:==~+=:~:,.....,,,,,,,~~~====~,,,,,,,')
  77. print(':::~~~:,::,,::::,......+~~===~:,.....,,,,,,~~~~~==~,,,,....,')
  78. print('~:~:,,,,,:::::,..........~~::~,:....:~~~~~::::~:::::,,,,,,,,')
  79. print('~...~~~,,::~~::~:........~~~:~::.:,,:~::::::::::::::::::::::')
  80. print('+..???+?~,::::::::::::~:~::~~~:~::::::::::::::::~~=~~~~~~~~=')
  81. print('...?????+?,.:::::::::::~~:~~::~:::::::::::::::,~++++++++++++')
  82. print('?=??????+??~,::::::::~~~~~~~~~~::::::::::::::,=+++++++++++++')
  83. print('????????????::::::,::~~~~~~~~~~:::::::::::::,+++++++++++++++')
  84. print('??+??????????:,,::,:::~~~~~~~:::::::::::::,+++++++++++++++++')
  85. print('??????????????+,,,,:::~~,~~~~~:::=,:::::,?+?++++++++++++++++')
  86. print('????????????????+,:::~~:,~~~~~~~~:~::::=+??+?++?++++++++++++')
  87. print('??????????????????:::~~~~~~~~~~~:::::::???????++++++++++++++')
  88. print('??????????????????=:::~~~~~~~~~::::::::+??????+++++?+?++++++')
  89. print('=+==+====++++++++==:::~:,~~~~~:::,::::~====~~::::,,...,:~~=+')
  90. print('++++++++++++===++++::~:~~~~~~::::~::::=+++++++++++++========')
  91. print('=====+++++=====++++:~:~~~~~~::::::::::~++===================')
  92. print('+++==+======+++ ==================')
  93. print('~~~~==========~ EVERYBODY GETS A PROXY! ~~~~~~~~~~~~~~~~~~')
  94. print('~~~~~~~~~~~===~ ~~~~~~~~~~~~~~~~~~')
  95. print('=============++===:::::::::::::::::::::~~~~~~~~~~~~~~~~~~~:~')
  96. print('https://github.com/spaze/oprah-proxy :::==~=~~~~~~~~=~~~~~~~')
  97.  
  98. def register_device(self):
  99. print('DEBUG: Call register_device')
  100. data = {'client_type': self.client_type,
  101. 'device_hash': '4BE7D6F1BD040DE45A371FD831167BC108554111',
  102. 'device_name': 'Opera-Browser-Client'}
  103.  
  104. result = self.post('/v2/register_device', data)
  105. self.device_id = result['data']['device_id']
  106. print('DEBUG: Device id: %s' % self.device_id)
  107. self.device_id_hash = hashlib.sha1(
  108. str(self.device_id).encode('ascii')).hexdigest().upper()
  109. self.device_password = result['data']['device_password']
  110. print('DEBUG: Device registered')
  111.  
  112. def geo_list(self):
  113. print('DEBUG: Call geo_list')
  114. data = {'device_id': self.device_id_hash}
  115. result = self.post('/v2/geo_list', data)
  116. codes = []
  117. for geo in result['data']['geos']:
  118. codes.append(geo['country_code'])
  119. print('INFO: Supported country: %s %s' %
  120. (geo['country_code'], geo['country']))
  121. print('DEBUG: Geo list fetched')
  122. return codes
  123.  
  124. def discover(self, country_code):
  125. print('DEBUG: Call discover %s' % country_code)
  126. data = {'serial_no': self.device_id_hash,
  127. 'requested_geo': '"%s"' % country_code}
  128. result = self.post('/v2/discover', data)
  129.  
  130. print('INFO: Your location is %s%s%s' %
  131. (result['data']['requester_geo']['country_code'],
  132. '/' if result['data']['requester_geo']['state_code'] else '',
  133. result['data']['requester_geo']['state_code']))
  134. for ip in result['data']['ips']:
  135. for port in ip['ports']:
  136. if port == 443 and self.example_proxy is None:
  137. self.example_proxy = '%s:%s' % (ip['ip'], port)
  138. print('INFO: Proxy in %s/%s %s:%s' %
  139. (ip['geo']['country_code'], ip['geo']['state_code'],
  140. ip['ip'], port))
  141. print('DEBUG: Proxies discovered')
  142.  
  143. def everybody_gets_a_proxy(self):
  144. self.register_subscriber()
  145. self.register_device()
  146. for country_code in self.geo_list():
  147. self.discover(country_code)
  148. print(
  149. 'INFO: Pick a proxy from the list above and use these credentials:')
  150. print('INFO: Username: %s' % self.device_id_hash)
  151. print('INFO: Password: %s' % self.device_password)
  152. creds = ('%s:%s' % (self.device_id_hash, self.device_password)).encode(
  153. 'ascii')
  154. header = 'Proxy-Authorization: Basic %s' % base64.b64encode(
  155. creds).decode('ascii')
  156. print('INFO: HTTP header %s' % header)
  157. print('DEBUG: Example bash command: URL="http://www.opera.com" PROXY=%s '
  158. 'HEADER="%s"; echo -e "GET $URL HTTP/1.0\\n$HEADER\\n\\n" | '
  159. 'openssl s_client -connect $PROXY -ign_eof' % (
  160. self.example_proxy, header))
  161. print('DEBUG: For PAC-file for other browsers see '
  162. 'https://github.com/spaze/oprah-proxy#usage-with-other-browsers')
  163.  
  164.  
  165. you_get_a_proxy = OprahProxy('se0306',
  166. '7502E43F3381C82E571733A350099BB5D449DD48311839C099ADC4631BA0CC04')
  167. you_get_a_proxy.you_get_a_proxy()
  168. you_get_a_proxy.everybody_gets_a_proxy()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement