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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
% ----------------------------
\subsubsection{Initialization}
\begin{frame}[fragile]
\frametitle{iptables config}
\begin{itemize}
\item Create and change to new directory ex\_ipt
\item Get root (su)
\item Print current iptables configuration (iptables)
\item Save current configuration (iptables-save)
\item Reset iptables configuration (iptables)
\end{itemize}
\pause
\begin{beamerboxesrounded}[shadow=true]{Solution:}
\begin{scriptsize}
\begin{verbatim}
mkdir ex_ipt
cd ex_ipt
su
iptables -L
iptables-save > start.conf
iptables -X
iptables -F
iptables -Z
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\end{frame}
% ----------------------------
\subsubsection{Policy}
\begin{frame}[fragile]
\frametitle{Default Policy}
\begin{itemize}
\item Drop all incoming, outgoing and forwarding traffic
\item Save this default policies to file
\item Reset iptables and restore saved config
\end{itemize}
\pause
\begin{beamerboxesrounded}[shadow=true]{Solution:}
\begin{scriptsize}
\begin{verbatim}
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
iptables-save > step1
iptables -F
iptables-restore < step1
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\end{frame}
% ----------------------------
\subsubsection{User-defined Chains}
\begin{frame}[fragile]
\frametitle{LOGDROP}
\begin{itemize}
\item From now on, edit stepX file and load with iptables-restore
\item Create new Chain LOGDROP
\item Log and drop INPUT and OUTPUT traffic with new chain
\item Check with ping
\end{itemize}
\pause
\begin{beamerboxesrounded}[shadow=true]{Solution:}
\begin{scriptsize}
\begin{verbatim}
# New chain
:LOGDROP - [0:0]
-A LOGDROP -m limit --limit 2/min -j LOG --log-prefix "LOGDROP: "
-A LOGDROP -j DROP
# Catch all falling through
-A INPUT -i eth0 -j LOGDROP
-A OUTPUT -o eth0 -j LOGDROP
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\end{frame}
% ----------------------------
\subsubsection{Traffic Filter}
\begin{frame}[fragile]
\frametitle{Allow loopback traffic}
\begin{itemize}
\item Allow INPUT and OUTPUT traffic on interface lo
\end{itemize}
\pause
\begin{beamerboxesrounded}[shadow=true]{Solution:}
\begin{scriptsize}
\begin{verbatim}
# loopback
-A INPUT -i lo -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\end{frame}
% ----------------------------
\begin{frame}[fragile]
\frametitle{DNS}
\begin{itemize}
\item Allow DNS requests from this machine (UDP, Port 53)
\item Allow DNS responses
\end{itemize}
\pause
\begin{beamerboxesrounded}[shadow=true]{Solution:}
\begin{scriptsize}
\begin{verbatim}
# DNS
-A OUTPUT -p udp --dport 53 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -p udp -m state --state ESTABLISHED -j ACCEPT
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\end{frame}
% ----------------------------
\begin{frame}[fragile]
\frametitle{ICMP}
\begin{itemize}
\item Allow simple ping requests (icmp-type 0 and 8)
\item Limit to 2 requests per second
\end{itemize}
\pause
\begin{beamerboxesrounded}[shadow=true]{Solution:}
\begin{scriptsize}
\begin{verbatim}
# PING limited accept
-A INPUT -p icmp --icmp-type 0 -m limit --limit 2/s -j ACCEPT
-A INPUT -p icmp --icmp-type 8 -m limit --limit 2/s -j ACCEPT
-A INPUT -p icmp -j DROP
# Limit outgoing PING as well
-A OUTPUT -p icmp --icmp-type 0 -m limit --limit 2/s -j ACCEPT
-A OUTPUT -p icmp --icmp-type 8 -m limit --limit 2/s -j ACCEPT
-A OUTPUT -p icmp -j DROP
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\end{frame}
% ----------------------------
\begin{frame}[fragile]
\frametitle{Established Connections}
\begin{itemize}
\item Allow INPUT and OUTPUT traffic for all ESTABLISHed connections
\item Remove obsolete rules (DNS)
\end{itemize}
\pause
\begin{beamerboxesrounded}[shadow=true]{Solution:}
\begin{scriptsize}
\begin{verbatim}
# Allow established connections in and out
-A INPUT -m state --state ESTABLISHED -j ACCEPT
-A OUTPUT -m state --state ESTABLISHED -j ACCEPT
[...]
# DNS
-A OUTPUT -p udp --dport 53 -m state --state NEW,ESTABLISHED -j ACCEPT
# -A INPUT -p udp -m state --state ESTABLISHED -j ACCEPT
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\end{frame}
% ----------------------------
\begin{frame}[fragile]
\frametitle{Log new connections}
\begin{itemize}
\item Create new Chain LOGNEW\_ACCEPT
\item New Connections should be logged with prefix ''New: ''
\item Traffic should be accepted
\end{itemize}
\pause
\begin{beamerboxesrounded}[shadow=true]{Solution:}
\begin{scriptsize}
\begin{verbatim}
# LOGNEW_ACCEPT Chain
:LOGNEW_ACCEPT - [0:0]
-A LOGNEW_ACCEPT -m state --state NEW -j LOG --log-prefix "New: "
-A LOGNEW_ACCEPT -j ACCEPT
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\end{frame}
% ----------------------------
\begin{frame}[fragile]
\frametitle{Log new DNS connections}
\begin{itemize}
\item Log new DNS connection with rule LOGNEW\_ACCEPT
\end{itemize}
\pause
\begin{beamerboxesrounded}[shadow=true]{Solution:}
\begin{scriptsize}
\begin{verbatim}
# DNS
-A OUTPUT -p udp --dport 53 --sport 1024:65535 -m state --state NEW,ESTABLISHED \
-j LOGNEW_ACCEPT
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\end{frame}
% ----------------------------
\subsubsection{Summary}
\begin{frame}[fragile]
\frametitle{Full example with Ping, DNS, and SSH}
\begin{scriptsize}
\begin{verbatim}
# Generated by iptables-save v1.4.14 on Sat Apr 6 19:47:41 2013
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT DROP [0:0]
# New chain
:LOGDROP - [0:0]
-A LOGDROP -m limit --limit 2/min -j LOG --log-prefix "LOGDROP: "
-A LOGDROP -j DROP
# DNS Chain
:LOGNEW_ACCEPT - [0:0]
-A LOGNEW_ACCEPT -m state --state NEW -j LOG --log-prefix "New: "
-A LOGNEW_ACCEPT -j ACCEPT
\end{verbatim}
\end{scriptsize}
\end{frame}
% ----------------------------
\begin{frame}[fragile]
\frametitle{Full example with Ping, DNS, and SSH}
\begin{scriptsize}
\begin{verbatim}
# loopback
-A INPUT -i lo -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
# PING limited accept
-A INPUT -p icmp --icmp-type 0 -m limit --limit 2/s -j ACCEPT
-A INPUT -p icmp --icmp-type 8 -m limit --limit 2/s -j ACCEPT
-A INPUT -p icmp -j LOGDROP
-A OUTPUT -p icmp --icmp-type 0 -m limit --limit 2/s -j ACCEPT
-A OUTPUT -p icmp --icmp-type 8 -m limit --limit 2/s -j ACCEPT
-A OUTPUT -p icmp -j LOGDROP
# Allow established connections in and out
-A INPUT -m state --state ESTABLISHED -j ACCEPT
-A OUTPUT -m state --state ESTABLISHED -j ACCEPT
\end{verbatim}
\end{scriptsize}
\end{frame}
% ----------------------------
\begin{frame}[fragile]
\frametitle{Full example with Ping, DNS, and SSH}
\begin{scriptsize}
\begin{verbatim}
# DNS
-A OUTPUT -p udp --dport 53 --sport 1024:65535 -m state --state NEW,ESTABLISHED \
-j LOGNEW_ACCEPT
# Outgoing SSH
-A OUTPUT -p tcp --dport ssh --sport 1024:65535 -m state --state NEW,ESTABLISHED \
-j LOGNEW_ACCEPT
# Incoming SSH
-A INPUT -p tcp --dport ssh -m state --state NEW,ESTABLISHED -j LOGNEW_ACCEPT
# Catch all falling through
-A INPUT -i eth0 -j LOGDROP
-A OUTPUT -o eth0 -j LOGDROP
COMMIT
# Completed on Sat Apr 6 19:47:41 2013
\end{verbatim}
\end{scriptsize}
\end{frame}
|