• Stars
    star
    246
  • Rank 164,726 (Top 4 %)
  • Language
    PHP
  • License
    MIT License
  • Created almost 12 years ago
  • Updated about 11 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A PHP library to use the Snapchat API

Snaphax: a PHP library to use the Snapchat API

This library allows you to communicate with Snapchat's servers using their undocumented HTTP API. It was reverse engineered from the official Android client (version 1.6)

Warning

I made Snaphax by reverse engineering the app. It may be extremely buggy or piss off the Snapchat people. Use at your own risk.

How to use

Pretty simple:

	require_once('snaphax/snaphax.php');

	$opts = array();
	$opts['username'] = 'username';
	$opts['password'] = 'password';
	$opts['debug'] = 1; 

	$s = new Snaphax($opts);
	$result = $s->login();
	var_dump($result);

Limitations

Only login (with list of new media) and fetching of image/video snaps is implemented. This is obviously a huge failing which I am to correct when I have more time.

Motivation and development process

I'm a huge fan of Snapchat, a photo/video sharing app that allows you to set expiration times on the media you send to your friends. They can't open it after they've seen it for up to 10 seconds, and if they take a screenshot, the other party is notified.

I'm stunned and delighted by the fact that a simple feature like auto-expiration of images can create such a compelling and challenging service. And it's not just me: everyone I've told about Snapchat who has used it has loved it, and as of last November more than one billion snaps had been exchanged using the service.

But I hate closed products, so I set about figuring out how it worked. Adam Caudill wrote an excellent analysis of their HTTP-based API by using an HTTPS traffic sniffer. Unfortunately this information now seems out of date.

I ended up having to fetch the official Android client's app binary (APK), decompiling the whole thing with a mix of tools (all of them seemed to produce subtly incorrect output), tracing the control flow a bit, and then puzzling through the process of creating their dreaded access tokens (called req_token in the HTTP calls).

This involved me paging through Fiddler, trying to generate SHA-256 hashes seemingly at random, tearing my heart out, and weeping openly.

Their system is a bit unusual: it AES-256 hashes two input values separately, using a secret key contained in the binary, and then uses a fixed pattern string to pull bytes from one or the other. The final composition of the two is used in HTTP requests. Why not just append the values pre-hash? The security profile would be similar.

Other things about the API that I've discovered so far:

  • Speaks JSON over HTTPS, using POST as the verb
  • Not made for human consumption; difficult error messaging
  • Doesn't seem to support JSONP (i.e., callback parameter in post data is ignored)
  • Blob (image/video) downloads are encrypted using AES. This code successfully decodes them before they are returned by the library.

The apocalyptic future

The TODO list is almost endless at this point:

  • API likely to change
  • DOCS!!!
  • Figure out the /device call - what's this do? also device_id in /login resp
  • Syncing (to mark snaps as seen)
  • Image/video uploading
  • Friend list maintenance
  • Port to Javascript (probably via Node + NPM since their API doesn't seem to support JSONP)
  • Add support for PHP composer
  • Test framework

License

MIT

Credits

Made by Thomas Lackner <@tlack> with a lot of help from @adamcaudill. And of course none of this would be possible without the inventiveness of the Snapchat team

More Repositories

1

xxl

a minimal vector programming language
C
177
star
2

vino

Vino is a 3rd party client for the Vine video sharing service's undocumented API
JavaScript
93
star
3

b-decoded

arthur whitney's b interpreter translated into a more traditional flavor of C
C
83
star
4

popup-chat

esp8266 instant message board/chat room - runs as open wifi access point (captive portal)
C++
50
star
5

hairytext

A data labeling and NLP tool for Elixir (uses Spacy)
Elixir
20
star
6

node-web-repl

A web-based REPL that you can add to your Node.js apps
JavaScript
10
star
7

qmvp

qmvp is boiler plate for creating a Minimum Viable Product website in Q
Nginx
9
star
8

semantics

Semantic similarity via text embeddings in Elixir - powered by SentenceTransformers by SBert.net
Elixir
6
star
9

atree

Stevan Apter-style trees in C++17
C++
5
star
10

PPO-positioner-GM6020

Attempt to use reinforcement learning with PPO instead of PID controller to position GM6020 motor via CANBus
Python
3
star
11

m5stickv-camera-webserver

M5StickV / Kendryte K210 / Sipeed Maix camera board -> Linux serial -> webserver
Python
3
star
12

cproto2atomnif

Call C functions from AtomVM (Erlang/Elixir on microcontrollers)
Python
2
star
13

rl-experiments

Reinforcement learning experiments
Python
2
star
14

ghettodotfiles

ghetto sloppy dotfiles
Vim Script
2
star
15

qqq

www toolkit for q
JavaScript
2
star
16

motioncam

ESP8266 + Arducam + motion sensor example setup
Arduino
2
star
17

xacto

Q-inspired Javascript convenience library and in-memory database
JavaScript
2
star
18

fazuul

Misc notes and things about the game Fazuul
C++
2
star
19

gan-guesser

The game where you guess what the GAN is generating
Python
2
star
20

quagga

Quagga is a web-based development environment for Q/Kdb+
JavaScript
2
star
21

canbus-gm6020-esp8266-webserver

An example of creating a webserver on an ESP8266 to control a DJI / RoboMaster GM6020 motor via Seeed Studios CAN-BUS Shield
C++
1
star
22

lorademo0

Very simple test with Arduino LoRa+OLED (for Heltec ESP32 + LoRa dev boards)
Arduino
1
star
23

rem

reMarkable app ideas and design files
HTML
1
star
24

boothbusy

Is this room busy? Web interface for motion sensors (ESP8266 and HC-SR501)
Arduino
1
star
25

qwa

An attempt Web Analytics written in Q
Shell
1
star
26

binance.q

Binance.com helper tools written in Q / Kdb
1
star
27

jiyi

Telegram memory bot and group chat bouncer
1
star
28

esp8266CANbus

test code for interacting with CAN devices on a Wemos D1 Mini (ESP8266)
Arduino
1
star
29

grunt-less-boilerplate

Grunt + Less + Livereload boilerplate
JavaScript
1
star
30

node-express3-hogan

node.js app boilerplate that utilizes Express 3.0 and Hogan (including partials)
JavaScript
1
star
31

exqdr

Qdrant database connector for Elixir
Elixir
1
star
32

persist-state.q

Save your Q/Kdb+ workspace on exit, restore on start
1
star
33

dobot-tcn

Experiments with Time Contrastive Networks on the Dobot Magician robotic arm
Python
1
star
34

stex

Static site generator for Express.js apps
JavaScript
1
star
35

grunt-bootstrap-boilerplate

Grunt + Bootstrap + Livereload boiler plate (patched up Yeoman generator)
JavaScript
1
star
36

xs-pink

tiny programming language experiment
JavaScript
1
star