-- fixed valgrind issues
-- refactored Shells to support multiple files/policies
-- changed detect reset to accommodate buffer population before reassembly
+-- initial multiple policy binding
119
-- updated binder
PolicyMap::PolicyMap()
{
- shells.push_back(new Shell);
- inspection_policy.push_back(new InspectionPolicy);
- ips_policy.push_back(new IpsPolicy);
- network_policy.push_back(new NetworkPolicy);
+ add_shell(new Shell);
set_inspection_policy(inspection_policy[0]);
set_ips_policy(ips_policy[0]);
network_policy.clear();
}
+unsigned PolicyMap::add_shell(Shell* sh)
+{
+ shells.push_back(sh);
+ inspection_policy.push_back(new InspectionPolicy);
+ ips_policy.push_back(new IpsPolicy);
+ network_policy.push_back(new NetworkPolicy);
+ return shells.size() - 1;
+}
+
+//-------------------------------------------------------------------------
+// policy nav
+//-------------------------------------------------------------------------
+
+static THREAD_LOCAL NetworkPolicy* s_traffic_policy = nullptr;
+static THREAD_LOCAL InspectionPolicy* s_inspection_policy = nullptr;
+static THREAD_LOCAL IpsPolicy* s_detection_policy = nullptr;
+
+NetworkPolicy* get_network_policy()
+{ return s_traffic_policy; }
+
+InspectionPolicy* get_inspection_policy()
+{ return s_inspection_policy; }
+
+IpsPolicy* get_ips_policy()
+{ return s_detection_policy; }
+
+void set_network_policy(NetworkPolicy* p)
+{ s_traffic_policy = p; }
+
+void set_inspection_policy(InspectionPolicy* p)
+{ s_inspection_policy = p; }
+
+void set_ips_policy(IpsPolicy* p)
+{ s_detection_policy = p; }
+
+void set_policies(SnortConfig* sc, unsigned i)
+{
+ PolicyMap* pm = sc->policy_map;
+
+ if ( i < pm->shells.size() )
+ {
+ set_network_policy(pm->network_policy[i]);
+ set_inspection_policy(pm->inspection_policy[i]);
+ set_ips_policy(pm->ips_policy[i]);
+ }
+}
+
+void set_default_policy()
+{
+ set_network_policy(snort_conf->policy_map->network_policy[0]);
+ set_ips_policy(snort_conf->policy_map->ips_policy[0]);
+ set_inspection_policy(snort_conf->policy_map->inspection_policy[0]);
+}
+
};
//-------------------------------------------------------------------------
-// binding stuff - FIXIT-H tbd
+// binding stuff
//-------------------------------------------------------------------------
class Shell;
PolicyMap();
~PolicyMap();
- InspectionPolicy* get_inspection_policy()
- { return inspection_policy[0]; };
-
- IpsPolicy* get_ips_policy()
- { return ips_policy[0]; };
-
- NetworkPolicy* get_network_policy()
- { return network_policy[0]; };
-
- unsigned add_shell(Shell* sh)
- {
- shells.push_back(sh);
- return shells.size() - 1;
- };
+ unsigned add_shell(Shell*);
Shell* get_shell(unsigned i = 0)
{ return i < shells.size() ? shells[i] : nullptr; };
std::vector<NetworkPolicy*> network_policy;
};
+//-------------------------------------------------------------------------
+// navigator stuff
+//-------------------------------------------------------------------------
+
+// FIXIT-L may be inlined at some point; on lockdown for now
+NetworkPolicy* get_network_policy();
+InspectionPolicy* get_inspection_policy();
+IpsPolicy* get_ips_policy();
+
+void set_network_policy(NetworkPolicy*);
+void set_inspection_policy(InspectionPolicy*);
+void set_ips_policy(IpsPolicy*);
+
+void set_policies(struct SnortConfig*, unsigned = 0);
+void set_default_policy();
+
#endif
static void CleanExit(int);
static void SnortCleanup();
-//-------------------------------------------------------------------------
-// nascent policy management
-//-------------------------------------------------------------------------
-// FIXIT-H need stub binding rule to set these for runtime
-// FIXIT-H need to set these on load too somehow
-
-static THREAD_LOCAL NetworkPolicy* s_traffic_policy = nullptr;
-static THREAD_LOCAL InspectionPolicy* s_inspection_policy = nullptr;
-static THREAD_LOCAL IpsPolicy* s_detection_policy = nullptr;
-
-NetworkPolicy* get_network_policy()
-{ return s_traffic_policy; }
-
-InspectionPolicy* get_inspection_policy()
-{ return s_inspection_policy; }
-
-IpsPolicy* get_ips_policy()
-{ return s_detection_policy; }
-
-void set_network_policy(NetworkPolicy* p)
-{ s_traffic_policy = p; }
-
-void set_inspection_policy(InspectionPolicy* p)
-{ s_inspection_policy = p; }
-
-void set_ips_policy(IpsPolicy* p)
-{ s_detection_policy = p; }
-
//-------------------------------------------------------------------------
// utility
//-------------------------------------------------------------------------
else
pm = POLICY_MODE__PASSIVE;
- sc->get_ips_policy()->policy_mode = pm;
+ get_ips_policy()->policy_mode = pm;
}
static void SnortInit(int argc, char **argv)
}
}
-void set_default_policy()
+static void set_policy(Packet* p) // FIXIT-H delete this?
{
- set_network_policy(snort_conf->policy_map->network_policy[0]);
- set_ips_policy(snort_conf->policy_map->ips_policy[0]);
- set_inspection_policy(snort_conf->policy_map->inspection_policy[0]);
-}
-
-static void set_policy(Packet*) // FIX SSN implement based on bindings
-{
- // for now need to just get stream_* inspectors and call appropriately
-#if 0
- int vlanId = (p->vh) ? vlan::vth_vlan(p->vh) : -1;
- const sfip_t *srcIp = p->ptrs.ip_api.get_src(); // returns nullptr if not set
- const sfip_t *dstIp = p->ptrs.ip_api.get_dst();
-
- //set policy id for this packet
- setCurrentPolicy(snort_conf, sfGetApplicablePolicyId(
- snort_conf->policy_config, vlanId, srcIp, dstIp));
-#else
set_default_policy();
-#endif
+ p->user_policy_id = get_ips_policy()->user_policy_id;
}
void DecodeRebuiltPacket (
p->flow = lws;
- set_policy(p); // FIX SSN rebuilt should reuse original bindings
- p->user_policy_id = get_ips_policy()->user_policy_id;
+ set_policy(p); // FIXIT-H rebuilt should reuse original bindings from flow
SnortEventqPop();
}
p->proto_bits &= ~PROTO_BIT__IP;
#endif
- set_policy(p);
-
- p->user_policy_id = get_ips_policy()->user_policy_id;
+ set_policy(p); // FIXIT-H should not need this here
/* just throw away the packet if we are configured to ignore this port */
if ( !(p->packet_flags & PKT_IGNORE) )
void snort_idle();
void snort_rotate();
-// FIXIT-L may be inlined at some point; on lockdown for now
-NetworkPolicy* get_network_policy();
-InspectionPolicy* get_inspection_policy();
-IpsPolicy* get_ips_policy();
-
-void set_network_policy(NetworkPolicy*);
-void set_inspection_policy(InspectionPolicy*);
-void set_ips_policy(IpsPolicy*);
-
void CapturePacket();
void DecodeRebuiltPacket (Packet*, const DAQ_PktHdr_t*, const uint8_t* pkt, Flow*);
void DetectRebuiltPacket (Packet*);
DAQ_Verdict fail_open(void*, const DAQ_PktHdr_t*, const uint8_t*);
DAQ_Verdict packet_callback(void*, const DAQ_PktHdr_t*, const uint8_t*);
-void set_default_policy();
-
typedef void (*MainHook_f)(Packet*);
void set_main_hook(MainHook_f);
static inline int ScIpChecksums(void)
{
- return snort_conf->get_network_policy()->checksum_eval & CHECKSUM_FLAG__IP;
+ return get_network_policy()->checksum_eval & CHECKSUM_FLAG__IP;
}
static inline int ScIpChecksumDrops(void)
{
- return snort_conf->get_network_policy()->checksum_drop & CHECKSUM_FLAG__IP;
+ return get_network_policy()->checksum_drop & CHECKSUM_FLAG__IP;
}
static inline int ScUdpChecksums(void)
{
- return snort_conf->get_network_policy()->checksum_eval & CHECKSUM_FLAG__UDP;
+ return get_network_policy()->checksum_eval & CHECKSUM_FLAG__UDP;
}
static inline int ScUdpChecksumDrops(void)
{
- return snort_conf->get_network_policy()->checksum_drop & CHECKSUM_FLAG__UDP;
+ return get_network_policy()->checksum_drop & CHECKSUM_FLAG__UDP;
}
static inline int ScTcpChecksums(void)
{
- return snort_conf->get_network_policy()->checksum_eval & CHECKSUM_FLAG__TCP;
+ return get_network_policy()->checksum_eval & CHECKSUM_FLAG__TCP;
}
static inline int ScTcpChecksumDrops(void)
{
- return snort_conf->get_network_policy()->checksum_drop & CHECKSUM_FLAG__TCP;
+ return get_network_policy()->checksum_drop & CHECKSUM_FLAG__TCP;
}
static inline int ScIcmpChecksums(void)
{
- return snort_conf->get_network_policy()->checksum_eval & CHECKSUM_FLAG__ICMP;
+ return get_network_policy()->checksum_eval & CHECKSUM_FLAG__ICMP;
}
static inline int ScIcmpChecksumDrops(void)
{
- return snort_conf->get_network_policy()->checksum_drop & CHECKSUM_FLAG__ICMP;
+ return get_network_policy()->checksum_drop & CHECKSUM_FLAG__ICMP;
}
static inline uint8_t ScMinTTL(void)
{
- return snort_conf->get_network_policy()->min_ttl;
+ return get_network_policy()->min_ttl;
}
static inline uint8_t ScNewTTL(void)
{
- return snort_conf->get_network_policy()->new_ttl;
+ return get_network_policy()->new_ttl;
}
static inline int ScInlineMode(void)
{
- return ((snort_conf->get_ips_policy()->policy_mode) == POLICY_MODE__INLINE );
+ return ((get_ips_policy()->policy_mode) == POLICY_MODE__INLINE );
}
static inline int ScInlineTestMode(void)
{
- return ((snort_conf->get_ips_policy()->policy_mode) == POLICY_MODE__INLINE_TEST );
+ return ((get_ips_policy()->policy_mode) == POLICY_MODE__INLINE_TEST );
}
//-------------------------------------------------------------------------
#endif
InspectionPolicy* get_inspection_policy()
- { return policy_map->get_inspection_policy(); };
+ { return policy_map->inspection_policy[0]; };
IpsPolicy* get_ips_policy()
- { return policy_map->get_ips_policy(); };
+ { return policy_map->ips_policy[0]; };
NetworkPolicy* get_network_policy()
- { return policy_map->get_network_policy(); };
+ { return policy_map->network_policy[0]; };
};
SnortConfig* SnortConfNew(void);
void InspectorManager::instantiate(
const InspectApi* api, Module*, SnortConfig* sc)
{
- // FIXIT-H only configures inspectors in base policy; must be
- // revisited when bindings are implemented
FrameworkConfig* fc = sc->framework_config;
- FrameworkPolicy* fp = sc->policy_map->inspection_policy[0]->framework_policy;
+ FrameworkPolicy* fp = get_inspection_policy()->framework_policy;
// FIXIT-H should not need to lookup inspector etc
// since given api and mod
fp->binder = get_instance(fp, bind_id)->handler;
}
-bool InspectorManager::configure(SnortConfig *sc)
+static bool configure(SnortConfig* sc, FrameworkPolicy* fp)
{
- sort(s_handlers.begin(), s_handlers.end(), PHGlobal::comp);
-
- // FIXIT-H do we need more than one framework policy?
- // if so, must vectorize(), etc. multiple times
- FrameworkPolicy* fp = sc->policy_map->inspection_policy[0]->framework_policy;
bool ok = true;
for ( auto* p : fp->ilist )
sort(fp->ilist.begin(), fp->ilist.end(), PHInstance::comp);
fp->vectorize();
- if ( fp->service.num && !fp->binder && get_wizard() )
+ if ( fp->service.num && !fp->binder && InspectorManager::get_wizard() )
instantiate_binder(sc, fp);
return ok;
}
+bool InspectorManager::configure(SnortConfig *sc)
+{
+ sort(s_handlers.begin(), s_handlers.end(), PHGlobal::comp);
+ bool ok = true;
+
+ for ( auto* p : sc->policy_map->inspection_policy )
+ ok = ::configure(sc, p->framework_policy) && ok;
+
+ return ok;
+}
+
void InspectorManager::print_config(SnortConfig *sc)
{
InspectionPolicy* pi = get_inspection_policy();
bindings.push_back(b);
}
-vector<Binding*> BinderModule::get_data()
+vector<Binding*>& BinderModule::get_data()
{
return bindings; // move semantics
}
PegCount* get_counts() const;
ProfileStats* get_profile() const;
- std::vector<Binding*> get_data();
+ std::vector<Binding*>& get_data();
private:
Binding* work;
std::vector<Binding*> bindings;
class Binder : public Inspector
{
public:
- Binder(vector<Binding*>);
+ Binder(vector<Binding*>&);
~Binder();
void show(SnortConfig*)
vector<Binding*> bindings;
};
-Binder::Binder(vector<Binding*> v)
+Binder::Binder(vector<Binding*>& v)
{
- bindings = v;
+ bindings = std::move(v);
}
Binder::~Binder()
static Inspector* bind_ctor(Module* m)
{
BinderModule* mod = (BinderModule*)m;
- vector<Binding*> pb = mod->get_data();
+ vector<Binding*>& pb = mod->get_data();
return new Binder(pb);
}
//DEBUG_WRAP(DebugMessage(DEBUG_DETECT, "OK\n"););
}
+static void parse_file(SnortConfig* sc, Shell* sh)
+{
+ const char* fname = sh->get_file();
+ LogMessage("Loading %s:\n", fname);
+ push_parse_location(fname);
+ sh->configure(sc);
+ pop_parse_location();
+}
+
//-------------------------------------------------------------------------
// public methods
//-------------------------------------------------------------------------
if ( !sh )
break;
- fname = sh->get_file();
- LogMessage("Loading %s:\n", fname);
- push_parse_location(fname);
- sh->configure(sc);
- pop_parse_location();
+ set_policies(sc, i);
+ parse_file(sc, sh);
}
+ set_policies(sc);
return sc;
}
#define FTP_EVASIVE_TELNET_CMD_STR \
"(ftp) Evasive (incomplete) TELNET CMD on FTP Command Channel"
-// FIXIT-H convert to Lua and use as module default settings
-#if 0
-static const char* DEFAULT_FTP_CONF[] =
-{
- "hardcoded_config "
- "def_max_param_len 100 "
-
- // eg must appear in at least one *_cmds parameter
- "ftp_cmds { USER PASS ACCT CWD CDUP SMNT QUIT REIN TYPE STRU"
- " MODE RETR STOR STOU APPE ALLO REST RNFR RNTO ABOR"
- " DELE RMD MKD PWD LIST NLST SITE SYST STAT HELP NOOP } "
- "ftp_cmds { AUTH ADAT PROT PBSZ CONF ENC } "
- "ftp_cmds { PORT PASV LPRT LPSV EPRT EPSV } "
- "ftp_cmds { FEAT OPTS } "
- "ftp_cmds { MDTM REST SIZE MLST MLSD } "
-
- "alt_max_param_len 0 { CDUP QUIT REIN PASV STOU ABOR PWD SYST NOOP } ",
-
- "cmd_validity MODE < char SBC > "
- "cmd_validity STRU < char FRPO [ string ] > "
- "cmd_validity ALLO < int [ char R int ] > "
- "cmd_validity TYPE < { char AE [ char NTC ] | char I | char L [ number ] } > "
- "cmd_validity PORT < host_port > "
- "cmd_validity LPRT < long_host_port > "
- "cmd_validity EPRT < extd_host_port > "
- "cmd_validity EPSV < [ { '1' | '2' | 'ALL' } ] > ",
-
- "data_chan_cmds { PORT PASV LPRT LPSV EPRT EPSV } "
- "data_xfer_cmds { RETR STOR STOU APPE LIST NLST } "
- "file_put_cmds { STOR STOU } "
- "file_get_cmds { RETR } "
- "login_cmds { USER PASS } "
- "dir_cmds { CWD 250 CDUP 250 PWD 257 } "
- "encr_cmds { AUTH } "
-};
-#endif
-
//-------------------------------------------------------------------------
static const Parameter ftp_server_validity_params[] =