2021 redhat simpleVM
GitHub - fghcvjk/2021redhat: 第四届 “红帽杯” 网络安全大赛 - 初赛
对于 llvm pwn
需要三个组件 一个是 opt 用于将一个对 ir 操作的规则 so 加载到一个 lr or bc 文件里。从而完成 ir 层面的处理。
而这里已经给了 opt 与 so 我们要写的就是 bc 去利用这个 opt。
123456[*] '/home/squ/prac/pwn/opt-8' Arch: amd64-64-little RELRO: Partial RELRO X Stack: No canary found X NX: NX enabled √ PIE: No PIE (0x400000) X
# pass 练习
假设我要找到一个函数的所有调用
拿到一个 function
遍历所有 BasicBlock
遍历 BB 中的所有 instruction
根据 instruction 构造一个 CallBase 也就是这个 in ...
afl-forkserver-maneuver
# forkserver 的目的
参见 lcamtuf.blogspot
如果每次由 fuzzer 来进行 fork-execve 那么每次目标程序都得进装载器链接器和动态加载库打一套 十分浪费时间。
但是 如果我们劫持了目标程序的_start 让目标程序一开始执行我们写入的 forkserver 代码,这样就能在装载之后通过 COW 实现低成本的 fork。
也就是 forkserver 本身就注入到目标程序里面去了,作为目标程序的起始点不断的进行 fork。
# trampoline
这个被插桩到每个基本块之前
1234567891011121314151617181920static const u8* trampoline_fmt_64 = "\n" "/* --- AFL TRAMPOLINE (64-BIT) --- */\n" "\n" ".align 4\n" "\n" "leaq -(128+24)(%%rsp), %%rsp\n" ...
CVE-2022-0847-DIRTY-PIPE-detail
# basic
(之后会把 docker 做好传上去 以后就不用折腾了 QAQ)
https://hub.docker.com/repository/docker/squirre17/dirtypipe
# page cache
Linux 的换页机制是脏页机制,也就是写一个文件是通过写内存缓存页,然后标记脏位,在换页的时候一次性写回磁盘。而不是每次都写磁盘。
在打开文件的时候可以用 O_DIRECT | O_SYNC 来标记对脏页进行直写策略,换回同步。
但这里并不是对文件进行硬存级别的篡改,假设文件进了内存,然后我修改了这个文件内存中的部分内容,短时间再次访问这个文件会直接从内存缓存中拿到我们篡改过的内容而不是去 disk 上取。
# structs
# file
fs.h - include/linux/fs.h - Linux source code (v5.13-rc1) - Bootlin
每一个打开的文件描述符和一个 struct 相对应
pipe_inode_info 指向一个内核管道
1234567891011struct file {... ...
debugger-impl
How debuggers work: Part 1 - Basics - Eli Bendersky’s website
单纯的复现此文章。
# single step
首先是 ptrace
12long ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data);
对于第一个 request 的参数
PTRACE_TRACEME request, which means that this child process asks the OS kernel to let its parent trace it.
这个参数只用于子进程,所以这里是在 fork 之后
第三个对地址进行和第四个是地址操作相关,根据 request 的类型,是对这个 addr 进行 poke,或者 peek 这个数据到 data 里(或者直接 peek 到返回值)。
Indicates that this process is to be traced by its parent. ...
Ghidra-INDIRECT-explanation
123456789undefined4 FUN_000114b8(void){ undefined4 in_r3; printf("%s(%d)\n","part_data_end",0x7d,in_r3,in_r3); return 0;}
output result as following (pcode-refined)
123456789(ram, 0x114d4, 4) INDIRECT (ram, 0x114d4, 4) , (const, 0x15, 4)(ram, 0x114d8, 4) INDIRECT (ram, 0x114d8, 4) , (const, 0x15, 4) --- CALL (ram, 0x10ba4, 8) , (ram, 0x114d8, 4) , (ram, 0x114d4, 4) , (const, 0x7d, 4) , (register, 0x2c, 4) , (register, 0x2c, 4)(register, 0x20, 4) COPY (const, 0 ...
shared-memory-and-semaphore-machenism
# 分类
管道
消息队列
信号
共享内存
信号量
套接字
# 共享内存
1234int shmget(key_t key, size_t size, int shmflg);void *shmat(int shmid, const void *shmaddr, int shmflg);int shmdt(const void *shmaddr);int shmctl(int shmid, int cmd, struct shmid_ds *buf);
shmget() returns the identifier of the System V shared memory segment associated with the value of the argument key. It may be used either to obtain the identifier of a previously created shared memory segment (when shmflg is zero and key does not have the value ...
llvm-init
123sudo apt install lld-12sudo ln -s /lib/llvm-9/bin/llc /bin/llcsudo ln -s /lib/llvm-9/bin/opt /bin/opt
官方文档:LLVM Language Reference Manual — LLVM 16.0.0git documentation
1clang -Xclang -ast-dump -fsyntax-only test.c
生成 AST
-S Only run preprocess and compilation steps
-emit-llvm Use the LLVM representation for assembler and object files
-c Only run preprocess, compile, and assemble steps (生成字节码的 bc 文件)
1clang -S -emit-llvm test.c
生成的 ir 中
123 ...
hexp-2020-kernel-rop
Challenges
hxpCTF 2020 kernel-rop
已经同步到 gittee
先读取出 init 的文件系统
12gunzip initramfs.cpio.gzmv vmlinuz vmlinux
设置 inittab 中 sh 权限为 root
1setuidgid 0000 sh
# hackme.so
1234567891011121314151617181920ssize_t __fastcall hackme_write(file *f, const char *data, size_t size, loff_t *off){ unsigned __int64 v4; // rdx ssize_t size_1; // rbx int tmp[32]; // [rsp+0h] [rbp-A0h] BYREF unsigned __int64 v8; // [rsp+80h] [rbp-20h] size_1 = v4; v8 = __readgsqword(0x28u); if ( v4 > 0x1000 ) { ...
a-easy-virtualization-challenge
12345678910111213__int64 __fastcall sub_5713A8(__int64 a1){ __int64 result; // rax result = sub_70031D(a1, "pci-device", "/home/wang/qemu/hw/misc/myrfid.c", 369LL, "rfid_class_init"); *(_QWORD *)(result + 176) = qxl_reset_handler; *(_QWORD *)(result + 184) = 0LL; *(_WORD *)(result + 208) = 0x420; [1] <<- vendor_id *(_WORD *)(result + 210) = 0x1337; [2] <<- device_id *(_BYTE *)(result + 212) = 0x69; *(_WORD *)(result + 214) = ...
2022-cakeCTF-pwn-wp
CakeCTF 2022
# welkerme
没开 kaslr 没开 smep
找到 cc 和 pkc 一把梭了
# str.vs.cstr
c++ 简单溢出
没开 pie 和 relro
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364#include <array>#include <iostream>struct Test { Test() { std::fill(_c_str, _c_str + 0x20, 0); } char* c_str() { return _c_str; } std::string& str() { return _str; }private: __attribute__((used)) void call_me() { std::system(& ...