📊
CTF-All-In-One
  • 简介
  • 前言
  • 一、基础知识篇
    • 1.1 CTF 简介
    • 1.2 学习方法
    • 1.3 Linux 基础
    • 1.4 Web 安全基础
      • 1.4.1 HTML 基础
      • 1.4.2 HTTP 协议基础
      • 1.4.3 JavaScript 基础
      • 1.4.4 常见 Web 服务器基础
      • 1.4.5 OWASP Top Ten Project 漏洞基础
      • 1.4.6 PHP 源码审计基础
    • 1.5 逆向工程基础
      • 1.5.1 C/C++ 语言基础
      • 1.5.2 汇编基础
      • 1.5.3 Linux ELF
      • 1.5.4 Windows PE
      • 1.5.5 静态链接
      • 1.5.6 动态链接
      • 1.5.7 内存管理
      • 1.5.8 glibc malloc
      • 1.5.9 Linux 内核
      • 1.5.10 Windows 内核
      • 1.5.11 jemalloc
    • 1.6 密码学基础
      • 1.6.1 密码学导论
      • 1.6.2 流密码
      • 1.6.3 分组密码
      • 1.6.4 公钥密码
      • 1.6.5 消息认证和哈希函数
      • 1.6.6 数字签名
      • 1.6.7 密码协议
      • 1.6.8 密钥分配与管理
      • 1.6.9 数字货币
    • 1.7 Android 安全基础
      • 1.7.1 Android 环境搭建
      • 1.7.2 Dalvik 指令集
      • 1.7.3 ARM 汇编基础
      • 1.7.4 Android 常用工具
  • 二、工具篇
    • 虚拟化分析环境
      • 2.1.1 VirtualBox
      • 2.1.2 QEMU
      • 2.1.3 Docker
      • 2.1.4 Unicorn
    • 静态分析工具
      • 2.2.1 radare2
      • 2.2.2 IDA Pro
      • 2.2.3 JEB
      • 2.2.4 Capstone
      • 2.2.5 Keystone
      • 2.2.6 Ghidra
    • 动态分析工具
      • 2.3.1 GDB
      • 2.3.2 OllyDbg
      • 2.3.3 x64dbg
      • 2.3.4 WinDbg
      • 2.3.5 LLDB
    • 其他工具
      • 2.4.1 pwntools
      • 2.4.2 zio
      • 2.4.3 metasploit
      • 2.4.4 binwalk
      • 2.4.5 Burp Suite
      • 2.4.6 Wireshark
      • 2.4.7 Cuckoo Sandbox
  • 三、分类专题篇
    • Pwn
      • 3.1.1 格式化字符串漏洞
      • 3.1.2 整数溢出
      • 3.1.3 栈溢出
      • 3.1.4 返回导向编程(ROP)(x86)
      • 3.1.5 返回导向编程(ROP)(ARM)
      • 3.1.6 Linux 堆利用(一)
      • 3.1.7 Linux 堆利用(二)
      • 3.1.8 Linux 堆利用(三)
      • 3.1.9 Linux 堆利用(四)
      • 3.1.10 内核 ROP
      • 3.1.11 Linux 内核漏洞利用
      • 3.1.12 Windows 内核漏洞利用
      • 3.1.13 竞争条件
      • 3.1.14 虚拟机逃逸
    • Reverse
      • 3.2.1 patch 二进制文件
      • 3.2.2 脱壳技术(PE)
      • 3.2.3 脱壳技术(ELF)
      • 3.2.4 反调试技术(PE)
      • 3.2.5 反调试技术(ELF)
      • 3.2.6 指令混淆
    • Web
      • 3.3.1 SQL 注入利用
      • 3.3.2 XSS 漏洞利用
    • Crypto
    • Misc
      • 3.5.1 Lsb
    • Mobile
  • 四、技巧篇
    • 4.1 Linux 内核调试
    • 4.2 Linux 命令行技巧
    • 4.3 GCC 编译参数解析
    • 4.4 GCC 堆栈保护技术
    • 4.5 ROP 防御技术
    • 4.6 one-gadget RCE
    • 4.7 通用 gadget
    • 4.8 使用 DynELF 泄露函数地址
    • 4.9 shellcode 开发
    • 4.10 跳转导向编程(JOP)
    • 4.11 利用 mprotect 修改栈权限
    • 4.12 利用 __stack_chk_fail
    • 4.13 利用 _IO_FILE 结构
    • 4.14 glibc tcache 机制
    • 4.15 利用 vsyscall 和 vDSO
  • 五、高级篇
    • 5.0 软件漏洞分析
    • 5.1 模糊测试
      • 5.1.1 AFL fuzzer
      • 5.1.2 libFuzzer
    • 5.2 动态二进制插桩
      • 5.2.1 Pin
      • 5.2.2 DynamoRio
      • 5.2.3 Valgrind
    • 5.3 符号执行
      • 5.3.1 angr
      • 5.3.2 Triton
      • 5.3.3 KLEE
      • 5.3.4 S²E
    • 5.4 数据流分析
      • 5.4.1 Soot
    • 5.5 污点分析
      • 5.5.1 TaintCheck
    • 5.6 LLVM
      • 5.6.1 Clang
    • 5.7 程序切片
    • 5.8 SAT/SMT
      • 5.8.1 Z3
    • 5.9 基于模式的漏洞分析
    • 5.10 基于二进制比对的漏洞分析
    • 5.11 反编译技术
      • 5.11.1 RetDec
  • 六、题解篇
    • Pwn
      • 6.1.1 pwn HCTF2016 brop
      • 6.1.2 pwn NJCTF2017 pingme
      • 6.1.3 pwn XDCTF2015 pwn200
      • 6.1.4 pwn BackdoorCTF2017 Fun-Signals
      • 6.1.5 pwn GreHackCTF2017 beerfighter
      • 6.1.6 pwn DefconCTF2015 fuckup
      • 6.1.7 pwn 0CTF2015 freenote
      • 6.1.8 pwn DCTF2017 Flex
      • 6.1.9 pwn RHme3 Exploitation
      • 6.1.10 pwn 0CTF2017 BabyHeap2017
      • 6.1.11 pwn 9447CTF2015 Search-Engine
      • 6.1.12 pwn N1CTF2018 vote
      • 6.1.13 pwn 34C3CTF2017 readme_revenge
      • 6.1.14 pwn 32C3CTF2015 readme
      • 6.1.15 pwn 34C3CTF2017 SimpleGC
      • 6.1.16 pwn HITBCTF2017 1000levels
      • 6.1.17 pwn SECCONCTF2016 jmper
      • 6.1.18 pwn HITBCTF2017 Sentosa
      • 6.1.19 pwn HITBCTF2018 gundam
      • 6.1.20 pwn 33C3CTF2016 babyfengshui
      • 6.1.21 pwn HITCONCTF2016 Secret_Holder
      • 6.1.22 pwn HITCONCTF2016 Sleepy_Holder
      • 6.1.23 pwn BCTF2016 bcloud
      • 6.1.24 pwn HITCONCTF2016 House_of_Orange
      • 6.1.25 pwn HCTF2017 babyprintf
      • 6.1.26 pwn 34C3CTF2017 300
      • 6.1.27 pwn SECCONCTF2016 tinypad
      • 6.1.28 pwn ASISCTF2016 b00ks
      • 6.1.29 pwn Insomni'hack_teaserCTF2017 The_Great_Escape_part-3
      • 6.1.30 pwn HITCONCTF2017 Ghost_in_the_heap
      • 6.1.31 pwn HITBCTF2018 mutepig
      • 6.1.32 pwn SECCONCTF2017 vm_no_fun
      • 6.1.33 pwn 34C3CTF2017 LFA
      • 6.1.34 pwn N1CTF2018 memsafety
      • 6.1.35 pwn 0CTF2018 heapstorm2
      • 6.1.36 pwn NJCTF2017 messager
      • 6.1.37 pwn sixstarctf2018 babystack
      • 6.1.38 pwn HITCONCMT2017 pwn200
      • 6.1.39 pwn BCTF2018 house_of_Atum
      • 6.1.40 pwn LCTF2016 pwn200
      • 6.1.41 pwn PlaidCTF2015 PlaidDB
      • 6.1.42 pwn hacklu2015 bookstore
      • 6.1.43 pwn 0CTF2018 babyheap
      • 6.1.44 pwn ASIS2017 start_hard
      • 6.1.45 pwn LCTF2016 pwn100
    • Reverse
      • 6.2.1 re XHPCTF2017 dont_panic
      • 6.2.2 re ECTF2016 tayy
      • 6.2.3 re CodegateCTF2017 angrybird
      • 6.2.4 re CSAWCTF2015 wyvern
      • 6.2.5 re PicoCTF2014 Baleful
      • 6.2.6 re SECCONCTF2017 printf_machine
      • 6.2.7 re CodegateCTF2018 RedVelvet
      • 6.2.8 re DefcampCTF2015 entry_language
    • Web
      • 6.3.1 web HCTF2017 babycrack
    • Crypto
    • Misc
    • Mobile
  • 七、实战篇
    • CVE
      • 7.1.1 CVE-2017-11543 tcpdump sliplink_print 栈溢出漏洞
      • 7.1.2 CVE-2015-0235 glibc __nss_hostname_digits_dots 堆溢出漏洞
      • 7.1.3 CVE-2016-4971 wget 任意文件上传漏洞
      • 7.1.4 CVE-2017-13089 wget skip_short_body 栈溢出漏洞
      • 7.1.5 CVE–2018-1000001 glibc realpath 缓冲区下溢漏洞
      • 7.1.6 CVE-2017-9430 DNSTracer 栈溢出漏洞
      • 7.1.7 CVE-2018-6323 GNU binutils elf_object_p 整型溢出漏洞
      • 7.1.8 CVE-2010-2883 Adobe CoolType SING 表栈溢出漏洞
      • 7.1.9 CVE-2010-3333 Microsoft Word RTF pFragments 栈溢出漏洞
    • Malware
  • 八、学术篇
    • 8.1 The Geometry of Innocent Flesh on the Bone: Return-into-libc without Function Calls (on the x86)
    • 8.2 Return-Oriented Programming without Returns
    • 8.3 Return-Oriented Rootkits: Bypassing Kernel Code Integrity Protection Mechanisms
    • 8.4 ROPdefender: A Detection Tool to Defend Against Return-Oriented Programming Attacks
    • 8.5 Data-Oriented Programming: On the Expressiveness of Non-Control Data Attacks
    • 8.7 What Cannot Be Read, Cannot Be Leveraged? Revisiting Assumptions of JIT-ROP Defenses
    • 8.9 Symbolic Execution for Software Testing: Three Decades Later
    • 8.10 AEG: Automatic Exploit Generation
    • 8.11 Address Space Layout Permutation (ASLP): Towards Fine-Grained Randomization of Commodity Softwa
    • 8.13 New Frontiers of Reverse Engineering
    • 8.14 Who Allocated My Memory? Detecting Custom Memory Allocators in C Binaries
    • 8.21 Micro-Virtualization Memory Tracing to Detect and Prevent Spraying Attacks
    • 8.22 Practical Memory Checking With Dr. Memory
    • 8.23 Evaluating the Effectiveness of Current Anti-ROP Defenses
    • 8.24 How to Make ASLR Win the Clone Wars: Runtime Re-Randomization
    • 8.25 (State of) The Art of War: Offensive Techniques in Binary Analysis
    • 8.26 Driller: Augmenting Fuzzing Through Selective Symbolic Execution
    • 8.27 Firmalice - Automatic Detection of Authentication Bypass Vulnerabilities in Binary Firmware
    • 8.28 Cross-Architecture Bug Search in Binary Executables
    • 8.29 Dynamic Hooks: Hiding Control Flow Changes within Non-Control Data
    • 8.30 Preventing brute force attacks against stack canary protection on networking servers
    • 8.33 Under-Constrained Symbolic Execution: Correctness Checking for Real Code
    • 8.34 Enhancing Symbolic Execution with Veritesting
    • 8.38 TaintEraser: Protecting Sensitive Data Leaks Using Application-Level Taint Tracking
    • 8.39 DART: Directed Automated Random Testing
    • 8.40 EXE: Automatically Generating Inputs of Death
    • 8.41 IntPatch: Automatically Fix Integer-Overflow-to-Buffer-Overflow Vulnerability at Compile-Time
    • 8.42 Dynamic Taint Analysis for Automatic Detection, Analysis, and Signature Generation of Exploits
    • 8.43 DTA++: Dynamic Taint Analysis with Targeted Control-Flow Propagation
    • 8.44 Superset Disassembly: Statically Rewriting x86 Binaries Without Heuristics
    • 8.45 Ramblr: Making Reassembly Great Again
    • 8.46 FreeGuard: A Faster Secure Heap Allocator
    • 8.48 Reassembleable Disassembling
  • 九、附录
    • 9.1 更多 Linux 工具
    • 9.2 更多 Windows 工具
    • 9.3 更多资源
    • 9.4 Linux 系统调用表
    • 9.5 python2到3字符串转换
    • 9.6 幻灯片
