Last active
March 29, 2016 06:32
-
-
Save zaersk/7602717d9ad2877ce117 to your computer and use it in GitHub Desktop.
Attempt to login to Instagram using their unofficial API (no OAuth tokens).
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
// | |
// main.m | |
// ER1 | |
// | |
// Created by @zaersk_ on 7/19/14. | |
// Copyright (c) 2014 Zaersk. All rights reserved. | |
// | |
// Attempt to login to Instagram using their unofficial API (no OAuth tokens). | |
#import <Foundation/Foundation.h> | |
#import <CommonCrypto/CommonHMAC.h> | |
@interface ER1 : NSObject { | |
} | |
@end | |
@implementation ER1 : NSObject | |
-(void)sayHi { | |
// Get Device UUID | |
NSString *uuid = [[NSUUID UUID] UUIDString]; | |
NSString *password = @"password"; | |
NSString *username = @"username"; | |
NSString *csrftoken = @"missing"; // # Don't change this, smartypants # | |
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: | |
uuid, @"_uuid", | |
password, @"password", | |
username, @"username",uuid,@"device_id",@NO,@"from_reg",csrftoken,@"_csrftoken", nil]; | |
NSError *error2; | |
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:kNilOptions error:&error2]; | |
NSLog(@"%@",hexHash(jsonData)); | |
NSString *jsonDataString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; | |
NSString *signedBody = [NSString stringWithFormat:@"%@.%@",hexHash(jsonData),jsonDataString]; | |
NSString *igSigKeyVersion = @"4"; | |
NSLog(@"%@",signedBody); | |
// Instagram Login | |
NSMutableURLRequest *requestCreatePost = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://i.instagram.com/api/v1/accounts/login/"]]; | |
NSString *boundary = uuid; | |
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary]; | |
NSString *createPostLength = [NSString stringWithFormat:@"%lu", (unsigned long)[signedBody length]]; | |
[requestCreatePost setHTTPMethod:@"POST"]; | |
[requestCreatePost setValue:createPostLength forHTTPHeaderField:@"Content-Length"]; | |
[requestCreatePost setValue:contentType forHTTPHeaderField:@"Content-Type"]; | |
[requestCreatePost addValue:@"Instagram 6.0.4 (iPhone4,1; iPhone OS 7_1_2; en_US; en) AppleWebKit/420+" forHTTPHeaderField:@"User-Agent"]; | |
[requestCreatePost setValue:@"en;q=1, fr;q=0.9, de;q=0.8, zh-Hans;q=0.7, zh-Hant;q=0.6, ja;q=0.5" forHTTPHeaderField:@"Accept-Language"]; | |
[requestCreatePost setValue:@"mid=U8RKdAAAAAHC0GFTAhi4DgVV15bs" forHTTPHeaderField:@"Cookie"]; | |
NSMutableData *body = [NSMutableData data]; | |
[body appendData:[[NSString stringWithFormat:@"\r--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; | |
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"signed_body\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; | |
[body appendData:[[NSString stringWithFormat:@"%@", signedBody] dataUsingEncoding:NSUTF8StringEncoding]]; | |
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; | |
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"ig_sig_key_version\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; | |
[body appendData:[[NSString stringWithFormat:@"%@", igSigKeyVersion] dataUsingEncoding:NSUTF8StringEncoding]]; | |
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; | |
[requestCreatePost setHTTPBody:body]; | |
NSData *data2 = [NSURLConnection sendSynchronousRequest:requestCreatePost returningResponse:nil error:nil]; | |
NSString *dataString2 = [[NSString alloc] initWithData:data2 encoding:NSASCIIStringEncoding]; | |
NSLog(@"%@", dataString2); | |
} | |
static NSString * hexHash(NSData * input) { | |
unsigned char output[CC_SHA256_DIGEST_LENGTH]; | |
CC_SHA256(input.bytes, (unsigned int)input.length, output); | |
NSMutableString * str = [NSMutableString string]; | |
for (int i = 0; i < CC_SHA256_DIGEST_LENGTH; i++) { | |
[str appendFormat:@"%02x", output[i]]; | |
} | |
return str; | |
} | |
@end | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
// insert code here... | |
ER1 *er = [ER1 new]; | |
[er sayHi]; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It says "Your version of Instagram is out of date." Even if I set Instagram 6.6.1 version.