This commit is contained in:
firmianay 2018-03-15 23:16:56 +08:00
parent 3b48cb5bb0
commit bce95a5b08
7 changed files with 94 additions and 19 deletions

View File

@ -85,7 +85,7 @@ GitHub 地址https://github.com/firmianay/CTF-All-In-One
* [4.9 给 ELF 文件打 patch](doc/4.9_patch_elf.md)
* [4.10 给 PE 文件打 patch](doc/4.10_patch_pe.md)
* [五、高级篇](doc/5_advanced.md)
* [5.1 Fuzz 测试](doc/5.1_fuzz.md)
* [5.1 模糊测试](doc/5.1_fuzzing.md)
* [5.1.1 AFL fuzzer](doc/5.1.1_afl_fuzzer.md)
* [5.1.2 libFuzzer](doc/5.1.2_libfuzzer.md)
* [5.2 Pin 动态二进制插桩](doc/5.2_pin.md)

View File

@ -76,12 +76,16 @@ $ cat /proc/sys/kernel/yama/ptrace_scope
- `break <address>` 在程序指令的地址处打断点。
- `break ... if <cond>` 设置条件断点,`...` 代表上述参数之一(或无参数),`cond` 为条件表达式,仅在 `cond` 值非零时停住程序。
#### info breakpoints -- i b
查看断点,观察点和捕获点的列表。用法:
- `info breakpoints [list…]`
- `info break [list…]`
`list…` 用来指定若干个断点的编号(可省略),可以是 `2` `1-3` `2 5` 等。
#### info
- `info breakpoints -- i b` 查看断点,观察点和捕获点的列表。
- `info breakpoints [list…]`
- `info break [list…]`
- `list…` 用来指定若干个断点的编号(可省略),可以是 `2` `1-3` `2 5` 等。
- `info display` 打印自动显示的表达式列表,每个表达式都带有项目编号,但不显示其值。
- `info reg` 显示当前寄存器信息。
- `info threads` 打印出所有线程的信息,包含 Thread ID、Target ID 和 Frame。
- `info frame` 打印出指定栈帧的详细信息。
- `info proc` 查看 proc 里的进程信息。
#### disable -- dis
禁用断点,参数使用空格分隔。不带参数时禁用所有断点。
@ -113,6 +117,8 @@ $ cat /proc/sys/kernel/yama/ptrace_scope
为表达式设置观察点。每当一个表达式的值改变时,观察点就会停止执行您的程序。
- `watch [-l|-location] <expr>` 如果给出了 `-l` 或者 `-location`,则它会对 `expr` 求值并观察它所指向的内存。
另外 `rwatch` 表示在访问时停止,`awatch` 表示在访问和改变时都停止。
#### step -- s
单步执行程序,直到到达不同的源码行。
- `step [N]` 参数 `N` 表示执行 N 次(或由于另一个原因直到程序停止)。
@ -175,8 +181,11 @@ $ cat /proc/sys/kernel/yama/ptrace_scope
`fmt` 用于指定显示格式。对于格式 `i``s`,或者包括单位大小或单位数量,将表达式 `addr` 添加为每次程序停止时要检查的内存地址。
#### info display
打印自动显示的表达式列表,每个表达式都带有项目编号,但不显示其值。
#### disassemble -- disas
反汇编命令。
- `disas <func>` 反汇编指定函数
- `disas <addr>` 反汇编某地址所在函数
- `disas <begin_addr> <end_addr>` 反汇编从开始地址到结束地址的部分
#### undisplay
取消某些表达式在程序停止时自动显示。参数是表达式的编号(使用 `info display` 查询编号)。不带参数表示取消所有自动显示表达式。
@ -227,12 +236,12 @@ run `python2 -c 'print "A"*100'`
但如果程序是使用 exec 来启动了一个新的程序,可以使用 `set follow-exec-mode new`(默认为`same` 来新建一个 inferior 给新程序,而父进程的 inferior 仍然保留。
#### info threads
打印出所有线程的信息,包含 Thread ID、Target ID 和 Frame。
#### thread apply all bt
打印出所有线程的堆栈信息。
#### generate-core-file
将调试中的进程生成内核转储文件。
## gdb-peda
当 gdb 启动时,它会在当前用户的主目录中寻找一个名为 `.gdbinit` 的文件;如果该文件存在,则 gdb 就执行该文件中的所有命令。通常,该文件用于简单的配置命令。但是 `.gdbinit` 的配置十分繁琐,因此对 gdb 的扩展通常用插件的方式来实现,通过 python 的脚本可以很方便的实现需要的功能。

View File

@ -1,6 +0,0 @@
# 5.1 Fuzz 测试
- [AFL](#afl)
## AFL

24
doc/5.1_fuzzing.md Normal file
View File

@ -0,0 +1,24 @@
# 5.1 模糊测试
- [简介](#简介)
- [参考资料](#参考资料)
## 简介
模糊测试fuzzing是一种通过向程序提供非预期的输入并监控输出中的异常来发现软件中的故障的方法。
用于模糊测试的模糊测试器fuzzer分为两类
- 一类是基于变异的模糊测试器,它通过对已有的数据样本进行变异来创建测试用例
- 另一类是基于生成的模糊测试器,它为被测试系统使用的协议或文件格式建模,基于模型生成输入并据此创建测试用例。
模糊测试通常包含下面几个基本阶段:
1. 确定测试目标
2. 确定输入向量
3. 生成模糊测试数据
4. 执行模糊测试数据
5. 监视异常
6. 判定发现的漏洞是否可被利用
## 参考资料
- [Fuzzing](https://en.wikipedia.org/wiki/Fuzzing)

View File

@ -2,14 +2,44 @@
- [简介](#简介)
- [初步使用](#初步使用)
- [内部实现](#内部实现)
- [参考资料](#参考资料)
## 简介
Clang 一个基于 LLVM 的编译器前端,支持 C/C++/Objective-C 等语言。其开发目标是替代 GCC。
在软件安全的应用中,已经有许多代码分析工具都基于 Clang 和 LLVM开发社区也都十分活跃。
## 初步使用
首先我们来编译安装 LLVM 和 Clang
```bash
$ svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
$ cd llvm/tools
$ svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
$ svn co http://llvm.org/svn/llvm-project/lld/trunk lld # optional
$ svn co http://llvm.org/svn/llvm-project/polly/trunk polly # optional
$ cd clang/tools
$ svn co http://llvm.org/svn/llvm-project/clang-tools-extra/trunk extra # optional
$ cd ../../../.. && cd llvm/projects
$ svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt # optional
$ svn co http://llvm.org/svn/llvm-project/openmp/trunk openmp # optional
$ svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx # optional
$ svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi # optional
$ svn co http://llvm.org/svn/llvm-project/test-suite/trunk test-suite # optional
$ cd ../.. && cd llvm
$
$ mkdir build && cd build
```
## 内部实现
Clang 前端的主要流程如下:
```
Driver -> Lex -> Parse -> Sema -> CodeGen (LLVM IR)
```
## 参考资料
- [llvm documentation](http://llvm.org/docs/index.html)

View File

@ -1,6 +1,6 @@
# 第五章 高级篇
- [5.1 Fuzz 测试](5.1_fuzz.md)
- [5.1 模糊测试](5.1_fuzzing.md)
- [5.1.1 AFL fuzzer](5.1.1_afl_fuzzer.md)
- [5.1.2 libFuzzer](5.1.2_libfuzzer.md)
- [5.2 Pin 动态二进制插桩](5.2_pin.md)

View File

@ -17,6 +17,7 @@
- [strace](#strace)
- [strip](#strip)
- [strings](#strings)
- [valgrind](#valgrind)
- [xxd](#xxd)
@ -159,6 +160,8 @@ $ foremost image.o
-S, --source Intermix source code with disassembly
-s, --full-contents Display the full contents of all sections requested
-R, --dynamic-reloc Display the dynamic relocation entries in the file
-l, --line-numbers Include line numbers and filenames in output
-M intel Display instruction in Intel ISA
```
#### 常见用法
@ -307,11 +310,13 @@ $ ssdeep -bm hash.txt modified.elf
#### 重要参数
```text
-i print instruction pointer at time of syscall
-o file send trace output to FILE instead of stderr
-c count time, calls, and errors for each syscall and report summary
-e expr a qualifying expression: option=[!]all or option=[!]val1[,val2]...
options: trace, abbrev, verbose, raw, signal, read, write, fault
-p pid trace process with process id PID, may be repeated
-f follow forks
```
@ -366,6 +371,19 @@ $ strings [executable] | grep -i upx
```
## valgrind
valgrind 能检测出内存的非法使用等。使用它无需在检测对象程序编译时指定特别的参数,也不需要链接其他的函数库。
#### 重要参数
```
--leak-check=no|summary|full search for memory leaks at exit? [summary]
--show-reachable=yes same as --show-leak-kinds=all
--trace-children=no|yes Valgrind-ise child processes (follow execve)? [no]
--vgdb=no|yes|full activate gdbserver? [yes]
full is slower but provides precise watchpoint/step
```
## xxd
**xxd** 的作用就是将一个文件以十六进制的形式显示出来。