Powered by GitBook
On this page
  • dd
  • 重要参数
  • 常见用法
  • dmesg
  • file
  • 技巧
  • edb
  • 安装
  • foremost
  • ldd
  • ltrace
  • md5sum
  • nm
  • objcopy
  • objdump
  • od
  • readelf
  • socat
  • ssdeep
  • strace
  • strip
  • strings
  • valgrind
  • xxd

Was this helpful?

  1. 九、附录

9.1 更多 Linux 工具

Previous九、附录Next9.2 更多 Windows 工具

Last updated 3 years ago

Was this helpful?

dd

dd 命令用于复制文件并对原文件的内容进行转换和格式化处理。

重要参数

if=FILE         read from FILE instead of stdin
of=FILE         write to FILE instead of stdout
skip=N          skip N ibs-sized blocks at start of input
bs=BYTES        read and write up to BYTES bytes at a time

patch 偏移 12345 处的一个字节:

echo 'X' | dd of=binary.file bs=1 seek=12345 count=1

常见用法

$ dd if=[file1] of=[file2] skip=[size] bs=[bytes]

dump 运行时的内存镜像:

  • cat /proc/<pid>/maps

  • 找到内存中 text 段和 data 段

  • dd if=/proc/<pid>/mem of=/path/a.out skip=xxxx bs= 1 count=xxxx

