Skip to content

Latest commit

 

History

History
executable file
·
314 lines (178 loc) · 4.94 KB

攻防对抗技术笔记.md

File metadata and controls

executable file
·
314 lines (178 loc) · 4.94 KB

攻防对抗技术笔记

Author: L1B0

[TOC]

2019-4-22

1. 计算机安全三要素

a. 保密性(Confidentiality) b. 完整性(Integrity) c. 可靠性(Availability)

2. 漏洞特点

a. 持久性与时效性

3. OpenSSL漏洞 - over_read

原理 a. n2s函数(network2host): 小端序转大端序 b. memcpy(),可以读取任意长度的数据

解决方法 a. check payload length

4. RPC(Remote Procedure Call)

2019-4-25

1. UAF漏洞:Use After Free

2. Double Free漏洞:unlink

3. 指令执行完,影响CPU的寄存器(mov eax 4)和内存(mov [eax] 4),cache

2019-4-28

1. ios越狱

a. PCB控制块存在于kernel b. 内核态提供系统调用set-UID

2. Set-UID Concept

  • Allow user to run a program with the program owner's privilege(特权).
  • with tempoary elevated privileges.
  • Example: passwd - ruid(user1) euid(root)

3. fd不关闭,使用shell利用echo

2019-4-29

1. system: 直接执行命令(用户输入)

2. execve: data与command分离

3. Principle of Isolation

​ a. Don't mix code and data.

​ b. TrustZone: 硬件实现

4. Principle of Least Privilege

5. Summary

  • The need for privileged programs
  • How the Set-UID programs work

6. Environment Variables

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

2019-5-6

1. 拦截库函数的实现(strcpy)_360杀毒

a. 改程序,jmp到自己的函数

b. Linux中LD_PRELOAD机制

2. sprintf导致的溢出 和 PWD可篡改

攻击

// 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()

3. Set-UID Approach VS Service Approach

Set-UID: 有更大的攻击面,因为env可被user篡改

Lab02 - Shellshock Attack

1. Background: Shell Functions

foo='() { echo "I'm fine" }; /bin/sh'
echo foo
declare -f foo
export foo

2. Attack

Lab03 - Buffer overflow Attack

1. memory分布

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 

3. attack

shellcode

4. defense

ASLR: Address Space Layout Randomization

NX: Non-Executable Stack

Cannary: 在栈上填充一段数据,防止栈溢出

Lab04 - Return to Libc Attack and ROP

1. Non-executable stack

a. 编译设置

gcc -z noexecstack test.c -o test

b. 实现原理

大致通过内存,页表实现(页帧),设置标志位(x)。

2. How to attack?

Jump to existing code: e.g. libc library

Function: system(‘/bin/sh’)

gcc -S prog.c
cat prog.s

return -> 1?

3. ROP

2019-5-20

1. 为什么x86会有这么多rop?

a. 未对齐的内存访问

b. 指令集不定长,可以从任意地方截取一段。

2. Countermeasures Aganist Control-Flow Attacks

a. 编译器拓展 - 添加安全措施

b. 程序语言 - rust

c. 随机性&多样性

d. 二进制文件插桩 - Binary Instrumentation

###3. shadow stack

###4. Control-Flow Integrity

非间接跳转

call eax [eax] [0x1234]

jmp eax

ret

5. soundness and completeness

可靠 : 一定对,但不全

完备:一定全,但不全对

2019-5-23

Lab06 - Race Condition Vulnerability

  1. 发生在多个进程竞争同一种资源
  2. 利用的时间窗口:Time-Of-Check To TIme-Of-Use
  3. ACID: 原子性(Atomicity)、一致性(Consistency)、隔离性(Isolation)、持久性(Durability)

Lab07 - Dirty COW(Copy-On-Wrie) Attack

  1. mmap() - system call to map files or devices into memory
  2. Copy-On-Write: 修改时创建一个拷贝进行操作。
  3. Swap:

Lab08 - DKOM(Direct Kernel Object Manipulation)

  1. task_struct
sudo insmod hello.ko

隐藏进程

Fuzzing

  • 自动生成测试用例

  • mutation based fuzzing: 随便测试,改几个字节

  • generation based fuzzing:

  • AFL fuzzing: 插桩,回馈机制

PTFuzzing(Processor Trace)

Symbolic Execution

Jame C King, Symbolic Execution and Program Testing CACM, 1976

指令本质: 修改内存,寄存器