根進程檢查記憶體的能力

根進程檢查記憶體的能力

我知道在 Linux 機器上,如果一個進程能夠獲得 root 權限,它就可以存取它通常無法存取的檔案系統的部分內容。

我想問一個 root 的 Linux 進程是否可以檢查系統上任何其他進程的記憶體?因此,如果我有一個進程在其堆疊或堆疊中包含秘密,那麼根進程是否能夠存取它,如果是,它將如何做到這一點?

(無論是誰回答,也可以考慮 root shell 進程;我只關心具有 root 存取權限的進程)

答案1

是的,你可以,例如,請參閱這個答案 https://stackoverflow.com/questions/12977179/reading-living-process-memory-without-interrupting-it

或玩/dev/<pid>/mem/dev/kmem像這樣

例如使用這段程式碼,使用者可以讀取主機上任何進程的記憶體。

#! /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()

ptrace另請參閱和的使用gdb,這些工具旨在即時執行此操作。

讀取 bash shell 內存

root 讀取 bash shell 內存

答案2

是的。

根功能已被破壞。現在,一個進程可以擁有它們的子集(包括根沒有)。

透過查看功能手冊頁,我們可以看到 root 可以(通常)做什麼。

我包括一個很少這裡:

   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.

此處顯示的模組CAP_SYS_MODULE可用於載入可以執行此操作的核心模組;CAP_SYS_RAWIO可以用來打開/dev/mem;還有其他具有其他功能的方法,包括ptrace.

相關內容