Skip to content

Commit cf072c4

Browse files
Sn0rtSn0rt
Sn0rt
authored and
Sn0rt
committed
update: first commit and many things will be append.
0 parents  commit cf072c4

28 files changed

+558
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.aux
2+
*.out
3+
peda*

Makefile

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Index = "index"
2+
Tex = ".tex"
3+
Aux = ".aux"
4+
5+
all: compile clean
6+
7+
compile:
8+
xelatex $(Index)$(Tex)
9+
bibtex $(Index)$(Aux)
10+
xelatex $(Index)$(Tex)
11+
xelatex $(Index)$(Tex)
12+
13+
clean:
14+
$(RM) -rf *.log *.aux *.toc *.bbl *.bbg *.blg *.out */*.aux auto
15+
16+
.PHONY:clean_all
17+
clean_all:
18+
$(RM) -rf *.log *.aux *.toc *.bbl *.bbg *.blg *.out */*.aux auto

README.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# linux exploit development tutorial
2+
3+
## what's this ?
4+
5+
A series tutorial for linux exploit development to newbie.
6+
7+
## how to organize ?
8+
9+
### chapter 1: Basic knowledge
10+
11+
base knowledge like : what's stack and heap ? how convert c language to assembly language ? what's elf and memroy layout? etc..
12+
base vulnerability problems like : what's is overflow and memory corruption ? how heap working ? etc...
13+
14+
### chapter 2: Stack security
15+
16+
we focus userspace stack security mechanism and bypass.
17+
18+
### chapter 3: Heap security
19+
20+
we focus userspace heap(ptmalloc2 of glibc) security mechanism and bypass.
21+
22+
### chapter 4: Kernel security
23+
24+
we focus kernel security mechanism for self and userland.
25+
WIP...
26+
27+
### chapter 5: Vulnerability discovery
28+
29+
WIP...
30+
31+
## how to modify and update ?
32+
33+
```shell
34+
sudo dnf install texlive-\* -y
35+
git clone git@github.com:hardenedlinux/linux_exploit_development_tutorial.git
36+
cd linux_exploit_development_tutorial
37+
make # preview
38+
```
39+
40+
## how to hand on ?
41+
42+
some source code in `lab-code`.
43+
44+
WIP...
45+
46+
## copyleft
47+
48+
CC-BY-NC-SA 4.0 Unported

