Compare commits

...
319 Commits
Author SHA1 Message Date
Alfredo Cardigliano a50169a7b3 Moved to 3.2 2020-02-20 10:15:44 +01:00
Luca Deri dd80ec869a Fixes #837 2020-02-19 23:44:22 +01:00
Luca Deri 1714d7aa52 Fixes #842 2020-02-19 23:40:53 +01:00
Luca Deri 90e08b3568 Fixes #845 2020-02-19 23:38:33 +01:00
Luca Deri 080e23e30e Merge pull request #846 from catenacyber/fuzzofix
Fix various buffer over reads
2020-02-19 22:55:18 +01:00
Luca Deri edce5a8c1f Fix for disabling guess when not requested 2020-02-19 12:24:26 +01:00
Alfredo Cardigliano c8ccf33f07 nDPI 3.2 changelog 2020-02-19 12:10:49 +01:00
Philippe Antoine ee979ac14a Fix kerberos leak 2020-02-18 13:32:20 +01:00
Philippe Antoine 3eb9907dd7 Fix various buffer over reads 2020-02-18 11:50:22 +01:00
Luca Deri fdf8dd724f Minor fix 2020-02-17 22:15:36 +01:00
Luca Deri 37121a9b58 Added protocol range check 2020-02-17 19:34:47 +01:00
Luca Deri bbaf9147b6 Fixed TLS client SNI dissection 2020-02-17 18:48:21 +01:00
Luca Deri 9796fdc0e9 Temporarely disabled x390 s390x as we have no way to debug the code on such platforms 2020-02-15 17:31:30 +01:00
Luca Deri e0a058af67 Merge pull request #844 from catenacyber/fuzz2fix
Fuzz2fix
2020-02-15 17:21:52 +01:00
Alfredo Cardigliano 80e9826040 Add ndpi_serialize_string_raw to add raw json values 2020-02-14 16:32:00 +01:00
Philippe Antoine bf7dcd63c3 Checks length for next ip header 2020-02-14 14:18:31 +01:00
Philippe Antoine b287dccecf Checks l4 size against l3 size 2020-02-14 14:02:19 +01:00
emanuele-f cb34c6b233 Add fpic in the reader 2020-02-14 12:06:55 +01:00
emanuele-f fd94270507 Remove decimals in test results for IAT, packet lengths and goodput ratio 2020-02-14 11:42:20 +01:00
Emanuele Faranda 03cf975c07 Merge pull request #840 from xnox/more-tests
travis: bump to bionic, add arm64 & s390x.
2020-02-14 10:32:31 +00:00
emanuele-f 428661c00b Add debug symbols when using --with-llvm-sanitizer 2020-02-14 11:09:00 +01:00
emanuele-f 5c52c00ea4 Add the --with-llvm-sanitizer flag
To enable the leaks detector, set the ASAN_OPTIONS=detect_leaks=1
environment variable, e.g:

	ASAN_OPTIONS=detect_leaks=1 example/ndpiReader -i test.pcap
2020-02-13 18:42:13 +01:00
Luca Deri f89f25c118 Added ndpi_is_protocol_detected() API call 2020-02-13 15:20:47 +01:00
emanuele-f d4ae8a5f16 Fix memory invalid access in SMTP and leaks in TLS 2020-02-13 10:46:30 +01:00
emanuele-f 7234f36949 Fix possible leak 2020-02-13 10:14:57 +01:00
emanuele-f 2efc09a20e Fix invalid memory read 2020-02-12 19:36:47 +01:00
emanuele-f 3fa61a394b Fix little leak on the proto_defaults strdup 2020-02-12 17:15:01 +01:00
Dimitri John Ledkov 582a01303f travis: bump to bionic, add arm64 & s390x. 2020-02-10 18:26:47 +00:00
Luca 97fb50e837 Merge branch 'dev' of https://github.com/ntop/nDPI into dev 2020-02-10 15:26:21 +01:00
Luca Deri a3da5604a3 Allocation fix in kerberos dissector 2020-02-10 15:25:40 +01:00
Luca af6c86de28 Merge branch 'dev' of https://github.com/ntop/nDPI into dev 2020-02-10 15:04:37 +01:00
Luca Deri 34984f1aec Removed outdated AppVeyor link 2020-02-08 11:25:39 +01:00
Luca Deri 83bbb4cb69 Compliation warning fixes 2020-02-08 11:24:40 +01:00
Luca Deri ff4f32ff48 Merge pull request #839 from catenacyber/fuzzbadge
Adds oss-fuzz badge to REAMDE
2020-02-08 11:21:23 +01:00
Luca Deri 33d761a55a Merge pull request #838 from catenacyber/fix2
Adds missing checks
2020-02-08 11:20:54 +01:00
Luca Deri 2bd89be3e2 Added new TLS test files 2020-02-08 10:38:22 +01:00
Luca Deri 5cad39f0e8 Added export of TLS supported version in TLS header 2020-02-07 23:26:03 +01:00
Luca Deri 3be263aafc Added TLS ALPN support 2020-02-07 21:54:04 +01:00
Luca 452ba1f339 Improvements for DNS continuous flow dissection 2020-02-06 19:19:36 +01:00
emanuele-f ec15089208 Little enhancements 2020-02-06 18:22:00 +01:00
Philippe Antoine af661bd652 Adds oss-fuzz badge to REAMDE 2020-02-06 10:56:33 +01:00
Luca Deri 4613515635 Category matching fix 2020-02-05 08:37:24 +01:00
Luca Deri 2009361b89 Fix for IPv6 address format across the various platforms/distributions 2020-02-04 22:51:07 +01:00
Luca Deri f027ab1ae7 Merge branch 'dev' of https://github.com/ntop/nDPI into dev 2020-02-04 22:50:37 +01:00
Luca Deri fa26c62b0c Fix for IPv6 address format across the various platforms/distributions 2020-02-04 22:50:08 +01:00
Luca Deri 0faba29351 Result update 2020-02-04 22:38:56 +01:00
Luca Deri 2701cc9491 Warnign fix 2020-02-04 22:34:08 +01:00
Luca Deri 88fc9232ff Code improvements 2020-02-04 22:31:02 +01:00
Luca Deri 0703ab5ac5 Improved DNS response decoding
The first decoded address is now reported by ndpiReader
2020-02-04 22:16:54 +01:00
Philippe Antoine 418ea234ae Adds missing checks
Found by fuzzing
2020-02-03 22:38:31 +01:00
Luca 3e99b73635 Updte WebattackRCE.pcap.out with libpcre disabled 2020-02-02 22:15:55 +01:00
Luca 6dbe81588f Added --with-pcre to enable libpcre usage 2020-02-02 22:07:21 +01:00
Luca 2b6a639192 Libfuzz fixes 2020-02-02 21:54:36 +01:00
Luca 9e87645022 PCRE fixes 2020-02-02 19:54:31 +01:00
Luca 626fcf1418 Added missing additiona libs 2020-02-02 17:01:07 +01:00
Luca Deri 5b11c2ffc5 Merge pull request #836 from MrTiz9/dev
nDPI now detects RCE injections in HTTP requests
2020-02-02 16:19:26 +01:00
Luca Deri 8486eb08ea Merge pull request #835 from catenacyber/fuzzfix
Fuzz fixes
2020-02-02 16:17:03 +01:00
MrTiz9 ce4f4fbe2f Added missing pcap.out for RCE detections 2020-02-01 17:23:22 +01:00
MrTiz9 3422574c17 FIXED - nDPI now detect RCE injections via PCRE instead Intel Hyperscan 2020-02-01 17:18:35 +01:00
MrTiz9 b3138d5e3e Merge branch 'dev' of https://github.com/ntop/nDPI into dev-unstable 2020-02-01 13:47:42 +01:00
Philippe Antoine 0bf2ca56a8 Uses ip_size in get_ndpi_flow_info6 2020-01-31 15:37:36 +01:00
Philippe Antoine b97360d931 Fix infinite loop in ndpi_workflow_process_packet 2020-01-31 15:26:34 +01:00
Philippe Antoine 579dd7dff9 Fix memcached read overflow 2020-01-31 15:21:03 +01:00
Philippe Antoine ff89a14b49 Modifies fuzz target to fix leaks 2020-01-31 15:13:35 +01:00
Philippe Antoine b5b2260f2e Fix undefined shift in dns 2020-01-31 14:50:18 +01:00
lucaderi 39b1ad3087 PCRE fix 2020-01-31 07:09:54 +01:00
Luca Deri c68ea3067b Added libpcre lib if present 2020-01-30 22:24:24 +01:00
Alfredo Cardigliano 4e538b1e4d Disabeld community id debug 2020-01-30 15:20:52 +01:00
MrTiz9 5c8c2d843a nDPI now detect RCE injections via PCRE instead Intel Hyperscan - BUGGY, DOES NOT COMPILE 2020-01-30 15:08:26 +01:00
MrTiz9 ea957687e1 Merge branch 'dev' of https://github.com/ntop/nDPI into dev-unstable 2020-01-30 14:57:58 +01:00
Luca Deri c84ed5a712 Added check for libpcre presence 2020-01-29 00:41:35 +01:00
Alfredo Cardigliano ab2a011cf9 Community ID hash fixes 2020-01-25 16:04:00 +01:00
Luca Deri d86d632fe6 Added memory boundary check in HTTP dissector 2020-01-24 21:04:27 +01:00
Luca Deri 87d228f78e Fixed heap-buffer-overflow in citrix decoder 2020-01-24 19:50:38 +01:00
Luca Deri a7a4bf32d3 Merge pull request #833 from catenacyber/travisfuzz2
Fix sanitizers build on Travis
2020-01-24 19:38:18 +01:00
Alfredo Cardigliano e20c4acbde Implement ndpi_flowv6_flow_hash ndpi_flowv4_flow_hash. Add ndpi_base64_encode. 2020-01-24 18:36:38 +01:00
MrTiz9 daf15e70bf Added missing pcap.out for RCE detections 2020-01-24 17:16:18 +01:00
MrTiz9 daa1171593 nDPI now detect RCE in HTTP GET requests 2020-01-24 17:16:18 +01:00
Philippe Antoine dc5fecfc92 Use MSAN_SYMBOLIZER_PATH now that it works 2020-01-24 10:15:16 +01:00
Philippe Antoine 79e1ec9f50 Complete absolute path for symbolizer 2020-01-24 10:03:23 +01:00
Philippe Antoine 902a1c7b4c Trying with ASAN_SYMBOLIZER_PATH 2020-01-24 09:53:06 +01:00
Philippe Antoine 5b88867084 Looking for symbolizer 2020-01-24 09:46:53 +01:00
Philippe Antoine 4749e61bdb Debug symbols in LDFLAGS 2020-01-24 09:23:56 +01:00
Philippe Antoine 4f230943cf Debug compilation flag for fuzz targets
And adding include file to fuzz_ndpi_reader
2020-01-24 09:10:52 +01:00
Philippe Antoine 6186e1ab01 Only one env 2020-01-24 08:40:05 +01:00
Philippe Antoine 9fe8bf018a Use clang++7 for fuzz targets in Travis 2020-01-24 08:24:18 +01:00
Philippe Antoine e082134a0d Fix sanitizers build on Travis 2020-01-24 08:14:44 +01:00
Luca Deri cedbf3b636 Merge pull request #832 from catenacyber/travisfuzz
Adds fuzz targets build and run to travis
2020-01-23 18:36:40 +01:00
Luca Deri 5f6fd8d2a5 Merge pull request #831 from catenacyber/fuzzcorpus
Generates automatically corpus for fuzz target
2020-01-23 18:35:48 +01:00
Philippe Antoine cbb755666e Typo fix 2020-01-23 09:09:21 +01:00
Philippe Antoine 1d024ece7a Adds fuzz targets build and run to travis
Build comes with the different sanitizers
2020-01-22 16:36:12 +01:00
Philippe Antoine 77db14fd7a Generates automatically corpus for fuzz target 2020-01-22 16:12:50 +01:00
Luca Deri 5a40f9b7fd Minor fixes 2020-01-21 20:52:42 +01:00
Luca Deri 931f51bd77 ndpi_load_categories_file() now returns the number of loaded hosts or -1 in case of error 2020-01-20 23:37:09 +01:00
Luca Deri 283588a37b Crash fix when not using CSV output 2020-01-19 20:50:23 +01:00
Luca 812505b56b Added sanity check 2020-01-15 20:49:21 -07:00
Luca Deri 98d9f524f9 Merge pull request #830 from catenacyber/fuzzpcap
Adds another fuzz target
2020-01-14 16:37:55 -08:00
Luca Deri 0023a96f80 Merge pull request #828 from vitalivanov/pull_764
example: fix compilation of ndpireader on latest dpdk.
2020-01-14 16:37:28 -08:00
Luca Deri 9f7b1c84f2 Merge pull request #829 from vitalivanov/pull_warning_vit
example: fix build warning.
2020-01-14 16:36:51 -08:00
Alfredo Cardigliano e1047b324b Fix misleading error message 2020-01-14 10:57:05 +01:00
Philippe Antoine 10738a0ca3 New fuzz target : fuzz_ndpi_reader 2020-01-14 08:20:15 +01:00
Philippe Antoine fe312ffbe1 Compile libndpireader 2020-01-14 08:20:15 +01:00
Vitaliy Ivanov 24f2cd6fc1 example: fix build warning.
ndpiReader.c:24:0: warning: "_GNU_SOURCE" redefined
 #define _GNU_SOURCE
<command-line>:0:0: note: this is the location of the previous definition

Signed-off-by: Vitaliy Ivanov <vitaliyi@interfacemasters.com>
2020-01-13 16:15:58 +02:00
Vitaliy Ivanov cbabbd5865 example: fix compilation of ndpireader on latest dpdk.
reader_util.c:1708:43: error: 'ETHER_MAX_LEN' undeclared here (not in a function)
             .rxmode = { .max_rx_pkt_len = ETHER_MAX_LEN }
                                           ^~~~~~~~~~~~~

DPDK before 19.08 had a macro ETHER_MAX_LEN, in later versions it was
changed to RTE_ETHER_MAX_LEN.

Signed-off-by: Vitaliy Ivanov <vitaliyi@interfacemasters.com>
2020-01-13 16:10:09 +02:00
Luca Deri da5208ee68 Updated results with the new output 2020-01-10 23:21:11 +01:00
Luca Deri bccf1c433a Added missing flow extra info export in flows 2020-01-10 23:15:54 +01:00
Luca Deri cc7593fe5a Merge branch 'dev' of https://github.com/ntop/nDPI into dev 2020-01-10 22:21:42 +01:00
Luca Deri 5571ce114d Added flow extra info field
Updated tests/results
2020-01-10 22:21:16 +01:00
Luca 4dd887e516 Added further TLS checks 2020-01-10 18:18:07 +01:00
Luca Deri a3e06da2a8 Minor cleanup 2020-01-10 12:46:53 +01:00
Luca Deri dc21079851 Fix for invalid TLS leght 2020-01-09 18:51:03 +01:00
Luca Deri 5987ec6014 Added check for preventing TLS misbehavior 2020-01-09 17:14:37 +01:00
Luca 757b0c602f Fix for avoiding misdetection in TLS 2020-01-09 10:30:14 +01:00
Luca Deri 498b346219 Added bootstrap ethereum nodes 2020-01-08 22:44:30 +01:00
Luca Deri 3e66bbc5bc Tool for listing the current bitcoin IPv4 nodes 2020-01-08 22:14:34 +01:00
Luca Deri 3ba7667887 Various ethereum improvements 2020-01-08 22:01:45 +01:00
Luca Deri fd943d6000 Code hardening 2020-01-08 17:13:24 +01:00
Luca Deri 691778df33 Cosmetic fixes 2020-01-06 22:25:20 +01:00
Luca Deri 81c3f5813c Added check to avoid double allocations with retransmitted packets 2020-01-06 21:27:51 +01:00
Luca Deri fdf402d027 Added missing RPM files 2020-01-06 18:20:52 +01:00
Luca Deri f0014a5a24 Removed TLS debug code that could have caused crashes 2020-01-05 21:28:35 +01:00
Luca Deri 53a5be3399 Added packet boundary checks 2020-01-05 20:58:16 +01:00
Luca Deri f389969c0b Use share instead of sbin for sample files
Fixes #826
2020-01-05 18:50:56 +01:00
Luca Deri dc02afa3ea Merge pull request #825 from aouinizied/fix_python_bindings
Update Python cffi bindings.
2020-01-05 18:47:43 +01:00
Luca Deri d1fb41a161 Minor cleanup 2020-01-05 18:42:36 +01:00
Luca Deri ef16591f3f Merge branch 'dev' of https://github.com/ntop/nDPI into dev 2020-01-05 18:25:44 +01:00
Luca Deri 29dd45838d Updated (C) 2020-01-05 18:24:58 +01:00
emanuele-f 798bb6e2e1 Fix leaks and sha1 certificate detection 2020-01-02 14:39:51 +01:00
emanuele-f 2332cbfefe Fix invalid free on non-tls flows 2020-01-02 14:10:21 +01:00
emanuele-f a58a135758 Add fingerprint_set flag 2020-01-02 12:56:25 +01:00
Luca 634457615c Updated TLS support 2020-01-02 10:47:23 +01:00
Luca cb825766ea Minor changes 2020-01-02 10:37:53 +01:00
Luca 8b01056b21 Renamed TLS requested server name 2020-01-02 07:37:03 +01:00
Luca f6c7a33177 Added TLS test 2020-01-01 21:27:18 +01:00
Luca daae1cc9b1 Reworked TLS dissection 2020-01-01 12:59:19 +01:00
Luca Deri 499c80535b Minor fix 2019-12-29 22:27:48 +01:00
Luca 9fb3a57a71 Kerberos fixes
Minor TLS cleanup
2019-12-29 10:45:42 +01:00
Luca 257ec7cc5f Removed disable_metadata_export preference that is no longer useful
since ndpi_process_extra_packet() can drive limited or full metadata export
2019-12-29 08:07:35 +01:00
emanuele-f 73c7ccdb65 Fix crash in ndpi_fill_ip_protocol_category when both saddr and daddr are 0
In this corner case, the "prefix" variable was not initialized leading to a failed assertion and crash:

ndpi_patricia_search_best2: Assertion `prefix->bitlen <= patricia->maxbits' failed.
2019-12-23 15:20:09 +01:00
Zied Aouini cffb11fbc9 Update ndpi_flow_struct definition. 2019-12-23 11:22:23 +01:00
Luca Deri 23421b47d9 Added snprintf() return code check 2019-12-18 19:49:46 +01:00
Luca Deri 1cab9fe838 Fix for custom protocol detection 2019-12-18 19:35:40 +01:00
Luca Deri 27ea04c08e Merge pull request #824 from catenacyber/stunfix
Fix read buffer overflow in stun
2019-12-18 19:29:23 +01:00
Luca Deri 5c225b8a2e Merge pull request #821 from aouinizied/win32-lib-appveyor
Win32 lib appveyor
2019-12-18 19:22:12 +01:00
Luca Deri 4961241c62 Merge pull request #823 from haroflow/dev
Changed 13.64.0.0/11 range from Skype to Microsoft
2019-12-18 19:18:28 +01:00
Philippe Antoine 843204299c Fix read buffer overflow in stun 2019-12-18 13:48:33 +01:00
Simone Mainardi 09cd95d54a Fixes informative subprotocols
Wrongly marked subprotocols were causing issues on ntopng.
This fixes https://github.com/ntop/ntopng/issues/3129
2019-12-17 18:12:15 +01:00
Renan de Souza 1d3bef41a4 Added *whatsapp-*.fbcdn.net IPs as WhatsApp 2019-12-16 15:32:46 -03:00
Luca Deri e21fe5d594 Added intrusion_detection.c in DPDK makefile 2019-12-16 17:56:08 +01:00
Renan de Souza 9133955219 Changed 13.64.0.0/11 range from Skype to Microsoft, blocking this range also blocks some azure-hosted websites 2019-12-16 10:50:19 -03:00
Zied Aouini acb74905a5 Switch to dev branch. 2019-12-16 01:36:02 +01:00
Zied Aouini ed3fff554a Add Appveyor build status. 2019-12-16 01:34:42 +01:00
Zied Aouini 7ebe6a0c82 Add LDFLAGS for Win32. 2019-12-16 01:24:42 +01:00
Zied Aouini 87333aa68c Add branch. 2019-12-16 01:19:37 +01:00
Zied Aouini e593319ba0 Fix Win32. 2019-12-16 01:14:10 +01:00
Zied Aouini 812a3e7099 Add mingw host target 2019-12-16 01:11:55 +01:00
Zied Aouini 1097f5488d Add .appveyor.yml 2019-12-16 01:10:26 +01:00
Zied Aouini b90410e335 Add .gitattributes 2019-12-16 01:09:09 +01:00
Luca Deri deed27cbef Implemented nDPI timeline visualizer 2019-12-15 23:35:43 +01:00
Luca Deri ea001b439a TLS decoding improvements 2019-12-14 16:17:34 +01:00
Luca Deri 14e5adc7c2 Win fixes 2019-12-14 15:05:47 +01:00
Luca Deri 81012b3201 CSV output enhancements 2019-12-13 12:50:52 +01:00
Luca Deri 406aa12468 Fixed CSV output 2019-12-13 09:45:34 +01:00
Luca 2c2bb11c9b Fixed output format 2019-12-11 11:27:00 +01:00
Luca Deri 1bd63d68a5 CSV export improvements 2019-12-11 09:45:14 +01:00
Luca Deri bf5e9b7b0b Fixed bug that prevented SMTP email to be dissected 2019-12-09 19:04:13 +01:00
Luca Deri 7fe9dddf65 Fixed invalid password report on telnet 2019-12-09 18:43:05 +01:00
Luca Deri 6d7f3976f3 Code cleanup 2019-12-09 18:02:48 +01:00
Luca Deri 65d526d8f6 Code cleanup 2019-12-09 15:28:44 +01:00
Luca Deri 56eeb965bf Code cleanup 2019-12-09 13:10:21 +01:00
Luca Deri c4d476cc58 Code improvements 2019-12-09 00:29:02 +01:00
Luca Deri 23b0b8625d Minor changes to the IDS score calculation 2019-12-09 00:11:32 +01:00
Luca Deri 558983c99c Merge pull request #813 from SimoneRicci97/dev
Fixed intrusion detection
2019-12-09 00:01:09 +01:00
Luca Deri c8d6f2845f Improved memory management in the kerberos dissector 2019-12-08 23:59:53 +01:00
Luca Deri 1a115cac5a Merge pull request #817 from MrTiz9/dev
Integration of the libinjection library
2019-12-08 23:49:23 +01:00
Luca Deri 11401edfe7 Merge branch 'dev' of https://github.com/ntop/nDPI into dev 2019-12-08 23:47:25 +01:00
Luca Deri 239842b821 Major kerberos rework 2019-12-08 23:47:04 +01:00
MrTiz9 606ff10ecf Integration of the libinjection library to detect SQL injections and XSS type attacks in HTTP requests 2019-12-05 18:09:43 +01:00
emanuele-f d37b69ce9c Fix corner case causing access to already freed memory 2019-12-04 18:36:54 +01:00
emanuele-f 226a9abf22 Additional memory bounds checks 2019-12-04 18:34:08 +01:00
emanuele-f f26096ee4c Fix reversed offset check 2019-12-04 15:20:49 +01:00
emanuele-f 2b3ef7e762 Fix invalid memory access 2019-12-04 14:21:04 +01:00
emanuele-f d62526f9ed Fix invalid reads and add valgrind test 2019-12-04 13:06:05 +01:00
Luca Deri e66d7216b8 Removed header space with JSON serialization 2019-12-04 10:52:51 +01:00
Luca Deri fbc59c5f81 Merge branch 'dev' of https://github.com/ntop/nDPI into dev 2019-12-01 22:27:26 +01:00
Luca Deri 32dc9e3225 Refreshed Whatsapp server list 2019-12-01 22:26:57 +01:00
Luca Deri b4468239b9 Merge pull request #814 from aouinizied/python_cffi_bindings
Implement cffi bindings.
2019-12-01 21:56:10 +01:00
Luca Deri 95c1282ef4 Improved categories with streaming 2019-12-01 21:52:28 +01:00
Luca Deri a7b0457753 Improved category detection with HTTP 2019-12-01 21:40:04 +01:00
Luca Deri 7da7ae622b Improvements to stop dissection when the first protocol is detected
Used IP-based detection to compute the application protocol
Improved application detection
2019-11-28 23:20:40 +01:00
aouinizied a95cfcc989 Implement cffi bindings. 2019-11-28 03:09:13 +01:00
Simone Ricci a65c959940 Fixed intrusion detection 2019-11-26 21:20:22 +01:00
Luca Deri d328c3bccc Overflow fix 2019-11-26 17:58:49 +01:00
Luca Deri 8368568443 Added buffer overflow check in smpp dissector 2019-11-26 17:45:08 +01:00
Luca Deri c223bb1f10 Fixed buffer overflow in DNS dissection 2019-11-26 17:42:59 +01:00
Luca Deri c7efd0892f Fixed buffer overflow in amazon video dissector 2019-11-26 17:30:36 +01:00
Luca ae9429408b Added webattacj results 2019-11-25 18:40:14 +01:00
Luca Deri 0ce56d5714 Updated results 2019-11-23 19:55:06 +01:00
Luca Deri 509cfcb556 Fixed invalid category matching in HTTP
Fixed overlapping categories
2019-11-23 19:54:06 +01:00
Luca Deri 3b203d57e9 Merge branch 'dev' of https://github.com/ntop/nDPI into dev 2019-11-23 13:28:15 +01:00
Luca Deri 68d66b780c Added new test pcaps
Renamed protocol 104 to IEC60870 (more meaningful)
2019-11-23 13:27:34 +01:00
Luca Deri f94d6cca7d Memory fixes 2019-11-23 12:14:52 +01:00
Luca Deri 382217887b Nested encapsulation dissection 2019-11-23 11:53:00 +01:00
Luca Deri 537c11a985 Fixes for uninitialized variables 2019-11-23 11:39:23 +01:00
Luca Deri bdc0719e76 Added auth failed support with FTP 2019-11-21 23:31:52 +01:00
Luca Deri fc82cdfa4a Implemented telnet password export 2019-11-21 19:36:01 +01:00
Luca Deri e98b994a39 Updated results 2019-11-21 13:35:04 +01:00
Luca Deri a58c838c4c Added flow duration and goodput in output (-v and -c) 2019-11-21 13:31:56 +01:00
Luca Deri f91f2c57ef Fixed skype/soom false positives 2019-11-20 23:28:24 +01:00
emanuele-f 68b7986d9b Expose API to calculate the MD5 hash 2019-11-20 11:57:21 +01:00
Alfredo Cardigliano ead0325deb Rounding up serializer buffer to be divisible by 4 (required by zmq encryption) 2019-11-19 19:03:06 +01:00
emanuele-f 0b819badd2 Possible leak fix 2019-11-19 11:42:04 +01:00
Simone Mainardi 3754e6dd12 Fixes crash when searching kerberos usernames
Fixes

(gdb) f 0
101                         if(cname_str[cname_len-1] == '$') {
(gdb) p cname_len
$3 = 0
2019-11-19 11:34:34 +01:00
Luca Deri da029607a0 Removed (unreliable) line protocol detection 2019-11-18 21:21:52 +01:00
Luca Deri 803dc6ff77 Minor fix 2019-11-17 22:42:32 +01:00
Luca Deri 65a629304c Kerberos dissection improvements 2019-11-17 22:35:10 +01:00
Luca Deri 51cfdfb0d8 Removed unused JSON-C code 2019-11-17 17:51:45 +01:00
Luca Deri 53108c9ff1 Merge pull request #811 from aouinizied/python_bindings_fix
Python bindings fix and improve
2019-11-15 19:51:15 +01:00
aouinizied 82a186e096 Polish. 2019-11-15 19:30:50 +01:00
aouinizied e467fe9aa6 Improve python bindings. 2019-11-15 19:18:30 +01:00
Luca Deri 7a1940e1f7 Modified Diameter category to network
Updated test results
2019-11-14 15:13:13 +01:00
Alfredo Cardigliano 6b7c56c909 New ndpi_serialize_string_boolean/ndpi_serialize_uint32_boolean 2019-11-13 18:16:44 +01:00
Luca 470d30ac23 Fixed SQL Injection detection 2019-11-13 17:37:48 +01:00
Luca 7e87bfd039 Added support of default /32 in ndpi_load_ipv4_ptree() 2019-11-12 16:37:18 +01:00
Luca Deri ab9ccf9eb9 Fixed new nDPi API 2019-11-12 12:28:34 +01:00
Luca Deri 15ec013af8 Added ndpi_load_ipv4_ptree() API call 2019-11-11 23:52:24 +01:00
emanuele-f 748f10c0d6 Fix possible crash due to unsigned int number wrapping 2019-11-11 10:18:55 +01:00
Luca Deri 8181d63a95 Added ndpi_init_detection_module() API preferences 2019-11-10 22:57:21 +01:00
Luca d0e7e69552 Renamed DNSoverHTTPS to handle bot DoH and DoT 2019-11-08 09:23:52 +00:00
Luca 0558d641f2 Added ndpi_finalize_initalization() initialization function 2019-11-07 19:28:16 +00:00
Alfredo Cardigliano ac46a4dd58 Added L2TP tunnel type. Warning fix. 2019-11-06 09:55:22 +01:00
Luca fb56b042c0 Merge branch 'dev' of https://github.com/ntop/nDPI into dev 2019-11-05 12:15:27 +00:00
Luca 6298ecc271 Added tunnelling decapsulation 2019-11-05 08:21:31 +00:00
Luca Deri a26fe08aa6 Updated results 2019-11-04 22:11:33 +01:00
Luca Deri 5b2c0f68fe Telnet fix 2019-11-04 22:06:02 +01:00
Luca Deri e695dd6ead Merge branch 'dev' of https://github.com/ntop/nDPI into dev 2019-11-03 17:15:48 +01:00
Luca Deri 953571e3d8 Added comment 2019-11-03 17:15:40 +01:00
Luca Deri 01455c3188 Merge pull request #808 from oleg-umnik/dev
Change type
2019-11-03 17:15:06 +01:00
Luca Deri a5210af823 Merge pull request #807 from oleg-umnik/fix_3
Align CSV header with actual row data
2019-11-03 17:14:38 +01:00
Luca Deri 9e42b525ec Merge pull request #806 from oleg-umnik/fix_1
Don't leak memory in live capture mode
2019-11-03 17:13:49 +01:00
Luca Deri 02d69b72f5 Merge pull request #803 from haroflow/dev
Updated Breed's descriptions in ndpi_get_proto_breed_name
2019-11-03 17:13:18 +01:00
Luca Deri c998e2e9ef Merge pull request #802 from AndrewKarelin/dev
Added some public DNSoverHTTPS servers
2019-11-03 17:07:17 +01:00
Luca Deri a3a85106a1 Implemented SQL Injection and XSS attack detection 2019-11-01 23:05:11 +01:00
Luca 75302a10bd Merge branch 'dev' of https://github.com/ntop/nDPI into dev 2019-10-31 09:31:42 +01:00
Luca 2ab0433aca Updated content-type parsing 2019-10-31 09:31:26 +01:00
Luca e272db0f7f content type parsing fix 2019-10-31 09:15:57 +01:00
Luca Deri 3580765ba3 Updated result 2019-10-31 09:04:52 +01:00
Luca cb79d89f83 Merge branch 'dev' of https://github.com/ntop/nDPI into dev 2019-10-31 08:58:03 +01:00
Luca 2e178d0f05 Improved libary initialization for custom protocols 2019-10-31 08:57:33 +01:00
Luca Deri edf0b171e2 Merge pull request #810 from catenacyber/fuzztarget
Adds fuzz target
2019-10-31 08:54:44 +01:00
Philippe Antoine 148506ede8 Adds fuzz target
And configur option enable-fuzztargets
2019-10-31 08:37:42 +01:00
Luca c0a08d9ca2 Merge branch 'dev' of https://github.com/ntop/nDPI into dev 2019-10-31 00:14:40 +01:00
Luca 4802987178 Initial work towards HTTP content-type export 2019-10-31 00:14:20 +01:00
Luca Deri 1cd7cf9990 Merge pull request #809 from catenacyber/fuzz1fix
Fix buffer over read in ndpi_handle_ipv6_extension_headers
2019-10-30 17:31:28 +01:00
Philippe Antoine 4830755fac Fix buffer over read in ndpi_handle_ipv6_extension_headers 2019-10-30 17:18:21 +01:00
Renan de Souza 124545e1ed Added twitch.tv website 2019-10-29 16:26:17 -03:00
Luca af01e61c89 Fixed invalid guess with the top defined protocol 2019-10-29 19:45:15 +01:00
Renan de Souza 9400a3b9ef Added ranges 20.180.0.0/14, 20.184.0.0/13 to Skype 2019-10-29 15:28:08 -03:00
Luca 6e314ea6d7 Added zabbix dissector 2019-10-29 19:25:46 +01:00
Oleg A. Arkhangelsky dfd962a8bc Change type
Use double type instead of float when printing time for CSV file.
Float type is too small for 64 bit int time so cast corrupts value.
2019-10-29 21:23:42 +03:00
Oleg A. Arkhangelsky cfcbfe1e8f Align CSV header with actual row data 2019-10-29 21:20:56 +03:00
Luca 0e54f87b18 Added telnet dissector
Improved data report
2019-10-29 19:12:42 +01:00
Oleg A. Arkhangelsky 9f5e5b90e5 Don't leak memory in live capture mode 2019-10-29 21:11:31 +03:00
Renan de Souza d619ba0857 Merge remote-tracking branch 'upstream/dev' into dev 2019-10-29 14:59:18 -03:00
Renan de Souza fbea243e56 Added brasilbandalarga.com.br and .eaqbr.com.br as EAQ on host_match[] 2019-10-29 11:48:23 -03:00
Renan de Souza d062386656 Added ^pastebin.com to host_match[] 2019-10-29 09:54:42 -03:00
Luca Deri d2f04f5bdf Fixed prototype 2019-10-29 10:32:13 +01:00
Luca Deri 42c8d3ac27 Added ability to defien custom protocols 2019-10-29 10:29:12 +01:00
Luca Deri d53563ab46 Implemented Microsoft range 2019-10-28 00:15:51 +01:00
Luca Deri 3d5f0ee315 Implemented stacked DPI decoding 2019-10-27 23:20:56 +01:00
Luca Deri ecdb7cdc55 Various improvements in particular for CapWAP and Bloomberg 2019-10-27 23:05:24 +01:00
Luca Deri fd38b752c4 Added capwap support 2019-10-27 19:03:23 +01:00
Luca Deri 64804a2a24 Fixed some false positivies with skype and stun-based protocols 2019-10-27 12:23:57 +01:00
Luca Deri b603cb4530 nDPI TLS improvements using the server certificate 2019-10-26 10:54:32 +02:00
Luca Deri 8f2c7c0638 Code cleanup 2019-10-26 08:28:14 +02:00
Luca Deri 044ba7697a Improved guess 2019-10-25 16:02:44 +02:00
Luca Deri e6bd64b3ea Improved HTTP reporting in ndpiReader 2019-10-25 15:56:47 +02:00
Renan de Souza 56db916833 Merge remote-tracking branch 'upstream/dev' into dev 2019-10-25 08:57:49 -03:00
Luca Deri 12cf0c4763 Further SMB improvements 2019-10-25 07:22:29 +02:00
Luca Deri 0a92e0f532 Ficed invalid SMBv1 detection 2019-10-25 07:00:57 +02:00
Luca Deri e6f9177fdb SSH dissection improvements 2019-10-25 00:05:18 +02:00
Luca Deri c3f6a4a57a SMTP and SSH dissection fixes 2019-10-24 23:28:32 +02:00
Renan de Souza 653c209253 Added 52.84.0.0/14 range as Amazon 2019-10-24 14:50:54 -03:00
Luca Deri 0974075fa0 Major cleanup
Removed ndpi_pref_http_dont_dissect_response and ndpi_pref_dns_dont_dissect_response as the ndpi_extra_dissection_possible() call will now handle everything
2019-10-24 19:48:55 +02:00
Renan de Souza 53e1ee3475 Changed Breeds descriptions in ndpi_get_proto_breed_name: Dangerous to Potentially Dangerous, added Dangerous (SMBv1) 2019-10-24 14:43:10 -03:00
Andrew Karelin 46affea055 Added some public DNSoverHTTPS servers
List of servers taken from https://github.com/curl/curl/wiki/DNS-over-HTTPS
2019-10-23 18:47:51 +05:00
Luca Deri 0ffe5cf1ff Added extra processing for POP and SMTP 2019-10-22 00:57:35 +02:00
Luca Deri d023f9bf2d Silenced TLS warning 2019-10-21 15:33:20 +02:00
Alfredo Cardigliano b2832cee8e rpm-sign fix for centos8 2019-10-21 09:26:40 +02:00
Luca Deri 960aa77b6d Reworked email metaata extraction 2019-10-21 01:27:07 +02:00
Luca Deri 58daa5ed7d Added POP3 metadata extraction 2019-10-20 23:06:05 +02:00
Luca Deri 437e8bd706 Implemented IMAP data extraction 2019-10-20 22:46:08 +02:00
Luca Deri 1a5c7daaf6 Implemented FTP user/pwd extraction 2019-10-20 21:49:45 +02:00
Luca Deri c1ba4764b5 Merge pull request #799 from ntop/ndpi_memleak_fix
Fix memory leak in ndpiReader.
2019-10-20 11:47:13 +02:00
Ravi Kerur 7cb3cb7353 Fix memory leak in ndpiReader.
Changes in library for strict function prototype.

Signed-off-by: Ravi Kerur <ravi.kerur@viasat.com>
2019-10-19 08:59:48 -07:00
Alfredo Cardigliano 604abaf81c Disabled debug_package 2019-10-18 12:30:42 +02:00
Luca Deri 8b157bb13f Ports are not JSON printed when 0 (e.g. with ICMP) 2019-10-17 00:38:42 +02:00
Luca Deri a8c71dcd20 Improved ndpi_flow2json 2019-10-17 00:29:30 +02:00
Alfredo Cardigliano 363a8f6282 Checking gmtime_r return value 2019-10-16 07:54:33 +02:00
Luca Deri 5b314cf1c3 Updated ndpi_flow2json 2019-10-16 12:31:41 +02:00
Luca Deri 02783bd7c6 Merge branch 'dev' of https://github.com/ntop/nDPI into dev 2019-10-15 23:06:41 +02:00
Luca Deri d5c918d258 Initial implementation of ndpi_flow2json APi call 2019-10-15 23:06:30 +02:00
emanuele-f 6b044335cd Implement nDPI patricia tree API 2019-10-15 01:22:17 +02:00
Luca Deri cbe20d3740 Fixes for API changes 2019-10-09 22:25:40 +02:00
Luca Deri 21bc84e837 Modified API signatures for
- ndpi_ssl_version2str()
- ndpi_detection_giveup()
2019-10-09 22:09:58 +02:00
Luca Deri 203359ed7f Fixed ndpi_ssl_version2str() 2019-10-08 23:57:56 +02:00
Luca Deri 24a26a2e94 Added NetBIOS metadata export 2019-10-08 23:40:56 +02:00
Luca Deri 0a7521060a Merge branch 'dev' of https://github.com/ntop/nDPI into dev 2019-10-08 13:32:43 +02:00
Luca Deri 6b5a9aa992 Implemented Kerberos metadata extraction 2019-10-08 13:32:21 +02:00
emanuele-f 2dfdaa4d70 Replace strtok with reentrant version 2019-10-08 11:59:20 +02:00
emanuele-f f2504494fe New API functions: ndpi_load_categories_file and ndpi_load_category 2019-10-08 11:55:47 +02:00
Luca Deri 256858d2e5 Merge branch 'dev' of https://github.com/ntop/nDPI into dev 2019-10-08 11:36:11 +02:00
Luca Deri 10873bfe35 Added ndpi_get_l4_proto_name() and ndpi_get_l4_proto_info() API calls to print L4 protocol 2019-10-08 11:35:33 +02:00
emanuele-f e939f1c1d1 Fix leaks in ndpi_load_hostname_category when ac_automata_add fails 2019-10-08 11:07:59 +02:00
emanuele-f b2c8cb655c ndpi_load_hostname_category now performs strdup on the name argument
This simplifies the API as an application is not required to keep references to the strings to free
2019-10-08 10:23:00 +02:00
emanuele-f 4bdbf02c2d Fix invalid memory accesses 2019-10-04 14:35:51 +02:00
Luca Deri f83b2a0940 Fixed ndpi_extra_dissection_possible() 2019-10-04 14:13:53 +02:00
emanuele-f 76ec74cbf1 Fix out of bounds read in ndpi_match_custom_category 2019-10-04 11:54:05 +02:00
Luca Deri 8ae5da1472 Moved to 3.1 release 2019-10-04 07:45:57 +00:00
325 changed files with 29127 additions and 8388 deletions
+17
View File
@@ -0,0 +1,17 @@
version: 3.1.{build}
branches:
only:
- dev
environment:
matrix:
- COMPILER: mingw
MINGW_DIR: c:\msys64\mingw32
before_build:
- set Path=%MINGW_DIR%\bin;%Path%
build_script:
- set Path=%MINGW_DIR%\bin;c:\msys64\usr\bin;
- bash autogen.sh
- cd src/lib
- make
+3
View File
@@ -0,0 +1,3 @@
*.sh -crlf
*.ac -crlf
*.am -crlf
+84 -1
View File
@@ -7,6 +7,7 @@ matrix:
- os: linux
compiler: gcc
dist: bionic
addons:
apt:
packages:
@@ -15,12 +16,55 @@ matrix:
- os: linux
compiler: clang
dist: bionic
addons:
apt:
packages:
- libpcap-dev
- autogen
- os: linux
compiler: gcc
dist: bionic
arch: arm64
addons:
apt:
packages:
- libpcap-dev
- autogen
- os: linux
compiler: clang
dist: bionic
arch: arm64
addons:
apt:
packages:
- libpcap-dev
- autogen
# Targets below have been disabled as we have no way
# to debug on tsuch platforms at the moment
# - os: linux
# compiler: gcc
# dist: bionic
# arch: s390x
# addons:
# apt:
# packages:
# - libpcap-dev
# - autogen
#
# - os: linux
# compiler: clang
# dist: bionic
# arch: s390x
# addons:
# apt:
# packages:
# - libpcap-dev
# - autogen
- os: linux
compiler: gcc-8
addons:
@@ -75,6 +119,45 @@ matrix:
env:
- MATRIX_EVAL="CC=clang-7 && CXX=clang++-7"
- name: fuzza
env: CXXFLAGS="-g -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address -fsanitize=fuzzer-no-link" CFLAGS="-g -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address -fsanitize=fuzzer-no-link" LDFLAGS="-g -fsanitize=address" QA_FUZZ=asan CC=clang-7 && CXX=clang++-7 ASAN_SYMBOLIZER_PATH=/usr/local/clang-7.0.0/bin/llvm-symbolizer
os: linux
compiler: clang-7
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-7
packages:
- clang-7
- libpcap-dev
- autogen
- name: fuzzm
env: CXXFLAGS="-g -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=memory -fsanitize=fuzzer-no-link" CFLAGS="-g -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=memory -fsanitize=fuzzer-no-link" LDFLAGS="-g -fsanitize=memory" QA_FUZZ=msan CC=clang-7 && CXX=clang++-7 MSAN_SYMBOLIZER_PATH=/usr/local/clang-7.0.0/bin/llvm-symbolizer
os: linux
compiler: clang-7
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-7
packages:
- clang-7
- libpcap-dev
- autogen
- name: fuzzu
env: CXXFLAGS="-g -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=undefined -fsanitize=fuzzer-no-link" CFLAGS="-g -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=undefined -fno-sanitize-recover=undefined,integer -fsanitize=fuzzer-no-link" LDFLAGS="-g -fsanitize=undefined" QA_FUZZ=ubsan CC=clang-7 && CXX=clang++-7
os: linux
compiler: clang-7
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-7
packages:
- clang-7
- libpcap-dev
- autogen
before_install:
@@ -85,7 +168,7 @@ before_script:
# - lcov --directory . --zerocounters
script:
- ./configure
- if [ -n "$QA_FUZZ" ]; then ./configure --enable-fuzztargets ; else ./configure ; fi
- make
#after_script:
+90 -5
View File
@@ -1,5 +1,91 @@
# CHANGELOG
#### nDPI 3.2 (February 2020)
## New Features
* New API calls
* Protocol detection: ndpi_is_protocol_detected
* Categories: ndpi_load_categories_file / ndpi_load_category
* JSON/TLV serialization: ndpi_serialize_string_boolean / ndpi_serialize_uint32_boolean
* Patricia tree: ndpi_load_ipv4_ptree
* Module initialization: ndpi_init_detection_module / ndpi_finalize_initalization
* Base64 encoding: ndpi_base64_encode
* JSON exprot: ndpi_flow2json
* Print protocol: ndpi_get_l4_proto_name / ndpi_get_l4_proto_info
* Libfuzz integration
* Implemented Community ID hash (API call ndpi_flowv6_flow_hash and ndpi_flowv4_flow_hash)
* Detection of RCE in HTTP GET requests via PCRE
* Integration of the libinjection library to detect SQL injections and XSS type attacks in HTTP requests
## New Supported Protocols and Services
* TLS
* Added ALPN support
* Added export of supported version in TLS header
* Added Telnet dissector with metadata extraction
* Added Zabbix dissector
* Added POP3/IMAP metadata extraction
* Added FTP user/password extraction
* Added NetBIOS metadata extraction
* Added Kerberos metadata extraction
* Implemented SQL Injection and XSS attack detection
* Host-based detection improvements and changes
* Added Microsoft range
* Added twitch.tv website
* Added brasilbandalarga.com.br and .eaqbr.com.br as EAQ
* Added 20.180.0.0/14, 20.184.0.0/13 range as Skype
* Added 52.84.0.0/14 range as Amazon
* Added ^pastebin.com
* Changed 13.64.0.0/11 range from Skype to Microsoft
* Refreshed Whatsapp server list, added *whatsapp-*.fbcdn.net IPs
* Added public DNSoverHTTPS servers
## Improvements
* Reworked and improved the TLS dissector
* Reworked Kerberos dissector
* Improved DNS response decoding
* Support for DNS continuous flow dissection
* Improved Python bindings
* Improved Ethereum support
* Improved categories detection with streaming and HTTP
* Support for IP-based detection to compute the application protocol
* Renamed protocol 104 to IEC60870 (more meaningful)
* Added failed authentication support with FTP
* Renamed DNSoverHTTPS to handle bot DoH and DoT
* Implemented stacked DPI decoding
* Improvements for CapWAP and Bloomberg
* Improved SMB dissection
* Improved SSH dissection
* Added capwap support
* Modified API signatures for ndpi_ssl_version2str / ndpi_detection_giveup
* Removed ndpi_pref_http_dont_dissect_response / ndpi_pref_dns_dont_dissect_response (replaced by ndpi_extra_dissection_possible)
## Fixes
* Fixed memory invalid access in SMTP and leaks in TLS
* Fixed a few memory leaks
* Fixrd invalid memory access in a few protocol dissectors (HTTP, memcached, Citrix, STUN, DNS, Amazon Video, TLS, Viber)
* Fixed IPv6 address format across the various platforms/distributions
* Fixed infinite loop in ndpi_workflow_process_packet
* Fixed SHA1 certificate detection
* Fixed custom protocol detection
* Fixed SMTP dissection (including email)
* Fixed Telnet dissection and invalid password report
* Fixed invalid category matching in HTTP
* Fixed Skype and STUN false positives
* Fixed SQL Injection detection
* Fixed invalid SMBv1 detection
* Fixed SSH dissection
* Fixed ndpi_ssl_version2str
* Fixed ndpi_extra_dissection_possible
* Fixed out of bounds read in ndpi_match_custom_category
## Misc
* ndpiReader
* CSV output enhancements
* Added tunnelling decapsulation
* Improved HTTP reporting
------------------------------------------------------------------------
#### nDPI 3.0 (October 2019)
## New Features
@@ -67,7 +153,6 @@
* Fix DNS rsp_addr missing in some tiny responses
* Various hardening fixes
------------------------------------------------------------------------
#### nDPI 2.8 (March 2019)
@@ -145,10 +230,10 @@
* Deb and RPM packages: ndpi with shared libraries and binaries, ndpi-dev with headers and static libraries
* Protocols now have an optional subprotocol: Spotify cannot have subprotocols, DNS can (DNS.Spotify)
* New API functions:
- ndpi_fill_ip_protocol_category to handle ICMP flows category
- ndpi_flowv4_flow_hash and ndpi_flowv6_flow_hash to support the Community ID Flow Hashing (https://github.com/corelight/community-id-spec)
- ndpi_protocol2id to print the protocol as ID
- ndpi_get_custom_category_match to search host in custom categories
* ndpi_fill_ip_protocol_category to handle ICMP flows category
* ndpi_flowv4_flow_hash and ndpi_flowv6_flow_hash to support the Community ID Flow Hashing (https://github.com/corelight/community-id-spec)
* ndpi_protocol2id to print the protocol as ID
* ndpi_get_custom_category_match to search host in custom categories
* Changed ndpi_detection_giveup API: guess is now part of the call
* Added DPDK support to ndpiReader
* Removed Musical.ly protocol (service no longer used)
+4
View File
@@ -1,6 +1,10 @@
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = src/lib example tests
if BUILD_FUZZTARGETS
SUBDIRS += fuzz
endif
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libndpi.pc
+1
View File
@@ -4,6 +4,7 @@
[![Build Status](https://travis-ci.org/ntop/nDPI.png?branch=dev)](https://travis-ci.org/ntop/nDPI)
[![Code Quality: Cpp](https://img.shields.io/lgtm/grade/cpp/g/ntop/nDPI.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/ntop/nDPI/context:cpp)
[![Total Alerts](https://img.shields.io/lgtm/alerts/g/ntop/nDPI.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/ntop/nDPI/alerts)
[![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/ndpi.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:ndpi)
## What is nDPI ?
+3 -3
View File
@@ -1,7 +1,7 @@
#!/bin/sh
NDPI_MAJOR="2"
NDPI_MINOR="9"
NDPI_MAJOR="3"
NDPI_MINOR="2"
NDPI_PATCH="0"
NDPI_VERSION_SHORT="$NDPI_MAJOR.$NDPI_MINOR.$NDPI_PATCH"
@@ -45,4 +45,4 @@ cat configure | sed "s/#define PACKAGE/#define NDPI_PACKAGE/g" | sed "s/#define
cat configure.tmp > configure
chmod +x configure
./configure $*
./configure "$*"
+87 -48
View File
@@ -4,6 +4,15 @@ AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([foreign subdir-objects])
AC_ARG_WITH(llvm_sanitizer, [ --with-llvm-sanitizer Build with support for the LLVM address sanitizer])
AS_IF([test "${with_llvm_sanitizer+set}" = set],[
CFLAGS="${CFLAGS} -g -O2 -Wno-unused-value -fsanitize=address -fno-omit-frame-pointer"
LDFLAGS="${LDFLAGS} -fsanitize=address"
CC=clang
CXX=clang++
])
LT_INIT
AC_PROG_CC
@@ -41,6 +50,7 @@ AC_DEFINE_UNQUOTED(NDPI_GIT_DATE, "${GIT_DATE}", [Last GIT change])
AC_CHECK_HEADERS([netinet/in.h stdint.h stdlib.h string.h unistd.h])
ADDITIONAL_LIBS=
PCAP_HOME=$HOME/PF_RING/userland
DPDK_TARGET=
@@ -68,8 +78,14 @@ SYSTEM=`uname -s`
if test $SYSTEM = "Darwin"; then
CC=clang
fi
CUSTOM_NDPI=
if test -d ../nDPI-custom; then :
CUSTOM_NDPI="-DCUSTOM_NDPI_PROTOCOLS"
AC_MSG_RESULT([Compiling with custom nDPI protocols])
fi
AC_ARG_WITH(hyperscan, [ --with-hyperscan Enable nDPI build with Intel Hyperscan])
AS_IF([test "${with_hyperscan+set}" = set],[
@@ -90,58 +106,80 @@ AS_IF([test "${with_hyperscan+set}" = set],[
])
])
if test -f $PCAP_HOME/libpcap/libpcap.a; then :
echo "Using libpcap from $PCAP_HOME"
PCAP_INC="-I $PCAP_HOME/libpcap"
PCAP_LIB="$PCAP_HOME/libpcap/libpcap.a $PCAP_HOME/lib/libpfring.a $LIBNUMA `$PCAP_HOME/lib/pfring_config --libs`"
AC_CHECK_LIB([rt], [clock_gettime], [PCAP_LIB="$PCAP_LIB -lrt"])
AC_CHECK_LIB([nl], [nl_handle_alloc], [PCAP_LIB="$PCAP_LIB -lnl"])
# The dlopen() function is in libdl on GLIBC-based systems
# and in the C library for *BSD systems
AC_CHECK_LIB([dl], [dlopen, dlsym], [DL_LIB="-ldl"],
[AC_CHECK_LIB([c], [dlopen, dlsym], [DL_LIB="-lc"],
[AC_MSG_ERROR([unable to find the dlopen(), dlsym() functions]) ]) ])
else
AC_CHECK_LIB([pcap], [pcap_open_live], [PCAP_LIB="-lpcap"])
if test $ac_cv_lib_pcap_pcap_open_live = "no"; then :
echo ""
echo "ERROR: Missing libpcap(-dev) library required to compile the example application"
echo "ERROR: Please install it and try again"
exit
fi
fi
dnl> https://github.com/json-c/json-c
AC_ARG_ENABLE([json-c],
AS_HELP_STRING([--disable-json-c], [Disable json-c support]))
AS_IF([test "x$enable_json_c" != "xno"], [
PKG_CHECK_MODULES([JSONC],[json-c],
[
CFLAGS="$CFLAGS $JSONC_CFLAGS"
LDFLAGS="$LDFLAGS $JSONC_LIBS"
AC_CHECK_LIB(json-c, json_object_new_object, AC_DEFINE_UNQUOTED(HAVE_JSON_C, 1, [The JSON-C library is present]))
],
[
JSONC_HOME="$HOME/json-c"
if test -d "$JSONC_HOME"; then :
CFLAGS="$CFLAGS -I $JSONC_HOME"
LDFLAGS="$LDFLAGS $JSONC_HOME/.libs/libjson-c.a"
AC_MSG_RESULT([Found json-c in $JSONC_HOME])
AC_DEFINE_UNQUOTED(HAVE_JSON_C, 1, [The JSON-C library is present])
fi
])
])
case "$host" in
*-*-mingw32*|*-*-msys)
CFLAGS="${CFLAGS} -DOS_WIN32"
LDFLAGS="${LDFLAGS} -lws2_32 -lucrtbase"
;;
*)
if test -f $PCAP_HOME/libpcap/libpcap.a; then :
echo "Using libpcap from $PCAP_HOME"
PCAP_INC="-I $PCAP_HOME/libpcap"
PCAP_LIB="$PCAP_HOME/libpcap/libpcap.a $PCAP_HOME/lib/libpfring.a $LIBNUMA `$PCAP_HOME/lib/pfring_config --libs`"
AC_CHECK_LIB([rt], [clock_gettime], [PCAP_LIB="$PCAP_LIB -lrt"])
AC_CHECK_LIB([nl], [nl_handle_alloc], [PCAP_LIB="$PCAP_LIB -lnl"])
# The dlopen() function is in libdl on GLIBC-based systems
# and in the C library for *BSD systems
AC_CHECK_LIB([dl], [dlopen, dlsym], [DL_LIB="-ldl"],[AC_CHECK_LIB([c], [dlopen, dlsym], [DL_LIB="-lc"],[AC_MSG_ERROR([unable to find the dlopen(), dlsym() functions]) ]) ])
else
AC_CHECK_LIB([pcap], [pcap_open_live], [PCAP_LIB="-lpcap"])
if test $ac_cv_lib_pcap_pcap_open_live = "no"; then :
echo ""
echo "ERROR: Missing libpcap(-dev) library required to compile the example application"
echo "ERROR: Please install it and try again"
exit
fi
fi
;;
esac
AC_ARG_ENABLE([debug-messages],
AS_HELP_STRING([--enable-debug-messages], [Define NDPI_ENABLE_DEBUG_MESSAGES=1]), [
AC_DEFINE(NDPI_ENABLE_DEBUG_MESSAGES, 1, [Enable ndpi_debug_messages]) ])
AC_ARG_ENABLE(fuzztargets,
AS_HELP_STRING([--enable-fuzztargets], [Enable fuzz targets]),[enable_fuzztargets=$enableval],[enable_fuzztargets=no])
AM_CONDITIONAL([BUILD_FUZZTARGETS], [test "x$enable_fuzztargets" = "xyes"])
AS_IF([test "x$enable_fuzztargets" = "xyes"], [
AC_PROG_CXX
AC_LANG_PUSH(C++)
tmp_saved_flags=$[]_AC_LANG_PREFIX[]FLAGS
AS_IF([test "x$LIB_FUZZING_ENGINE" = "x"], [
LIB_FUZZING_ENGINE=-fsanitize=fuzzer
AC_SUBST(LIB_FUZZING_ENGINE)
])
_AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $LIB_FUZZING_ENGINE"
AC_MSG_CHECKING([whether $CXX accepts $LIB_FUZZING_ENGINE])
AC_LINK_IFELSE([AC_LANG_SOURCE([[
#include <sys/types.h>
extern "C" int LLVMFuzzerTestOneInput(const unsigned char *Data, size_t Size);
extern "C" int LLVMFuzzerTestOneInput(const unsigned char *Data, size_t Size) {
(void)Data;
(void)Size;
return 0;
}
]])],
[ AC_MSG_RESULT(yes)
has_sanitizefuzzer=yes],
[ AC_MSG_RESULT(no) ]
)
_AC_LANG_PREFIX[]FLAGS=$tmp_saved_flags
AC_LANG_POP()
])
AM_CONDITIONAL([HAS_FUZZLDFLAGS], [test "x$has_sanitizefuzzer" = "xyes"])
AC_CHECK_LIB(pthread, pthread_setaffinity_np, AC_DEFINE_UNQUOTED(HAVE_PTHREAD_SETAFFINITY_NP, 1, [libc has pthread_setaffinity_np]))
AC_CONFIG_FILES([Makefile example/Makefile example/Makefile.dpdk tests/Makefile libndpi.pc src/include/ndpi_define.h src/lib/Makefile python/Makefile])
dnl> PCRE
AC_ARG_WITH(pcre, [ --with-pcre Enable nDPI build with libpcre])
if test "${with_pcre+set}" = set; then :
AC_CHECK_LIB(pcre, pcre_compile, AC_DEFINE_UNQUOTED(HAVE_PCRE, 1, [libpcre(-dev) is present]))
if test "x$ac_cv_lib_pcre_pcre_compile" = xyes; then :
ADDITIONAL_LIBS=-lpcre
fi
fi
AC_CONFIG_FILES([Makefile example/Makefile example/Makefile.dpdk tests/Makefile libndpi.pc src/include/ndpi_define.h src/lib/Makefile python/Makefile fuzz/Makefile])
AC_CONFIG_HEADERS(src/include/ndpi_config.h)
AC_SUBST(GIT_RELEASE)
AC_SUBST(NDPI_MAJOR)
@@ -152,8 +190,9 @@ AC_SUBST(SVN_DATE)
AC_SUBST(JSON_C_LIB)
AC_SUBST(PCAP_INC)
AC_SUBST(PCAP_LIB)
AC_SUBST(ADDITIONAL_LIBS)
AC_SUBST(DL_LIB)
AC_SUBST(DPDK_TARGET)
AC_SUBST(HAVE_PTHREAD_SETAFFINITY_NP)
AC_SUBST(CUSTOM_NDPI)
AC_OUTPUT
+1 -1
View File
@@ -17,7 +17,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
APP = ndpiReader.dpdk
LIBNDPI = $(PWD)/../src/lib/libndpi.a
SRCS-y := reader_util.c ndpiReader.c
SRCS-y := reader_util.c intrusion_detection.c ndpiReader.c
CFLAGS += -g
CFLAGS += -Wno-strict-prototypes -Wno-missing-prototypes -Wno-missing-declarations -Wno-unused-parameter -I $(PWD)/../src/include @CFLAGS@ -DUSE_DPDK
+19 -10
View File
@@ -1,25 +1,34 @@
CC=@CC@
CXX=@CXX@
CFLAGS=-g -I../src/include @CFLAGS@
LIBNDPI=../src/lib/libndpi.a
LDFLAGS=$(LIBNDPI) @PCAP_LIB@ -lpthread -lm @LDFLAGS@
OBJS=ndpiReader.o reader_util.o
SRCHOME=../src
CFLAGS=-g -fPIC -DPIC -I$(SRCHOME)/include @CFLAGS@
LIBNDPI=$(SRCHOME)/lib/libndpi.a
LDFLAGS=$(LIBNDPI) @PCAP_LIB@ @ADDITIONAL_LIBS@ -lpthread -lm @LDFLAGS@
HEADERS=intrusion_detection.h reader_util.h $(SRCHOME)/include/ndpi_api.h \
$(SRCHOME)/include/ndpi_typedefs.h $(SRCHOME)/include/ndpi_protocol_ids.h
OBJS=ndpiReader.o reader_util.o intrusion_detection.o
PREFIX?=@prefix@
all: ndpiReader @DPDK_TARGET@
ndpiReader: $(OBJS) $(LIBNDPI)
$(CXX) $(CFLAGS) $(OBJS) -o $@ $(LDFLAGS)
EXECUTABLE_SOURCES := ndpiReader.c
COMMON_SOURCES := $(filter-out $(EXECUTABLE_SOURCES),$(wildcard *.c ))
libndpiReader.a: $(COMMON_SOURCES:%.c=%.o) $(LIBNDPI)
ar rsv libndpiReader.a $(COMMON_SOURCES:%.c=%.o)
ndpiReader: libndpiReader.a $(LIBNDPI) $(EXECUTABLE_SOURCES:%.c=%.o)
$(CXX) $(CFLAGS) $(EXECUTABLE_SOURCES:%.c=%.o) libndpiReader.a -o $@ $(LDFLAGS)
%.o: %.c $(HEADERS) Makefile
$(CC) $(CFLAGS) -c $< -o $@
install:
mkdir -p $(DESTDIR)$(PREFIX)/bin/
mkdir -p $(DESTDIR)$(PREFIX)/sbin/ndpi
mkdir -p $(DESTDIR)$(PREFIX)/share/ndpi
cp ndpiReader $(DESTDIR)$(PREFIX)/bin/
cp protos.txt $(DESTDIR)$(PREFIX)/sbin/ndpi/ndpiProtos.txt
cp mining_hosts.txt $(DESTDIR)$(PREFIX)/sbin/ndpi/ndpiCustomCategory.txt
cp protos.txt $(DESTDIR)$(PREFIX)/share/ndpi/ndpiProtos.txt
cp mining_hosts.txt $(DESTDIR)$(PREFIX)/share/ndpi/ndpiCustomCategory.txt
[ -f build/app/ndpiReader.dpdk ] && cp build/app/ndpiReader.dpdk $(DESTDIR)$(PREFIX)/bin/ || true
[ -f ndpiReader.dpdk ] && cp ndpiReader.dpdk $(DESTDIR)$(PREFIX)/bin/ || true
@@ -27,7 +36,7 @@ dpdk:
make -f Makefile.dpdk
check:
cppcheck --template='{file}:{line}:{severity}:{message}' --quiet --enable=all --force -I../src/include -I/usr/local/include/json-c *.c
cppcheck --template='{file}:{line}:{severity}:{message}' --quiet --enable=all --force -I$(SRCHOME)/include *.c
clean:
/bin/rm -f *.o ndpiReader ndpiReader.dpdk
+468
View File
@@ -0,0 +1,468 @@
/*
* intrusion_detection.c
*
* Copyright (C) 2011-19 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
*
* nDPI is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* nDPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with nDPI. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "intrusion_detection.h"
double normalize(ndpi_norm_value* tresholds){
if(tresholds->upper_bound != tresholds->lower_bound){
tresholds->norm_value = (tresholds->value - tresholds->lower_bound) / (tresholds->upper_bound - tresholds->lower_bound);
}else{
if(tresholds->value > tresholds->upper_bound){
tresholds->norm_value = 1 + (tresholds->value - tresholds->lower_bound) / tresholds->upper_bound;
}else{
tresholds->norm_value = 1 - (tresholds->value - tresholds->lower_bound) / tresholds->upper_bound;
}
}
if(tresholds->norm_value >= 0){
return tresholds->norm_value * tresholds->weight;
}
else{
return (1 - tresholds->norm_value) * tresholds->weight;
}
}
double get_flow_score(ndpi_norm_value* scores, int n_metrics){
double flow_score = 0;
for(int i=0; i<n_metrics; i++){
flow_score += normalize(&scores[i]);
}
return flow_score;
}
/* ********************************** */
double Ddos_score(struct ndpi_flow_info* flow){
double f = (double)flow->first_seen/1000.0, l = (double)flow->last_seen/1000.0;
int n_metrics = 6;
ndpi_norm_value* scores = malloc(n_metrics * sizeof(ndpi_norm_value));
/* pktlen_c_to_s_avg */
int i = 0;
scores[i].lower_bound = 70.0;
scores[i].upper_bound = 263.4799999999999;
scores[i].weight = 0.21257330032661592;
scores[i].value = ndpi_data_average(flow->pktlen_c_to_s);
/* pktlen_s_to_c_max */
i++;
scores[i].lower_bound = 90.0;
scores[i].upper_bound = 2974.0;
scores[i].weight = 0.21073785073559176;
scores[i].value = ndpi_data_max(flow->pktlen_s_to_c);
/* pktlen_s_to_c_avg */
i++;
scores[i].lower_bound = 72.7;
scores[i].upper_bound = 1130.4199999999996;
scores[i].weight = 0.21257330032661592;
scores[i].value = ndpi_data_average(flow->pktlen_s_to_c);
/* pktlen_s_to_c_stddev */
i++;
scores[i].lower_bound = 0.0;
scores[i].upper_bound = 906.0;
scores[i].weight = 0.20990954527912953;
scores[i].value = ndpi_data_stddev(flow->pktlen_s_to_c);
/* fin */
i++;
scores[i].lower_bound = 0.0;
scores[i].upper_bound = 2.0;
scores[i].weight = 0.07710300166602348;
scores[i].value = flow->fin_count;
/* s_to_c_fin */
i++;
scores[i].lower_bound = 0.0;
scores[i].upper_bound = 2.0;
scores[i].weight = 0.07710300166602348;
scores[i].value = flow->dst2src_fin_count;
// sum = 1.0
double flow_score = get_flow_score(scores, n_metrics);
free(scores);
return flow_score;
}
double Dos_goldeneye_score(struct ndpi_flow_info* flow){
double f = (double)flow->first_seen/1000.0, l = (double)flow->last_seen/1000.0;
int n_metrics = 6;
ndpi_norm_value* scores = malloc(n_metrics * sizeof(ndpi_norm_value));
/* pktlen_s_to_c_max */
int i = 0;
scores[i].lower_bound = 74.0;
scores[i].upper_bound = 3292.6699999999764;
scores[i].weight = 0.3123007140611667;
scores[i].value = ndpi_data_max(flow->pktlen_s_to_c);
/* pktlen_s_to_c_avg */
i++;
scores[i].lower_bound = 68.7;
scores[i].upper_bound = 1354.0569999999987;
scores[i].weight = 0.23802038891633356;
scores[i].value = ndpi_data_average(flow->pktlen_s_to_c);
/* pktlen_s_to_c_stddev */
i++;
scores[i].lower_bound = 0.0;
scores[i].upper_bound = 959.4469999999993;
scores[i].weight = 0.3111779763775991;
scores[i].value = ndpi_data_stddev(flow->pktlen_s_to_c);
/* syn */
i++;
scores[i].lower_bound = 0.0;
scores[i].upper_bound = 2.0;
scores[i].weight = 0.0464364305923564;
scores[i].value = flow->syn_count;
/* c_to_s_syn */
i++;
scores[i].lower_bound = 0.0;
scores[i].upper_bound = 1.0;
scores[i].weight = 0.04562805946018772;
scores[i].value = flow->src2dst_syn_count;
/* s_to_c_syn */
i++;
scores[i].lower_bound = 0.0;
scores[i].upper_bound = 2.0;
scores[i].weight = 0.0464364305923564;
scores[i].value = flow->dst2src_syn_count;
// sum = 0.9999999999999998
double flow_score = get_flow_score(scores, n_metrics);
free(scores);
return flow_score;
}
double Dos_hulk_score(struct ndpi_flow_info* flow){
double f = (double)flow->first_seen/1000.0, l = (double)flow->last_seen/1000.0;
int n_metrics = 6;
ndpi_norm_value* scores = malloc(n_metrics * sizeof(ndpi_norm_value));
/* duration */
int i = 0;
scores[i].lower_bound = 0.0;
scores[i].upper_bound = 539.40668006422;
scores[i].weight = 0.16666666666666666;
scores[i].value = (l - f);
/* src2dst_packets */
i++;
scores[i].lower_bound = 2.0;
scores[i].upper_bound = 41.0;
scores[i].weight = 0.16666666666666666;
scores[i].value = flow->src2dst_packets;
/* dst2src_packets */
i++;
scores[i].lower_bound = 2.0;
scores[i].upper_bound = 45.0;
scores[i].weight = 0.16666666666666666;
scores[i].value = flow->dst2src_packets;
/* src2dst_bytes */
i++;
scores[i].lower_bound = 146.0;
scores[i].upper_bound = 6306.300000000001;
scores[i].weight = 0.16666666666666666;
scores[i].value = flow->src2dst_bytes;
/* ack */
i++;
scores[i].lower_bound = 0.0;
scores[i].upper_bound = 82.0;
scores[i].weight = 0.16666666666666666;
scores[i].value = flow->ack_count;
/* syn */
i++;
scores[i].lower_bound = 0.0;
scores[i].upper_bound = 2.0;
scores[i].weight = 0.16666666666666666;
scores[i].value = flow->syn_count;
// sum = 0.9999999999999999
double flow_score = get_flow_score(scores, n_metrics);
free(scores);
return flow_score;
}
double Dos_slow_score(struct ndpi_flow_info* flow){
double f = (double)flow->first_seen/1000.0, l = (double)flow->last_seen/1000.0;
int n_metrics = 6;
ndpi_norm_value* scores = malloc(n_metrics * sizeof(ndpi_norm_value));
/* pktlen_s_to_c_max */
int i = 0;
scores[i].lower_bound = 90.0;
scores[i].upper_bound = 3135.0;
scores[i].weight = 0.1760747755022144;
scores[i].value = ndpi_data_max(flow->pktlen_s_to_c);
/* pktlen_s_to_c_avg */
i++;
scores[i].lower_bound = 80.37100000000001;
scores[i].upper_bound = 1292.5900000000008;
scores[i].weight = 0.17600137023171597;
scores[i].value = ndpi_data_average(flow->pktlen_s_to_c);
/* dst2src_bytes */
i++;
scores[i].lower_bound = 262.0;
scores[i].upper_bound = 53227.80000000002;
scores[i].weight = 0.16919914849886225;
scores[i].value = flow->dst2src_bytes;
/* syn */
i++;
scores[i].lower_bound = 0.0;
scores[i].upper_bound = 2.0;
scores[i].weight = 0.168000195747388;
scores[i].value = flow->syn_count;
/* c_to_s_syn */
i++;
scores[i].lower_bound = 0.0;
scores[i].upper_bound = 1.0;
scores[i].weight = 0.14272431427243143;
scores[i].value = flow->src2dst_syn_count;
/* s_to_c_syn */
i++;
scores[i].lower_bound = 0.0;
scores[i].upper_bound = 2.0;
scores[i].weight = 0.168000195747388;
scores[i].value = flow->dst2src_syn_count;
// sum = 1.0
double flow_score = get_flow_score(scores, n_metrics);
free(scores);
return flow_score;
}
double Ftp_patator_score(struct ndpi_flow_info* flow){
double f = (double)flow->first_seen/1000.0, l = (double)flow->last_seen/1000.0;
int n_metrics = 6;
ndpi_norm_value* scores = malloc(n_metrics * sizeof(ndpi_norm_value));
/* iat_flow_min */
int i = 0;
scores[i].lower_bound = 0.0;
scores[i].upper_bound = 24.0;
scores[i].weight = 0.002732919254658385;
scores[i].value = ndpi_data_min(flow->iat_flow);
/* pktlen_s_to_c_max */
i++;
scores[i].lower_bound = 90.0;
scores[i].upper_bound = 3393.0;
scores[i].weight = 0.007453416149068323;
scores[i].value = ndpi_data_max(flow->pktlen_s_to_c);
/* pktlen_s_to_c_avg */
i++;
scores[i].lower_bound = 81.3;
scores[i].upper_bound = 1315.021;
scores[i].weight = 0.9833540372670807;
scores[i].value = ndpi_data_average(flow->pktlen_s_to_c);
/* dst2src_bytes */
i++;
scores[i].lower_bound = 256.0;
scores[i].upper_bound = 56434.0;
scores[i].weight = 0.0034782608695652175;
scores[i].value = flow->dst2src_bytes;
/* fin */
i++;
scores[i].lower_bound = 0.0;
scores[i].upper_bound = 2.0;
scores[i].weight = 0.0014906832298136647;
scores[i].value = flow->fin_count;
/* rst */
i++;
scores[i].lower_bound = 0.0;
scores[i].upper_bound = 2.0;
scores[i].weight = 0.0014906832298136647;
scores[i].value = flow->rst_count;
// sum = 1.0
double flow_score = get_flow_score(scores, n_metrics);
free(scores);
return flow_score;
}
double Hearthbleed_score(struct ndpi_flow_info* flow){
double f = (double)flow->first_seen/1000.0, l = (double)flow->last_seen/1000.0;
int n_metrics = 6;
ndpi_norm_value* scores = malloc(n_metrics * sizeof(ndpi_norm_value));
/* iat_flow_max */
int i = 0;
scores[i].lower_bound = 0.0;
scores[i].upper_bound = 595213.3999999999;
scores[i].weight = 0.16666666666666666;
scores[i].value = ndpi_data_max(flow->iat_flow);
/* iat_flow_stddev */
i++;
scores[i].lower_bound = 0.0;
scores[i].upper_bound = 245377.74799999973;
scores[i].weight = 0.16666666666666666;
scores[i].value = ndpi_data_stddev(flow->iat_flow);
/* pktlen_s_to_c_max */
i++;
scores[i].lower_bound = 74.0;
scores[i].upper_bound = 3380.0;
scores[i].weight = 0.16666666666666666;
scores[i].value = ndpi_data_max(flow->pktlen_s_to_c);
/* pktlen_s_to_c_avg */
i++;
scores[i].lower_bound = 70.0;
scores[i].upper_bound = 1344.6399999999996;
scores[i].weight = 0.16666666666666666;
scores[i].value = ndpi_data_average(flow->pktlen_s_to_c);
/* pktlen_s_to_c_stddev */
i++;
scores[i].lower_bound = 0.0;
scores[i].upper_bound = 944.6399999999996;
scores[i].weight = 0.16666666666666666;
scores[i].value = ndpi_data_stddev(flow->pktlen_s_to_c);
/* duration */
i++;
scores[i].lower_bound = 0.0;
scores[i].upper_bound = 711.6677598000391;
scores[i].weight = 0.16666666666666666;
scores[i].value = (l - f);
// sum = 0.9999999999999999
double flow_score = get_flow_score(scores, n_metrics);
free(scores);
return flow_score;
}
double Infiltration_score(struct ndpi_flow_info* flow){
double f = (double)flow->first_seen/1000.0, l = (double)flow->last_seen/1000.0;
int n_metrics = 6;
ndpi_norm_value* scores = malloc(n_metrics * sizeof(ndpi_norm_value));
/* pktlen_c_to_s_max */
int i = 0;
scores[i].lower_bound = 72.0;
scores[i].upper_bound = 1840.739999999998;
scores[i].weight = 0.11937557392102846;
scores[i].value = ndpi_data_max(flow->pktlen_c_to_s);
/* pktlen_c_to_s_avg */
i++;
scores[i].lower_bound = 70.0;
scores[i].upper_bound = 296.56599999999816;
scores[i].weight = 0.12526782981328435;
scores[i].value = ndpi_data_average(flow->pktlen_c_to_s);
/* pktlen_s_to_c_max */
i++;
scores[i].lower_bound = 90.0;
scores[i].upper_bound = 3496.1399999999776;
scores[i].weight = 0.13927150290786652;
scores[i].value = ndpi_data_max(flow->pktlen_s_to_c);
/* pktlen_s_to_c_avg */
i++;
scores[i].lower_bound = 72.6;
scores[i].upper_bound = 1367.7959999999991;
scores[i].weight = 0.12182430364248545;
scores[i].value = ndpi_data_average(flow->pktlen_s_to_c);
/* src2dst_bytes */
i++;
scores[i].lower_bound = 144.0;
scores[i].upper_bound = 7847.69999999999;
scores[i].weight = 0.12059993878175697;
scores[i].value = flow->src2dst_bytes;
/* dst2src_bytes */
i++;
scores[i].lower_bound = 236.0;
scores[i].upper_bound = 74486.7799999998;
scores[i].weight = 0.3736608509335782;
scores[i].value = flow->dst2src_bytes;
// sum = 1.0
double flow_score = get_flow_score(scores, n_metrics);
free(scores);
return flow_score;
}
double Ssh_patator_score(struct ndpi_flow_info* flow){
double f = (double)flow->first_seen/1000.0, l = (double)flow->last_seen/1000.0;
int n_metrics = 6;
ndpi_norm_value* scores = malloc(n_metrics * sizeof(ndpi_norm_value));
/* fin */
int i = 0;
scores[i].lower_bound = 0.0;
scores[i].upper_bound = 2.0;
scores[i].weight = 0.0033738191632928477;
scores[i].value = flow->fin_count;
/* psh */
i++;
scores[i].lower_bound = 0.0;
scores[i].upper_bound = 30.0;
scores[i].weight = 0.33076923076923076;
scores[i].value = flow->psh_count;
/* c_to_s_syn */
i++;
scores[i].lower_bound = 0.0;
scores[i].upper_bound = 1.0;
scores[i].weight = 0.0004048582995951417;
scores[i].value = flow->src2dst_syn_count;
/* c_to_s_psh */
i++;
scores[i].lower_bound = 0.0;
scores[i].upper_bound = 12.0;
scores[i].weight = 0.33130904183535764;
scores[i].value = flow->src2dst_psh_count;
/* s_to_c_fin */
i++;
scores[i].lower_bound = 0.0;
scores[i].upper_bound = 2.0;
scores[i].weight = 0.0033738191632928477;
scores[i].value = flow->dst2src_fin_count;
/* s_to_c_psh */
i++;
scores[i].lower_bound = 0.0;
scores[i].upper_bound = 30.0;
scores[i].weight = 0.33076923076923076;
scores[i].value = flow->dst2src_psh_count;
// sum = 1.0
double flow_score = get_flow_score(scores, n_metrics);
free(scores);
return flow_score;
}
+69
View File
@@ -0,0 +1,69 @@
/*
* intrusion_detection.h
*
* Copyright (C) 2011-19 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
*
* nDPI is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* nDPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with nDPI. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef _INTRUSION_DETECTION_H_
#define _INTRUSION_DETECTION_H_
/*
Code to detect attacks reported in
https://www.unb.ca/cic/datasets/ids-2017.html
https://www.unb.ca/cic/datasets/ids-2018.html
*/
#include <stdio.h>
#include <stdlib.h>
#include "reader_util.h"
#include "ndpi_api.h"
typedef struct norm_values{
double upper_bound;
double lower_bound;
double weight;
double value;
double norm_value;
}ndpi_norm_value;
double normalize(ndpi_norm_value* tresholds);
double get_flow_score(ndpi_norm_value* scores, int n_metrics);
/* ********************************** */
double Ddos_score(struct ndpi_flow_info* flow);
double Dos_goldeneye_score(struct ndpi_flow_info* flow);
double Dos_hulk_score(struct ndpi_flow_info* flow);
double Dos_slow_score(struct ndpi_flow_info* flow);
double Ftp_patator_score(struct ndpi_flow_info* flow);
double Hearthbleed_score(struct ndpi_flow_info* flow);
double Infiltration_score(struct ndpi_flow_info* flow);
double Ssh_patator_score(struct ndpi_flow_info* flow);
#endif /* _INTRUSION_DETECTION_H_ */
+136
View File
@@ -0,0 +1,136 @@
#!/usr/bin/env python
#
# Copyright (C) 2019 - ntop.org
#
# nDPI is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# nDPI is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with nDPI. If not, see <http://www.gnu.org/licenses/>.
#
#
# Usage
#
# 1) Generate a CSV file using the ndpiReader tool. Example:
# ./ndpiReader -C sample.json -i sample.pcap
#
# 2) Open Google Chrome and type in the URL 'chrome://tracing/'
#
# 3) Inside Chrome click on 'Load' or drop sample.json in the
# Chrome window to visualize the output
#
import sys
import json
protos = {}
lastId = 1
def get_timestamp(seen):
tok = seen.split(".")
return int(tok[0]) * 1000 + int(tok[1])
def get_record(toks, csv_fields):
global protos
global lastId
if len(toks) < 11:
return None
record = dict()
ndpiProtocol = toks[10]
ndpi_protos = ndpiProtocol.split(".")
if(len(ndpi_protos) == 1):
app_proto = ndpi_protos[0]
else:
app_proto = ndpi_protos[1]
id = protos.get(ndpiProtocol)
if(id == None):
lastId = lastId + 1
protos[ndpiProtocol] = lastId
id = lastId
#print(ndpiProtocol+"="+str(id))
ip_address = toks[5]
server_name = toks[11]
record["cat"] = "flow"
record["pid"] = ip_address
record["tid"] = ndpiProtocol # id
record["ts"] = get_timestamp(toks[2])
record["ph"] = "X"
record["name"] = app_proto
if(server_name == ""):
args = {}
else:
args = { "name": server_name }
record["args"] = args
record["dur"] = get_timestamp(toks[3]) - record["ts"]
# if we do not have the legend we just return
if csv_fields is None:
return record
# Otherwise we just add everything we find as a string
if(0):
idx = 0
for tok in toks:
name = csv_fields[idx]
idx += 1
record["args"][name] = str(tok)
return record
def get_record_dict(filename):
csv_fields = None
records = []
fin = open(filename, "r");
for line in fin:
line = line.replace("\n","")
# Get the legend if present
if line[0] == '#':
csv_fields = []
line = line.replace("#", "")
toks = line.split(",")
for tok in toks:
csv_fields.append(tok)
continue
toks = line.split(",")
flow_id = int(toks[0])
record = get_record(toks, csv_fields)
if record is None:
print("Error while parsing " + line)
continue
records.append(record)
json_dict = dict()
json_dict["traceEvents"] = records
return json_dict
if __name__ == "__main__":
if len(sys.argv) != 3:
print("ndpi2json <csv_file> <json_file>")
sys.exit(0)
record_dict = get_record_dict(sys.argv[1])
#print(record_dict)
#json_string = json.dumps(json_dict)
#print(json_string)
with open(sys.argv[2], 'w') as fp:
json.dump(record_dict, fp)
print("Written " + str(len(record_dict["traceEvents"])) + " records")
+411 -1343
View File
File diff suppressed because it is too large Load Diff
+348 -127
View File
@@ -69,7 +69,8 @@
/* mask for Bad FCF presence */
#define BAD_FCS 0x50 /* 0101 0000 */
#define GTP_U_V1_PORT 2152
#define GTP_U_V1_PORT 2152
#define NDPI_CAPWAP_DATA_PORT 5247
#define TZSP_PORT 37008
#ifndef DLT_LINUX_SLL
@@ -123,7 +124,6 @@ void ndpi_analyze_payload(struct ndpi_flow_info *flow,
u_int16_t payload_len,
u_int32_t packet_id) {
struct payload_stats *ret;
u_int i;
struct flow_id_stats *f;
struct packet_id_stats *p;
@@ -185,7 +185,7 @@ void ndpi_payload_analyzer(struct ndpi_flow_info *flow,
u_int16_t i, j;
u_int16_t scan_len = ndpi_min(max_packet_payload_dissection, payload_len);
if((flow->entropy.src2dst_pkt_count+flow->entropy.dst2src_pkt_count) <= max_num_packets_per_flow) {
if((flow->src2dst_packets+flow->dst2src_packets) <= max_num_packets_per_flow) {
#ifdef DEBUG_PAYLOAD
printf("[hashval: %u][proto: %u][vlan: %u][%s:%u <-> %s:%u][direction: %s][payload_len: %u]\n",
flow->hashval, flow->protocol, flow->vlan_id,
@@ -306,8 +306,6 @@ void ndpi_report_payload_stats() {
}
}
/* ***************************************************** */
void ndpi_free_flow_info_half(struct ndpi_flow_info *flow) {
@@ -413,7 +411,7 @@ struct ndpi_workflow* ndpi_workflow_init(const struct ndpi_workflow_prefs * pref
set_ndpi_flow_malloc(NULL), set_ndpi_flow_free(NULL);
/* TODO: just needed here to init ndpi malloc wrapper */
module = ndpi_init_detection_module();
module = ndpi_init_detection_module(ndpi_no_prefs);
if(module == NULL) {
NDPI_LOG(0, NULL, NDPI_LOG_ERROR, "global structure initialization failed\n");
@@ -457,7 +455,29 @@ void ndpi_flow_info_freer(void *node) {
struct ndpi_flow_info *flow = (struct ndpi_flow_info*)node;
ndpi_free_flow_info_half(flow);
ndpi_free_flow_data_analysis(flow);
if(flow->ssh_tls.server_names) {
ndpi_free(flow->ssh_tls.server_names);
flow->ssh_tls.server_names = NULL;
}
if(flow->ssh_tls.tls_alpn) {
ndpi_free(flow->ssh_tls.tls_alpn);
flow->ssh_tls.tls_alpn = NULL;
}
if(flow->ssh_tls.tls_supported_versions) {
ndpi_free(flow->ssh_tls.tls_supported_versions);
flow->ssh_tls.tls_supported_versions = NULL;
}
ndpi_free(flow);
}
/* ***************************************************** */
void ndpi_free_flow_data_analysis(struct ndpi_flow_info *flow) {
if(flow->iat_c_to_s) ndpi_free_data_analysis(flow->iat_c_to_s);
if(flow->iat_s_to_c) ndpi_free_data_analysis(flow->iat_s_to_c);
@@ -465,8 +485,6 @@ void ndpi_flow_info_freer(void *node) {
if(flow->pktlen_s_to_c) ndpi_free_data_analysis(flow->pktlen_s_to_c);
if(flow->iat_flow) ndpi_free_data_analysis(flow->iat_flow);
ndpi_free(flow);
}
/* ***************************************************** */
@@ -532,10 +550,6 @@ int ndpi_workflow_node_cmp(const void *a, const void *b) {
static void
ndpi_flow_update_byte_count(struct ndpi_flow_info *flow, const void *x,
unsigned int len, u_int8_t src_to_dst_direction) {
const unsigned char *data = x;
u_int32_t i;
u_int32_t current_count = 0;
/*
* implementation note: The spec says that 4000 octets is enough of a
* sample size to accurately reflect the byte distribution. Also, to avoid
@@ -545,6 +559,8 @@ ndpi_flow_update_byte_count(struct ndpi_flow_info *flow, const void *x,
if((flow->entropy.src2dst_pkt_count+flow->entropy.dst2src_pkt_count) <= max_num_packets_per_flow) {
/* octet count was already incremented before processing this payload */
u_int32_t current_count;
if(src_to_dst_direction) {
current_count = flow->entropy.src2dst_l4_bytes - len;
} else {
@@ -552,6 +568,9 @@ ndpi_flow_update_byte_count(struct ndpi_flow_info *flow, const void *x,
}
if(current_count < ETTA_MIN_OCTETS) {
u_int32_t i;
const unsigned char *data = x;
for(i=0; i<len; i++) {
if(src_to_dst_direction) {
flow->entropy.src2dst_byte_count[data[i]]++;
@@ -580,11 +599,13 @@ static void
ndpi_flow_update_byte_dist_mean_var(ndpi_flow_info_t *flow, const void *x,
unsigned int len, u_int8_t src_to_dst_direction) {
const unsigned char *data = x;
double delta;
unsigned int i;
if((flow->entropy.src2dst_pkt_count+flow->entropy.dst2src_pkt_count) <= max_num_packets_per_flow) {
unsigned int i;
for(i=0; i<len; i++) {
double delta;
if(src_to_dst_direction) {
flow->entropy.src2dst_num_bytes += 1;
delta = ((double)data[i] - flow->entropy.src2dst_bd_mean);
@@ -606,33 +627,16 @@ float ndpi_flow_get_byte_count_entropy(const uint32_t byte_count[256],
unsigned int num_bytes)
{
int i;
float tmp, sum = 0.0;
float sum = 0.0;
for(i=0; i<256; i++) {
tmp = (float) byte_count[i] / (float) num_bytes;
float tmp = (float) byte_count[i] / (float) num_bytes;
if(tmp > FLT_EPSILON) {
sum -= tmp * logf(tmp);
}
}
return sum / logf(2.0);
}
/* ***************************************************** */
static void patchIPv6Address(char *str) {
int i = 0, j = 0;
while(str[i] != '\0') {
if((str[i] == ':')
&& (str[i+1] == '0')
&& (str[i+2] == ':')) {
str[j++] = ':';
str[j++] = ':';
i += 3;
} else
str[j++] = str[i++];
}
if(str[j] != '\0') str[j] = '\0';
return(sum / logf(2.0));
}
/* ***************************************************** */
@@ -640,6 +644,7 @@ static void patchIPv6Address(char *str) {
static struct ndpi_flow_info *get_ndpi_flow_info(struct ndpi_workflow * workflow,
const u_int8_t version,
u_int16_t vlan_id,
ndpi_packet_tunnel tunnel_type,
const struct ndpi_iphdr *iph,
const struct ndpi_ipv6hdr *iph6,
u_int16_t ip_offset,
@@ -677,8 +682,13 @@ static struct ndpi_flow_info *get_ndpi_flow_info(struct ndpi_workflow * workflow
l3 = (const u_int8_t*)iph;
} else {
l4_offset = sizeof(struct ndpi_ipv6hdr);
if(sizeof(struct ndpi_ipv6hdr) > ipsize)
return NULL;
l3 = (const u_int8_t*)iph6;
}
if (ipsize < l4_offset + l4_packet_len)
return NULL;
*proto = iph->protocol;
@@ -694,16 +704,16 @@ static struct ndpi_flow_info *get_ndpi_flow_info(struct ndpi_workflow * workflow
workflow->stats.packet_len[4]++;
else if(l4_packet_len >= 1500)
workflow->stats.packet_len[5]++;
if(l4_packet_len > workflow->stats.max_packet_len)
workflow->stats.max_packet_len = l4_packet_len;
l4 = ((const u_int8_t *) l3 + l4_offset);
l4 =& ((const u_int8_t *) l3)[l4_offset];
if(*proto == IPPROTO_TCP && l4_packet_len >= sizeof(struct ndpi_tcphdr)) {
u_int tcp_len;
// tcp
// TCP
workflow->stats.tcp_count++;
*tcph = (struct ndpi_tcphdr *)l4;
*sport = ntohs((*tcph)->source), *dport = ntohs((*tcph)->dest);
@@ -712,8 +722,7 @@ static struct ndpi_flow_info *get_ndpi_flow_info(struct ndpi_workflow * workflow
*payload_len = ndpi_max(0, l4_packet_len-4*(*tcph)->doff);
l4_data_len = l4_packet_len - sizeof(struct ndpi_tcphdr);
} else if(*proto == IPPROTO_UDP && l4_packet_len >= sizeof(struct ndpi_udphdr)) {
// udp
// UDP
workflow->stats.udp_count++;
*udph = (struct ndpi_udphdr *)l4;
*sport = ntohs((*udph)->source), *dport = ntohs((*udph)->dest);
@@ -785,6 +794,7 @@ static struct ndpi_flow_info *get_ndpi_flow_info(struct ndpi_workflow * workflow
memset(newflow, 0, sizeof(struct ndpi_flow_info));
newflow->flow_id = flow_id++;
newflow->hashval = hashval;
newflow->tunnel_type = tunnel_type;
newflow->protocol = iph->protocol, newflow->vlan_id = vlan_id;
newflow->src_ip = iph->saddr, newflow->dst_ip = iph->daddr;
newflow->src_port = htons(*sport), newflow->dst_port = htons(*dport);
@@ -793,7 +803,7 @@ static struct ndpi_flow_info *get_ndpi_flow_info(struct ndpi_workflow * workflow
newflow->iat_s_to_c = ndpi_alloc_data_analysis(DATA_ANALUYSIS_SLIDING_WINDOW);
newflow->pktlen_c_to_s = ndpi_alloc_data_analysis(DATA_ANALUYSIS_SLIDING_WINDOW),
newflow->pktlen_s_to_c = ndpi_alloc_data_analysis(DATA_ANALUYSIS_SLIDING_WINDOW),
newflow->iat_flow = ndpi_alloc_data_analysis(DATA_ANALUYSIS_SLIDING_WINDOW);;
newflow->iat_flow = ndpi_alloc_data_analysis(DATA_ANALUYSIS_SLIDING_WINDOW);
if(version == IPVERSION) {
inet_ntop(AF_INET, &newflow->src_ip, newflow->src_name, sizeof(newflow->src_name));
@@ -802,7 +812,7 @@ static struct ndpi_flow_info *get_ndpi_flow_info(struct ndpi_workflow * workflow
inet_ntop(AF_INET6, &iph6->ip6_src, newflow->src_name, sizeof(newflow->src_name));
inet_ntop(AF_INET6, &iph6->ip6_dst, newflow->dst_name, sizeof(newflow->dst_name));
/* For consistency across platforms replace :0: with :: */
patchIPv6Address(newflow->src_name), patchIPv6Address(newflow->dst_name);
ndpi_patchIPv6Address(newflow->src_name), ndpi_patchIPv6Address(newflow->dst_name);
}
if((newflow->ndpi_flow = ndpi_flow_malloc(SIZEOF_FLOW_STRUCT)) == NULL) {
@@ -892,7 +902,7 @@ static struct ndpi_flow_info *get_ndpi_flow_info(struct ndpi_workflow * workflow
rflow->entropy.dst2src_opackets++;
}
}
return(rflow);
}
}
@@ -901,8 +911,10 @@ static struct ndpi_flow_info *get_ndpi_flow_info(struct ndpi_workflow * workflow
static struct ndpi_flow_info *get_ndpi_flow_info6(struct ndpi_workflow * workflow,
u_int16_t vlan_id,
ndpi_packet_tunnel tunnel_type,
const struct ndpi_ipv6hdr *iph6,
u_int16_t ip_offset,
u_int16_t ipsize,
struct ndpi_tcphdr **tcph,
struct ndpi_udphdr **udph,
u_int16_t *sport, u_int16_t *dport,
@@ -927,8 +939,8 @@ static struct ndpi_flow_info *get_ndpi_flow_info6(struct ndpi_workflow * workflo
iph.protocol = options[0];
}
return(get_ndpi_flow_info(workflow, 6, vlan_id, &iph, iph6, ip_offset,
sizeof(struct ndpi_ipv6hdr),
return(get_ndpi_flow_info(workflow, 6, vlan_id, tunnel_type,
&iph, iph6, ip_offset, ipsize,
ntohs(iph6->ip6_hdr.ip6_un1_plen),
tcph, udph, sport, dport,
src, dst, proto, payload,
@@ -937,17 +949,31 @@ static struct ndpi_flow_info *get_ndpi_flow_info6(struct ndpi_workflow * workflo
/* ****************************************************** */
static u_int8_t is_ndpi_proto(struct ndpi_flow_info *flow, u_int16_t id) {
if((flow->detected_protocol.master_protocol == id)
|| (flow->detected_protocol.app_protocol == id))
return(1);
else
return(0);
}
/* ****************************************************** */
void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_flow_info *flow) {
u_int i;
if(!flow->ndpi_flow) return;
snprintf(flow->host_server_name, sizeof(flow->host_server_name), "%s",
flow->ndpi_flow->host_server_name);
if(flow->detected_protocol.app_protocol == NDPI_PROTOCOL_DHCP) {
snprintf(flow->flow_extra_info, sizeof(flow->flow_extra_info), "%s",
flow->ndpi_flow->flow_extra_info);
if(is_ndpi_proto(flow, NDPI_PROTOCOL_DHCP)) {
snprintf(flow->dhcp_fingerprint, sizeof(flow->dhcp_fingerprint), "%s", flow->ndpi_flow->protos.dhcp.fingerprint);
} else if(flow->detected_protocol.app_protocol == NDPI_PROTOCOL_BITTORRENT) {
u_int i, j, n = 0;
} else if(is_ndpi_proto(flow, NDPI_PROTOCOL_BITTORRENT)) {
u_int j, n = 0;
for(i=0, j = 0; j < sizeof(flow->bittorent_hash)-1; i++) {
sprintf(&flow->bittorent_hash[j], "%02x",
@@ -958,60 +984,136 @@ void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_fl
if(n == 0) flow->bittorent_hash[0] = '\0';
}
/* DNS */
else if(is_ndpi_proto(flow, NDPI_PROTOCOL_DNS)) {
if(flow->ndpi_flow->protos.dns.rsp_type == 0x1)
inet_ntop(AF_INET, &flow->ndpi_flow->protos.dns.rsp_addr.ipv4, flow->info, sizeof(flow->info));
else {
inet_ntop(AF_INET6, &flow->ndpi_flow->protos.dns.rsp_addr.ipv6, flow->info, sizeof(flow->info));
/* For consistency across platforms replace :0: with :: */
ndpi_patchIPv6Address(flow->info);
}
}
/* MDNS */
else if(flow->detected_protocol.app_protocol == NDPI_PROTOCOL_MDNS) {
else if(is_ndpi_proto(flow, NDPI_PROTOCOL_MDNS)) {
snprintf(flow->info, sizeof(flow->info), "%s", flow->ndpi_flow->protos.mdns.answer);
}
/* UBNTAC2 */
else if(flow->detected_protocol.app_protocol == NDPI_PROTOCOL_UBNTAC2) {
else if(is_ndpi_proto(flow, NDPI_PROTOCOL_UBNTAC2)) {
snprintf(flow->info, sizeof(flow->info), "%s", flow->ndpi_flow->protos.ubntac2.version);
}
/* FTP */
else if((is_ndpi_proto(flow, NDPI_PROTOCOL_FTP_CONTROL))
|| /* IMAP */ is_ndpi_proto(flow, NDPI_PROTOCOL_MAIL_IMAP)
|| /* POP */ is_ndpi_proto(flow, NDPI_PROTOCOL_MAIL_POP)
|| /* SMTP */ is_ndpi_proto(flow, NDPI_PROTOCOL_MAIL_SMTP)) {
if(flow->ndpi_flow->protos.ftp_imap_pop_smtp.username[0] != '\0')
snprintf(flow->info, sizeof(flow->info), "User: %s][Pwd: %s%s",
flow->ndpi_flow->protos.ftp_imap_pop_smtp.username,
flow->ndpi_flow->protos.ftp_imap_pop_smtp.password,
flow->ndpi_flow->protos.ftp_imap_pop_smtp.auth_failed ? "][Auth Failed" : "");
}
/* KERBEROS */
else if(is_ndpi_proto(flow, NDPI_PROTOCOL_KERBEROS)) {
if((flow->ndpi_flow->protos.kerberos.hostname[0] != '\0')
|| (flow->ndpi_flow->protos.kerberos.username[0] != '\0')) {
snprintf(flow->info, sizeof(flow->info), "%s%s%s%s",
flow->ndpi_flow->protos.kerberos.domain /* = realm */,
flow->ndpi_flow->protos.kerberos.domain[0] != '\0' ? "\\" : "",
flow->ndpi_flow->protos.kerberos.hostname,
flow->ndpi_flow->protos.kerberos.username);
} else if(flow->ndpi_flow->protos.kerberos.domain[0] != '\0')
snprintf(flow->info, sizeof(flow->info), "%s",
flow->ndpi_flow->protos.kerberos.domain);
#if 0
if(flow->info[0] != '\0')
printf("->> (%d) [%s][%s][%s]<<--\n",
htons(flow->src_port),
flow->ndpi_flow->protos.kerberos.domain,
flow->ndpi_flow->protos.kerberos.hostname,
flow->ndpi_flow->protos.kerberos.username);
#endif
}
/* HTTP */
else if(flow->detected_protocol.master_protocol == NDPI_PROTOCOL_HTTP) {
else if((flow->detected_protocol.master_protocol == NDPI_PROTOCOL_HTTP)
|| is_ndpi_proto(flow, NDPI_PROTOCOL_HTTP)) {
if(flow->ndpi_flow->http.url != NULL) {
snprintf(flow->http.url, sizeof(flow->http.url), "%s", flow->ndpi_flow->http.url);
flow->http.response_status_code = flow->ndpi_flow->http.response_status_code;
snprintf(flow->http.content_type, sizeof(flow->http.content_type), "%s", flow->ndpi_flow->http.content_type ? flow->ndpi_flow->http.content_type : "");
snprintf(flow->http.user_agent, sizeof(flow->http.user_agent), "%s", flow->ndpi_flow->http.user_agent ? flow->ndpi_flow->http.user_agent : "");
}
} else if(is_ndpi_proto(flow, NDPI_PROTOCOL_TELNET)) {
snprintf(flow->telnet.username, sizeof(flow->telnet.username), "%s", flow->ndpi_flow->protos.telnet.username);
snprintf(flow->telnet.password, sizeof(flow->telnet.password), "%s", flow->ndpi_flow->protos.telnet.password);
} else if(is_ndpi_proto(flow, NDPI_PROTOCOL_SSH)) {
snprintf(flow->ssh_tls.client_requested_server_name,
sizeof(flow->ssh_tls.client_requested_server_name), "%s",
flow->ndpi_flow->protos.ssh.client_signature);
snprintf(flow->ssh_tls.server_info, sizeof(flow->ssh_tls.server_info), "%s",
flow->ndpi_flow->protos.ssh.server_signature);
snprintf(flow->ssh_tls.client_hassh, sizeof(flow->ssh_tls.client_hassh), "%s",
flow->ndpi_flow->protos.ssh.hassh_client);
snprintf(flow->ssh_tls.server_hassh, sizeof(flow->ssh_tls.server_hassh), "%s",
flow->ndpi_flow->protos.ssh.hassh_server);
}
else if(flow->detected_protocol.app_protocol != NDPI_PROTOCOL_DNS) {
/* SSH */
if(flow->detected_protocol.app_protocol == NDPI_PROTOCOL_SSH) {
snprintf(flow->ssh_tls.client_info, sizeof(flow->ssh_tls.client_info), "%s",
flow->ndpi_flow->protos.ssh.client_signature);
snprintf(flow->ssh_tls.server_info, sizeof(flow->ssh_tls.server_info), "%s",
flow->ndpi_flow->protos.ssh.server_signature);
snprintf(flow->ssh_tls.client_hassh, sizeof(flow->ssh_tls.client_hassh), "%s",
flow->ndpi_flow->protos.ssh.hassh_client);
snprintf(flow->ssh_tls.server_hassh, sizeof(flow->ssh_tls.server_hassh), "%s",
flow->ndpi_flow->protos.ssh.hassh_server);
}
/* TLS */
else if((flow->detected_protocol.app_protocol == NDPI_PROTOCOL_TLS)
|| (flow->detected_protocol.master_protocol == NDPI_PROTOCOL_TLS)
|| (flow->ndpi_flow->protos.stun_ssl.ssl.ja3_client[0] != '\0')
) {
flow->ssh_tls.ssl_version = flow->ndpi_flow->protos.stun_ssl.ssl.ssl_version;
snprintf(flow->ssh_tls.client_info, sizeof(flow->ssh_tls.client_info), "%s",
flow->ndpi_flow->protos.stun_ssl.ssl.client_certificate);
snprintf(flow->ssh_tls.server_info, sizeof(flow->ssh_tls.server_info), "%s",
flow->ndpi_flow->protos.stun_ssl.ssl.server_certificate);
snprintf(flow->ssh_tls.server_organization, sizeof(flow->ssh_tls.server_organization), "%s",
flow->ndpi_flow->protos.stun_ssl.ssl.server_organization);
flow->ssh_tls.notBefore = flow->ndpi_flow->protos.stun_ssl.ssl.notBefore;
flow->ssh_tls.notAfter = flow->ndpi_flow->protos.stun_ssl.ssl.notAfter;
snprintf(flow->ssh_tls.ja3_client, sizeof(flow->ssh_tls.ja3_client), "%s",
flow->ndpi_flow->protos.stun_ssl.ssl.ja3_client);
snprintf(flow->ssh_tls.ja3_server, sizeof(flow->ssh_tls.ja3_server), "%s",
flow->ndpi_flow->protos.stun_ssl.ssl.ja3_server);
flow->ssh_tls.server_unsafe_cipher = flow->ndpi_flow->protos.stun_ssl.ssl.server_unsafe_cipher;
flow->ssh_tls.server_cipher = flow->ndpi_flow->protos.stun_ssl.ssl.server_cipher;
/* TLS */
else if((is_ndpi_proto(flow, NDPI_PROTOCOL_TLS))
|| (flow->detected_protocol.master_protocol == NDPI_PROTOCOL_TLS)
|| (flow->ndpi_flow->protos.stun_ssl.ssl.ja3_client[0] != '\0')
) {
flow->ssh_tls.ssl_version = flow->ndpi_flow->protos.stun_ssl.ssl.ssl_version;
snprintf(flow->ssh_tls.client_requested_server_name,
sizeof(flow->ssh_tls.client_requested_server_name), "%s",
flow->ndpi_flow->protos.stun_ssl.ssl.client_requested_server_name);
if(flow->ndpi_flow->protos.stun_ssl.ssl.server_names_len > 0)
flow->ssh_tls.server_names = ndpi_strdup(flow->ndpi_flow->protos.stun_ssl.ssl.server_names);
snprintf(flow->ssh_tls.server_organization, sizeof(flow->ssh_tls.server_organization), "%s",
flow->ndpi_flow->protos.stun_ssl.ssl.server_organization);
flow->ssh_tls.notBefore = flow->ndpi_flow->protos.stun_ssl.ssl.notBefore;
flow->ssh_tls.notAfter = flow->ndpi_flow->protos.stun_ssl.ssl.notAfter;
snprintf(flow->ssh_tls.ja3_client, sizeof(flow->ssh_tls.ja3_client), "%s",
flow->ndpi_flow->protos.stun_ssl.ssl.ja3_client);
snprintf(flow->ssh_tls.ja3_server, sizeof(flow->ssh_tls.ja3_server), "%s",
flow->ndpi_flow->protos.stun_ssl.ssl.ja3_server);
flow->ssh_tls.server_unsafe_cipher = flow->ndpi_flow->protos.stun_ssl.ssl.server_unsafe_cipher;
flow->ssh_tls.server_cipher = flow->ndpi_flow->protos.stun_ssl.ssl.server_cipher;
if(flow->ndpi_flow->l4.tcp.tls.fingerprint_set) {
memcpy(flow->ssh_tls.sha1_cert_fingerprint,
flow->ndpi_flow->l4.tcp.tls_sha1_certificate_fingerprint, 20);
flow->ndpi_flow->l4.tcp.tls.sha1_certificate_fingerprint, 20);
flow->ssh_tls.sha1_cert_fingerprint_set = 1;
}
if(flow->ndpi_flow->protos.stun_ssl.ssl.alpn) {
if((flow->ssh_tls.tls_alpn = ndpi_strdup(flow->ndpi_flow->protos.stun_ssl.ssl.alpn)) != NULL) {
/* Replace , with ; to avoid issues with CSVs */
for(i=0; flow->ssh_tls.tls_alpn[i] != '\0'; i++) if(flow->ssh_tls.tls_alpn[i] == ',') flow->ssh_tls.tls_alpn[i] = ';';
}
}
if(flow->ssh_tls.tls_supported_versions) {
if((flow->ssh_tls.tls_supported_versions = ndpi_strdup(flow->ndpi_flow->protos.stun_ssl.ssl.tls_supported_versions)) != NULL) {
/* Replace , with ; to avoid issues with CSVs */
for(i=0; flow->ssh_tls.tls_supported_versions[i] != '\0'; i++) if(flow->ssh_tls.tls_supported_versions[i] == ',') flow->ssh_tls.tls_supported_versions[i] = ';';
}
}
if(flow->ndpi_flow->protos.stun_ssl.ssl.alpn
&& flow->ndpi_flow->protos.stun_ssl.ssl.tls_supported_versions)
snprintf(flow->info, sizeof(flow->info), "ALPN: %s][TLS Supported Versions: %s",
flow->ndpi_flow->protos.stun_ssl.ssl.alpn,
flow->ndpi_flow->protos.stun_ssl.ssl.tls_supported_versions);
else if(flow->ndpi_flow->protos.stun_ssl.ssl.alpn)
snprintf(flow->info, sizeof(flow->info), "ALPN: %s",
flow->ndpi_flow->protos.stun_ssl.ssl.alpn);
}
if(flow->detection_completed && (!flow->check_extra_packets)) {
if(flow->detected_protocol.app_protocol == NDPI_PROTOCOL_UNKNOWN) {
if(is_ndpi_proto(flow, NDPI_PROTOCOL_UNKNOWN)) {
if(workflow->__flow_giveup_callback != NULL)
workflow->__flow_giveup_callback(workflow, flow, workflow->__flow_giveup_udata);
} else {
@@ -1029,14 +1131,48 @@ void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_fl
* @brief Clear entropy stats if it meets prereq.
*/
static void
ndpi_clear_entropy_stats(struct ndpi_flow_info *flow)
{
ndpi_clear_entropy_stats(struct ndpi_flow_info *flow) {
if(flow->entropy.src2dst_pkt_count + flow->entropy.dst2src_pkt_count == max_num_packets_per_flow) {
memcpy(&flow->last_entropy, &flow->entropy, sizeof(struct ndpi_entropy));
memset(&flow->entropy, 0x00, sizeof(struct ndpi_entropy));
}
}
void update_tcp_flags_count(struct ndpi_flow_info* flow, struct ndpi_tcphdr* tcp, u_int8_t src_to_dst_direction){
if(tcp->cwr){
flow->cwr_count++;
src_to_dst_direction ? flow->src2dst_cwr_count++ : flow->dst2src_cwr_count++;
}
if(tcp->ece){
flow->ece_count++;
src_to_dst_direction ? flow->src2dst_ece_count++ : flow->dst2src_ece_count++;
}
if(tcp->rst){
flow->rst_count++;
src_to_dst_direction ? flow->src2dst_rst_count++ : flow->dst2src_rst_count++;
}
if(tcp->ack){
flow->ack_count++;
src_to_dst_direction ? flow->src2dst_ack_count++ : flow->dst2src_ack_count++;
}
if(tcp->fin){
flow->fin_count++;
src_to_dst_direction ? flow->src2dst_fin_count++ : flow->dst2src_fin_count++;
}
if(tcp->syn){
flow->syn_count++;
src_to_dst_direction ? flow->src2dst_syn_count++ : flow->dst2src_syn_count++;
}
if(tcp->psh){
flow->psh_count++;
src_to_dst_direction ? flow->src2dst_psh_count++ : flow->dst2src_psh_count++;
}
if(tcp->urg){
flow->urg_count++;
src_to_dst_direction ? flow->src2dst_urg_count++ : flow->dst2src_urg_count++;
}
}
/* ****************************************************** */
/**
Function to process the packet:
@@ -1048,6 +1184,7 @@ ndpi_clear_entropy_stats(struct ndpi_flow_info *flow)
static struct ndpi_proto packet_processing(struct ndpi_workflow * workflow,
const u_int64_t time,
u_int16_t vlan_id,
ndpi_packet_tunnel tunnel_type,
const struct ndpi_iphdr *iph,
struct ndpi_ipv6hdr *iph6,
u_int16_t ip_offset,
@@ -1061,21 +1198,23 @@ static struct ndpi_proto packet_processing(struct ndpi_workflow * workflow,
u_int8_t proto;
struct ndpi_tcphdr *tcph = NULL;
struct ndpi_udphdr *udph = NULL;
u_int16_t sport, dport, payload_len;
u_int16_t sport, dport, payload_len = 0;
u_int8_t *payload;
u_int8_t src_to_dst_direction = 1;
u_int8_t begin_or_end_tcp = 0;
struct ndpi_proto nproto = { NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_UNKNOWN };
if(iph)
flow = get_ndpi_flow_info(workflow, IPVERSION, vlan_id, iph, NULL,
flow = get_ndpi_flow_info(workflow, IPVERSION, vlan_id,
tunnel_type, iph, NULL,
ip_offset, ipsize,
ntohs(iph->tot_len) - (iph->ihl * 4),
&tcph, &udph, &sport, &dport,
&src, &dst, &proto,
&payload, &payload_len, &src_to_dst_direction, when);
else
flow = get_ndpi_flow_info6(workflow, vlan_id, iph6, ip_offset,
flow = get_ndpi_flow_info6(workflow, vlan_id,
tunnel_type, iph6, ip_offset, ipsize,
&tcph, &udph, &sport, &dport,
&src, &dst, &proto,
&payload, &payload_len, &src_to_dst_direction, when);
@@ -1088,13 +1227,24 @@ static struct ndpi_proto packet_processing(struct ndpi_workflow * workflow,
workflow->stats.total_ip_bytes += rawsize;
ndpi_flow = flow->ndpi_flow;
if(tcph != NULL){
update_tcp_flags_count(flow, tcph, src_to_dst_direction);
if(tcph->syn && !flow->src2dst_bytes){
flow->c_to_s_init_win = rawsize;
}else if(tcph->syn && tcph->ack && flow->src2dst_bytes == flow->c_to_s_init_win){
flow->s_to_c_init_win = rawsize;
}
}
if((tcph != NULL) && (tcph->fin || tcph->rst || tcph->syn))
begin_or_end_tcp = 1;
if(flow->entropy.flow_last_pkt_time.tv_sec) {
ndpi_timer_sub(&when, &flow->entropy.flow_last_pkt_time, &tdiff);
if(flow->iat_flow) {
if(flow->iat_flow
&& (tdiff.tv_sec >= 0) /* Discard backward time */
) {
u_int32_t ms = ndpi_timeval_to_milliseconds(tdiff);
if(ms > 0)
@@ -1107,7 +1257,9 @@ static struct ndpi_proto packet_processing(struct ndpi_workflow * workflow,
if(flow->entropy.src2dst_last_pkt_time.tv_sec) {
ndpi_timer_sub(&when, &flow->entropy.src2dst_last_pkt_time, &tdiff);
if(flow->iat_c_to_s) {
if(flow->iat_c_to_s
&& (tdiff.tv_sec >= 0) /* Discard backward time */
) {
u_int32_t ms = ndpi_timeval_to_milliseconds(tdiff);
ndpi_data_add_value(flow->iat_c_to_s, ms);
@@ -1115,7 +1267,7 @@ static struct ndpi_proto packet_processing(struct ndpi_workflow * workflow,
}
ndpi_data_add_value(flow->pktlen_c_to_s, rawsize);
flow->src2dst_packets++, flow->src2dst_bytes += rawsize;
flow->src2dst_packets++, flow->src2dst_bytes += rawsize, flow->src2dst_goodput_bytes += payload_len;
memcpy(&flow->entropy.src2dst_last_pkt_time, &when, sizeof(when));
} else {
if(flow->entropy.dst2src_last_pkt_time.tv_sec && (!begin_or_end_tcp)) {
@@ -1127,9 +1279,8 @@ static struct ndpi_proto packet_processing(struct ndpi_workflow * workflow,
ndpi_data_add_value(flow->iat_s_to_c, ms);
}
}
ndpi_data_add_value(flow->pktlen_s_to_c, rawsize);
flow->dst2src_packets++, flow->dst2src_bytes += rawsize;
flow->dst2src_packets++, flow->dst2src_bytes += rawsize, flow->dst2src_goodput_bytes += payload_len;
memcpy(&flow->entropy.dst2src_last_pkt_time, &when, sizeof(when));
}
@@ -1146,21 +1297,21 @@ static struct ndpi_proto packet_processing(struct ndpi_workflow * workflow,
if((flow->entropy.src2dst_pkt_count+flow->entropy.dst2src_pkt_count) <= max_num_packets_per_flow) {
if(flow->bidirectional)
flow->entropy.score = ndpi_classify(flow->entropy.src2dst_pkt_len, flow->entropy.src2dst_pkt_time,
flow->entropy.dst2src_pkt_len, flow->entropy.dst2src_pkt_time,
flow->entropy.src2dst_start, flow->entropy.dst2src_start,
max_num_packets_per_flow, flow->src_port, flow->dst_port,
flow->src2dst_packets, flow->dst2src_packets,
flow->entropy.src2dst_opackets, flow->entropy.dst2src_opackets,
flow->entropy.src2dst_l4_bytes, flow->entropy.dst2src_l4_bytes, 1,
flow->entropy.src2dst_byte_count, flow->entropy.dst2src_byte_count);
else
flow->entropy.score = ndpi_classify(flow->entropy.src2dst_pkt_len, flow->entropy.src2dst_pkt_time,
NULL, NULL, flow->entropy.src2dst_start, flow->entropy.src2dst_start,
max_num_packets_per_flow, flow->src_port, flow->dst_port,
flow->src2dst_packets, 0,
flow->entropy.src2dst_opackets, 0,
flow->entropy.src2dst_l4_bytes, 0, 1,
flow->entropy.src2dst_byte_count, NULL);
flow->entropy.dst2src_pkt_len, flow->entropy.dst2src_pkt_time,
flow->entropy.src2dst_start, flow->entropy.dst2src_start,
max_num_packets_per_flow, flow->src_port, flow->dst_port,
flow->src2dst_packets, flow->dst2src_packets,
flow->entropy.src2dst_opackets, flow->entropy.dst2src_opackets,
flow->entropy.src2dst_l4_bytes, flow->entropy.dst2src_l4_bytes, 1,
flow->entropy.src2dst_byte_count, flow->entropy.dst2src_byte_count);
else
flow->entropy.score = ndpi_classify(flow->entropy.src2dst_pkt_len, flow->entropy.src2dst_pkt_time,
NULL, NULL, flow->entropy.src2dst_start, flow->entropy.src2dst_start,
max_num_packets_per_flow, flow->src_port, flow->dst_port,
flow->src2dst_packets, 0,
flow->entropy.src2dst_opackets, 0,
flow->entropy.src2dst_l4_bytes, 0, 1,
flow->entropy.src2dst_byte_count, NULL);
}
}
@@ -1177,9 +1328,9 @@ static struct ndpi_proto packet_processing(struct ndpi_workflow * workflow,
if((proto == IPPROTO_TCP)
&& (
(flow->detected_protocol.app_protocol == NDPI_PROTOCOL_TLS)
is_ndpi_proto(flow, NDPI_PROTOCOL_TLS)
|| (flow->detected_protocol.master_protocol == NDPI_PROTOCOL_TLS)
|| (flow->detected_protocol.app_protocol == NDPI_PROTOCOL_SSH)
|| is_ndpi_proto(flow, NDPI_PROTOCOL_SSH)
|| (flow->detected_protocol.master_protocol == NDPI_PROTOCOL_SSH))
) {
if((flow->src2dst_packets+flow->dst2src_packets) < 10 /* MIN_NUM_ENCRYPT_SKIP_PACKETS */)
@@ -1196,9 +1347,9 @@ static struct ndpi_proto packet_processing(struct ndpi_workflow * workflow,
} else {
if((proto == IPPROTO_TCP)
&& (
(flow->detected_protocol.app_protocol == NDPI_PROTOCOL_TLS)
is_ndpi_proto(flow, NDPI_PROTOCOL_TLS)
|| (flow->detected_protocol.master_protocol == NDPI_PROTOCOL_TLS)
|| (flow->detected_protocol.app_protocol == NDPI_PROTOCOL_SSH)
|| is_ndpi_proto(flow, NDPI_PROTOCOL_SSH)
|| (flow->detected_protocol.master_protocol == NDPI_PROTOCOL_SSH))
)
flow->has_human_readeable_strings = 0;
@@ -1213,26 +1364,34 @@ static struct ndpi_proto packet_processing(struct ndpi_workflow * workflow,
(((proto == IPPROTO_UDP) && ((flow->src2dst_packets + flow->dst2src_packets) > max_num_udp_dissected_pkts))
|| ((proto == IPPROTO_TCP) && ((flow->src2dst_packets + flow->dst2src_packets) > max_num_tcp_dissected_pkts))) ? 1 : 0;
#if 0
printf("%s()\n", __FUNCTION__);
#endif
flow->detected_protocol = ndpi_detection_process_packet(workflow->ndpi_struct, ndpi_flow,
iph ? (uint8_t *)iph : (uint8_t *)iph6,
ipsize, time, src, dst);
if(enough_packets || (flow->detected_protocol.app_protocol != NDPI_PROTOCOL_UNKNOWN)) {
if((!enough_packets)
&& (flow->detected_protocol.master_protocol == NDPI_PROTOCOL_TLS)
&& (!flow->ndpi_flow->l4.tcp.tls_srv_cert_fingerprint_processed))
&& ndpi_extra_dissection_possible(workflow->ndpi_struct, ndpi_flow))
; /* Wait for certificate fingerprint */
else {
/* New protocol detected or give up */
flow->detection_completed = 1;
#if 0
/* Check if we should keep checking extra packets */
if(ndpi_flow && ndpi_flow->check_extra_packets)
flow->check_extra_packets = 1;
#endif
if(flow->detected_protocol.app_protocol == NDPI_PROTOCOL_UNKNOWN) {
u_int8_t proto_guessed;
if(flow->detected_protocol.app_protocol == NDPI_PROTOCOL_UNKNOWN)
flow->detected_protocol = ndpi_detection_giveup(workflow->ndpi_struct, flow->ndpi_flow,
enable_protocol_guess);
enable_protocol_guess, &proto_guessed);
}
process_ndpi_collected_info(workflow, flow);
}
@@ -1275,6 +1434,7 @@ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow,
struct ndpi_ipv6hdr *iph6;
struct ndpi_proto nproto = { NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_UNKNOWN };
ndpi_packet_tunnel tunnel_type = ndpi_no_tunnel;
/* lengths and offsets */
u_int16_t eth_offset = 0;
@@ -1287,7 +1447,7 @@ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow,
u_int64_t time;
u_int16_t ip_offset = 0, ip_len;
u_int16_t frag_off = 0, vlan_id = 0;
u_int8_t proto = 0;
u_int8_t proto = 0, recheck_type;
/*u_int32_t label;*/
/* counters */
@@ -1316,7 +1476,11 @@ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow,
datalink_type = (int)pcap_datalink(workflow->pcap_handle);
#endif
datalink_check:
if(header->caplen < eth_offset + 40)
return(nproto); /* Too short */
switch(datalink_type) {
case DLT_NULL:
if(ntohl(*((u_int32_t*)&packet[eth_offset])) == 2)
@@ -1384,6 +1548,10 @@ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow,
return(nproto);
}
if(header->caplen < (eth_offset + radio_len + sizeof(struct ndpi_wifi_header)))
return(nproto);
/* Calculate 802.11 header length (variable) */
wifi = (struct ndpi_wifi_header*)( packet + eth_offset + radio_len);
fc = wifi->fc;
@@ -1414,6 +1582,9 @@ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow,
return(nproto);
}
ether_type_check:
recheck_type = 0;
/* check ether type */
switch(type) {
case VLAN:
@@ -1421,13 +1592,16 @@ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow,
type = (packet[ip_offset+2] << 8) + packet[ip_offset+3];
ip_offset += 4;
vlan_packet = 1;
// double tagging for 802.1Q
if(type == 0x8100) {
while((type == 0x8100) && (((bpf_u_int32)ip_offset) < header->caplen)) {
vlan_id = ((packet[ip_offset] << 8) + packet[ip_offset+1]) & 0xFFF;
type = (packet[ip_offset+2] << 8) + packet[ip_offset+3];
ip_offset += 4;
}
recheck_type = 1;
break;
case MPLS_UNI:
case MPLS_MULTI:
mpls.u32 = *((uint32_t *) &packet[ip_offset]);
@@ -1440,20 +1614,30 @@ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow,
mpls.u32 = ntohl(mpls.u32);
ip_offset += 4;
}
recheck_type = 1;
break;
case PPPoE:
workflow->stats.pppoe_count++;
type = ETH_P_IP;
ip_offset += 8;
recheck_type = 1;
break;
default:
break;
}
if(recheck_type)
goto ether_type_check;
workflow->stats.vlan_count += vlan_packet;
iph_check:
/* Check and set IP header size and total packet length */
if (header->caplen < ip_offset + sizeof(struct ndpi_iphdr))
return(nproto); /* Too short for next IP header*/
iph = (struct ndpi_iphdr *) &packet[ip_offset];
/* just work on Ethernet packets that contain IP */
@@ -1466,7 +1650,8 @@ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow,
if(cap_warning_used == 0) {
if(!workflow->prefs.quiet_mode)
NDPI_LOG(0, workflow->ndpi_struct, NDPI_LOG_DEBUG, "\n\nWARNING: packet capture size is smaller than packet size, DETECTION MIGHT NOT WORK CORRECTLY\n\n");
NDPI_LOG(0, workflow->ndpi_struct, NDPI_LOG_DEBUG,
"\n\nWARNING: packet capture size is smaller than packet size, DETECTION MIGHT NOT WORK CORRECTLY\n\n");
cap_warning_used = 1;
}
}
@@ -1478,7 +1663,8 @@ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow,
if(iph->protocol == IPPROTO_IPV6) {
ip_offset += ip_len;
goto iph_check;
if (ip_len > 0)
goto iph_check;
}
if((frag_off & 0x1FFF) != 0) {
@@ -1495,6 +1681,8 @@ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow,
return(nproto);
}
} else if(iph->version == 6) {
if (header->caplen < ip_offset + sizeof(struct ndpi_ipv6hdr))
return(nproto); /* Too short for IPv6 header*/
iph6 = (struct ndpi_ipv6hdr *)&packet[ip_offset];
proto = iph6->ip6_hdr.ip6_un1_nxt;
ip_len = sizeof(struct ndpi_ipv6hdr);
@@ -1530,6 +1718,8 @@ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow,
u_int8_t flags = packet[offset];
u_int8_t message_type = packet[offset+1];
tunnel_type = ndpi_gtp_tunnel;
if((((flags & 0xE0) >> 5) == 1 /* GTPv1 */) &&
(message_type == 0xFF /* T-PDU */)) {
@@ -1547,11 +1737,13 @@ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow,
}
} else if((sport == TZSP_PORT) || (dport == TZSP_PORT)) {
/* https://en.wikipedia.org/wiki/TZSP */
u_int offset = ip_offset+ip_len+sizeof(struct ndpi_udphdr);
u_int8_t version = packet[offset];
u_int8_t ts_type = packet[offset+1];
u_int offset = ip_offset+ip_len+sizeof(struct ndpi_udphdr);
u_int8_t version = packet[offset];
u_int8_t ts_type = packet[offset+1];
u_int16_t encapsulates = ntohs(*((u_int16_t*)&packet[offset+2]));
tunnel_type = ndpi_tzsp_tunnel;
if((version == 1) && (ts_type == 0) && (encapsulates == 1)) {
u_int8_t stop = 0;
@@ -1583,11 +1775,33 @@ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow,
}
}
}
} else if(sport == NDPI_CAPWAP_DATA_PORT) {
/* We dissect ONLY CAPWAP traffic */
u_int offset = ip_offset+ip_len+sizeof(struct ndpi_udphdr);
if((offset+40) < header->caplen) {
u_int16_t msg_len = packet[offset+1] >> 1;
offset += msg_len;
if(packet[offset] == 0x02) {
/* IEEE 802.11 Data */
offset += 24;
/* LLC header is 8 bytes */
type = ntohs((u_int16_t)*((u_int16_t*)&packet[offset+6]));
ip_offset = offset + 8;
tunnel_type = ndpi_capwap_tunnel;
goto iph_check;
}
}
}
}
/* process the packet */
return(packet_processing(workflow, time, vlan_id, iph, iph6,
return(packet_processing(workflow, time, vlan_id, tunnel_type, iph, iph6,
ip_offset, header->caplen - ip_offset,
header->caplen, header, packet, header->ts));
}
@@ -1645,8 +1859,15 @@ u_int32_t ethernet_crc32(const void* data, size_t n_bytes) {
#ifdef USE_DPDK
#include <rte_version.h>
#include <rte_ether.h>
static const struct rte_eth_conf port_conf_default = {
#if (RTE_VERSION < RTE_VERSION_NUM(19, 8, 0, 0))
.rxmode = { .max_rx_pkt_len = ETHER_MAX_LEN }
#else
.rxmode = { .max_rx_pkt_len = RTE_ETHER_MAX_LEN }
#endif
};
/* ************************************ */
+30 -11
View File
@@ -32,6 +32,7 @@
#include "uthash.h"
#include <pcap.h>
#include "ndpi_classify.h"
#include "ndpi_typedefs.h"
#ifdef USE_DPDK
#include <rte_eal.h>
@@ -93,7 +94,7 @@ typedef struct ndpi_ja3_info {
// external hash table (host ip -> <ip string, hash table ja3c, hash table ja3s>)
// used to aggregate ja3 fingerprints by hosts
typedef struct ndpi_host_ja3_fingerprints{
typedef struct ndpi_host_ja3_fingerprints {
u_int32_t ip;
char *ip_string;
char *dns_name;
@@ -160,49 +161,66 @@ typedef struct ndpi_flow_info {
u_int16_t dst_port;
u_int8_t detection_completed, protocol, bidirectional, check_extra_packets;
u_int16_t vlan_id;
ndpi_packet_tunnel tunnel_type;
struct ndpi_flow_struct *ndpi_flow;
char src_name[48], dst_name[48];
u_int8_t ip_version;
u_int32_t cwr_count, src2dst_cwr_count, dst2src_cwr_count;
u_int32_t ece_count, src2dst_ece_count, dst2src_ece_count;
u_int32_t urg_count, src2dst_urg_count, dst2src_urg_count;
u_int32_t ack_count, src2dst_ack_count, dst2src_ack_count;
u_int32_t psh_count, src2dst_psh_count, dst2src_psh_count;
u_int32_t syn_count, src2dst_syn_count, dst2src_syn_count;
u_int32_t fin_count, src2dst_fin_count, dst2src_fin_count;
u_int32_t rst_count, src2dst_rst_count, dst2src_rst_count;
u_int32_t c_to_s_init_win, s_to_c_init_win;
u_int64_t first_seen, last_seen;
u_int64_t src2dst_bytes, dst2src_bytes;
u_int64_t src2dst_goodput_bytes, dst2src_goodput_bytes;
u_int32_t src2dst_packets, dst2src_packets;
u_int32_t has_human_readeable_strings;
char human_readeable_string_buffer[32];
// result only, not used for flow identification
ndpi_protocol detected_protocol;
// Flow data analysis
struct ndpi_analyze_struct *iat_c_to_s, *iat_s_to_c, *iat_flow,
*pktlen_c_to_s, *pktlen_s_to_c;
char info[96];
char host_server_name[256];
char info[160];
char flow_extra_info[16];
char host_server_name[240];
char bittorent_hash[41];
char dhcp_fingerprint[48];
struct {
u_int16_t ssl_version;
char client_info[64], server_info[64],
client_hassh[33], server_hassh[33],
char client_requested_server_name[64], server_info[64],
client_hassh[33], server_hassh[33], *server_names,
*tls_alpn, *tls_supported_versions,
server_organization[64],
ja3_client[33], ja3_server[33],
sha1_cert_fingerprint[20];
u_int8_t sha1_cert_fingerprint_set;
time_t notBefore, notAfter;
u_int16_t server_cipher;
ndpi_cipher_weakness client_unsafe_cipher, server_unsafe_cipher;
ndpi_cipher_weakness client_unsafe_cipher, server_unsafe_cipher;
} ssh_tls;
struct {
char url[256];
char url[256], content_type[64], user_agent[128];
u_int response_status_code;
} http;
struct {
char username[32], password[32];
} telnet;
void *src_id, *dst_id;
struct ndpi_entropy entropy;
struct ndpi_entropy last_entropy;
} ndpi_flow_info_t;
@@ -299,6 +317,7 @@ int ndpi_workflow_node_cmp(const void *a, const void *b);
void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_flow_info *flow);
u_int32_t ethernet_crc32(const void* data, size_t n_bytes);
void ndpi_flow_info_freer(void *node);
void ndpi_free_flow_data_analysis(struct ndpi_flow_info *flow);
const char* print_cipher_id(u_int32_t cipher);
float ndpi_flow_get_byte_count_entropy(const uint32_t byte_count[256], unsigned int num_bytes);
+33
View File
@@ -0,0 +1,33 @@
bin_PROGRAMS = fuzz_process_packet fuzz_ndpi_reader
fuzz_process_packet_SOURCES = fuzz_process_packet.c
fuzz_process_packet_LDFLAGS = ../src/lib/libndpi.a $(ADDITIONAL_LIBS)
if HAS_FUZZLDFLAGS
fuzz_process_packet_LDFLAGS += $(LIB_FUZZING_ENGINE)
else
fuzz_process_packet_SOURCES += onefile.c
endif
# force usage of CXX for linker
fuzz_process_packet_LINK=$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CXX) $(AM_CXXFLAGS) $(CXXFLAGS) \
$(fuzz_process_packet_LDFLAGS) $(LDFLAGS) -o $@
fuzz_ndpi_reader_SOURCES = fuzz_ndpi_reader.c
fuzz_ndpi_reader_CFLAGS = -I../example/
fuzz_ndpi_reader_LDFLAGS = ../example/libndpiReader.a ../src/lib/libndpi.a $(PCAP_LIB) $(ADDITIONAL_LIBS)
if HAS_FUZZLDFLAGS
fuzz_ndpi_reader_LDFLAGS += $(LIB_FUZZING_ENGINE)
else
fuzz_ndpi_reader_SOURCES += onefile.c
endif
# force usage of CXX for linker
fuzz_ndpi_reader_LINK=$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CXX) $(AM_CXXFLAGS) $(CXXFLAGS) \
$(fuzz_ndpi_reader_LDFLAGS) $(LDFLAGS) -o $@
EXTRA_fuzz_ndpi_reader_DEPENDENCIES = fuzz_ndpi_reader_seed_corpus.zip
testpcaps := $(wildcard ../tests/pcap/*.pcap)
fuzz_ndpi_reader_seed_corpus.zip: $(testpcaps)
zip -r fuzz_ndpi_reader_seed_corpus.zip $(testpcaps)
+91
View File
@@ -0,0 +1,91 @@
#include "reader_util.h"
#include "ndpi_api.h"
#include <pcap/pcap.h>
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
struct ndpi_workflow_prefs *prefs = NULL;
int nDPI_LogLevel = 0;
char *_debug_protocols = NULL;
u_int32_t current_ndpi_memory = 0, max_ndpi_memory = 0;
u_int8_t enable_protocol_guess = 1, enable_payload_analyzer = 0;
u_int8_t enable_joy_stats = 0;
u_int8_t human_readeable_string_len = 5;
u_int8_t max_num_udp_dissected_pkts = 16 /* 8 is enough for most protocols, Signal requires more */, max_num_tcp_dissected_pkts = 80 /* due to telnet */;
int bufferToFile(const char * name, const uint8_t *Data, size_t Size) {
FILE * fd;
if (remove(name) != 0) {
if (errno != ENOENT) {
printf("failed remove, errno=%d\n", errno);
return -1;
}
}
fd = fopen(name, "wb");
if (fd == NULL) {
printf("failed open, errno=%d\n", errno);
return -2;
}
if (fwrite (Data, 1, Size, fd) != Size) {
fclose(fd);
return -3;
}
fclose(fd);
return 0;
}
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
pcap_t * pkts;
const u_char *pkt;
struct pcap_pkthdr *header;
int r;
char errbuf[PCAP_ERRBUF_SIZE];
NDPI_PROTOCOL_BITMASK all;
if (prefs == NULL) {
prefs = calloc(sizeof(struct ndpi_workflow_prefs), 1);
if (prefs == NULL) {
//should not happen
return 1;
}
prefs->decode_tunnels = 1;
prefs->num_roots = 16;
prefs->max_ndpi_flows = 1024;
prefs->quiet_mode = 0;
}
bufferToFile("/tmp/fuzz.pcap", Data, Size);
pkts = pcap_open_offline("/tmp/fuzz.pcap", errbuf);
if (pkts == NULL) {
return 0;
}
struct ndpi_workflow * workflow = ndpi_workflow_init(prefs, pkts);
// enable all protocols
NDPI_BITMASK_SET_ALL(all);
ndpi_set_protocol_detection_bitmask2(workflow->ndpi_struct, &all);
memset(workflow->stats.protocol_counter, 0,
sizeof(workflow->stats.protocol_counter));
memset(workflow->stats.protocol_counter_bytes, 0,
sizeof(workflow->stats.protocol_counter_bytes));
memset(workflow->stats.protocol_flows, 0,
sizeof(workflow->stats.protocol_flows));
ndpi_finalize_initalization(workflow->ndpi_struct);
r = pcap_next_ex(pkts, &header, &pkt);
while (r > 0) {
/* allocate an exact size buffer to check overflows */
uint8_t *packet_checked = malloc(header->caplen);
memcpy(packet_checked, pkt, header->caplen);
ndpi_workflow_process_packet(workflow, header, packet_checked);
free(packet_checked);
r = pcap_next_ex(pkts, &header, &pkt);
}
ndpi_workflow_free(workflow);
pcap_close(pkts);
return 0;
}
+28
View File
@@ -0,0 +1,28 @@
#include "ndpi_api.h"
#include <stdint.h>
#include <stdio.h>
struct ndpi_detection_module_struct *ndpi_info_mod = NULL;
struct ndpi_id_struct *src;
struct ndpi_id_struct *dst;
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
if (ndpi_info_mod == NULL) {
ndpi_info_mod = ndpi_init_detection_module(ndpi_no_prefs);
NDPI_PROTOCOL_BITMASK all;
NDPI_BITMASK_SET_ALL(all);
ndpi_set_protocol_detection_bitmask2(ndpi_info_mod, &all);
src = ndpi_malloc(SIZEOF_ID_STRUCT);
dst = ndpi_malloc(SIZEOF_ID_STRUCT);
}
struct ndpi_flow_struct *ndpi_flow = ndpi_flow_malloc(SIZEOF_FLOW_STRUCT);
memset(ndpi_flow, 0, SIZEOF_FLOW_STRUCT);
memset(src, 0, SIZEOF_ID_STRUCT);
memset(dst, 0, SIZEOF_ID_STRUCT);
ndpi_detection_process_packet(ndpi_info_mod, ndpi_flow, Data, Size, 0, src, dst);
ndpi_free_flow(ndpi_flow);
return 0;
}
+2 -2
View File
@@ -29,8 +29,8 @@ build-rpm: build-src cleanup-rpm
tar cvfz $(HOME)/rpmbuild/SOURCES/ndpi-@PACKAGE_VERSION@.tgz ndpi-@PACKAGE_VERSION@
@rm -f $(HOME)/rpmbuild/RPMS/$(PLATFORM)/$(PACKAGE)
@rpmbuild -bb ./$(APPL).spec --define "buildnumber $(GIT_REVISION)"
@if [[ $EUID -ne 0 ]]; then ./rpm-sign.exp $(HOME)/rpmbuild/RPMS/$(PLATFORM)/$(PACKAGE); fi
@if [[ $EUID -ne 0 ]]; then ./rpm-sign.exp $(HOME)/rpmbuild/RPMS/$(PLATFORM)/$(DEV_PACKAGE); fi
@if [[ $EUID -ne 0 ]]; then @RPM_SIGN_CMD@ $(HOME)/rpmbuild/RPMS/$(PLATFORM)/$(PACKAGE); fi
@if [[ $EUID -ne 0 ]]; then @RPM_SIGN_CMD@ $(HOME)/rpmbuild/RPMS/$(PLATFORM)/$(DEV_PACKAGE); fi
@echo ""
@echo "Package contents:"
@rpm -qpl $(HOME)/rpmbuild/RPMS/$(PLATFORM)/$(PACKAGE)
+12
View File
@@ -583,6 +583,7 @@ PACKAGE_URL=''
ac_subst_vars='LTLIBOBJS
LIBOBJS
RPM_SIGN_CMD
MAJOR_RELEASE
GIT_REVISION
KERNEL
@@ -1698,6 +1699,16 @@ PACKAGE_VERSION=`../version.sh --release`
MAJOR_RELEASE=`../version.sh --major-release`
GIT_REVISION=`../version.sh --revision`
CENTOS_RELEASE=`cat /etc/centos-release | cut -d ' ' -f 3|cut -d '.' -f 1`
if test $CENTOS_RELEASE = "release"; then
CENTOS_RELEASE=`cat /etc/centos-release | cut -d ' ' -f 4|cut -d '.' -f 1`
fi
RPM_SIGN_CMD="rpm --addsign"
if test "$CENTOS_RELEASE" -ne 8; then
RPM_SIGN_CMD="./rpm-sign.exp"
fi
ac_config_files="$ac_config_files Makefile ndpi.spec"
@@ -1710,6 +1721,7 @@ ac_config_files="$ac_config_files Makefile ndpi.spec"
cat >confcache <<\_ACEOF
# This file is a shell script that caches the results of configure
# tests run on this system so they can be shared between configure
+11
View File
@@ -29,6 +29,16 @@ PACKAGE_VERSION=`../version.sh --release`
MAJOR_RELEASE=`../version.sh --major-release`
GIT_REVISION=`../version.sh --revision`
CENTOS_RELEASE=`cat /etc/centos-release | cut -d ' ' -f 3|cut -d '.' -f 1`
if test $CENTOS_RELEASE = "release"; then
CENTOS_RELEASE=`cat /etc/centos-release | cut -d ' ' -f 4|cut -d '.' -f 1`
fi
RPM_SIGN_CMD="rpm --addsign"
if test "$CENTOS_RELEASE" -ne 8; then
RPM_SIGN_CMD="./rpm-sign.exp"
fi
AC_CONFIG_FILES([Makefile ndpi.spec])
AC_SUBST(PACKAGE_VERSION)
@@ -39,6 +49,7 @@ AC_SUBST(DATE)
AC_SUBST(KERNEL)
AC_SUBST(GIT_REVISION)
AC_SUBST(MAJOR_RELEASE)
AC_SUBST(RPM_SIGN_CMD)
AC_OUTPUT
+4
View File
@@ -12,6 +12,8 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-root
%{?el6:Requires: glibc >= 2.3.4 numactl coreutils }
AutoReqProv: no
%define debug_package %{nil}
%description
nDPI Open and Extensible LGPLv3 Deep Packet Inspection Library.
@@ -75,6 +77,8 @@ rm -fr $RPM_BUILD_ROOT
/usr/local/lib/libndpi.so.@MAJOR_RELEASE@
/usr/local/lib/libndpi.so.@PACKAGE_VERSION@
/usr/local/bin/ndpiReader
/usr/local/share/ndpi/ndpiCustomCategory.txt
/usr/local/share/ndpi/ndpiProtos.txt
/etc/ld.so.conf.d/ndpi.conf
%{libdir}/pkgconfig/libndpi.pc
-7
View File
@@ -1,7 +0,0 @@
This direcgory contains the Python bindings for nDPI
Usage:
- python3 ndpi_example.py <interface>
- python3 ndpi_example.py <pcap_file>
Code courtesy of Massimo Puddu
+44
View File
@@ -0,0 +1,44 @@
nDPI Python bindings
--------------------
This directory contains the Python3 bindings for nDPI. We provide both ctypes and cffi based bindings.
**ctypes bindings**
Files:
* ndpi_typestruct.py
* ndpi_wrap.c
* Makefile.in
Example:
.. code-block:: bash
pip3 install scapy
python3 ndpi_example.py <interface>
python3 ndpi_example.py <pcap_file>
Code courtesy:
* Massimo Puddu
* Zied Aouini
**cffi bindings**
Files:
* ndpi.py
Example (using NFStream package):
.. code-block:: bash
pip3 install nfstream
python3 flow_printer.py <interface>
python3 flow_printer.py <pcap_file>
Code courtesy:
* Zied Aouini
+39
View File
@@ -0,0 +1,39 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
file: flow_printer.py
This file is part of nfstream.
Copyright (C) 2019 - Zied Aouini <aouinizied@gmail.com>
nfstream is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
nfstream is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with nfstream.
If not, see <http://www.gnu.org/licenses/>.
"""
from nfstream import NFStreamer
import sys
path = sys.argv[1]
flow_streamer = NFStreamer(source=path)
result = {}
try:
for flow in flow_streamer:
print(flow)
try:
result[flow.application_name] += flow.total_packets
except KeyError:
result[flow.application_name] = flow.total_packets
print("Summary (Application Name: Packets):")
print(result)
except KeyboardInterrupt:
print("Summary (Application Name: Packets):")
print(result)
print("Terminated.")
+1297
View File
File diff suppressed because it is too large Load Diff
+88 -67
View File
@@ -1,43 +1,44 @@
#!/usr/bin/env python3
#
# ndpi_example.py
#
# Copyright (C) 2011-19 - ntop.org
#
# nDPI is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# nDPI is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with nDPI. If not, see <http://www.gnu.org/licenses/>.
#
# -*- coding: utf-8 -*-
"""
file: ndpi_example.py
This file is part of nDPI.
Copyright (C) 2011-19 - ntop.org
Copyright (C) 2019 - Zied Aouini <aouinizied@gmail.com> (Incremental improvements)
nDPI is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
nDPI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with nDPI.
If not, see <http://www.gnu.org/licenses/>.
"""
from ndpi_typestruct import *
from ctypes import *
from scapy.all import *
import sys
# ------- return type & pcapstruct to declare -------
class workflow(Structure):
class WorkFlow(Structure):
_fields_ = [("src_ip", c_uint32),
("dst_ip", c_uint32),
("src_port", c_uint16),
("dst_port", c_uint16),
("protocol", c_uint8),
("packets", c_uint32),
("detected_protocol", ndpi_protocol),
("detected_protocol", NDPIProtocol),
("detection_completed", c_uint8),
("id", c_uint32),
("src_id", POINTER(ndpi_id_struct)),
("dst_id", POINTER(ndpi_id_struct)),
("flow", POINTER(ndpi_flow_struct))]
("src_id", POINTER(NDPIIdStruct)),
("dst_id", POINTER(NDPIIdStruct)),
("flow", POINTER(NDPIFlowStruct))]
CMCFUN = CFUNCTYPE(c_int, c_void_p, c_void_p)
@@ -48,17 +49,19 @@ FREE = CFUNCTYPE(None, c_void_p)
def node_proto_guess_walker(nodo, which, depth, user_data):
global ndpi_info_mod
flow = cast(nodo, POINTER(POINTER(workflow))).contents.contents
if which == 0 or which == 3: #execute only preorder operation of the tree
flow = cast(nodo, POINTER(POINTER(WorkFlow))).contents.contents
if which == 0 or which == 3: # execute only preorder operation of the tree
if flow.detection_completed == 0: # order for tree operation
flow.detected_protocol = ndpi.ndpi_detection_giveup(ndpi_info_mod, flow.flow, flow.protocol,
int(socket.ntohl(flow.src_ip)), 1)
flow.detected_protocol = ndpi.ndpi_detection_giveup(ndpi_info_mod,
flow.flow,
1,
cast(addressof(c_uint8(0)), POINTER(c_uint8)))
count_protocol[flow.detected_protocol.app_protocol] += flow.packets
def py_cmp_fun(a, b):
fa = cast(a, POINTER(workflow))
fb = cast(b, POINTER(workflow))
fa = cast(a, POINTER(WorkFlow))
fb = cast(b, POINTER(WorkFlow))
if fa.contents.src_ip < fb.contents.src_ip: return -1
elif fa.contents.src_ip > fb.contents.src_ip: return 1
@@ -83,7 +86,7 @@ free_walk = FREE(freer)
# --------------------------------------
# number of anylized packet
# number of analyzed packet
packet_number = 0
flow_count = 0
max_num_udp_dissected_pkts = 16
@@ -103,6 +106,8 @@ if ndpi.ndpi_get_api_version() != ndpi.ndpi_wrap_get_api_version():
ndpi_info_mod = ndpi.ndpi_init_detection_module()
if ndpi_info_mod is None:
sys.exit(-1)
else:
ndpi_ndpi_finalize_initalization(ndpi_info_mod)
def ip2int(ip):
@@ -113,30 +118,34 @@ def ip2int(ip):
return int(struct.unpack("!I", packedIP)[0])
def get_flow(packet):
def get_flow(pkt):
global flows_root
global flows_root_ref
global flow_count
ip_packet = packet[1]
ip_packet = pkt[1]
ip_protocol = ip_packet.proto
transport_packet = None
if ip_protocol == 6 or ip_protocol == 17: transport_packet = packet[2]
if ip_protocol == 6 or ip_protocol == 17:
transport_packet = pkt[2]
if transport_packet is not None:
# to avoid two nodes in one binary tree for a flow
ip_src = ip2int(ip_packet.src)
ip_dst = ip2int(ip_packet.dst)
src_port = transport_packet.sport
dst_port = transport_packet.dport
else: return None
# set flows to correct type and data
ndpi_flow = pointer(ndpi_flow_struct())
memset(ndpi_flow, 0, sizeof(ndpi_flow_struct))
if ip_src > ip_dst:
flow = workflow(ip_src, ip_dst, src_port, dst_port, int(ip_packet.proto), 0, ndpi_protocol(), 0, 0, pointer(ndpi_id_struct()), pointer(ndpi_id_struct()), ndpi_flow)
else:
flow = workflow(ip_dst, ip_src, dst_port, src_port, int(ip_packet.proto), 0, ndpi_protocol(), 0, 0, pointer(ndpi_id_struct()), pointer(ndpi_id_struct()), ndpi_flow)
return None
# set flows to correct type and data
ndpi_flow = pointer(NDPIFlowStruct())
memset(ndpi_flow, 0, sizeof(NDPIFlowStruct))
if ip_src > ip_dst:
flow = WorkFlow(ip_src, ip_dst, src_port, dst_port, int(ip_packet.proto), 0, NDPIProtocol(), 0, 0,
pointer(NDPIIdStruct()), pointer(NDPIIdStruct()), ndpi_flow)
else:
flow = WorkFlow(ip_dst, ip_src, dst_port, src_port, int(ip_packet.proto), 0, NDPIProtocol(), 0, 0,
pointer(NDPIIdStruct()), pointer(NDPIIdStruct()), ndpi_flow)
flow_ref = pointer(flow)
res = ndpi.ndpi_tfind(flow_ref, flows_root_ref, cmp_func)
if res is None:
@@ -144,41 +153,45 @@ def get_flow(packet):
lista.append(flow)
flow_count += 1
return pointer(flow)
flow = cast(res, POINTER(POINTER(workflow))).contents
flow = cast(res, POINTER(POINTER(WorkFlow))).contents
return flow
def packetcaptured(packet):
def packetcaptured(pkt):
global packet_number
global start_time
global ndpi_info_mod
flow = None
h = pcap_pkthdr()
h = PcapPktHdr()
#getting flow
# getting flow
try:
flow = get_flow(packet)
flow = get_flow(pkt)
except AttributeError:
pass # ignore packet
pass # ignore packet
if flow is None: return
#filling pcap_pkthdr
h.len = h.caplen = len(packet)
h.ts.tv_sec = int(packet["IP"].time/1000000)
h.ts.tv_usec = int(packet["IP"].time)
# filling pcap_pkthdr
h.len = h.caplen = len(pkt)
h.ts.tv_sec = int(pkt["IP"].time/1000000)
h.ts.tv_usec = int(pkt["IP"].time)
# real work
if int(packet[1].frag) == 0: # not fragmented packet
if int(pkt[1].frag) == 0: # not fragmented packet
flow.contents.packets += 1
packet_number += 1
# get ndpi_iphdr address
iphdr_addr = cast(c_char_p(packet[1].build()), c_void_p)
iphdr_addr = cast(c_char_p(pkt[1].build()), c_void_p)
ndpi_flow = flow.contents.flow
if flow.contents.detection_completed is 0:
flow.contents.detected_protocol = ndpi.ndpi_detection_process_packet(ndpi_info_mod, ndpi_flow, cast(iphdr_addr, POINTER(c_uint8)),
int(packet[1].len), h.ts.tv_usec, flow.contents.src_id, flow.contents.dst_id)
flow.contents.detected_protocol = ndpi.ndpi_detection_process_packet(ndpi_info_mod,
ndpi_flow,
cast(iphdr_addr, POINTER(c_uint8)),
int(pkt[1].len),
h.ts.tv_usec,
flow.contents.src_id,
flow.contents.dst_id)
flow1 = flow.contents.detected_protocol
@@ -187,27 +200,32 @@ def packetcaptured(packet):
if flow.contents.protocol == 6: valid = flow.contents.packets > max_num_tcp_dissected_pkts
elif flow.contents.protocol == 17: valid = flow.contents.packets > max_num_udp_dissected_pkts
#should we continue anylizing packet or not?
# should we continue anylizing packet or not?
if valid or flow1.app_protocol is not 0:
if valid or flow1.master_protocol is not 91: #or # 91 is NDPI_PROTOCOL_TLS
flow.contents.detection_completed = 1 #protocol found
if valid or flow1.master_protocol is not 91: # or # 91 is NDPI_PROTOCOL_TLS
flow.contents.detection_completed = 1 # protocol found
if flow1.app_protocol is 0:
flow.contents.detected_protocol = ndpi.ndpi_detection_giveup(ndpi_info_mod, ndpi_flow, 1)
flow.contents.detected_protocol = ndpi.ndpi_detection_giveup(ndpi_info_mod,
ndpi_flow,
1,
cast(addressof(c_uint8(0)),
POINTER(c_uint8)))
def result():
global flows_root_ref
global ndpi_info_mod
print('\nnumber of anylized packet ' + str(packet_number))
print('number of flows ' + str(flow_count))
print('\nnumber of analyzed packet: ' + str(packet_number))
print('number of flows: ' + str(flow_count))
ndpi.ndpi_twalk(flows_root_ref.contents, guess_walker, None)
print('\nDetected protocols:')
for i in range(0, ndpi.ndpi_get_num_supported_protocols(ndpi_info_mod)):
if count_protocol[i] > 0:
print(cast(ndpi.ndpi_get_proto_name(ndpi_info_mod, i), c_char_p).value + ': '.encode('UTF-8') + str(count_protocol[i]).encode('UTF-8'))
print("{}: {} packets".format(
cast(ndpi.ndpi_get_proto_name(ndpi_info_mod, i), c_char_p).value.decode('utf-8'),
str(count_protocol[i])))
def free(ndpi_struct):
@@ -216,16 +234,16 @@ def free(ndpi_struct):
def initialize(ndpi_struct):
all = NDPI_PROTOCOL_BITMASK()
all = NDPIProtocolBitMask()
ndpi.ndpi_wrap_NDPI_BITMASK_SET_ALL(pointer(all))
ndpi.ndpi_set_protocol_detection_bitmask2(ndpi_struct, pointer(all))
print('Using nDPI ' + str(cast(ndpi.ndpi_revision(), c_char_p).value))
print('Using nDPI ' + cast(ndpi.ndpi_revision(), c_char_p).value.decode("utf-8"))
initialize(ndpi_info_mod)
if(len(sys.argv) != 2):
if len(sys.argv) != 2:
print("\nUsage: ndpi_example.py <device>")
sys.exit(0)
@@ -247,6 +265,9 @@ else:
sniff(iface=sys.argv[1], prn=packetcaptured)
except KeyboardInterrupt:
print('\nInterrupted\n')
except PermissionError:
sys.exit('\nRoot privilege required for live capture on interface: {}\n'.format(sys.argv[1]))
result()
free(ndpi_info_mod)
+447 -356
View File
File diff suppressed because it is too large Load Diff
+109 -33
View File
@@ -1,7 +1,7 @@
/*
* ndpi_api.h
*
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
@@ -138,11 +138,23 @@ extern "C" {
/**
* Returns a new initialized detection module
* Note that before you can use it you can still load
* hosts and do other things. As soon as you are ready to use
* it do not forget to call first ndpi_finalize_initalization()
*
* @par prefs = load preferences
* @return the initialized detection module
*
*/
struct ndpi_detection_module_struct *ndpi_init_detection_module(ndpi_init_prefs prefs);
/**
* Completes the initialization (2nd step)
*
* @return the initialized detection module
*
*/
struct ndpi_detection_module_struct *ndpi_init_detection_module(void);
void ndpi_finalize_initalization(struct ndpi_detection_module_struct *ndpi_str);
/**
* Frees the memory allocated in the specified flow
@@ -207,30 +219,21 @@ extern "C" {
void ndpi_set_protocol_detection_bitmask2(struct ndpi_detection_module_struct *ndpi_struct,
const NDPI_PROTOCOL_BITMASK * detection_bitmask);
/**
* Function to be called to see in case of unknown match to see if there is
* a partial match that has been prevented by the current nDPI preferences configuration
*
* @par ndpi_struct = the detection module
* @par flow = the flow given for the detection module
* @return the detected protocol even if the flow is not completed;
*
*/
ndpi_protocol ndpi_get_partial_detection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow);
/**
/**
* Function to be called before we give up with detection for a given flow.
* This function reduces the NDPI_UNKNOWN_PROTOCOL detection
*
* @par ndpi_struct = the detection module
* @par flow = the flow given for the detection module
* @par enable_guess = guess protocol if unknown
* @par protocol_was_guessed = 1 if the protocol was guesses (requires enable_guess = 1), 0 otherwise
* @return the detected protocol even if the flow is not completed;
*
*/
ndpi_protocol ndpi_detection_giveup(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
u_int8_t enable_guess);
u_int8_t enable_guess,
u_int8_t *protocol_was_guessed);
/**
* Processes an extra packet in order to get more information for a given protocol
@@ -503,6 +506,21 @@ extern "C" {
u_int8_t ndpi_is_subprotocol_informative(struct ndpi_detection_module_struct *ndpi_mod,
u_int16_t protoId);
/**
* Set hostname-based protocol
*
* @par ndpi_mod = the detection module
* @par flow = the flow to which this communication belongs to
* @par master_protocol = the master protocol for this flow
* @par name = the host name
* @par name_len = length of the host name
*
*/
int ndpi_match_hostname_protocol(struct ndpi_detection_module_struct *ndpi_mod,
struct ndpi_flow_struct *flow,
u_int16_t master_protocol,
char *name, u_int name_len);
/**
* Get protocol category as string
*
@@ -613,6 +631,16 @@ extern "C" {
int ndpi_load_protocols_file(struct ndpi_detection_module_struct *ndpi_mod,
const char* path);
/**
* Read a file and load the categories
*
* @par ndpi_mod = the detection module
* @par path = the path of the file
* @return 0 if the file is loaded correctly;
* -1 else
*/
int ndpi_load_categories_file(struct ndpi_detection_module_struct *ndpi_str, const char* path);
/**
* Get the total number of the supported protocols
*
@@ -744,26 +772,32 @@ extern "C" {
*/
int ndpi_match_string(void *_automa, char *string_to_match);
void ndpi_load_ip_category(struct ndpi_detection_module_struct *ndpi_struct,
char *ip_address_and_mask, ndpi_protocol_category_t category);
int ndpi_load_ip_category(struct ndpi_detection_module_struct *ndpi_struct,
const char *ip_address_and_mask, ndpi_protocol_category_t category);
int ndpi_load_hostname_category(struct ndpi_detection_module_struct *ndpi_struct,
char *name, ndpi_protocol_category_t category);
const char *name_to_add, ndpi_protocol_category_t category);
int ndpi_load_category(struct ndpi_detection_module_struct *ndpi_struct,
const char *ip_or_name, ndpi_protocol_category_t category);
int ndpi_enable_loaded_categories(struct ndpi_detection_module_struct *ndpi_struct);
int ndpi_fill_ip_protocol_category(struct ndpi_detection_module_struct *ndpi_struct,
u_int32_t saddr,
u_int32_t daddr,
ndpi_protocol *ret);
int ndpi_match_custom_category(struct ndpi_detection_module_struct *ndpi_struct,
char *name, unsigned long *id);
char *name, u_int name_len, unsigned long *id);
void ndpi_fill_protocol_category(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
ndpi_protocol *ret);
int ndpi_get_custom_category_match(struct ndpi_detection_module_struct *ndpi_struct,
char *name_or_ip, unsigned long *id);
char *name_or_ip, u_int name_len, unsigned long *id);
int ndpi_set_detection_preferences(struct ndpi_detection_module_struct *ndpi_mod,
ndpi_detection_preference pref,
int value);
/* Tells to called on what l4 protocol given application protocol can be found */
ndpi_l4_proto_info ndpi_get_l4_proto_info(struct ndpi_detection_module_struct *ndpi_struct, u_int16_t ndpi_proto_id);
const char* ndpi_get_l4_proto_name(ndpi_l4_proto_info proto);
ndpi_proto_defaults_t* ndpi_get_proto_defaults(struct ndpi_detection_module_struct *ndpi_mod);
u_int ndpi_get_ndpi_num_supported_protocols(struct ndpi_detection_module_struct *ndpi_mod);
u_int ndpi_get_ndpi_num_custom_protocols(struct ndpi_detection_module_struct *ndpi_mod);
@@ -782,11 +816,12 @@ extern "C" {
*
* @par The automata initialized with ndpi_init_automa();
* @par The (sub)string to search
* @par The (sub)string length
* @par The id associated with the matched string or 0 id not found.
* @return 0 in case of match, or -1 if no match, or -2 if an error occurred.
*
*/
int ndpi_match_string_id(void *_automa, char *string_to_match, unsigned long *id);
int ndpi_match_string_id(void *_automa, char *string_to_match, u_int match_len, unsigned long *id);
/* Utility functions to set ndpi malloc/free/print wrappers */
void set_ndpi_malloc(void* (*__ndpi_malloc)(size_t size));
@@ -810,13 +845,39 @@ extern "C" {
struct ndpi_flow_struct *flow);
u_int8_t ndpi_is_safe_ssl_cipher(u_int32_t cipher);
const char* ndpi_cipher2str(u_int32_t cipher);
const char* ndpi_tunnel2str(ndpi_packet_tunnel tt);
u_int16_t ndpi_guess_host_protocol_id(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow);
int ndpi_has_human_readeable_string(struct ndpi_detection_module_struct *ndpi_struct,
char *buffer, u_int buffer_size,
u_int8_t min_string_match_len, /* Will return 0 if no string > min_string_match_len have been found */
char *outbuf, u_int outbuf_len);
char* ndpi_ssl_version2str(u_int16_t version);
char* ndpi_ssl_version2str(u_int16_t version, u_int8_t *unknown_tls_version);
void ndpi_patchIPv6Address(char *str);
void ndpi_user_pwd_payload_copy(u_int8_t *dest, u_int dest_len, u_int offset,
const u_int8_t *src, u_int src_len);
u_char* ndpi_base64_decode(const u_char *src, size_t len, size_t *out_len);
char* ndpi_base64_encode(unsigned char const* bytes_to_encode, ssize_t in_len);
int ndpi_load_ipv4_ptree(struct ndpi_detection_module_struct *ndpi_str,
const char *path, u_int16_t protocol_id);
int ndpi_flow2json(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
u_int8_t ip_version,
u_int8_t l4_protocol, u_int16_t vlan_id,
u_int32_t src_v4, u_int32_t dst_v4,
struct ndpi_in6_addr *src_v6, struct ndpi_in6_addr *dst_v6,
u_int16_t src_port, u_int16_t dst_port,
ndpi_protocol l7_protocol,
ndpi_serializer *serializer);
void ndpi_md5(const u_char *data, size_t data_len, u_char hash[16]);
/* ptree (trie) API */
ndpi_ptree_t* ndpi_ptree_create(void);
int ndpi_ptree_insert(ndpi_ptree_t *tree, const ndpi_ip_addr_t *addr, u_int8_t bits, uint user_data);
int ndpi_ptree_match_addr(ndpi_ptree_t *tree, const ndpi_ip_addr_t *addr, uint *user_data);
void ndpi_ptree_destroy(ndpi_ptree_t *tree);
/* Serializer */
int ndpi_init_serializer_ll(ndpi_serializer *serializer, ndpi_serialization_format fmt,
@@ -824,10 +885,7 @@ extern "C" {
int ndpi_init_serializer(ndpi_serializer *serializer, ndpi_serialization_format fmt);
void ndpi_term_serializer(ndpi_serializer *serializer);
void ndpi_reset_serializer(ndpi_serializer *serializer);
int ndpi_serialize_string_int32(ndpi_serializer *serializer,
const char *key, int32_t value);
int ndpi_serialize_string_int64(ndpi_serializer *serializer,
const char *key, int64_t value);
int ndpi_serialize_uint32_uint32(ndpi_serializer *serializer,
u_int32_t key, u_int32_t value);
int ndpi_serialize_uint32_uint64(ndpi_serializer *serializer,
@@ -841,6 +899,13 @@ extern "C" {
const char *format /* e.f. "%.2f" */);
int ndpi_serialize_uint32_string(ndpi_serializer *serializer,
u_int32_t key, const char *value);
int ndpi_serialize_uint32_boolean(ndpi_serializer *serializer,
u_int32_t key, u_int8_t value);
int ndpi_serialize_string_int32(ndpi_serializer *serializer,
const char *key, int32_t value);
int ndpi_serialize_string_int64(ndpi_serializer *serializer,
const char *key, int64_t value);
int ndpi_serialize_string_uint32(ndpi_serializer *serializer,
const char *key, u_int32_t value);
int ndpi_serialize_string_uint32_format(ndpi_serializer *serializer,
@@ -850,20 +915,26 @@ extern "C" {
const char *key, u_int64_t value);
int ndpi_serialize_string_string(ndpi_serializer *serializer,
const char *key, const char *value);
int ndpi_serialize_string_binary(ndpi_serializer *_serializer,
int ndpi_serialize_string_binary(ndpi_serializer *serializer,
const char *key, const char *_value,
u_int16_t vlen);
int ndpi_serialize_string_raw(ndpi_serializer *_serializer,
const char *key, const char *_value,
u_int16_t vlen);
int ndpi_serialize_string_float(ndpi_serializer *serializer,
const char *key, float value,
const char *format /* e.f. "%.2f" */);
int ndpi_serialize_string_boolean(ndpi_serializer *serializer,
const char *key, u_int8_t value);
int ndpi_serialize_end_of_record(ndpi_serializer *serializer);
int ndpi_serialize_start_of_block(ndpi_serializer *_serializer,
int ndpi_serialize_start_of_block(ndpi_serializer *serializer,
const char *key);
int ndpi_serialize_end_of_block(ndpi_serializer *_serializer);
char* ndpi_serializer_get_buffer(ndpi_serializer *_serializer, u_int32_t *buffer_len);
u_int32_t ndpi_serializer_get_buffer_len(ndpi_serializer *_serializer);
int ndpi_serializer_set_buffer_len(ndpi_serializer *_serializer, u_int32_t l);
int ndpi_serialize_end_of_block(ndpi_serializer *serializer);
char* ndpi_serializer_get_buffer(ndpi_serializer *serializer, u_int32_t *buffer_len);
u_int32_t ndpi_serializer_get_buffer_len(ndpi_serializer *serializer);
u_int32_t ndpi_serializer_get_internal_buffer_size(ndpi_serializer *serializer);
int ndpi_serializer_set_buffer_len(ndpi_serializer *serializer, u_int32_t l);
void ndpi_serializer_set_csv_separator(ndpi_serializer *serializer, char separator);
void ndpi_serializer_create_snapshot(ndpi_serializer *serializer);
@@ -912,6 +983,11 @@ extern "C" {
const char* ndpi_data_ratio2str(float ratio);
void ndpi_data_print_window_values(struct ndpi_analyze_struct *s); /* debug */
ndpi_url_risk ndpi_validate_url(char *url);
u_int8_t ndpi_is_protocol_detected(struct ndpi_detection_module_struct *ndpi_str,
ndpi_protocol proto);
#ifdef __cplusplus
}
#endif
+1 -2
View File
@@ -43,8 +43,7 @@
#ifndef NDPI_CLASSIFY_H
#define NDPI_CLASSIFY_H
#include <stdint.h>
#include <sys/time.h>
/* constants */
#define NUM_PARAMETERS_SPLT_LOGREG 208
+2 -1
View File
@@ -1,7 +1,7 @@
/*
* ndpi_main.h
*
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
@@ -114,6 +114,7 @@ extern "C" {
extern int ndpi_parse_ip_string(const char *ip_str, ndpi_ip_addr_t *parsed_ip);
extern char *ndpi_get_ip_string(const ndpi_ip_addr_t * ip, char *buf, u_int buf_len);
extern u_int8_t ndpi_is_ipv6(const ndpi_ip_addr_t *ip);
extern char* ndpi_get_proto_by_id(struct ndpi_detection_module_struct *ndpi_mod, u_int id);
u_int16_t ndpi_get_proto_by_name(struct ndpi_detection_module_struct *ndpi_mod, const char *name);
+21 -17
View File
@@ -1,8 +1,7 @@
/*
* ndpi_protocol_ids.h
*
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
@@ -23,12 +22,8 @@
*/
#ifndef __NDPI_API_H__
#endif
#ifndef __NDPI_PROTOCOLS_DEFAULT_H__
#define __NDPI_PROTOCOLS_DEFAULT_H__
#ifndef __NDPI_PROTOCOLS_IDS_H__
#define __NDPI_PROTOCOLS_IDS_H__
#define NDPI_DETECTION_SUPPORT_IPV6
#define NDPI_PROTOCOL_SIZE 2
@@ -75,12 +70,12 @@ typedef enum {
NDPI_PROTOCOL_SKYPE_CALL = 38, /* Skype call and videocalls */
NDPI_PROTOCOL_SIGNAL = 39,
NDPI_PROTOCOL_MEMCACHED = 40, /* Memcached - Darryl Sokoloski <darryl@egloo.ca> */
NDPI_PROTOCOL_SMBV23 = 41, /* SMB version 2/3 */
NDPI_PROTOCOL_SMBV23 = 41, /* SMB version 2/3 */
NDPI_PROTOCOL_MINING = 42, /* Bitcoin, Ethereum, ZCash, Monero */
NDPI_PROTOCOL_NEST_LOG_SINK = 43, /* Nest Log Sink (Nest Protect) - Darryl Sokoloski <darryl@egloo.ca> */
NDPI_PROTOCOL_MODBUS = 44, /* Modbus */
NDPI_PROTOCOL_WHATSAPP_CALL = 45, /* WhatsApp video ad audio calls go here */
NDPI_PROTOCOL_DATASAVER = 46, /* Protocols used to save data on Internet communications */
NDPI_PROTOCOL_DATASAVER = 46, /* Protocols used to save data on Internet communications */
NDPI_PROTOCOL_XBOX = 47,
NDPI_PROTOCOL_QQ = 48,
NDPI_PROTOCOL_TIKTOK = 49,
@@ -230,16 +225,16 @@ typedef enum {
NDPI_PROTOCOL_KAKAOTALK = 193, /* KakaoTalk Chat (no voice call) */
NDPI_PROTOCOL_KAKAOTALK_VOICE = 194, /* KakaoTalk Voice */
NDPI_PROTOCOL_TWITCH = 195, /* Edoardo Dominici <edoaramis@gmail.com> */
NDPI_PROTOCOL_DNS_OVER_HTTPS = 196,
NDPI_PROTOCOL_DOH_DOT = 196, /* DoH (DNS over HTTPS), DoT (DNS over TLS) */
NDPI_PROTOCOL_WECHAT = 197,
NDPI_PROTOCOL_MPEGTS = 198,
NDPI_PROTOCOL_SNAPCHAT = 199,
NDPI_PROTOCOL_SINA = 200,
NDPI_PROTOCOL_HANGOUT_DUO = 201, /* Google Hangout ad Duo (merged as they are very similar) */
NDPI_PROTOCOL_HANGOUT_DUO = 201, /* Google Hangout ad Duo (merged as they are very similar) */
NDPI_PROTOCOL_IFLIX = 202, /* www.vizuamatix.com R&D team & M.Mallawaarachchie <manoj_ws@yahoo.com> */
NDPI_PROTOCOL_GITHUB = 203,
NDPI_PROTOCOL_BJNP = 204,
NDPI_PROTOCOL_LINE = 205, /* https://en.wikipedia.org/wiki/Line_(software) */
NDPI_PROTOCOL_FREE_205 = 205,
NDPI_PROTOCOL_WIREGUARD = 206,
NDPI_PROTOCOL_SMPP = 207, /* Damir Franusic <df@release14.org> */
NDPI_PROTOCOL_DNSCRYPT = 208,
@@ -279,14 +274,22 @@ typedef enum {
NDPI_PROTOCOL_WHATSAPP_FILES = 242, /* Videos, pictures, voice messages... */
NDPI_PROTOCOL_TARGUS_GETDATA = 243,
NDPI_PROTOCOL_DNP3 = 244,
NDPI_PROTOCOL_104 = 245,
/*
NDPI_PROTOCOL_IEC60870 = 245, /* https://en.wikipedia.org/wiki/IEC_60870-5 */
NDPI_PROTOCOL_BLOOMBERG = 246,
NDPI_PROTOCOL_CAPWAP = 247,
NDPI_PROTOCOL_ZABBIX = 248,
#ifdef CUSTOM_NDPI_PROTOCOLS
#include "../../../nDPI-custom/custom_ndpi_protocol_ids.h"
#endif
/*
IMPORTANT
before allocating a new identifier please fill up
one of those named NDPI_PROTOCOL_FREE_XXX and not used
(placeholders to avoid protocol renumbering)
*/
/* IMPORTANT:NDPI_LAST_IMPLEMENTED_PROTOCOL MUST BE THE LAST ELEMENT */
NDPI_LAST_IMPLEMENTED_PROTOCOL
} ndpi_protocol_id_t;
@@ -294,4 +297,5 @@ typedef enum {
#define NDPI_PROTOCOL_NO_MASTER_PROTO NDPI_PROTOCOL_UNKNOWN
#define NDPI_MAX_SUPPORTED_PROTOCOLS NDPI_LAST_IMPLEMENTED_PROTOCOL
#define NDPI_MAX_NUM_CUSTOM_PROTOCOLS (NDPI_NUM_BITS-NDPI_LAST_IMPLEMENTED_PROTOCOL)
#endif
#endif /* __NDPI_PROTOCOL_IDS_H__ */
+3 -161
View File
@@ -1,7 +1,7 @@
/*
* ndpi_protocols.h
*
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
@@ -51,165 +51,6 @@ u_int ndpi_search_tcp_or_udp_raw(struct ndpi_detection_module_struct *ndpi_struc
void ndpi_search_tcp_or_udp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
/* Applications and other protocols. */
void ndpi_search_diameter(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_lisp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_edonkey(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_fasttrack_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_directconnect(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_applejuice_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_i23v5(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_socrates(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_soulseek_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_msn(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_yahoo(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_oscar(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_sip(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_imo(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_direct_download_link_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_mail_pop_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_mail_imap_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_mail_smtp_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_http_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_http_subprotocol_conf(struct ndpi_detection_module_struct *ndpi_struct, char *attr, char *value, int protocol_id);
void ndpi_search_ftp_control(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_ftp_data(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_usenet_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_rtsp_tcp_udp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_filetopia_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_vmware(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_ssl_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_mms_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_icecast_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_shoutcast_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_veohtv_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_openft_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_stun(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_tvants_udp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_sopcast(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_tvuplayer(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_ppstream(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_pplive(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_iax(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_mgcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_zattoo(struct ndpi_detection_module_struct*ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_qq(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_feidian(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_ssh_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_ayiya(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_thunder(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_activesync(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_in_non_tcp_udp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_vnc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_dhcp_udp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_steam(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_halflife2(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_xbox(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_smb_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_telnet_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_ntp_udp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_nfs(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_rtp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_ssdp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_worldofwarcraft(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_postgres_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_mysql_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_bgp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_quake(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_battlefield(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_secondlife(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_pcanywhere(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_rdp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_snmp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_kontiki(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_syslog(struct ndpi_detection_module_struct*ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_mdns(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_ipp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_ldap(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_warcraft3(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_kerberos(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_xdmcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_tftp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_mssql_tds(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_pptp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_stealthnet(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_dhcpv6_udp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_afp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_checkmk(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_aimini(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_florensia(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_maplestory(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_dofus(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_world_of_kung_fu(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_fiesta(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_crossfire_tcp_udp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_guildwars_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_armagetron_udp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_dropbox(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_citrix(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_dcerpc(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_netflow(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_sflow(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_radius(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_wsus(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_teamview(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_lotus_notes(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_gtp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_spotify(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_h323(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_openvpn(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_noe(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_ciscovpn(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_viber(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_teamspeak(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_corba(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_collectd(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_oracle(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_rsync(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_rtcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_skinny(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_tor(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_whois_das(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_socks5(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_socks4(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_rtmp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_pando(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_megaco(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_redis(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_zmq(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_vhua(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_telegram(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_quic(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_eaq(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_kakaotalk_voice(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_mpegts(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_starcraft(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_ubntac2(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_coap(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_mqtt (struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_someip (struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_rx(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_git(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_drda(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_bjnp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_smpp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_tinc(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_fix(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_csgo(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_ajp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_memcached(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_nest_log_sink(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_wireguard(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_targus_getdata(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_apple_push(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_amazon_video(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
/* --- INIT FUNCTIONS --- */
void init_diameter_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_afp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_aimini_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
@@ -369,7 +210,8 @@ void init_memcached_dissector(struct ndpi_detection_module_struct *ndpi_struct,
void init_nest_log_sink_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_ookla_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_modbus_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_line_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_capwap_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_zabbix_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_wireguard_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_targus_getdata_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_dnp3_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
+98 -26
View File
@@ -1,7 +1,7 @@
/*
* ndpi_typedefs.h
*
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
@@ -35,6 +35,28 @@ typedef enum {
NDPI_LOG_DEBUG_EXTRA
} ndpi_log_level_t;
typedef enum {
ndpi_l4_proto_unknown = 0,
ndpi_l4_proto_tcp_only,
ndpi_l4_proto_udp_only,
ndpi_l4_proto_tcp_and_udp,
} ndpi_l4_proto_info;
typedef enum {
ndpi_no_tunnel = 0,
ndpi_gtp_tunnel,
ndpi_capwap_tunnel,
ndpi_tzsp_tunnel,
ndpi_l2tp_tunnel,
} ndpi_packet_tunnel;
typedef enum {
ndpi_url_no_problem = 0,
ndpi_url_possible_xss,
ndpi_url_possible_sql_injection,
ndpi_url_possible_rce_injection
} ndpi_url_risk;
/* NDPI_VISIT */
typedef enum {
ndpi_preorder,
@@ -616,17 +638,19 @@ struct ndpi_flow_tcp_struct {
/* NDPI_PROTOCOL_TELNET */
u_int32_t telnet_stage:2; // 0 - 2
void* tls_srv_cert_fingerprint_ctx;
struct {
struct {
u_int8_t *buffer;
u_int buffer_len, buffer_used;
} message;
void* srv_cert_fingerprint_ctx; /* SHA-1 */
/* NDPI_PROTOCOL_TLS */
u_int8_t tls_seen_client_cert:1,
tls_seen_server_cert:1,
tls_seen_certificate:1,
tls_srv_cert_fingerprint_found:1,
tls_srv_cert_fingerprint_processed:1,
tls_stage:2, _pad:1; // 0 - 5
int16_t tls_record_offset, tls_fingerprint_len; /* Need to be signed */
u_int8_t tls_sha1_certificate_fingerprint[20];
/* NDPI_PROTOCOL_TLS */
u_int8_t hello_processed:1, certificate_processed:1, subprotocol_detected:1,
fingerprint_set:1, _pad:4;
u_int8_t sha1_certificate_fingerprint[20];
} tls;
/* NDPI_PROTOCOL_POSTGRES */
u_int32_t postgres_stage:3;
@@ -919,10 +943,7 @@ typedef enum {
} ndpi_protocol_category_t;
typedef enum {
ndpi_pref_http_dont_dissect_response = 0,
ndpi_pref_dns_dont_dissect_response,
ndpi_pref_direction_detect_disable,
ndpi_pref_disable_metadata_export,
ndpi_pref_direction_detect_disable = 0,
} ndpi_detection_preference;
/* ntop extensions */
@@ -982,6 +1003,15 @@ struct hs {
};
#endif
#ifdef HAVE_PCRE
#include <pcre.h>
struct pcre_struct {
pcre *compiled;
pcre_extra *optimized;
};
#endif
struct ndpi_detection_module_struct {
NDPI_PROTOCOL_BITMASK detection_bitmask;
NDPI_PROTOCOL_BITMASK generic_http_packet_bitmask;
@@ -1038,7 +1068,8 @@ struct ndpi_detection_module_struct {
content_automa, /* Used for HTTP subprotocol_detection */
subprotocol_automa, /* Used for HTTP subprotocol_detection */
bigrams_automa, impossible_bigrams_automa; /* TOR */
/* IMPORTANT: please update ndpi_finalize_initalization() whenever you add a new automa */
struct {
#ifdef HAVE_HYPERSCAN
struct hs *hostnames;
@@ -1098,10 +1129,8 @@ struct ndpi_detection_module_struct {
ndpi_proto_defaults_t proto_defaults[NDPI_MAX_SUPPORTED_PROTOCOLS+NDPI_MAX_NUM_CUSTOM_PROTOCOLS];
u_int8_t http_dont_dissect_response:1, dns_dont_dissect_response:1,
direction_detect_disable:1, /* disable internal detection of packet direction */
disable_metadata_export:1 /* No metadata is exported */
;
u_int8_t direction_detect_disable:1, /* disable internal detection of packet direction */
_pad:7;
void *hyperscan; /* Intel Hyperscan */
};
@@ -1123,7 +1152,8 @@ struct ndpi_flow_struct {
/* init parameter, internal used to set up timestamp,... */
u_int16_t guessed_protocol_id, guessed_host_protocol_id, guessed_category, guessed_header_category;
u_int8_t l4_proto, protocol_id_already_guessed:1, host_already_guessed:1, init_finished:1, setup_packet_direction:1, packet_direction:1, check_extra_packets:1;
u_int8_t l4_proto, protocol_id_already_guessed:1, host_already_guessed:1,
init_finished:1, setup_packet_direction:1, packet_direction:1, check_extra_packets:1;
/*
if ndpi_struct->direction_detect_disable == 1
@@ -1146,13 +1176,16 @@ struct ndpi_flow_struct {
struct ndpi_flow_udp_struct udp;
} l4;
/* Place textual flow info here */
char flow_extra_info[16];
/*
Pointer to src or dst that identifies the
server of this connection
*/
struct ndpi_id_struct *server_id;
/* HTTP host or DNS query */
u_char host_server_name[256];
u_char host_server_name[240];
/*
This structure below will not not stay inside the protos
@@ -1163,12 +1196,22 @@ struct ndpi_flow_struct {
*/
struct {
ndpi_http_method method;
char *url, *content_type;
char *url, *content_type, *user_agent;
u_int8_t num_request_headers, num_response_headers;
u_int8_t request_version; /* 0=1.0 and 1=1.1. Create an enum for this? */
u_int16_t response_status_code; /* 200, 404, etc. */
} http;
/*
Put outside of the union to avoid issues in case the protocol
is remapped to somethign pther than Kerberos due to a faulty
dissector
*/
struct {
char *pktbuf;
u_int16_t pktbuf_maxlen, pktbuf_currlen;
} kerberos_buf;
union {
/* the only fields useful for nDPI and ntopng */
struct {
@@ -1182,10 +1225,15 @@ struct ndpi_flow_struct {
u_int8_t version;
} ntp;
struct {
char hostname[48], domain[48], username[48];
} kerberos;
struct {
struct {
u_int16_t ssl_version;
char client_certificate[64], server_certificate[64], server_organization[64];
u_int16_t ssl_version, server_names_len;
char client_requested_server_name[64], *server_names, server_organization[64],
*alpn, *tls_supported_versions;
u_int32_t notBefore, notAfter;
char ja3_client[33], ja3_server[33];
u_int16_t server_cipher;
@@ -1208,6 +1256,14 @@ struct ndpi_flow_struct {
u_int8_t last_one_byte_pkt, last_byte;
} imo;
struct {
u_int8_t username_detected:1, username_found:1,
password_detected:1, password_found:1,
_pad:4;
u_int8_t character_id;
char username[32], password[32];
} telnet;
struct {
char answer[96];
} mdns;
@@ -1223,6 +1279,11 @@ struct ndpi_flow_struct {
u_char nat_ip[24];
} http;
struct {
u_int8_t auth_found:1, auth_failed:1, _pad:5;
char username[16], password[16];
} ftp_imap_pop_smtp;
struct {
/* Bittorrent hash */
u_char hash[20];
@@ -1258,7 +1319,6 @@ struct ndpi_flow_struct {
/* NDPI_PROTOCOL_HTTP */
u_int8_t http_detected:1;
u_int16_t http_upper_protocol, http_lower_protocol;
/* NDPI_PROTOCOL_RTSP */
u_int8_t rtsprdt_stage:2, rtsp_control_flow:1;
@@ -1345,6 +1405,14 @@ typedef struct {
u_int8_t value;
} ndpi_network;
typedef u_int32_t ndpi_init_prefs;
typedef enum
{
ndpi_no_prefs = 0,
ndpi_dont_load_tor_hosts,
} ndpi_prefs;
typedef struct {
int protocol_id;
ndpi_protocol_category_t protocol_category;
@@ -1427,4 +1495,8 @@ struct ndpi_analyze_struct {
#define MAX_SERIES_LEN 512
#define MIN_SERIES_LEN 8
/* **************************************** */
typedef struct ndpi_ptree ndpi_ptree_t;
#endif /* __NDPI_TYPEDEFS_H__ */
+4 -1
View File
@@ -75,6 +75,9 @@ typedef unsigned __int64 u_int64_t;
extern unsigned long waitForNextEvent(unsigned long ulDelay /* ms */);
#define sleep(a /* sec */) waitForNextEvent(1000*a /* ms */)
#define sleep(a /* sec */) waitForNextEvent(1000*a /* ms */)
#define localtime_r(a, b) localtime_s(b, a)
#define strtok_r strtok_s
#define timegm _mkgmtime
#endif /* __NDPI_WIN32_H__ */
+5 -4
View File
@@ -14,7 +14,8 @@ prefix = @prefix@
libdir = ${prefix}/lib
includedir = ${prefix}/include/ndpi
CC = @CC@
CFLAGS += -fPIC -DPIC -I../include -Ithird_party/include -DNDPI_LIB_COMPILATION -O2 -g -Wall
CFLAGS += -fPIC -DPIC -I../include -Ithird_party/include -DNDPI_LIB_COMPILATION -Wall @CFLAGS@ @CUSTOM_NDPI@
LDFLAGS = @LDFLAGS@
RANLIB = ranlib
OBJECTS = $(patsubst protocols/%.c, protocols/%.o, $(wildcard protocols/*.c)) $(patsubst third_party/src/%.c, third_party/src/%.o, $(wildcard third_party/src/*.c)) $(patsubst ./%.c, ./%.o, $(wildcard ./*.c))
@@ -42,15 +43,15 @@ ndpi_main.c: ndpi_content_match.c.inc
$(NDPI_LIB_STATIC): $(OBJECTS)
ar rc $@ $(OBJECTS)
$(RANLIB) $@
$(RANLIB) $@
$(NDPI_LIB_SHARED): $(OBJECTS)
$(CC) -shared -fPIC $(SONAME_FLAG) -o $@ $(OBJECTS)
$(CC) -shared -fPIC $(SONAME_FLAG) -o $@ $(OBJECTS) $(LDFLAGS) @ADDITIONAL_LIBS@
ln -fs $(NDPI_LIB_SHARED) $(NDPI_LIB_SHARED_BASE)
ln -fs $(NDPI_LIB_SHARED) $(NDPI_LIB_SHARED_BASE).$(NDPI_VERSION_MAJOR)
%.o: %.c $(HEADERS) Makefile
$(CC) $(CFLAGS) -c $< -o $@
$(CC) $(CFLAGS) -c $< -o $@ $(LDFLAGS)
clean:
/bin/rm -f $(NDPI_LIB_STATIC) $(OBJECTS) *.o *.so *.lo $(NDPI_LIB_SHARED)
+450 -449
View File
File diff suppressed because it is too large Load Diff
+376
View File
@@ -0,0 +1,376 @@
/*
* ndpi_community_id.c
*
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
*
* nDPI is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* nDPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with nDPI. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifdef HAVE_CONFIG_H
#include "ndpi_config.h"
#endif
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include "ndpi_api.h"
#include "ndpi_config.h"
#include <time.h>
#ifndef WIN32
#include <unistd.h>
#endif
#if defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__
#include <sys/endian.h>
#endif
#include "ndpi_sha1.h"
#define NDPI_ICMP6_ECHO_REQUEST 128
#define NDPI_ICMP6_ECHO_REPLY 129
#define NDPI_MLD_LISTENER_QUERY 130
#define NDPI_MLD_LISTENER_REPORT 131
#define NDPI_ROUTER_SOLICIT 133
#define NDPI_ROUTER_ADVERT 134
#define NDPI_NEIGHBOR_SOLICIT 135
#define NDPI_NEIGHBOR_ADVERT 136
#define NDPI_ICMP_ECHOREPLY 0
#define NDPI_ICMP_ECHO 8
#define NDPI_ICMP_ROUTERADVERT 9
#define NDPI_ICMP_ROUTERSOLICIT 10
#define NDPI_ICMP_TIMESTAMP 13
#define NDPI_ICMP_TIMESTAMPREPLY 14
#define NDPI_ICMP_INFO_REQUEST 15
#define NDPI_ICMP_INFO_REPLY 16
#define NDPI_ICMP_MASKREQ 17
#define NDPI_ICMP_MASKREPLY 18
#define NDPI_ICMP6_WRUREQUEST 139
#define NDPI_ICMP6_WRUREPLY 140
/* **************************************************** */
static ssize_t ndpi_community_id_buf_copy(u_int8_t * const dst, const void * const src, ssize_t len) {
if(src)
memcpy(dst, src, len);
else
memset(dst, 0, len);
return len;
}
/* **************************************************** */
/*
https://github.com/corelight/community-id-spec/blob/bda913f617389df07cdaa23606e11bbd318e265c/community-id.py#L56
*/
static u_int8_t ndpi_community_id_icmp_type_to_code_v4(u_int8_t icmp_type, u_int8_t icmp_code, int *is_one_way) {
*is_one_way = 0;
switch(icmp_type) {
case NDPI_ICMP_ECHO:
return NDPI_ICMP_ECHOREPLY;
case NDPI_ICMP_ECHOREPLY:
return NDPI_ICMP_ECHO;
case NDPI_ICMP_TIMESTAMP:
return NDPI_ICMP_TIMESTAMPREPLY;
case NDPI_ICMP_TIMESTAMPREPLY:
return NDPI_ICMP_TIMESTAMP;
case NDPI_ICMP_INFO_REQUEST:
return NDPI_ICMP_INFO_REPLY;
case NDPI_ICMP_INFO_REPLY:
return NDPI_ICMP_INFO_REQUEST;
case NDPI_ICMP_ROUTERSOLICIT:
return NDPI_ICMP_ROUTERADVERT;
case NDPI_ICMP_ROUTERADVERT:
return NDPI_ICMP_ROUTERSOLICIT;
case NDPI_ICMP_MASKREQ:
return NDPI_ICMP_MASKREPLY;
case NDPI_ICMP_MASKREPLY:
return NDPI_ICMP_MASKREQ;
default:
*is_one_way = 1;
return icmp_code;
}
}
/* **************************************************** */
/*
https://github.com/corelight/community-id-spec/blob/bda913f617389df07cdaa23606e11bbd318e265c/community-id.py#L83
*/
static u_int8_t ndpi_community_id_icmp_type_to_code_v6(u_int8_t icmp_type, u_int8_t icmp_code, int *is_one_way) {
*is_one_way = 0;
switch(icmp_type) {
case NDPI_ICMP6_ECHO_REQUEST:
return NDPI_ICMP6_ECHO_REPLY;
case NDPI_ICMP6_ECHO_REPLY:
return NDPI_ICMP6_ECHO_REQUEST;
case NDPI_ROUTER_SOLICIT:
return NDPI_ROUTER_ADVERT;
case NDPI_ROUTER_ADVERT:
return NDPI_ROUTER_SOLICIT;
case NDPI_NEIGHBOR_SOLICIT:
return NDPI_NEIGHBOR_ADVERT;
case NDPI_NEIGHBOR_ADVERT:
return NDPI_NEIGHBOR_SOLICIT;
case NDPI_MLD_LISTENER_QUERY:
return NDPI_MLD_LISTENER_REPORT;
case NDPI_MLD_LISTENER_REPORT:
return NDPI_MLD_LISTENER_QUERY;
case NDPI_ICMP6_WRUREQUEST:
return NDPI_ICMP6_WRUREPLY;
case NDPI_ICMP6_WRUREPLY:
return NDPI_ICMP6_WRUREQUEST;
// Home Agent Address Discovery Request Message and reply
case 144:
return 145;
case 145:
return 144;
default:
*is_one_way = 1;
return icmp_code;
}
}
/* **************************************************** */
/*
https://github.com/corelight/community-id-spec/blob/bda913f617389df07cdaa23606e11bbd318e265c/community-id.py#L164
*/
static int ndpi_community_id_peer_v4_is_less_than(u_int32_t ip1, u_int32_t ip2, u_int16_t p1, u_int16_t p2) {
int comp = memcmp(&ip1, &ip2, sizeof(u_int32_t));
return comp < 0 || (comp == 0 && p1 < p2);
}
/* **************************************************** */
static int ndpi_community_id_peer_v6_is_less_than(struct ndpi_in6_addr *ip1, struct ndpi_in6_addr *ip2, u_int16_t p1, u_int16_t p2) {
int comp = memcmp(ip1, ip2, sizeof(struct ndpi_in6_addr));
return comp < 0 || (comp == 0 && p1 < p2);
}
/* **************************************************** */
static void ndpi_community_id_sha1_hash(const uint8_t *message, size_t len, u_char *hash /* 20-bytes */) {
SHA1_CTX ctx;
SHA1Init(&ctx);
SHA1Update(&ctx, message, len);
SHA1Final(hash, &ctx);
}
/* **************************************************** */
/*
https://github.com/corelight/community-id-spec/blob/bda913f617389df07cdaa23606e11bbd318e265c/community-id.py#L285
*/
static int ndpi_community_id_finalize_and_compute_hash(u_int8_t *comm_buf, u_int16_t off, u_int8_t l4_proto,
u_int16_t src_port, u_int16_t dst_port, char *hash_buf, u_int8_t hash_buf_len) {
u_int8_t pad = 0;
uint32_t hash[5];
char *community_id;
/* L4 proto */
off += ndpi_community_id_buf_copy(&comm_buf[off], &l4_proto, sizeof(l4_proto));
/* Pad */
off += ndpi_community_id_buf_copy(&comm_buf[off], &pad, sizeof(pad));
/* Source and destination ports */
switch(l4_proto) {
case IPPROTO_ICMP:
case IPPROTO_ICMPV6:
case IPPROTO_SCTP:
case IPPROTO_UDP:
case IPPROTO_TCP:
off += ndpi_community_id_buf_copy(&comm_buf[off], &src_port, sizeof(src_port));
off += ndpi_community_id_buf_copy(&comm_buf[off], &dst_port, sizeof(dst_port));
break;
}
/* Compute SHA1 */
ndpi_community_id_sha1_hash(comm_buf, off, (u_char*)hash);
/* Base64 encoding */
community_id = ndpi_base64_encode((u_int8_t*)hash, sizeof(hash));
if (community_id == NULL)
return -1;
#if 0 /* Debug Info */
printf("Hex output: ");
for(int i = 0; i < off; i++)
printf("%.2x ", comm_buf[i]);
printf("\n");
printf("Sha1 sum: ");
for(int i = 0; i < 5; i++)
printf("%.2x ", ntohl(hash[i]));
printf("\n");
printf("Base64: %s\n", community_id);
#endif
if (hash_buf_len < 2 || hash_buf_len-2 < strlen(community_id)+1) {
ndpi_free(community_id);
return -1;
}
/* Writing hash */
hash_buf[0] = '1';
hash_buf[1] = ':';
strcpy(&hash_buf[2], community_id);
ndpi_free(community_id);
return 0;
}
/* **************************************************** */
/*
NOTE:
- Leave fields empty/zero when information is missing (e.g. with ICMP ports are zero)
- The hash_buf most be 30+1 bits or longer
- Return code: 0 = OK, -1 otherwise
*/
int ndpi_flowv4_flow_hash(u_int8_t l4_proto, u_int32_t src_ip, u_int32_t dst_ip,
u_int16_t src_port, u_int16_t dst_port,
u_int8_t icmp_type, u_int8_t icmp_code,
u_char *hash_buf, u_int8_t hash_buf_len) {
/*
Input buffer (40 bytes)
2 - Seed
16 - IPv6 src
16 - IPv6 dst
1 - L4 proto
1 - Pad
2 - Port src
2 - Port dst
*/
u_int8_t comm_buf[40] = { 0 };
u_int16_t off = 0;
u_int16_t seed = 0;
u_int32_t *ip_a_ptr, *ip_b_ptr;
u_int16_t port_a, port_b;
int icmp_one_way = 0;
/* Adjust the ports according to the specs */
switch(l4_proto) {
case IPPROTO_ICMP:
src_port = icmp_type;
dst_port = ndpi_community_id_icmp_type_to_code_v4(icmp_type, icmp_code, &icmp_one_way);
break;
case IPPROTO_SCTP:
case IPPROTO_UDP:
case IPPROTO_TCP:
/* src/dst port ok */
break;
default:
src_port = dst_port = 0;
break;
}
/* Convert tuple to NBO */
src_ip = htonl(src_ip);
dst_ip = htonl(dst_ip);
src_port = htons(src_port);
dst_port = htons(dst_port);
/*
The community id hash doesn't have the definition of client and server, it just sorts IP addresses
and ports to make sure the smaller ip address is the first. This performs this check and
possibly swap client ip and port.
*/
if(icmp_one_way || ndpi_community_id_peer_v4_is_less_than(src_ip, dst_ip, src_port, dst_port)) {
ip_a_ptr = &src_ip, ip_b_ptr = &dst_ip;
port_a = src_port, port_b = dst_port;
} else {
/* swap flow peers */
ip_a_ptr = &dst_ip, ip_b_ptr = &src_ip;
port_a = dst_port, port_b = src_port;
}
/* Seed */
off = ndpi_community_id_buf_copy(&comm_buf[off], &seed, sizeof(seed));
/* Source and destination IPs */
off += ndpi_community_id_buf_copy(&comm_buf[off], ip_a_ptr, sizeof(src_ip));
off += ndpi_community_id_buf_copy(&comm_buf[off], ip_b_ptr, sizeof(dst_ip));
return ndpi_community_id_finalize_and_compute_hash(comm_buf, off,
l4_proto, port_a, port_b, (char*)hash_buf, hash_buf_len);
}
/* **************************************************** */
int ndpi_flowv6_flow_hash(u_int8_t l4_proto, struct ndpi_in6_addr *src_ip, struct ndpi_in6_addr *dst_ip,
u_int16_t src_port, u_int16_t dst_port,
u_int8_t icmp_type, u_int8_t icmp_code,
u_char *hash_buf, u_int8_t hash_buf_len) {
u_int8_t comm_buf[40] = { 0 };
u_int16_t off = 0;
u_int16_t seed = 0;
struct ndpi_in6_addr *ip_a_ptr, *ip_b_ptr;
u_int16_t port_a, port_b;
int icmp_one_way = 0;
switch(l4_proto) {
case IPPROTO_ICMPV6:
src_port = icmp_type;
dst_port = ndpi_community_id_icmp_type_to_code_v6(icmp_type, icmp_code, &icmp_one_way);
break;
case IPPROTO_SCTP:
case IPPROTO_UDP:
case IPPROTO_TCP:
/* src/dst port ok */
break;
default:
src_port = dst_port = 0;
break;
}
/* Convert tuple to NBO */
src_port = htons(src_port);
dst_port = htons(dst_port);
if(icmp_one_way || ndpi_community_id_peer_v6_is_less_than(src_ip, dst_ip, src_port, dst_port)) {
ip_a_ptr = src_ip, ip_b_ptr = dst_ip;
port_a = src_port, port_b = dst_port;
} else {
ip_a_ptr = dst_ip, ip_b_ptr = src_ip;
port_a = dst_port, port_b = src_port;
}
/* Seed */
off = ndpi_community_id_buf_copy(&comm_buf[off], &seed, sizeof(seed));
/* Source and destination IPs */
off += ndpi_community_id_buf_copy(&comm_buf[off], ip_a_ptr, sizeof(struct ndpi_in6_addr));
off += ndpi_community_id_buf_copy(&comm_buf[off], ip_b_ptr, sizeof(struct ndpi_in6_addr));
return ndpi_community_id_finalize_and_compute_hash(comm_buf, off,
l4_proto, port_a, port_b, (char*)hash_buf, hash_buf_len);
}
/* **************************************************** */
File diff suppressed because it is too large Load Diff
+765 -367
View File
File diff suppressed because it is too large Load Diff
+255 -140
View File
@@ -1,7 +1,7 @@
/*
* ndpi_serializer.c
*
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
@@ -45,26 +45,32 @@
static u_int64_t ndpi_htonll(u_int64_t v) {
union { u_int32_t lv[2]; u_int64_t llv; } u;
u.lv[0] = htonl(v >> 32);
u.lv[1] = htonl(v & 0xFFFFFFFFULL);
return u.llv;
return(u.llv);
}
/* ********************************** */
static u_int64_t ndpi_ntohll(u_int64_t v) {
union { u_int32_t lv[2]; u_int64_t llv; } u;
u.llv = v;
return ((u_int64_t)ntohl(u.lv[0]) << 32) | (u_int64_t)ntohl(u.lv[1]);
return((u_int64_t)ntohl(u.lv[0]) << 32) | (u_int64_t)ntohl(u.lv[1]);
}
/* ********************************** */
static int ndpi_is_number(const char *str, u_int32_t str_len) {
int i;
for (i = 0; i < str_len; i++)
if (!isdigit(str[i])) return 0;
return 1;
for(i = 0; i < str_len; i++)
if(!isdigit(str[i])) return(0);
return(1);
}
/* ********************************** */
@@ -80,7 +86,7 @@ static int ndpi_json_string_escape(const char *src, int src_len, char *dst, int
dst[j++] = '"';
for (i = 0; i < src_len && j < dst_max_len; i++) {
for(i = 0; i < src_len && j < dst_max_len; i++) {
c = src[i];
@@ -122,7 +128,7 @@ static int ndpi_json_string_escape(const char *src, int src_len, char *dst, int
dst[j++] = '"';
dst[j+1] = '\0';
return j;
return(j);
}
/* ********************************** */
@@ -178,7 +184,7 @@ int ndpi_init_serializer_ll(ndpi_serializer *_serializer,
int ndpi_init_serializer(ndpi_serializer *_serializer,
ndpi_serialization_format fmt) {
return ndpi_init_serializer_ll(_serializer, fmt, NDPI_SERIALIZER_DEFAULT_BUFFER_SIZE);
return(ndpi_init_serializer_ll(_serializer, fmt, NDPI_SERIALIZER_DEFAULT_BUFFER_SIZE));
}
/* ********************************** */
@@ -194,7 +200,7 @@ char* ndpi_serializer_get_buffer(ndpi_serializer *_serializer, u_int32_t *buffer
*buffer_len = serializer->status.size_used;
if(serializer->fmt == ndpi_serialization_format_json) {
while(buf[0] == '\0')
while((buf[0] == '\0') || (buf[0] == ' '))
buf++, *buffer_len = *buffer_len - 1;
}
@@ -209,6 +215,12 @@ u_int32_t ndpi_serializer_get_buffer_len(ndpi_serializer *_serializer) {
/* ********************************** */
u_int32_t ndpi_serializer_get_internal_buffer_size(ndpi_serializer *_serializer) {
return(((ndpi_private_serializer*)_serializer)->buffer_size);
}
/* ********************************** */
int ndpi_serializer_set_buffer_len(ndpi_serializer *_serializer, u_int32_t l) {
ndpi_private_serializer *p = (ndpi_private_serializer*)_serializer;
@@ -250,9 +262,9 @@ static inline int ndpi_extend_serializer_buffer(ndpi_serializer *_serializer, u_
void *r;
ndpi_private_serializer *serializer = (ndpi_private_serializer*)_serializer;
if (min_len < NDPI_SERIALIZER_DEFAULT_BUFFER_INCR) {
if (serializer->initial_buffer_size < NDPI_SERIALIZER_DEFAULT_BUFFER_INCR) {
if (min_len < serializer->initial_buffer_size)
if(min_len < NDPI_SERIALIZER_DEFAULT_BUFFER_INCR) {
if(serializer->initial_buffer_size < NDPI_SERIALIZER_DEFAULT_BUFFER_INCR) {
if(min_len < serializer->initial_buffer_size)
min_len = serializer->initial_buffer_size;
} else {
min_len = NDPI_SERIALIZER_DEFAULT_BUFFER_INCR;
@@ -260,6 +272,7 @@ static inline int ndpi_extend_serializer_buffer(ndpi_serializer *_serializer, u_
}
new_size = serializer->buffer_size + min_len;
new_size = ((new_size / 4) + 1) * 4; /* required by zmq encryption */
r = realloc((void *) serializer->buffer, new_size);
@@ -455,7 +468,7 @@ static inline void ndpi_serialize_json_pre(ndpi_serializer *_serializer) {
serializer->status.size_used--; /* Remove ']'*/
serializer->status.size_used--; /* Remove '}'*/
if (serializer->status.flags & NDPI_SERIALIZER_STATUS_SOB)
if(serializer->status.flags & NDPI_SERIALIZER_STATUS_SOB)
serializer->status.flags &= ~NDPI_SERIALIZER_STATUS_SOB;
else if(serializer->status.flags & NDPI_SERIALIZER_STATUS_COMMA)
serializer->buffer[serializer->status.size_used++] = ',';
@@ -479,10 +492,10 @@ static inline void ndpi_serialize_json_post(ndpi_serializer *_serializer) {
static inline ndpi_serialization_type ndpi_serialize_key_uint32(ndpi_private_serializer *serializer, u_int32_t key) {
ndpi_serialization_type kt;
if (key <= 0xff) {
if(key <= 0xff) {
ndpi_serialize_single_uint8(serializer, key);
kt = ndpi_serialization_uint8;
} else if (key <= 0xffff) {
} else if(key <= 0xffff) {
ndpi_serialize_single_uint16(serializer, key);
kt = ndpi_serialization_uint16;
} else {
@@ -490,7 +503,7 @@ static inline ndpi_serialization_type ndpi_serialize_key_uint32(ndpi_private_ser
kt = ndpi_serialization_uint32;
}
return kt;
return(kt);
}
/* ********************************** */
@@ -529,10 +542,10 @@ int ndpi_serialize_uint32_uint32(ndpi_serializer *_serializer,
kt = ndpi_serialize_key_uint32(serializer, key);
type = (kt << 4);
if (value <= 0xff) {
if(value <= 0xff) {
ndpi_serialize_single_uint8(serializer, value);
type |= ndpi_serialization_uint8;
} else if (value <= 0xffff) {
} else if(value <= 0xffff) {
ndpi_serialize_single_uint16(serializer, value);
type |= ndpi_serialization_uint16;
} else {
@@ -577,7 +590,7 @@ int ndpi_serialize_uint32_uint64(ndpi_serializer *_serializer,
(serializer->status.size_used > 0) ? serializer->csv_separator : "",
(unsigned long long)value);
} else {
if (value <= 0xffffffff) {
if(value <= 0xffffffff) {
return(ndpi_serialize_uint32_uint32(_serializer, key, value));
} else {
ndpi_serialization_type kt;
@@ -633,10 +646,10 @@ int ndpi_serialize_uint32_int32(ndpi_serializer *_serializer,
kt = ndpi_serialize_key_uint32(serializer, key);
type = (kt << 4);
if (value <= 127 && value >= -128) {
if(value <= 127 && value >= -128) {
ndpi_serialize_single_uint8(serializer, value);
type |= ndpi_serialization_int8;
} else if (value <= 32767 && value >= -32768) {
} else if(value <= 32767 && value >= -32768) {
ndpi_serialize_single_uint16(serializer, value);
type |= ndpi_serialization_int16;
} else {
@@ -681,8 +694,9 @@ int ndpi_serialize_uint32_int64(ndpi_serializer *_serializer,
(serializer->status.size_used > 0) ? serializer->csv_separator : "",
(long long int)value);
} else {
if (value <= 2147483647 && value >= -2147483648) {
}
else {
if((value & 0xFFFFFFFF) == value) {
return(ndpi_serialize_uint32_int32(_serializer, key, value));
} else {
ndpi_serialization_type kt;
@@ -805,7 +819,39 @@ static int ndpi_serialize_uint32_binary(ndpi_serializer *_serializer,
int ndpi_serialize_uint32_string(ndpi_serializer *_serializer,
u_int32_t key, const char *_value) {
const char *value = _value ? _value : "";
return ndpi_serialize_uint32_binary(_serializer, key, value, strlen(value));
return(ndpi_serialize_uint32_binary(_serializer, key, value, strlen(value)));
}
/* ********************************** */
int ndpi_serialize_uint32_boolean(ndpi_serializer *_serializer,
u_int32_t key, u_int8_t value) {
ndpi_private_serializer *serializer = (ndpi_private_serializer*)_serializer;
u_int32_t buff_diff = serializer->buffer_size - serializer->status.size_used;
u_int32_t needed = 24;
if(serializer->fmt != ndpi_serialization_format_json &&
serializer->fmt != ndpi_serialization_format_csv)
return -1;
if(buff_diff < needed) {
if(ndpi_extend_serializer_buffer(_serializer, needed - buff_diff) < 0)
return(-1);
buff_diff = serializer->buffer_size - serializer->status.size_used;
}
if(serializer->fmt == ndpi_serialization_format_json) {
ndpi_serialize_json_pre(_serializer);
serializer->status.size_used += snprintf((char *) &serializer->buffer[serializer->status.size_used], buff_diff,
"\"%u\":%s", key, value ? "true" : "false");
ndpi_serialize_json_post(_serializer);
} else if(serializer->fmt == ndpi_serialization_format_csv) {
serializer->status.size_used += snprintf((char *) &serializer->buffer[serializer->status.size_used], buff_diff,
"%s%s", (serializer->status.size_used > 0) ? serializer->csv_separator : "",
value ? "true" : "false");
}
return(0);
}
/* ********************************** */
@@ -817,8 +863,8 @@ static int ndpi_serialize_binary_int32(ndpi_serializer *_serializer,
u_int32_t buff_diff = serializer->buffer_size - serializer->status.size_used;
u_int32_t needed;
if (ndpi_is_number(key, klen))
return ndpi_serialize_uint32_int32(_serializer, atoi(key), value);
if(ndpi_is_number(key, klen))
return(ndpi_serialize_uint32_int32(_serializer, atoi(key), value));
needed =
sizeof(u_int8_t) /* type */ +
@@ -847,11 +893,11 @@ static int ndpi_serialize_binary_int32(ndpi_serializer *_serializer,
serializer->status.size_used += snprintf((char *) &serializer->buffer[serializer->status.size_used], buff_diff,
"%s%d", (serializer->status.size_used > 0) ? serializer->csv_separator : "", value);
} else {
if (value <= 127 && value >= -128) {
if(value <= 127 && value >= -128) {
serializer->buffer[serializer->status.size_used++] = (ndpi_serialization_string << 4) | ndpi_serialization_int8;
ndpi_serialize_single_string(serializer, key, klen);
ndpi_serialize_single_uint8(serializer, value);
} else if (value <= 32767 && value >= -32768) {
} else if(value <= 32767 && value >= -32768) {
serializer->buffer[serializer->status.size_used++] = (ndpi_serialization_string << 4) | ndpi_serialization_int16;
ndpi_serialize_single_string(serializer, key, klen);
ndpi_serialize_single_uint16(serializer, value);
@@ -869,7 +915,7 @@ static int ndpi_serialize_binary_int32(ndpi_serializer *_serializer,
int ndpi_serialize_string_int32(ndpi_serializer *_serializer,
const char *key, int32_t value) {
return ndpi_serialize_binary_int32(_serializer, key, strlen(key), value);
return(ndpi_serialize_binary_int32(_serializer, key, strlen(key), value));
}
/* ********************************** */
@@ -881,8 +927,8 @@ int ndpi_serialize_binary_int64(ndpi_serializer *_serializer,
u_int32_t buff_diff = serializer->buffer_size - serializer->status.size_used;
u_int32_t needed;
if (ndpi_is_number(key, klen))
return ndpi_serialize_uint32_int64(_serializer, atoi(key), value);
if(ndpi_is_number(key, klen))
return(ndpi_serialize_uint32_int64(_serializer, atoi(key), value));
needed =
sizeof(u_int8_t) /* type */ +
@@ -912,7 +958,7 @@ int ndpi_serialize_binary_int64(ndpi_serializer *_serializer,
"%s%lld", (serializer->status.size_used > 0) ? serializer->csv_separator : "",
(long long int)value);
} else {
if (value <= 2147483647 && value >= -2147483648) {
if ((value & 0xFFFFFFFF) == value) {
return(ndpi_serialize_string_int32(_serializer, key, value));
} else {
serializer->buffer[serializer->status.size_used++] = (ndpi_serialization_string << 4) | ndpi_serialization_int64;
@@ -928,7 +974,7 @@ int ndpi_serialize_binary_int64(ndpi_serializer *_serializer,
int ndpi_serialize_string_int64(ndpi_serializer *_serializer,
const char *key, int64_t value) {
return ndpi_serialize_binary_int64(_serializer, key, strlen(key), value);
return(ndpi_serialize_binary_int64(_serializer, key, strlen(key), value));
}
/* ********************************** */
@@ -939,8 +985,8 @@ static int ndpi_serialize_binary_uint32(ndpi_serializer *_serializer,
u_int32_t buff_diff = serializer->buffer_size - serializer->status.size_used;
u_int32_t needed;
if (ndpi_is_number(key, klen))
return ndpi_serialize_uint32_uint32(_serializer, atoi(key), value);
if(ndpi_is_number(key, klen))
return(ndpi_serialize_uint32_uint32(_serializer, atoi(key), value));
needed =
sizeof(u_int8_t) /* type */ +
@@ -969,11 +1015,11 @@ static int ndpi_serialize_binary_uint32(ndpi_serializer *_serializer,
serializer->status.size_used += snprintf((char *) &serializer->buffer[serializer->status.size_used], buff_diff,
"%s%u", (serializer->status.size_used > 0) ? serializer->csv_separator : "", value);
} else {
if (value <= 0xff) {
if(value <= 0xff) {
serializer->buffer[serializer->status.size_used++] = (ndpi_serialization_string << 4) | ndpi_serialization_uint8;
ndpi_serialize_single_string(serializer, key, klen);
ndpi_serialize_single_uint8(serializer, value);
} else if (value <= 0xffff) {
} else if(value <= 0xffff) {
serializer->buffer[serializer->status.size_used++] = (ndpi_serialization_string << 4) | ndpi_serialization_uint16;
ndpi_serialize_single_string(serializer, key, klen);
ndpi_serialize_single_uint16(serializer, value);
@@ -991,7 +1037,7 @@ static int ndpi_serialize_binary_uint32(ndpi_serializer *_serializer,
int ndpi_serialize_string_uint32(ndpi_serializer *_serializer,
const char *key, u_int32_t value) {
return ndpi_serialize_binary_uint32(_serializer, key, strlen(key), value);
return(ndpi_serialize_binary_uint32(_serializer, key, strlen(key), value));
}
/* ********************************** */
@@ -1021,8 +1067,8 @@ static int ndpi_serialize_binary_uint64(ndpi_serializer *_serializer,
u_int32_t buff_diff = serializer->buffer_size - serializer->status.size_used;
u_int32_t needed;
if (ndpi_is_number(key, klen))
return ndpi_serialize_uint32_uint64(_serializer, atoi(key), value);
if(ndpi_is_number(key, klen))
return(ndpi_serialize_uint32_uint64(_serializer, atoi(key), value));
needed =
sizeof(u_int8_t) /* type */ +
@@ -1052,7 +1098,7 @@ static int ndpi_serialize_binary_uint64(ndpi_serializer *_serializer,
"%s%llu", (serializer->status.size_used > 0) ? serializer->csv_separator : "",
(unsigned long long)value);
} else {
if (value <= 0xffffffff) {
if(value <= 0xffffffff) {
return(ndpi_serialize_string_uint32(_serializer, key, value));
} else {
serializer->buffer[serializer->status.size_used++] = (ndpi_serialization_string << 4) | ndpi_serialization_uint64;
@@ -1068,7 +1114,7 @@ static int ndpi_serialize_binary_uint64(ndpi_serializer *_serializer,
int ndpi_serialize_string_uint64(ndpi_serializer *_serializer,
const char *key, u_int64_t value) {
return ndpi_serialize_binary_uint64(_serializer, key, strlen(key), value);
return(ndpi_serialize_binary_uint64(_serializer, key, strlen(key), value));
}
/* ********************************** */
@@ -1082,8 +1128,8 @@ static int ndpi_serialize_binary_float(ndpi_serializer *_serializer,
u_int32_t buff_diff = serializer->buffer_size - serializer->status.size_used;
u_int32_t needed;
if (ndpi_is_number(key, klen))
return ndpi_serialize_uint32_float(_serializer, atoi(key), value, format);
if(ndpi_is_number(key, klen))
return(ndpi_serialize_uint32_float(_serializer, atoi(key), value, format));
needed =
sizeof(u_int8_t) /* type */ +
@@ -1133,24 +1179,22 @@ int ndpi_serialize_string_float(ndpi_serializer *_serializer,
const char *key,
float value,
const char *format /* e.f. "%.2f" */) {
return ndpi_serialize_binary_float(_serializer, key, strlen(key), value, format);
return(ndpi_serialize_binary_float(_serializer, key, strlen(key), value, format));
}
/* ********************************** */
static int ndpi_serialize_binary_binary(ndpi_serializer *_serializer,
/* Key is a <string, len> pair, value is a raw value */
static int ndpi_serialize_binary_raw(ndpi_serializer *_serializer,
const char *key,
u_int16_t klen,
const char *_value,
u_int16_t vlen) {
const char *value,
u_int16_t vlen,
u_int8_t escape) {
ndpi_private_serializer *serializer = (ndpi_private_serializer*)_serializer;
const char *value = _value ? _value : "";
u_int32_t buff_diff = serializer->buffer_size - serializer->status.size_used;
u_int32_t needed;
if (ndpi_is_number(key, klen))
return ndpi_serialize_uint32_string(_serializer, atoi(key), _value);
needed =
sizeof(u_int8_t) /* type */ +
sizeof(u_int16_t) /* key len */ +
@@ -1174,9 +1218,13 @@ static int ndpi_serialize_binary_binary(ndpi_serializer *_serializer,
buff_diff = serializer->buffer_size - serializer->status.size_used;
serializer->status.size_used += snprintf((char *) &serializer->buffer[serializer->status.size_used], buff_diff, ":");
buff_diff = serializer->buffer_size - serializer->status.size_used;
serializer->status.size_used += ndpi_json_string_escape(value, vlen,
(char *) &serializer->buffer[serializer->status.size_used], buff_diff);
buff_diff = serializer->buffer_size - serializer->status.size_used;
if (escape)
serializer->status.size_used += ndpi_json_string_escape(value, vlen,
(char *) &serializer->buffer[serializer->status.size_used], buff_diff);
else
serializer->status.size_used += snprintf((char *) &serializer->buffer[serializer->status.size_used], buff_diff,
value, vlen);
ndpi_serialize_json_post(_serializer);
} else if(serializer->fmt == ndpi_serialization_format_csv) {
serializer->status.size_used += snprintf((char *) &serializer->buffer[serializer->status.size_used], buff_diff,
@@ -1194,14 +1242,32 @@ static int ndpi_serialize_binary_binary(ndpi_serializer *_serializer,
/* ********************************** */
int ndpi_serialize_string_binary(ndpi_serializer *_serializer,
const char *key, const char *_value,
u_int16_t vlen) {
return ndpi_serialize_binary_binary(_serializer, key, strlen(key), _value, vlen);
/* Key is a <string, len> pair, value is a <string, len> pair */
static int ndpi_serialize_binary_binary(ndpi_serializer *_serializer,
const char *key,
u_int16_t klen,
const char *_value,
u_int16_t vlen) {
const char *value = _value ? _value : "";
if(ndpi_is_number(key, klen))
return(ndpi_serialize_uint32_binary(_serializer, atoi(key), value, vlen));
return ndpi_serialize_binary_raw(_serializer, key, klen, value, vlen, 1 /* escape */);
}
/* ********************************** */
/* Key is a string, value is a <string, len> pair */
int ndpi_serialize_string_binary(ndpi_serializer *_serializer,
const char *key, const char *_value,
u_int16_t vlen) {
return(ndpi_serialize_binary_binary(_serializer, key, strlen(key), _value, vlen));
}
/* ********************************** */
/* Key is a string, value is a string (strlen is used to compute the len) */
int ndpi_serialize_string_string(ndpi_serializer *_serializer,
const char *key, const char *_value) {
return(ndpi_serialize_binary_binary(_serializer, key, strlen(key), _value, strlen(_value)));
@@ -1209,6 +1275,55 @@ int ndpi_serialize_string_string(ndpi_serializer *_serializer,
/* ********************************** */
/* Key is a string, value is a raw json value (it can be a number, an escaped/quoted string, an array, ..) */
int ndpi_serialize_string_raw(ndpi_serializer *_serializer,
const char *key, const char *_value, u_int16_t vlen) {
return(ndpi_serialize_binary_raw(_serializer, key, strlen(key), _value, vlen, 0 /* do not escape */));
}
/* ********************************** */
int ndpi_serialize_string_boolean(ndpi_serializer *_serializer,
const char *key, u_int8_t value) {
ndpi_private_serializer *serializer = (ndpi_private_serializer*)_serializer;
u_int32_t buff_diff = serializer->buffer_size - serializer->status.size_used;
u_int16_t klen = strlen(key);
u_int32_t needed;
if(serializer->fmt != ndpi_serialization_format_json &&
serializer->fmt != ndpi_serialization_format_csv)
return -1;
if(ndpi_is_number(key, klen))
return(ndpi_serialize_uint32_boolean(_serializer, atoi(key), value));
needed = klen + 16;
if(buff_diff < needed) {
if(ndpi_extend_serializer_buffer(_serializer, needed - buff_diff) < 0)
return(-1);
buff_diff = serializer->buffer_size - serializer->status.size_used;
}
if(serializer->fmt == ndpi_serialization_format_json) {
ndpi_serialize_json_pre(_serializer);
serializer->status.size_used += ndpi_json_string_escape(key, klen,
(char *) &serializer->buffer[serializer->status.size_used], buff_diff);
buff_diff = serializer->buffer_size - serializer->status.size_used;
serializer->status.size_used += snprintf((char *) &serializer->buffer[serializer->status.size_used], buff_diff, ":%s",
value ? "true" : "false");
ndpi_serialize_json_post(_serializer);
} else if(serializer->fmt == ndpi_serialization_format_csv) {
serializer->status.size_used += snprintf((char *) &serializer->buffer[serializer->status.size_used], buff_diff,
"%s%s", (serializer->status.size_used > 0) ? serializer->csv_separator : "",
value ? "true" : "false");
}
return(0);
}
/* ********************************** */
/* Serialize start of nested block (JSON only)*/
int ndpi_serialize_start_of_block(ndpi_serializer *_serializer,
const char *key) {
@@ -1216,13 +1331,13 @@ int ndpi_serialize_start_of_block(ndpi_serializer *_serializer,
u_int32_t buff_diff = serializer->buffer_size - serializer->status.size_used;
u_int32_t needed, klen = strlen(key);
if (serializer->fmt != ndpi_serialization_format_json)
return -1;
if(serializer->fmt != ndpi_serialization_format_json)
return(-1);
needed = 16 + klen;
if (buff_diff < needed) {
if (ndpi_extend_serializer_buffer(_serializer, needed - buff_diff) < 0)
if(buff_diff < needed) {
if(ndpi_extend_serializer_buffer(_serializer, needed - buff_diff) < 0)
return(-1);
buff_diff = serializer->buffer_size - serializer->status.size_used;
}
@@ -1248,18 +1363,18 @@ int ndpi_serialize_end_of_block(ndpi_serializer *_serializer) {
u_int32_t buff_diff = serializer->buffer_size - serializer->status.size_used;
u_int32_t needed;
if (serializer->fmt != ndpi_serialization_format_json)
return -1;
if(serializer->fmt != ndpi_serialization_format_json)
return(-1);
needed = 4;
if (buff_diff < needed) {
if (ndpi_extend_serializer_buffer(_serializer, needed - buff_diff) < 0)
if(buff_diff < needed) {
if(ndpi_extend_serializer_buffer(_serializer, needed - buff_diff) < 0)
return(-1);
buff_diff = serializer->buffer_size - serializer->status.size_used;
}
buff_diff = serializer->buffer_size - serializer->status.size_used;
// buff_diff = serializer->buffer_size - serializer->status.size_used;
ndpi_serialize_json_post(_serializer);
return(0);
@@ -1287,7 +1402,7 @@ void ndpi_serializer_create_snapshot(ndpi_serializer *_serializer) {
void ndpi_serializer_rollback_snapshot(ndpi_serializer *_serializer) {
ndpi_private_serializer *serializer = (ndpi_private_serializer*)_serializer;
if (serializer->has_snapshot) {
if(serializer->has_snapshot) {
memcpy(&serializer->status, &serializer->snapshot, sizeof(ndpi_private_serializer_status));
serializer->has_snapshot = 0;
@@ -1340,7 +1455,7 @@ int ndpi_init_deserializer(ndpi_deserializer *deserializer,
ndpi_serialization_format ndpi_deserialize_get_format(ndpi_deserializer *_deserializer) {
ndpi_private_deserializer *deserializer = (ndpi_private_deserializer*)_deserializer;
return deserializer->fmt;
return(deserializer->fmt);
}
/* ********************************** */
@@ -1348,12 +1463,12 @@ ndpi_serialization_format ndpi_deserialize_get_format(ndpi_deserializer *_deseri
static inline ndpi_serialization_type ndpi_deserialize_get_key_subtype(ndpi_private_deserializer *deserializer) {
u_int8_t type;
if (deserializer->status.size_used >= deserializer->buffer_size)
return ndpi_serialization_unknown;
if(deserializer->status.size_used >= deserializer->buffer_size)
return(ndpi_serialization_unknown);
type = deserializer->buffer[deserializer->status.size_used];
return (ndpi_serialization_type) (type >> 4);
return((ndpi_serialization_type) (type >> 4));
}
/* ********************************** */
@@ -1361,12 +1476,12 @@ static inline ndpi_serialization_type ndpi_deserialize_get_key_subtype(ndpi_priv
static inline ndpi_serialization_type ndpi_deserialize_get_value_subtype(ndpi_private_deserializer *deserializer) {
u_int8_t type;
if (deserializer->status.size_used >= deserializer->buffer_size)
if(deserializer->status.size_used >= deserializer->buffer_size)
return(ndpi_serialization_unknown);
type = deserializer->buffer[deserializer->status.size_used];
return (ndpi_serialization_type) (type & 0xf);
return(ndpi_serialization_type) (type & 0xf);
}
/* ********************************** */
@@ -1404,7 +1519,7 @@ ndpi_serialization_type ndpi_deserialize_get_item_type(ndpi_deserializer *_deser
}
*key_type = kt;
return et;
return(et);
}
/* ********************************** */
@@ -1414,14 +1529,14 @@ static inline int ndpi_deserialize_get_single_string_size(ndpi_private_deseriali
u_int16_t expected, str_len;
expected = sizeof(u_int16_t) /* len */;
if (buff_diff < expected) return -2;
if(buff_diff < expected) return(-2);
str_len = ntohs(*((u_int16_t *) &deserializer->buffer[offset]));
expected += str_len;
if (buff_diff < expected) return -2;
if(buff_diff < expected) return(-2);
return expected;
return(expected);
}
/* ********************************** */
@@ -1457,11 +1572,11 @@ static inline int ndpi_deserialize_get_single_size(ndpi_private_deserializer *de
size = 0;
break;
default:
return -2;
return(-2);
break;
}
return size;
return(size);
}
/* ********************************** */
@@ -1475,25 +1590,25 @@ int ndpi_deserialize_next(ndpi_deserializer *_deserializer) {
expected = sizeof(u_int8_t) /* type */;
if (buff_diff < expected) return -2;
if(buff_diff < expected) return(-2);
kt = ndpi_deserialize_get_key_subtype(deserializer);
size = ndpi_deserialize_get_single_size(deserializer, kt, deserializer->status.size_used + expected);
if (size < 0) return -2;
if(size < 0) return(-2);
expected += size;
et = ndpi_deserialize_get_value_subtype(deserializer);
size = ndpi_deserialize_get_single_size(deserializer, et, deserializer->status.size_used + expected);
if (size < 0) return -2;
if(size < 0) return(-2);
expected += size;
deserializer->status.size_used += expected;
return 0;
return(0);
}
/* ********************************** */
@@ -1509,12 +1624,12 @@ int ndpi_deserialize_key_uint32(ndpi_deserializer *_deserializer,
int size;
expected = sizeof(u_int8_t) /* type */;
if (buff_diff < expected) return -2;
if(buff_diff < expected) return(-2);
kt = ndpi_deserialize_get_key_subtype(deserializer);
size = ndpi_deserialize_get_single_size(deserializer, kt, deserializer->status.size_used + expected);
if (size < 0) return -2;
if(size < 0) return(-2);
offset = deserializer->status.size_used + expected;
@@ -1531,11 +1646,11 @@ int ndpi_deserialize_key_uint32(ndpi_deserializer *_deserializer,
*key = v8;
break;
default:
return -1;
return(-1);
break;
}
return 0;
return(0);
}
/* ********************************** */
@@ -1549,16 +1664,16 @@ int ndpi_deserialize_key_string(ndpi_deserializer *_deserializer,
int size;
expected = sizeof(u_int8_t) /* type */;
if (buff_diff < expected) return -2;
if(buff_diff < expected) return(-2);
kt = ndpi_deserialize_get_key_subtype(deserializer);
size = ndpi_deserialize_get_single_size(deserializer, kt, deserializer->status.size_used + expected);
if (size < 0) return -2;
if(size < 0) return(-2);
ndpi_deserialize_single_string(deserializer, deserializer->status.size_used + expected, key);
return 0;
return(0);
}
/* ********************************** */
@@ -1574,17 +1689,17 @@ int ndpi_deserialize_value_uint32(ndpi_deserializer *_deserializer,
int size;
expected = sizeof(u_int8_t) /* type */;
if (buff_diff < expected) return -2;
if(buff_diff < expected) return(-2);
kt = ndpi_deserialize_get_key_subtype(deserializer);
size = ndpi_deserialize_get_single_size(deserializer, kt, deserializer->status.size_used + expected);
if (size < 0) return -2;
if(size < 0) return(-2);
expected += size;
et = ndpi_deserialize_get_value_subtype(deserializer);
size = ndpi_deserialize_get_single_size(deserializer, et, deserializer->status.size_used + expected);
if (size < 0) return -2;
if(size < 0) return(-2);
offset = deserializer->status.size_used + expected;
@@ -1604,7 +1719,7 @@ int ndpi_deserialize_value_uint32(ndpi_deserializer *_deserializer,
break;
}
return 0;
return(0);
}
/* ********************************** */
@@ -1620,28 +1735,28 @@ int ndpi_deserialize_value_uint64(ndpi_deserializer *_deserializer,
int rc;
expected = sizeof(u_int8_t) /* type */;
if (buff_diff < expected) return -2;
if(buff_diff < expected) return(-2);
kt = ndpi_deserialize_get_key_subtype(deserializer);
size = ndpi_deserialize_get_single_size(deserializer, kt, deserializer->status.size_used + expected);
if (size < 0) return -2;
if(size < 0) return(-2);
expected += size;
et = ndpi_deserialize_get_value_subtype(deserializer);
size = ndpi_deserialize_get_single_size(deserializer, et, deserializer->status.size_used + expected);
if (size < 0) return -2;
if(size < 0) return(-2);
if(et != ndpi_serialization_uint64) {
/* Try with smaller uint types */
rc = ndpi_deserialize_value_uint32(_deserializer, &v32);
*value = v32;
return rc;
return(rc);
}
ndpi_deserialize_single_uint64(deserializer, deserializer->status.size_used + expected, value);
return 0;
return(0);
}
/* ********************************** */
@@ -1657,17 +1772,17 @@ int ndpi_deserialize_value_int32(ndpi_deserializer *_deserializer,
int size;
expected = sizeof(u_int8_t) /* type */;
if (buff_diff < expected) return -2;
if(buff_diff < expected) return(-2);
kt = ndpi_deserialize_get_key_subtype(deserializer);
size = ndpi_deserialize_get_single_size(deserializer, kt, deserializer->status.size_used + expected);
if (size < 0) return -2;
if(size < 0) return(-2);
expected += size;
et = ndpi_deserialize_get_value_subtype(deserializer);
size = ndpi_deserialize_get_single_size(deserializer, et, deserializer->status.size_used + expected);
if (size < 0) return -2;
if(size < 0) return(-2);
offset = deserializer->status.size_used + expected;
@@ -1687,7 +1802,7 @@ int ndpi_deserialize_value_int32(ndpi_deserializer *_deserializer,
break;
}
return 0;
return(0);
}
/* ********************************** */
@@ -1703,28 +1818,28 @@ int ndpi_deserialize_value_int64(ndpi_deserializer *_deserializer,
int rc;
expected = sizeof(u_int8_t) /* type */;
if (buff_diff < expected) return(-2);
if(buff_diff < expected) return(-2);
kt = ndpi_deserialize_get_key_subtype(deserializer);
size = ndpi_deserialize_get_single_size(deserializer, kt, deserializer->status.size_used + expected);
if (size < 0) return -2;
if(size < 0) return(-2);
expected += size;
et = ndpi_deserialize_get_value_subtype(deserializer);
size = ndpi_deserialize_get_single_size(deserializer, et, deserializer->status.size_used + expected);
if (size < 0) return -2;
if(size < 0) return(-2);
if(et != ndpi_serialization_int64) {
/* Try with smaller int types */
rc = ndpi_deserialize_value_int32(_deserializer, &v32);
*value = v32;
return rc;
return(rc);
}
ndpi_deserialize_single_int64(deserializer, deserializer->status.size_used + expected, value);
return 0;
return(0);
}
/* ********************************** */
@@ -1738,24 +1853,24 @@ int ndpi_deserialize_value_float(ndpi_deserializer *_deserializer,
int size;
expected = sizeof(u_int8_t) /* type */;
if (buff_diff < expected) return(-2);
if(buff_diff < expected) return(-2);
kt = ndpi_deserialize_get_key_subtype(deserializer);
size = ndpi_deserialize_get_single_size(deserializer, kt, deserializer->status.size_used + expected);
if (size < 0) return -2;
if(size < 0) return(-2);
expected += size;
et = ndpi_deserialize_get_value_subtype(deserializer);
size = ndpi_deserialize_get_single_size(deserializer, et, deserializer->status.size_used + expected);
if (size < 0) return -2;
if(size < 0) return(-2);
if(et != ndpi_serialization_float)
return -1;
return(-1);
ndpi_deserialize_single_float(deserializer, deserializer->status.size_used + expected, value);
return 0;
return(0);
}
/* ********************************** */
@@ -1769,24 +1884,24 @@ int ndpi_deserialize_value_string(ndpi_deserializer *_deserializer,
int size;
expected = sizeof(u_int8_t) /* type */;
if (buff_diff < expected) return(-2);
if(buff_diff < expected) return(-2);
kt = ndpi_deserialize_get_key_subtype(deserializer);
size = ndpi_deserialize_get_single_size(deserializer, kt, deserializer->status.size_used + expected);
if (size < 0) return -2;
if(size < 0) return(-2);
expected += size;
et = ndpi_deserialize_get_value_subtype(deserializer);
size = ndpi_deserialize_get_single_size(deserializer, et, deserializer->status.size_used + expected);
if (size < 0) return -2;
if(size < 0) return(-2);
if(et != ndpi_serialization_string)
return -1;
return(-1);
ndpi_deserialize_single_string(deserializer, deserializer->status.size_used + expected, value);
return 0;
return(0);
}
/* ********************************** */
@@ -1801,30 +1916,30 @@ int ndpi_deserialize_clone_item(ndpi_deserializer *_deserializer, ndpi_serialize
u_int16_t expected;
int size;
if (serializer->fmt != ndpi_serialization_format_tlv)
return -3;
if(serializer->fmt != ndpi_serialization_format_tlv)
return(-3);
expected = sizeof(u_int8_t) /* type */;
if (src_buff_diff < expected) return -2;
if(src_buff_diff < expected) return(-2);
kt = ndpi_deserialize_get_key_subtype(deserializer);
size = ndpi_deserialize_get_single_size(deserializer, kt, deserializer->status.size_used + expected);
if (size < 0) return -2;
if(size < 0) return(-2);
expected += size;
et = ndpi_deserialize_get_value_subtype(deserializer);
size = ndpi_deserialize_get_single_size(deserializer, et, deserializer->status.size_used + expected);
if (size < 0) return -2;
if(size < 0) return(-2);
expected += size;
if (dst_buff_diff < expected) {
if (ndpi_extend_serializer_buffer(_serializer, expected - dst_buff_diff) < 0)
return -1;
if(dst_buff_diff < expected) {
if(ndpi_extend_serializer_buffer(_serializer, expected - dst_buff_diff) < 0)
return(-1);
dst_buff_diff = serializer->buffer_size - serializer->status.size_used;
}
@@ -1834,7 +1949,7 @@ int ndpi_deserialize_clone_item(ndpi_deserializer *_deserializer, ndpi_serialize
serializer->status.size_used += expected;
return 0;
return(0);
}
/* ********************************** */
@@ -1852,7 +1967,7 @@ int ndpi_deserialize_clone_all(ndpi_deserializer *deserializer, ndpi_serializer
while((et = ndpi_deserialize_get_item_type(deserializer, &kt)) != ndpi_serialization_unknown) {
if (et == ndpi_serialization_end_of_record) {
if(et == ndpi_serialization_end_of_record) {
ndpi_serialize_end_of_record(serializer);
ndpi_deserialize_next(deserializer);
continue;
@@ -1868,54 +1983,54 @@ int ndpi_deserialize_clone_all(ndpi_deserializer *deserializer, ndpi_serializer
key_is_string = 1;
break;
default:
return -1;
return(-1);
}
switch(et) {
case ndpi_serialization_uint32:
ndpi_deserialize_value_uint32(deserializer, &u32);
if (key_is_string) ndpi_serialize_binary_uint32(serializer, ks.str, ks.str_len, u32);
if(key_is_string) ndpi_serialize_binary_uint32(serializer, ks.str, ks.str_len, u32);
else ndpi_serialize_uint32_uint32(serializer, k32, u32);
break;
case ndpi_serialization_uint64:
ndpi_deserialize_value_uint64(deserializer, &u64);
if (key_is_string) ndpi_serialize_binary_uint64(serializer, ks.str, ks.str_len, u64);
if(key_is_string) ndpi_serialize_binary_uint64(serializer, ks.str, ks.str_len, u64);
else ndpi_serialize_uint32_uint64(serializer, k32, u64);
break;
case ndpi_serialization_int32:
ndpi_deserialize_value_int32(deserializer, &i32);
if (key_is_string) ndpi_serialize_binary_int32(serializer, ks.str, ks.str_len, i32);
if(key_is_string) ndpi_serialize_binary_int32(serializer, ks.str, ks.str_len, i32);
else ndpi_serialize_uint32_int32(serializer, k32, i32);
break;
case ndpi_serialization_int64:
ndpi_deserialize_value_int64(deserializer, &i64);
if (key_is_string) ndpi_serialize_binary_int64(serializer, ks.str, ks.str_len, i64);
if(key_is_string) ndpi_serialize_binary_int64(serializer, ks.str, ks.str_len, i64);
else ndpi_serialize_uint32_int64(serializer, k32, i64);
break;
case ndpi_serialization_float:
ndpi_deserialize_value_float(deserializer, &f);
if (key_is_string) ndpi_serialize_binary_float(serializer, ks.str, ks.str_len, f, "%.3f");
if(key_is_string) ndpi_serialize_binary_float(serializer, ks.str, ks.str_len, f, "%.3f");
else ndpi_serialize_uint32_float(serializer, k32, f, "%.3f");
break;
case ndpi_serialization_string:
ndpi_deserialize_value_string(deserializer, &vs);
if (key_is_string) ndpi_serialize_binary_binary(serializer, ks.str, ks.str_len, vs.str, vs.str_len);
if(key_is_string) ndpi_serialize_binary_binary(serializer, ks.str, ks.str_len, vs.str, vs.str_len);
else ndpi_serialize_uint32_binary(serializer, k32, vs.str, vs.str_len);
break;
default:
return -2;
return(-2);
}
ndpi_deserialize_next(deserializer);
}
return 0;
return(0);
}
/* ********************************** */
+674 -16
View File
@@ -1,7 +1,7 @@
/*
* ndpi_utils.c
*
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
@@ -21,20 +21,19 @@
*
*/
#ifdef HAVE_CONFIG_H
#include "ndpi_config.h"
#endif
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include "ahocorasick.h"
#include "libcache.h"
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_UNKNOWN
#include "ndpi_api.h"
#include "ndpi_config.h"
#include "ndpi_api.h"
#include "ahocorasick.h"
#include "libcache.h"
#include <time.h>
#ifndef WIN32
@@ -48,6 +47,11 @@
#include "third_party/include/ndpi_patricia.h"
#include "third_party/include/ht_hash.h"
#include "third_party/include/libinjection.h"
#include "third_party/include/libinjection_sqli.h"
#include "third_party/include/libinjection_xss.h"
#include "third_party/include/rce_injection.h"
#define NDPI_CONST_GENERIC_PROTOCOL_NAME "GenericProtocol"
// #define MATCH_DEBUG 1
@@ -211,10 +215,11 @@ void ndpi_tdestroy(void *vrootp, void (*freefct)(void *))
u_int8_t ndpi_net_match(u_int32_t ip_to_check,
u_int32_t net,
u_int32_t num_bits)
{
u_int32_t num_bits) {
u_int32_t mask = 0;
num_bits &= 0x1F; /* Avoid overflows */
mask = ~(~mask >> num_bits);
return(((ip_to_check & mask) == (net & mask)) ? 1 : 0);
@@ -628,7 +633,6 @@ static int ndpi_is_valid_char(char c) {
/* ******************************************************************** */
static int ndpi_find_non_eng_bigrams(struct ndpi_detection_module_struct *ndpi_struct,
char *str) {
char s[3];
@@ -710,8 +714,10 @@ int ndpi_has_human_readeable_string(struct ndpi_detection_module_struct *ndpi_st
/* ********************************** */
char* ndpi_ssl_version2str(u_int16_t version) {
static char v[8];
char* ndpi_ssl_version2str(u_int16_t version, u_int8_t *unknown_tls_version) {
static char v[12];
*unknown_tls_version = 0;
switch(version) {
case 0x0300: return("SSLv3");
@@ -719,16 +725,668 @@ char* ndpi_ssl_version2str(u_int16_t version) {
case 0x0302: return("TLSv1.1");
case 0x0303: return("TLSv1.2");
case 0x0304: return("TLSv1.3");
case 0xfb1a: return("TLSv1.3 (Fizz)"); /* https://engineering.fb.com/security/fizz/ */
case 0xfeff: return("DTLSv1.0");
case 0xfefd: return("DTLSv1.2");
case 0XFB1A: return("TLSv1.3 (Fizz)"); /* https://engineering.fb.com/security/fizz/ */
case 0XFEFF: return("DTLSv1.0");
case 0XFEFD: return("DTLSv1.2");
}
if((version >= 0x7f00) && (version <= 0x7fff))
return("TLSv1.3 (draft)");
snprintf(v, sizeof(v), "%04X", version);
*unknown_tls_version = 1;
snprintf(v, sizeof(v), "TLS (%04X)", version);
return(v);
}
/* ***************************************************** */
void ndpi_patchIPv6Address(char *str) {
int i = 0, j = 0;
while(str[i] != '\0') {
if((str[i] == ':')
&& (str[i+1] == '0')
&& (str[i+2] == ':')) {
str[j++] = ':';
str[j++] = ':';
i += 3;
} else
str[j++] = str[i++];
}
if(str[j] != '\0') str[j] = '\0';
}
/* ********************************** */
void ndpi_user_pwd_payload_copy(u_int8_t *dest, u_int dest_len,
u_int offset,
const u_int8_t *src, u_int src_len) {
u_int i, j=0, k = dest_len-1;
for(i=offset; (i<src_len) && (j<=k); i++) {
if((j == k) || (src[i] < ' '))
break;
dest[j++] = src[i];
}
dest[j <=k ? j : k] = '\0';
}
/* ********************************** */
/* ********************************** */
/* http://web.mit.edu/freebsd/head/contrib/wpa/src/utils/base64.c */
static const unsigned char base64_table[65] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/**
* base64_decode - Base64 decode
* @src: Data to be decoded
* @len: Length of the data to be decoded
* @out_len: Pointer to output length variable
* Returns: Allocated buffer of out_len bytes of decoded data,
* or %NULL on failure
*
* Caller is responsible for freeing the returned buffer.
*/
u_char* ndpi_base64_decode(const u_char *src, size_t len, size_t *out_len) {
u_char dtable[256], *out, *pos, block[4], tmp;
size_t i, count, olen;
int pad = 0;
memset(dtable, 0x80, 256);
for (i = 0; i < sizeof(base64_table) - 1; i++)
dtable[base64_table[i]] = (u_char) i;
dtable['='] = 0;
count = 0;
for (i = 0; i < len; i++) {
if (dtable[src[i]] != 0x80)
count++;
}
if (count == 0 || count % 4)
return NULL;
olen = count / 4 * 3;
pos = out = ndpi_malloc(olen);
if (out == NULL)
return NULL;
count = 0;
for (i = 0; i < len; i++) {
tmp = dtable[src[i]];
if (tmp == 0x80)
continue;
if (src[i] == '=')
pad++;
block[count] = tmp;
count++;
if (count == 4) {
*pos++ = (block[0] << 2) | (block[1] >> 4);
*pos++ = (block[1] << 4) | (block[2] >> 2);
*pos++ = (block[2] << 6) | block[3];
count = 0;
if (pad) {
if (pad == 1)
pos--;
else if (pad == 2)
pos -= 2;
else {
/* Invalid padding */
ndpi_free(out);
return NULL;
}
break;
}
}
}
*out_len = pos - out;
return out;
}
/* ********************************** */
char* ndpi_base64_encode(unsigned char const* bytes_to_encode, ssize_t in_len) {
ssize_t len = 0, ret_size;
char *ret;
int i = 0;
unsigned char char_array_3[3];
unsigned char char_array_4[4];
ret_size = ((in_len+2)/3)*4;
if((ret = (char*)ndpi_malloc(ret_size+1)) == NULL)
return NULL;
while (in_len--) {
char_array_3[i++] = *(bytes_to_encode++);
if(i == 3) {
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
char_array_4[3] = char_array_3[2] & 0x3f;
for(i = 0; i < 4; i++)
ret[len++] = base64_table[char_array_4[i]];
i = 0;
}
}
if(i) {
for(int j = i; j < 3; j++)
char_array_3[j] = '\0';
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
char_array_4[3] = char_array_3[2] & 0x3f;
for(int j = 0; (j < i + 1); j++)
ret[len++] = base64_table[char_array_4[j]];
while((i++ < 3))
ret[len++] = '=';
}
ret[len++] = '\0';
return ret;
}
/* ********************************** */
/* ********************************** */
int ndpi_flow2json(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
u_int8_t ip_version,
u_int8_t l4_protocol, u_int16_t vlan_id,
u_int32_t src_v4, u_int32_t dst_v4,
struct ndpi_in6_addr *src_v6, struct ndpi_in6_addr *dst_v6,
u_int16_t src_port, u_int16_t dst_port,
ndpi_protocol l7_protocol,
ndpi_serializer *serializer) {
char buf[64], src_name[32], dst_name[32];
if(ndpi_init_serializer(serializer, ndpi_serialization_format_json) == -1)
return(-1);
if(ip_version == 4) {
inet_ntop(AF_INET, &src_v4, src_name, sizeof(src_name));
inet_ntop(AF_INET, &dst_v4, dst_name, sizeof(dst_name));
} else {
inet_ntop(AF_INET6, src_v6, src_name, sizeof(src_name));
inet_ntop(AF_INET6, dst_v6, dst_name, sizeof(dst_name));
/* For consistency across platforms replace :0: with :: */
ndpi_patchIPv6Address(src_name), ndpi_patchIPv6Address(dst_name);
}
ndpi_serialize_string_string(serializer, "src_ip", src_name);
ndpi_serialize_string_string(serializer, "dest_ip", dst_name);
if(src_port) ndpi_serialize_string_uint32(serializer, "src_port", src_port);
if(dst_port) ndpi_serialize_string_uint32(serializer, "dst_port", dst_port);
switch(l4_protocol) {
case IPPROTO_TCP:
ndpi_serialize_string_string(serializer, "proto", "TCP");
break;
case IPPROTO_UDP:
ndpi_serialize_string_string(serializer, "proto", "UDP");
break;
case IPPROTO_ICMP:
ndpi_serialize_string_string(serializer, "proto", "ICMP");
break;
default:
ndpi_serialize_string_uint32(serializer, "proto", l4_protocol);
break;
}
ndpi_serialize_start_of_block(serializer, "ndpi");
ndpi_serialize_string_string(serializer, "proto", ndpi_protocol2name(ndpi_struct, l7_protocol, buf, sizeof(buf)));
if(l7_protocol.category != NDPI_PROTOCOL_CATEGORY_UNSPECIFIED)
ndpi_serialize_string_string(serializer, "category", ndpi_category_get_name(ndpi_struct, l7_protocol.category));
ndpi_serialize_end_of_block(serializer);
if(flow == NULL) return(0);
switch(l7_protocol.master_protocol ? l7_protocol.master_protocol : l7_protocol.app_protocol) {
case NDPI_PROTOCOL_DHCP:
ndpi_serialize_start_of_block(serializer, "dhcp");
ndpi_serialize_string_string(serializer, "fingerprint", flow->protos.dhcp.fingerprint);
ndpi_serialize_end_of_block(serializer);
break;
case NDPI_PROTOCOL_BITTORRENT:
{
u_int i, j, n = 0;
char bittorent_hash[32];
for(i=0, j = 0; j < sizeof(bittorent_hash)-1; i++) {
sprintf(&bittorent_hash[j], "%02x",
flow->protos.bittorrent.hash[i]);
j += 2, n += flow->protos.bittorrent.hash[i];
}
if(n == 0) bittorent_hash[0] = '\0';
ndpi_serialize_start_of_block(serializer, "bittorrent");
ndpi_serialize_string_string(serializer, "hash", bittorent_hash);
ndpi_serialize_end_of_block(serializer);
}
break;
case NDPI_PROTOCOL_DNS:
ndpi_serialize_start_of_block(serializer, "dns");
if(flow->host_server_name[0] != '\0')
ndpi_serialize_string_string(serializer, "query", (const char*)flow->host_server_name);
ndpi_serialize_string_uint32(serializer, "num_queries", flow->protos.dns.num_queries);
ndpi_serialize_string_uint32(serializer, "num_answers", flow->protos.dns.num_answers);
ndpi_serialize_string_uint32(serializer, "reply_code", flow->protos.dns.reply_code);
ndpi_serialize_string_uint32(serializer, "query_type", flow->protos.dns.query_type);
ndpi_serialize_string_uint32(serializer, "rsp_type", flow->protos.dns.rsp_type);
inet_ntop(AF_INET, &flow->protos.dns.rsp_addr, buf, sizeof(buf));
ndpi_serialize_string_string(serializer, "rsp_addr", buf);
ndpi_serialize_end_of_block(serializer);
break;
case NDPI_PROTOCOL_MDNS:
ndpi_serialize_start_of_block(serializer, "mdns");
ndpi_serialize_string_string(serializer, "answer", flow->protos.mdns.answer);
ndpi_serialize_end_of_block(serializer);
break;
case NDPI_PROTOCOL_UBNTAC2:
ndpi_serialize_start_of_block(serializer, "ubntac2");
ndpi_serialize_string_string(serializer, "version", flow->protos.ubntac2.version);
ndpi_serialize_end_of_block(serializer);
break;
case NDPI_PROTOCOL_KERBEROS:
ndpi_serialize_start_of_block(serializer, "kerberos");
ndpi_serialize_string_string(serializer, "hostname", flow->protos.kerberos.hostname);
ndpi_serialize_string_string(serializer, "domain", flow->protos.kerberos.domain);
ndpi_serialize_string_string(serializer, "username", flow->protos.kerberos.username);
ndpi_serialize_end_of_block(serializer);
break;
case NDPI_PROTOCOL_TELNET:
ndpi_serialize_start_of_block(serializer, "telnet");
ndpi_serialize_string_string(serializer, "username", flow->protos.telnet.username);
ndpi_serialize_string_string(serializer, "password", flow->protos.telnet.password);
ndpi_serialize_end_of_block(serializer);
break;
case NDPI_PROTOCOL_HTTP:
ndpi_serialize_start_of_block(serializer, "http");
if(flow->host_server_name[0] != '\0')
ndpi_serialize_string_string(serializer, "hostname", (const char*)flow->host_server_name);
ndpi_serialize_string_string(serializer, "url", flow->http.url);
ndpi_serialize_string_uint32(serializer, "code", flow->http.response_status_code);
ndpi_serialize_string_string(serializer, "content_type", flow->http.content_type);
ndpi_serialize_string_string(serializer, "user_agent", flow->http.user_agent);
ndpi_serialize_end_of_block(serializer);
break;
case NDPI_PROTOCOL_MAIL_IMAP:
ndpi_serialize_start_of_block(serializer, "imap");
ndpi_serialize_string_string(serializer, "user", flow->protos.ftp_imap_pop_smtp.username);
ndpi_serialize_string_string(serializer, "password", flow->protos.ftp_imap_pop_smtp.password);
ndpi_serialize_end_of_block(serializer);
break;
case NDPI_PROTOCOL_MAIL_POP:
ndpi_serialize_start_of_block(serializer, "pop");
ndpi_serialize_string_string(serializer, "user", flow->protos.ftp_imap_pop_smtp.username);
ndpi_serialize_string_string(serializer, "password", flow->protos.ftp_imap_pop_smtp.password);
ndpi_serialize_end_of_block(serializer);
break;
case NDPI_PROTOCOL_MAIL_SMTP:
ndpi_serialize_start_of_block(serializer, "smtp");
ndpi_serialize_string_string(serializer, "user", flow->protos.ftp_imap_pop_smtp.username);
ndpi_serialize_string_string(serializer, "password", flow->protos.ftp_imap_pop_smtp.password);
ndpi_serialize_end_of_block(serializer);
break;
case NDPI_PROTOCOL_FTP_CONTROL:
ndpi_serialize_start_of_block(serializer, "ftp");
ndpi_serialize_string_string(serializer, "user", flow->protos.ftp_imap_pop_smtp.username);
ndpi_serialize_string_string(serializer, "password", flow->protos.ftp_imap_pop_smtp.password);
ndpi_serialize_string_uint32(serializer, "auth_failed", flow->protos.ftp_imap_pop_smtp.auth_failed);
ndpi_serialize_end_of_block(serializer);
break;
case NDPI_PROTOCOL_SSH:
ndpi_serialize_start_of_block(serializer, "ssh");
ndpi_serialize_string_string(serializer, "client_signature", flow->protos.ssh.client_signature);
ndpi_serialize_string_string(serializer, "server_signature", flow->protos.ssh.server_signature);
ndpi_serialize_string_string(serializer, "hassh_client", flow->protos.ssh.hassh_client);
ndpi_serialize_string_string(serializer, "hassh_server", flow->protos.ssh.hassh_server);
ndpi_serialize_end_of_block(serializer);
break;
case NDPI_PROTOCOL_TLS:
if(flow->protos.stun_ssl.ssl.ssl_version) {
char notBefore[32], notAfter[32];
struct tm a, b, *before = NULL, *after = NULL;
u_int i, off;
u_int8_t unknown_tls_version;
char *version = ndpi_ssl_version2str(flow->protos.stun_ssl.ssl.ssl_version, &unknown_tls_version);
if(flow->protos.stun_ssl.ssl.notBefore)
before = gmtime_r((const time_t *)&flow->protos.stun_ssl.ssl.notBefore, &a);
if(flow->protos.stun_ssl.ssl.notAfter)
after = gmtime_r((const time_t *)&flow->protos.stun_ssl.ssl.notAfter, &b);
if(!unknown_tls_version) {
ndpi_serialize_start_of_block(serializer, "tls");
ndpi_serialize_string_string(serializer, "version", version);
ndpi_serialize_string_string(serializer, "client_requested_server_name",
flow->protos.stun_ssl.ssl.client_requested_server_name);
if(flow->protos.stun_ssl.ssl.server_names)
ndpi_serialize_string_string(serializer, "server_names", flow->protos.stun_ssl.ssl.server_names);
ndpi_serialize_string_string(serializer, "issuer", flow->protos.stun_ssl.ssl.server_organization);
if(before) {
strftime(notBefore, sizeof(notBefore), "%F %T", before);
ndpi_serialize_string_string(serializer, "notbefore", notBefore);
}
if(after) {
strftime(notAfter, sizeof(notAfter), "%F %T", after);
ndpi_serialize_string_string(serializer, "notafter", notAfter);
}
ndpi_serialize_string_string(serializer, "ja3", flow->protos.stun_ssl.ssl.ja3_client);
ndpi_serialize_string_string(serializer, "ja3s", flow->protos.stun_ssl.ssl.ja3_server);
ndpi_serialize_string_uint32(serializer, "unsafe_cipher", flow->protos.stun_ssl.ssl.server_unsafe_cipher);
ndpi_serialize_string_string(serializer, "cipher", ndpi_cipher2str(flow->protos.stun_ssl.ssl.server_cipher));
if(flow->l4.tcp.tls.sha1_certificate_fingerprint[0] != '\0') {
for(i=0, off=0; i<20; i++) {
int rc = snprintf(&buf[off], sizeof(buf)-off,"%s%02X", (i > 0) ? ":" : "",
flow->l4.tcp.tls.sha1_certificate_fingerprint[i] & 0xFF);
if(rc <= 0) break; else off += rc;
}
ndpi_serialize_string_string(serializer, "fingerprint", buf);
}
ndpi_serialize_end_of_block(serializer);
}
}
break;
} /* switch */
return(0);
}
/* ********************************** */
const char* ndpi_tunnel2str(ndpi_packet_tunnel tt) {
switch(tt) {
case ndpi_no_tunnel:
return("No-Tunnel");
break;
case ndpi_gtp_tunnel:
return("GTP");
break;
case ndpi_capwap_tunnel:
return("CAPWAP");
break;
case ndpi_tzsp_tunnel:
return("TZSP");
break;
case ndpi_l2tp_tunnel:
return("L2TP");
break;
}
return("");
}
/* ********************************** */
/*
/dv/vulnerabilities/xss_r/?name=%3Cscript%3Econsole.log%28%27JUL2D3WXHEGWRAFJE2PI7OS71Z4Z8RFUHXGNFLUFYVP6M3OL55%27%29%3Bconsole.log%28document.cookie%29%3B%3C%2Fscript%3E
/dv/vulnerabilities/sqli/?id=1%27+and+1%3D1+union+select+null%2C+table_name+from+information_schema.tables%23&Submit=Submit
*/
/* https://www.rosettacode.org/wiki/URL_decoding#C */
static int ishex(int x) {
return(x >= '0' && x <= '9') || (x >= 'a' && x <= 'f') || (x >= 'A' && x <= 'F');
}
/* ********************************** */
static int ndpi_url_decode(const char *s, char *out) {
char *o;
const char *end = s + strlen(s);
int c;
for(o = out; s <= end; o++) {
c = *s++;
if(c == '+') c = ' ';
else if(c == '%' && (!ishex(*s++)||
!ishex(*s++)||
!sscanf(s - 2, "%2x", (unsigned int*)&c)))
return(-1);
if(out) *o = c;
}
return(o - out);
}
/* ********************************** */
static int ndpi_is_sql_injection(char* query) {
struct libinjection_sqli_state state;
size_t qlen = strlen(query);
libinjection_sqli_init(&state, query, qlen, FLAG_NONE);
return libinjection_is_sqli(&state);
}
/* ********************************** */
static int ndpi_is_xss_injection(char* query) {
size_t qlen = strlen(query);
return libinjection_xss(query, qlen);
}
/* ********************************** */
#ifdef HAVE_PCRE
static void ndpi_compile_rce_regex() {
const char *pcreErrorStr;
int pcreErrorOffset;
for(int i = 0; i < N_RCE_REGEX; i++) {
comp_rx[i] = (struct pcre_struct*)ndpi_malloc(sizeof(struct pcre_struct));
comp_rx[i]->compiled = pcre_compile(rce_regex[i], 0, &pcreErrorStr,
&pcreErrorOffset, NULL);
if(comp_rx[i]->compiled == NULL) {
#ifdef DEBUG
NDPI_LOG_ERR(ndpi_str, "ERROR: Could not compile '%s': %s\n", rce_regex[i],
pcreErrorStr);
#endif
continue;
}
comp_rx[i]->optimized = pcre_study(comp_rx[i]->compiled, 0, &pcreErrorStr);
#ifdef DEBUG
if(pcreErrorStr != NULL) {
NDPI_LOG_ERR(ndpi_str, "ERROR: Could not study '%s': %s\n", rce_regex[i],
pcreErrorStr);
}
#endif
}
free((void *)pcreErrorStr);
}
static int ndpi_is_rce_injection(char* query) {
if (!initialized_comp_rx) {
ndpi_compile_rce_regex();
initialized_comp_rx = 1;
}
int pcreExecRet;
int subStrVec[30];
for(int i = 0; i < N_RCE_REGEX; i++) {
unsigned int length = strlen(query);
pcreExecRet = pcre_exec(comp_rx[i]->compiled,
comp_rx[i]->optimized,
query, length, 0, 0, subStrVec, 30);
if (pcreExecRet >= 0) {
return 1;
}
#ifdef DEBUG
else {
switch(pcreExecRet) {
case PCRE_ERROR_NOMATCH:
NDPI_LOG_ERR(ndpi_str, "ERROR: String did not match the pattern\n");
break;
case PCRE_ERROR_NULL:
NDPI_LOG_ERR(ndpi_str, "ERROR: Something was null\n");
break;
case PCRE_ERROR_BADOPTION:
NDPI_LOG_ERR(ndpi_str, "ERROR: A bad option was passed\n");
break;
case PCRE_ERROR_BADMAGIC:
NDPI_LOG_ERR(ndpi_str, "ERROR: Magic number bad (compiled re corrupt?)\n");
break;
case PCRE_ERROR_UNKNOWN_NODE:
NDPI_LOG_ERR(ndpi_str, "ERROR: Something kooky in the compiled re\n");
break;
case PCRE_ERROR_NOMEMORY:
NDPI_LOG_ERR(ndpi_str, "ERROR: Ran out of memory\n");
break;
default:
NDPI_LOG_ERR(ndpi_str, "ERROR: Unknown error\n");
break;
}
}
#endif
}
size_t ushlen = sizeof(ush_commands) / sizeof(ush_commands[0]);
for(int i = 0; i < ushlen; i++) {
if(strstr(query, ush_commands[i]) != NULL) {
return 1;
}
}
size_t pwshlen = sizeof(pwsh_commands) / sizeof(pwsh_commands[0]);
for(int i = 0; i < pwshlen; i++) {
if(strstr(query, pwsh_commands[i]) != NULL) {
return 1;
}
}
return 0;
}
#endif
/* ********************************** */
ndpi_url_risk ndpi_validate_url(char *url) {
char *orig_str = NULL, *str = NULL, *question_mark = strchr(url, '?');
ndpi_url_risk rc = ndpi_url_no_problem;
if(question_mark) {
char *tmp;
orig_str = str = ndpi_strdup(&question_mark[1]); /* Skip ? */
if(!str) goto validate_rc;
str = strtok_r(str, "&", &tmp);
while(str != NULL) {
char *value = strchr(str, '=');
char *decoded;
if(!value)
break;
else
value = &value[1];
if(value[0] != '\0') {
if(!(decoded = (char*)ndpi_malloc(strlen(value)+1)))
break;
if(ndpi_url_decode(value, decoded) < 0) {
/* Invalid string */
} else if(decoded[0] != '\0') {
/* Valid string */
if(ndpi_is_xss_injection(decoded))
rc = ndpi_url_possible_xss;
else if(ndpi_is_sql_injection(decoded))
rc = ndpi_url_possible_sql_injection;
#ifdef HAVE_PCRE
else if(ndpi_is_rce_injection(decoded))
rc = ndpi_url_possible_rce_injection;
#endif
#ifdef URL_CHECK_DEBUG
printf("=>> [rc: %u] %s\n", rc, decoded);
#endif
}
ndpi_free(decoded);
if(rc != ndpi_url_no_problem)
break;
}
str = strtok_r(NULL, "&", &tmp);
}
}
validate_rc:
if(orig_str) ndpi_free(orig_str);
return(rc);
}
/* ******************************************************************** */
u_int8_t ndpi_is_protocol_detected(struct ndpi_detection_module_struct *ndpi_str,
ndpi_protocol proto) {
if((proto.master_protocol != NDPI_PROTOCOL_UNKNOWN)
|| (proto.app_protocol != NDPI_PROTOCOL_UNKNOWN)
|| (proto.category != NDPI_PROTOCOL_CATEGORY_UNSPECIFIED))
return(1);
else
return(0);
}
+1 -1
View File
@@ -2,7 +2,7 @@
* afp.c
*
* Copyright (C) 2009-11 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+1 -1
View File
@@ -2,7 +2,7 @@
* aimini.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+21 -22
View File
@@ -1,7 +1,7 @@
/*
* amazon_video.c
*
* Copyright (C) 2018 by ntop.org
* Copyright (C) 2018-20 by ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
@@ -28,37 +28,36 @@
#include "ndpi_api.h"
static void ndpi_check_amazon_video(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search Amazon Prime\n");
if((packet->tcp != NULL) &&
(packet->payload[0] == 0xFE &&
packet->payload[1] == 0xED &&
packet->payload[2] == 0xFA &&
packet->payload[3] == 0xCE))
{
if(packet->payload_packet_len > 4) {
if((packet->tcp != NULL) &&
(packet->payload[0] == 0xFE &&
packet->payload[1] == 0xED &&
packet->payload[2] == 0xFA &&
packet->payload[3] == 0xCE)) {
NDPI_LOG_INFO(ndpi_struct, "found Amazon Video on TCP\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_AMAZON_VIDEO, NDPI_PROTOCOL_UNKNOWN);
return;
}
else if((packet->udp != NULL) &&
(packet->payload[0] == 0xDE &&
packet->payload[1] == 0xAD &&
packet->payload[2] == 0xBE &&
packet->payload[3] == 0xEF))
{
} else if((packet->udp != NULL) &&
(packet->payload[0] == 0xDE &&
packet->payload[1] == 0xAD &&
packet->payload[2] == 0xBE &&
packet->payload[3] == 0xEF)) {
NDPI_LOG_INFO(ndpi_struct, "found Amazon Video on UDP\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_AMAZON_VIDEO, NDPI_PROTOCOL_UNKNOWN);
} else {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
}
}
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
void ndpi_search_amazon_video(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
void ndpi_search_amazon_video(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search amazon_video\n");
@@ -69,8 +68,8 @@ void ndpi_search_amazon_video(struct ndpi_detection_module_struct *ndpi_struct,
}
void init_amazon_video_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
void init_amazon_video_dissector(struct ndpi_detection_module_struct *ndpi_struct,
u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask) {
ndpi_set_bitmask_protocol_detection("AMAZON_VIDEO", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_AMAZON_VIDEO,
ndpi_search_amazon_video,
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* amqp.c
*
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* nDPI is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
+1 -1
View File
@@ -2,7 +2,7 @@
* applejuice.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+1 -1
View File
@@ -2,7 +2,7 @@
* armagetron.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+1 -1
View File
@@ -2,7 +2,7 @@
* flash.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+1 -1
View File
@@ -2,7 +2,7 @@
* ftp.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+1 -1
View File
@@ -2,7 +2,7 @@
* manolito.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+1 -1
View File
@@ -2,7 +2,7 @@
* popo.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+1 -1
View File
@@ -2,7 +2,7 @@
* secondlife.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* ayiya.c
*
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+1 -1
View File
@@ -2,7 +2,7 @@
* battlefield.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* bgp.c
*
* Copyright (C) 2016-19 - ntop.org
* Copyright (C) 2016-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+24 -13
View File
@@ -2,7 +2,7 @@
* bittorrent.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
@@ -72,9 +72,7 @@ static void ndpi_add_connection_as_bittorrent(struct ndpi_detection_module_struc
} else
bt_hash = (const char*)&flow->packet.payload[28];
if(!ndpi_struct->disable_metadata_export) {
if(bt_hash) memcpy(flow->protos.bittorrent.hash, bt_hash, 20);
}
if(bt_hash) memcpy(flow->protos.bittorrent.hash, bt_hash, 20);
}
ndpi_int_change_protocol(ndpi_struct, flow, NDPI_PROTOCOL_BITTORRENT, NDPI_PROTOCOL_UNKNOWN);
@@ -376,19 +374,32 @@ static void ndpi_int_search_bittorrent_tcp(struct ndpi_detection_module_struct *
return;
}
static u_int8_t is_port(u_int16_t a, u_int16_t b, u_int16_t what) {
return(((what == a) || (what == b)) ? 1 : 0);
}
void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
char *bt_proto = NULL;
/* This is broadcast */
if(packet->iph
&& (((packet->iph->saddr == 0xFFFFFFFF) || (packet->iph->daddr == 0xFFFFFFFF))
|| (packet->udp
&& ((ntohs(packet->udp->source) == 3544) /* teredo.c */
|| (ntohs(packet->udp->dest) == 3544))))) {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
if(packet->iph) {
if((packet->iph->saddr == 0xFFFFFFFF) || (packet->iph->daddr == 0xFFFFFFFF))
goto exclude_bt;
if(packet->udp) {
u_int16_t sport = ntohs(packet->udp->source), dport = ntohs(packet->udp->dest);
if(is_port(sport, dport, 3544) /* teredo */
|| is_port(sport, dport, 5246) || is_port(sport, dport, 5247)/* CAPWAP */) {
exclude_bt:
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
}
}
}
if(packet->detected_protocol_stack[0] != NDPI_PROTOCOL_BITTORRENT) {
@@ -397,8 +408,8 @@ void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, st
if((packet->tcp != NULL)
&& (packet->tcp_retransmission == 0 || packet->num_retried_bytes)) {
ndpi_int_search_bittorrent_tcp(ndpi_struct, flow);
}
else if(packet->udp != NULL) {
} else if(packet->udp != NULL) {
/* UDP */
char *bt_search = "BT-SEARCH * HTTP/1.1\r\n";
if((ntohs(packet->udp->source) < 1024)
+3 -1
View File
@@ -1,7 +1,7 @@
/*
* btlib.c
*
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
* Contributed by Vitaly Lavrov <vel21ripn@gmail.com>
*
* This file is part of nDPI, an open source deep packet inspection
@@ -39,8 +39,10 @@ typedef unsigned long long int u_int64_t;
#include <stdint.h>
#include <stdlib.h>
#ifndef WIN32
#include <arpa/inet.h>
#endif
#endif
#include "btlib.h"
+123
View File
@@ -0,0 +1,123 @@
/*
* capwap.c
*
* Copyright (C) 2019 - ntop.org
*
* nDPI is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* nDPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with nDPI. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ndpi_protocol_ids.h"
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_CAPWAP
#include "ndpi_api.h"
#define NDPI_CAPWAP_CONTROL_PORT 5246
#define NDPI_CAPWAP_DATA_PORT 5247
static void ndpi_int_capwap_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CAPWAP, NDPI_PROTOCOL_UNKNOWN);
}
/* ************************************************** */
static void ndpi_search_setup_capwap(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
u_int16_t sport, dport;
if(!packet->iph) {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
}
sport = ntohs(packet->udp->source), dport = ntohs(packet->udp->dest);
if((dport == NDPI_CAPWAP_CONTROL_PORT)
&& (packet->iph->daddr == 0xFFFFFFFF)
&& (packet->payload_packet_len >= 16)
&& (packet->payload[0] == 0x0)
&& (packet->payload[8] == 6 /* Mac len */)
)
goto capwap_found;
if(((sport == NDPI_CAPWAP_CONTROL_PORT) || (dport == NDPI_CAPWAP_CONTROL_PORT))
&& ((packet->payload[0] == 0x0) || (packet->payload[0] == 0x1))
) {
u_int16_t msg_len, offset, to_add;
if(packet->payload[0] == 0x0)
offset = 13, to_add = 13;
else
offset = 15, to_add = 17;
msg_len = ntohs(*(u_int16_t*)&packet->payload[offset]);
if((msg_len+to_add) == packet->payload_packet_len)
goto capwap_found;
}
if(
(((dport == NDPI_CAPWAP_DATA_PORT) && (packet->iph->daddr != 0xFFFFFFFF)) || (sport == NDPI_CAPWAP_DATA_PORT))
&& (packet->payload_packet_len >= 16)
&& (packet->payload[0] == 0x0)
) {
u_int8_t is_80211_data = (packet->payload[9] & 0x0C) >> 2;
if((sport == NDPI_CAPWAP_DATA_PORT) && (is_80211_data == 2 /* IEEE 802.11 Data */))
goto capwap_found;
else if(dport == NDPI_CAPWAP_DATA_PORT) {
u_int16_t msg_len = ntohs(*(u_int16_t*)&packet->payload[13]);
if((packet->payload[8] == 1 /* Mac len */)
|| (packet->payload[8] == 6 /* Mac len */)
|| (packet->payload[8] == 4 /* Wireless len */)
|| ((msg_len+15) == packet->payload_packet_len))
goto capwap_found;
}
}
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
capwap_found:
ndpi_int_capwap_add_connection(ndpi_struct, flow);
}
void ndpi_search_capwap(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
if(packet->udp && (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN))
ndpi_search_setup_capwap(ndpi_struct, flow);
}
void init_capwap_dissector(struct ndpi_detection_module_struct *ndpi_struct,
u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
ndpi_set_bitmask_protocol_detection("CAPWAP", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_CAPWAP,
ndpi_search_capwap,
NDPI_SELECTION_BITMASK_PROTOCOL_UDP_WITH_PAYLOAD,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);
*id += 1;
}
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* checkmk.c
*
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+2 -2
View File
@@ -1,7 +1,7 @@
/*
* citrix.c
*
* Copyright (C) 2012-19 - ntop.org
* Copyright (C) 2012-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
@@ -51,7 +51,7 @@ static void ndpi_check_citrix(struct ndpi_detection_module_struct *ndpi_struct,
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CITRIX, NDPI_PROTOCOL_UNKNOWN);
}
return;
} else if(payload_len > 4) {
} else if(payload_len > 22) {
char citrix_header[] = { 0x1a, 0x43, 0x47, 0x50, 0x2f, 0x30, 0x31 };
if((memcmp(packet->payload, citrix_header, sizeof(citrix_header)) == 0)
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* collectd.c
*
* Copyright (C) 2014-19 - ntop.org
* Copyright (C) 2014-20 - ntop.org
*
* nDPI is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* crossfire.c
*
* Copyright (C) 2012-19 - ntop.org
* Copyright (C) 2012-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+24 -33
View File
@@ -1,7 +1,7 @@
/*
* dhcp.c
*
* Copyright (C) 2016-19 - ntop.org
* Copyright (C) 2016-20 - ntop.org
*
* nDPI is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@@ -100,45 +100,36 @@ void ndpi_search_dhcp_udp(struct ndpi_detection_module_struct *ndpi_struct, stru
if(msg_type <= 8) foundValidMsgType = 1;
} else if(id == 55 /* Parameter Request List / Fingerprint */) {
if(!ndpi_struct->disable_metadata_export) {
u_int idx, offset = 0;
u_int idx, offset = 0;
for(idx = 0; idx < len && offset < sizeof(flow->protos.dhcp.fingerprint) - 2; idx++) {
int rc = snprintf((char*)&flow->protos.dhcp.fingerprint[offset],
sizeof(flow->protos.dhcp.fingerprint) - offset,
"%s%u", (idx > 0) ? "," : "",
(unsigned int)dhcp->options[i+2+idx] & 0xFF);
for(idx = 0; idx < len && offset < sizeof(flow->protos.dhcp.fingerprint) - 2; idx++) {
#if 1
offset += snprintf((char*)&flow->protos.dhcp.fingerprint[offset],
sizeof(flow->protos.dhcp.fingerprint) - offset,
"%s%u", (idx > 0) ? "," : "", dhcp->options[i+2+idx] & 0xFF);
#else
offset += snprintf((char*)&flow->protos.dhcp.fingerprint[offset],
sizeof(flow->protos.dhcp.fingerprint) - offset,
"%02X", dhcp->options[i+2+idx] & 0xFF);
#endif
}
flow->protos.dhcp.fingerprint[sizeof(flow->protos.dhcp.fingerprint) - 1] = '\0';
if(rc < 0) break; else offset += rc;
}
flow->protos.dhcp.fingerprint[sizeof(flow->protos.dhcp.fingerprint) - 1] = '\0';
} else if(id == 60 /* Class Identifier */) {
if(!ndpi_struct->disable_metadata_export) {
char *name = (char*)&dhcp->options[i+2];
int j = 0;
j = ndpi_min(len, sizeof(flow->protos.dhcp.class_ident)-1);
strncpy((char*)flow->protos.dhcp.class_ident, name, j);
flow->protos.dhcp.class_ident[j] = '\0';
}
char *name = (char*)&dhcp->options[i+2];
int j = 0;
j = ndpi_min(len, sizeof(flow->protos.dhcp.class_ident)-1);
strncpy((char*)flow->protos.dhcp.class_ident, name, j);
flow->protos.dhcp.class_ident[j] = '\0';
} else if(id == 12 /* Host Name */) {
if(!ndpi_struct->disable_metadata_export) {
char *name = (char*)&dhcp->options[i+2];
int j = 0;
char *name = (char*)&dhcp->options[i+2];
int j = 0;
#ifdef DHCP_DEBUG
NDPI_LOG_DBG2(ndpi_struct, "[DHCP] '%.*s'\n",name,len);
NDPI_LOG_DBG2(ndpi_struct, "[DHCP] '%.*s'\n",name,len);
// while(j < len) { printf( "%c", name[j]); j++; }; printf("\n");
#endif
j = ndpi_min(len, sizeof(flow->host_server_name)-1);
strncpy((char*)flow->host_server_name, name, j);
flow->host_server_name[j] = '\0';
}
j = ndpi_min(len, sizeof(flow->host_server_name)-1);
strncpy((char*)flow->host_server_name, name, j);
flow->host_server_name[j] = '\0';
}
i += len + 2;
+1 -1
View File
@@ -2,7 +2,7 @@
* dhcpv6.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+1 -1
View File
@@ -2,7 +2,7 @@
* directconnect.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+2 -2
View File
@@ -2,7 +2,7 @@
* directdownloadlink.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
@@ -56,7 +56,7 @@ u_int8_t search_ddl_domains(struct ndpi_detection_module_struct *ndpi_struct, st
{
struct ndpi_packet_struct *packet = &flow->packet;
u_int16_t filename_start = 0;
u_int8_t i = 1;
u_int16_t i = 1;
u_int16_t host_line_len_without_port;
if (packet->payload_packet_len < 100) {
+84 -58
View File
@@ -1,7 +1,7 @@
/*
* dns.c
*
* Copyright (C) 2012-19 - ntop.org
* Copyright (C) 2012-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
@@ -32,6 +32,8 @@
// #define DNS_DEBUG 1
static void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
/* *********************************************** */
static u_int16_t get16(int *i, const u_int8_t *payload) {
@@ -45,7 +47,9 @@ static u_int16_t get16(int *i, const u_int8_t *payload) {
/* *********************************************** */
static u_int getNameLength(u_int i, const u_int8_t *payload, u_int payloadLen) {
if(payload[i] == 0x00)
if(i >= payloadLen)
return(0);
else if(payload[i] == 0x00)
return(1);
else if(payload[i] == 0xC0)
return(2);
@@ -60,18 +64,19 @@ static u_int getNameLength(u_int i, const u_int8_t *payload, u_int payloadLen) {
}
}
/*
allowed chars for dns names A-Z 0-9 _ -
Perl script for generation map:
my @M;
for(my $ch=0; $ch < 256; $ch++) {
$M[$ch >> 5] |= 1 << ($ch & 0x1f) if chr($ch) =~ /[a-z0-9_-]/i;
}
print join(',', map { sprintf "0x%08x",$_ } @M),"\n";
allowed chars for dns names A-Z 0-9 _ -
Perl script for generation map:
my @M;
for(my $ch=0; $ch < 256; $ch++) {
$M[$ch >> 5] |= 1 << ($ch & 0x1f) if chr($ch) =~ /[a-z0-9_-]/i;
}
print join(',', map { sprintf "0x%08x",$_ } @M),"\n";
*/
static uint32_t dns_validchar[8] = {
0x00000000,0x03ff2000,0x87fffffe,0x07fffffe,0,0,0,0
};
static uint32_t dns_validchar[8] =
{
0x00000000,0x03ff2000,0x87fffffe,0x07fffffe,0,0,0,0
};
/* *********************************************** */
@@ -83,6 +88,7 @@ static int search_valid_dns(struct ndpi_detection_module_struct *ndpi_struct,
memcpy(dns_header, (struct ndpi_dns_packet_header*)&flow->packet.payload[x],
sizeof(struct ndpi_dns_packet_header));
dns_header->tr_id = ntohs(dns_header->tr_id);
dns_header->flags = ntohs(dns_header->flags);
dns_header->num_queries = ntohs(dns_header->num_queries);
@@ -133,58 +139,80 @@ static int search_valid_dns(struct ndpi_detection_module_struct *ndpi_struct,
/* This is a good reply: we dissect it both for request and response */
/* Leave the statement below commented necessary in case of call to ndpi_get_partial_detection() */
/* if(ndpi_struct->dns_dont_dissect_response == 0) */ {
x++;
if(flow->packet.payload[x] != '\0') {
while((x < flow->packet.payload_packet_len)
&& (flow->packet.payload[x] != '\0')) {
x++;
}
x++;
if(flow->packet.payload[x] != '\0') {
while((x < flow->packet.payload_packet_len)
&& (flow->packet.payload[x] != '\0')) {
x++;
}
x += 4;
x++;
}
if(dns_header->num_answers > 0) {
u_int16_t rsp_type;
u_int16_t num;
x += 4;
for(num = 0; num < dns_header->num_answers; num++) {
u_int16_t data_len;
if(dns_header->num_answers > 0) {
u_int16_t rsp_type;
u_int16_t num;
if((x+6) >= flow->packet.payload_packet_len) {
break;
}
for(num = 0; num < dns_header->num_answers; num++) {
u_int16_t data_len;
if((data_len = getNameLength(x, flow->packet.payload, flow->packet.payload_packet_len)) == 0) {
break;
} else
x += data_len;
if((x+6) >= flow->packet.payload_packet_len) {
break;
}
rsp_type = get16(&x, flow->packet.payload);
flow->protos.dns.rsp_type = rsp_type;
if((data_len = getNameLength(x, flow->packet.payload, flow->packet.payload_packet_len)) == 0) {
break;
} else
x += data_len;
/* here x points to the response "class" field */
if((x+12) <= flow->packet.payload_packet_len) {
x += 6;
data_len = get16(&x, flow->packet.payload);
if((x+2) >= flow->packet.payload_packet_len) {
break;
}
rsp_type = get16(&x, flow->packet.payload);
flow->protos.dns.rsp_type = rsp_type;
if(((x + data_len) <= flow->packet.payload_packet_len)
&& (((rsp_type == 0x1) && (data_len == 4)) /* A */
/* here x points to the response "class" field */
if((x+12) <= flow->packet.payload_packet_len) {
x += 6;
data_len = get16(&x, flow->packet.payload);
if((x + data_len) <= flow->packet.payload_packet_len) {
// printf("[rsp_type: %u][data_len: %u]\n", rsp_type, data_len);
if(rsp_type == 0x05 /* CNAME */) {
x += data_len;
continue; /* Skip CNAME */
}
if((((rsp_type == 0x1) && (data_len == 4)) /* A */
#ifdef NDPI_DETECTION_SUPPORT_IPV6
|| ((rsp_type == 0x1c) && (data_len == 16)) /* AAAA */
|| ((rsp_type == 0x1c) && (data_len == 16)) /* AAAA */
#endif
)) {
)) {
memcpy(&flow->protos.dns.rsp_addr, flow->packet.payload + x, data_len);
}
}
break;
}
break;
}
}
if((flow->packet.detected_protocol_stack[0] == NDPI_PROTOCOL_DNS)
|| (flow->packet.detected_protocol_stack[1] == NDPI_PROTOCOL_DNS)) {
/* Request already set the protocol */
// flow->extra_packets_func = NULL; /* Removed so the caller can keep dissecting DNS flows */
} else {
/* We missed the request */
u_int16_t s_port = flow->packet.udp ? ntohs(flow->packet.udp->source) : ntohs(flow->packet.tcp->source);
ndpi_set_detected_protocol(ndpi_struct, flow,
(s_port == 5355) ? NDPI_PROTOCOL_LLMNR : NDPI_PROTOCOL_DNS,
NDPI_PROTOCOL_UNKNOWN);
}
} else
return(1 /* invalid */);
}
@@ -199,18 +227,13 @@ static int search_dns_again(struct ndpi_detection_module_struct *ndpi_struct, st
/* possibly dissect the DNS reply */
ndpi_search_dns(ndpi_struct, flow);
if(flow->protos.dns.num_answers > 0) {
/* stop extra processing */
return(0);
}
/* Possibly more processing */
return(1);
}
/* *********************************************** */
void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
static void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
int payload_offset;
u_int8_t is_query;
u_int16_t s_port = 0, d_port = 0;
@@ -239,7 +262,7 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
ret.master_protocol = NDPI_PROTOCOL_UNKNOWN;
ret.app_protocol = (d_port == 5355) ? NDPI_PROTOCOL_LLMNR : NDPI_PROTOCOL_DNS;
if(invalid) {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
@@ -248,7 +271,7 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
/* extract host name server */
max_len = sizeof(flow->host_server_name)-1;
off = sizeof(struct ndpi_dns_packet_header) + payload_offset;
while(j < max_len && off < flow->packet.payload_packet_len && flow->packet.payload[off] != '\0') {
uint8_t c, cl = flow->packet.payload[off++];
@@ -261,8 +284,11 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
if(j && j < max_len) flow->host_server_name[j++] = '.';
while(j < max_len && cl != 0) {
u_int32_t shift;
c = flow->packet.payload[off++];
flow->host_server_name[j++] = (dns_validchar[c >> 5] & (1 << (c & 0x1f))) ? c : '_';
shift = ((u_int32_t) 1) << (c & 0x1f);
flow->host_server_name[j++] = tolower((dns_validchar[c >> 5] & shift) ? c : '_');
cl--;
}
}
@@ -270,13 +296,13 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
if(j > 0) {
ndpi_protocol_match_result ret_match;
ret.app_protocol = ndpi_match_host_subprotocol(ndpi_struct, flow,
(char *)flow->host_server_name,
strlen((const char*)flow->host_server_name),
&ret_match,
NDPI_PROTOCOL_DNS);
if(ret_match.protocol_category != NDPI_PROTOCOL_CATEGORY_UNSPECIFIED)
flow->category = ret_match.protocol_category;
@@ -288,8 +314,8 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
/* Report if this is a DNS query or reply */
flow->protos.dns.is_query = is_query;
if(is_query && (ndpi_struct->dns_dont_dissect_response == 0) && (flow->check_extra_packets == 0)) {
if(is_query) {
/* In this case we say that the protocol has been detected just to let apps carry on with their activities */
ndpi_set_detected_protocol(ndpi_struct, flow, ret.app_protocol, ret.master_protocol);
+1 -1
View File
@@ -2,7 +2,7 @@
* dofus.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* drda.c
*
* Copyright (C) 2012-19 - ntop.org
* Copyright (C) 2012-20 - ntop.org
*
* This module is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* eaq.c
*
* Copyright (C) 2015-19 - ntop.org
* Copyright (C) 2015-20 - ntop.org
*
* This module is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
+38 -37
View File
@@ -2,7 +2,7 @@
* fasttrack.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
@@ -37,47 +37,48 @@ static void ndpi_int_fasttrack_add_connection(struct ndpi_detection_module_struc
void ndpi_search_fasttrack_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search FASTTRACK\n");
NDPI_LOG_DBG(ndpi_struct, "search FASTTRACK\n");
if ( (packet->payload != NULL)
&& (packet->payload_packet_len > 6)
&& (ntohs(get_u_int16_t(packet->payload, packet->payload_packet_len - 2)) == 0x0d0a)) {
NDPI_LOG_DBG2(ndpi_struct, "detected 0d0a at the end of the packet\n");
if ( (packet->payload != NULL)
&& (packet->payload_packet_len > 6)
&& (ntohs(get_u_int16_t(packet->payload, packet->payload_packet_len - 2)) == 0x0d0a)) {
NDPI_LOG_DBG2(ndpi_struct, "detected 0d0a at the end of the packet\n");
if (memcmp(packet->payload, "GIVE ", 5) == 0 && packet->payload_packet_len >= 8) {
u_int16_t i;
for (i = 5; i < (packet->payload_packet_len - 2); i++) {
// make shure that the argument to GIVE is numeric
if (!(packet->payload[i] >= '0' && packet->payload[i] <= '9')) {
goto exclude_fasttrack;
}
}
NDPI_LOG_INFO(ndpi_struct, "found FASTTRACK\n");
ndpi_int_fasttrack_add_connection(ndpi_struct, flow);
return;
}
if (packet->payload_packet_len > 50 && memcmp(packet->payload, "GET /", 5) == 0) {
u_int8_t a = 0;
NDPI_LOG_DBG2(ndpi_struct, "detected GET /. \n");
ndpi_parse_packet_line_info(ndpi_struct, flow);
for (a = 0; a < packet->parsed_lines; a++) {
if ((packet->line[a].len > 17 && memcmp(packet->line[a].ptr, "X-Kazaa-Username: ", 18) == 0)
|| (packet->line[a].len > 23 && memcmp(packet->line[a].ptr, "User-Agent: PeerEnabler/", 24) == 0)) {
NDPI_LOG_INFO(ndpi_struct,
"found FASTTRACK X-Kazaa-Username: || User-Agent: PeerEnabler/\n");
ndpi_int_fasttrack_add_connection(ndpi_struct, flow);
return;
}
}
}
if (memcmp(packet->payload, "GIVE ", 5) == 0 && packet->payload_packet_len >= 8) {
u_int16_t i;
for (i = 5; i < (packet->payload_packet_len - 2); i++) {
// make shure that the argument to GIVE is numeric
if (!(packet->payload[i] >= '0' && packet->payload[i] <= '9')) {
goto exclude_fasttrack;
}
}
exclude_fasttrack:
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_LOG_INFO(ndpi_struct, "found FASTTRACK\n");
ndpi_int_fasttrack_add_connection(ndpi_struct, flow);
return;
}
if (packet->payload_packet_len > 50 && memcmp(packet->payload, "GET /", 5) == 0) {
u_int16_t a = 0;
NDPI_LOG_DBG2(ndpi_struct, "detected GET /. \n");
ndpi_parse_packet_line_info(ndpi_struct, flow);
for (a = 0; a < packet->parsed_lines; a++) {
if ((packet->line[a].len > 17 && memcmp(packet->line[a].ptr, "X-Kazaa-Username: ", 18) == 0)
|| (packet->line[a].len > 23 && memcmp(packet->line[a].ptr, "User-Agent: PeerEnabler/", 24) == 0)) {
NDPI_LOG_INFO(ndpi_struct,
"found FASTTRACK X-Kazaa-Username: || User-Agent: PeerEnabler/\n");
ndpi_int_fasttrack_add_connection(ndpi_struct, flow);
return;
}
}
}
}
exclude_fasttrack:
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
+1 -1
View File
@@ -2,7 +2,7 @@
* fiesta.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* fix.c
*
* Copyright (C) 2017-19 - ntop.org
* Copyright (C) 2017-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+1 -1
View File
@@ -2,7 +2,7 @@
* florensia.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* ftp_data.c
*
* Copyright (C) 2016-19 - ntop.org
* Copyright (C) 2016-20 - ntop.org
*
* The signature is based on the Libprotoident library.
*
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* git.c
*
* Copyright (C) 2012-19 - ntop.org
* Copyright (C) 2012-20 - ntop.org
*
* This module is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
+1 -1
View File
@@ -2,7 +2,7 @@
* gnutella.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* gtp.c
*
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* nDPI is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
+1 -1
View File
@@ -2,7 +2,7 @@
* guildwars.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+1 -1
View File
@@ -2,7 +2,7 @@
* halflife2_and_mods.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* hangout.c
*
* Copyright (C) 2012-19 - ntop.org
* Copyright (C) 2012-20 - ntop.org
*
* This module is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
+169 -156
View File
@@ -1,7 +1,7 @@
/*
* http.c
*
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
@@ -28,54 +28,112 @@
#include "ndpi_api.h"
#include <stdlib.h>
static void ndpi_int_http_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
u_int16_t category) {
#ifdef DEBUG
printf("[%s] [http_dont_dissect_response: %u]->> %s\n", __FUNCTION__,
ndpi_struct->http_dont_dissect_response, flow->http.response_status_code);
static void ndpi_search_http_tcp(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow);
/* *********************************************** */
static int ndpi_search_http_tcp_again(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
ndpi_search_http_tcp(ndpi_struct, flow);
#ifdef HTTP_DEBUG
printf("=> %s()\n", __FUNCTION__);
#endif
if(flow->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN) {
/* This is HTTP and it is not a sub protocol (e.g. skype or dropbox) */
if((flow->host_server_name[0] != '\0') && (flow->http.response_status_code != 0)) {
/* stop extra processing */
flow->extra_packets_func = NULL; /* We're good now */
return(0);
}
ndpi_search_tcp_or_udp(ndpi_struct, flow);
/* Possibly more processing */
return(1);
}
/* If no custom protocol has been detected */
if(flow->guessed_host_protocol_id != NDPI_PROTOCOL_UNKNOWN) {
ndpi_int_reset_protocol(flow);
flow->http_upper_protocol = flow->guessed_host_protocol_id, flow->http_lower_protocol = NDPI_PROTOCOL_HTTP;
} else
flow->http_upper_protocol = NDPI_PROTOCOL_HTTP, flow->http_lower_protocol = NDPI_PROTOCOL_UNKNOWN;
/* *********************************************** */
if(ndpi_struct->http_dont_dissect_response)
ndpi_set_detected_protocol(ndpi_struct, flow, flow->http_upper_protocol, flow->http_lower_protocol);
else {
flow->detected_protocol_stack[0] = NDPI_PROTOCOL_UNKNOWN, flow->detected_protocol_stack[1] = NDPI_PROTOCOL_UNKNOWN;
flow->packet.detected_protocol_stack[0] = NDPI_PROTOCOL_UNKNOWN, flow->packet.detected_protocol_stack[1] = NDPI_PROTOCOL_UNKNOWN;
/* https://www.freeformatter.com/mime-types-list.html */
static ndpi_protocol_category_t ndpi_http_check_content(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
if(packet->content_line.len > 0) {
u_int app_len = sizeof("application");
if(packet->content_line.len > app_len) {
if(ndpi_strncasestr((const char *)&packet->content_line.ptr[app_len], "mpeg",
packet->content_line.len-app_len) != NULL) {
flow->guessed_category = flow->category = NDPI_PROTOCOL_CATEGORY_STREAMING;
return(flow->category);
}
}
} else {
if((!ndpi_struct->http_dont_dissect_response) && (flow->http.response_status_code == 0)) {
flow->http_upper_protocol = flow->detected_protocol_stack[0], flow->http_lower_protocol = flow->detected_protocol_stack[1];
flow->detected_protocol_stack[0] = NDPI_PROTOCOL_UNKNOWN, flow->detected_protocol_stack[1] = NDPI_PROTOCOL_UNKNOWN;
flow->packet.detected_protocol_stack[0] = NDPI_PROTOCOL_UNKNOWN, flow->packet.detected_protocol_stack[1] = NDPI_PROTOCOL_UNKNOWN;
switch(packet->content_line.ptr[0]) {
case 'a':
if(strncasecmp((const char *)packet->content_line.ptr, "audio",
ndpi_min(packet->content_line.len, 5)) == 0)
flow->guessed_category = flow->category = NDPI_PROTOCOL_CATEGORY_MEDIA;
break;
case 'v':
if(strncasecmp((const char *)packet->content_line.ptr, "video",
ndpi_min(packet->content_line.len, 5)) == 0)
flow->guessed_category = flow->category = NDPI_PROTOCOL_CATEGORY_MEDIA;
break;
}
}
flow->http_detected = 1, flow->guessed_category = category;
return(flow->category);
}
/* *********************************************** */
static void ndpi_int_http_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
u_int16_t http_protocol,
ndpi_protocol_category_t category) {
#ifdef HTTP_DEBUG
printf("=> %s()\n", __FUNCTION__);
#endif
if(flow->extra_packets_func && (flow->guessed_host_protocol_id == NDPI_PROTOCOL_UNKNOWN))
return; /* Nothing new to add */
/* This is HTTP and it is not a sub protocol (e.g. skype or dropbox) */
ndpi_search_tcp_or_udp(ndpi_struct, flow);
/* If no custom protocol has been detected */
if((flow->guessed_host_protocol_id == NDPI_PROTOCOL_UNKNOWN) || (http_protocol != NDPI_PROTOCOL_HTTP))
flow->guessed_host_protocol_id = http_protocol;
category = ndpi_http_check_content(ndpi_struct, flow);
ndpi_int_reset_protocol(flow);
ndpi_set_detected_protocol(ndpi_struct, flow, flow->guessed_host_protocol_id, NDPI_PROTOCOL_HTTP);
/* This is necessary to inform the core to call this dissector again */
flow->check_extra_packets = 1;
flow->max_extra_packets_to_check = 5;
flow->extra_packets_func = ndpi_search_http_tcp_again;
flow->http_detected = 1, flow->guessed_category = flow->category = category;
}
/* ************************************************************* */
static void rtsp_parse_packet_acceptline(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
if(packet->accept_line.len >= 28 && memcmp(packet->accept_line.ptr, "application/x-rtsp-tunnelled", 28) == 0) {
if((packet->accept_line.len >= 28)
&& (memcmp(packet->accept_line.ptr, "application/x-rtsp-tunnelled", 28) == 0)) {
NDPI_LOG_INFO(ndpi_struct, "found RTSP accept line\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_RTSP);
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_RTSP, NDPI_PROTOCOL_CATEGORY_MEDIA);
}
}
/* ************************************************************* */
static void setHttpUserAgent(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow, char *ua) {
if ( !strcmp(ua, "Windows NT 5.0")) ua = "Windows 2000";
@@ -91,59 +149,50 @@ static void setHttpUserAgent(struct ndpi_detection_module_struct *ndpi_struct,
* https://github.com/ua-parser/uap-core/blob/master/regexes.yaml */
//printf("==> %s\n", ua);
if(!ndpi_struct->disable_metadata_export) {
snprintf((char*)flow->protos.http.detected_os, sizeof(flow->protos.http.detected_os), "%s", ua);
}
snprintf((char*)flow->protos.http.detected_os,
sizeof(flow->protos.http.detected_os), "%s", ua);
}
static void parseHttpSubprotocol(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
/* ************************************************************* */
static void ndpi_http_parse_subprotocol(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
if((flow->l4.tcp.http_stage == 0) || (flow->http.url && flow->http_detected)) {
char *double_col = strchr((char*)flow->host_server_name, ':');
ndpi_protocol_match_result ret_match;
if(double_col) double_col[0] = '\0';
/**
NOTE
If http_dont_dissect_response = 1 dissection of HTTP response
mime types won't happen
*/
ndpi_match_host_subprotocol(ndpi_struct, flow, (char *)flow->host_server_name,
strlen((const char *)flow->host_server_name),
&ret_match,
NDPI_PROTOCOL_HTTP);
ndpi_match_hostname_protocol(ndpi_struct, flow, NDPI_PROTOCOL_HTTP,
(char *)flow->host_server_name,
strlen((const char *)flow->host_server_name));
}
}
/* ************************************************************* */
/**
NOTE
ndpi_parse_packet_line_info is in ndpi_main.c
*/
static void check_content_type_and_change_protocol(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
if((!ndpi_struct->http_dont_dissect_response) && flow->http_detected && (flow->http.response_status_code != 0)) {
ndpi_set_detected_protocol(ndpi_struct, flow, flow->http_upper_protocol, flow->http_lower_protocol);
#ifdef DEBUG
printf("[%s] [http_dont_dissect_response: %u]->> %s\n",
__FUNCTION__, ndpi_struct->http_dont_dissect_response, flow->http.response_status_code);
#endif
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_HTTP, NDPI_PROTOCOL_UNKNOWN);
if(flow->http_detected && (flow->http.response_status_code != 0))
return;
}
#if defined(NDPI_PROTOCOL_1KXUN) || defined(NDPI_PROTOCOL_IQIYI)
/* PPStream */
if(flow->l4.tcp.ppstream_stage > 0 && flow->iqiyi_counter == 0) {
NDPI_LOG_INFO(ndpi_struct, "found PPStream\n");
/* ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_PPSTREAM); */
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_PPSTREAM, NDPI_PROTOCOL_HTTP);
}
else if(flow->iqiyi_counter > 0) {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_PPSTREAM,
NDPI_PROTOCOL_HTTP, NDPI_PROTOCOL_CATEGORY_STREAMING);
} else if(flow->iqiyi_counter > 0) {
NDPI_LOG_INFO(ndpi_struct, "found iQiyi\n");
/* ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_IQIYI); */
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_IQIYI, NDPI_PROTOCOL_HTTP);
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_IQIYI,
NDPI_PROTOCOL_HTTP, NDPI_PROTOCOL_CATEGORY_STREAMING);
}
#endif
@@ -151,14 +200,10 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
/* 1KXUN */
if(flow->kxun_counter > 0) {
NDPI_LOG_INFO(ndpi_struct, "found 1kxun\n");
/* ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_1KXUN); */
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_1KXUN, NDPI_PROTOCOL_HTTP);
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_1KXUN, NDPI_PROTOCOL_CATEGORY_STREAMING);
}
#endif
/* Leave the statement below commented necessary in case of call to ndpi_get_partial_detection() */
/* if(!ndpi_struct->http_dont_dissect_response) */ {
if((flow->http.url == NULL)
&& (packet->http_url_name.len > 0)
&& (packet->host_line.len > 0)) {
@@ -198,18 +243,6 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
}
}
if((flow->http.content_type == NULL) && (packet->content_line.len > 0)) {
int len = packet->content_line.len + 1;
flow->http.content_type = ndpi_malloc(len);
if(flow->http.content_type) {
strncpy(flow->http.content_type, (char*)packet->content_line.ptr,
packet->content_line.len);
flow->http.content_type[packet->content_line.len] = '\0';
}
}
}
if(packet->user_agent_line.ptr != NULL && packet->user_agent_line.len != 0) {
/**
Format examples:
@@ -267,14 +300,24 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
setHttpUserAgent(ndpi_struct, flow, token);
}
}
}
else if(memcmp(ua, "netflix-ios-app", 15) == 0) {
} else if((packet->user_agent_line.len > 14) && (memcmp(ua, "netflix-ios-app", 15) == 0)) {
NDPI_LOG_INFO(ndpi_struct, "found netflix\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_NETFLIX);
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_NETFLIX, NDPI_PROTOCOL_CATEGORY_STREAMING);
return;
}
}
if(flow->http.user_agent == NULL) {
int len = packet->user_agent_line.len + 1;
flow->http.user_agent = ndpi_malloc(len);
if(flow->http.user_agent) {
strncpy(flow->http.user_agent, (char*)packet->user_agent_line.ptr,
packet->user_agent_line.len);
flow->http.user_agent[packet->user_agent_line.len] = '\0';
}
}
NDPI_LOG_DBG2(ndpi_struct, "User Agent Type line found %.*s\n",
packet->user_agent_line.len, packet->user_agent_line.ptr);
}
@@ -286,36 +329,21 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
NDPI_LOG_DBG2(ndpi_struct, "HOST line found %.*s\n",
packet->host_line.len, packet->host_line.ptr);
/* call ndpi_match_host_subprotocol to see if there is a match with known-host HTTP subprotocol */
if((ndpi_struct->http_dont_dissect_response) || flow->http_detected) {
ndpi_protocol_match_result ret_match;
ndpi_match_host_subprotocol(ndpi_struct, flow,
(char*)packet->host_line.ptr,
packet->host_line.len,
&ret_match,
NDPI_PROTOCOL_HTTP);
}
/* Copy result for nDPI apps */
if(!ndpi_struct->disable_metadata_export) {
len = ndpi_min(packet->host_line.len, sizeof(flow->host_server_name)-1);
strncpy((char*)flow->host_server_name, (char*)packet->host_line.ptr, len);
flow->host_server_name[len] = '\0';
}
len = ndpi_min(packet->host_line.len, sizeof(flow->host_server_name)-1);
strncpy((char*)flow->host_server_name, (char*)packet->host_line.ptr, len);
flow->host_server_name[len] = '\0';
flow->extra_packets_func = NULL; /* We're good now */
flow->server_id = flow->dst;
if(packet->forwarded_line.ptr) {
len = ndpi_min(packet->forwarded_line.len, sizeof(flow->protos.http.nat_ip)-1);
if(!ndpi_struct->disable_metadata_export) {
strncpy((char*)flow->protos.http.nat_ip, (char*)packet->forwarded_line.ptr, len);
flow->protos.http.nat_ip[len] = '\0';
}
strncpy((char*)flow->protos.http.nat_ip, (char*)packet->forwarded_line.ptr, len);
flow->protos.http.nat_ip[len] = '\0';
}
if(!ndpi_struct->http_dont_dissect_response)
parseHttpSubprotocol(ndpi_struct, flow);
ndpi_http_parse_subprotocol(ndpi_struct, flow);
/**
check result of host subprotocol detection
@@ -339,7 +367,7 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
}
if((flow->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN)
&& ((ndpi_struct->http_dont_dissect_response) || flow->http_detected)
&& (flow->http_detected)
&& (packet->http_origin.len > 0)) {
ndpi_protocol_match_result ret_match;
@@ -354,15 +382,15 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
if(packet->detected_protocol_stack[0] != NDPI_PROTOCOL_HTTP) {
NDPI_LOG_INFO(ndpi_struct, "found HTTP/%s\n",
ndpi_get_proto_name(ndpi_struct, packet->detected_protocol_stack[0]));
ndpi_int_http_add_connection(ndpi_struct, flow, packet->detected_protocol_stack[0]);
ndpi_int_http_add_connection(ndpi_struct, flow, packet->detected_protocol_stack[0], NDPI_PROTOCOL_CATEGORY_WEB);
return; /* We have identified a sub-protocol so we're done */
}
}
}
#if 0
if(!ndpi_struct->http_dont_dissect_response && flow->http_detected)
parseHttpSubprotocol(ndpi_struct, flow);
if(flow->http_detected)
ndpi_http_parse_subprotocol(ndpi_struct, flow);
#endif
if(flow->guessed_protocol_id == NDPI_PROTOCOL_UNKNOWN)
@@ -382,7 +410,18 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
NDPI_LOG_DBG2(ndpi_struct, "Content Type line found %.*s\n",
packet->content_line.len, packet->content_line.ptr);
if((ndpi_struct->http_dont_dissect_response) || flow->http_detected) {
if((flow->http.content_type == NULL) && (packet->content_line.len > 0)) {
int len = packet->content_line.len + 1;
flow->http.content_type = ndpi_malloc(len);
if(flow->http.content_type) {
strncpy(flow->http.content_type, (char*)packet->content_line.ptr,
packet->content_line.len);
flow->http.content_type[packet->content_line.len] = '\0';
}
}
if(flow->http_detected) {
ndpi_protocol_match_result ret_match;
ndpi_match_content_subprotocol(ndpi_struct, flow,
@@ -391,13 +430,17 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
}
}
ndpi_int_http_add_connection(ndpi_struct, flow, packet->detected_protocol_stack[0]);
ndpi_int_http_add_connection(ndpi_struct, flow, packet->detected_protocol_stack[0], NDPI_PROTOCOL_CATEGORY_WEB);
}
/* ************************************************************* */
static void check_http_payload(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
/* Add here your paylod code check */
}
/* ************************************************************* */
/**
* Functions to check whether the packet begins with a valid http request
* @param ndpi_struct
@@ -434,7 +477,7 @@ static u_int16_t http_request_url_offset(struct ndpi_detection_module_struct *nd
packet->payload_packet_len);
/* Check first char */
if(!strchr(http_fs,packet->payload[0])) return 0;
if(!packet->payload_packet_len || !strchr(http_fs,packet->payload[0])) return 0;
/**
FIRST PAYLOAD PACKET FROM CLIENT
**/
@@ -490,7 +533,7 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
flow->http.response_status_code = 0; /* Out of range */
}
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_HTTP);
ndpi_parse_packet_line_info(ndpi_struct, flow);
check_content_type_and_change_protocol(ndpi_struct, flow);
return;
}
@@ -528,7 +571,7 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
</cross-domain-policy>
*/
ookla_found:
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_OOKLA, NDPI_PROTOCOL_UNKNOWN);
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_OOKLA, NDPI_PROTOCOL_CATEGORY_WEB);
if(ndpi_struct->ookla_cache == NULL)
ndpi_struct->ookla_cache = ndpi_lru_cache_init(1024);
@@ -592,32 +635,12 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
goto ookla_found;
}
/* Check for additional field introduced by Steam */
int x = 1;
if(packet->line[x].len >= 11 && (memcmp(packet->line[x].ptr, "x-steam-sid", 11)) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found STEAM\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_STEAM);
check_content_type_and_change_protocol(ndpi_struct, flow);
return;
}
/* Check for additional field introduced by Facebook */
x = 1;
while(packet->line[x].len != 0) {
if(packet->line[x].len >= 12 && (memcmp(packet->line[x].ptr, "X-FB-SIM-HNI", 12)) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found FACEBOOK\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_FACEBOOK);
check_content_type_and_change_protocol(ndpi_struct, flow);
return;
}
x++;
}
#if defined(NDPI_PROTOCOL_1KXUN) || defined(NDPI_PROTOCOL_IQIYI)
/* check PPStream protocol or iQiyi service
(iqiyi is delivered by ppstream) */
// substring in url
if(ndpi_strnstr((const char*) &packet->payload[filename_start], "iqiyi.com", (packet->payload_packet_len - filename_start)) != NULL) {
if(ndpi_strnstr((const char*) &packet->payload[filename_start], "iqiyi.com",
(packet->payload_packet_len - filename_start)) != NULL) {
if(flow->kxun_counter == 0) {
flow->l4.tcp.ppstream_stage++;
flow->iqiyi_counter++;
@@ -659,14 +682,14 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
if((packet->http_url_name.len > 7)
&& (!strncmp((const char*) packet->http_url_name.ptr, "http://", 7))) {
NDPI_LOG_INFO(ndpi_struct, "found HTTP_PROXY\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_HTTP_PROXY);
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_HTTP_PROXY, NDPI_PROTOCOL_CATEGORY_WEB);
check_content_type_and_change_protocol(ndpi_struct, flow);
}
if(filename_start == 8 && (memcmp(packet->payload, "CONNECT ", 8) == 0)) {
/* nathan@getoffmalawn.com */
NDPI_LOG_INFO(ndpi_struct, "found HTTP_CONNECT\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_HTTP_CONNECT);
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_HTTP_CONNECT, NDPI_PROTOCOL_CATEGORY_WEB);
check_content_type_and_change_protocol(ndpi_struct, flow);
}
@@ -681,17 +704,11 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
in 99.99% of the cases is like that.
*/
if(ndpi_struct->http_dont_dissect_response) {
if(flow->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN) /* No subprotocol found */
NDPI_LOG_INFO(ndpi_struct, "found HTTP\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_HTTP);
} else {
flow->http_detected = 1;
NDPI_LOG_DBG2(ndpi_struct,
"HTTP START Found, we will look further for the response...\n");
flow->l4.tcp.http_stage = packet->packet_direction + 1; // packet_direction 0: stage 1, packet_direction 1: stage 2
}
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_HTTP, NDPI_PROTOCOL_CATEGORY_WEB);
flow->http_detected = 1;
NDPI_LOG_DBG2(ndpi_struct,
"HTTP START Found, we will look further for the response...\n");
flow->l4.tcp.http_stage = packet->packet_direction + 1; // packet_direction 0: stage 1, packet_direction 1: stage 2
check_content_type_and_change_protocol(ndpi_struct, flow);
return;
}
@@ -715,7 +732,8 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_OOKLA);
/**
At first check, if this is for sure a response packet (in another direction. If not, if HTTP is detected do nothing now and return,
At first check, if this is for sure a response packet
(in another direction. If not, if HTTP is detected do nothing now and return,
otherwise check the second packet for the HTTP request
*/
if((flow->l4.tcp.http_stage - packet->packet_direction) == 1) { /* Expected a response package */
@@ -749,7 +767,7 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
&& memcmp(&packet->line[0].ptr[packet->line[0].len - 9], " HTTP/1.", 8) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found HTTP\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_HTTP);
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_HTTP, NDPI_PROTOCOL_CATEGORY_WEB);
check_content_type_and_change_protocol(ndpi_struct, flow);
NDPI_LOG_DBG2(ndpi_struct,
@@ -771,7 +789,7 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
if((packet->parsed_lines == 1) && (packet->packet_direction == 1 /* server -> client */)) {
/* In Apache if you do "GET /\n\n" the response comes without any header */
NDPI_LOG_INFO(ndpi_struct, "found HTTP. (apache)\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_HTTP);
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_HTTP, NDPI_PROTOCOL_CATEGORY_WEB);
check_content_type_and_change_protocol(ndpi_struct, flow);
return;
}
@@ -779,7 +797,7 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
/* If we already detected the HTTP request, we can add the connection and then check for the sub-protocol */
if(flow->http_detected) {
NDPI_LOG_INFO(ndpi_struct, "found HTTP\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_HTTP);
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_HTTP, NDPI_PROTOCOL_CATEGORY_WEB);
}
/* Parse packet line and we look for the subprotocols */
@@ -799,10 +817,10 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
}
}
void ndpi_search_http_tcp(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
/* ********************************* */
static void ndpi_search_http_tcp(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
/* Break after 20 packets. */
if(flow->packet_counter > 20) {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
@@ -810,10 +828,6 @@ void ndpi_search_http_tcp(struct ndpi_detection_module_struct *ndpi_struct,
return;
}
if(packet->detected_protocol_stack[0] != NDPI_PROTOCOL_UNKNOWN) {
return;
}
NDPI_LOG_DBG(ndpi_struct, "search HTTP\n");
ndpi_check_http_tcp(ndpi_struct, flow);
}
@@ -850,8 +864,7 @@ char* ndpi_get_http_content_type(struct ndpi_detection_module_struct *ndpi_mod,
void init_http_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id,
NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
NDPI_PROTOCOL_BITMASK *detection_bitmask) {
ndpi_set_bitmask_protocol_detection("HTTP",ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_HTTP,
ndpi_search_http_tcp,
+1 -1
View File
@@ -2,7 +2,7 @@
* http_activesync.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+1 -1
View File
@@ -2,7 +2,7 @@
* iax.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+2 -2
View File
@@ -2,7 +2,7 @@
* icecast.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
@@ -36,7 +36,7 @@ static void ndpi_int_icecast_add_connection(struct ndpi_detection_module_struct
void ndpi_search_icecast_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
u_int8_t i;
u_int16_t i;
NDPI_LOG_DBG(ndpi_struct, "search icecast\n");
+38 -20
View File
@@ -2,45 +2,63 @@
* iec60870-5-104.c
* Extension for industrial 104 protocol recognition
*
* Created by Cesar HM
* Created by Cesar HM <cesar91hoyos@gmail.com>
*
* Copyright (C) 2019 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
*
* nDPI is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* nDPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with nDPI. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ndpi_protocol_ids.h"
#include "ndpi_api.h"
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_104
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_IEC60870
void ndpi_search_104_tcp(struct ndpi_detection_module_struct *ndpi_struct,
void ndpi_search_iec60870_tcp(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search 104\n");
u_int16_t iec104_port = htons(2404); // port used by 104
u_int16_t iec104_port = htons(2404); // port used by IEC60870
/* Check connection over TCP */
NDPI_LOG_DBG(ndpi_struct, "search IEC60870\n");
if(packet->tcp) {
/* The start byte of 104 is 0x68
* The usual port: 2404
*/
if ( packet->payload[0] == 0x68 &&
((packet->tcp->dest == iec104_port) || (packet->tcp->source == iec104_port)) ){
NDPI_LOG_INFO(ndpi_struct, "found 104\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_104, NDPI_PROTOCOL_UNKNOWN);
return;
}
*/
if((packet->payload[0] == 0x68) &&
((packet->tcp->dest == iec104_port) || (packet->tcp->source == iec104_port)) ){
NDPI_LOG_INFO(ndpi_struct, "found 104\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_IEC60870, NDPI_PROTOCOL_UNKNOWN);
return;
}
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
void init_104_dissector(struct ndpi_detection_module_struct *ndpi_struct,
u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask) {
ndpi_set_bitmask_protocol_detection("104", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_104,
ndpi_search_104_tcp,
u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask) {
ndpi_set_bitmask_protocol_detection("IEC60870", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_IEC60870,
ndpi_search_iec60870_tcp,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);
+1 -1
View File
@@ -2,7 +2,7 @@
* ipp.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+3 -2
View File
@@ -2,7 +2,7 @@
* irc.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
@@ -492,9 +492,10 @@ void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
ndpi_parse_packet_line_info(ndpi_struct, flow);
} else {
flow->l4.tcp.irc_3a_counter++;
packet->parsed_lines = 0;
}
for (i = 0; i < packet->parsed_lines; i++) {
if (packet->line[i].ptr[0] == ':') {
if ((packet->line[i].len > 0) && packet->line[i].ptr[0] == ':') {
flow->l4.tcp.irc_3a_counter++;
if (flow->l4.tcp.irc_3a_counter == 7) { /* ':' == 0x3a */
NDPI_LOG_INFO(ndpi_struct, "found irc. 0x3a. seven times.");
+1 -1
View File
@@ -2,7 +2,7 @@
* jabber.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* kakaotalk_voice.c
*
* Copyright (C) 2015-19 - ntop.org
* Copyright (C) 2015-20 - ntop.org
*
* This module is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
+366 -29
View File
@@ -1,8 +1,8 @@
/*
* kerberos.c
*
* Copyright (C) 2011-20 - ntop.org
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
@@ -19,7 +19,7 @@
*
* You should have received a copy of the GNU Lesser General Public License
* along with nDPI. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
#include "ndpi_protocol_ids.h"
@@ -28,53 +28,390 @@
#include "ndpi_api.h"
/* #define KERBEROS_DEBUG 1 */
#define KERBEROS_PORT 88
static void ndpi_int_kerberos_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow)
{
struct ndpi_flow_struct *flow) {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_KERBEROS, NDPI_PROTOCOL_UNKNOWN);
NDPI_LOG_DBG(ndpi_struct, "trace KERBEROS\n");
}
/* ************************************************* */
void ndpi_search_kerberos(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
void ndpi_search_kerberos(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
u_int16_t sport = packet->tcp ? ntohs(packet->tcp->source) : ntohs(packet->udp->source);
u_int16_t dport = packet->tcp ? ntohs(packet->tcp->dest) : ntohs(packet->udp->dest);
NDPI_LOG_DBG(ndpi_struct, "search KERBEROS\n");
if((sport != KERBEROS_PORT) && (dport != KERBEROS_PORT)) {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
}
NDPI_LOG_DBG(ndpi_struct, "search KERBEROS\n");
/* I have observed 0a,0c,0d,0e at packet->payload[19/21], maybe there are other possibilities */
if (packet->payload_packet_len >= 4 && ntohl(get_u_int32_t(packet->payload, 0)) == packet->payload_packet_len - 4) {
if (packet->payload_packet_len > 19 &&
packet->payload[14] == 0x05 &&
(packet->payload[19] == 0x0a ||
packet->payload[19] == 0x0c || packet->payload[19] == 0x0d || packet->payload[19] == 0x0e)) {
ndpi_int_kerberos_add_connection(ndpi_struct, flow);
return;
#ifdef KERBEROS_DEBUG
printf("\n[Kerberos] Process packet [len: %u]\n", packet->payload_packet_len);
#endif
if(flow->kerberos_buf.pktbuf != NULL) {
u_int missing = flow->kerberos_buf.pktbuf_maxlen - flow->kerberos_buf.pktbuf_currlen;
}
if (packet->payload_packet_len > 21 &&
packet->payload[16] == 0x05 &&
(packet->payload[21] == 0x0a ||
packet->payload[21] == 0x0c || packet->payload[21] == 0x0d || packet->payload[21] == 0x0e)) {
ndpi_int_kerberos_add_connection(ndpi_struct, flow);
return;
if(packet->payload_packet_len <= missing) {
memcpy(&flow->kerberos_buf.pktbuf[flow->kerberos_buf.pktbuf_currlen], packet->payload, packet->payload_packet_len);
flow->kerberos_buf.pktbuf_currlen += packet->payload_packet_len;
}
if(flow->kerberos_buf.pktbuf_currlen == flow->kerberos_buf.pktbuf_maxlen) {
packet->payload = (u_int8_t *)flow->kerberos_buf.pktbuf;
packet->payload_packet_len = flow->kerberos_buf.pktbuf_currlen;
#ifdef KERBEROS_DEBUG
printf("[Kerberos] Packet is now full: processing\n");
#endif
} else {
#ifdef KERBEROS_DEBUG
printf("[Kerberos] Missing %u bytes: skipping\n",
flow->kerberos_buf.pktbuf_maxlen - flow->kerberos_buf.pktbuf_currlen);
#endif
return;
}
}
}
/* I have observed 0a,0c,0d,0e at packet->payload[19/21], maybe there are other possibilities */
if(packet->payload_packet_len >= 4) {
u_int32_t kerberos_len, expected_len;
u_int16_t base_offset = 0;
if(packet->tcp) {
kerberos_len = ntohl(get_u_int32_t(packet->payload, 0)),
expected_len = packet->payload_packet_len - 4;
base_offset = 4;
} else
base_offset = 0, kerberos_len = expected_len = packet->payload_packet_len;
#ifdef KERBEROS_DEBUG
printf("[Kerberos] [Kerberos len: %u][expected_len: %u]\n", kerberos_len, expected_len);
#endif
if(kerberos_len < 12000) {
/*
Kerberos packets might be too long for a TCP packet
so it could be split across two packets. Instead of
rebuilding the stream we use a heuristic approach
*/
if(kerberos_len > expected_len) {
if(packet->tcp) {
if(flow->kerberos_buf.pktbuf == NULL) {
flow->kerberos_buf.pktbuf = (char*)ndpi_malloc(kerberos_len+4);
if(flow->kerberos_buf.pktbuf != NULL) {
flow->kerberos_buf.pktbuf_maxlen = kerberos_len+4;
#ifdef KERBEROS_DEBUG
printf("[Kerberos] Allocated %u bytes\n", flow->kerberos_buf.pktbuf_maxlen);
#endif
}
}
if(flow->kerberos_buf.pktbuf != NULL) {
if(packet->payload_packet_len <= flow->kerberos_buf.pktbuf_maxlen) {
memcpy(flow->kerberos_buf.pktbuf, packet->payload, packet->payload_packet_len);
flow->kerberos_buf.pktbuf_currlen = packet->payload_packet_len;
}
}
}
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
} else if(kerberos_len == expected_len) {
if(packet->payload_packet_len > 128) {
u_int16_t koffset, i;
for(i=8; i<16; i++)
if((packet->payload[base_offset+i] == 0x03)
&& (packet->payload[base_offset+i+1] == 0x02)
&& (packet->payload[base_offset+i+2] == 0x01)
&& (packet->payload[base_offset+i+3] != 0x05)
)
break;
koffset = base_offset + i + 3;
#ifdef KERBEROS_DEBUG
printf("[Kerberos] [msg-type: 0x%02X/%u][koffset: %u]\n",
packet->payload[koffset], packet->payload[koffset], koffset);
#endif
if(((packet->payload[koffset] == 0x0A)
|| (packet->payload[koffset] == 0x0C)
|| (packet->payload[koffset] == 0x0D)
|| (packet->payload[koffset] == 0x0E))) {
u_int16_t koffsetp, body_offset, pad_len;
u_int8_t msg_type = packet->payload[koffset];
#ifdef KERBEROS_DEBUG
printf("[Kerberos] Packet found 0x%02X/%u\n", msg_type, msg_type);
#endif
if(msg_type != 0x0d) /* TGS-REP */ {
/* Process only on requests */
if(packet->payload[koffset+1] == 0xA3) {
if(packet->payload[koffset+3] == 0x30)
pad_len = packet->payload[koffset+4];
else {
/* Long pad */
pad_len = packet->payload[koffset+2];
for(i=3; i<10; i++) if(packet->payload[koffset+i] == pad_len) break;
pad_len = (packet->payload[koffset+i+1] << 8) + packet->payload[koffset+i+2];
koffset += i-2;
}
} else
pad_len = 0;
#ifdef KERBEROS_DEBUG
printf("pad_len=0x%02X/%u\n", pad_len, pad_len);
#endif
if(pad_len > 0) {
koffsetp = koffset + 2;
for(i=0; i<4; i++) if(packet->payload[koffsetp] != 0x30) koffsetp++; /* ASN.1 */
#ifdef KERBEROS_DEBUG
printf("koffsetp=%u [%02X %02X] [byte 0 must be 0x30]\n", koffsetp, packet->payload[koffsetp], packet->payload[koffsetp+1]);
#endif
} else
koffsetp = koffset;
body_offset = koffsetp + 1 + pad_len;
for(i=0; i<10; i++) if(packet->payload[body_offset] != 0x05) body_offset++; /* ASN.1 */
#ifdef KERBEROS_DEBUG
printf("body_offset=%u [%02X %02X] [byte 0 must be 0x05]\n", body_offset, packet->payload[body_offset], packet->payload[body_offset+1]);
#endif
}
if(msg_type == 0x0A) /* AS-REQ */ {
#ifdef KERBEROS_DEBUG
printf("[Kerberos] Processing AS-REQ\n");
#endif
if(body_offset < packet->payload_packet_len) {
u_int16_t name_offset;
name_offset = body_offset + 13;
for(i=0; i<20; i++) if(packet->payload[name_offset] != 0x1b) name_offset++; /* ASN.1 */
#ifdef KERBEROS_DEBUG
printf("name_offset=%u [%02X %02X] [byte 0 must be 0x1b]\n", name_offset, packet->payload[name_offset], packet->payload[name_offset+1]);
#endif
if(name_offset < packet->payload_packet_len) {
u_int cname_len;
name_offset += 1;
if(packet->payload[name_offset+1] < ' ') /* Isn't printable ? */
name_offset++;
if(packet->payload[name_offset+1] == 0x1b)
name_offset += 2;
cname_len = packet->payload[name_offset];
if((cname_len+name_offset) < packet->payload_packet_len) {
u_int realm_len, realm_offset;
char cname_str[48];
u_int8_t num_cname = 0;
while(++num_cname <= 2) {
if(cname_len > sizeof(cname_str)-1)
cname_len = sizeof(cname_str)-1;
strncpy(cname_str, (char*)&packet->payload[name_offset+1], cname_len);
cname_str[cname_len] = '\0';
for(i=0; i<cname_len; i++) cname_str[i] = tolower(cname_str[i]);
#ifdef KERBEROS_DEBUG
printf("[AS-REQ][s/dport: %u/%u][Kerberos Cname][len: %u][%s]\n", sport, dport, cname_len, cname_str);
#endif
if(((strcmp(cname_str, "host") == 0) || (strcmp(cname_str, "ldap") == 0)) && (packet->payload[name_offset+1+cname_len] == 0x1b)) {
name_offset += cname_len + 2;
cname_len = packet->payload[name_offset];
} else
break;
}
realm_offset = cname_len + name_offset + 3;
/* if cname does not end with a $ then it's a username */
if(cname_len && cname_str[cname_len-1] == '$') {
cname_str[cname_len-1] = '\0';
snprintf(flow->protos.kerberos.hostname, sizeof(flow->protos.kerberos.hostname), "%s", cname_str);
} else
snprintf(flow->protos.kerberos.username, sizeof(flow->protos.kerberos.username), "%s", cname_str);
for(i=0; i<14; i++) if(packet->payload[realm_offset] != 0x1b) realm_offset++; /* ASN.1 */
#ifdef KERBEROS_DEBUG
printf("realm_offset=%u [%02X %02X] [byte 0 must be 0x1b]\n", realm_offset, packet->payload[realm_offset], packet->payload[realm_offset+1]);
#endif
realm_offset += 1;
//if(num_cname == 2) realm_offset++;
realm_len = packet->payload[realm_offset];
if((realm_offset+realm_len) < packet->payload_packet_len) {
char realm_str[48];
if(realm_len > sizeof(realm_str)-1)
realm_len = sizeof(realm_str)-1;
realm_offset += 1;
strncpy(realm_str, (char*)&packet->payload[realm_offset], realm_len);
realm_str[realm_len] = '\0';
for(i=0; i<realm_len; i++) realm_str[i] = tolower(realm_str[i]);
#ifdef KERBEROS_DEBUG
printf("[AS-REQ][Kerberos Realm][len: %u][%s]\n", realm_len, realm_str);
#endif
snprintf(flow->protos.kerberos.domain, sizeof(flow->protos.kerberos.domain), "%s", realm_str);
}
}
}
}
} else if(msg_type == 0x0c) /* TGS-REQ */ {
#ifdef KERBEROS_DEBUG
printf("[Kerberos] Processing TGS-REQ\n");
#endif
if(body_offset < packet->payload_packet_len) {
u_int name_offset, padding_offset = body_offset + 4;
name_offset = padding_offset;
for(i=0; i<14; i++) if(packet->payload[name_offset] != 0x1b) name_offset++; /* ASN.1 */
#ifdef KERBEROS_DEBUG
printf("name_offset=%u [%02X %02X] [byte 0 must be 0x1b]\n", name_offset, packet->payload[name_offset], packet->payload[name_offset+1]);
#endif
if(name_offset < packet->payload_packet_len) {
u_int realm_len;
name_offset++;
realm_len = packet->payload[name_offset];
if((realm_len+name_offset) < packet->payload_packet_len) {
char realm_str[48];
if(realm_len > sizeof(realm_str)-1)
realm_len = sizeof(realm_str)-1;
name_offset += 1;
strncpy(realm_str, (char*)&packet->payload[name_offset], realm_len);
realm_str[realm_len] = '\0';
for(i=0; i<realm_len; i++) realm_str[i] = tolower(realm_str[i]);
#ifdef KERBEROS_DEBUG
printf("[TGS-REQ][s/dport: %u/%u][Kerberos Realm][len: %u][%s]\n", sport, dport, realm_len, realm_str);
#endif
snprintf(flow->protos.kerberos.domain, sizeof(flow->protos.kerberos.domain), "%s", realm_str);
/* If necessary we can decode sname */
if(flow->kerberos_buf.pktbuf) ndpi_free(flow->kerberos_buf.pktbuf);
flow->kerberos_buf.pktbuf = NULL;
}
}
}
if(packet->udp)
ndpi_int_kerberos_add_connection(ndpi_struct, flow);
/* We set the protocol in the response */
if(flow->kerberos_buf.pktbuf != NULL) {
ndpi_free(flow->kerberos_buf.pktbuf);
flow->kerberos_buf.pktbuf = NULL;
}
return;
} else if(msg_type == 0x0d) /* TGS-REP */ {
u_int16_t pad_data_len, cname_offset;
#ifdef KERBEROS_DEBUG
printf("[Kerberos] Processing TGS-REP\n");
#endif
koffsetp = koffset + 4;
pad_data_len = packet->payload[koffsetp];
/* Skip realm already filled in request */
cname_offset = pad_data_len + koffsetp + 15;
if(cname_offset < packet->payload_packet_len) {
u_int8_t cname_len = packet->payload[cname_offset];
if((cname_offset+cname_offset) < packet->payload_packet_len) {
char cname_str[48];
if(cname_len > sizeof(cname_str)-1)
cname_len = sizeof(cname_str)-1;
strncpy(cname_str, (char*)&packet->payload[cname_offset+1], cname_len);
cname_str[cname_len] = '\0';
for(i=0; i<cname_len; i++) cname_str[i] = tolower(cname_str[i]);
#ifdef KERBEROS_DEBUG
printf("[TGS-REP][s/dport: %u/%u][Kerberos Cname][len: %u][%s]\n",
sport, dport, cname_len, cname_str);
#endif
if(cname_len && cname_str[cname_len-1] == '$') {
cname_str[cname_len-1] = '\0';
snprintf(flow->protos.kerberos.hostname, sizeof(flow->protos.kerberos.hostname), "%s", cname_str);
} else
snprintf(flow->protos.kerberos.username, sizeof(flow->protos.kerberos.username), "%s", cname_str);
ndpi_int_kerberos_add_connection(ndpi_struct, flow);
}
}
}
return;
}
if(packet->payload_packet_len > 21 &&
packet->payload[16] == 0x05 &&
(packet->payload[21] == 0x0a ||
packet->payload[21] == 0x0c || packet->payload[21] == 0x0d || packet->payload[21] == 0x0e)) {
ndpi_int_kerberos_add_connection(ndpi_struct, flow);
return;
}
}
}
} else {
#ifdef KERBEROS_DEBUG
printf("[Kerberos][s/dport: %u/%u] Skipping packet: too long [kerberos_len: %u]\n",
sport, dport, kerberos_len);
#endif
if(flow->protos.kerberos.domain[0] != '\0')
return;
}
}
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
void init_kerberos_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
void init_kerberos_dissector(struct ndpi_detection_module_struct *ndpi_struct,
u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask) {
ndpi_set_bitmask_protocol_detection("Kerberos", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_KERBEROS,
ndpi_search_kerberos,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_OR_UDP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);
*id += 1;
}
+1 -1
View File
@@ -2,7 +2,7 @@
* kontiki.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+1 -1
View File
@@ -2,7 +2,7 @@
* ldap.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
-70
View File
@@ -1,70 +0,0 @@
/*
* line.c
*
* Copyright (C) 2019 - ntop.org
*
* nDPI is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* nDPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with nDPI. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ndpi_protocol_ids.h"
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_LINE
#include "ndpi_api.h"
static void ndpi_line_report_protocol(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
/* printf("-> payload_len=%u\n", flow->packet.payload_packet_len); */
NDPI_LOG_INFO(ndpi_struct, "found line\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_LINE, NDPI_PROTOCOL_LINE);
}
void ndpi_search_line(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search line\n");
if (packet->iph) {
/* 125.209.252.xxx */
if (((ntohl(packet->iph->saddr) & 0xFFFFFF00 /* 255.255.255.0 */) == 0x7DD1FC00) ||
((ntohl(packet->iph->daddr) & 0xFFFFFF00 /* 255.255.255.0 */) == 0x7DD1FC00)) {
if ((packet->payload_packet_len == 110) && (flow->packet.payload[0] == 0xB6) &&
(flow->packet.payload[1] == 0x18) && (flow->packet.payload[2] == 0x00) &&
(flow->packet.payload[3] == 0x6A)) {
ndpi_line_report_protocol(ndpi_struct, flow);
return;
}
}
}
if ((packet->payload_packet_len == 46 && ntohl(get_u_int32_t(packet->payload, 0)) == 0xb6130006) ||
(packet->payload_packet_len == 8 && ntohl(get_u_int32_t(packet->payload, 0)) == 0xb6070004) ||
(packet->payload_packet_len == 16 && ntohl(get_u_int32_t(packet->payload, 0)) == 0xb609000c)) {
ndpi_line_report_protocol(ndpi_struct, flow);
return;
}
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
void init_line_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
ndpi_set_bitmask_protocol_detection("Line", ndpi_struct, detection_bitmask, *id, NDPI_PROTOCOL_LINE,
ndpi_search_line, NDPI_SELECTION_BITMASK_PROTOCOL_UDP_WITH_PAYLOAD,
SAVE_DETECTION_BITMASK_AS_UNKNOWN, ADD_TO_DETECTION_BITMASK);
*id += 1;
}
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* list.c
*
* Copyright (C) 2017-19 - ntop.org
* Copyright (C) 2017-20 - ntop.org
*
* nDPI is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* lotus_notes.c
*
* Copyright (C) 2012-19 - ntop.org
* Copyright (C) 2012-20 - ntop.org
*
* nDPI is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
+93 -46
View File
@@ -1,7 +1,7 @@
/*
* mail_imap.c
*
* Copyright (C) 2016-19 - ntop.org
* Copyright (C) 2016-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
@@ -28,6 +28,7 @@
#include "ndpi_api.h"
/* #define IMAP_DEBUG 1*/
static void ndpi_int_mail_imap_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
@@ -44,17 +45,21 @@ void ndpi_search_mail_imap_tcp(struct ndpi_detection_module_struct *ndpi_struct,
/* const u_int8_t *command = 0; */
NDPI_LOG_DBG(ndpi_struct, "search IMAP_IMAP\n");
if (flow->l4.tcp.mail_imap_starttls == 2) {
#ifdef IMAP_DEBUG
printf("%s() [%s]\n", __FUNCTION__, packet->payload);
#endif
if(flow->l4.tcp.mail_imap_starttls == 2) {
NDPI_LOG_DBG2(ndpi_struct, "starttls detected\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MAIL_IMAP);
NDPI_DEL_PROTOCOL_FROM_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_TLS);
return;
}
if (packet->payload_packet_len >= 4 && ntohs(get_u_int16_t(packet->payload, packet->payload_packet_len - 2)) == 0x0d0a) {
if(packet->payload_packet_len >= 4 && ntohs(get_u_int16_t(packet->payload, packet->payload_packet_len - 2)) == 0x0d0a) {
// the DONE command appears without a tag
if (packet->payload_packet_len == 6 && ((packet->payload[0] == 'D' || packet->payload[0] == 'd')
if(packet->payload_packet_len == 6 && ((packet->payload[0] == 'D' || packet->payload[0] == 'd')
&& (packet->payload[1] == 'O' || packet->payload[1] == 'o')
&& (packet->payload[2] == 'N' || packet->payload[2] == 'n')
&& (packet->payload[3] == 'E' || packet->payload[3] == 'e'))) {
@@ -62,37 +67,37 @@ void ndpi_search_mail_imap_tcp(struct ndpi_detection_module_struct *ndpi_struct,
saw_command = 1;
} else {
if (flow->l4.tcp.mail_imap_stage < 4) {
if(flow->l4.tcp.mail_imap_stage < 4) {
// search for the first space character (end of the tag)
while (i < 20 && i < packet->payload_packet_len) {
if (i > 0 && packet->payload[i] == ' ') {
if(i > 0 && packet->payload[i] == ' ') {
space_pos = i;
break;
}
if (!((packet->payload[i] >= 'a' && packet->payload[i] <= 'z') ||
if(!((packet->payload[i] >= 'a' && packet->payload[i] <= 'z') ||
(packet->payload[i] >= 'A' && packet->payload[i] <= 'Z') ||
(packet->payload[i] >= '0' && packet->payload[i] <= '9') || packet->payload[i] == '*' || packet->payload[i] == '.')) {
goto imap_excluded;
}
i++;
}
if (space_pos == 0 || space_pos == (packet->payload_packet_len - 1)) {
if(space_pos == 0 || space_pos == (packet->payload_packet_len - 1)) {
goto imap_excluded;
}
// now walk over a possible mail number to the next space
i++;
if (i < packet->payload_packet_len && (packet->payload[i] >= '0' && packet->payload[i] <= '9')) {
if(i < packet->payload_packet_len && (packet->payload[i] >= '0' && packet->payload[i] <= '9')) {
while (i < 20 && i < packet->payload_packet_len) {
if (i > 0 && packet->payload[i] == ' ') {
if(i > 0 && packet->payload[i] == ' ') {
space_pos = i;
break;
}
if (!(packet->payload[i] >= '0' && packet->payload[i] <= '9')) {
if(!(packet->payload[i] >= '0' && packet->payload[i] <= '9')) {
goto imap_excluded;
}
i++;
}
if (space_pos == 0 || space_pos == (packet->payload_packet_len - 1)) {
if(space_pos == 0 || space_pos == (packet->payload_packet_len - 1)) {
goto imap_excluded;
}
}
@@ -103,23 +108,23 @@ void ndpi_search_mail_imap_tcp(struct ndpi_detection_module_struct *ndpi_struct,
/* command = &(packet->payload[command_start]); */
}
if ((command_start + 3) < packet->payload_packet_len) {
if ((packet->payload[command_start] == 'O' || packet->payload[command_start] == 'o')
if((command_start + 3) < packet->payload_packet_len) {
if((packet->payload[command_start] == 'O' || packet->payload[command_start] == 'o')
&& (packet->payload[command_start + 1] == 'K' || packet->payload[command_start + 1] == 'k')
&& packet->payload[command_start + 2] == ' ') {
flow->l4.tcp.mail_imap_stage += 1;
if (flow->l4.tcp.mail_imap_starttls == 1)
if(flow->l4.tcp.mail_imap_starttls == 1)
flow->l4.tcp.mail_imap_starttls = 2;
saw_command = 1;
} else if ((packet->payload[command_start] == 'U' || packet->payload[command_start] == 'u')
} else if((packet->payload[command_start] == 'U' || packet->payload[command_start] == 'u')
&& (packet->payload[command_start + 1] == 'I' || packet->payload[command_start + 1] == 'i')
&& (packet->payload[command_start + 2] == 'D' || packet->payload[command_start + 2] == 'd')) {
flow->l4.tcp.mail_imap_stage += 1;
saw_command = 1;
}
}
if ((command_start + 10) < packet->payload_packet_len) {
if ((packet->payload[command_start] == 'C' || packet->payload[command_start] == 'c')
if((command_start + 10) < packet->payload_packet_len) {
if((packet->payload[command_start] == 'C' || packet->payload[command_start] == 'c')
&& (packet->payload[command_start + 1] == 'A' || packet->payload[command_start + 1] == 'a')
&& (packet->payload[command_start + 2] == 'P' || packet->payload[command_start + 2] == 'p')
&& (packet->payload[command_start + 3] == 'A' || packet->payload[command_start + 3] == 'a')
@@ -133,8 +138,8 @@ void ndpi_search_mail_imap_tcp(struct ndpi_detection_module_struct *ndpi_struct,
saw_command = 1;
}
}
if ((command_start + 8) < packet->payload_packet_len) {
if ((packet->payload[command_start] == 'S' || packet->payload[command_start] == 's')
if((command_start + 8) < packet->payload_packet_len) {
if((packet->payload[command_start] == 'S' || packet->payload[command_start] == 's')
&& (packet->payload[command_start + 1] == 'T' || packet->payload[command_start + 1] == 't')
&& (packet->payload[command_start + 2] == 'A' || packet->payload[command_start + 2] == 'a')
&& (packet->payload[command_start + 3] == 'R' || packet->payload[command_start + 3] == 'r')
@@ -148,36 +153,71 @@ void ndpi_search_mail_imap_tcp(struct ndpi_detection_module_struct *ndpi_struct,
saw_command = 1;
}
}
if ((command_start + 5) < packet->payload_packet_len) {
if ((packet->payload[command_start] == 'L' || packet->payload[command_start] == 'l')
if((command_start + 5) < packet->payload_packet_len) {
if((packet->payload[command_start] == 'L' || packet->payload[command_start] == 'l')
&& (packet->payload[command_start + 1] == 'O' || packet->payload[command_start + 1] == 'o')
&& (packet->payload[command_start + 2] == 'G' || packet->payload[command_start + 2] == 'g')
&& (packet->payload[command_start + 3] == 'I' || packet->payload[command_start + 3] == 'i')
&& (packet->payload[command_start + 4] == 'N' || packet->payload[command_start + 4] == 'n')) {
/* xxxx LOGIN "username" "password" */
char str[256], *item;
u_int len = packet->payload_packet_len > sizeof(str) ? sizeof(str) : packet->payload_packet_len;
strncpy(str, (const char*)packet->payload, len);
str[len] = '\0';
item = strchr(str, '"');
if(item) {
char *column;
item++;
column = strchr(item, '"');
if(column) {
column[0] = '\0';
snprintf(flow->protos.ftp_imap_pop_smtp.username,
sizeof(flow->protos.ftp_imap_pop_smtp.username),
"%s", item);
column = strchr(&column[1], '"');
if(column) {
item = &column[1];
column = strchr(item, '"');
if(column) {
column[0] = '\0';
snprintf(flow->protos.ftp_imap_pop_smtp.password,
sizeof(flow->protos.ftp_imap_pop_smtp.password),
"%s", item);
}
}
}
}
flow->l4.tcp.mail_imap_stage += 1;
saw_command = 1;
} else if ((packet->payload[command_start] == 'F' || packet->payload[command_start] == 'f')
} else if((packet->payload[command_start] == 'F' || packet->payload[command_start] == 'f')
&& (packet->payload[command_start + 1] == 'E' || packet->payload[command_start + 1] == 'e')
&& (packet->payload[command_start + 2] == 'T' || packet->payload[command_start + 2] == 't')
&& (packet->payload[command_start + 3] == 'C' || packet->payload[command_start + 3] == 'c')
&& (packet->payload[command_start + 4] == 'H' || packet->payload[command_start + 4] == 'h')) {
flow->l4.tcp.mail_imap_stage += 1;
saw_command = 1;
} else if ((packet->payload[command_start] == 'F' || packet->payload[command_start] == 'f')
} else if((packet->payload[command_start] == 'F' || packet->payload[command_start] == 'f')
&& (packet->payload[command_start + 1] == 'L' || packet->payload[command_start + 1] == 'l')
&& (packet->payload[command_start + 2] == 'A' || packet->payload[command_start + 2] == 'a')
&& (packet->payload[command_start + 3] == 'G' || packet->payload[command_start + 3] == 'g')
&& (packet->payload[command_start + 4] == 'S' || packet->payload[command_start + 4] == 's')) {
flow->l4.tcp.mail_imap_stage += 1;
saw_command = 1;
} else if ((packet->payload[command_start] == 'C' || packet->payload[command_start] == 'c')
} else if((packet->payload[command_start] == 'C' || packet->payload[command_start] == 'c')
&& (packet->payload[command_start + 1] == 'H' || packet->payload[command_start + 1] == 'h')
&& (packet->payload[command_start + 2] == 'E' || packet->payload[command_start + 2] == 'e')
&& (packet->payload[command_start + 3] == 'C' || packet->payload[command_start + 3] == 'c')
&& (packet->payload[command_start + 4] == 'K' || packet->payload[command_start + 4] == 'k')) {
flow->l4.tcp.mail_imap_stage += 1;
saw_command = 1;
} else if ((packet->payload[command_start] == 'S' || packet->payload[command_start] == 's')
} else if((packet->payload[command_start] == 'S' || packet->payload[command_start] == 's')
&& (packet->payload[command_start + 1] == 'T' || packet->payload[command_start + 1] == 't')
&& (packet->payload[command_start + 2] == 'O' || packet->payload[command_start + 2] == 'o')
&& (packet->payload[command_start + 3] == 'R' || packet->payload[command_start + 3] == 'r')
@@ -186,8 +226,8 @@ void ndpi_search_mail_imap_tcp(struct ndpi_detection_module_struct *ndpi_struct,
saw_command = 1;
}
}
if ((command_start + 12) < packet->payload_packet_len) {
if ((packet->payload[command_start] == 'A' || packet->payload[command_start] == 'a')
if((command_start + 12) < packet->payload_packet_len) {
if((packet->payload[command_start] == 'A' || packet->payload[command_start] == 'a')
&& (packet->payload[command_start + 1] == 'U' || packet->payload[command_start + 1] == 'u')
&& (packet->payload[command_start + 2] == 'T' || packet->payload[command_start + 2] == 't')
&& (packet->payload[command_start + 3] == 'H' || packet->payload[command_start + 3] == 'h')
@@ -203,8 +243,8 @@ void ndpi_search_mail_imap_tcp(struct ndpi_detection_module_struct *ndpi_struct,
saw_command = 1;
}
}
if ((command_start + 9) < packet->payload_packet_len) {
if ((packet->payload[command_start] == 'N' || packet->payload[command_start] == 'n')
if((command_start + 9) < packet->payload_packet_len) {
if((packet->payload[command_start] == 'N' || packet->payload[command_start] == 'n')
&& (packet->payload[command_start + 1] == 'A' || packet->payload[command_start + 1] == 'a')
&& (packet->payload[command_start + 2] == 'M' || packet->payload[command_start + 2] == 'm')
&& (packet->payload[command_start + 3] == 'E' || packet->payload[command_start + 3] == 'e')
@@ -217,26 +257,26 @@ void ndpi_search_mail_imap_tcp(struct ndpi_detection_module_struct *ndpi_struct,
saw_command = 1;
}
}
if ((command_start + 4) < packet->payload_packet_len) {
if ((packet->payload[command_start] == 'L' || packet->payload[command_start] == 'l')
if((command_start + 4) < packet->payload_packet_len) {
if((packet->payload[command_start] == 'L' || packet->payload[command_start] == 'l')
&& (packet->payload[command_start + 1] == 'S' || packet->payload[command_start + 1] == 's')
&& (packet->payload[command_start + 2] == 'U' || packet->payload[command_start + 2] == 'u')
&& (packet->payload[command_start + 3] == 'B' || packet->payload[command_start + 3] == 'b')) {
flow->l4.tcp.mail_imap_stage += 1;
saw_command = 1;
} else if ((packet->payload[command_start] == 'L' || packet->payload[command_start] == 'l')
} else if((packet->payload[command_start] == 'L' || packet->payload[command_start] == 'l')
&& (packet->payload[command_start + 1] == 'I' || packet->payload[command_start + 1] == 'i')
&& (packet->payload[command_start + 2] == 'S' || packet->payload[command_start + 2] == 's')
&& (packet->payload[command_start + 3] == 'T' || packet->payload[command_start + 3] == 't')) {
flow->l4.tcp.mail_imap_stage += 1;
saw_command = 1;
} else if ((packet->payload[command_start] == 'N' || packet->payload[command_start] == 'n')
} else if((packet->payload[command_start] == 'N' || packet->payload[command_start] == 'n')
&& (packet->payload[command_start + 1] == 'O' || packet->payload[command_start + 1] == 'o')
&& (packet->payload[command_start + 2] == 'O' || packet->payload[command_start + 2] == 'o')
&& (packet->payload[command_start + 3] == 'P' || packet->payload[command_start + 3] == 'p')) {
flow->l4.tcp.mail_imap_stage += 1;
saw_command = 1;
} else if ((packet->payload[command_start] == 'I' || packet->payload[command_start] == 'i')
} else if((packet->payload[command_start] == 'I' || packet->payload[command_start] == 'i')
&& (packet->payload[command_start + 1] == 'D' || packet->payload[command_start + 1] == 'd')
&& (packet->payload[command_start + 2] == 'L' || packet->payload[command_start + 2] == 'l')
&& (packet->payload[command_start + 3] == 'E' || packet->payload[command_start + 3] == 'e')) {
@@ -244,8 +284,8 @@ void ndpi_search_mail_imap_tcp(struct ndpi_detection_module_struct *ndpi_struct,
saw_command = 1;
}
}
if ((command_start + 6) < packet->payload_packet_len) {
if ((packet->payload[command_start] == 'S' || packet->payload[command_start] == 's')
if((command_start + 6) < packet->payload_packet_len) {
if((packet->payload[command_start] == 'S' || packet->payload[command_start] == 's')
&& (packet->payload[command_start + 1] == 'E' || packet->payload[command_start + 1] == 'e')
&& (packet->payload[command_start + 2] == 'L' || packet->payload[command_start + 2] == 'l')
&& (packet->payload[command_start + 3] == 'E' || packet->payload[command_start + 3] == 'e')
@@ -253,7 +293,7 @@ void ndpi_search_mail_imap_tcp(struct ndpi_detection_module_struct *ndpi_struct,
&& (packet->payload[command_start + 5] == 'T' || packet->payload[command_start + 5] == 't')) {
flow->l4.tcp.mail_imap_stage += 1;
saw_command = 1;
} else if ((packet->payload[command_start] == 'E' || packet->payload[command_start] == 'e')
} else if((packet->payload[command_start] == 'E' || packet->payload[command_start] == 'e')
&& (packet->payload[command_start + 1] == 'X' || packet->payload[command_start + 1] == 'x')
&& (packet->payload[command_start + 2] == 'I' || packet->payload[command_start + 2] == 'i')
&& (packet->payload[command_start + 3] == 'S' || packet->payload[command_start + 3] == 's')
@@ -261,7 +301,7 @@ void ndpi_search_mail_imap_tcp(struct ndpi_detection_module_struct *ndpi_struct,
&& (packet->payload[command_start + 5] == 'S' || packet->payload[command_start + 5] == 's')) {
flow->l4.tcp.mail_imap_stage += 1;
saw_command = 1;
} else if ((packet->payload[command_start] == 'A' || packet->payload[command_start] == 'a')
} else if((packet->payload[command_start] == 'A' || packet->payload[command_start] == 'a')
&& (packet->payload[command_start + 1] == 'P' || packet->payload[command_start + 1] == 'p')
&& (packet->payload[command_start + 2] == 'P' || packet->payload[command_start + 2] == 'p')
&& (packet->payload[command_start + 3] == 'E' || packet->payload[command_start + 3] == 'e')
@@ -274,16 +314,23 @@ void ndpi_search_mail_imap_tcp(struct ndpi_detection_module_struct *ndpi_struct,
}
if (saw_command == 1) {
if (flow->l4.tcp.mail_imap_stage == 3 || flow->l4.tcp.mail_imap_stage == 5) {
NDPI_LOG_INFO(ndpi_struct, "found MAIL_IMAP\n");
ndpi_int_mail_imap_add_connection(ndpi_struct, flow);
if(saw_command == 1) {
if((flow->l4.tcp.mail_imap_stage == 3)
|| (flow->l4.tcp.mail_imap_stage == 5)
|| (flow->l4.tcp.mail_imap_stage == 7)
) {
if((flow->protos.ftp_imap_pop_smtp.username[0] != '\0')
|| (flow->l4.tcp.mail_imap_stage >= 7)) {
NDPI_LOG_INFO(ndpi_struct, "found MAIL_IMAP\n");
ndpi_int_mail_imap_add_connection(ndpi_struct, flow);
}
return;
}
}
}
if (packet->payload_packet_len > 1 && packet->payload[packet->payload_packet_len - 1] == ' ') {
if(packet->payload_packet_len > 1 && packet->payload[packet->payload_packet_len - 1] == ' ') {
NDPI_LOG_DBG2(ndpi_struct,
"maybe a split imap command -> need next packet and imap_stage is set to 4.\n");
flow->l4.tcp.mail_imap_stage = 4;
@@ -294,7 +341,7 @@ void ndpi_search_mail_imap_tcp(struct ndpi_detection_module_struct *ndpi_struct,
// skip over possible authentication hashes etc. that cannot be identified as imap commands or responses
// if the packet count is low enough and at least one command or response was seen before
if ((packet->payload_packet_len >= 2 && ntohs(get_u_int16_t(packet->payload, packet->payload_packet_len - 2)) == 0x0d0a)
if((packet->payload_packet_len >= 2 && ntohs(get_u_int16_t(packet->payload, packet->payload_packet_len - 2)) == 0x0d0a)
&& flow->packet_counter < 6 && flow->l4.tcp.mail_imap_stage >= 1) {
NDPI_LOG_DBG2(ndpi_struct,
"no imap command or response but packet count < 6 and imap stage >= 1 -> skip\n");

Some files were not shown because too many files have changed in this diff Show More