Created
November 16, 2013 07:23
-
-
Save yefim/7497093 to your computer and use it in GitHub Desktop.
snapchat upload in python Rewritten from: https://github.com/dstelljes/php-snapchat/blob/master/src/snapchat.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| import time | |
| import pprint | |
| import hashlib | |
| # import rijndael | |
| from Crypto.Cipher import AES | |
| DEFAULT_OPTIONS = { | |
| 'blob_enc_key': 'M02cnQ51Ji97vwT4', | |
| 'debug': False, | |
| 'pattern': | |
| '0001110111101110001111010101111011010001001110011000110001000110', | |
| 'secret': 'iEk21fuwZApXlz93750dmW22pw389dPwOk', | |
| 'static_token': 'm198sOkJEn37DjqZ32lpRu76xmw288xSQ9', | |
| # 'url': 'https://feelinsonice-hrd.appspot.com/bq' | |
| 'url': 'https://feelinsonice--hrd-appspot-com-sfa0vorks4ru.runscope.net/bq' | |
| } | |
| iv = "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16" | |
| BLOCK_SIZE = 16 | |
| pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) \ | |
| * chr(BLOCK_SIZE - len(s) % BLOCK_SIZE) | |
| unpad = lambda s: s[0:-ord(s[-1])] | |
| headers = { | |
| 'User-Agent': 'Snapchat/6.0.2 (iPhone6,1; iOS 7.0.4; gzip)' | |
| } | |
| def encrypt(s): | |
| c = AES.new(DEFAULT_OPTIONS['blob_enc_key'], AES.MODE_ECB, iv) | |
| s = pad(s) | |
| s = c.encrypt(s) | |
| return s | |
| def decrypt(enc): | |
| c = AES.new(DEFAULT_OPTIONS['blob_enc_key'], AES.MODE_ECB, iv) | |
| enc = c.decrypt(enc) | |
| return unpad(enc) | |
| def hash(first, second): | |
| first = DEFAULT_OPTIONS['secret'] + str(first) | |
| second = str(second) + DEFAULT_OPTIONS['secret'] | |
| hash1 = hashlib.sha256(first).hexdigest() | |
| hash2 = hashlib.sha256(second).hexdigest() | |
| result = "" | |
| for i, p in enumerate(DEFAULT_OPTIONS['pattern']): | |
| if p == '0': | |
| h = hash1[i] | |
| else: | |
| h = hash2[i] | |
| result = result + str(h) | |
| return result | |
| ts = int(time.time() * 1000) | |
| data = { | |
| 'username': 'spoonpics', | |
| 'password': 'master321', | |
| 'timestamp': ts, | |
| 'req_token': hash(DEFAULT_OPTIONS['static_token'], ts), | |
| 'version': '6.0.0' | |
| } | |
| r = requests.post(DEFAULT_OPTIONS['url'] + '/login', | |
| data=data, | |
| headers=headers) | |
| auth_token = r.json()['auth_token'] | |
| # auth_token = 'f362fd59-9e08-4950-9dab-417fabdc6ede' | |
| ts = int(time.time() * 1000) | |
| with open('/home/geoff/Code/scratch/pic.jpg', 'r') as content_file: | |
| encrypted = encrypt(content_file.read()) | |
| f = open('/home/geoff/Code/scratch/pic.enc.jpg', 'wb+') | |
| f.write(encrypted) | |
| media_id = 'SPOONPICS~' + str(int(time.time())) | |
| u_data = { | |
| 'media_id': media_id, | |
| 'type': 0, # image is 0, video is 1 | |
| 'timestamp': ts, | |
| 'username': 'spoonpics', | |
| 'req_token': hash(auth_token, ts), | |
| 'version': '6.0.0' | |
| } | |
| # pprint.pprint(u_data) | |
| u = requests.post(DEFAULT_OPTIONS['url'] + '/upload', | |
| data=u_data, | |
| files={'data': f}, | |
| headers=headers) | |
| ts = int(time.time() * 1000) | |
| s_data = { | |
| 'media_id': media_id, | |
| 'recipient': 'yefim', | |
| 'time': 4, | |
| 'timestamp': ts, | |
| 'username': 'spoonpics', | |
| 'req_token': hash(auth_token, ts), | |
| 'version': '6.0.0' | |
| } | |
| s = requests.post(DEFAULT_OPTIONS['url'] + '/send', | |
| data=s_data, | |
| headers=headers) | |
| pprint.pprint(s.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment