forked from voipmonitor/sniffer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fraud.h
1165 lines (1117 loc) · 33.3 KB
/
fraud.h
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
#ifndef FRAUD_H
#define FRAUD_H
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include "voipmonitor.h"
#include "country_detect.h"
#include "tools.h"
#include "sql_db.h"
#include "register.h"
#include "filter_register.h"
#define fraud_alert_rcc 21
#define fraud_alert_chc 22
#define fraud_alert_chcr 23
#define fraud_alert_d 24
#define fraud_alert_spc 25
#define fraud_alert_rc 26
#define fraud_alert_seq 27
#define fraud_alert_reg_ua 43
#define fraud_alert_reg_short 44
#define fraud_alert_reg_expire 46
extern timeval t;
class TimePeriod {
public:
TimePeriod(SqlDb_row *dbRow = NULL);
bool checkTime(const char *time) {
return(checkTime(getDateTime(time)));
}
bool checkTime(u_int64_t time) {
return(checkTime(getDateTime(time)));
}
bool checkTime(time_t time) {
return(checkTime(getDateTime(time)));
}
bool checkTime(struct tm time) {
bool rslt = true;
if(is_hourmin) {
if(from_hour * 100 + from_minute > to_hour * 100 + to_minute) {
if(time.tm_hour * 100 + time.tm_min < from_hour * 100 + from_minute &&
time.tm_hour * 100 + time.tm_min > to_hour * 100 + to_minute) {
rslt = false;
}
} else {
if(time.tm_hour * 100 + time.tm_min < from_hour * 100 + from_minute ||
time.tm_hour * 100 + time.tm_min > to_hour * 100 + to_minute) {
rslt = false;
}
}
}
if(is_weekday && rslt) {
if(from_weekday > to_weekday) {
if(time.tm_wday + 1 < from_weekday &&
time.tm_wday + 1 > to_weekday) {
rslt = false;
}
} else {
if(time.tm_wday + 1 < from_weekday ||
time.tm_wday + 1 > to_weekday) {
rslt = false;
}
}
}
if(is_monthday && rslt) {
if(from_monthday > to_monthday) {
if(time.tm_mday < from_monthday &&
time.tm_mday > to_monthday) {
rslt = false;
}
} else {
if(time.tm_mday < from_monthday ||
time.tm_mday > to_monthday) {
rslt = false;
}
}
}
if(is_month && rslt) {
if(from_month > to_month) {
if(time.tm_mon + 1 < from_month &&
time.tm_mon + 1 > to_month) {
rslt = false;
}
} else {
if(time.tm_mon + 1 < from_month ||
time.tm_mon + 1 > to_month) {
rslt = false;
}
}
}
return(rslt);
}
private:
string descr;
bool is_hourmin;
int from_hour;
int from_minute;
int to_hour;
int to_minute;
bool is_weekday;
int from_weekday;
int to_weekday;
bool is_monthday;
int from_monthday;
int to_monthday;
bool is_month;
int from_month;
int to_month;
};
class CacheNumber_location {
public:
struct sNumber {
sNumber(const char *number = NULL, u_int32_t ip = 0, const char *domain = NULL) {
if(number) {
this->number = number;
}
this->ip = ip;
if(domain) {
this->domain = domain;
}
}
string number;
u_int32_t ip;
string domain;
bool operator == (const sNumber& other) const {
return(this->number == other.number &&
this->ip == other.ip &&
this->domain == other.domain);
}
bool operator < (const sNumber& other) const {
return(this->number < other.number ? 1 : this->number > other.number ? 0 :
this->ip < other.ip ? 1 : this->ip > other.ip ? 0 :
this->domain < other.domain);
}
};
struct sIpRec {
sIpRec() {
ip = 0;
at = 0;
old_ip = 0;
old_at = 0;
fresh_at = 0;
}
u_int32_t ip;
string country_code;
string continent_code;
u_int64_t at;
u_int32_t old_ip;
string old_country_code;
string old_continent_code;
u_int64_t old_at;
u_int64_t fresh_at;
};
CacheNumber_location();
~CacheNumber_location();
bool checkNumber(const char *number, u_int32_t number_ip, const char *domain,
u_int32_t ip, u_int64_t at,
bool *diffCountry = NULL, bool *diffContinent = NULL,
u_int32_t *oldIp = NULL, string *oldCountry = NULL, string *oldContinent = NULL,
const char *ip_country = NULL, const char *ip_continent = NULL);
bool loadNumber(const char *number, u_int32_t number_ip, const char *domain, u_int64_t at);
void saveNumber(const char *number, u_int32_t number_ip, const char *domain, sIpRec *ipRec, bool update = false);
void cleanup(u_int64_t at);
private:
string getTable(const char *domain);
private:
SqlDb *sqlDb;
map<sNumber, sIpRec> cache;
u_int64_t last_cleanup_at;
};
struct sFraudNumberInfo {
sFraudNumberInfo() {
local_called_number = true;
}
string caller_number;
string called_number;
string country_code_caller_number;
string country2_code_caller_number;
string country_code_called_number;
string country2_code_called_number;
string continent_code_caller_number;
string continent2_code_caller_number;
string continent_code_called_number;
string continent2_code_called_number;
string country_prefix_caller;
string country_prefix_called;
bool local_called_number;
};
struct sFraudCallInfo : public sFraudNumberInfo {
enum eTypeCallInfo {
typeCallInfo_beginCall,
typeCallInfo_connectCall,
typeCallInfo_seenByeCall,
typeCallInfo_endCall
};
sFraudCallInfo() {
typeCallInfo = (eTypeCallInfo)0;
call_type = 0;
caller_ip = 0;
called_ip = 0;
at_begin = 0;
at_connect = 0;
at_seen_bye = 0;
at_end = 0;
at_last = 0;
local_called_ip = true;
}
eTypeCallInfo typeCallInfo;
int call_type;
string callid;
u_int32_t caller_ip;
u_int32_t called_ip;
string country_code_caller_ip;
string country_code_called_ip;
string continent_code_caller_ip;
string continent_code_called_ip;
bool local_called_ip;
string caller_domain;
string called_domain;
u_int64_t at_begin;
u_int64_t at_connect;
u_int64_t at_seen_bye;
u_int64_t at_end;
u_int64_t at_last;
};
struct sFraudRtpStreamInfo : public sFraudNumberInfo {
enum eTypeRtpStreamInfo {
typeRtpStreamInfo_beginStream,
typeRtpStreamInfo_endStream
};
sFraudRtpStreamInfo() {
rtp_src_ip = 0;
rtp_src_ip_group = 0;
rtp_src_port = 0;
rtp_dst_ip = 0;
rtp_dst_ip_group = 0;
rtp_dst_port = 0;
local_called_number = true;
at = 0;
}
eTypeRtpStreamInfo typeRtpStreamInfo;
string callid;
u_int32_t rtp_src_ip;
u_int32_t rtp_src_ip_group;
u_int16_t rtp_src_port;
u_int32_t rtp_dst_ip;
u_int32_t rtp_dst_ip_group;
u_int16_t rtp_dst_port;
string country_code_rtp_src_ip;
string country_code_rtp_dst_ip;
string continent_code_rtp_src_ip;
string continent_code_rtp_dst_ip;
u_int64_t at;
};
struct sFraudEventInfo {
enum eTypeEventInfo {
typeEventInfo_sipPacket,
typeEventInfo_register,
typeEventInfo_registerResponse
};
sFraudEventInfo() {
typeEventInfo = (eTypeEventInfo)0;
src_ip = 0;
dst_ip = 0;
sip_method = 0;
at = 0;
block_store = NULL;
block_store_index = 0;
dlt = 0;
}
eTypeEventInfo typeEventInfo;
u_int32_t src_ip;
u_int32_t dst_ip;
unsigned sip_method;
u_int64_t at;
string ua;
struct pcap_block_store *block_store;
u_int32_t block_store_index;
u_int16_t dlt;
};
struct sFraudRegisterInfo_id {
u_int32_t sipcallerip;
u_int32_t sipcalledip;
string to_num;
string to_domain;
string digest_username;
bool operator == (const sFraudRegisterInfo_id& other) const {
return(this->sipcallerip == other.sipcallerip &&
this->sipcalledip == other.sipcalledip &&
this->to_num == other.to_num &&
this->to_domain == other.to_domain &&
this->digest_username == other.digest_username);
}
bool operator < (const sFraudRegisterInfo_id& other) const {
int rslt_cmp_to_num;
int rslt_cmp_to_domain;
int rslt_cmp_digest_username;
return((this->sipcallerip < other.sipcallerip) ? 1 : (this->sipcallerip > other.sipcallerip) ? 0 :
(this->sipcalledip < other.sipcalledip) ? 1 : (this->sipcalledip > other.sipcalledip) ? 0 :
((rslt_cmp_to_num = strcasecmp(this->to_num.c_str(), other.to_num.c_str())) < 0) ? 1 : (rslt_cmp_to_num > 0) ? 0 :
((rslt_cmp_to_domain = strcasecmp(this->to_domain.c_str(), other.to_domain.c_str())) < 0) ? 1 : (rslt_cmp_to_domain > 0) ? 0 :
((rslt_cmp_digest_username = strcasecmp(this->digest_username.c_str(), other.digest_username.c_str())) < 0));
}
};
struct sFraudRegisterInfo_data {
string from_num;
string from_name;
string from_domain;
string contact_num;
string contact_domain;
string digest_realm;
string ua;
eRegisterState state;
eRegisterState prev_state;
u_int64_t at;
u_int64_t prev_state_at;
u_int32_t time_from_prev_state;
};
struct sFraudRegisterInfo : public sFraudRegisterInfo_id, public sFraudRegisterInfo_data {
};
class FraudAlertInfo {
public:
FraudAlertInfo(class FraudAlert *alert);
virtual ~FraudAlertInfo() {}
string getAlertTypeString();
string getAlertDescr();
unsigned int getAlertDbId();
virtual string getJson() { return("{}"); }
protected:
void setAlertJsonBase(JsonExport *json);
protected:
FraudAlert *alert;
};
class FraudAlert {
public:
enum eFraudAlertType {
_rcc = fraud_alert_rcc,
_chc = fraud_alert_chc,
_chcr = fraud_alert_chcr,
_d = fraud_alert_d,
_spc = fraud_alert_spc,
_rc = fraud_alert_rc,
_seq = fraud_alert_seq,
_reg_ua = fraud_alert_reg_ua,
_reg_short = fraud_alert_reg_short,
_reg_expire = fraud_alert_reg_expire
};
enum eTypeLocation {
_typeLocation_NA,
_typeLocation_country,
_typeLocation_continent
};
enum eTypeBy {
_typeBy_NA,
_typeBy_source_ip,
_typeBy_destination_ip,
_typeBy_source_number,
_typeBy_rtp_stream_ip,
_typeBy_rtp_stream_ip_group,
_typeBy_summary
};
enum eLocalInternational {
_li_local,
_li_international,
_li_booth
};
enum eCondition12 {
_cond12_and,
_cond12_or,
_cond12_both_directions
};
FraudAlert(eFraudAlertType type, unsigned int dbId);
virtual ~FraudAlert();
bool isReg();
bool loadAlert();
void loadFraudDef();
eFraudAlertType getType() {
return(type);
}
string getTypeString();
string getDescr() {
return(descr);
}
unsigned int getDbId() {
return(dbId);
}
bool openVerbLog();
virtual void evCall(sFraudCallInfo */*callInfo*/) {}
virtual void evRtpStream(sFraudRtpStreamInfo */*rtpStreamInfo*/) {}
virtual void evEvent(sFraudEventInfo */*eventInfo*/) {}
virtual void evRegister(sFraudRegisterInfo */*registerInfo*/) {}
virtual bool okFilterIp(u_int32_t ip, u_int32_t ip2);
virtual bool okFilterPhoneNumber(const char *numb, const char *numb2);
virtual bool okFilterDomain(const char *domain);
virtual bool okFilter(sFraudCallInfo *callInfo);
virtual bool okFilter(sFraudRtpStreamInfo *rtpStreamInfo);
virtual bool okFilter(sFraudEventInfo *eventInfo);
virtual bool okFilter(sFraudRegisterInfo *registerInfo);
virtual bool okDayHour(sFraudCallInfo *callInfo) {
if(!callInfo->at_last) {
return(true);
}
return(this->okDayHour(callInfo->at_last / 1000000ull));
}
virtual bool okDayHour(sFraudRtpStreamInfo *rtpStreamInfo) {
if(!rtpStreamInfo->at) {
return(true);
}
return(this->okDayHour(rtpStreamInfo->at / 1000000ull));
}
virtual bool okDayHour(sFraudEventInfo *eventInfo) {
if(!eventInfo->at) {
return(true);
}
return(this->okDayHour(eventInfo->at / 1000000ull));
}
virtual bool okDayHour(time_t at);
virtual void evAlert(FraudAlertInfo *alertInfo);
protected:
virtual void loadAlertVirt() {}
virtual void addFraudDef(SqlDb_row */*row*/) {}
virtual bool defFilterIp() { return(false); }
virtual bool defFilterIp2() { return(false); }
virtual bool defFilterIpCondition12() { return(false); }
virtual bool defFilterNumber() { return(false); }
virtual bool defFilterNumber2() { return(false); }
virtual bool defFilterNumberCondition12() { return(false); }
virtual bool defFilterUA() { return(false); }
virtual bool defUseDomain() { return(false); }
virtual bool defFilterDomain() { return(false); }
virtual bool defFraudDef() { return(false); }
virtual bool defConcuretCallsLimit() { return(false); }
virtual bool defTypeBy() { return(false); }
virtual bool defTypeChangeLocation() { return(false); }
virtual bool defChangeLocationOk() { return(false); }
virtual bool defDestLocation() { return(false); }
virtual bool defDestPrefixes() { return(false); }
virtual bool defInterval() { return(false); }
virtual bool defFilterInternational() { return(false); }
virtual bool defOnlyConnected() { return(false); }
virtual bool defSuppressRepeatingAlerts() { return(false); }
virtual bool defStorePcaps() { return(false); }
virtual bool supportVerbLog() { return(false); }
protected:
eFraudAlertType type;
unsigned int dbId;
SqlDb_row dbRow;
string descr;
ListIP_wb ipFilter;
ListIP_wb ipFilter2;
eCondition12 ipFilterCondition12;
ListPhoneNumber_wb phoneNumberFilter;
ListPhoneNumber_wb phoneNumberFilter2;
eCondition12 phoneNumberFilterCondition12;
ListUA_wb uaFilter;
bool useDomain;
ListCheckString domainFilter;
unsigned int concurentCallsLimitLocal;
unsigned int concurentCallsLimitInternational;
unsigned int concurentCallsLimitBoth;
eTypeBy typeBy;
eTypeLocation typeChangeLocation;
vector<string> changeLocationOk;
vector<string> destLocation;
vector<string> destPrefixes;
u_int32_t intervalLength;
u_int32_t intervalLimit;
bool filterInternational;
CheckInternational checkInternational;
bool onlyConnected;
bool suppressRepeatingAlerts;
int alertOncePerHours;
int hour_from;
int hour_to;
bool day_of_week[7];
bool day_of_week_set;
bool storePcaps;
string storePcapsToPaths;
FILE *verbLog;
friend class FraudAlerts;
friend class FraudAlert_rcc_base;
friend class FraudAlert_rcc_timePeriods;
};
class FraudAlertReg_filter {
public:
FraudAlertReg_filter(class FraudAlertReg *parent);
~FraudAlertReg_filter();
void setFilter(const char *description, const char *filter_str);
protected:
void evRegister(sFraudRegisterInfo *registerInfo);
bool okFilter(sFraudRegisterInfo *registerInfo);
protected:
string description;
string filter_str;
cRegisterFilter *filter;
u_int64_t ev_counter;
map<sFraudRegisterInfo_id, sFraudRegisterInfo_data> ev_map;
u_int64_t start_interval;
FraudAlertReg *parent;
friend class FraudAlertReg;
};
class FraudAlertReg : public FraudAlert {
public:
FraudAlertReg(eFraudAlertType type, unsigned int dbId);
~FraudAlertReg();
protected:
void evRegister(sFraudRegisterInfo *registerInfo);
bool checkUA(const char *ua);
bool checkRegisterTimeSecLe(sFraudRegisterInfo *registerInfo);
private:
void loadAlertVirt();
void loadFilters();
protected:
map<u_int32_t, FraudAlertReg_filter*> filters;
u_int32_t intervalLength;
u_int32_t intervalLimit;
vector<cRegExp*> ua_regex;
bool ua_reg_neg;
u_int32_t registerTimeSecLe;
friend class FraudAlertReg_filter;
};
class FraudAlert_rcc_callInfo {
public:
FraudAlert_rcc_callInfo();
void addLocal(const char *callid, u_int64_t at) {
calls_local[callid] = at;
}
void addInternational(const char *callid, u_int64_t at) {
calls_international[callid] = at;
}
private:
map<string, u_int64_t> calls_local;
map<string, u_int64_t> calls_international;
u_int64_t last_alert_info_local;
u_int64_t last_alert_info_international;
u_int64_t last_alert_info_li;
friend class FraudAlert_rcc_base;
};
class FraudAlert_rcc_rtpStreamInfo {
public:
struct str_dipn_port {
str_dipn_port(string str, u_int32_t ip1, u_int16_t port1, u_int32_t ip2, u_int16_t port2) {
this->str = str;
this->dipn_port = d_item<ipn_port>(ipn_port(ip1, port1), ipn_port(ip2, port2));
}
bool operator == (const str_dipn_port& other) const {
return(this->str == other.str &&
this->dipn_port == other.dipn_port);
}
bool operator < (const str_dipn_port& other) const {
return(this->str < other.str ||
(this->str == other.str && this->dipn_port < other.dipn_port));
}
string str;
d_item<ipn_port> dipn_port;
};
public:
FraudAlert_rcc_rtpStreamInfo();
void addLocal(const char *callid, u_int32_t saddr, u_int16_t sport, u_int32_t daddr, u_int16_t dport, u_int64_t at) {
calls_local[str_dipn_port(callid, saddr, sport, daddr, dport)] = at;
}
void removeLocal(const char *callid, u_int32_t saddr, u_int16_t sport, u_int32_t daddr, u_int16_t dport) {
calls_local.erase(str_dipn_port(callid, saddr, sport, daddr, dport));
}
void addInternational(const char *callid, u_int32_t saddr, u_int16_t sport, u_int32_t daddr, u_int16_t dport, u_int64_t at) {
calls_international[str_dipn_port(callid, saddr, sport, daddr, dport)] = at;
}
void removeInternational(const char *callid, u_int32_t saddr, u_int16_t sport, u_int32_t daddr, u_int16_t dport) {
calls_international.erase(str_dipn_port(callid, saddr, sport, daddr, dport));
}
private:
map<str_dipn_port, u_int64_t> calls_local;
map<str_dipn_port, u_int64_t> calls_international;
u_int64_t last_alert_info_local;
u_int64_t last_alert_info_international;
u_int64_t last_alert_info_li;
friend class FraudAlert_rcc_base;
};
class FraudAlert_rcc_base {
private:
struct sAlertInfo {
sAlertInfo(size_t concurentCalls = 0, u_int64_t at = 0) {
this->concurentCalls = concurentCalls;
this->at = at;
}
size_t concurentCalls;
u_int64_t at;
};
struct sIdAlert {
sIdAlert(u_int32_t ip = 0) {
this->ip = ip;
}
sIdAlert(const char *number) {
this->number = number;
this->ip = 0;
}
sIdAlert(d_u_int32_t rtp_stream) {
this->rtp_stream = rtp_stream;
this->ip = 0;
}
bool operator == (const sIdAlert& other) const {
return(this->ip ?
this->ip == other.ip :
!this->number.empty() ?
this->number == other.number :
this->rtp_stream == other.rtp_stream);
}
bool operator < (const sIdAlert& other) const {
return(this->ip ?
this->ip < other.ip :
!this->number.empty() ?
this->number < other.number :
this->rtp_stream < other.rtp_stream);
}
u_int32_t ip;
string number;
d_u_int32_t rtp_stream;
};
public:
FraudAlert_rcc_base(class FraudAlert_rcc *parent);
~FraudAlert_rcc_base();
void evCall_rcc(sFraudCallInfo *callInfo, class FraudAlert_rcc *alert, bool timeperiod);
void evRtpStream_rcc(sFraudRtpStreamInfo *rtpStreamInfo, class FraudAlert_rcc *alert, bool timeperiod);
protected:
virtual bool checkTime(u_int64_t /*time*/) { return(true); }
virtual string getDescr() { return(""); }
FraudAlert::eTypeBy getTypeBy();
private:
bool checkOkAlert(sIdAlert idAlert, size_t concurentCalls, u_int64_t at,
FraudAlert::eLocalInternational li,
FraudAlert_rcc *alert);
protected:
unsigned int concurentCallsLimitLocal_tp;
unsigned int concurentCallsLimitInternational_tp;
unsigned int concurentCallsLimitBoth_tp;
FraudAlert_rcc_callInfo calls_summary;
map<u_int32_t, FraudAlert_rcc_callInfo*> calls_by_ip;
map<string, FraudAlert_rcc_callInfo*> calls_by_number;
map<d_u_int32_t, FraudAlert_rcc_rtpStreamInfo*> calls_by_rtp_stream;
private:
map<sIdAlert, sAlertInfo> alerts_local;
map<sIdAlert, sAlertInfo> alerts_international;
map<sIdAlert, sAlertInfo> alerts_booth;
FraudAlert_rcc *parent;
};
class FraudAlert_rcc_timePeriods : public FraudAlert_rcc_base {
private:
struct sAlertInfo {
sAlertInfo() {
concurentCallsLimitLocal = 0;
concurentCallsLimitInternational = 0;
concurentCallsLimitBoth = 0;
at = 0;
}
unsigned int concurentCallsLimitLocal;
unsigned int concurentCallsLimitInternational;
unsigned int concurentCallsLimitBoth;
u_int64_t at;
};
public:
FraudAlert_rcc_timePeriods(const char *descr,
int concurentCallsLimitLocal,
int concurentCallsLimitInternational,
int concurentCallsLimitBoth,
unsigned int dbId,
class FraudAlert_rcc *parent);
void loadTimePeriods();
protected:
bool checkTime(u_int64_t time) {
vector<TimePeriod>::iterator iter = timePeriods.begin();
while(iter != timePeriods.end()) {
if((*iter).checkTime(time)) {
return(true);
}
++iter;
}
return(false);
}
string getDescr() {
return(descr);
}
private:
string descr;
unsigned int dbId;
vector<TimePeriod> timePeriods;
map<u_int32_t, sAlertInfo> alerts;
FraudAlert_rcc *parent;
};
class FraudAlertInfo_rcc : public FraudAlertInfo {
public:
FraudAlertInfo_rcc(FraudAlert *alert);
void set_ip(FraudAlert::eLocalInternational localInternational,
const char *timeperiod_name,
u_int32_t ip, const char *ip_location_code,
unsigned int concurentCalls);
void set_number(FraudAlert::eLocalInternational localInternational,
const char *timeperiod_name,
string number, const char *number_location_code,
unsigned int concurentCalls);
void set_rtp_stream(FraudAlert::eLocalInternational localInternational,
const char *timeperiod_name,
FraudAlert::eTypeBy type_by, d_u_int32_t rtp_stream,
unsigned int concurentCalls);
void set_summary(FraudAlert::eLocalInternational localInternational,
const char *timeperiod_name,
unsigned int concurentCalls);
string getJson();
private:
FraudAlert::eLocalInternational localInternational;
string timeperiod_name;
FraudAlert::eTypeBy type_by;
u_int32_t ip;
string ip_location_code;
string number;
string number_location_code;
d_u_int32_t rtp_stream;
unsigned int concurentCalls;
};
class FraudAlert_rcc : public FraudAlert, FraudAlert_rcc_base {
public:
FraudAlert_rcc(unsigned int dbId);
void evCall(sFraudCallInfo *callInfo);
void evRtpStream(sFraudRtpStreamInfo *rtpStreamInfo);
protected:
void addFraudDef(SqlDb_row *row);
bool defFilterIp() { return(true); }
bool defFilterIp2() { return(true); }
bool defFilterIpCondition12() { return(true); }
bool defFilterNumber() { return(true); }
bool defFilterNumber2() { return(true); }
bool defFilterNumberCondition12() { return(true); }
bool defFraudDef() { return(true); }
bool defConcuretCallsLimit() { return(true); }
bool defDestPrefixes() { return(true); }
bool defTypeBy() { return(true); }
bool defSuppressRepeatingAlerts() { return(true); }
bool supportVerbLog() { return(true); }
private:
vector<FraudAlert_rcc_timePeriods> timePeriods;
};
class FraudAlertInfo_chc : public FraudAlertInfo {
public:
FraudAlertInfo_chc(FraudAlert *alert);
void set(const char *number,
FraudAlert::eTypeLocation typeLocation,
u_int32_t ip,
const char *location_code,
u_int32_t ip_old,
const char *location_code_old,
u_int32_t ip_dst);
string getJson();
private:
string number;
FraudAlert::eTypeLocation typeLocation;
u_int32_t ip;
u_int32_t ip_old;
u_int32_t ip_dst;
string location_code;
string location_code_old;
};
class FraudAlert_chc : public FraudAlert {
public:
FraudAlert_chc(unsigned int dbId);
void evCall(sFraudCallInfo *callInfo);
protected:
bool defFilterNumber() { return(true); }
bool defTypeChangeLocation() { return(true); }
bool defChangeLocationOk() { return(true); }
bool defOnlyConnected() { return(true); }
};
class FraudAlert_chcr : public FraudAlert {
public:
FraudAlert_chcr(unsigned int dbId);
void evCall(sFraudCallInfo *callInfo);
protected:
bool defFilterIp() { return(true); }
bool defFilterIp2() { return(true); }
bool defFilterNumber() { return(true); }
bool defUseDomain() { return(true); }
bool defFilterDomain() { return(true); }
bool defTypeChangeLocation() { return(true); }
bool defChangeLocationOk() { return(true); }
};
class FraudAlertInfo_d : public FraudAlertInfo {
public:
FraudAlertInfo_d(FraudAlert *alert);
void set(const char *src_number,
const char *dst_number,
const char *country_code,
const char *continent_code);
string getJson();
private:
string src_number;
string dst_number;
string country_code;
string continent_code;
};
class FraudAlert_d : public FraudAlert {
private:
struct sAlertInfo {
sAlertInfo(const char *country_code = NULL, u_int64_t at = 0) {
if(country_code) {
this->country_code = country_code;
}
this->at = at;
}
string country_code;
u_int64_t at;
};
public:
FraudAlert_d(unsigned int dbId);
void evCall(sFraudCallInfo *callInfo);
protected:
bool defFilterIp() { return(true); }
bool defFilterNumber() { return(true); }
bool defDestLocation() { return(true); }
bool defOnlyConnected() { return(true); }
bool defSuppressRepeatingAlerts() { return(true); }
private:
bool checkOkAlert(const char *src_number, const char *dst_number,
const char *country_code, u_int64_t at);
private:
map<dstring, sAlertInfo> alerts;
};
class FraudAlertInfo_spc : public FraudAlertInfo {
public:
FraudAlertInfo_spc(FraudAlert *alert);
void set(unsigned int ip,
unsigned int count,
unsigned int count_invite = 0,
unsigned int count_message = 0,
unsigned int count_register = 0);
string getJson();
private:
unsigned int ip;
unsigned int count;
unsigned int count_invite;
unsigned int count_message;
unsigned int count_register;
};
class FraudAlert_spc : public FraudAlert {
private:
struct sCounts {
u_int64_t count;
u_int64_t count_invite;
u_int64_t count_message;
u_int64_t count_register;
};
struct sAlertInfo {
sAlertInfo(u_int64_t count = 0, u_int64_t at = 0) {
this->count = count;
this->at = at;
}
u_int64_t count;
u_int64_t at;
};
public:
FraudAlert_spc(unsigned int dbId);
void evEvent(sFraudEventInfo *eventInfo);
protected:
bool defFilterIp() { return(true); }
bool defFilterUA() { return(true); }
bool defInterval() { return(true); }
bool defSuppressRepeatingAlerts() { return(true); }
private:
bool checkOkAlert(u_int32_t ip, u_int64_t count, u_int64_t at);
private:
map<u_int32_t, sCounts> count;
u_int64_t start_interval;
map<u_int32_t, sAlertInfo> alerts;
};
class FraudAlert_rc : public FraudAlert {
private:
struct sAlertInfo {
sAlertInfo(u_int64_t count = 0, u_int64_t at = 0) {
this->count = count;
this->at = at;
}
u_int64_t count;
u_int64_t at;
};
public:
FraudAlert_rc(unsigned int dbId);
~FraudAlert_rc();
void evEvent(sFraudEventInfo *eventInfo);
protected:
bool defFilterIp() { return(true); }
bool defFilterUA() { return(true); }
bool defInterval() { return(true); }
bool defTypeBy() { return(true); }
bool defStorePcaps() { return(true); }
bool defSuppressRepeatingAlerts() { return(true); }
private:
void loadAlertVirt();
bool checkOkAlert(u_int32_t ip, u_int64_t count, u_int64_t at);
string getDumpName(u_int32_t ip, u_int64_t at);
private:
bool withResponse;
map<u_int32_t, u_int64_t> count;
map<u_int32_t, PcapDumper*> dumpers;
u_int64_t start_interval;
map<u_int32_t, sAlertInfo> alerts;
};
class FraudAlertInfo_seq : public FraudAlertInfo {
public:
FraudAlertInfo_seq(FraudAlert *alert);
void set(unsigned int ip,
const char *number,
unsigned int count,
const char *country_code_ip,
const char *country_code_number);
string getJson();
private:
unsigned int ip;
string number;
unsigned int count;
string country_code_ip;
string country_code_number;
};
class FraudAlert_seq : public FraudAlert {
private:
struct sIpNumber {
sIpNumber(u_int32_t ip = 0, const char *number = NULL) {
this->ip = ip;
this->number = number ? number : "";
}
bool operator < (const sIpNumber& other) const {
return(this->ip != other.ip ? this->ip < other.ip :
this->number < other.number);
}
u_int32_t ip;
string number;
};
struct sAlertInfo {
sAlertInfo(u_int64_t count = 0, u_int64_t at = 0) {
this->count = count;
this->at = at;
}
u_int64_t count;
u_int64_t at;
};
public:
FraudAlert_seq(unsigned int dbId);
void evCall(sFraudCallInfo *callInfo);
protected:
bool defFilterIp() { return(true); }
bool defFilterNumber() { return(true); }
bool defInterval() { return(true); }
bool defFilterInternational() { return(true); }
bool defSuppressRepeatingAlerts() { return(true); }
private:
bool checkOkAlert(sIpNumber ipNumber, u_int64_t count, u_int64_t at);
private:
map<sIpNumber, u_int64_t> count;
u_int64_t start_interval;
map<sIpNumber, sAlertInfo> alerts;
};
class FraudAlertInfo_reg : public FraudAlertInfo {
public:
FraudAlertInfo_reg(FraudAlert *alert);
void set(const char *filter_descr,
unsigned int count,
map<sFraudRegisterInfo_id, sFraudRegisterInfo_data> *reg_map);
string getJson();
private: