Author: L1B0
[TOC]
a. 保密性(Confidentiality) b. 完整性(Integrity) c. 可靠性(Availability)
a. 持久性与时效性
原理 a. n2s函数(network2host): 小端序转大端序 b. memcpy(),可以读取任意长度的数据
解决方法 a. check payload length
a. PCB控制块存在于kernel b. 内核态提供系统调用set-UID
- Allow user to run a program with the program owner's privilege(特权).
- with tempoary elevated privileges.
- Example: passwd - ruid(user1) euid(root)
a. Don't mix code and data.
b. TrustZone: 硬件实现
- The need for privileged programs
- How the Set-UID programs work
a. LD_PRELOAD and LD_LIBRARY_PATH
gcc -c sleep.c
gcc -shared -o libmylib.so.1.0.1 sleep.o
export LD_PRELOAD=./libmylib.so.1.0.1
export LD_LIBRARY_PATH=.
./mytest
Dynamic linker ignores the LD_PRELOAD and LD_LIBRARY_PATH environment when EUID and GUID differ.
b. system: firstly call execvel,then evecvel call /bin/sh
a. 改程序,jmp到自己的函数
b. Linux中LD_PRELOAD机制
// prog.c
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char arr[64]; // 溢出
char *ptr;
ptr = getenv("PWD"); // 可篡改
if(ptr != NULL)
{
sprintf(arr,"Present working directory is: %s",ptr); // don't check the length
printf("%s\n",arr);
}
return 0;
}
a. use a secure version of getenv(), such as secure_getenv().
When EUID and RUID don’t match it returns NULL.
b. use a secure version of sprintf()
Set-UID: 有更大的攻击面,因为env可被user篡改
foo='() { echo "I'm fine" }; /bin/sh'
echo foo
declare -f foo
export foo
a. stack栈: 局部变量
b. heap堆:动态分配空间的变量
c. bss:未初始化的或者初始化为0的全局变量和静态变量
d. data: 已初始化的全局变量
###2. call, return
a. call
call funcA // push IP
push ebp
mov ebp esp
sub esp 20
b. ret
add esp 20
pop ebp
ret
shellcode
ASLR: Address Space Layout Randomization
NX: Non-Executable Stack
Cannary: 在栈上填充一段数据,防止栈溢出
a. 编译设置
gcc -z noexecstack test.c -o test
b. 实现原理
大致通过内存,页表实现(页帧),设置标志位(x)。
Jump to existing code: e.g. libc library
Function: system(‘/bin/sh’)
gcc -S prog.c
cat prog.s
return -> 1?
a. 未对齐的内存访问
b. 指令集不定长,可以从任意地方截取一段。
a. 编译器拓展 - 添加安全措施
b. 程序语言 - rust
c. 随机性&多样性
d. 二进制文件插桩 - Binary Instrumentation
###3. shadow stack
###4. Control-Flow Integrity
非间接跳转
call eax [eax] [0x1234]
jmp eax
ret
可靠 : 一定对,但不全
完备:一定全,但不全对
- 发生在多个进程竞争同一种资源
- 利用的时间窗口:Time-Of-Check To TIme-Of-Use
- ACID: 原子性(Atomicity)、一致性(Consistency)、隔离性(Isolation)、持久性(Durability)
- mmap() - system call to map files or devices into memory
- Copy-On-Write: 修改时创建一个拷贝进行操作。
- Swap:
- task_struct
sudo insmod hello.ko
隐藏进程
-
自动生成测试用例
-
mutation based fuzzing: 随便测试,改几个字节
-
generation based fuzzing:
-
AFL fuzzing: 插桩,回馈机制
Jame C King, Symbolic Execution and Program Testing CACM, 1976
指令本质: 修改内存,寄存器