Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions osquery/events/linux/http_event_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
#include <osquery/registry_factory.h>
#include <osquery/utils/conversions/split.h>
#include <osquery/utils/conversions/tryto.h>
#include <osquery/system.h>

#include <pwd.h>
#include <arpa/inet.h>
#include <boost/range/adaptor/map.hpp>
#include <netinet/if_ether.h>
#include <netinet/in.h>
#include <netinet/ip.h>
Expand All @@ -30,6 +31,7 @@

#include <set>
#include <vector>
#include <boost/range/adaptor/map.hpp>

#include "http_event_publisher.h"

Expand Down Expand Up @@ -102,7 +104,6 @@ inline bool readIPv6SourceDest(const unsigned char* packet,

return true;
}

} // namespace

/// Internal traffic filter
Expand Down Expand Up @@ -339,6 +340,22 @@ void HTTPLookupEventPublisher::processPacket(unsigned char* args,
long size_tcp;
long size_payload;

// Use privilege dropper
auto dropper = DropPrivileges::get();
// set low privilege mode only if it is running in root context
if (getuid() == 0) {
// Attempt to drop to nobody.
auto nobody = getpwnam("nobody");
if( nobody == nullptr) {
LOG(WARNING) << "Could not get 'nobody' uid and gid";
}
if (!dropper->dropTo(nobody->pw_uid, nobody->pw_gid) && (!(geteuid() == nobody->pw_uid))) {
LOG(WARNING) << "Failed to drop privilege to nobody";
}
} else {
LOG(WARNING) << "Not root, skipping privilege drop";
}

/*Linux consists of 16 more bytes of Linux cooked capture header,Skipping.*/
packet = packet + 16;

Expand Down