dmesg

dmesg 命令用于显示 Linux 内核环形缓冲区(ring buffer)的信息。开机信息和各种错误信息都会放到里面。在调试和故障诊断中非常有用。

-c, --read-clear
      Clear the ring buffer after first printing its contents.
-s, --buffer-size size
      Use a buffer of size to query the kernel ring buffer.  This is 16392  by  default.
-n, --console-level level
      Set the level at which printing of messages is done to the console.

file

file 命令用来探测给定文件的类型。

技巧

$ file -L [file]

当文件是链接文件时,直接显示符号链接所指向的文件类别。

edb

edb 是一个同时支持x86、x86-64的调试器。它主要向 OllyDbg 工具看齐,并可通过插件体系进行功能的扩充。

安装

$ yaourt -S edb

foremost

foremost 是一个基于文件文件头和尾部信息以及文件的内建数据结构恢复文件的命令行工具。

$ yaourt -S foremost

ldd

ldd 命令用于打印程序或者库文件所依赖的共享库列表。

ldd 实际上仅是 shell 脚本,重点是环境变量 LD_TRACE_LOADED_OBJECTS,在执行文件时把它设为 1,则与执行 ldd 效果一样。

$ ldd [executable]

$ LD_TRACE_LOADED_OBJECTS=1 [executable]

