-
Notifications
You must be signed in to change notification settings - Fork 81
/
finder.cpp
3588 lines (3366 loc) · 113 KB
/
finder.cpp
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
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "HikvisionLogin.h"
#include "STh.h"
#include "mainResources.h"
#include "externFunctions.h"
#include "externData.h"
#include "WebformWorker.h"
#include "Connector.h"
#include "BasicAuth.h"
#include "FTPAuth.h"
#include "SSHAuth.h"
#include <memory>
#include "FileUpdater.h"
#include "IPCAuth.h"
#include <qjsonobject.h>
#include "RTSP.h"
#include "MainStarter.h"
#ifndef WIN32
#define _cdecl
#include <errno.h>
int GetLastError(){
return errno;
}
#endif
extern "C"
{
void _cdecl __vcrt_initialize_telemetry_provider() {}
void _cdecl __telemetry_main_invoke_trigger() {}
void _cdecl __telemetry_main_return_trigger() {}
void _cdecl __vcrt_uninitialize_telemetry_provider() {}
};
unsigned char tl(unsigned char d)
{
if (d >= 192 && d <= 223)
{
return (unsigned char)(d + 32);
}
else
{
return tolower(d);
};
}
std::string toLowerStr(const char *str)
{
if (str != NULL) {
int tsz = strlen(str);
char *strr = new char[tsz + 1];
//ZeroMemory(strr, tsz);
strr[0] = 0;
for (int i = 0; i < tsz; i++)
{
strr[i] = tl(str[i]);
};
memset(strr + tsz, '\0', 1);
std::string tstr = std::string(strr);
delete[]strr;
return tstr;
}
else return "";
}
char* strstri(const char *_Str, const char *_SubStr)
{
if(_Str != NULL)
{
const std::string &_lowStr = toLowerStr(_Str);
const std::string &_lowSubStr = toLowerStr(_SubStr);
const char *resChar = strstr(_lowStr.c_str(), _lowSubStr.c_str());
if(resChar == 0) return NULL;
else {
return (char*)(_Str + (resChar - _lowStr.c_str()));
}
};
return 0;
}
bool gGlobalTrackLocked = false;
char *_findFirst(const char *str, char *delim)
{
int sz = strlen(str);
int dsz = strlen(delim);
for(int i = 0; i < sz; ++i)
{
for(int j = 0; j < dsz; ++j)
{
if(str[i] == delim[j]) return (char *)(str + i);
};
};
return NULL;
}
char *_findLast(char *str, char *delim)
{
int sz = strlen(str);
int dsz = strlen(delim);
int savedPosition = 0;
for(int i = 0; i < sz; ++i)
{
for(int j = 0; j < dsz; ++j)
{
if(str[i] == delim[j]) savedPosition = i;
};
};
return (char *)(str + savedPosition);
}
char *getCodePage(const char *str)
{
char cdpg[32] = {0};
char *ptr1 = strstri(str, "charset=");
if (ptr1 != NULL)
{
char *temp3 = _findFirst((char *)(ptr1 + 8), " \"'\n\r");
if (temp3 != NULL)
{
int ln = (int)(temp3 - ptr1 - 8);
if (ln > 16) return "WTF?";
strncpy(cdpg, (char *)(ptr1 + 8), (ln > 32) ? 32 : ln);
if (strstri(cdpg, "%s") != NULL) return "UTF-8";
return cdpg;
}
else
{
stt->doEmitionRedFoundData("[GetCodePage] [" + QString(temp3).mid(0, 16) + "]");
return "NULL";
};
}
ptr1 = strstri(str, "<meta ");
if(ptr1 != NULL)
{
char *ptr2 = strstri(ptr1 + 6, "charset=");
if(ptr2 != NULL)
{
char *temp4 = _findFirst((char *)(ptr2 + 6), " \"'>\n\r");
if(temp4 != NULL)
{
int ln = (int)(temp4 - ptr2 - 8);
if(ln > 16) return "WTF?";
strncpy(cdpg, (char *)(ptr2 + 8), (ln > 32) ? 32 : ln );
if(strstri(cdpg, "%s") != NULL) return "UTF-8";
return cdpg;
}
else
{
stt->doEmitionRedFoundData("[GetCodePage] [" + QString(ptr2).mid(0, 16) + "]");
return "NULL";
};
}
ptr2 = strstri(ptr1 + 6, "charset = ");
if(ptr2 != NULL)
{
char *temp4 = _findFirst((char *)(ptr2 + 10), " \"'>\n\r");
if(temp4 != NULL)
{
int ln = (int)(temp4 - ptr2 - 10);
if(ln > 16) return "WTF?";
strncpy(cdpg, (char *)(ptr2 + 10), (ln > 32) ? 32 : ln );
if(strstri(cdpg, "%s") != NULL) return "UTF-8";
return cdpg;
}
else
{
stt->doEmitionRedFoundData("[GetCodePage] [" + QString(ptr2).mid(0, 16) + "]");
return "NULL";
};
}
ptr2 = strstri(ptr1 + 6, "charset =");
if(ptr2 != NULL)
{
char *temp4 = _findFirst((char *)(ptr2 + 9), " \"'>\n\r");
if(temp4 != NULL)
{
int ln = (int)(temp4 - ptr2 - 9);
if(ln > 16) return "WTF?";
strncpy(cdpg, (char *)(ptr2 + 9), (ln > 32) ? 32 : ln );
if(strstri(cdpg, "%s") != NULL) return "UTF-8";
return cdpg;
}
else
{
stt->doEmitionRedFoundData("[GetCodePage] [" + QString(ptr2).mid(0, 16) + "]");
return "NULL";
};
}
else
{
if(strstri(str, "charset=") != NULL)
{
char *temp2 = strstri(str, "charset=");
char *temp3 = _findFirst((char *)(temp2 + 8), " \"'>\n\r");
if(temp3 != NULL)
{
int ln = (int)(temp3 - temp2 - 8);
if(ln > 16) return "WTF?";
strncpy(cdpg, (char *)(temp2 + 8), (ln > 32) ? 32 : ln );
if(strstri(cdpg, "%s") != NULL) return "UTF-8";
return cdpg;
}
else
{
stt->doEmitionRedFoundData("[GetCodePage] [" + QString(temp3).mid(0, 16) + "]");
return "NULL";
}
}
else return "NULL";
};
}
else return "NULL";
}
bool isNegative(const std::string *buff, const char *ip, int port, const char *cp)
{
QTextCodec *codec;
QString codedStr;
if (strstri(cp, "shift_jis") != NULL)
{
codec = QTextCodec::codecForName("Shift-JIS");
codedStr = codec->toUnicode(buff->c_str());
}
else if (strstri(cp, "utf") != NULL)
{
codec = QTextCodec::codecForName("UTF-8");
codedStr = codec->toUnicode(buff->c_str());
}
else if (strstri(cp, "cp") != NULL || strstri(cp, "windows") != NULL)
{
codec = QTextCodec::codecForName("Windows-1251");
codedStr = codec->toUnicode(buff->c_str());
}
else if (strstri(cp, "gb") != NULL)
{
codec = QTextCodec::codecForName("GB2312");
codedStr = codec->toUnicode(buff->c_str());
}
else codedStr = QString(buff->c_str());
for (auto negEntry : FileUpdater::negativeVector) {
FileUpdater::cv.wait(FileUpdater::lk, []{return FileUpdater::ready; });
if (!globalScanFlag) return true;
if (Utils::ustrstr(std::string(codedStr.toLocal8Bit().data()), negEntry) != -1) {
if (gNegDebugMode)
{
QTextCodec *nCodec = QTextCodec::codecForName("Windows-1251");
stt->doEmitionDebugFoundData("[<a href=\"" + QString(ip) +
"/\"><font color=\"#0084ff\">" + QString(ip) +
"</font></a>" + "]\tNegative hit: \"" + nCodec->toUnicode(negEntry.c_str()).toHtmlEscaped() + "\"");
}
++filtered;
return true;
}
}
//if (buff->size() < 200) {
// if (buff->find("rtsp") == -1) {
// std::size_t ptr1 = buff->find("\r\n\r\n");
// if (ptr1 != -1) {
// int sz = buff->size();
// int nSz = buff->substr(ptr1, sz).size() - 4;
// if (nSz < 100) {
// if (gNegDebugMode)
// {
// QTextCodec *nCodec = QTextCodec::codecForName("Windows-1251");
// stt->doEmitionDebugFoundData("[<a href=\"" + QString(ip) +
// "/\"><font color=\"#0084ff\">" + QString(ip) +
// "</font></a>]\tNegative hit: Size:" + QString::number(nSz));
// }
// ++filtered;
// return true;
// }
// }
// }
//}
return false;
}
int globalSearchPrnt(const std::string *buff)
{
if(Utils::ustrstr(buff, "en/_top.htm") != -1 || Utils::ustrstr(buff, "cannon http server") != -1
|| Utils::ustrstr(buff, "konica minolta") != -1 || Utils::ustrstr(buff, "/eng/home_frm.htm") != -1
|| Utils::ustrstr(buff, "networkScanner webserver") != -1 || Utils::ustrstr(buff, "/eng/htm/top.htm") != -1
|| Utils::ustrstr(buff, "pages/t_ixdmy.htm") != -1
|| Utils::ustrstr(buff, "/web/guest/") != -1 || Utils::ustrstr(buff, "printerInfo") != -1
|| Utils::ustrstr(buff, "hp photosmart") != -1
|| Utils::ustrstr(buff, "menu and") != -1
|| Utils::ustrstr(buff, "hewlett packard") != -1
|| Utils::ustrstr(buff, "laserjet") != -1 || Utils::ustrstr(buff, "supplies summary") != -1
|| Utils::ustrstr(buff, "seiko epson") != -1 || Utils::ustrstr(buff, "ink_y.png") != -1
|| Utils::ustrstr(buff, "epsonnet") != -1 || Utils::ustrstr(buff, "printer name") != -1
)
{
//if(gNegDebugMode) stt->doEmitionDebugFoundData("Printer detected.");
if (gNegDebugMode)
{
/*QTextCodec *nCodec = QTextCodec::codecForName("Windows-1251");*/
stt->doEmitionDebugFoundData("Printer ignored");
}
return -1;
};
return 0;
}
int sharedDetector(const char * ip, int port, const std::string *buffcpy, const char *cp) {
if (buffcpy->size() == 0) {
if (port == 9000) {
if (HikVis::checkSAFARI(ip, port)) return 6; //Safari CCTV
else if (HikVis::checkHikk(ip, port)) return 4; //Hikkvision iVMS
else if (HikVis::checkRVI(ip, port)) return 5; //RVI
else
{
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("Safari CCTV check failed - ignoring [<a href=\"" + QString(ip) +
"/\"><font color=\"#0084ff\">" + QString(ip) + "</font></a>]");
}
return -1;
}
}
else if(port == 8000) {
if (HikVis::checkHikk(ip, port)) return 4; //Hikkvision iVMS
else if (HikVis::checkRVI(ip, port)) return 5; //RVI
//else if (HikVis::checkSAFARI(ip, port)) return 6; //Safari CCTV
else
{
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("Hikkvision iVMS check failed - ignoring [<a href=\"" + QString(ip) +
"/\"><font color=\"#0084ff\">" + QString(ip) + "</font></a>]");
}
return -1;
}
}
else if (port == 37777) {
if (HikVis::checkRVI(ip, port)) return 5; //RVI
else if(HikVis::checkHikk(ip, port)) return 4; //Hikkvision iVMS
else if (HikVis::checkSAFARI(ip, port)) return 6; //Safari CCTV
else
{
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("RVI check failed - ignoring [<a href=\"" + QString(ip) +
"/\"><font color=\"#0084ff\">" + QString(ip) + "</font></a>]");
}
return -1;
}
} else {
//stt->doEmitionDebugFoundData("[<a href=\"" + QString(ip) + ":" + QString::number(port) +
// "/\"><font color=\"#0084ff\">" + QString(ip) + ":" + QString::number(port) +
// "</font></a>]\tNegative hit: Size: 0");
//return -1;
}
}
int isDig = Utils::isDigest(buffcpy);
if (isDig != -1) return 2; //Auth
if (Utils::ustrstr(buffcpy, "netwave ip camera") != -1) return 11;
if (Utils::ustrstr(buffcpy, "live view / - axis") != -1) return 12;
if (Utils::ustrstr(buffcpy, "vilar ipcamera") != -1) return 13;
if (Utils::ustrstr(buffcpy, "window.location = \"rdr.cgi\"") != -1) return 14;
if (Utils::ustrstr(buffcpy, "httpfileserver") != -1) return 15;
if(Utils::ustrstr(buffcpy, "real-time ip camera monitoring system") != -1
|| Utils::ustrstr(buffcpy, "server push mode") != -1
) return 17; //Real-time IP Camera Monitoring System
if(Utils::ustrstr(buffcpy, "linksys.com") != -1
&& Utils::ustrstr(buffcpy, "tm05") != -1) return 18; //linksys.com cameras
if(Utils::ustrstr(buffcpy, "reecam ip camera") != -1) return 19; //reecam cameras
if(Utils::ustrstr(buffcpy, "/view/viewer_index.shtml") != -1) return 20; //axis cameras
if(Utils::ustrstr(buffcpy, "bridge eyeon") != -1) return 21; //Bridge Eyeon
if(Utils::ustrstr(buffcpy, "ip camera control webpage") != -1
&& Utils::ustrstr(buffcpy, "/main/cs_motion.asp") != -1) return 22; //ip camera control
if(Utils::ustrstr(buffcpy, "network camera") != -1
&& Utils::ustrstr(buffcpy, "/live/index2.html") != -1) return 23; //network camera BB-SC384
if(Utils::ustrstr(buffcpy, "network camera") != -1
&& Utils::ustrstr(buffcpy, "/viewer/live/en/live.html") != -1) return 24; //Network Camera VB-M40
if(Utils::ustrstr(buffcpy, "panasonic ") != -1
&& Utils::ustrstr(buffcpy, ":60002/snapshotjpeg") != -1) return 25; //Panasonic wtfidonteven-camera
if(Utils::ustrstr(buffcpy, "sony network camera") != -1
&& Utils::ustrstr(buffcpy, "/command/inquiry.cgi?") != -1) return 26; //Sony Network Camera
if(Utils::ustrstr(buffcpy, "network camera") != -1
&& Utils::ustrstr(buffcpy, "src=\"webs.cgi?") != -1) return 27; //UA Network Camera
if(Utils::ustrstr(buffcpy, "network camera") != -1
&& Utils::ustrstr(buffcpy, "/viewer/live/index.html") != -1) return 28; //Network Camera VB-M40
if(Utils::ustrstr(buffcpy, "lg smart ip device") != -1) return 29; //LG Smart IP Device Camera
if(Utils::ustrstr(buffcpy, "/view/viewer_index.shtml") != -1) return 20; //axis cameras
if(Utils::ustrstr(buffcpy, "nas") != -1
&& Utils::ustrstr(buffcpy, "/cgi-bin/data/viostor-220/viostor/viostor.cgi") != -1) return 30; //NAX
if(Utils::ustrstr(buffcpy, "ip camera") != -1
&& Utils::ustrstr(buffcpy, "check_user.cgi") != -1) return 31; //axis cameras
if(Utils::ustrstr(buffcpy, "ws(\"user\");") != -1
&& Utils::ustrstr(buffcpy, "src=\"/tool.js") != -1
&& Utils::ustrstr(buffcpy, "<b class=\"xb1\"></b>") != -1) return 32; //web ip cam
if(Utils::ustrstr(buffcpy, "geovision") != -1
&& (Utils::ustrstr(buffcpy, "ip camera") != -1
|| Utils::ustrstr(buffcpy, "ssi.cgi/login.htm") != -1)
) return 33; //GEO web ip cam
if(Utils::ustrstr(buffcpy, "hikvision-webs") != -1
|| (
(Utils::ustrstr(buffcpy, "hikvision digital") != -1 || Utils::ustrstr(buffcpy, "doc/page/login.asp") != -1)
&& Utils::ustrstr(buffcpy, "dvrdvs-webs") != -1 || Utils::ustrstr(buffcpy, "app-webs") != -1 || Utils::ustrstr(buffcpy, "DNVRS-Webs") != -1)
||
(Utils::ustrstr(buffcpy, "lapassword") != -1
&& Utils::ustrstr(buffcpy, "lausername") != -1
&& Utils::ustrstr(buffcpy, "dologin()") != -1)
) return 34; //hikvision cam
if((Utils::ustrstr(buffcpy, "easy cam") != -1
&& Utils::ustrstr(buffcpy, "easy life") != -1)
|| (Utils::ustrstr(buffcpy, "ipcamera") != -1
&& Utils::ustrstr(buffcpy, "/tool.js") != -1)
) return 35; //EasyCam
if(Utils::ustrstr(buffcpy, "/config/cam_portal.cgi") != -1
|| Utils::ustrstr(buffcpy, "/config/easy_index.cgi") != -1) return 36; //Panasonic Cam
if(Utils::ustrstr(buffcpy, "panasonic") != -1
&& Utils::ustrstr(buffcpy, "/view/getuid.cgi") != -1) return 37; //Panasonic Cam WJ-HD180
if(Utils::ustrstr(buffcpy, "ipcam client") != -1 && (
Utils::ustrstr(buffcpy, "plugins.xpi") != -1 ||
Utils::ustrstr(buffcpy, "IPCWebComponents") != -1)
&& Utils::ustrstr(buffcpy, "js/upfile.js") != -1) return 38; //Foscam
if(Utils::ustrstr(buffcpy, "ip surveillance") != -1
&& Utils::ustrstr(buffcpy, "customer login") != -1) return 39; //EagleEye
if(Utils::ustrstr(buffcpy, "network camera") != -1
&& Utils::ustrstr(buffcpy, "/admin/index.shtml?") != -1) return 40; //Network Camera VB-C300
if(Utils::ustrstr(buffcpy, "sq-webcam") != -1
&& Utils::ustrstr(buffcpy, "liveview.html") != -1) return 41; //AVIOSYS-camera
if(Utils::ustrstr(buffcpy, "nw_camera") != -1
&& Utils::ustrstr(buffcpy, "/cgi-bin/getuid") != -1) return 42; //NW_camera
if(Utils::ustrstr(buffcpy, "micros") != -1
&& Utils::ustrstr(buffcpy, "/gui/gui_outer_frame.shtml") != -1) return 43; //NW_camera
if(Utils::ustrstr(buffcpy, "lapassword") != -1
&& Utils::ustrstr(buffcpy, "lausername") != -1
&& Utils::ustrstr(buffcpy, "g_ologin.dologin()") != -1
) return 44; //hikvision cam 2
if(Utils::ustrstr(buffcpy, "panasonic") != -1
&& Utils::ustrstr(buffcpy, "/config/index.cgi") != -1) return 45; //Panasonic Cam BB-HG???
if(Utils::ustrstr(buffcpy, "/ui/") != -1
&& Utils::ustrstr(buffcpy, "sencha-touch") != -1) return 46; //BUFFALO disk
if(Utils::ustrstr(buffcpy, "digital video server") != -1
&& Utils::ustrstr(buffcpy, "gui.css") != -1) return 47; //Digital Video Server
if(Utils::ustrstr(buffcpy, "/ipcamerasetup.zip") != -1
&& Utils::ustrstr(buffcpy, "download player") != -1
&& Utils::ustrstr(buffcpy, "ipcam") != -1
) return 48; //ipCam
if(Utils::ustrstr(buffcpy, "dvr") != -1
&& Utils::ustrstr(buffcpy, "ieorforefox") != -1
&& Utils::ustrstr(buffcpy, "sofari") != -1
) return 49; //IEORFOREFOX
if (Utils::ustrstr(buffcpy, "seyeon") != -1
&& (Utils::ustrstr(buffcpy, "/app/multi/single.asp") != -1
|| Utils::ustrstr(buffcpy, "/app/live/sim/single.asp") != -1)
) return 50; //Network Video System
if (Utils::ustrstr(buffcpy, "MASPRO DENKOH") != -1) return 51; //MASPRO
if (Utils::ustrstr(buffcpy, "webcamXP") != -1
&& Utils::ustrstr(buffcpy, "a valid username/password") != -1
) return 52; //Webcamxp5
if (Utils::ustrstr(buffcpy, "NetSuveillance") != -1
&& Utils::ustrstr(buffcpy, "l_bgm.gif") != -1
) return 53; //Jassun (http://176.32.180.42/Login.htm)
if (Utils::ustrstr(buffcpy, "WEB SERVICE") != -1
&& Utils::ustrstr(buffcpy, "jsmain/liveview.js") != -1
) return 54; //Beward (http://46.146.243.88:88/login.asp)
if (Utils::ustrstr(buffcpy, "get_status.cgi") != -1
&& Utils::ustrstr(buffcpy, "str_device+") != -1
) return 55; //QCam (http://1.177.123.118:8080/)
if (Utils::ustrstr(buffcpy, "EagleEyes") != -1
&& (Utils::ustrstr(buffcpy, "/Login.cgi?rnd=") != -1
|| Utils::ustrstr(buffcpy, "mobile480.htm") != -1)
) return 56; //EaglesEye (http://203.190.113.34:88/nobody/mobile480.htm)
if (Utils::ustrstr(buffcpy, "dvr_remember") != -1
&& Utils::ustrstr(buffcpy, "login_chk_usr_pwd") != -1
) return 57; //Network video client (http://203.190.113.54:60001/)
if (Utils::ustrstr(buffcpy, "QlikView") != -1) return 58; //QLikView (http://203.96.113.183/qlikview/login.htm)
if (Utils::ustrstr(buffcpy, "RTSP/1.") != -1) return 59; //RTSP (http://121.72.55.19:554/ Hisilicon Ipcam)
if (Utils::ustrstr(buffcpy, "ACTi Corporation") != -1) return 60; //ACTi (http://87.197.30.20/cgi-bin/videoconfiguration.cgi)
if (Utils::ustrstr(buffcpy, "airos_logo") != -1) return 61; //AirOS (http://103.5.73.114/login.cgi?uri=/)
if (Utils::ustrstr(buffcpy, "NetSuveillanceWebCookie") != -1 &&
Utils::ustrstr(buffcpy, "resizeL") != -1) return 62; //XMSECU (http://121.72.179.76/Login.htm)
//if (Utils::ustrstr(buffcpy, "ShareCenter") != -1) return 58; //ShareCenter (http://49.50.207.6/)
if (Utils::ustrstr(buffcpy, "nas - ") != -1
&& Utils::ustrstr(buffcpy, "login.html?pg=index.html") != -1) return 1; //https NAS (https://90.224.187.151/)
if(((Utils::ustrstr(buffcpy, "220") != -1) && (port == 21)) ||
Utils::ustrstr(buffcpy, "220 diskStation ftp server ready") != -1 ||
Utils::ustrstr(buffcpy, "220 ftp server ready") != -1
|| Utils::ustrstr(buffcpy, "500 'get': command not understood") != -1
) return 3; // 3 - FTP
if (Utils::ustrstr(buffcpy, "camera") != -1 ||
Utils::ustrstr(buffcpy, "webcamxp") != -1 ||
Utils::ustrstr(buffcpy, "ipcam") != -1 ||
Utils::ustrstr(buffcpy, "smart ip") != -1 ||
Utils::ustrstr(buffcpy, "sanpshot_icon") != -1 ||
Utils::ustrstr(buffcpy, "snapshot_icon") != -1
) return 0;
if((Utils::ustrstr(buffcpy, "hfs /") != -1 ||
Utils::ustrstr(buffcpy, "httpfileserver") != -1 ||
Utils::ustrstr(buffcpy, "index of") != -1 ||
Utils::ustrstr(buffcpy, "$lock extended") != -1
)
&& Utils::ustrstr(buffcpy, "customer") == -1
&& Utils::ustrstr(buffcpy, "purchase") == -1
&& Utils::ustrstr(buffcpy, "contac") == -1
&& Utils::ustrstr(buffcpy, "company") == -1
) return 1;
if (isNegative(buffcpy, ip, port, cp)) return -1;
//if (globalSearchPrnt(buffcpy) == -1) return -1;
return 1;
}
// 500 < 1600
//int _mainFinderFirst(const std::string *buffcpy, int port, const char *ip, const char *cp)
//{
// int flag = sharedDetector(ip, port, buffcpy, cp);
// if (flag != -2) return flag;
//
// return 0;
//}
////> 1600
//int _mainFinderSecond(const std::string *buffcpy, int port, const char *ip, const char *cp)
//{
// int flag = sharedDetector(ip, port, buffcpy, cp);
// if(flag != -2) return flag;
//
// return 3; //Suspicious
//}
int firstStage(const std::string *buffcpy, int port, const char *ip, const char *cp, int sz)
{
if (buffcpy->size() == 0 && sz != 0) {
stt->doEmitionYellowFoundData("Strange behavior: 0 bytes. " + QString(ip));
return -1;
}
int flag = sharedDetector(ip, port, buffcpy, cp);
if (flag != -2) return flag;
return 1;
}
int contentFilter(const std::string *buff, int port, const char *ip, const char *cp, int sz)
{
//int res = 0;
//if (sz <= 500) res = _mainFinderFirst(buff, 1, port, ip, cp);
//else if ((sz > 500 && sz <= 3500) || sz > 180000) res = _mainFinderFirst(buff, 0, port, ip, cp);
//else if (sz > 3500 && sz <= 180000) res = _mainFinderSecond(buff, port, ip, cp);
//return res;
if (sz < 180000) {
return firstStage(buff, port, ip, cp, sz);
}
else {
return 1;
}
}
void fillGlobalLogData(const char *ip, int port, const char *sz, const char *title,
const char *login, const char *pass, char *comment, char *cdpg, char *clss)
{
if(trackerOK == true)
{
while(gGlobalTrackLocked == true) Sleep(10);
gGlobalTrackLocked = true;
QJsonObject jsonData;
if(gMode == 0 || gMode == -1)
{
if(strlen(ip) > 0) jsonData.insert("ip_addr", QJsonValue(QString(ip)) );
else jsonData.insert("ip_addr", QJsonValue(QString("")) );
jsonData.insert("hostname", QJsonValue(QString("")) );
}
else
{
jsonData.insert("ip_addr", QJsonValue(QString("")) );
jsonData.insert("hostname", QJsonValue(QString(ip)) );
};
jsonData.insert("port", QJsonValue(QString::number(port)) );
jsonData.insert("recv", QJsonValue(QString(sz)));
QString tt = QString(base64_encode((const unsigned char *)title, strlen(title)).c_str());
if(strlen(title) == 0) jsonData.insert("title", QJsonValue(QString("NULL")) );
else jsonData.insert("title", QJsonValue(QString(base64_encode((const unsigned char *)title, strlen(title)).c_str())) );
if(strlen(login) > 0) jsonData.insert("login", QJsonValue(QString(login)) );
else jsonData.insert("login", QJsonValue(QString("")) );
if(strlen(pass) > 0) jsonData.insert("pass", QJsonValue(QString(pass)) );
else jsonData.insert("pass", QJsonValue(QString("")) );
if(strlen(comment) > 0) jsonData.insert("other", QJsonValue(QString(comment)) );
else jsonData.insert("other", QJsonValue(QString("")) );
if(strlen(cdpg) > 0) jsonData.insert("encoding", QJsonValue(QString(cdpg)) );
else jsonData.insert("encoding", QJsonValue(QString("")) );
if(strlen(clss) > 0) jsonData.insert("Class", QJsonValue(QString(clss)) );
else jsonData.insert("Class", QJsonValue(QString("")) );
jsonArr->push_front(jsonData);
gGlobalTrackLocked = false;
};
}
int __checkFileExistence(int flag)
{
char fileName[64] = {0};
if (flag == -22) sprintf(fileName, "./" DIR_NAME "%s_%s/" TYPE5 ".html", Utils::getStartDate().c_str(), Utils::getCurrentTarget().c_str());
else if (flag == 0 || flag == 15 || flag == -10) sprintf(fileName, "./" DIR_NAME "%s_%s/" TYPE1 ".html", Utils::getStartDate().c_str(), Utils::getCurrentTarget().c_str());
else if (flag == 3) sprintf(fileName, "./" DIR_NAME "%s_%s/" TYPE2 ".html", Utils::getStartDate().c_str(), Utils::getCurrentTarget().c_str());
else if (flag == 16) sprintf(fileName, "./" DIR_NAME "%s_%s/" TYPE4 ".html", Utils::getStartDate().c_str(), Utils::getCurrentTarget().c_str());
else if(flag >= 17 || flag == 11 || flag == 12
|| flag == 13 || flag == 14 || flag == 1) sprintf(fileName, "./" DIR_NAME "%s_%s/" TYPE3 ".html", Utils::getStartDate().c_str(), Utils::getCurrentTarget().c_str());
FILE *f = fopen(fileName, "r");
if(f == NULL) return true;
else
{
fclose(f);
return false;
};
}
bool ftsCameras = true;
bool ftsOther = true;
bool ftsSSH = true;
bool ftsFTP = true;
bool ftsBA = true;
std::atomic<bool> fOpened(false);
void fputsf(char *text, int flag)
{
char fileName[256] = { 0 };
if(flag == 0 || flag == 15 || flag == -10)
{
if (ftsCameras) ftsCameras = __checkFileExistence(flag);
sprintf(fileName, "./" DIR_NAME "%s_%s/" TYPE1 ".html", Utils::getStartDate().c_str(), Utils::getCurrentTarget().c_str());
}
else if(flag == 1)
{
if(ftsOther) ftsOther = __checkFileExistence(flag);
sprintf(fileName, "./" DIR_NAME "%s_%s/" TYPE2 ".html", Utils::getStartDate().c_str(), Utils::getCurrentTarget().c_str());
}
else if(flag == -22)
{
if(ftsSSH) ftsSSH = __checkFileExistence(flag);
sprintf(fileName, "./" DIR_NAME "%s_%s/" TYPE5 ".html", Utils::getStartDate().c_str(), Utils::getCurrentTarget().c_str());
}
else if(flag == 3)
{
if(ftsFTP) ftsFTP = __checkFileExistence(flag);
sprintf(fileName, "./" DIR_NAME "%s_%s/" TYPE4 ".html", Utils::getStartDate().c_str(), Utils::getCurrentTarget().c_str());
}
else if(flag >= 17 || flag == 11 || flag == 12
|| flag == 13 || flag == 14 || flag == 2
)
{
if(ftsBA) ftsBA = __checkFileExistence(flag);
sprintf(fileName, "./" DIR_NAME "%s_%s/" TYPE3 ".html", Utils::getStartDate().c_str(), Utils::getCurrentTarget().c_str());
}
else stt->doEmitionRedFoundData("Unknown flag [FLAG: " + QString::number(flag) + "]");
FILE *file = fopen(fileName, "a");
if(file != NULL)
{
time_t rtime;
time(&rtime);
if(horLineFlag == false)
{
horLineFlag = true;
char delimiter[128] = {0};
char cdate[32] = {0};
strcpy (cdate, "[");
strcat (cdate, ctime (&rtime));
memset (cdate + strlen(cdate) - 1, '\0', 1);
strcat (cdate, "] ");
strcpy(delimiter, "<hr><center><h5><font color=\"#a1a1a1\">");
strcat(delimiter, cdate);
strcat(delimiter, "</font></h5></center><hr>");
fputs (delimiter, file);
};
++saved;
char *string = new char[strlen(text) + 512];
if(flag != -22)
{
strcpy (string, "<div id=\"ipd\" style=\"color:#707070;text-decoration: none;\">");
char cdate[32] = {0};
strcat (cdate, "[");
strcat (cdate, ctime (&rtime));
memset (cdate + strlen(cdate) - 1, '\0', 1);
strcat (cdate, "] ");
strcat (string, cdate);
strcat (string, text);
strcat (string, "</div>");
}
else
{
strcpy (string, "<div id=\"ipd\" style=\"color:#707070;\">");
char cdate[32] = {0};
strcat (cdate, "[");
strcat (cdate, ctime (&rtime));
memset (cdate + strlen(cdate) - 1, '\0', 1);
strcat (cdate, "] ");
strcat (string, cdate);
strcat (string, text);
strcat (string, "</div>");
};
if (flag == 0 && ftsCameras)
{
char tmsg[1024] = {0};
ftsCameras = false;
strcpy(tmsg, "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /><title>" TYPE1 "</title>");
//strcat(tmsg, msg);
strcat(tmsg, HTTP_FILE_STYLE);
fputs (tmsg, file);
fputs(HTTP_FILE_HEADER, file);
};
if(flag == 1 && ftsOther)
{
char tmsg[1024] = {0};
ftsOther = false;
strcpy(tmsg, "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /><title>" TYPE2 "</title>");
//strcat(tmsg, msg);
strcat(tmsg, HTTP_FILE_STYLE);
fputs (tmsg, file);
fputs(HTTP_FILE_HEADER, file);
};
if(flag == -22 && ftsSSH)
{
char tmsg[1024] = {0};
ftsOther = false;
strcpy(tmsg, "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /><title>" TYPE5 "</title>");
//strcat(tmsg, msg);
strcat(tmsg, HTTP_FILE_STYLE);
fputs (tmsg, file);
fputs(HTTP_FILE_HEADER, file);
};
if(flag == 3 && ftsFTP)
{
char tmsg[1024] = {0};
ftsFTP = false;
strcpy(tmsg, "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /><title>" TYPE4 "</title>");
//strcat(tmsg, msg);
strcat(tmsg, HTTP_FILE_STYLE);
fputs (tmsg, file);
fputs(HTTP_FILE_HEADER, file);
};
if((flag >= 17 || flag == 11 || flag == 12 || flag == 13 || flag == 14 || flag == 2) && ftsBA)
{
char tmsg[1024] = {0};
ftsBA = false;
strcpy(tmsg, "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /><title>" TYPE3 "</title>");
//strcat(tmsg, msg);
strcat(tmsg, HTTP_FILE_STYLE);
fputs (tmsg, file);
fputs(HTTP_FILE_HEADER, file);
};
while(fOpened) {
Sleep((rand() % 10 + 60));
};
fOpened = true;
fputs (string, file);
fclose (file);
fOpened = false;
delete []string;
}
else
{
stt->doEmitionRedFoundData("Cannot open file [Flag: " + QString::number(flag) + " Err:" + QString::number(GetLastError()) + "]");
MainStarter::createResultFiles();
};
}
#define REDIRECT_PIC "<img src='data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAICAIAAAB/FOjAAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAA7SURBVHjaYmIgEbAA8f///4lUzcjIyILMAxE4lMINZUEWAxE4DIazmcjxA6YxRGkg0ussxJsNAQABBgDDuAwgjmnSVwAAAABJRU5ErkJggg=='/>"
#define PEKO_PIC "<a href='[PEKO]'><img src='data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAICAIAAAB/FOjAAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAABASURBVHjaYmAgETAC8Yd1fESqFgj6BNLw//9/Yo1nZGSBsPg/SgHJTwLPiXISSTYQpe4/BIHNZSHJBnIAQIABAEhuFAfSpDW+AAAAAElFTkSuQmCC'/></a>"
void putInFile(int flag, const char *ip, int port, int size, const char *finalstr, char *cp)
{
char log[4096] = {0}, msg[512] = {0};
QTextCodec *codec;
sprintf(msg, "<a href=\"%s/\"><span style=\"color: #a1a1a1;\">%s</span></a>",
ip, ip);
QString resMes(msg);
QString strf;
if(strstri(cp, "shift_jis") != NULL)
{
codec = QTextCodec::codecForName("Shift-JIS");
strf = codec->toUnicode(finalstr);
}
else if(strstri(cp, "utf") != NULL)
{
codec = QTextCodec::codecForName("UTF-8");
strf = codec->toUnicode(finalstr);
}
else if (strstri(cp, "cp") != NULL || strstri(cp, "windows") != NULL)
{
codec = QTextCodec::codecForName("Windows-1251");
strf = codec->toUnicode(finalstr);
}
else if (strstri(cp, "gb") != NULL)
{
codec = QTextCodec::codecForName("GB2312");
strf = codec->toUnicode(finalstr);
}
else strf = QString(finalstr);
if(flag != 6 && flag != 5 && flag != 4)
{
strcat(msg, " <font color=\"#0084ff\">: </font><font color=\"#ff9600\">");
int sz = strf.size();
strncat(msg, QString::fromLocal8Bit(finalstr).toHtmlEscaped().toLocal8Bit().data(), (sz < 128 ? sz : 128));
strcat(msg, "</font>");
resMes += " <font color=\"#0084ff\">: </font><font color=\"#ff9600\">" + strf.toHtmlEscaped() + "</font>";
};
resMes.replace("[PK]", PEKO_PIC);
stt->doEmitionFoundData(resMes.replace("[R]", REDIRECT_PIC));
sprintf(log, "<span id=\"hostSpan\"><a href=\"%s\"/><font color=MediumSeaGreen>%s</font></a>;</span> <span id=\"recvSpan\">Received: <font color=SteelBlue>%d</font>",
ip, ip, size);
//Generic camera
if(flag == 0 || flag == 15 || flag == -10)
{
fillGlobalLogData(ip, port, std::to_string(size).c_str(), finalstr, "", "", "", cp, TYPE1 );
}
//Other
else if(flag == 1)
{
fillGlobalLogData(ip, port, std::to_string(size).c_str(), finalstr, "", "", "", cp, TYPE2 );
}
//Special camera (Hikk, RVI, Safari, etc)
if(flag != 6 && flag != 5 && flag != 4)
{
strcat(log, ";</span> T: <font color=GoldenRod>");
strncat(log, QString::fromLocal8Bit(finalstr).toHtmlEscaped().toLocal8Bit().data(), 100);
strcat(log, "</font>");
};
strcat(log, "\n");
fputsf (log, flag);
//ZeroMemory(msg, strlen(msg));
msg[0] = 0;
}
//void _specFillerWF(const char *ip, int port, const char *finalstr, const char *login, const char *pass, int flag)
//{
// char log[512] = { 0 };
//
// ++PieBA;
//
// if (strlen(login) > 0 || strlen(pass) > 0)
// {
// sprintf(log, "[WF]:<span id=\"hostSpan\"><a href=\"%s\"><font color=darkturquoise>%s (%s:%s)</font></a></span> T: <font color=GoldenRod>%s</font>\n",
// ip, ip, login, pass, finalstr);
// }
//
// stt->doEmitionFoundData(QString::fromLocal8Bit(log));
//
// fputsf(log, flag);
//}
void _specFillerCustom(const char *ip, int port, const char *finalstr, const char *login, const char *pass, int flag, const char *classString) {
char log[512] = { 0 };
++PieBA;
if (strlen(login) > 0 || strlen(pass) > 0)
{
sprintf(log, "<font color=orangered>%s</font>: <span id=\"hostSpan\"><a href=\"%s\"><font color=darkcyan>%s (%s:%s)</font></a></span> T: <font color=GoldenRod>%s</font>\n",
classString, ip, ip, login, pass, finalstr);
}
stt->doEmitionFoundData(QString::fromLocal8Bit(log));
fputsf(log, flag);
}
void _specFillerBA(const char *ip, int port, const char *finalstr, const char *login, const char *pass, int flag)
{
/* char log[512] = {0};
++PieBA;
if (strlen(login) > 0 || strlen(pass) > 0)
{
sprintf(log, "[BA]:<span id=\"hostSpan\"><a href=\"%s:%s@%s\"><font color=MediumSeaGreen>%s:%s@%s</font></a></span> T: <font color=GoldenRod>%s</font>\n",
login, pass, ip, login, pass, ip, finalstr);
}
stt->doEmitionFoundData(QString::fromLocal8Bit(log));
fputsf(log, flag);*/
char log[512] = { 0 };
int offset = 0;
if (strstri(ip, "https://") != NULL) {
offset = 8;
}
else if (strstri(ip, "http://") != NULL) {
offset = 7;
}
if (strlen(login) > 0 || strlen(pass) > 0)
{
if (8 == offset) {
sprintf(log, "[BA]: <span id=\"hostSpan\"><a href=\"https://%s:%s@%s\"><font color=floralwhite>%s:%s@%s</font></a></span> T: <font color=GoldenRod>%s</font>\n",
login, pass, ip + offset, login, pass, ip + offset, finalstr);
}
else {
sprintf(log, "[BA]: <span id=\"hostSpan\"><a href=\"http://%s:%s@%s\"><font color=floralwhite>%s:%s@%s</font></a></span> T: <font color=GoldenRod>%s</font>\n",
login, pass, ip + offset, login, pass, ip + offset, finalstr);
}
} else {
if (8 == offset) {
sprintf(log, "[BA]: <span id=\"hostSpan\"><a href=\"https://%s\"><font color=floralwhite>%s</font></a></span> T: <font color=GoldenRod>%s</font>\n",
ip + offset, ip + offset, finalstr);
}
else {
sprintf(log, "[BA]: <span id=\"hostSpan\"><a href=\"http://%s\"><font color=floralwhite>%s</font></a></span> T: <font color=GoldenRod>%s</font>\n",
ip + offset, ip + offset, finalstr);
}
}
stt->doEmitionFoundData(QString::fromLocal8Bit(log));
fputsf(log, flag);
}
void _specFillerRSTP(const char *ip, int port, const char *finalstr, const char *login, const char *pass, int flag)
{
char log[512] = { 0 };
++PieBA;
if (strlen(login) > 0 || strlen(pass) > 0)
{
sprintf(log, "[RSTP]: <span id=\"hostSpan\"><a href=\"%s11\"><font color=\"#736AFF\">%s11 (%s:%s)</font></a></span> T: <font color=#F0E68C>%s</font>\n",
ip, ip, login, pass, finalstr);
}
else {
sprintf(log, "[RSTP]: <span id=\"hostSpan\"><a href=\"%s11\"><font color=\"#736AFF\">%s11</font></a></span> T: <font color=#F0E68C>%s</font>\n",
ip, ip, finalstr);
}
stt->doEmitionFoundDataCustom(QString::fromLocal8Bit(log), "3090C7");
fputsf(log, flag);
}
//void _specFillerWF(const char *ip, int port, char *finalstr, char *login, char *pass, int flag)
//{
// char log[512] = {0};
//
// ++PieWF;
//
// sprintf(log, "[WF]:<span id=\"hostSpan\"><a href=\"%s:%s\"><font color=MediumSeaGreen>%s:%s</font></a></span> T: <font color=GoldenRod>%s</font> Pass: <font color=SteelBlue>%s:%s</font>\n",
// ip, port, ip, port, finalstr, login, pass);
//
// stt->doEmitionFoundData(QString::fromLocal8Bit(log));
//
// fputsf (log , flag, "Web Form");
//}
//void _getFormVal(char *data, char *result, char *key, char *path = NULL)
//{
// char parVal[256] = {0};
// int psz = 0;
// char *pkeyResult1 = strstr(data, ">");
// if(pkeyResult1 != NULL)
// {
// psz = pkeyResult1 - data + 1;