slimm609/checksec

GitHub: slimm609/checksec

一款由 Golang 编写的高效跨平台工具,用于快速审计 Linux 二进制文件的安全编译属性及内核防护配置。

Stars: 2300 | Forks: 312

# checksec Checksec 用于检查可执行文件的属性(例如 PIE、RELRO、Canaries、ASLR、Fortify Source)。 它最初由 Tobias Klein 编写,原始源代码可在此处获取:http://www.trapkit.de/tools/checksec.html。随着时间的推移,其功能集不断扩展,并已从 Bash 迁移至 Golang。 版本:3.0.1 ## 更新 Checksec 最初于 2009 年初发布 1.0 版本,十多年来一直用于验证 Linux 系统的二进制检查。随着时间的推移,随着支持的检查增多以及 Linux 发行版的变化,这给 checksec 带来了更多的依赖项。为了能够检查文件的安全标志而添加越来越多的依赖项,对于依赖项较少的系统(包括嵌入式系统、distroless 容器和跨平台检查)来说,这并不是一个理想的解决方案。 - Bash 版本和 Golang 版本之间的功能将基本得到支持。 - 添加对 yaml 输出的支持 - 移除对 CSV 的支持 - JSON 和 XML 仍将受到支持 - 结果要快得多。当检查目录中的 694 个文件时 - bash: real 0m10.348s - golang: real 0m0.691s ## 适用于 OSX Checksec 可以从 OSX 扫描 Linux 文件,但是由于操作系统对资源(如 glibc)的依赖,某些检查可能会受到限制。 ## 示例 **普通(或 --format=cli)** ``` $checksec file /bin/ls RELRO Stack Canary NX PIE RPATH RUNPATH Symbols FORTIFY Fortified Fortifiable Name Partial RELRO Canary Found NX enabled PIE Enabled No RPATH No RUNPATH No Symbols No 0 14 /bin/ls ``` **yaml** ``` $ checksec file /bin/ls --output yaml - checks: canary: Canary Found fortified: "0" fortify_source: "No" fortifyable: "14" nx: NX enabled pie: PIE Enabled relro: Partial RELRO rpath: No RPATH runpath: No RUNPATH symbols: No Symbols name: /bin/ls ``` **xml** ``` $ checksec file /bin/ls --output xml /bin/ls Canary Found 0 14 No NX enabled PIE Enabled Partial RELRO No RPATH No RUNPATH No Symbols ``` **json** ``` $ checksec file /bin/ls --output json [ { "checks": { "canary": "Canary Found", "fortified": "0", "fortify_source": "No", "fortifyable": "14", "nx": "NX enabled", "pie": "PIE Enabled", "relro": "Partial RELRO", "rpath": "No RPATH", "runpath": "No RUNPATH", "symbols": "No Symbols" }, "name": "/bin/ls" } ] ``` **cli 中的 Fortify 测试** ``` $ checksec fortifyProc 1 _____ _ _ ______ _____ _ __ _____ ______ _____ / ____| | | | ____/ ____| |/ // ____| ____/ ____| | | | |__| | |__ | | | ' /| (___ | |__ | | | | | __ | __|| | | < \___ \| __|| | | |____| | | | |___| |____| . \ ____) | |___| |____ \_____|_| |_|______\_____|_|\_\_____/|______\_____| * FORTIFY_SOURCE support available (libc): Yes * Binary compiled with FORTIFY_SOURCE support: No ------ EXECUTABLE-FILE ------- | -------- LIBC -------- Fortifiable library functions | Checked function names Coming Soon SUMMARY * Number of checked functions in libc : 18 * Total number of library functions in the executable: 2011 * Number of Fortifiable functions in the executable : 12 * Number of checked functions in the executable : 0 * Number of unchecked functions in the executable : 12 ``` **cli 中的内核测试** ``` $ checksec kernel _____ _ _ ______ _____ _ __ _____ ______ _____ / ____| | | | ____/ ____| |/ // ____| ____/ ____| | | | |__| | |__ | | | ' /| (___ | |__ | | | | | __ | __|| | | < \___ \| __|| | | |____| | | | |___| |____| . \ ____) | |___| |____ \_____|_| |_|______\_____|_|\_\_____/|______\_____| Kernel configs only print what is supported by the specific kernel/kernel config Description Value Check Type Config Key Virtually-mapped kernel stack Disabled Kernel Config CONFIG_VMAP_STACK Harden str/mem functions Disabled Kernel Config CONFIG_FORTIFY_SOURCE Restrict Kernel RWX Enabled Kernel Config CONFIG_STRICT_KERNEL_RWX Restrict /dev/mem access Enabled Kernel Config CONFIG_STRICT_DEVMEM SELinux Kernel Flag Disabled Kernel Config CONFIG_SECURITY_SELINUX Emulate privileged access never Disabled Kernel Config CONFIG_ARM64_SW_TTBR0_PAN Restrict I/O access to /dev/mem Disabled Kernel Config CONFIG_IO_STRICT_DEVMEM Kernel Heap Randomization Disabled Kernel Config CONFIG_COMPAT_BRK Stack Protector Strong Disabled Kernel Config CONFIG_STACKPROTECTOR_STRONG Hardened Usercopy Disabled Kernel Config CONFIG_HARDENED_USERCOPY Restrict Module RWX Enabled Kernel Config CONFIG_STRICT_MODULE_RWX Address space layout randomization Disabled Kernel Config CONFIG_RANDOMIZE_BASE Randomize address of kernel image Disabled Kernel Config CONFIG_RANDOMIZE_BASE Stack Protector Disabled Kernel Config CONFIG_STACKPROTECTOR Unmap kernel in userspace (KAISER) Enabled Kernel Config CONFIG_UNMAP_KERNEL_AT_EL0 SLAB freelist randomization Disabled Kernel Config CONFIG_SLAB_FREELIST_RANDOM SELinux Enabled Disabled SELinux SELinux Protected symlinks Enabled Sysctl fs.protected_symlinks Protected hardlinks Enabled Sysctl fs.protected_hardlinks Ipv4 reverse path filtering Disabled Sysctl net.ipv4.conf.all.rp_filter YAMA Unknown Sysctl kernel.yama.ptrace_scope Exec Shield Unknown Sysctl kernel.exec-shield Unprivileged BPF Disabled Disabled Sysctl kernel.unprivileged_bpf_disabled Vanilla Kernel ASLR Enabled Sysctl kernel.randomize_va_space Dmesg Restrictions Enabled Sysctl kernel.dmesg_restrict Kernel Pointer Restrictions Disabled Sysctl kernel.kptr_restrict Protected fifos Disabled Sysctl fs.protected_fifos Protected regular Disabled Sysctl fs.protected_regular Performance events by normal users Enabled Sysctl kernel.perf_event_paranoid Disable Autoload TTY Line Disciplines Disabled Sysctl dev.tty.ldisc_autoload Disable Legacy TIOCSTI Disabled Sysctl dev.tty.legacy_tiocsti ``` **XML 中的内核测试** ``` $ checksec kernel --output xml CONFIG_IO_STRICT_DEVMEM Restrict I/O access to /dev/mem Disabled Kernel Config CONFIG_STRICT_MODULE_RWX Restrict Module RWX Enabled Kernel Config CONFIG_SECURITY_SELINUX SELinux Kernel Flag Disabled Kernel Config ``` **Json 中的内核测试** ``` $ checksec kernel --output json [ { "desc": "Hardened Usercopy", "name": "CONFIG_HARDENED_USERCOPY", "type": "Kernel Config", "value": "Disabled" }, { "desc": "Harden str/mem functions", "name": "CONFIG_FORTIFY_SOURCE", "type": "Kernel Config", "value": "Disabled" }, { "desc": "Restrict Kernel RWX", "name": "CONFIG_STRICT_KERNEL_RWX", "type": "Kernel Config", "value": "Enabled" }, { "desc": "Virtually-mapped kernel stack", "name": "CONFIG_VMAP_STACK", "type": "Kernel Config", "value": "Disabled" }, { "desc": "SELinux Kernel Flag", "name": "CONFIG_SECURITY_SELINUX", "type": "Kernel Config", "value": "Disabled" } ] ``` ## 用于交叉编译系统 checksec 工具可用于离线检查交叉编译的目标文件系统。需要注意的主要限制: * 内核测试 - 需要您在想要检查的正在运行的系统上执行该脚本,因为它们直接访问内核资源以识别系统配置/状态。您可以在 -k 选项后指定内核的配置文件。 * 文件检查 - 离线测试适用于除 Fortify 功能外的所有检查。默认情况下,Fortify 使用正在运行的系统的库,而不是离线文件系统中的库。有一些解决此问题的方法(chroot),但目前,理想的配置是在检查文件时在正在运行的系统上执行此脚本。另一种选择是通过 -libc 选项指定交叉编译的 libc 所在的位置。 checksec 工具的常规用例是对系统配置进行运行时检查。如果系统是嵌入式目标,则可能不存在原生 binutils 工具(如 readelf)。这将限制脚本的某些部分无法工作。 即使存在这些限制,该脚本提供的有价值信息量仍然使其成为检查离线文件系统的宝贵工具。
标签:AES-256, ASLR, DEP, DNS 反向解析, ELF文件, EVTX分析, EVTX分析, Fortify Source, Golang, Go语言, NX, PIE, RELRO, Stack Canary, Web截图, Web报告查看器, 二进制分析, 云安全运维, 云资产清单, 关系图谱, 基线检查, 子域名枚举, 安全合规, 安全编程, 容器安全, 嵌入式安全, 文件扫描, 漏洞评估, 程序破解, 系统安全, 编译器安全特性, 网络代理, 逆向工程, 防御验证