· 6 years ago · Jul 26, 2019, 08:26 AM
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using System.Net;
7using System.IO;
8using System.Text.RegularExpressions;
9using System.Security.Cryptography;
10using System.Threading;
11using System.Diagnostics;
12using System.Windows.Forms;
13
14namespace InstaRegister
15{
16 class Client : WebClient
17 {
18 public static string username = "";
19 public static string password = "";
20 public static int port = 22225;
21 public static int max_failures = 3;
22 public static Random rng = new Random();
23 public string session_id;
24 public string login;
25 public string country;
26 public int fail_count;
27 public int n_req_for_exit_node;
28 public HashSet<ServicePoint> service_points;
29 public string proxy_ip;
30 CookieContainer Cookies = new CookieContainer();
31
32 public Client(string proxy_ip, string country = null)
33 {
34 this.country = country;
35 this.proxy_ip = proxy_ip;
36 service_points = new HashSet<ServicePoint>();
37 switch_session_id();
38 }
39
40 public void switch_session_id()
41 {
42 clean_connection_pool();
43 session_id = rng.Next().ToString();
44 n_req_for_exit_node = 0;
45 update_super_proxy();
46 }
47
48 public void update_super_proxy()
49 {
50 Proxy = new WebProxy("session-" + session_id + ".zproxy.lum-superproxy.io", port);
51 login = username + (country != null ? "-country-" + country : "")
52 + "-session-" + session_id;
53 Proxy.Credentials = new NetworkCredential(login, password);
54 }
55
56 public void clean_connection_pool()
57 {
58 foreach (ServicePoint sp in service_points)
59 sp.CloseConnectionGroup(login);
60 service_points.Clear();
61 }
62
63 public bool have_good_super_proxy()
64 {
65 return fail_count < max_failures;
66 }
67
68 public void handle_response(WebException e = null)
69 {
70 if (e != null && should_switch_exit_node((HttpWebResponse)e.Response))
71 {
72 switch_session_id();
73 fail_count++;
74 return;
75 }
76 // success or other client/website error like 404...
77 n_req_for_exit_node++;
78 fail_count = 0;
79 }
80
81 public bool should_switch_exit_node(HttpWebResponse response)
82 {
83 return response == null ||
84 status_code_requires_exit_node_switch((int)response.StatusCode);
85 }
86
87 public bool status_code_requires_exit_node_switch(int code)
88 {
89 return code == 403 || code == 429 || code == 502 || code == 503;
90 }
91
92 protected override WebRequest GetWebRequest(Uri address)
93 {
94 var request = base.GetWebRequest(address) as HttpWebRequest;
95 request.AutomaticDecompression = DecompressionMethods.GZip;
96 WebHeaderCollection postHeaders = request.Headers;
97 request.Method = "POST";
98 request.Host = "i.instagram.com";
99 request.UserAgent = "Instagram 63.0.0.17.94 Android (26/8.0.0; 480dpi; 1080x1920; samsung; SM-A520F; a5y17lte; samsungexynos7880; ru_RU; 124584015)";
100 request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
101 postHeaders.Add("Cookie2", "$Version=1");
102 postHeaders.Add("Accept-Language", "en-US");
103 postHeaders.Add("X-IG-Connection-Type", "WIFI");
104 postHeaders.Add("X-IG-Capabilities", "BQ==");
105 postHeaders.Add("Accept-Encoding", "gzip");
106 request.ConnectionGroupName = login;
107 request.PreAuthenticate = true;
108 return request;
109 }
110
111 protected override WebResponse GetWebResponse(WebRequest request)
112 {
113 var x = (WebResponse)null;
114 try
115 {
116 var response = base.GetWebResponse(request);
117 x = response;
118 ServicePoint sp = ((HttpWebRequest)request).ServicePoint;
119 service_points.Add(sp);
120 }
121 catch (WebException error)
122 {
123 x = (WebResponse)error.Response;
124 }
125 return x;
126 }
127 }
128 class Account
129 {
130
131
132 public static int n_parallel_exit_nodes = 1;
133 public static int n_total_req = 1;
134 public static int switch_ip_every_n_req = 1;
135 public static int at_req = 0;
136 public static string super_proxy_ip;
137 private Random rnd = new Random();
138 private readonly Encoding encoding = Encoding.UTF8;
139
140 private const string SecretKey = "3f0a7d75e094c7385e3dbaa026877f2e067cbd1a4dbcf3867748f6b26f257117";
141 private string DeviceID = null;
142 private string guid = null;
143 private string CSRF = null;
144 private string mid = null;
145 CookieContainer Cookies = new CookieContainer();
146 public string session_id = new Random().Next().ToString();
147 public string Accountx(string Password, string Lumiuser, string Lumipass)
148 {
149 DeviceID = "android-" + HMAC(rnd.Next(1000, 9999).ToString(), "1337").ToString().Substring(0, Math.Min(64, 16));
150 guid = RandomString(8) + "-" + RandomString(4) + "-" + RandomString(4) + "-" + RandomString(4) + "-" + RandomString(12);
151 mid = "VjzMwwAEAAGFO33NbLSpjPGBnXJ_";
152 string url = "https://instagram.com/";
153 string step1 = GetHTML(url, Lumiuser, Lumipass);
154 if (step1.Contains("sai pass"))
155 {
156 return "sai pass";
157 }
158 else
159 {
160 CSRF = GetCSRF(GetHTML(url, Lumiuser, Lumipass));
161 string abc = Register(Password, Lumiuser, Lumipass);
162 return abc;
163 }
164 }
165
166 public string Register(string Password, string Lumiuser, string Lumipass)
167 {
168 string country = null;
169 string Username = randomacc(10);
170 string Email = randomacc(10) + "@gmail.com";
171 string Config = @"{""username"":""" + Username + @""",""first_name"":""Name"",""password"":""" + Password + @""",""guid"":""" + guid + @""",""email"":""" + Email + @""",""device_id"":""" + DeviceID + @"""}";
172 byte[] bytes = ASCIIEncoding.UTF8.GetBytes("signed_body=" + HMAC(Config, SecretKey) + "." + EncodeUrl(Config) + "&ig_sig_key_version=4");
173 var client = new Client(super_proxy_ip);
174
175 if (!client.have_good_super_proxy())
176 client.switch_session_id();
177 if (client.n_req_for_exit_node == switch_ip_every_n_req)
178 client.switch_session_id();
179 string status = "";
180 try
181 {
182 client.Headers.Add(HttpRequestHeader.Cookie,
183 "csrftoken = " + CSRF + ";" +
184 "mid = XQGEIQALAAG4YNOVnBcb5tJFUjEE");
185 byte[] myStream2 = client.UploadData("https://i.instagram.com/api/v1/accounts/create/", bytes);
186 string s = client.Encoding.GetString(myStream2);
187 Debug.WriteLine(s);
188 if (s.Contains("created_user"))
189 {
190 status = Username + "|ok";
191 } else if (s.Contains("feedback_required"))
192 {
193 status = "loi proxy";
194 }
195 }
196 catch (WebException e)
197 {
198 Console.WriteLine(e.Message);
199 client.handle_response(e);
200 }
201
202 client.clean_connection_pool();
203 client.Dispose();
204
205 return status;
206 }
207
208 private string GetCSRF(string HTML)
209 {
210 Regex Regex = new Regex(@"csrf_token"":""(.*)"",""");
211 string abc = Regex.Match(HTML).Groups[1].ToString();
212 string[] combo = abc.Split(new String[] { "," }, StringSplitOptions.None);
213 return Regex.Replace(combo[0], "[^a-zA-Z0-9_.]+", "", RegexOptions.Compiled);
214 }
215
216 private string GetHTML(string url, string lumiuser, string lumipass)
217 {
218 ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
219 HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
220 IWebProxy proxy = new WebProxy("zproxy.lum-superproxy.io:22225");
221 proxy.Credentials = new NetworkCredential(lumiuser, lumipass);
222 myRequest.Proxy = proxy;
223 WebHeaderCollection getHeaders = myRequest.Headers;
224 myRequest.Method = "GET";
225 myRequest.CookieContainer = Cookies;
226 string result = "";
227 try
228 {
229 WebResponse myResponse = myRequest.GetResponse();
230 StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);
231 try
232 {
233 result = sr.ReadToEnd();
234 sr.Close();
235 myResponse.Close();
236 }
237 catch (IOException) { }
238
239 }
240 catch (WebException error)
241 {
242 if(error.ToString().Contains("(407) Proxy Authentication Required"))
243 {
244 result = "sai pass";
245 }
246 }
247 return result;
248 }
249
250 private string ByteToString(byte[] buff)
251 {
252 string sbinary = "";
253 for (int i = 0; i < buff.Length; i++)
254 sbinary += buff[i].ToString("X2");
255 return sbinary;
256 }
257
258 private string HMAC(string String, string Key)
259 {
260 var keyByte = encoding.GetBytes(Key);
261 using (var hmacsha256 = new HMACSHA256(keyByte))
262 {
263 hmacsha256.ComputeHash(encoding.GetBytes(String));
264 return ByteToString(hmacsha256.Hash).ToLower();
265 }
266 }
267
268 private string RandomString(int length)
269 {
270 const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
271 var random = new Random();
272 return new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray()).ToLower();
273 }
274 private string randomacc(int length)
275 {
276 const string chars = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890.";
277 var random = new Random();
278 return new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray()).ToLower();
279 }
280 private string EncodeUrl(string Url)
281 {
282 return System.Uri.EscapeDataString(Url);
283 }
284 }
285}