9 #error bulk_extractor_i.h included before config.h
12 #ifndef BULK_EXTRACTOR_I_H
13 #define BULK_EXTRACTOR_I_H
15 #define DEBUG_PEDANTIC 0x0001
16 #define DEBUG_PRINT_STEPS 0x0002
17 #define DEBUG_SCANNER 0x0004
18 #define DEBUG_NO_SCANNERS 0x0008
19 #define DEBUG_DUMP_DATA 0x0010
20 #define DEBUG_DECODING 0x0020
21 #define DEBUG_INFO 0x0040
22 #define DEBUG_EXIT_EARLY 1000
23 #define DEBUG_ALLOCATE_512MiB 1002
26 #ifdef HAVE_NETINET_IN_H
27 # include <netinet/in.h>
32 #if defined(MINGW) || defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__)
38 #if defined(WIN32) || defined(__MINGW32__)
39 # include <winsock2.h>
41 # include <windowsx.h>
46 #if defined(WIN32) || !defined(__BYTE_ORDER)
47 # define __LITTLE_ENDIAN 1234
48 # define __BIG_ENDIAN 4321
49 # define __BYTE_ORDER __LITTLE_ENDIAN
52 #if (__BYTE_ORDER == __LITTLE_ENDIAN) && (__BYTE_ORDER == __BIG_ENDIAN)
53 # error Invalid __BYTE_ORDER
81 # error bulk_extractor_i.h requires C++
100 #ifdef HAVE_NETINET_IF_ETHER_H
101 # include <netinet/if_ether.h>
103 #ifdef HAVE_NETINET_IN_H
104 # include <netinet/in.h>
106 #ifdef HAVE_NET_ETHERNET_H
107 # include <net/ethernet.h>
111 #if defined(HAVE_LIBPCAP)
112 # ifdef HAVE_DIAGNOSTIC_REDUNDANT_DECLS
113 # pragma GCC diagnostic ignored "-Wredundant-decls"
115 # if defined(HAVE_PCAP_PCAP_H)
116 # include <pcap/pcap.h>
119 # if defined(HAVE_PCAP_H) && !defined(GOT_PCAP)
123 # if defined(HAVE_WPCAP_PCAP_H) && !defined(GOT_PCAP)
124 # include <wpcap/pcap.h>
127 # ifdef HAVE_DIAGNOSTIC_REDUNDANT_DECLS
128 # pragma GCC diagnostic warning "-Wredundant-decls"
165 # define IPPROTO_TCP 6
170 } __attribute__ ((__packed__));
177 } __attribute__ ((__packed__));
196 #if __BYTE_ORDER == __LITTLE_ENDIAN
200 #if __BYTE_ORDER == __BIG_ENDIAN
211 #define IP_OFFMASK 0x1fff
216 } __attribute__ ((__packed__));
246 } __attribute__((__packed__));
264 # if __BYTE_ORDER == __LITTLE_ENDIAN
268 # if __BYTE_ORDER == __BIG_ENDIAN
276 # define TH_PUSH 0x08
316 std::logic_error(
"frame too short to contain requisite network structures") {}
325 const struct timeval &ts_,
const uint8_t *d2,
size_t dl2):
333 const struct timeval &
ts;
337 static u_short
nshort(
const u_char *buf,
size_t pos);
377 #ifndef ETHERTYPE_PUP
378 #define ETHERTYPE_PUP 0x0200
381 #ifndef ETHERTYPE_SPRITE
382 #define ETHERTYPE_SPRITE 0x0500
386 #define ETHERTYPE_IP 0x0800
389 #ifndef ETHERTYPE_ARP
390 #define ETHERTYPE_ARP 0x0806
393 #ifndef ETHERTYPE_REVARP
394 #define ETHERTYPE_REVARP 0x8035
398 #define ETHERTYPE_AT 0x809B
401 #ifndef ETHERTYPE_AARP
402 #define ETHERTYPE_AARP 0x80F3
405 #ifndef ETHERTYPE_VLAN
406 #define ETHERTYPE_VLAN 0x8100
409 #ifndef ETHERTYPE_IPX
410 #define ETHERTYPE_IPX 0x8137
413 #ifndef ETHERTYPE_IPV6
414 #define ETHERTYPE_IPV6 0x86dd
417 #ifndef ETHERTYPE_LOOPBACK
418 #define ETHERTYPE_LOOPBACK 0x9000
424 return (buf[pos]<<8) | (buf[pos+1]);
440 switch(ip_header->
ip_v){
499 # ifdef HAVE_DIAGNOSTIC_CAST_ALIGN
500 # pragma GCC diagnostic ignored "-Wcast-align"
516 # ifdef HAVE_DIAGNOSTIC_CAST_ALIGN
517 # pragma GCC diagnostic warning "-Wcast-align"
542 # ifdef HAVE_DIAGNOSTIC_CAST_ALIGN
543 # pragma GCC diagnostic ignored "-Wcast-align"
559 # ifdef HAVE_DIAGNOSTIC_CAST_ALIGN
560 # pragma GCC diagnostic warning "-Wcast-align"
617 typedef std::map<std::string,std::string>
config_t;
633 if(flag==0) ret +=
"NONE ";
678 const std::string &
name,std::string *val,
const std::string &help);
679 virtual void get_config(
const std::string &
name,std::string *val,
const std::string &help);
680 virtual void get_config(
const std::string &
name,uint64_t *val,
const std::string &help);
681 virtual void get_config(
const std::string &
name,int32_t *val,
const std::string &help);
686 virtual void get_config(
const std::string &
name,
size_t *val,
const std::string &help);
687 #define HAVE_GET_CONFIG_SIZE_T
689 virtual void get_config(
const std::string &
name,
bool *val,
const std::string &help);
705 PrintOptions::const_iterator p = po.find(
"print_mode_t");
707 if(p->second==
"MODE_NONE")
return MODE_NONE;
708 if(p->second==
"MODE_HEX")
return MODE_HEX;
709 if(p->second==
"MODE_RAW")
return MODE_RAW;
710 if(p->second==
"MODE_HTTP")
return MODE_HTTP;
717 case MODE_NONE:po[
"print_mode_t"]=
"MODE_NONE";
return;
718 case MODE_HEX:po[
"print_mode_t"]=
"MODE_HEX";
return;
719 case MODE_RAW:po[
"print_mode_t"]=
"MODE_RAW";
return;
720 case MODE_HTTP:po[
"print_mode_t"]=
"MODE_HTTP";
return;
789 os <<
"scanner_params(" << sp.
sbuf <<
")";
855 bool detailed_settings,
871 inline std::string
itos(
int i){ std::stringstream ss; ss << i;
return ss.str();}
872 inline std::string
dtos(
double d){ std::stringstream ss; ss << d;
return ss.str();}
873 inline std::string
utos(
unsigned int i){ std::stringstream ss; ss << i;
return ss.str();}
874 inline std::string
utos(uint64_t i){ std::stringstream ss; ss << i;
return ss.str();}
875 inline std::string
utos(
uint16_t i){ std::stringstream ss; ss << i;
return ss.str();}
877 std::string utf8_line;
888 std::wstring utf16_line;
900 size_t pos = line.find(ch);
901 if(pos != std::string::npos) line.resize(pos);
904 #ifndef HAVE_ISXDIGIT
907 return (
c>=
'0' &&
c<=
'9') || (
c>=
'a' &&
c<=
'f') || (
c>=
'A' &&
c<=
'F');
912 #define ONE_HUNDRED_NANO_SEC_TO_SECONDS 10000000
913 #define SECONDS_BETWEEN_WIN32_EPOCH_AND_UNIX_EPOCH 11644473600LL
929 strftime(buf,
sizeof(buf),
"%Y-%m-%dT%H:%M:%SZ", &time_tm);
930 return std::string(buf);
940 strftime(buf,
sizeof(buf),
"%Y-%m-%dT%H:%M:%SZ", &time_tm);
941 return std::string(buf);
947 for(
size_t i = 0; i<
name.size(); i++){
948 if(((u_char)
name[i]) & 0x80)
return false;
949 if(((u_char)
name[i]) <
' ')
return false;
950 if(((u_char)
name[i]) == 0x7f)
return false;
std::set< std::string > feature_file_names_t
static uint32_t max_ngram
std::map< std::string, std::string > config_t
static bool dup_data_alerts
static void phase_shutdown(feature_recorder_set &fs, std::stringstream *sxml=0)
static void load_scanner(scanner_t scanner, const scanner_info::scanner_config &sc)
bool validASCIIName(const std::string &name)
static bool find_scanner_enabled()
static const int SCANNER_NO_USAGE
virtual ~scanner_config()
static const int SCANNER_WANTS_NGRAMS
static const size_t tcp_dport_off
static const int SCANNER_FAST_FIND
const uint8_t * get_ether_shost() const
std::wstring safe_utf8to16(std::string s)
static const int CURRENT_SP_VERSION
packet_info(const int dlt, const struct pcap_pkthdr *h, const u_char *d)
void scanner_t(const class scanner_params &sp, const class recursion_control_block &rcb)
const struct ip6_addr * get_ip6_src() const
uint8_t get_ip4_proto() const
static uint64_t dup_data_encountered
const struct in_addr * get_ip4_dst() const
static const int SCANNER_RECURSE
void process_t(const class scanner_params &sp)
static print_mode_t getPrintMode(const PrintOptions &po)
virtual void get_config(const scanner_info::config_t &c, const std::string &name, std::string *val, const std::string &help)
std::map< std::string, std::string > PrintOptions
static std::stringstream helpstream
uint16_t get_ip4_tcp_sport() const
recursion_control_block(process_t *callback_, std::string partName_)
scanner_params(phase_t phase_, const sbuf_t &sbuf_, class feature_recorder_set &fs_, std::stringstream *xmladd)
#define SECONDS_BETWEEN_WIN32_EPOCH_AND_UNIX_EPOCH
static uint32_t max_depth
uint16_t get_ip6_tcp_dport() const
static const size_t ip4_dst_off
static const size_t ip4_src_off
static const int SCANNER_RECURSE_EXPAND
static scanner_vector current_scanners
static void load_scanner_directories(const std::vector< std::string > &dirnames, const scanner_info::scanner_config &sc)
static const size_t ip6_nxt_hdr_off
static void process_packet(const be13::packet_info &pi)
uint16_t get_ip6_tcp_sport() const
std::ostream & operator<<(std::ostream &os, const class scanner_params &sp)
static void message_enabled_scanners(scanner_params::phase_t phase, feature_recorder_set &fs)
void packet_callback_t(void *user, const be13::packet_info &pi)
std::string unixTimeToISODate(const uint64_t &t)
histogram_defs_t histogram_defs
static PrintOptions no_options
const struct pcap_pkthdr * pcap_hdr
static u_short nshort(const u_char *buf, size_t pos)
static void add_enabled_scanner_histograms_to_feature_recorder_set(feature_recorder_set &fs)
static void scanners_enable(const std::string &name)
u_short ether_type() const
static void info_scanners(bool detailed_info, bool detailed_settings, scanner_t *const *scanners_builtin, const char enable_opt, const char disable_opt)
std::string microsoftDateToISODate(const uint64_t &time)
packet_callback_t * packet_cb
void truncate_at(std::string &line, char ch)
static std::string helpstr()
union be13::ip6_addr::@0 addr
uint8_t get_ip6_nxt_hdr() const
std::vector< scanner_def * > scanner_vector
const struct ip6_hdr * header
static const int CURRENT_SI_VERSION
const scanner_config * config
uint16_t get_ip4_tcp_dport() const
union be13::ip6_hdr::@1 ip6_ctlun
static const size_t ip6_dst_off
static void load_scanner_packet_handlers()
scanner_info(const scanner_info &i)
static void scanners_init(feature_recorder_set &fs)
static void set_scanner_enabled(const std::string &name, bool enable)
static void process_sbuf(const class scanner_params &sp)
std::string safe_utf16to8(std::wstring s)
const uint8_t *const ip_data
static const size_t ip4_proto_off
static void get_enabled_scanners(std::vector< std::string > &svector)
struct be13::ip6_hdr::@1::ip6_hdrctl ip6_un1
uint8_t ether_addr_octet[6]
static const int SCANNER_DISABLED
static void scanners_process_enable_disable_commands()
static void scanners_enable_all()
const struct ip4 * header
std::set< std::string > feature_names
const struct ip6_addr * get_ip6_dst() const
scanner_info & operator=(const scanner_info &i)
#define ONE_HUNDRED_NANO_SEC_TO_SECONDS
static void load_scanner_file(std::string fn, const scanner_info::scanner_config &sc)
std::string utos(unsigned int i)
uint16_t get_ip6_plen() const
static void load_scanners(scanner_t *const *scanners_builtin, const scanner_info::scanner_config &sc)
const struct timeval & ts
static void get_scanner_feature_file_names(feature_file_names_t &feature_file_names)
static uint32_t get_max_depth_seen()
static void scanners_disable(const std::string &name)
static void setPrintMode(PrintOptions &po, int mode)
packet_info(const int dlt, const struct pcap_pkthdr *h, const u_char *d, const struct timeval &ts_, const uint8_t *d2, size_t dl2)
std::string scanner_version
static const std::string flag_to_string(const int flag)
static const size_t ip6_plen_off
static const size_t tcp_sport_off
static void set_scanner_enabled_all(bool enable)
static const size_t ip6_src_off
class feature_recorder_set & fs
static void scanners_disable_all()
PrintOptions & print_options
scanner_params(phase_t phase_, const sbuf_t &sbuf_, class feature_recorder_set &fs_)
static void load_scanner_directory(const std::string &dirname, const scanner_info::scanner_config &sc)
std::string dtos(double d)
static scanner_t * find_scanner(const std::string &name)
static void set_scanner_debug(int debug)
const struct in_addr * get_ip4_src() const
struct ip4_addr ip_src ip_dst
scanner_params(const scanner_params &sp_existing, const sbuf_t &sbuf_new)
scanner_params(phase_t phase_, const sbuf_t &sbuf_, class feature_recorder_set &fs_, PrintOptions &print_options_)
static const int SCANNER_DEPTH_0
static const int SCANNER_NO_ALL
const uint8_t * get_ether_dhost() const
static const int SCANNER_FIND_SCANNER
@ PHASE_THREAD_BEFORE_SCAN
u16bit_iterator utf8to16(octet_iterator start, octet_iterator end, u16bit_iterator result)
octet_iterator utf16to8(u16bit_iterator start, u16bit_iterator end, octet_iterator result)
scanner_t * scanners_builtin[]
void gmtime_r(time_t *t, struct tm *tm)