Is there a (compatible) way to spoof (as the root user) unix socket (file system sockets) equal credentials that can be obtained getsockopt(), an option SO_PEERCRED?
getsockopt()
SO_PEERCRED
Background:I need to connect to a server application (which I cannot change) that checks the UIDprocess that connects to it through SO_PEERCRED. I would like to trick the information so that I can connect to the application as the root as well .
UID
UPDATE
To clarify the question:I am looking for a non-invasive way that the server sees a specific peer UID/ GID. The solutions are discouraged by which it is necessary to change the kernel (or use kernel modules) or change the server process or its loading / linking process > in any case ( LD_PRELOAD, intercepting system calls, etc.).
GID
LD_PRELOAD
In principle, the solution should work when working on any linux server (or unix in general) without any special requirements. The server process may already be running.
. , , SO_PEERCRED API , , .
, :
(setreuid(desired,-1)) connect. unix- , connect ( listen ). SO_PEERCRED . root.
setreuid(desired,-1)
connect
listen
API. API- , . sendmsg struct cmsg, , . , , , , - . , - . Google "SCM_CREDENTIALS" ( "man -K" ), .
sendmsg
struct cmsg
. , , UID GID , , ! PID , . , connect . . copy_peercred() unix_stream_connect() net/unix/af_unix.c. , , , PID , . AF_INET, IP, .
copy_peercred()
unix_stream_connect()
net/unix/af_unix.c
, , , - UID UID/GID, , root-, sudo .
sudo