Advertisement
Guest User

Untitled

a guest
Apr 13th, 2017
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.05 KB | None | 0 0
  1. <?php
  2. if (isset($_POST["submit"])) {
  3. $image = $_FILES["img"]["name"];
  4.  
  5.  
  6.  
  7. function SendRequest($url, $post, $post_data, $user_agent, $cookies) {
  8. $ch = curl_init();
  9. curl_setopt($ch, CURLOPT_URL, 'https://i.instagram.com/api/v1/'.$url);
  10. curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
  11. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  12. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  13.  
  14. if($post) {
  15. curl_setopt($ch, CURLOPT_POST, true);
  16. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  17. }
  18.  
  19. if($cookies) {
  20. curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
  21. } else {
  22. curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
  23. }
  24.  
  25. $response = curl_exec($ch);
  26. $http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  27. curl_close($ch);
  28.  
  29. return array($http, $response);
  30. }
  31.  
  32. function GenerateGuid() {
  33. return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
  34. mt_rand(0, 65535),
  35. mt_rand(0, 65535),
  36. mt_rand(0, 65535),
  37. mt_rand(16384, 20479),
  38. mt_rand(32768, 49151),
  39. mt_rand(0, 65535),
  40. mt_rand(0, 65535),
  41. mt_rand(0, 65535));
  42. }
  43.  
  44. function GenerateUserAgent() {
  45. $resolutions = array('720x1280', '320x480', '480x800', '1024x768', '1280x720', '768x1024', '480x320');
  46. $versions = array('GT-N7000', 'SM-N9000', 'GT-I9220', 'GT-I9100');
  47. $dpis = array('120', '160', '320', '240');
  48.  
  49. $ver = $versions[array_rand($versions)];
  50. $dpi = $dpis[array_rand($dpis)];
  51. $res = $resolutions[array_rand($resolutions)];
  52.  
  53. return 'Instagram 4.'.mt_rand(1,2).'.'.mt_rand(0,2).' Android ('.mt_rand(10,11).'/'.mt_rand(1,3).'.'.mt_rand(3,5).'.'.mt_rand(0,5).'; '.$dpi.'; '.$res.'; samsung; '.$ver.'; '.$ver.'; smdkc210; en_US)';
  54. }
  55.  
  56. function GenerateSignature($data) {
  57. return hash_hmac('sha256', $data, 'b4a23f5e39b5929e0666ac5de94c89d1618a2916');
  58. }
  59.  
  60. function GetPostData($filename) {
  61. if(!$filename) {
  62. echo "The image doesn't exist ".$filename;
  63. } else {
  64. $post_data = array('device_timestamp' => time(),
  65. 'photo' => '@'.$filename);
  66. return $post_data;
  67. }
  68. }
  69.  
  70.  
  71. // Set the username and password of the account that you wish to post a photo to
  72. $username = '*****';
  73. $password = '*****';
  74.  
  75. // Set the path to the file that you wish to post.
  76. // This must be jpeg format and it must be a perfect square
  77. $filename = $image;
  78. //$filename = 'pictures/test.jpg';
  79.  
  80. // Set the caption for the photo
  81. $caption = "Test caption";
  82.  
  83. // Define the user agent
  84. $agent = GenerateUserAgent();
  85.  
  86. // Define the GuID
  87. $guid = GenerateGuid();
  88.  
  89. // Set the devide ID
  90. $device_id = "android-".$guid;
  91.  
  92. /* LOG IN */
  93. // You must be logged in to the account that you wish to post a photo too
  94. // Set all of the parameters in the string, and then sign it with their API key using SHA-256
  95. $data ='{"device_id":"'.$device_id.'","guid":"'.$guid.'","username":"'.$username.'","password":"'.$password.'","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"}';
  96. $sig = GenerateSignature($data);
  97. $data = 'signed_body='.$sig.'.'.urlencode($data).'&ig_sig_key_version=4';
  98. $login = SendRequest('accounts/login/', true, $data, $agent, false);
  99. print_r($login);
  100. if(strpos($login[1], "Sorry, an error occurred while processing this request.")) {
  101. echo "Request failed, there's a chance that this proxy/ip is blocked";
  102. } else {
  103. if(empty($login[1])) {
  104. echo "Empty response received from the server while trying to login";
  105. } else {
  106. // Decode the array that is returned
  107. $obj = @json_decode($login[1], true);
  108.  
  109. if(empty($obj)) {
  110. echo "Could not decode the response: ".$body;
  111. } else {
  112. // Post the picture
  113. $data = GetPostData($filename);
  114. $post = SendRequest('media/upload/', true, $data, $agent, true);
  115.  
  116. if(empty($post[1])) {
  117. echo "Empty response received from the server while trying to post the image";
  118. } else {
  119. // Decode the response
  120. $obj = @json_decode($post[1], true);
  121.  
  122. if(empty($obj)) {
  123. echo "Could not decode the response";
  124. } else {
  125. $status = $obj['status'];
  126.  
  127. if($status == 'ok') {
  128. // Remove and line breaks from the caption
  129. $caption = preg_replace("/r|n/", "", $caption);
  130.  
  131. $media_id = $obj['media_id'];
  132. $device_id = "android-".$guid;
  133. $data = '{"device_id":"'.$device_id.'","guid":"'.$guid.'","media_id":"'.$media_id.'","caption":"'.trim($caption).'","device_timestamp":"'.time().'","source_type":"5","filter_type":"0","extra":"{}","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"}';
  134. $sig = GenerateSignature($data);
  135. $new_data = 'signed_body='.$sig.'.'.urlencode($data).'&ig_sig_key_version=4';
  136.  
  137. // Now, configure the photo
  138. $conf = SendRequest('media/configure/', true, $new_data, $agent, true);
  139.  
  140. if(empty($conf[1])) {
  141. echo "Empty response received from the server while trying to configure the image";
  142. } else {
  143. if(strpos($conf[1], "login_required")) {
  144. echo "You are not logged in. There's a chance that the account is banned";
  145. } else {
  146. $obj = @json_decode($conf[1], true);
  147. $status = $obj['status'];
  148.  
  149. if($status != 'fail') {
  150. echo "Success";
  151. } else {
  152. echo 'Fail';
  153. }
  154. }
  155. }
  156. } else {
  157. echo "Status isn't okay";
  158. }
  159. }
  160. }
  161. }
  162. }
  163. }
  164. }
  165. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement