#include "curses.h"
-#include <ctype.h>
-#include "flow/flow.h"
-#include "protocols/packet.h"
-
using namespace std;
enum DceRpcPduType
}
// map between service and curse details
-map<string, CurseDetails> curse_map
+static vector<CurseDetails> curse_map
{
// service_name alg is_tcp
- { "dce_udp", { dce_udp_curse, false }},
- { "dce_tcp", { dce_tcp_curse, true }},
- { "dce_smb", { dce_smb_curse, true }},
+ { "dce_udp", dce_udp_curse, false },
+ { "dce_tcp", dce_tcp_curse, true },
+ { "dce_smb", dce_smb_curse, true },
};
+bool CurseBook::add_curse(const char* key)
+{
+ for (const CurseDetails& curse : curse_map)
+ {
+ if (curse.service == key)
+ {
+ if (curse.is_tcp)
+ tcp_curses.push_back(&curse);
+ else
+ non_tcp_curses.push_back(&curse);
+ return true;
+ }
+ }
+ return false;
+}
+
+const vector<const CurseDetails*>& CurseBook::get_curses(bool tcp) const
+{
+ if (tcp)
+ return tcp_curses;
+ return non_tcp_curses;
+}
+
s2c_hexes = nullptr;
c2s_spells = nullptr;
s2c_spells = nullptr;
+ curses = nullptr;
}
WizardModule::~WizardModule()
delete c2s_spells;
delete s2c_spells;
+
+ delete curses;
}
ProfileStats* WizardModule::get_profile() const
spells.push_back(v.get_string());
else if ( v.is("curses") )
- curses.push_back(v.get_string());
+ curses->add_curse(v.get_string());
else
return false;
c2s_spells = new SpellBook;
s2c_spells = new SpellBook;
- curses.clear();
+
+ curses = new CurseBook;
}
else if ( !strcmp(fqn, "wizard.hexes") )
hex = true;
add_spells(s2c_spells, service);
}
- spells.clear();
service.clear();
+ spells.clear();
return true;
}
return b;
}
+CurseBook* WizardModule::get_curse_book()
+{
+ CurseBook* b = curses;
+ curses = nullptr;
+ return b;
+}
+
const PegInfo* WizardModule::get_pegs() const
{ return wiz_pegs; }
struct CurseServiceTracker
{
- string service;
+ const CurseDetails* curse;
CurseTracker* tracker;
};
void reset(Wand&, bool tcp, bool c2s);
bool cast_spell(Wand&, Flow*, const uint8_t*, unsigned);
bool spellbind(const MagicPage*&, Flow*, const uint8_t*, unsigned);
- bool cursebind(vector<CurseServiceTracker>&,Flow*, const uint8_t*, unsigned);
+ bool cursebind(vector<CurseServiceTracker>&, Flow*, const uint8_t*, unsigned);
public:
MagicBook* c2s_hexes;
MagicBook* c2s_spells;
MagicBook* s2c_spells;
- vector<string> curse_book;
+
+ CurseBook* curses;
};
//-------------------------------------------------------------------------
c2s_spells = m->get_book(true, false);
s2c_spells = m->get_book(false, false);
- curse_book = m->get_curse_book();
+
+ curses = m->get_curse_book();
}
Wizard::~Wizard()
delete c2s_spells;
delete s2c_spells;
+
+ delete curses;
}
void Wizard::reset(Wand& w, bool tcp, bool c2s)
if (w.curse_tracker.empty())
{
- for ( auto service:curse_book )
+ vector<const CurseDetails*> pages = curses->get_curses(tcp);
+ for ( const CurseDetails* curse : pages )
{
- if (tcp == curse_map[service].is_tcp)
- {
- if (tcp)
- w.curse_tracker.push_back({ service, new CurseTracker });
- else
- w.curse_tracker.push_back({ service, nullptr });
- }
+ if (tcp)
+ w.curse_tracker.push_back({ curse, new CurseTracker });
+ else
+ w.curse_tracker.push_back({ curse, nullptr });
}
}
}
return false;
}
+bool Wizard::cursebind(vector<CurseServiceTracker>& curse_tracker, Flow* f,
+ const uint8_t* data, unsigned len)
+{
+ for (const CurseServiceTracker& cst : curse_tracker)
+ {
+ if (cst.curse->alg(data, len, cst.tracker))
+ {
+ f->service = cst.curse->service.c_str();
+ // FIXIT-H need to make sure Flow's ipproto and service
+ // correspond to HostApplicationEntry's ipproto and service
+ host_cache_add_service(f->server_ip, f->ip_proto, f->server_port, f->service);
+ return true;
+ }
+ }
+
+ return false;
+}
+
bool Wizard::cast_spell(
Wand& w, Flow* f, const uint8_t* data, unsigned len)
{
return false;
}
-bool Wizard::cursebind(
- vector<CurseServiceTracker>& curse_tracker, Flow* f, const uint8_t* data, unsigned len)
-{
- bool match = false;
-
- for (auto const& p : curse_tracker)
- {
- if (curse_map[p.service].alg(data,len, p.tracker))
- {
- match = true;
- f->service = p.service.c_str();
- break;
- }
- }
-
- if (match)
- {
- // FIXIT-H need to make sure Flow's ipproto and service
- // correspond to HostApplicationEntry's ipproto and service
- host_cache_add_service(f->server_ip, f->ip_proto, f->server_port, f->service);
- }
-
- return match;
-}
-
//-------------------------------------------------------------------------
// api stuff
//-------------------------------------------------------------------------