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