-
Notifications
You must be signed in to change notification settings - Fork 1
/
untMain.pas
684 lines (497 loc) · 19.2 KB
/
untMain.pas
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
unit untMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, untVariables, untIniSettings, untGenericProcedures, ComCtrls, Clipbrd,
untLog, StdCtrls, untFileVersion, Menus, ExtCtrls, untCURL, IdHTTP, IdIOHandlerStack,
IdStackConsts, idWinsock2, LMDCustomComponent, LMDStarter, Buttons, Htmlview, shellAPI;
type
TfrmMain = class(TForm)
StatusBar: TStatusBar;
tmrStarup: TTimer;
LMDS: TLMDStarter;
PageControl: TPageControl;
tabExploitation: TTabSheet;
grpSimple: TGroupBox;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Bevel1: TBevel;
Label5: TLabel;
labResultOfTheTest: TLabel;
edtURL: TEdit;
radGetRequest: TRadioButton;
radPostRequest: TRadioButton;
memPostParameters: TMemo;
btnTestConditionTrue: TButton;
btnTestConditionFalse: TButton;
btnGetXML: TButton;
grpResults: TGroupBox;
memResults: TMemo;
tabOptions: TTabSheet;
grpOptions: TGroupBox;
Label1: TLabel;
memCharset: TMemo;
chkUseCURL: TCheckBox;
pnlKeywords: TPanel;
edtKeywordTrue: TEdit;
radConditionTrue: TRadioButton;
radConditionFalse: TRadioButton;
edtKeywordFalse: TEdit;
chkUseProxy: TCheckBox;
Label6: TLabel;
edtProxyServerIP: TEdit;
Label7: TLabel;
edtProxyServerPort: TEdit;
grpCustomHeader: TGroupBox;
chkUseCustomHTTPHeader: TCheckBox;
memCustomHTTPHeader: TMemo;
tabAbout: TTabSheet;
btnCopyToClipboard: TSpeedButton;
btnSaveToFile: TSpeedButton;
tmrUpdateProxy: TTimer;
dlgSave: TSaveDialog;
HTMLViewer: THTMLViewer;
Label8: TLabel;
pnlExploitationType: TPanel;
radStringBasedExploit: TRadioButton;
radIntegerBasedExploit: TRadioButton;
grpDataExtractionOptions: TGroupBox;
chkOptExtractAttributes: TCheckBox;
chkOptExtractComments: TCheckBox;
chkOptExtractNodeValues: TCheckBox;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure radConditionTrueClick(Sender: TObject);
procedure radConditionFalseClick(Sender: TObject);
procedure radGetRequestClick(Sender: TObject);
procedure radPostRequestClick(Sender: TObject);
procedure tmrStarupTimer(Sender: TObject);
procedure btnTestConditionTrueClick(Sender: TObject);
procedure btnTestConditionFalseClick(Sender: TObject);
procedure Getnumberofrootnodes1Click(Sender: TObject);
procedure btnGetXMLClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure chkUseProxyClick(Sender: TObject);
procedure edtProxyServerIPChange(Sender: TObject);
procedure edtProxyServerPortChange(Sender: TObject);
procedure tmrUpdateProxyTimer(Sender: TObject);
procedure chkUseCustomHTTPHeaderClick(Sender: TObject);
procedure btnSaveToFileClick(Sender: TObject);
procedure btnCopyToClipboardClick(Sender: TObject);
procedure HTMLViewerHotSpotClick(Sender: TObject; const SRC: string;
var Handled: Boolean);
private
{ Private declarations }
public
procedure SetCondition(param: string);
function GetCondition: string;
procedure SetRequestType(param: string);
function GetRequestType: string;
procedure useProxy(param: string; param2: boolean);
function GetProxyInUse: string;
procedure curlInUse(param: string);
function GetCurlInUse: string;
procedure CustomHTTPHeaderInUse(param: string; param2: boolean);
function GetCustomHTTPHeaderInUse: string;
procedure SetExploitationType(param: string);
function GetExploitationType: string;
end;
var
frmMain: TfrmMain;
implementation
{$R *.dfm}
{$R resources.RES}
//---------------------------------------------------------on the very beginning
procedure TfrmMain.FormCreate(Sender: TObject);
var
mySettings: string;
rs: TResourceStream;
begin
Randomize;
//-------- initialize dirs
currentDir := ExtractFileDir(paramstr(0));
currentIniSettingsFileName := currentDir + '\' + iniSettingsFileName;
currentLogFileName := currentDir + '\' + logFileName;
Application.Title := 'XPath Blind Explorer (ver.: ' + strBuildInfo + ')';
caption := Application.Title;
//-------- start log file
logOptions := ''; //---can be: [empty], file, file-rewite, screen, both, both-rewrite
LogInint;
Log('Application started');
//-------- enable double-buffering for win controls (remember: TRichEdit is exclusion, so dbl-buff should be switched off for it!)
EnableDoubleBuffering(frmMain, true);
dlgSave.InitialDir := currentDir;
myClip := TClipboard.Create;
pageControl.TabIndex := 0;
//-------- load settings form INI
if paramstr(1) = '' then mySettings := currentIniSettingsFileName else mySettings := paramstr(1);
if fileexists(mySettings) then LoadSettingsFromIni(mySettings) else
begin
application.MessageBox('Where is config file, may I ask you?...', 'Error', MB_OK);
application.ShowMainForm := false;
application.Terminate;
end;
batchFile := currentDir + '\tmp\run.cmd';
resultFile := currentDir + '\tmp\result.htm';
tempCurlConfig := currentDir + '\tmp\curl.tmp_config';
sourceHTTPHeader := currentDir + '\curl.default_config';
curlExe := currentDir + '\curl.exe';
forceDirectories(currentDir + '\tmp');
createBatchFile;
global_stop := true;
labResultOfTheTest.Caption := '';
//--- load texts from resources
rs := TResourceStream.Create(hInstance, PChar('license'), RT_RCDATA);
HTMLViewer.LoadFromStream(rs, '');
myLoader := TIdHTTP.Create(nil); //--- initialize loader
end;
//-----------------------------------------------------------------startup timer
procedure TfrmMain.tmrStarupTimer(Sender: TObject);
begin
tmrStarup.Enabled := false;
btnGetXML.SetFocus;
end;
//------------------------------------------------------------------update proxy
procedure TfrmMain.edtProxyServerIPChange(Sender: TObject);
begin
tmrUpdateproxy.Enabled := true;
end;
procedure TfrmMain.edtProxyServerPortChange(Sender: TObject);
begin
tmrUpdateproxy.Enabled := true;
end;
procedure TfrmMain.tmrUpdateProxyTimer(Sender: TObject);
begin
tmrUpdateProxy.Enabled := false;
if frmMain.chkUseProxy.Checked = true then
begin
myLoader.ProxyParams.ProxyServer := frmMain.edtProxyServerIP.Text;
myLoader.ProxyParams.ProxyPort := strToInt(frmMain.edtProxyServerPort.Text);
end else
begin
myLoader.ProxyParams.ProxyServer := '';
myLoader.ProxyParams.ProxyPort := 0;
end;
end;
//----------------------------set exploitation type (string or integer - based)
procedure TfrmMain.SetExploitationType(param: string);
begin
if param = 'string-based' then //--- condition "string-based" enabled
begin
radStringBasedExploit.Checked := true;
end else
if param = 'integer-based' then //--- condition "integer-based" enabled
begin
radIntegerBasedExploit.Checked := true;
end;
end;
//----------------------------get exploitation type (string or integer - based)
function TfrmMain.GetExploitationType: string;
begin
if radStringBasedExploit.Checked = true then result := 'string-based'
else if radIntegerBasedExploit.Checked = true then result := 'integer-based';
end;
//---------------------------------switch on/off custom HTTP header (true/false)
procedure TfrmMain.CustomHTTPHeaderInUse(param: string; param2: boolean);
begin
if param = 'true' then //--- condition "true" enabled
begin
if param2 = true then chkUseCustomHTTPHeader.Checked := true;
memCustomHTTPHeader.Enabled := true;
memCustomHTTPHeader.Color := clWhite;
end else
if param = 'false' then //--- condition "false" enabled
begin
if param2 = true then chkUseCustomHTTPHeader.Checked := false;
memCustomHTTPHeader.Enabled := false;
memCustomHTTPHeader.Color := clBtnFace;
end;
end;
//---------------------------------------get status of custom HTTP header switch
function TfrmMain.GetCustomHTTPHeaderInUse: string;
begin
if chkUseCustomHTTPHeader.Checked = true then result := 'true'
else if chkUseCustomHTTPHeader.Checked = false then result := 'false';
end;
procedure TfrmMain.chkUseCustomHTTPHeaderClick(Sender: TObject);
begin
if chkUseCustomHTTPHeader.Checked = true then CustomHTTPHeaderInUse('true', false) else CustomHTTPHeaderInUse('false', false);
end;
//----------------------------------------------------set condition (true/false)
procedure TfrmMain.SetCondition(param: string);
begin
if param = 'true' then //--- condition "true" enabled
begin
radConditionTrue.Checked := true;
edtKeywordTrue.Enabled := true;
edtKeywordTrue.Color := $00E8FEFF;
edtKeywordFalse.Enabled := false;
edtKeywordFalse.Color := clBtnFace;
end else
if param = 'false' then //--- condition "false" enabled
begin
radConditionFalse.Checked := true;
edtKeywordFalse.Enabled := true;
edtKeywordFalse.Color := $00E8FEFF;
edtKeywordTrue.Enabled := false;
edtKeywordTrue.Color := clBtnFace;
end;
end;
//---------------------------------------------------------get current condition
function TfrmMain.GetCondition: string;
begin
if radConditionTrue.Checked then result := 'true'
else if radConditionFalse.Checked then result := 'false';
end;
//--------------------------------------------------------------use proxy or not
procedure TfrmMain.useProxy(param: string; param2: boolean);
begin
if param = 'true' then //--- condition "true" enabled
begin
if param2 = true then chkUseProxy.Checked := true;
edtProxyServerIP.Enabled := true;
edtProxyServerIP.Color := clWhite;
edtProxyServerPort.Enabled := true;
edtProxyServerPort.Color := clWhite;
end else
if param = 'false' then //--- condition "false" enabled
begin
if param2 = true then chkUseProxy.Checked := false;
edtProxyServerIP.Enabled := false;
edtProxyServerIP.Color := clBtnFace;
edtProxyServerPort.Enabled := false;
edtProxyServerPort.Color := clBtnFace;
end;
end;
//------------------------------------------------------------switch proxy usage
procedure TfrmMain.chkUseProxyClick(Sender: TObject);
begin
if chkUseProxy.Checked = true then useProxy('true', false) else useProxy('false', false);
tmrUpdateproxy.Enabled := true;
end;
//---------------------------------------------------check if we are using proxy
function TfrmMain.GetProxyInUse: string;
begin
if chkUseProxy.Checked = true then result := 'true'
else if chkUseProxy.Checked = false then result := 'false';
end;
//-----------------------------------------------set checkbox: if CURL is in use
procedure TfrmMain.curlInUse(param: string);
begin
if param = 'true' then chkUseCURL.checked := true
else if param = 'false' then chkUseCURL.checked := false;
end;
//----------------------------------------------------check if we are using CURL
function TfrmMain.GetCurlInUse: string;
begin
if chkUseCURL.checked = true then result := 'true'
else if chkUseCURL.checked = false then result := 'false';
end;
//----------------------------------------------------switch to "true" condition
procedure TfrmMain.radConditionTrueClick(Sender: TObject);
begin
SetCondition('true');
end;
//---------------------------------------------------switch to "false" condition
procedure TfrmMain.radConditionFalseClick(Sender: TObject);
begin
SetCondition('false');
end;
//--------------------------------------------------------------set request type
procedure TfrmMain.SetRequestType(param: string);
begin
if param = 'get' then
begin
radGetRequest.Checked := true;
memPostParameters.Enabled := false;
memPostParameters.Color := clBtnFace;
end else
if param = 'post' then
begin
radPostRequest.Checked := true;
memPostParameters.Enabled := true;
memPostParameters.Color := clWhite;
end;
end;
//---------------------------------------------------get current type of request
function TfrmMain.GetRequestType: string;
begin
if radGetRequest.Checked then result := 'get'
else if radPostRequest.Checked then result := 'post';
end;
procedure TfrmMain.HTMLViewerHotSpotClick(Sender: TObject; const SRC: string;
var Handled: Boolean);
begin
ShellExecute(self.WindowHandle, 'open', pchar(HTMLViewer.LinkAttributes.Values['href']), nil, nil, SW_SHOWNORMAL);
end;
//---------------------------------------------------------------use GET request
procedure TfrmMain.radGetRequestClick(Sender: TObject);
begin
SetRequestType('get');
end;
//--------------------------------------------------------------use POST request
procedure TfrmMain.radPostRequestClick(Sender: TObject);
begin
SetRequestType('post');
end;
//---------------------------------------------------------test condition "TRUE"
procedure TfrmMain.btnTestConditionTrueClick(Sender: TObject);
var r: boolean;
myLoader: TIdHTTP;
url: string;
begin
btnTestConditionTrue.Enabled := false;
labResultOfTheTest.Caption := '';
myLoader := TIdHTTP.Create(nil);
application.ProcessMessages;
r := false;
//---------------------------------GET REQUEST
if radGetRequest.Checked then
begin
statusBar.Panels[1].Text := 'Testing: ' + URLEncode(TrimPayload(adv_test_payload_condition_true));
if global_use_curl then //-- use CURL
begin
GenerateGETRequest(sourceHTTPHeader,
URLEncode(trim(edtURL.Text) + TrimPayload(adv_test_payload_condition_true)));
r := testPayload(edtKeywordTrue.text);
end else
begin
URL := URLEncode(trim(frmMain.edtURL.Text) + TrimPayload(adv_test_payload_condition_true));
r := testPayload2(frmMain.edtKeywordTrue.text, GenerateGETRequest2(url, memCustomHTTPHeader.Text));
end;
end else
//---------------------------------POST REQUEST
if radPostRequest.Checked then
begin
if global_use_curl then //-- use CURL
begin
GeneratePOSTRequest(sourceHTTPHeader,
URLEncode(trim(edtURL.Text)),
URLEncode(trim(memPostParameters.Text) + TrimPayload(adv_test_payload_condition_true)));
r := testPayload(edtKeywordTrue.text);
end else
begin
URL := URLEncode(trim(frmMain.edtURL.Text));
r := testPayload2(frmMain.edtKeywordTrue.text, GeneratePOSTRequest2(url,
memPostParameters.Text + TrimPayload(adv_test_payload_condition_true),
memCustomHTTPHeader.Text));
end;
end;
if r = true then
begin
labResultOfTheTest.Font.Color := clBlack;
labResultOfTheTest.Caption := 'The test passsed! The "true" keyword IS found. :-)';
end else
begin
labResultOfTheTest.Font.Color := clRed;
labResultOfTheTest.Caption := 'The test failed. The "true" keyword IS NOT found.';
end;
btnTestConditionTrue.Enabled := true;
myLoader.Free;
end;
//--------------------------------------------------------test condition "FALSE"
procedure TfrmMain.btnTestConditionFalseClick(Sender: TObject);
var r: boolean;
myLoader: TIdHTTP;
url: string;
begin
btnTestConditionFalse.Enabled := false;
labResultOfTheTest.Caption := '';
myLoader := TIdHTTP.Create(nil);
application.ProcessMessages;
r := false;
//---------------------------------GET REQUEST
if radGetRequest.Checked then
begin
statusBar.Panels[1].Text := 'Testing: ' + URLEncode(TrimPayload(adv_test_payload_condition_false));
if global_use_curl then //-- use CURL
begin
GenerateGETRequest(sourceHTTPHeader,
URLEncode(trim(edtURL.Text) + TrimPayload(adv_test_payload_condition_false)));
r := testPayload(edtKeywordTrue.text);
end else
begin
URL := URLEncode(trim(frmMain.edtURL.Text) + TrimPayload(adv_test_payload_condition_false));
r := testPayload2(frmMain.edtKeywordTrue.text, GenerateGETRequest2(url, memCustomHTTPHeader.Text));
end;
end else
//---------------------------------POST REQUEST
if radPostRequest.Checked then
begin
if global_use_curl then //-- use CURL
begin
GeneratePOSTRequest(sourceHTTPHeader,
URLEncode(trim(edtURL.Text)),
URLEncode(trim(memPostParameters.Text) + TrimPayload(adv_test_payload_condition_false)));
r := testPayload(edtKeywordTrue.text);
end else
begin
URL := URLEncode(trim(frmMain.edtURL.Text));
r := testPayload2(frmMain.edtKeywordTrue.text, GeneratePOSTRequest2(url,
memPostParameters.Text + TrimPayload(adv_test_payload_condition_false),
memCustomHTTPHeader.Text));
end;
end;
if r = false then
begin
labResultOfTheTest.Font.Color := clBlack;
labResultOfTheTest.Caption := 'The test passsed! The "true" keyword IS NOT found. :-)';
end else
begin
labResultOfTheTest.Font.Color := clRed;
labResultOfTheTest.Caption := 'The test failed. The "true" keyword IS found.';
end;
btnTestConditionFalse.Enabled := true;
myLoader.Free;
end;
//------------------------------------------------get number of root child nodes
procedure TfrmMain.Getnumberofrootnodes1Click(Sender: TObject);
begin
memResults.Lines.Add('Nr of root child nodes found: ' + inttostr(getNumberOfChildNodes('*')));
end;
//---------------------------------------------------------extract XML structure
procedure TfrmMain.btnGetXMLClick(Sender: TObject);
const
btn_get_xml = '<GET XML>';
btn_stop = 'STOP';
begin
if btnGetXML.Caption = btn_get_xml then
begin
global_stop := false;
btnGetXML.Caption := btn_stop;
memResults.Clear;
GetXMLForNode('', chkUseCURL.Checked);
global_stop := true;
btnGetXML.Caption := btn_get_xml;
statusBar.Panels[1].Text := 'Exploitation stopped.';
end else
begin
global_stop := true;
btnGetXML.Caption := btn_get_xml;
end;
end;
//----------------------------------------------------save extracted XML to file
procedure TfrmMain.btnSaveToFileClick(Sender: TObject);
begin
if dlgSave.Execute = true then
begin
memResults.Lines.SaveToFile(dlgSave.FileName);
end;
end;
//-------------------------------------------copy extracted XML to the clipboard
procedure TfrmMain.btnCopyToClipboardClick(Sender: TObject);
begin
myClip.AsText := memResults.Lines.Text;
end;
//---------------------------------------------------------------on the very end
procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
SaveSettingsToIni(currentIniSettingsFileName);
myLoader.Free;
end;
procedure TfrmMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
canClose := global_stop;
end;
end.