4

I know on a Linux machine, if a process is able to get root privilege, it can access parts of the file system it normally wouldn't have access to.

I want to ask whether a rooted Linux process can inspect memory of any other process on a system ? So if I have a process which contains a secret in its heap or stack, will a rooted process be able to access it, and if yes, how will it do it ?

(Whoever answers may also consider a rooted shell process; I'm just concerned about a process with root access)

Jake
  • 1,353
  • 1
    A process with root can ptrace any other process and do whatever it likes to it. To include reading stack and heap, altering program code, randomly inducing segfaults.... – Tom Hunt Nov 05 '15 at 17:43

2 Answers2

2

yes you can, for examples see this answer https://stackoverflow.com/questions/12977179/reading-living-process-memory-without-interrupting-it

or play with /dev/<pid>/mem or /dev/kmem like this

e.g. with this code, root user can read memory of any process on the host.

#! /usr/bin/env python
import re
import sys

print(sys.argv[1] + ".dump") maps_file = open("/proc/"+ sys.argv[1] + "/maps", 'r') mem_file = open("/proc/" + sys.argv[1] + "/mem", 'rb', 0) output_file = open(sys.argv[1] + ".dump", 'wb') for line in maps_file.readlines(): # for each mapped region m = re.match(r'([0-9A-Fa-f]+)-([0-9A-Fa-f]+) ([-r])', line) if m.group(3) == 'r': # if this is a readable region start = int(m.group(1), 16) end = int(m.group(2), 16) mem_file.seek(start) # seek to region start chunk = mem_file.read(end - start) # read region contents output_file.write(chunk) # dump contents to standard output maps_file.close() mem_file.close() output_file.close()

See also the use of ptrace and gdb, tools which are designed to do this in real time.

reading bash shell memory

root reading bash shell memory

0

Yes.

The root capabilities have been broken up. Now A process can have a subset of them (including root having none).

By looking at the man page of capabilities, we can see what root can (normally) do.

I include a few here:

   CAP_DAC_OVERRIDE
          Bypass file read, write, and execute permission checks.  (DAC
          is an abbreviation of "discretionary access control".)

   CAP_KILL
          Bypass permission checks for sending signals (see kill(2)).
          This includes use of the ioctl(2) KDSIGACCEPT operation.

   CAP_NET_BIND_SERVICE
          Bind a socket to Internet domain privileged ports (port
          numbers less than 1024).

   CAP_SYS_MODULE
          * Load and unload kernel modules (see init_module(2) and
            delete_module(2));
          * in kernels before 2.6.25: drop capabilities from the system-
            wide capability bounding set.

   CAP_SYS_TIME
          Set system clock (settimeofday(2), stime(2), adjtimex(2)); set
          real-time (hardware) clock.

   CAP_SYS_RAWIO
          * Perform I/O port operations (iopl(2) and ioperm(2));
          * access /proc/kcore;
          * employ the FIBMAP ioctl(2) operation;
          * open devices for accessing x86 model-specific registers
            (MSRs, see msr(4));
          * update /proc/sys/vm/mmap_min_addr;
          * create memory mappings at addresses below the value
            specified by /proc/sys/vm/mmap_min_addr;
          * map files in /proc/bus/pci;
          * open /dev/mem and /dev/kmem;
          * perform various SCSI device commands;
          * perform certain operations on hpsa(4) and cciss(4) devices;
          * perform a range of device-specific operations on other
            devices.

Of the ones shown here, CAP_SYS_MODULE could be used in load a kernel module that could do it; CAP_SYS_RAWIO could be used to open /dev/mem; There are other ways with other capabilities, including ptrace.