Skip to content

Commit

Permalink
Report all live proxy OIDs on ping
Browse files Browse the repository at this point in the history
- create proxy crawling API function
- add it to the webhook ping() call
  • Loading branch information
astibal committed Nov 20, 2023
1 parent 3f2c55e commit 8966b11
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
46 changes: 46 additions & 0 deletions src/service/core/smithproxy_objapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,52 @@
#include <service/http/jsonize.hpp>
#include <proxy/mitmproxy.hpp>

void ObjAPI::for_each_proxy(std::function<void(MitmProxy*)> callable) {
auto const& instance = SmithProxy::instance();

auto lc_ = std::scoped_lock(socle::sobjectDB::getlock());


auto list_worker = [callable](const char* title, auto& listener) {
for (auto const& acc: listener) {
for(auto const& wrk: acc->tasks()) {

auto lc_ = std::scoped_lock(wrk.second->proxy_lock());

for(auto const& [ p, _ ] : wrk.second->proxies()) {
if(auto* proxy = dynamic_cast<MitmProxy*>(p.get()); p != nullptr) {
callable(proxy);
}
}
}
}
};

list_worker("plain acceptor", instance.plain_proxies);
list_worker("tls acceptor", instance.ssl_proxies);

list_worker("udp receiver", instance.udp_proxies);
list_worker("dtls receiver", instance.dtls_proxies);

list_worker("socks acceptor", instance.socks_proxies);

list_worker("plain redirect acceptor", instance.redir_plain_proxies);
list_worker("dns redirect receiver", instance.redir_udp_proxies);
list_worker("tls redirect acceptor", instance.redir_ssl_proxies);
}

nlohmann::json ObjAPI::proxy_session_connid_list() {

using nlohmann::json;
json ret;

for_each_proxy([&ret](MitmProxy const* px){
if(px) ret.push_back(px->to_connection_ID());
});

return ret;
}

nlohmann::json ObjAPI::proxy_session_list_json(uint64_t oid, bool active_only, bool tls_info, bool verbose) {
using nlohmann::json;
auto const& instance = SmithProxy::instance();
Expand Down
7 changes: 6 additions & 1 deletion src/service/core/smithproxy_objapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

#include <nlohmann/json.hpp>

class MitmMproxy;
struct ObjAPI {
void for_each_proxy(std::function<void(MitmProxy*)> callable);

nlohmann::json proxy_session_connid_list();
nlohmann::json proxy_session_list_json(uint64_t oid, bool active_only, bool tls_info, bool verbose);
};
};

3 changes: 2 additions & 1 deletion src/service/http/webhooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ namespace sx::http::webhooks {
nlohmann::json const ping = {
{ "action", "ping" },
{"source", get_hostid() },
{"type", "proxy"}
{"type", "proxy"},
{"proxies", SmithProxy::instance().API.proxy_session_connid_list() }
};
sx::http::AsyncRequest::emit(
to_string(ping),
Expand Down

0 comments on commit 8966b11

Please sign in to comment.