ltrace

ltrace 命令用于跟踪进程调用库函数的情况。

-f                  trace children (fork() and clone()).
-p PID              attach to the process with the process ID pid.
-S                  trace system calls as well as library calls.

md5sum

md5sum 命令采用MD5报文摘要算法(128位)计算和检查文件的校验和。

-b, --binary         read in binary mode
-c, --check          read MD5 sums from the FILEs and check them

nm

nm 命令被用于显示二进制目标文件的符号表。

-a, --debug-syms       Display debugger-only symbols
-D, --dynamic          Display dynamic symbols instead of normal symbols
-g, --extern-only      Display only external symbols

objcopy

如果我们要将一个二进制文件,比如图片、MP3音乐等东西作为目标文件中的一个段,可以使用 objcopy 工具,比如我们有一个图片文件 “image.jpg”:

$ objcopy -I binary -O elf32-i386 -B i386 image.jpg image.o

$ objdump -ht image.o

image.o:     file format elf32-i386

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .data         0000642f  00000000  00000000  00000034  2**0
                  CONTENTS, ALLOC, LOAD, DATA
SYMBOL TABLE:
00000000 l    d  .data	00000000 .data
00000000 g       .data	00000000 _binary_image_jpg_start
0000642f g       .data	00000000 _binary_image_jpg_end
0000642f g       *ABS*	00000000 _binary_image_jpg_size

