Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions cmake/Modules/EttercapLibCheck.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ check_function_exists(memmem HAVE_MEMMEM)
check_function_exists(memrchr HAVE_MEMRCHR)
check_function_exists(basename HAVE_BASENAME)
check_function_exists(strndup HAVE_STRNDUP)
check_function_exists(setresuid HAVE_SETRESUID)

find_library(HAVE_PCAP pcap)
if(HAVE_PCAP)
Expand Down
1 change: 1 addition & 0 deletions include/config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#cmakedefine HAVE_MEMMEM
#cmakedefine HAVE_MEMRCHR
#cmakedefine HAVE_BASENAME
#cmakedefine HAVE_SETRESUID

#cmakedefine HAVE_NCURSES
#cmakedefine HAVE_GTK
Expand Down
2 changes: 1 addition & 1 deletion include/ec.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
#define _REENTRANT /* for strtok_r() */
#endif
#include <string.h>
#include <unistd.h> /* for setresuid() and setresgid() */
#if defined (__USE_GNU)
#undef __USE_GNU
#endif
#if defined (_GNU_SOURCE)
#undef _GNU_SOURCE
#endif
#include <strings.h>
#include <unistd.h>
#include <time.h>

/*
Expand Down
26 changes: 26 additions & 0 deletions src/ec_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,17 @@ void regain_privs(void)
#ifdef OS_WINDOWS
return;
#endif
#ifdef HAVE_SETRESUID
/* the saved set-user-ID is still 0, see drop_privs() */
if (setresuid(0, 0, 0) < 0)
ERROR_MSG("setresuid()");

if (setresgid(0, 0, 0) < 0)
ERROR_MSG("setresgid()");
#else
if(seteuid(0) < 0)
ERROR_MSG("seteuid()");
#endif

USER_MSG("Regained root privileges: %d %d", getuid(), geteuid());
}
Expand Down Expand Up @@ -227,6 +236,22 @@ void drop_privs(void)

reset_logfile_owners(geteuid(), getegid(), uid, gid);

#ifdef HAVE_SETRESUID
/*
* set both the real and the effective IDs, keeping only the saved
* set-user-ID as root so regain_privs() still works.
* a process with real UID 0 and a non-root effective UID looks like a
* setuid binary to its children, and e.g. bubblewrap (used by the
* glycin image loaders behind GTK) refuses to run in that state.
*/
DEBUG_MSG("drop_privs: setresuid(%d) setresgid(%d)", uid, gid);

if ( setresgid(gid, gid, 0) < 0 )
ERROR_MSG("setresgid()");

if ( setresuid(uid, uid, 0) < 0 )
ERROR_MSG("setresuid()");
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
#else
DEBUG_MSG("drop_privs: seteuid(%d) setegid(%d)", uid, gid);

/* drop to a good uid/gid ;) */
Expand All @@ -235,6 +260,7 @@ void drop_privs(void)

if ( seteuid(uid) < 0 )
ERROR_MSG("seteuid()");
#endif

DEBUG_MSG("privs: UID: %d %d GID: %d %d", (int)getuid(), (int)geteuid(), (int)getgid(), (int)getegid() );
USER_MSG("Privileges dropped to EUID %d EGID %d...\n\n", (int)geteuid(), (int)getegid() );
Expand Down
Loading