chapter1/chapter_preparation.tex

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
\chapter{预备}
2+
\par 在这个level 我将要花点时间给大家介绍基本的漏洞类型和安全机制,然后关闭全部的安全
3+
保护机制,学习如何在Linux下面编写最基本的exp.
4+
5+
\section{安全机制}
6+
\par 分为两大类:编译相关(elf加固),部分编译选项控制着生成更安全的代码(损失部分性能或
7+
者空间),还有就说运行时的安全,都是为增加了漏洞利用的难度,不能从本质上去除软件的
8+
漏洞.
9+
10+
\subsection{STACK CANARY}
11+
\par Canary 是放置在缓冲区和控制数据之间的一个words被用来检测缓冲区溢出, 如果发生缓
12+
冲区溢出那么第一个被修改的数据通常是canary,当其验证失败通常说明发生了栈溢出,更
13+
多信息参考这里
14+
\footnote{\url{https://en.wikipedia.org/wiki/Buffer_overflow_protection\#Canaries}}.
15+
\begin{lstlisting}[language=sh]
16+
gcc -fstack-protector
17+
\end{lstlisting}
18+
19+
\subsection{NX}
20+
\par 在早期,指令是数据,数据也是数据,当PC指向哪里,那里的数据就会被当成指令被cpu执行,
21+
后来NX标志位被引入来区分指令和数据.更
22+
多信息参考这里\cite{Intel}
23+
\footnote{<<Intel® 64 and IA-32 Architectures Software Developer’s Manual>> volumes 3 section 4.6}
24+
\footnote{\url{https://en.wikipedia.org/wiki/NX_bit}}.
25+
26+
\begin{lstlisting}[language=sh]
27+
gcc -z execstack
28+
\end{lstlisting}
29+
30+
31+
\subsection{FORTIFY}
32+
\par 在编译和运行时候保护glibc:
33+
\begin{list}{\textbullet}{%
34+
\setlength\topsep{0pt} \setlength\partopsep{0pt}
35+
\setlength\parsep{0pt} \setlength\itemsep{0pt}
36+
}
37+
\item expand unbounded calls to "sprintf", "strcpy" into their "n"
38+
length-limited cousins when the size of a destination buffer is known
39+
(protects against memory overflows).
40+
\item stop format string "\%n" attacks when the format string is in a writable \% memory segment.
41+
\item require checking various important function return codes and arguments (e.g.system, write, open).
42+
\item require explicit file mask when creating new files.
43+
\end{list}
44+
\begin{lstlisting}[language=sh]
45+
gcc -D_FORTIFY_SOURCE=2 -O
46+
\end{lstlisting}
47+
48+
\subsection{PIE}
49+
-fPIC:
50+
类似于-fpic不过克服了部分平台对偏移表尺寸的限制.
51+
生成可用于共享库的位置独立代码。所有的内部寻址均通过全局偏移表(GOT)完成.要确
52+
定一个地址,需要将代码自身的内存位置作为表中一项插入.该选项需要操作系统支持,因
53+
此并不是在所有系统上均有效.该选项产生可以在共享库中存放并从中加载的目标模块.
54+
参考链接
55+
\footnote{\url{https://en.wikipedia.org/wiki/Position-independent_code\#PIE}}.
56+
57+
-fPIE:
58+
这选项类似于-fpic与-fPIC,但生成的位置无关代码只可以链接为可执行文件,它通常的链
59+
接选项是-pie.
60+
\begin{lstlisting}[language=sh]
61+
gcc -pie -fPIE
62+
\end{lstlisting}
63+
64+
\subsection{RELRO}
65+
\par Hardens ELF programs against loader memory area overwrites by having the loader mark any areas of the relocation table as read-only for any symbols resolved at
66+
load-time ("read-only relocations"). This reduces the area of possible
67+
GOT-overwrite-style memory corruption attacks
68+
\footnote{\url{http://blog.isis.poly.edu/exploitation\%20mitigation\%20techniques/exploitation\%20techniques/2011/06/02/relro-relocation-read-only/}}.
69+
70+
\subsubsection{ASLR}
71+
\footnote{\url{https://en.wikipedia.org/wiki/Address_space_layout_randomization}}
72+
73+
\section{漏洞类型}
74+
\subsection{栈溢出}
75+
\subsection{整数溢出}
76+
\subsection{off-by-one(stack base)}
77+
\subsection{格式化字符串}
78+
\%h(短写)
79+
\%n\$d(直接参数访问)
80+
\%n(任意内存写)
81+
\%s(任意内存读)
82+
83+
\section{Exp开发}
84+
\subsection{rop}
85+
nop seld + shellcode + ret
86+
\subsection{.dtors(废弃)}
87+
88+
\begin{lstlisting}[language=C]
89+
static void cleanup() __attribute__((destructor))
90+
\end{lstlisting}
91+
\subsection{覆写GOT}

chapter2/chapter_stack.tex

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
\chapter{stack}
2+
\par 这个阶段可能要花点时间了,需要学习主流的bypass安全机制的部分手段(base
3+
stack).
4+
\par ret2any: 返回到任何可以执行的地方, 已知的地方
5+
\begin{list}{\textbullet}{%
6+
\setlength\topsep{0pt} \setlength\partopsep{0pt}
7+
\setlength\parsep{0pt} \setlength\itemsep{0pt}
8+
}
9+
\item stack
10+
\item data/heap
11+
\item text
12+
\item library (libc)
13+
\item code chunk (ROP)
14+
\end{list}
15+
16+
\section{CANARY}
17+
\subsection{overwriting TLS}
18+
19+
\section{NX}
20+
\subsection{return-to-libc}
21+
\footnote{\url{https://sploitfun.wordpress.com/2015/05/08/bypassing-nx-bit-using-return-to-libc/}}.\newline
22+
\subsection{chained return-to-libc}
23+
\footnote{\url{https://sploitfun.wordpress.com/2015/05/08/bypassing-nx-bit-using-chained-return-to-libc/}}.\newline
24+
25+
\section{ASLR}
26+
\subsection{return-to-plt}
27+
\footnote{\url{https://sploitfun.wordpress.com/2015/05/08/bypassing-aslr-part-i/}}.\newline
28+
\subsection{brute-force}
29+
\footnote{\url{https://sploitfun.wordpress.com/2015/05/08/bypassing-aslr-part-ii/}}.\newline
30+
\subsection{overwriting GOT}
31+
\footnote{\url{https://sploitfun.wordpress.com/2015/05/08/bypassing-aslr-part-iii/}}.\newline

chapter3/chapter_heap.tex

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
\chapter{heap}
2+
3+
这个阶段可能要花更多的时间了,堆上面的安全一直是个相对高级的话题(windows下也是如
4+
此),在这个阶段讲要学习堆区域的bug.
5+
6+
\section{overflow using unlink}
7+
\footnote{\url{https://sploitfun.wordpress.com/2015/02/26/heap-overflow-using-unlink/}}.
8+
9+
\section{overwrite using malloc}
10+
\footnote{\url{https://sploitfun.wordpress.com/2015/03/04/heap-overflow-using-malloc-maleficarum/}}.
11+
12+
\section{off by one}
13+
\footnote{\url{https://sploitfun.wordpress.com/2015/06/09/off-by-one-vulnerability-heap-based}}.
14+
15+
\section{UAF(use after free)}
16+
\footnote{\url{https://sploitfun.wordpress.com/2015/06/16/use-after-free/}}.

chapter4/chapter_kernel.tex

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
\chapter{内核}
2+
这个阶段归档了kernel安全相关的文档(安全保护,利用).
3+
\section{安全机制}
4+
早期kernel可以随意访问用户态代码,ret2usr技术可以让内核执行用户态的代码,不过随着
5+
Linux的发展SMAP(禁止kernel随意访问用户态,RFLAGE.AC标志位置位可以),SMEP禁止
6+
kernel态直接执行用户态代码.
7+
\subsection{SMAP}
8+
现代Linux默认启用.
9+
\subsection{SMEP/PXN}
10+
现代Linux默认启用.
11+
\subsection{kaslr}
12+
ubuntu 14.04 desktop默认还没有启用,更多信息参考Ubuntu security Features
13+
\footnote{\url{https://wiki.ubuntu.com/Security/Features\#Userspace_Hardening}}
14+
\section{利用方法}
15+
\subsection{rop-2-usr(废弃)}
16+
早期能工作
17+
\subsection{rop}
18+
19+
\subsection{vDSO overwriting}
20+
SEMP using vDSO overwrites(CSAW Fianl 2015 string IPC)

chapter5/chapter_vuln_detection.tex

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
\chapter{漏洞挖掘}
2+
漏洞挖掘的重要性不言而喻,打个比喻上面写的如何啃肉,漏洞挖掘就是肉在哪里.
3+
\section{fuzz}
4+
5+
\subsection{why fuzz?}
6+
- 容易实现
7+
– 覆盖面广
8+
– 低投入高产出
9+
10+
\subsection{why not fuzz?}
11+
– 分析困难(无法调试)
12+
– Panic多 / Exploitable少
13+
– 欠缺精度
14+
15+
\subsection{where to fuzz?}
16+
– ioctl
17+
– sysctl
18+
– File system
19+
– Network
20+
\subsection{how to fuzz?}
21+
22+
23+
24+
\section{代码审计}
25+
\subsection{source}
26+
\begin{list}{\textbullet}{%
27+
\setlength\topsep{0pt} \setlength\partopsep{0pt}
28+
\setlength\parsep{0pt} \setlength\itemsep{0pt}
29+
}
30+
\item - Heap Overflow
31+
\item - Integer Overflow
32+
\item - Type Confusion
33+
\item - Use after Free
34+
\item - Logical Error
35+
\item - Kernel Information Leak
36+
\end{list}

fonts-external.sty

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
2+
\ProvidesPackage{fonts_external}[2016/10/09 fonts external package]
3+
4+
\RequirePackage{fontspec}
5+
\RequirePackage{xeCJK}
6+
7+
\defaultfontfeatures{Path = fonts-external/, Mapping=tex-text}
8+
9+
\setCJKmainfont[
10+
BoldFont=msyhbd.ttc,
11+
ItalicFont=msyhl.ttc,
12+
SmallCapsFont=msyh.ttc
13+
]{msyh.ttc}
14+
\setCJKsansfont{msyh.ttc}
15+
\setCJKmonofont{consola.ttf}
16+
17+
\setCJKfamilyfont{zhsong}{simsun.ttc}
18+
\setCJKfamilyfont{zhhei}{simhei.ttf}
19+
\setCJKfamilyfont{zhfs}{simfang.ttf}
20+
\setCJKfamilyfont{zhkai}{simkai.ttf}
21+
22+
\newcommand*{\songti}{\CJKfamily{zhsong}} % 宋体
23+
\newcommand*{\heiti}{\CJKfamily{zhhei}} % 黑体
24+
\newcommand*{\kaishu}{\CJKfamily{zhkai}} % 楷书
25+
\newcommand*{\fangsong}{\CJKfamily{zhfs}} % 仿宋
26+
27+
\endinput

fonts-external/consola.ttf

434 KB
Binary file not shown.

fonts-external/msyh.ttc

22.5 MB
Binary file not shown.

fonts-external/msyhbd.ttc

15.5 MB
Binary file not shown.

fonts-external/msyhl.ttc

11.4 MB
Binary file not shown.

fonts-external/simfang.ttf

10.1 MB
Binary file not shown.

fonts-external/simhei.ttf

9.3 MB
Binary file not shown.

fonts-external/simkai.ttf

11.2 MB
Binary file not shown.

fonts-external/simsun.ttc

17.4 MB
Binary file not shown.

index.pdf

254 KB
Binary file not shown.

0 commit comments

Comments
 (0)