三个变量的使用方法如下:

const char *start = _binary_image_jpg_start;    // 数据的起始地址
const char *end = _binary_image_jpg_end;        // 数据的末尾地址+1
int size = (int)_binary_image_jpg_size;         // 数据大小

这一技巧可能出现在 CTF 隐写题中,使用 foremost 工具可以将图片提取出来:

$ foremost image.o

objdump

objdump 命令是用查看目标文件或者可执行的目标文件的构成的gcc工具。

-d, --disassemble        Display assembler contents of executable sections
-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

对特定段进行转储:

$ objdump -s -j [section] [binary]

对地址进行指定和转储:

$ objdump -s --start-address=[address] --stop-address=[address] [binary]

当包含调试信息时,还可以使用 -l 和 -S 来分别对应行号和源码。

结合使用 objdump 和 grep。

$ objdump -d [executable] | grep -A 30 [function_name]

查找 GOT 表地址:

$ objdump -R [binary] | grep [function_name]

从可执行文件中提取 shellcode (注意,在objdump中可能会删除空字节):

$ for i in `objdump -d print_flag | tr '\t' ' ' | tr ' ' '\n' | egrep '^[0-9a-f]{2}$' ` ; do echo -n "\x$i" ; done

od

od 命令用于输出文件的八进制、十六进制或其它格式编码的字节,通常用于显示或查看文件中不能直接显示在终端的字符。

  -A, --address-radix=RADIX   output format for file offsets; RADIX is one
                                of [doxn], for Decimal, Octal, Hex or None
  -t, --format=TYPE           select output format or formats
  -v, --output-duplicates     do not use * to mark line suppression

另外加上 z 可以显示 ASCII 码。

用十六进制转存每个字节:

$ od -t x1z -A x [file]

转存字符串:

$ od -A x -s [file]

$ od -A n -s [file]

readelf

readelf 命令用来显示一个或者多个 elf 格式的目标文件的信息,可以通过它的选项来控制显示哪些信息。

-h --file-header       Display the ELF file header
-e --headers           Equivalent to: -h -l -S
-l --program-headers   Display the program headers
-S --section-headers   Display the sections' header
-s --syms              Display the symbol table
-r --relocs            Display the relocations (if present)
-d --dynamic           Display the dynamic section (if present)

另外 -w 选项表示 DWARF2 调试信息。

查找库中函数的偏移量,常用于 ret2lib:

$ readelf -s [path/to/library.so] | grep [function_name]@

例如:

$ readelf -s /usr/lib/libc-2.26.so | grep system@
   595: 0000000000041fa0    45 FUNC    GLOBAL DEFAULT   12 __libc_system@@GLIBC_PRIVATE
  1378: 0000000000041fa0    45 FUNC    WEAK   DEFAULT   12 system@@GLIBC_2.2.5

