-
Notifications
You must be signed in to change notification settings - Fork 2
/
Requester.cs
383 lines (341 loc) · 16.1 KB
/
Requester.cs
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
using System;
using System.Collections.Generic;
using System.Net;
using MSC.Hash;
using System.Text.RegularExpressions;
using System.Drawing;
namespace MSC.Brute
{
public class RequestManage
{
public WebHeaderCollection Headers { set; get; }
public string SourcePage { set; get; }
public CookieContainer Cookies { set; get; }
public int StatusCode { set; get; }
public string CookiesString { set; get; }
public bool ErrorAst { get; set; }
public string Location { get; set; }
public string RedirectedUrl { set; get; }
public byte[] Bytes { set; get; }
public override string ToString()
{
return string.Format("Headers: {0}\nStatusCode: {1}\nCookies: {2}\nErrorAst: {3}\nLocation: {4}\nRedirectedUrl: {5}", Headers.ToString(), StatusCode.ToString(), CookiesString, ErrorAst.ToString(), Location, RedirectedUrl);
}
}
public class Token
{
public string RegexPattern { set; get; }
public List<string> GrpValue { set; get; }
public MatchCollection Matchs { get; set; }
public RequestManage Manage { set; get; }
}
public class Proxy
{
public string Ip { set; get; }
public int Port { set; get; }
public string Username { set; get; }
public string Password { set; get; }
public static Proxy Parse(string proxy)
{
try {
Proxy newproxy = new Proxy();
newproxy.Ip = proxy.Split(':')[0];
newproxy.Port = int.Parse(proxy.Split(':')[1]);
return newproxy;
}
catch
{
throw new Exception("Can not pars string.");
}
}
public override string ToString()
{
return string.Format("{0}:{1}@{2};{3}", Ip, Port.ToString(), Username, Password);
}
}
public class Account
{
public string Username { set; get; }
public string Password { set; get; }
public string Capture { set; get; }
public bool Hit { set; get; }
public override string ToString()
{
return string.Format("{0}:{1}", Username, Password);
}
}
public class Requester
{
public Logger logger = new Logger();
Requests Rs = new Requests();
public void SetLogger(Logger logg, bool SetOnCore = false)
{
logger = logg;
if (SetOnCore)
Rs.SetLogger(logger);
}
public Logger GetCoreLogger()
{
return Rs.GetLogger();
}
public Logger GetBaseLogger()
{
return logger;
}
/// <summary>
/// GetToken in page for Secound request (List Token)
/// </summary>
/// <param name="Tokken">Token List array for get all value grupe in request.</param>
/// <param name="config">Config for Request.</param>
/// <param name="manage">Keep your request by cookies.</param>
/// <param name="Proxy">Send request by proxy service.</param>
public List<Token> GetToken(List<Token> Tokken, Config config, RequestManage manage = null, Proxy Proxy = null)
{
config.Method = Method.GET;
logger.AddMessage("Method config automatic seted on GET", Log.Type.Infomation);
RequestManage man = GETData(config, manage, Proxy);
List<Token> end = new List<Token>();
foreach (Token tok in Tokken)
{
Token tik = new Token();
tik = tok;
Match match = Regex.Match(man.SourcePage, tik.RegexPattern);
tik.Matchs = Regex.Matches(man.SourcePage, tik.RegexPattern);
tik.GrpValue = new List<string>();
for (int i = 1; i <= match.Groups.Count; i++)
{
if (match.Groups[i].Success)
tik.GrpValue.Add(match.Groups[i].Value.ToString());
}
logger.AddMessage("Found " + match.Groups.Count.ToString() + " Groups in Regexing.", Log.Type.Infomation);
tik.Manage = man;
logger.AddMessage("RequestManage OutPut\nSoucePage:\n" + man.SourcePage + "\n\nCookies:\n" + Utils.GetCookiesString(man.Cookies, config) + "\n\nHeaders:\n" + man.Headers.ToString(), Log.Type.OutPut);
end.Add(tik);
}
return end;
}
/// <summary>
/// GetToken in page for Secound request (One Token)
/// </summary>
/// /// <param name="Tokken">Token for get all value grupe in request.</param>
/// <param name="config">Config for Request.</param>
/// <param name="manage">Keep your request by cookies.</param>
/// <param name="Proxy">Send request by proxy service.</param>
public Token GetToken(Token Tokken, Config config, RequestManage manage = null, Proxy Proxy = null)
{
Token end = new Token();
end = Tokken;
config.Method = Method.GET;
logger.AddMessage("Method config automatic seted on GET", Log.Type.Infomation);
RequestManage man = GETData(config, manage, Proxy);
Match match = Regex.Match(man.SourcePage, Tokken.RegexPattern);
end.Matchs = Regex.Matches(man.SourcePage, Tokken.RegexPattern);
end.GrpValue = new List<string>();
for (int i = 1; i <= match.Groups.Count; i++)
{
if (match.Groups[i].Success)
end.GrpValue.Add(match.Groups[i].Value.ToString());
}
logger.AddMessage("Found " + match.Groups.Count.ToString() + " Groups in Regexing.", Log.Type.Infomation);
end.Manage = man;
logger.AddMessage("RequestManage OutPut\nSoucePage:\n" + man.SourcePage + "\n\nCookies:\n" + Utils.GetCookiesString(man.Cookies, config) + "\n\nHeaders:\n" + man.Headers.ToString(), Log.Type.OutPut);
return end;
}
/// <summary>
/// GetToken in page for Secound request (One Value)
/// </summary>
/// <param name="RegexP">Regex Pattenrn for get request value.</param>
/// <param name="config">Config for Request.</param>
/// <param name="manage">Keep your request by cookies.</param>
/// <param name="Proxy">Send request by proxy service.</param>
public RequestManage GetToken(string RegexP, Config config, RequestManage manage = null, Proxy Proxt = null)
{
config.Method = Method.GET;
logger.AddMessage("Method config automatic seted on GET", Log.Type.Infomation);
RequestManage get = GETData(config, manage, Proxt);
Match match = Regex.Match(get.SourcePage, RegexP);
logger.AddMessage("Found " + match.Groups.Count.ToString() + " Groups in Regexing.", Log.Type.Infomation);
RequestManage end = get;
end.SourcePage = match.Groups[1].ToString();
logger.AddMessage("RequestManage OutPut\nSoucePage:\n" + end.SourcePage + "\n\nCookies:\n" + Utils.GetCookiesString(end.Cookies, config) + "\n\nHeaders:\n" + end.Headers.ToString(), Log.Type.OutPut);
return end;
}
/// <summary>
/// Check account and set capture by your setting in params
/// </summary>
/// <param name="ac">Account for check.</param>
/// <param name="config">Config for Request.</param>
/// <param name="manage">Keep your request by cookies.</param>
/// <param name="Proxy">Send request by proxy service.</param>
/// <param name="Caper">Capture array list for get capture account.</param>
public Account CheckAccount(Config config, Account ac, Capture[] Caper, RequestManage manage = null, Proxy proxy = null)
{
RequestManage Get = new RequestManage();
if (config.Method == Method.POST)
Get = POSTData(config, manage, proxy);
else if (config.Method == Method.GET)
Get = GETData(config, manage, proxy);
ac.Hit = isHit(config, Get.SourcePage);
if (Caper != null)
ac = CaptureAccount(Get.SourcePage, Caper, ac, config, manage, proxy);
logger.AddMessage("Account:\nUsername=" + ac.Username + "\nPassword=" + ac.Password + "\nHit=" + ac.Hit + "\nCapture=" + ac.Capture, Log.Type.OutPut);
return ac;
}
/// <summary>
/// Check account for Value
/// </summary>
/// <param name="config">Config for Request.</param>
/// <param name="manage">Keep your request by cookies.</param>
/// <param name="Proxy">Send request by proxy service.</param>
public bool CheckAccount(Config config, RequestManage Manage = null, Proxy proxy = null)
{
RequestManage Get = new RequestManage();
if (config.Method == Method.POST)
Get = POSTData(config, Manage, proxy);
else if (config.Method == Method.GET)
Get = GETData(config, Manage, proxy);
bool End = isHit(config, Get.SourcePage);
logger.AddMessage("Hit=" + End.ToString(), Log.Type.OutPut);
return End;
}
/// <summary>
/// Normal PostData
/// </summary>
/// <param name="config">Config for Request.</param>
/// <param name="manage">Keep your request by cookies.</param>
/// <param name="Proxy">Send request by proxy service.</param>
public RequestManage POSTData(Config config, RequestManage Manage = null, Proxy proxy = null)
{
config.Method = Method.POST;
logger.AddMessage("Method config automatic seted on POST", Log.Type.Infomation);
RequestManage Get = Rs.GetRequestByData(config, Manage, proxy);
return Get;
}
/// <summary>
/// Normal GETData
/// </summary>
/// <param name="config">Config for Request.</param>
/// <param name="manage">Keep your request by cookies.</param>
/// <param name="Proxy">Send request by proxy service.</param>
public RequestManage GETData(Config config, RequestManage Manage = null, Proxy proxy = null)
{
config.Method = Method.GET;
logger.AddMessage("Method config automatic seted on GET", Log.Type.Infomation);
RequestManage Get = Rs.GetPageSource(config, Manage, proxy);
return Get;
}
/// <summary>
/// Repleace username and password account in source whit Varible seeting in config
/// </summary>
/// <param name="ac">Account for replace in source.</param>
/// <param name="config">Config for Request.</param>
/// <param name="source">The base text for replace account into it.</param>
public string ReplaceAccount(Account ac, string source, Config config)
{
logger.AddMessage("Account:\nUsername=" + ac.Username + "\nPassword=" + ac.Password + "\nHit=" + ac.Hit + "\nCapture=" + ac.Capture, Log.Type.OutPut);
if (config.Varible.Count != 0)
{
foreach (HashType Item in config.Varible)
{
switch (Item)
{
case HashType.MD5:
ac.Password = Hashs.MD5(ac.Password);
logger.AddMessage("Password changed to MD5 : " + ac.Password, Log.Type.Infomation);
break;
case HashType.SHA1:
ac.Password = Hashs.SHA1(ac.Password);
logger.AddMessage("Password changed to SHA1 : " + ac.Password, Log.Type.Infomation);
break;
case HashType.SHA256:
ac.Password = Hashs.SHA256(ac.Password);
logger.AddMessage("Password changed to SHA256 : " + ac.Password, Log.Type.Infomation);
break;
case HashType.SHA512:
ac.Password = Hashs.SHA512(ac.Password);
logger.AddMessage("Password changed to SHA512 : " + ac.Password, Log.Type.Infomation);
break;
case HashType.Base64:
ac.Password = Hashs.StringToBase64(ac.Password);
logger.AddMessage("Password changed to Base64 : " + ac.Password, Log.Type.Infomation);
break;
}
}
}
try {
string[] userpass = config.DataSet.Split('*');
source = source.Replace(userpass[0], ac.Username).Replace(userpass[1], ac.Password);
}
catch(Exception ex) { logger.AddMessage("Error: " + ex.Message, Log.Type.Error); }
logger.AddMessage("OutPut Source: " + source, Log.Type.OutPut);
return source;
}
/// <summary>
/// Capture account whit setting
/// </summary>
/// <param name="Account">Account for capture.</param>
/// <param name="config">Config for Request.</param>
/// <param name="manage">Keep your request by cookies.</param>
/// <param name="Proxy">Send request by proxy service.</param>
/// <param name="Capture">Capture array list for get capture account.</param>
/// <param name="source">The source page for search values in Regex Capture.</param>
public Account CaptureAccount(string source, Capture[] Capture, Account Account, Config config, RequestManage manage = null, Proxy Proxy = null)
{
RequestManage manage2 = new RequestManage();
string end = "";
manage2.SourcePage = source;
foreach (Capture cap in Capture)
{
manage2.SourcePage = source;
config.LoginURL = cap.Redirect;
if (cap.Redirect != null)
{
if (config.Method == Method.GET)
manage2 = GETData(config, cap.UseCookies ? manage : null, Proxy);
else if (config.Method == Method.POST)
{
manage2 = POSTData(config, cap.UseCookies ? manage : null, Proxy);
}
}
if (cap.RemoveLines)
manage2.SourcePage = source.Replace("\n", "");
if (cap.RemoveSpaseChars)
manage2.SourcePage = source.Replace(" ", "");
if (cap.Remove2SpaseChars)
manage2.SourcePage = source.Replace(" ", "");
MatchCollection match = Regex.Matches(manage2.SourcePage, cap.Regex);
for (int i = 0; i < match.Count; i++)
if (i < cap.MaxMatchs)
for (int j = 1; j <= match[i].Groups.Count; j++)
if (match[i].Groups[j].Success)
end += cap.Lable[i] + match[i].Groups[j].ToString() + " # ";
end += " | ";
}
Account.Capture = end;
logger.AddMessage("Account:\nUsername=" + Account.Username + "\nPassword=" + Account.Password + "\nHit=" + Account.Hit + "\nCapture=" + Account.Capture, Log.Type.OutPut);
return Account;
}
public bool isHit(Config config, string SourcePage)
{
bool flag = false;
bool End;
if (!flag)
{
End = SourcePage.Contains(config.SourceSuccess);
if (config.Contains)
{
if (End)
flag = true;
else flag = false;
}
else
{
if (!End)
flag = true;
else flag = false;
}
}
return flag;
}
}
}