Skip to content

Commit

Permalink
enable "statistics" filter and make it available in config
Browse files Browse the repository at this point in the history
  • Loading branch information
astibal committed Oct 4, 2023
1 parent 208f438 commit 011ab98
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
13 changes: 13 additions & 0 deletions src/proxy/mitmproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@

#include <log/logger.hpp>
#include <service/cfgapi/cfgapi.hpp>
#include <service/http/webhooks.hpp>

#include <uxcom.hpp>
#include <staticcontent.hpp>
#include <policy/authfactory.hpp>

#include <traflog/fsoutput.hpp>
#include <service/tpool.hpp>

#include <algorithm>

Expand Down Expand Up @@ -193,6 +195,17 @@ MitmProxy::~MitmProxy() {
if(tlog()) tlog()->write_left("Connection stop\n");
}


if(not filters_.empty() and sx::http::webhooks::is_enabled()) {
auto event = nlohmann::json();

for (auto &[name, filter]: filters_) {
filter->update_states();
event[name] = filter->to_json(iINF);
}
sx::http::webhooks::send_action("connection-info", event);
}

current_sessions()--;
}

Expand Down
32 changes: 26 additions & 6 deletions src/service/cfgapi/cfgapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include <proxy/mitmhost.hpp>

#include <proxy/filters/sinkhole.hpp>
#include <proxy/filters/statsfilter.hpp>

#include <inspect/dnsinspector.hpp>
#include <inspect/pyinspector.hpp>
Expand Down Expand Up @@ -1173,6 +1174,9 @@ int CfgFactory::load_db_features() {
auto sa = std::make_shared<CfgString>("sink-all");
db_features["sink-all"] = std::move(sa);

auto statistics = std::make_shared<CfgString>("statistics");
db_features["statistics"] = std::move(statistics);

return static_cast<int>(db_features.size());
}

Expand Down Expand Up @@ -2613,17 +2617,33 @@ void CfgFactory::policy_apply_features(std::shared_ptr<PolicyRule> const & polic

// apply feature tags
if(policy_rule and not policy_rule->features.empty()) {
FilterProxy* f = nullptr;
FilterProxy* sink_filter = nullptr;
FilterProxy* statistics_filter = nullptr;

for(auto const& it: policy_rule->features) {
if(it->value() == "sink-left") { if(not f) f = new SinkholeFilter(mitm_proxy, true, false); }
if(it->value() == "sink-right") { if(not f) f = new SinkholeFilter(mitm_proxy, false, true); }
if(it->value() == "sink-all") { if(not f) f = new SinkholeFilter(mitm_proxy, true, true); }
if(not sink_filter) {
if (it->value() == "sink-all") sink_filter = new SinkholeFilter(mitm_proxy, true, true);
else if (it->value() == "sink-left") sink_filter = new SinkholeFilter(mitm_proxy, true, false);
else if (it->value() == "sink-right") sink_filter = new SinkholeFilter(mitm_proxy, false, true);
}

if(not statistics_filter) {
if (it->value() == "statistics") {
statistics_filter = new StatsFilter(mitm_proxy);

}
}
}

if(f) {
mitm_proxy->add_filter(f->to_string(iINF), f);
if(statistics_filter) {
mitm_proxy->add_filter("statistics", statistics_filter);
}
if(sink_filter) {
mitm_proxy->add_filter("sinkhole", sink_filter);
}

}

}

int CfgFactory::policy_apply (baseHostCX *originator, baseProxy *proxy, int matched_policy) {
Expand Down

0 comments on commit 011ab98

Please sign in to comment.