forked from simsong/bulk_extractor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan_accts_lg.cpp
749 lines (606 loc) · 22.6 KB
/
scan_accts_lg.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
#include "config.h"
// if liblightgrep isn't present, compiles to nothing
#ifdef HAVE_LIBLIGHTGREP
#include <algorithm>
#include <string>
#include "be20_api/scanner_params.h"
#include "histogram.h"
#include "scan_ccns2.h"
#include "pattern_scanner.h"
#include "pattern_scanner_utils.h"
namespace accts {
const char* const DefaultEncodingsCStrings[] = {"UTF-8", "UTF-16LE"};
const vector<string> DefaultEncodings(
DefaultEncodingsCStrings,
DefaultEncodingsCStrings +
sizeof(DefaultEncodingsCStrings)/sizeof(DefaultEncodingsCStrings[0])
);
const vector<string> OnlyUTF8Encoding(1, "UTF-8");
const vector<string> OnlyUTF16LEEncoding(1, "UTF-16LE");
const LG_KeyOptions DefaultOptions = { 0, 1 }; // patterns, case-insensitive
//
// helper functions
//
bool is_pdf_box(const sbuf_t& sbuf, size_t pos) {
const char box[] = "Box";
const size_t c0 = pos >= 10 ? pos - 10 : 10 - pos - 1;
const uint8_t* i = search(sbuf.buf + c0, sbuf.buf + pos, box, box + strlen(box));
return i != sbuf.buf + pos;
/*
return i != sbuf.buf + pos && (
(i + 2 < sbuf.buf + pos && *(i+1) == ' ' && *(i+2) == '[')
|| *(i+1) == '['
);
*/
}
inline bool valid_char(char ch) {
return isdigit(ch) || isspace(ch) || ch=='[' || ch==']' ||
ch=='<' || ch=='Z' || ch=='.' || ch=='l' || ch=='j';
}
bool valid_phone_utf16le(const sbuf_t& sbuf, size_t pos, size_t len) {
// We want invalid characters before and after (assuming there is a
// before and after)
bool invalid_before = false;
bool invalid_after = false;
if (pos > 16) {
for (size_t i = pos-16; i < pos; ++i) {
if (sbuf[i] != '\0' && !valid_char(sbuf[i])) {
invalid_before = true;
break;
}
}
}
else {
invalid_before = true;
}
if (sbuf.bufsize < pos+len+16) {
for (size_t i = pos+len; i < pos+len+16; ++i) {
if (sbuf[i] != '\0' && !valid_char(sbuf[i])) {
invalid_after = true;
break;
}
}
}
else {
invalid_after = true;
}
/*
* 2013-05-28: if followed by ' #{1,5} ' then it's not a phone either!
*/
if (pos+len+10 < sbuf.bufsize) {
if (sbuf[pos+len] == ' ' && sbuf[pos+len+1] == '\0' &&
isdigit(sbuf[pos+len+2]) && sbuf[pos+len+3] == '\0') {
for (size_t i = pos+len+2; i+3 < sbuf.bufsize && i < pos+len+16; i += 2) {
if (isdigit(sbuf[i]) && sbuf[i+1] == '\0' &&
sbuf[i+2] == ' ' && sbuf[i+3] == '\0') {
return false; // not valid
}
}
}
}
/* If it is followed by a dash and a number, it's not a phone number */
if (pos+len+4 < sbuf.bufsize) {
if (sbuf[pos+len] == '-' && sbuf[pos+len+1] == '\0' &&
isdigit(sbuf[pos+len+2] && sbuf[pos+len+3] == '\0')) {
return false;
}
}
return invalid_before && invalid_after;
}
//
// subpatterns
//
// const string END("([^0-9e.]|(\\.[^0-9]))");
const string END("([^\\z2E\\z30-\\z39\\z45\\z65]|(\\.[^\\z30-\\z39]))");
const string BLOCK("[0-9]{4}");
const string DELIM("[- ]");
const string DB("(" + BLOCK + DELIM + ")");
const string SDB("([45][0-9]{3}" + DELIM + ")");
const string TDEL("[ /.-]");
const string PHONETEXT_UTF8_CTX("[^\\z41-\\z5A\\z61-\\z7A]");
const string PHONETEXT_UTF16LE_CTX("([^\\z41-\\z5A\\z61-\\z7A]\\z00|[^\\z00])");
const string PHONETEXT_COMMON("(tel[.ephon]*|fax|facsimile|DSN|telex|TTD|mobile|cell):?");
const string PHONETEXT_UTF8("(" + PHONETEXT_UTF8_CTX + PHONETEXT_COMMON + ")");
const string PHONETEXT_UTF16LE("(" + PHONETEXT_UTF16LE_CTX + PHONETEXT_COMMON + ")");
const string YEAR("(19[0-9][0-9]|20[01][0-9])");
const string MONTH("(Jan(uary)?|Feb(ruary)?|Mar(ch)?|Apr(il)?|May|Jun(e)?|Jul(y)?|Aug(ust)?|Sep(tember)?|Oct(ober)?|Nov(ember)?|Dec(ember)?|0?[1-9]|1[0-2])");
const string DAY("([0-2]?[0-9]|3[01])");
const string SYEAR("([0-9][0-9])");
const string SMONTH("([01][0-2])");
const string DATEA("(" + YEAR + "-" + MONTH + "-" + DAY + ")");
const string DATEB("(" + YEAR + "/" + MONTH + "/" + DAY + ")");
const string DATEC("(" + DAY + " " + MONTH + " " + YEAR + ")");
const string DATED("(" + MONTH + " " + DAY + "[, ]+" + YEAR + ")");
const string DATEFORMAT("(" + DATEA + "|" + DATEB + "|" + DATEC + "|" + DATED + ")");
//
// the scaner
//
class Scanner: public PatternScanner {
public:
Scanner(): PatternScanner("accts_lg"), CCN_Recorder(0), CCN_Track2_Recorder(0), Telephone_Recorder(0), Alert_Recorder(0), PII_Recorder(0), SIN_Recorder(0) {}
virtual ~Scanner() {}
virtual Scanner* clone() const { return new Scanner(*this); }
virtual void startup(const scanner_params& sp);
virtual void init(const scanner_params& sp);
virtual void initScan(const scanner_params&);
feature_recorder* CCN_Recorder;
feature_recorder* CCN_Track2_Recorder;
feature_recorder* Telephone_Recorder;
feature_recorder* Alert_Recorder;
feature_recorder* PII_Recorder;
feature_recorder* SIN_Recorder;
void ccnHitHandler(const LG_SearchHit& hit, const scanner_params& sp);
void ccnUTF16LEHitHandler(const LG_SearchHit& hit, const scanner_params& sp);
void ccnTrack2HitHandler(const LG_SearchHit& hit, const scanner_params& sp);
void ccnTrack2UTF16LEHitHandler(const LG_SearchHit& hit, const scanner_params& sp);
void telephoneHitHandler(const LG_SearchHit& hit, const scanner_params& sp);
void telephoneUTF16LEHitHandler(const LG_SearchHit& hit, const scanner_params& sp);
void telephoneTrailingCtxHitHandler(const LG_SearchHit& hit, const scanner_params& sp);
void telephoneTrailingCtxUTF16LEHitHandler(const LG_SearchHit& hit, const scanner_params& sp);
void validatedTelephoneHitHandler(const LG_SearchHit& hit, const scanner_params& sp);
void validatedTelephoneUTF16LEHitHandler(const LG_SearchHit& hit, const scanner_params& sp);
void bitlockerHitHandler(const LG_SearchHit& hit, const scanner_params& sp);
void bitlockerUTF16LEHitHandler(const LG_SearchHit& hit, const scanner_params& sp);
void piiHitHandler(const LG_SearchHit& hit, const scanner_params& sp);
void piiUTF16LEHitHandler(const LG_SearchHit& hit, const scanner_params& sp);
void sinHitHandler(const LG_SearchHit& hit, const scanner_params& sp);
void sinUTF16LEHitHandler(const LG_SearchHit& hit, const scanner_params& sp);
void sinHitHandler2(const LG_SearchHit& hit, const scanner_params& sp);
void sinUTF16LEHitHandler2(const LG_SearchHit& hit, const scanner_params& sp);
void dateHitHandler(const LG_SearchHit& hit, const scanner_params& sp);
private:
Scanner(const Scanner& s):
PatternScanner(s),
CCN_Recorder(s.CCN_Recorder),
CCN_Track2_Recorder(s.CCN_Track2_Recorder),
Telephone_Recorder(s.Telephone_Recorder),
Alert_Recorder(s.Alert_Recorder),
PII_Recorder(s.PII_Recorder),
SIN_Recorder(s.SIN_Recorder)
{}
Scanner& operator=(const Scanner&);
};
void Scanner::startup(const scanner_params& sp) {
sp.check_version();
sp.info->name = "accts_lg";
sp.info->author = "Simson L. Garfinkel, modified by Tim Walsh";
sp.info->description = "scans for CCNs, track 2, PII (including SSN and Canadian SIN), and phone #s";
sp.info->scanner_version = "1.0";
// define the feature files this scanner creates
sp.info->feature_names.insert("ccn");
sp.info->feature_names.insert("pii"); // personally identifiable information
sp.info->feature_names.insert("sin"); // canadian social insurance number
sp.info->feature_names.insert("ccn_track2");
sp.info->feature_names.insert("telephone");
sp.info->histogram_defs.insert(histogram_def("ccn", "", "histogram"));
sp.info->histogram_defs.insert(histogram_def("ccn_track2", "", "histogram"));
// define the histograms to make
sp.info->histogram_defs.insert(
histogram_def("telephone", "", "histogram", HistogramMaker::FLAG_NUMERIC)
);
scan_ccns2_debug = sp.info->config->debug; // get debug value
}
void Scanner::init(const scanner_params& sp) {
//
// patterns
//
// FIXME: leading context
// FIXME: trailing context
/* #### #### #### #### --- most credit card numbers*/
const string REGEX2("[^\\z30-\\z39\\z41-\\z5A\\z61-\\z7A]" + SDB + DB + DB + BLOCK + END);
new Handler(
*this,
REGEX2,
OnlyUTF8Encoding,
DefaultOptions,
&Scanner::ccnHitHandler
);
const string REGEX2_UTF16LE("([^\\z30-\\z39\\z41-\\z5A\\z61-\\z7A]\\z00|[^\\z00])" + SDB + DB + DB + BLOCK + END);
new Handler(
*this,
REGEX2_UTF16LE,
OnlyUTF16LEEncoding,
DefaultOptions,
&Scanner::ccnUTF16LEHitHandler
);
// FIXME: leading context
// FIXME: trailing context
/* 3### ###### ######### --- 15 digits beginning with 3 and funny space. */
/* Must be american express... */
const string REGEX3("[^\\z30-\\z39\\z41-\\z5A\\z61-\\z7A\\z2E]3[0-9]{3}" + DELIM + "[0-9]{6}" + DELIM + "[0-9]{5}" + END);
new Handler(
*this,
REGEX3,
OnlyUTF8Encoding,
DefaultOptions,
&Scanner::ccnHitHandler
);
const string REGEX3_UTF16LE("([^\\z30-\\z39\\z41-\\z5A\\z61-\\z7A\\z2E]\\z00|[^\\z00])3[0-9]{3}" + DELIM + "[0-9]{6}" + DELIM + "[0-9]{5}" + END);
new Handler(
*this,
REGEX3_UTF16LE,
OnlyUTF16LEEncoding,
DefaultOptions,
&Scanner::ccnUTF16LEHitHandler
);
// FIXME: leading context
// FIXME: trailing context
/* 3### ###### ######### --- 15 digits beginning with 3 and funny space. */
/* Must be american express... */
const string REGEX4("[^\\z30-\\z39\\z41-\\z5A\\z61-\\z7A\\z2E]3[0-9]{14}" + END);
new Handler(
*this,
REGEX4,
OnlyUTF8Encoding,
DefaultOptions,
&Scanner::ccnHitHandler
);
const string REGEX4_UTF16LE("([^\\z30-\\z39\\z41-\\z5A\\z61-\\z7A\\z2E]\\z00|[^\\z00])3[0-9]{14}" + END);
new Handler(
*this,
REGEX4_UTF16LE,
OnlyUTF16LEEncoding,
DefaultOptions,
&Scanner::ccnUTF16LEHitHandler
);
// FIXME: leading context
// FIXME: trailing context
/* ############### 13-19 numbers as a block beginning with a 4 or 5
* followed by something that is not a digit.
* Yes, CCNs can now be up to 19 digits long.
* http://www.creditcards.com/credit-card-news/credit-card-appearance-1268.php
*/
const string REGEX5("[^\\z30-\\z39\\z41-\\z5A\\z61-\\z7A\\z2E][4-6][0-9]{15,18}" + END);
new Handler(
*this,
REGEX5,
OnlyUTF8Encoding,
DefaultOptions,
&Scanner::ccnHitHandler
);
const string REGEX5_UTF16LE("([^\\z30-\\z39\\z41-\\z5A\\z61-\\z7A\\z2E]\\z00|[^\\z00])[4-6][0-9]{15,18}" + END);
new Handler(
*this,
REGEX5_UTF16LE,
OnlyUTF16LEEncoding,
DefaultOptions,
&Scanner::ccnUTF16LEHitHandler
);
// FIXME: leading context
/* ;###############=YYMM101#+? --- track2 credit card data */
/* {SYEAR}{SMONTH} */
/* ;CCN=05061010000000000738? */
const string REGEX6("[^\\z30-\\z39\\z41-\\z5A\\z61-\\z7A][4-6][0-9]{15,18}=" + SYEAR + SMONTH + "101[0-9]{13}");
new Handler(
*this,
REGEX6,
OnlyUTF8Encoding,
DefaultOptions,
&Scanner::ccnTrack2HitHandler
);
const string REGEX6_UTF16LE("([^\\z30-\\z39\\z41-\\z5A\\z61-\\z7A]\\z00|[^\\z00])[4-6][0-9]{15,18}=" + SYEAR + SMONTH + "101[0-9]{13}");
new Handler(
*this,
REGEX6_UTF16LE,
OnlyUTF16LEEncoding,
DefaultOptions,
&Scanner::ccnTrack2UTF16LEHitHandler
);
// FIXME: trailing context
// FIXME: leading context
/* US phone numbers without area code in parens */
/* New addition: If proceeded by " ####? ####? "
* then do not consider this a phone number. We see a lot of that stuff in
* PDF files.
*/
const string REGEX7("[^\\z30-\\z39\\z41-\\z5A\\z61-\\z7A]([0-9]{3}" + TDEL + "){2}[0-9]{4}" + END);
new Handler(
*this,
REGEX7,
OnlyUTF8Encoding,
DefaultOptions,
&Scanner::validatedTelephoneHitHandler
);
const string REGEX7_UTF16LE("([^\\z30-\\z39\\z41-\\z5A\\z61-\\z7A]\\z00|[^\\z00])([0-9]{3}" + TDEL + "){2}[0-9]{4}" + END);
new Handler(
*this,
REGEX7,
OnlyUTF16LEEncoding,
DefaultOptions,
&Scanner::validatedTelephoneUTF16LEHitHandler
);
// FIXME: trailing context
// FIXME: leading context
/* US phone number with parens, like (215) 555-1212 */
const string REGEX8("[^\\z30-\\z39\\z41-\\z5A\\z61-\\z7A]\\([0-9]{3}\\)" + TDEL + "?[0-9]{3}" + TDEL + "[0-9]{4}" + END);
new Handler(
*this,
REGEX8,
OnlyUTF8Encoding,
DefaultOptions,
&Scanner::telephoneTrailingCtxHitHandler
);
const string REGEX8_UTF16LE("([^\\z30-\\z39\\z41-\\z5A\\z61-\\z7A]\\z00|[^\\z00])\\([0-9]{3}\\)" + TDEL + "?[0-9]{3}" + TDEL + "[0-9]{4}" + END);
new Handler(
*this,
REGEX8_UTF16LE,
OnlyUTF16LEEncoding,
DefaultOptions,
&Scanner::telephoneTrailingCtxUTF16LEHitHandler
);
// FIXME: trailing context
// FIXME: leading context
/* Generalized international phone numbers */
const string REGEX9("[^\\z30-\\z39\\z41-\\z5A\\z61-\\z7A]\\+[0-9]{1,3}(" + TDEL + "[0-9]{2,3}){2,6}[0-9]{2,4}" + END);
new Handler(
*this,
REGEX9,
OnlyUTF8Encoding,
DefaultOptions,
&Scanner::validatedTelephoneHitHandler
);
const string REGEX9_UTF16LE("([^\\z30-\\z39\\z41-\\z5A\\z61-\\z7A]\\z00|[^\\z00])\\+[0-9]{1,3}(" + TDEL + "[0-9]{2,3}){2,6}[0-9]{2,4}" + END);
new Handler(
*this,
REGEX9,
OnlyUTF16LEEncoding,
DefaultOptions,
&Scanner::validatedTelephoneHitHandler
);
// FIXME: leading context
/* Generalized number with prefix */
const string REGEX10(PHONETEXT_UTF8 + "[0-9/ .+]{7,18}");
new Handler(
*this,
REGEX10,
OnlyUTF8Encoding,
DefaultOptions,
&Scanner::telephoneHitHandler
);
const string REGEX10_UTF16LE(PHONETEXT_UTF16LE + "[0-9/ .+]{7,18}");
new Handler(
*this,
REGEX10_UTF16LE,
OnlyUTF16LEEncoding,
DefaultOptions,
&Scanner::telephoneUTF16LEHitHandler
);
// FIXME: leading context
/* Generalized number with city code and prefix */
const string REGEX11(PHONETEXT_UTF8 + "[0-9 +]+ ?\\([0-9]{2,4}\\) ?[\\-0-9]{4,8}");
new Handler(
*this,
REGEX11,
OnlyUTF8Encoding,
DefaultOptions,
&Scanner::telephoneHitHandler
);
const string REGEX11_UTF16LE(PHONETEXT_UTF16LE + "[0-9 +]+ ?\\([0-9]{2,4}\\) ?[\\-0-9]{4,8}");
new Handler(
*this,
REGEX11_UTF16LE,
OnlyUTF16LEEncoding,
DefaultOptions,
&Scanner::telephoneUTF16LEHitHandler
);
// FIXME: trailing context
/* Generalized international phone numbers */
const string REGEX12("fedex[^a-z]+([0-9]{4}[- ]?){2}[0-9]" + END);
new Handler(
*this,
REGEX12,
OnlyUTF8Encoding,
DefaultOptions,
&Scanner::piiHitHandler
);
new Handler(
*this,
REGEX12,
OnlyUTF16LEEncoding,
DefaultOptions,
&Scanner::piiUTF16LEHitHandler
);
// FIXME: trailing context
const string REGEX13("ssn:?[ \\t]+[0-9]{3}-?[0-9]{2}-?[0-9]{4}" + END);
new Handler(
*this,
REGEX13,
OnlyUTF8Encoding,
DefaultOptions,
&Scanner::piiHitHandler
);
new Handler(
*this,
REGEX13,
OnlyUTF16LEEncoding,
DefaultOptions,
&Scanner::piiUTF16LEHitHandler
);
const string REGEX14("dob:?[ \\t]+" + DATEFORMAT);
new Handler(
*this,
REGEX14,
DefaultEncodings,
DefaultOptions,
&Scanner::dateHitHandler
);
// FIXME: trailing context
const string REGEX15("sin:?[ \\t]+[0-9]{3}[ -]?[0-9]{3}[ -]?[0-9]{3}" + END);
new Handler(
*this,
REGEX15,
OnlyUTF8Encoding,
DefaultOptions,
&Scanner::sinHitHandler
);
new Handler(
*this,
REGEX15,
OnlyUTF16LEEncoding,
DefaultOptions,
&Scanner::sinUTF16LEHitHandler
);
const string REGEX16("[^0-9][0-9]{3}-[0-9]{3}-[0-9]{3}" + END);
new Handler(
*this,
REGEX16,
OnlyUTF8Encoding,
DefaultOptions,
&Scanner::sinHitHandler2
);
new Handler(
*this,
REGEX16,
OnlyUTF16LEEncoding,
DefaultOptions,
&Scanner::sinUTF16LEHitHandler2
);
// FIXME: leading context
// FIXME: trailing context
/* Possible BitLocker Recovery Key. */
const string BITLOCKER("[^\\z30-\\z39]([0-9]{6}-){7}[0-9]{6}[^\\z30-\\z39]");
new Handler(
*this,
BITLOCKER,
OnlyUTF8Encoding,
DefaultOptions,
&Scanner::bitlockerHitHandler
);
const string BITLOCKER_UTF16LE("([^\\z30-\\z39]\\z00|[^\\z00])([0-9]{6}-){7}[0-9]{6}[^\\z30-\\z39]");
new Handler(
*this,
BITLOCKER,
OnlyUTF16LEEncoding,
DefaultOptions,
&Scanner::bitlockerUTF16LEHitHandler
);
}
void Scanner::initScan(const scanner_params& sp) {
CCN_Recorder = sp.fs.named_feature_recorder("ccn");
CCN_Track2_Recorder = sp.fs.named_feature_recorder("ccn_track2");
Telephone_Recorder = sp.fs.named_feature_recorder("telephone");
Alert_Recorder = sp.fs.get_alert_recorder();
PII_Recorder = sp.fs.named_feature_recorder("pii");
SIN_Recorder = sp.fs.named_feature_recorder("sin");
}
void Scanner::ccnHitHandler(const LG_SearchHit& hit, const scanner_params& sp) {
const size_t pos = hit.Start + 1;
const size_t len = hit.End - (*(sp.sbuf.buf+hit.End-2) == '.' ? 2 : 1) - pos;
if (valid_ccn(reinterpret_cast<const char*>(sp.sbuf.buf)+pos, len)) {
CCN_Recorder->write_buf(sp.sbuf, pos, len);
}
}
void Scanner::ccnUTF16LEHitHandler(const LG_SearchHit& hit, const scanner_params& sp) {
const size_t pos = hit.Start + (*(sp.sbuf.buf+hit.Start+1) == '\0' ? 2 : 1); const size_t len = hit.End - pos;
const string ascii(low_utf16le_to_ascii(sp.sbuf.buf+pos, len));
if (valid_ccn(ascii.c_str(), ascii.size())) {
CCN_Recorder->write_buf(sp.sbuf, pos, len);
}
}
void Scanner::ccnTrack2HitHandler(const LG_SearchHit& hit, const scanner_params& sp) {
const size_t pos = hit.Start + 1;
const size_t len = hit.End - pos;
if (valid_ccn(reinterpret_cast<const char*>(sp.sbuf.buf)+pos, len)) {
CCN_Recorder->write_buf(sp.sbuf, pos, len);
}
}
void Scanner::ccnTrack2UTF16LEHitHandler(const LG_SearchHit& hit, const scanner_params& sp) {
const size_t pos = hit.Start + (*(sp.sbuf.buf+hit.Start+1) == '\0' ? 2 : 1);
const size_t len = hit.End - pos;
const string ascii(low_utf16le_to_ascii(sp.sbuf.buf+pos, len));
if (valid_ccn(ascii.c_str(), ascii.size())) {
CCN_Recorder->write_buf(sp.sbuf, pos, len);
}
}
void Scanner::telephoneHitHandler(const LG_SearchHit& hit, const scanner_params& sp) {
Telephone_Recorder->write_buf(sp.sbuf, hit.Start+1, hit.End-hit.Start-1);
}
void Scanner::telephoneUTF16LEHitHandler(const LG_SearchHit& hit, const scanner_params& sp) {
const size_t start = hit.Start + (*(sp.sbuf.buf + hit.Start + 1) == '\0' ? 2 : 1);
const size_t len = hit.End - start;
Telephone_Recorder->write_buf(sp.sbuf, start, len);
}
void Scanner::telephoneTrailingCtxHitHandler(const LG_SearchHit& hit, const scanner_params& sp) {
Telephone_Recorder->write_buf(
sp.sbuf,
hit.Start+1,
hit.End - (*(sp.sbuf.buf+hit.End-2) == '.' ? 2 : 1) - (hit.Start+1)
);
}
void Scanner::telephoneTrailingCtxUTF16LEHitHandler(const LG_SearchHit& hit, const scanner_params& sp) {
Telephone_Recorder->write_buf(
sp.sbuf,
hit.Start+1,
hit.End - (*(sp.sbuf.buf+hit.End-3) == '.' ? 3 : 1) -(hit.Start+1)
);
}
void Scanner::validatedTelephoneHitHandler(const LG_SearchHit& hit, const scanner_params& sp) {
const size_t pos = hit.Start + 1;
const size_t len = hit.End - (*(sp.sbuf.buf+hit.End-2) == '.' ? 2 : 1) - pos;
if (valid_phone(sp.sbuf, pos, len)){
if (!is_pdf_box(sp.sbuf, pos)) {
Telephone_Recorder->write_buf(sp.sbuf, pos, len);
}
}
}
void Scanner::validatedTelephoneUTF16LEHitHandler(const LG_SearchHit& hit, const scanner_params& sp) {
const size_t pos = hit.Start + 1;
const size_t len = hit.End - (*(sp.sbuf.buf+hit.End-2) == '.' ? 2 : 1) - pos;
if (valid_phone_utf16le(sp.sbuf, pos, len)){
Telephone_Recorder->write_buf(sp.sbuf, pos, len);
}
}
void Scanner::bitlockerHitHandler(const LG_SearchHit& hit, const scanner_params& sp) {
Alert_Recorder->write(sp.sbuf.pos0 + hit.Start + 1, reinterpret_cast<const char*>(sp.sbuf.buf) + 1, "Possible BitLocker Recovery Key (ASCII).");
}
void Scanner::bitlockerUTF16LEHitHandler(const LG_SearchHit& hit, const scanner_params& sp) {
const size_t pos = hit.Start + (*(sp.sbuf.buf + hit.Start + 1) == '\0' ? 2 : 1);
const size_t len = (hit.End - 1) - pos;
Alert_Recorder->write(sp.sbuf.pos0 + pos, low_utf16le_to_ascii(sp.sbuf.buf + pos, len), "Possible BitLocker Recovery Key (UTF-16).");
}
void Scanner::piiHitHandler(const LG_SearchHit& hit, const scanner_params& sp) {
PII_Recorder->write_buf(
sp.sbuf, hit.Start,
hit.End - (*(sp.sbuf.buf+hit.End-2) == '.' ? 2 : 1) - hit.Start
);
}
void Scanner::piiUTF16LEHitHandler(const LG_SearchHit& hit, const scanner_params& sp) {
PII_Recorder->write_buf(
sp.sbuf, hit.Start,
hit.End - (*(sp.sbuf.buf+hit.End-3) == '.' ? 3 : 1) - hit.Start
);
}
void Scanner::sinHitHandler(const LG_SearchHit& hit, const scanner_params& sp) {
SIN_Recorder->write_buf(
sp.sbuf, hit.Start,
hit.End - (*(sp.sbuf.buf+hit.End-2) == '.' ? 2 : 1) - hit.Start
);
}
void Scanner::sinUTF16LEHitHandler(const LG_SearchHit& hit, const scanner_params& sp) {
SIN_Recorder->write_buf(
sp.sbuf, hit.Start,
hit.End - (*(sp.sbuf.buf+hit.End-3) == '.' ? 3 : 1) - hit.Start
);
}
void Scanner::sinHitHandler2(const LG_SearchHit& hit, const scanner_params& sp) {
SIN_Recorder->write_buf(
sp.sbuf, hit.Start+1,
hit.End - (*(sp.sbuf.buf+hit.End-2) == '.' ? 2 : 1) - hit.Start
);
}
void Scanner::sinUTF16LEHitHandler2(const LG_SearchHit& hit, const scanner_params& sp) {
SIN_Recorder->write_buf(
sp.sbuf, hit.Start+1,
hit.End - (*(sp.sbuf.buf+hit.End-3) == '.' ? 3 : 1) - hit.Start
);
}
void Scanner::dateHitHandler(const LG_SearchHit& hit, const scanner_params& sp) {
PII_Recorder->write_buf(sp.sbuf, hit.Start, hit.End - hit.Start);
}
Scanner TheScanner;
}
extern "C"
void scan_accts_lg(struct scanner_params &sp) {
scan_lg(accts::TheScanner, sp, rcb);
}
#endif // HAVE_LIBLIGHTGREP