UNIX sockets: is it possible to fool getsockopt () SO_PEERCRED?

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?

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 .

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.).

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.

+5
source share
2 answers

. , , SO_PEERCRED API , , ​​ .

, :

  • (setreuid(desired,-1)) connect. unix- , connect ( listen ). SO_PEERCRED . root.

  • API. API- , . sendmsg struct cmsg, , . , , , , - . , - . Google "SCM_CREDENTIALS" ( "man -K" ), .

+3

. , , UID GID , ​​, ! PID , . , connect . . copy_peercred() unix_stream_connect() net/unix/af_unix.c. , , ​​ , PID , . AF_INET, ​​ IP, .

, , , - UID UID/GID, , root-, sudo .

-1

All Articles