socat

socat 是 netcat 的加强版,CTF 中经常需要使用使用它连接服务器。

$ yaourt -S socat
$ socat [options] <address> <address>

连接远程端口

$ socat - TCP:localhost:80

监听端口

$ socat TCP-LISTEN:700 -

正向 shell

$ socat TCP-LISTEN:700 EXEC:/bin/bash

反弹 shell

$ socat tcp-connect:localhost:700 exec:'bash -li',pty,stderr,setsid,sigint,sane

将本地 80 端口转发到远程的 80 端口

$ socat TCP-LISTEN:80,fork TCP:www.domain.org:80

fork 服务器

$ socat tcp-l:9999,fork exec:./pwn1

跟踪 malloc 和 free 调用及相应的地址:

$ socat tcp-listen:1337,fork,reuseaddr system:"ltrace -f -e malloc+free-@libc.so*  ./pwn"

ssdeep

模糊哈希算法又叫基于内容分割的分片分片哈希算法(context triggered piecewise hashing, CTPH),主要用于文件的相似性比较。

-m - Match FILES against known hashes in file
-b - Uses only the bare name of files; all path information omitted
$ ssdeep -b orginal.elf > hash.txt
$ ssdeep -bm hash.txt modified.elf

strace

strace 命令对应用的系统调用和信号传递的跟踪结果进行分析,以达到解决问题或者是了解应用工作过程的目的。

-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

strip

strip 命令用于删除可执行文件中的符号和段。

-g -S -d --strip-debug           Remove all debugging symbols & sections
-R --remove-section=<name>       Also remove section <name> from the output

使用 -d 后,可以删除不使用的信息,并保留函数名等。用 gdb 进行调试时,只要保留了函数名,都可以进行调试。另外如果对 .o 和 .a 文件进行 strip 后,就不能和其他目标文件进行链接了。

strings

strings 命令在对象文件或二进制文件中查找可打印的字符串。字符串是4个或更多可打印字符的任意序列,以换行符或空字符结束。strings 命令对识别随机对象文件很有用。

-a --all                  Scan the entire file, not just the data section [default]
-t --radix={o,d,x}        Print the location of the string in base 8, 10 or 16
-e --encoding={s,S,b,l,B,L} Select character size and endianess:
                            s = 7-bit, S = 8-bit, {b,l} = 16-bit, {B,L} = 32-bit

-e 的作用,例如在这样一个二进制文件中:

$ rabin2 -z a.out
vaddr=0x080485d0 paddr=0x000005d0 ordinal=000 sz=17 len=16 section=.rodata type=ascii string=Enter password:
vaddr=0x080485e5 paddr=0x000005e5 ordinal=001 sz=10 len=9 section=.rodata type=ascii string=Congrats!
vaddr=0x080485ef paddr=0x000005ef ordinal=002 sz=7 len=6 section=.rodata type=ascii string=Wrong!
vaddr=0x0804a040 paddr=0x00001040 ordinal=000 sz=36 len=8 section=.data type=utf32le string=w0wgreat

字符串 w0wgreat 类型为 utf32le,而不是传统的 ascii,这时 strings 就需要指定 -e L 参数:

$ strings a.out | grep w0wgreat
$ strings -e L a.out | grep w0wgreat
w0wgreat

组合使用 strings 和 grep。

在 ret2lib 攻击中,得到字符串的偏移:

$ strings -t x /lib32/libc-2.24.so | grep /bin/sh

检查是否使用了 UPX 加壳

$ 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 的作用就是将一个文件以十六进制的形式显示出来。

-g          number of octets per group in normal output. Default 2 (-e: 4).
-i          output in C include file style.
-l len      stop after <len> octets.
-r          reverse operation: convert (or patch) hexdump into binary.
-u          use upper case hex letters.
$ xxd -g1 [binary]
dd
dmesg
file
edb
foremost
ldd
ltrace
md5sum
nm
objcopy
objdump
od
readelf
socat
ssdeep
strace
strip
strings
valgrind
xxd