forked from berke1337/hacksheet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hacksheet.tex
343 lines (278 loc) · 9.59 KB
/
hacksheet.tex
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
% This work is licensed under the following license:
%
% Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported
%
% Please see the file COPYING for more information.
\documentclass[10pt,landscape]{article}
\usepackage{alltt}
\usepackage{cprotect}
\usepackage{enumitem}
\usepackage[T1]{fontenc}
\usepackage[landscape,margin=13mm,footskip=1pt,includefoot]{geometry}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage[utf8]{inputenc}
\usepackage{multicol}
\usepackage{setspace}
\usepackage{titlesec}
\usepackage{upquote}
\usepackage{xspace}
\graphicspath{{figs/}}
\pagestyle{empty}
\parindent=0pt
\hypersetup{
colorlinks=true, % false: boxed links; true: colored links
linkcolor=red, % color of internal links
citecolor=cyan, % color of links to bibliography
filecolor=magenta, % color of file links
urlcolor=blue % color of external links
}
\setitemize{itemsep=1pt,topsep=0pt,parsep=1pt,leftmargin=10pt}
%\titleformat{\subsection}{\sc}{}{}{}
\titlespacing{\subsection}{0pt}{*0}{*1}
\newcommand{\todo}[1]{\textit{\textcolor{red}{TODO: #1}}}
\newcommand{\minisec}[1]{\textsc{#1}\\}
\newcommand{\first}{\emph{(i)}~}
\newcommand{\second}{\emph{(ii)}~}
\newcommand{\third}{\emph{(iii)}~}
\newcommand{\fourth}{\emph{(iv)}~}
\newcommand{\fifth}{\emph{(v)}~}
\newcommand{\os}[1]{\texttt{\footnotesize{#1}}}
\newcommand{\freebsd}{\os{F}}
\newcommand{\bsd}{\os{B}}
\newcommand{\unix}{\os{U}}
\newcommand{\linux}{\os{L}}
\newcommand{\macos}{\os{M}}
\newcommand{\windows}{\os{W}}
\newcommand{\xp}{\os{xp}}
\newcommand{\kk}{\os{2k}}
\newcommand{\kkt}{\os{2k3}}
\newcommand{\kke}{\os{2k8}}
\newcommand{\seven}{\os{7}}
\newenvironment{action}[1]
{\begin{minipage}[c]{\linewidth}$\star$~#1\begin{itemize}[leftmargin=1cm]}
{\end{itemize}\end{minipage}\vspace*{3pt}}
\newcommand{\cmd}[2]{\item[#1] {\small\tt\# #2}}
\newcommand{\comment}[1]{\textrm{\small(#1)}}
\newcommand{\bulletpoint}[1]{\item {\small #1}}
\newcommand{\tool}[2]{\item[#1] {\footnotesize\sc{#2}}\xspace}
\newcommand{\button}[1]{\footnotesize\sf#1}
\newcommand{\click}{$\rightarrow$\xspace}
\begin{document}
\begin{multicols*}{3}
{\Huge\scshape
HackSheet\hspace{-2pt}\raisebox{15pt}{\tiny{master}}\hspace{-4pt}
}
%\hfill\includegraphics[width=.4\linewidth]{bro-logo-small}
%\vspace{-38pt}
{\scriptsize
\setstretch{1.5}
\begin{tabular}{l l}
%Version: & \today\\
Author: & \href{http://matthias.vallentin.net}{Matthias Vallentin}\\
Web: & \url{https://github.com/mavam/hacksheet}\\
License: & \href{http://creativecommons.org/licenses/by-nc-sa/3.0/}
{Attribution-NonCommercial-ShareAlike 3.0 Unported}
\end{tabular}
}
%\hfill
%\href{http://creativecommons.org/licenses/by-nc-sa/3.0/}
%{\includegraphics[width=.2\linewidth]{by-nc-sa}}
%\vspace{-10pt}
\vspace{-10pt}
\section*{Terminology}
Each command contains a list of flags that indicate the OS requirement: Linux
(\linux), BSD (\bsd), FreeBSD (\freebsd), Mac OS (\macos), UNIX (\unix), and
Windows (\windows).
\section*{Reconnaissance}
\subsection*{Scanning}
\begin{action}{Ping sweep of subnet and host range}
\cmd{\unix}{nmap -sP 10.0.0.0/24 192.168.0.128-254}
\end{action}
\begin{action}{Scan specific TCP and UDP ports}
\cmd{\unix}{nmap -pT:21-25,80,U:5000-6000 target}
\end{action}
\begin{action}{TCP SYN scan without connecting}
\cmd{\unix}{nmap -P0 -sS target}
\end{action}
\begin{action}{Detect OS}
\cmd{\unix}{nmap -O target}
\cmd{\unix}{p0f -s trace.pcap}
\end{action}
\begin{action}{Grab application banners}
\cmd{\unix}{nmap -sV target}
\cmd{\unix}{echo QUIT | nc target 1-1024}
\end{action}
\subsection*{Wireless}
\section*{Vulnerability Scanning}
\subsection*{Web}
\begin{action}{Look for web server vulnerabilities}
\cmd{\unix}{nikto -host 10.0.0.1}
\end{action}
\section*{Hardening}
\subsection*{Physical}
\begin{action}{Check devices}
\bulletpoint{Hardware keylogger (e.g., USB dongles)}
\bulletpoint{Rogue WiFi cards}
\end{action}
\subsection*{OS \& Software}
\begin{action}{Check for package repositories}
\cmd{\linux}{vi /etc/apt/sources.list} \comment{Ubuntu}
\cmd{\linux}{vi /etc/yum.repos.d/*} \comment{RHEL/Fedora}
\end{action}
\begin{action}{Run package updates}
\cmd{\linux}{yum upgrade \emph{package}}
\cmd{\linux}{apt-get upgrade \emph{package}}
\end{action}
\begin{action}{Update Kernel}
\cmd{\linux}{yum update kernel} \comment{RHEL/Fedora}
\cmd{\linux}{apt-cache search linux-image; apt-get install
linux-image-\emph{x.x.x-xx}} \comment{Debian}
\end{action}
\begin{action}{Harden SSHD}
\tool{\unix}{fail2ban}
\cmd{\unix}{vi /etc/ssh/sshd\_config\\
Protocol 2\\
AllowUsers root admin webmaster\\
AllowGroup sshusers\\
PasswordAuthentication no\\
HostbasedAuthentication no\\
RSAAuthentication yes\\
PubkeyAuthentication yes\\
PermitEmptyPasswords no\\
PermitRootLogin no\\
ServerKeyBits 2048\\
IgnoreRhosts yes\\
RhostsAuthentication no\\
RhostsRSAAuthentication no}
\end{action}
\subsection*{User Management}
\begin{action}{Show account security settings}
\cmd{\unix}{passwd -l \emph{user}}
\cmd{\linux}{chage -l \emph{user}}
\cmd{\windows}{net accounts}
\cmd{\windows}{net accounts /domain}
\end{action}
\begin{action}{Look for users with root privileges}
\cmd{\unix}{awk -F: '\$3 == 0 \{print \$1\}' /etc/passwd}
\end{action}
\begin{action}{Look for users with empty passwords}
\cmd{\unix}{awk -F: '\$2 == "" \{print \$1\}' /etc/shadow}
\end{action}
\begin{action}{Verify group memberships}
\cmd{\unix}{vi /etc/group} \comment{admin, sudo, wheel}
\end{action}
\begin{action}{Check \texttt{sudo} users}
\cmd{\unix}{visudo}
\end{action}
\begin{action}{Check crontab users}
\cmd{\unix}{for u in \$(cut -f1 -d: /etc/passwd); do crontab -u \$u -l; done}
\end{action}
\begin{action}{Check remote authentication}
\cmd{\unix}{vi \textasciitilde/.rhosts}
\cmd{\unix}{vi \textasciitilde/.ssh/*}
\end{action}
\begin{action}{Change passwords}
\cmd{\unix}{pwgen -sy} \comment{generate strong passwords}
\cmd{\unix}{passwd \emph{user}}
\end{action}
\subsection*{File System}
\begin{action}{Secure mount points}
\cmd{\unix}{mount -o nodev,noexec,nosuid /dev.. /tmp}
\end{action}
\begin{action}{List file attributes}
\cmd{\linux}{lsattr /var/log/foo}
\cmd{\bsd}{ls -ol /var/log/foo}
\end{action}
\begin{action}{Make files append-only}
\cmd{\linux}{chattr +a /var/log/foo}
\end{action}
\subsection*{Network}
\begin{action}{Show firewall rules}
\cmd{\linux}{for t in nat mangle filter raw; do iptables -t \$t -nL; done}
\cmd{\windows}{netsh firewall show portopening}
\cmd{\windows}{netsh firewall show allowedprogram}
\cmd{\windows}{netsh firewall show config}
\end{action}
\begin{action}{Check DNS resolver}
\cmd{\unix}{vi /etc/resolv.conf}
\end{action}
\begin{action}{Disable IPv6}
\cmd{\linux}{ipv6.disable=1} \comment{add to kernel line}
\cmd{\linux}{vi /etc/sysctl.conf\\
net.ipv6.conf.all.disable\_ipv6 = 1\\
net.ipv6.conf.<interface0>.disable\_ipv6 = 1\\
net.ipv6.conf.<interfaceN>.disable\_ipv6 = 1\\
vi /etc/hosts \comment{comment IPv6 hosts}}
\cmd{\linux}{vi /etc/sysconfig/network\\
NETWORKING\_IPV6=no\\
IPV6INIT=no\\
service network restart}
\cmd{\linux}{vi /etc/modprobe.conf\\
install ipv6 /bin/true \comment{append to file}}
\cmd{\linux}{vi /etc/modprobe.conf \comment{RHEL/CentOS}\\
alias net-pf-10 off}
\cmd{\linux}{vi /etc/modprobe.conf \comment{Debian/Ubuntu}\\
alias net-pf-10 off \\
alias ipv6 off}
\cmd{\windows}{reg add
hklm{\textbackslash}system{\textbackslash}currentcontrolset{\textbackslash}services{\textbackslash}
tcpip6{\textbackslash}parameters /v DisabledComponents /t REG\_DWORD /d 255}
\end{action}
\begin{action}{Check network configuration}
\cmd{\linux}{vi /etc/network/interfaces} \comment{Ubuntu}
\cmd{\linux}{vi /etc/sysconfig/network-scripts/ifcfg-eth*} \comment{RHEL}
\end{action}
\section*{Forensics}
\subsection*{Users}
\begin{action}{Inspect logged in and past users}
\cmd{\unix}{w}
\cmd{\unix}{last | head}
\cmd{\unix}{ps -ef | awk '\$6 != "?"'} (interactive procs)
\end{action}
\subsection*{Processes}
\begin{action}{Inspect startup items}
\cmd{\linux}{initctl show-config}
(\href{http://upstart.ubuntu.com/cookbook/upstart_cookbook.pdf}{upstart},
Ubuntu)
\cmd{\freebsd}{less /etc/rc.local} (deprecated)
\cmd{\freebsd}{grep local\_start /etc/defaults/rc.conf}
\tool{\windows}{Autoruns} \button{Everything}
\end{action}
\begin{action}{Find SETUID and SETGID files and types}
\cmd{\unix}{find / \textbackslash( -perm -4000 -o -perm -2000 \textbackslash)
-exec file \textbackslash\{\textbackslash\} \textbackslash;}
\cmd{\unix}{crontab -e\\
0 4 * * * find / \textbackslash( -perm -4000 -o -perm -2000 \textbackslash)
-type f > /var/log/sidlog.new \&\&
diff /var/log/sidlog.new /var/log/sidlog \&\&
mv /var/log/sidlog.new /var/log/sidlog}
\end{action}
\begin{action}{Find world/group writeable directories}
\cmd{\unix}{find / \textbackslash( -perm -g+w -o -perm -o+w \textbackslash)
-type d -exec ls -ald \textbackslash\{\textbackslash\} \textbackslash;}
\end{action}
\begin{action}{Find all unsigned processes}
\tool{\windows}{ProcessExplorer}
\button{Options} \click \button{Verify Image Signatures}
\end{action}
\begin{action}{Display listening TCP/UDP ports}
\cmd{\linux\windows\unix}{netstat -tun}
\cmd{\bsd}{netstat -p tcp -an | egrep 'Proto|LISTEN|udp'}
\cmd{\unix}{lsof -nPi | awk '/LISTEN/'}
\cmd{\freebsd}{sockstat -4 -l}
\end{action}
\begin{action}{Check active connections to find backdoors}
\cmd{\unix}{lsof -nPi | awk '/ESTABLISHED/'}
\end{action}
\subsection*{Cleanup}
\begin{action}{Kill all processes accessing a mount point}
\cmd{\unix}{fuser -k -c /mnt/secret}
\end{action}
\section*{References}
\begin{itemize}
\small
\item \url{http://bit.ly/cmd-line-kung-fu}
\end{itemize}
\end{multicols*}
\end{document}