Advertisement
ardann

Untitled

Jul 13th, 2018
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.83 KB | None | 0 0
  1. <?php
  2. $user = "";
  3. $pass = "";
  4. /*
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20. */
  21. function instagram($ighost, $useragent, $url, $cookie = 0, $data = 0, $httpheader = array(), $proxy = 0, $userpwd = 0, $is_socks5 = 0)
  22. {
  23.     $url = $ighost ? 'https://i.instagram.com/api/v1/' . $url : $url;
  24.     $ch = curl_init($url);
  25.     curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
  26.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  27.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  28.     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  29.     curl_setopt($ch, CURLOPT_TIMEOUT, 20);
  30.     if($proxy) curl_setopt($ch, CURLOPT_PROXY, $proxy);
  31.     if($userpwd) curl_setopt($ch, CURLOPT_PROXYUSERPWD, $userpwd);
  32.     if($is_socks5) curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
  33.     if($httpheader) curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
  34.     curl_setopt($ch, CURLOPT_HEADER, 1);
  35.     if($cookie) curl_setopt($ch, CURLOPT_COOKIE, $cookie);
  36.     if ($data):
  37.         curl_setopt($ch, CURLOPT_POST, 1);
  38.         curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  39.     endif;
  40.     $response = curl_exec($ch);
  41.     $httpcode = curl_getinfo($ch);
  42.     if(!$httpcode) return false; else{
  43.         $header = substr($response, 0, curl_getinfo($ch, CURLINFO_HEADER_SIZE));
  44.         $body = substr($response, curl_getinfo($ch, CURLINFO_HEADER_SIZE));
  45.         curl_close($ch);
  46.         return array($header, $body);
  47.     }
  48. }
  49.  
  50. function generateDeviceId($seed)
  51. {
  52.     $volatile_seed = filemtime(__DIR__);
  53.     return 'android-'.substr(md5($seed.$volatile_seed), 16);
  54. }
  55.  
  56. function generateSignature($data)
  57. {
  58.     $hash = hash_hmac('sha256', $data, 'b4946d296abf005163e72346a6d33dd083cadde638e6ad9c5eb92e381b35784a');
  59.     return 'ig_sig_key_version=4&signed_body='.$hash.'.'.urlencode($data);
  60. }
  61.  
  62. function generate_useragent()
  63. {
  64.     return 'Instagram 12.0.0.7.91 Android (18/4.3; 320dpi; 720x1280; Xiaomi; HM 1SW; armani; qcom; en_US)';
  65. }
  66.  
  67. function get_csrftoken()
  68. {
  69.     $fetch = instagram('si/fetch_headers/', null, null);
  70.     $header = $fetch[0];
  71.     if (!preg_match('#Set-Cookie: csrftoken=([^;]+)#', $fetch[0], $token)) {
  72.         return json_encode(array('result' => false, 'content' => 'Missing csrftoken'));
  73.     } else {
  74.         return substr($token[0], 22);
  75.     }
  76. }
  77. function generateUUID($type)
  78. {
  79.     $uuid = sprintf(
  80.         '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
  81.         mt_rand(0, 0xffff),
  82.         mt_rand(0, 0xffff),
  83.         mt_rand(0, 0xffff),
  84.         mt_rand(0, 0x0fff) | 0x4000,
  85.         mt_rand(0, 0x3fff) | 0x8000,
  86.         mt_rand(0, 0xffff),
  87.         mt_rand(0, 0xffff),
  88.         mt_rand(0, 0xffff)
  89.     );
  90.  
  91.     return $type ? $uuid : str_replace('-', '', $uuid);
  92. }
  93. function save($name, $isi)
  94. {
  95.     $jud1 = fopen($name, "a");
  96.     fwrite($jud1, $isi . "\n");
  97.     fclose($jud1);
  98. }
  99. function curl($url, $post=null)
  100. {
  101.     $c = curl_init();
  102.     curl_setopt($c, CURLOPT_URL, $url);
  103.     if($post != null){
  104.         curl_setopt($c, CURLOPT_POST, true);
  105.         curl_setopt($c, CURLOPT_POSTFIELDS, $post);
  106.     }
  107.     curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
  108.     curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
  109.     curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
  110.     $curl = curl_exec($c);
  111.     curl_close($c);
  112.     return $curl;
  113. }
  114.  
  115. function login($post_username, $post_password)
  116. {
  117.     $postq = json_encode([
  118.         'phone_id' => generateUUID(true),
  119.         '_csrftoken' => get_csrftoken(),
  120.         'username' => $post_username,
  121.         'guid' => generateUUID(true),
  122.         'device_id' => generateUUID(true),
  123.         'password' => $post_password,
  124.         'login_attempt_count' => 0
  125.     ]);
  126.     $a = instagram(1, generate_useragent(), 'accounts/login/', 0, generateSignature($postq));
  127.     $header = $a[0];
  128.     $a = json_decode($a[1]);
  129.     if($a->status == 'ok'){
  130.         preg_match_all('%Set-Cookie: (.*?);%',$header,$d);$cookies = '';
  131.         for($o=0;$o<count($d[0]);$o++)$cookies.=$d[1][$o].";";
  132.         $array = json_encode(['result' => true, 'cookies' => $cookies, 'useragent' => generate_useragent(), /*'id' => $id, */'devid' => generateUUID(true), 'username' => $post_username, 'password' => $post_password]);
  133.         //$array = json_encode(['result' => true, 'cookies' => $cookies, 'useragent' => generate_useragent(), 'id' => $a->logged_in_user->pk, 'username' => $post_username, 'password' => $post_password]);
  134.     } else {
  135.         $array = json_encode(['result' => false, 'msg' => ''.$a->message.'']);
  136.     }
  137.     return $array;
  138. }
  139.  
  140. function masuk($username, $password)
  141. {
  142.     $login = json_decode(login($username, $password));
  143.     if ($login->result == true) {
  144.         $file = fopen("$username.ig", "w");
  145.         fwrite($file, json_encode(array(
  146.             'cookies' => $login->cookies,
  147.             'useragent' => $login->useragent,
  148.             //'id' => $login->id,
  149.             'device_id' => $login->devid,
  150.             'username' => $login->username,
  151.             'password' => $login->password
  152.         )));
  153.         fclose($file);
  154.         return "data berhasil diinput\n";
  155.     } else {
  156.         return "Gagal login\n";
  157.     }
  158. }
  159. print_r(login($user,$pass));
  160. print_r(masuk($user,$pass));
  161. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement