1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
% vim : tabstop 4
%%%%%%%%%%%%%%%%%%%%
% seguridad.tex - Transparencias de la sección de Seguridad del Curso de C
% Guillermo Ramos Gutiérrez <wille@acm.asoc.fi.upm.es>
%%%%%%%%%%%%%%%%%%%%%
\documentclass{beamer}
\mode<presentation>
{
\usetheme{ACM}
\setbeamercovered{transparent}
}
\usepackage[spanish]{babel}
\usepackage[utf8]{inputenc}
\usepackage{times}
\usepackage{color}
\title[Curso de C: Seguridad]
{Curso de C: Seguridad}
\author[Guillermo Ramos]
{
Guillermo Ramos \\
\texttt{wille@acm.asoc.fi.upm.es}
}
\institute[ACM FI - UPM]
{
ACM Facultad de Informática \\
Universidad Politécnica de Madrid
}
\date{24 de marzo de 2011}
\pgfdeclareimage[height=0.7cm]{acm-logo}{acm}
\logo{\pgfuseimage{acm-logo}}
\AtBeginSection[]
{
\begin{frame}<beamer>
\frametitle{Contenido}
\tableofcontents[currentsection]
\end{frame}
}
\begin{document}
\begin{frame}
\titlepage
\end{frame}
\begin{frame}{Contenido}
\tableofcontents
\end{frame}
\section{¿De qué va todo esto?}
\begin{frame}{}
\begin{center}
\textbf{\huge 01010000}
\end{center}
\end{frame}
\begin{frame}{}
\begin{center}
\textbf{\huge 01010001} \\
\vspace{1cm}
\uncover<1>{¿0x50?} \\
\uncover<2>{¿push eax?} \\
\uncover<3>{¿true?}
\end{center}
\end{frame}
\begin{frame}{}
\begin{center}
\textbf{\huge 01010000} \\
\vspace{1cm}
$\surd$ 0x50 \\
$\surd$ push eax \\
$\surd$ true
\end{center}
\end{frame}
\begin{frame}{}
\begin{center}
\includegraphics[width=3cm]{img/dudewtf.png}
\end{center}
\end{frame}
\begin{frame}{En resumen}
\begin{itemize}
\item Problema: \textbf{distinguir datos de código}
\item La información no tiene más significado que el que le da un proceso.
\item Esto se suele aprovechar para controlar los fallos de software y modificar el flujo de ejecución.
\end{itemize}
\end{frame}
\section{Memoria}
\subsection{Memoria Virtual}
\begin{frame}{Memoria Virtual}
\begin{center}
\includegraphics[width=6cm]{img/memoria_virtual.png}
\end{center}
\end{frame}
\subsection{Organización de memoria}
\begin{frame}{Organización de memoria}
\begin{center}
\includegraphics[width=6cm]{img/memory_org.png}
\end{center}
\end{frame}
\begin{frame}{Ejemplo}
\begin{center}
\begin{block}{ejemplounopuntocé.c}
char global; \\
float pi = 3.14; \\[3mm]
int main() \{ \\
\hspace{1cm}int local; \\
\hspace{1cm}char* buffer = (char*)malloc(20); \\
\hspace{1cm}return 0; \\
\}
\end{block}
\end{center}
\end{frame}
\begin{frame}{Ejemplo}
\begin{center}
\begin{block}{ejemplounopuntocé.c}
char global; \textcolor{red}{// bss} \\
float pi = 3.14; \textcolor{red}{// data} \\[3mm]
int main() \{ \textcolor{red}{// code} \\
\hspace{1cm}int local; \textcolor{red}{// stack} \\
\hspace{1cm}char* buffer = (char*)malloc(20); \textcolor{red}{// heap (*buffer)} \\
\hspace{1cm}return 0; \\
\}
\end{block}
\end{center}
\end{frame}
\subsection{La pila}
\begin{frame}{La pila}
Guarda el estado de las funciones en \textbf{marcos de pila} \\
Cada marco de pila almacena:
\begin{itemize}
\item Parámetros
\item Variables locales
\item Dirección de retorno de la función
\end{itemize}
\end{frame}
\begin{frame}{El marco de pila}
\begin{center}
\includegraphics[width=6cm]{img/stack_frame_struct.png}
\end{center}
\end{frame}
\begin{frame}{La pila}
\begin{center}
\includegraphics[width=6cm]{img/stack_call_struct.png}
\end{center}
\end{frame}
\begin{frame}{Ejemplos}
\begin{center}
\includegraphics[width=6cm]{img/showmethecode.png}
\end{center}
\end{frame}
\section{Buffer Overflows}
\begin{frame}{Introducción}
\begin{center}
\textit{At first I was like...} \\[3mm]
\includegraphics[width=8cm]{img/bof1.png}
\end{center}
\end{frame}
\begin{frame}{Introducción}
\begin{center}
\textit{... but then I was like...} \\[3mm]
\includegraphics[width=7cm]{img/nuclear_explosion.png}
\end{center}
\end{frame}
\begin{frame}{Introducción}
\begin{center}
Un buffer overflow ocurre cuando no se controla la cantidad de datos que se pueden
copiar en un buffer y se sigue escribiendo tras haberlo rellenado, provocando
la sobreescritura de la memoria adyacente a él. \\[3mm]
\includegraphics[width=6cm]{img/bof2.png}
\end{center}
\end{frame}
\begin{frame}{Introducción}
\begin{center}
\includegraphics[width=8cm]{img/stack_overflow_1.png}
\end{center}
\end{frame}
\begin{frame}{Introducción}
\begin{center}
\includegraphics[width=8cm]{img/stack_overflow_2.png}
\end{center}
\end{frame}
\begin{frame}{Introducción}
\begin{center}
\includegraphics[width=8cm]{img/stack_overflow.png}
\end{center}
\end{frame}
\begin{frame}{Ejemplos}
\begin{center}
\includegraphics[width=6cm]{img/showmethecode.png}
\end{center}
\end{frame}
\section{Format Strings}
\begin{frame}{Introducción}
\begin{center}
\begin{block}{ejemplodospuntocé.c}
int main(int argc, char** argv) \{ \\
\hspace{1cm}if (argc $>$ 1) \\
\hspace{2cm}printf(argv[1]); \\
\hspace{1cm}return 0; \\
\}
\end{block}
\begin{block}{ejemplotrespuntocé.c}
int main(int argc, char** argv) \{ \\
\hspace{1cm}if (argc $>$ 1) \\
\hspace{2cm}printf("\%s", argv[1]); \\
\hspace{1cm}return 0; \\
\}
\end{block}
\end{center}
\end{frame}
\begin{frame}{\%x\%x\%x\%x\%x\%x\%x\%x\%x\%x\%x\%x\%x\%x\%x\%x\%x}
\begin{center}
Un ataque de format strings es una inyección de caracteres que hace que printf() o cualquier
derivado interprete que debe insertar parámetros en la salida. Al no haberlos, usa memoria
de la pila.
\end{center}
\end{frame}
\begin{frame}{Ejemplos}
\begin{center}
\includegraphics[width=6cm]{img/showmethecode.png}
\end{center}
\end{frame}
\section{}
\begin{frame}{}
\begin{center}
¿Dudas, preguntas? \\
\includegraphics[width=5cm]{img/dudas.jpg}
\end{center}
\end{frame}
\begin{frame}{}
\textbf{Bibliografía recomendada:}
\begin{thebibliography}{99}
\bibitem{} \htmladdnormallink{Erickson, J. (2008). \textit{The Art of Exploitation, 2nd Edition}}{http://www.amazon.com/Hacking-Art-Exploitation-Jon-Erickson/dp/1593271441/}
\bibitem{} \htmladdnormallink{Anley, C., Heasman, J., Lindner, F., Richarte, G. (2007). \textit{The Shellcoder's
Handbook: Discovering and Exploiting Security Holes}}{http://www.amazon.com/Shellcoders-Handbook-Discovering-Exploiting-Security/dp/047008023X/}
\end{thebibliography}
\end{frame}
\begin{frame}{}
\begin{center}
\textbf{¡Gracias por venir!}
\end{center}
\end{frame}
\end{document}
|