プロジェクト

全般

プロフィール

CTF Forensic » 履歴 » バージョン 2

kanata, 2025/04/13 14:34

1 1 kanata
# CTF Forensic
2
3
{{toc}}
4
5
# Command gadgets
6
7
- ハッシュ値生成
8
9
md5sum sha1sum sha224sum sha256sum
10
11
## find
12
13
通常のファイル検索
14
15
```
16
find `pwd` -name "${1}" -print 2>/dev/null
17
```
18
19
どんな種類のファイルがあるか検索
20
21
```
22
find ./ | xargs file
23
```
24
25
## xz
26
27
圧縮
28
29
```
30
xz -zk ファイル
31
```
32
33
展開
34
35
```
36
unxz -dk ファイル
37
```
38
39
## ディスクイメージからzipファイルを抜き出す(python)
40
41
dは1個目、yは二個目
42
43
```
44
$python
45
>>> d = open("入力ファイル名","rb").read()
46
>>> z = d[d.find("PK\x03\x04"):d.find("PK\x05\x06")+22]
47
>>> len(z)
48
>>> open("出力ファイル名","wb").write(d[d.find("PK\x03\x04"):d.find("PK\x05\x06")+22])
49
>>> y = d[d.find("PK\x05\x06")+22:]
50
>>> open("出力ファイル名","wb").write(y[y.find("PK\x03\x04"):y.find("PK\x05\x06")+22])
51
```
52
53
## gzipファイルに付けられたコメントを表示する
54
55
標準的なコマンドがない。ただ、
56
57
- ファイル名
58
- NULL(0x00)
59
- コメント
60
61
というフォーマットになっているので、がんばれは読めると思われる。
62
63
参考:http://www.gzip.org/zlib/rfc-gzip.html
64
65
ちなみにコメントの有無は、fileコマンドで
66
67
```
68
comment,
69
```
70
71
が出てきたらコメント在り。
72
73
## zipファイルに付けられたコメントを表示する
74
75
zipの中のファイル毎にコメントを付けられる仕様。あんまり使われてないけど。
76
77
```
78
unzip -lz a.zip
79
```
80
81
## Exif情報を取得する
82
83
ImageMagickでExif情報を取得するには、identifyコマンドを使う。 
84
85
```
86
identify -verbose a.jpg
87
```
88
89
## ddコマンドで保存したイメージファイルをマウントする 
90
91
```
92
% sudo fdisk -u -l disk_20130530-1400.img
93
94
ディスク acid_20130530-1400.img: 4012 MB, 4012900352 バイト
95
ヘッド 255, セクタ 63, シリンダ 487, 合計 7837696 セクタ
96
Units = セクタ数 of 1 * 512 = 512 バイト
97
セクタサイズ (論理 / 物理): 512 バイト / 512 バイト
98
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
99
ディスク識別子: 0x00014d34
100
101
デバイス ブート 始点 終点 ブロック Id システム
102
disk_20130530-1400.img1 8192 122879 57344 c W95 FAT32 (LBA)
103
disk_20130530-1400.img2 122880 7774207 3825664 83 Linux
104
105
% sudo mount -o loop,offset=$((512*122880)) disk_20130530-1400.img /mnt
106
```
107
108
## 時刻指定でgrepする
109
110
find_by_date.sh
111
112
```
113
#!/bin/sh
114
115
DATE_FROM="201504250000.00"
116
DATE_TO="201504262359.59"
117
118
touch -t $DATE_FROM /tmp/tmp_date_from.$$
119
touch -t $DATE_TO   /tmp/tmp_date_to.$$
120
121
find $SEARCH_PATH -type f -newer /tmp/tmp_date_from.$$ ! -newer /tmp/tmp_date_to.$$ -ls;
122
123
exit 0
124
```
125
126
grep_by_date.sh
127
128
```
129
#!/bin/sh
130
131
LIST=`/usr/local/bin/find_by_date.sh $1 $2 $3|awk '{print $NF'}`
132
133
for WORD in ${LIST}
134
do
135
        grep $4 ${WORD} 2>/dev/null
136
        if [ $? = "0" ]
137
        then
138
                echo "########## ${WORD} is founded ##########"
139
        fi
140
done
141
142
exit 0
143
```
144
145
## 画像ファイルのEXIF情報を取得する
146
147
```bash 
148
$ identify -verbose ファイルPATH
149
```
150
151
[俺的備忘録 〜なんかいろいろ〜 - コンソール上でImageMagickを使って画像ファイルのEXIF情報を取得する](https://orebibou.com/2017/08/%e3%82%b3%e3%83%b3%e3%82%bd%e3%83%bc%e3%83%ab%e4%b8%8a%e3%81%a7imagemagick%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e7%94%bb%e5%83%8f%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%81%aeexif%e6%83%85%e5%a0%b1/)
152
153
154
155
156
157
158
159
160
161
162
163
# WebService / Application
164
165
## Online TrID File Identifier
166
167
http://mark0.net/onlinetrid.aspx
168
169
## binvis.io - バイナリビューア
170
171
http://binvis.io/#/
172
173
174
175
176
# Setup
177
178
## hachoir-subfile のインストール
179
180
CentOSへの[hachoir-subfile](https://bitbucket.org/haypo/hachoir/wiki/hachoir-subfile)のインストール
181
182
```
183
$ cd /home/user/PythonSandBox
184
$ source bin/activate # virtualenvによる仮想環境に移行
185
186
(PythonSandBox)$ cd tmp
187
(PythonSandBox)$ mkdir hachoir
188
(PythonSandBox)$ hachoir
189
(PythonSandBox)$ wget http://cheeseshop.python.org/packages/source/h/hachoir-core/hachoir-core-1.3.3.tar.gz
190
(PythonSandBox)$ wget http://cheeseshop.python.org/packages/source/h/hachoir-parser/hachoir-parser-1.3.4.tar.gz
191
(PythonSandBox)$ wget http://cheeseshop.python.org/packages/source/h/hachoir-metadata/hachoir-metadata-1.3.3.tar.gz
192
(PythonSandBox)$ wget http://cheeseshop.python.org/packages/source/h/hachoir-urwid/hachoir-urwid-1.1.tar.gz
193
(PythonSandBox)$ wget http://cheeseshop.python.org/packages/source/h/hachoir-wx/hachoir-wx-0.3.tar.gz
194
(PythonSandBox)$ wget http://cheeseshop.python.org/packages/source/h/hachoir-subfile/hachoir-subfile-0.5.3.tar.gz
195
(PythonSandBox)$ wget http://cheeseshop.python.org/packages/source/h/hachoir-regex/hachoir-regex-1.0.5.tar.gz
196
```
197
198
次に、ダウンロードした全てのファイルをtar xvfzで展開。その中に入っているsetup.py全てについて
199
200
```
201
(PythonSandBox)$./setup.py build
202
(PythonSandBox)$./setup.py install
203
```
204
205
を実施する。順番はあんまり関係ないみたい
206
207
## zpipeのインストール
208
209
zlib部分の圧縮・伸張ができるプログラム
210
211
使い方
212
213
```
214
$ zpipe < src.bin > dest.bin    #圧縮
215
$ zpipe -d < src.bin > dest.bin #伸張
216
```
217
218
注: deflateInitで圧縮されたzlib圧縮データのことである。deflateInit2でGZIP圧縮されたデータではない。
219
220
ビルド方法
221
222
```
223
$ cd /tmp
224
$ git clone https://github.com/madler/zlib
225
$ cd zlib
226
$ ./configure
227
$ make
228
$ cd examples
229
$ gcc zpipe.c -lz -o zpipe
230
```
231
232
233
234
235
# フォレンジック調査で使用するマウント関連のコマンド 
236
237
http://sec-v6.blogspot.jp/2013/03/blog-post.html
238
239
## ディスクイメージをそのままマウントする
240
241
```
242
mount [image_file] [mount_point]
243
```
244
245
## 特定のパーティションをマウントする
246
247
ディスクイメージの中の特定パーティションのみマウントするにはまずオフセットを調べる。
248
オフセットを調べるには fdisk または mmls を使用する。
249
250
```
251
fdisk -lu [image_file]
252
mmls [image_file]
253
```
254
255
mmls は sleuthkit.org で開発されている sleuthkit に入っているコマンド。SIFT ではデフォルトで使用可能。
256
マウントしたいパーティションの start となっている数値にセクタサイズ(通常512)をかけた数が offset となり、この値を mount コマンドで指定する。
257
258
```
259
mount -o loop,offset=[start*512] [image_file] [mount_point]
260
```
261
262
フォレンジック調査なら読み取り専用のオプション -o ro loop、ファイルタイプとして -t ntfs とか nls=utf8 とか付け加える。
263
264
## E01 イメージの取り扱い
265
266
EnCase image file format で保全されたディスクイメージを扱いたい場合にいは SIFT に入っている ewfmount を使う。
267
ewfmount により E01 イメージを dd イメージで操作できる。
268
269
```
270
ewfmount [e01_image_file] [mount_point]
271
```
272
273
 E01 イメージが一つではなく複数に分割されている場合は末尾がE01のファイルを指定するだけ。 
274
この状態で [mount_point] 配下に ewf1 という dd イメージファイルができ、それをマウントすることができる。 アンマウントは通常通り umount コマンドでできる。
275
276
## イメージディスクの作成
277
イメージディスクの作成は下記コマンドで実行。
278
279
```
280
dd if=[input_disk] of=[output_file] bs=512 obs=1024k count=[number] conv=sync,noerror 
281
```
282
283
# メモリフォレンジック
284
285
## volatility
286
287
[volatility](http://www.volatilityfoundation.org/)一択
288
289
>ちなみにこの分野は日本語書籍がほぼ無い
290
291
1. imageinfoオプションで、OS判別してvolatilityのプロファイルを特定
292
2. その上で、各種コマンドを叩いて調べる
293
3. [SANSのチートシート](https://digital-forensics.sans.org/media/poster_2014_find_evil.pdf)から怪しいプロセスを発見するのがまず一歩か
294
295
> 1個しかないプロセスが複数あるとか、親プロセスがおかしいとか
296
297
298
 * dllの読み込みは、false false false だったら怪しい、true  false true  は正常な可能性が高い
299
300
>> DLLの隠蔽、DLLのリンクは三種類の双方向リストで管理されており、これを細工して隠蔽できる
301
302
 * 後述のstringsコマンドで抽出した文字列を、volatilityを使ってメモリイメージと紐付けられる。それをgrepでいろいろ見る。
303
304
305
```
306
# Help
307
volatility -h
308
volatility pslist --help
309
310
# Info これでOSを特定する
311
volatility -f [image] imageinfo
312
313
$ volatility  -f win7_trial_64bit.raw imageinfo
314
Volatility Foundation Volatility Framework 2.4
315
Determining profile based on KDBG search...
316
317
          Suggested Profile(s) : Win7SP0x64, Win7SP1x64, Win2008R2SP0x64, Win2008R2SP1x64
318
                     AS Layer1 : AMD64PagedMemory (Kernel AS)
319
                     AS Layer2 : FileAddressSpace (/Users/Michael/Desktop/win7_trial_64bit.raw)
320
                      PAE type : PAE
321
                           DTB : 0x187000L
322
                          KDBG : 0xf80002803070
323
          Number of Processors : 1
324
     Image Type (Service Pack) : 0
325
                KPCR for CPU 0 : 0xfffff80002804d00L
326
             KUSER_SHARED_DATA : 0xfffff78000000000L
327
           Image date and time : 2012-02-22 11:29:02 UTC+0000
328
     Image local date and time : 2012-02-22 03:29:02 -0800
329
```
330
331
>この場合、プロファイルは Win7SP0x64 か Win2008R2SP0x64 (Image Type (Service Pack) : 0 から絞り込める)
332
333
334
```
335
# Process
336
volatility -f [image] --profile=[OS Profile] pslist
337
volatility -f [image] --profile=[OS Profile] psscan
338
volatility -f [image] --profile=[OS Profile] pstree
339
volatility -f [image] --profile=[OS Profile] psxview
340
volatility -f [image] --profile=[OS Profile] psxview --apply-rules
341
342
# Network
343
volatility -f [image] --profile=[OS Profile] netscan #Vista以降
344
volatility -f [image] --profile=[OS Profile] connections #
345
volatility -f [image] --profile=[OS Profile] connscan    #
346
volatility -f [image] --profile=[OS Profile] sockscan    #
347
348
# Registry
349
volatility -f [image] --profile=[OS Profile] hivelist
350
volatility -f [image] --profile=[OS Profile] printkey -K "[registry key]"
351
volatility -f [image] --profile=[OS Profile] userassist
352
volatility -f [image] --profile=[OS Profile] shellbags
353
volatility -f [image] --profile=[OS Profile] shellbags --output-file=[shellbags.body] --output=body
354
volatility -f [image] --profile=[OS Profile] shimcache
355
volatility -f [image] --profile=[OS Profile] getsids --offset [address]
356
volatility -f [image] --profile=[OS Profile] privs --offset [address]
357
volatility -f [image] --profile=[OS Profile] hashdump
358
volatility -f [image] --profile=[OS Profile] lsadump
359
360
# Command history
361
volatility -f [image] --profile=[OS Profile] cmdscan
362
volatility -f [image] --profile=[OS Profile] consoles
363
364
# DLL
365
volatility -f [image] --profile=[OS Profile] dlllist
366
volatility -f [image] --profile=[OS Profile] handles -p [pid] -t File
367
volatility -f [image] --profile=[OS Profile] handles -p [pid] -t Key
368
volatility -f [image] --profile=[OS Profile] handles -p [pid] -t Directory
369
volatility -f [image] --profile=[OS Profile] handles -p [pid] -t Port
370
volatility -f [image] --profile=[OS Profile] handles -p [pid] -t Mutant
371
volatility -f [image] --profile=[OS Profile] handles --offset [address]
372
373
# evtlog
374
volatility -f [image] --profile=[OS Profile] evtlogs -D [Directory]
375
volatility -f [image] --profile=[OS Profile] evtlogs --save-evt -D [Directory]
376
377
# Service
378
volatility -f [image] --profile=[OS Profile] svcscan
379
380
# FileSystem
381
volatility -f [image] --profile=[OS Profile] mftparser --output-file=[outfile.txt]
382
volatility -f [image] --profile=[OS Profile] mftparser --output-file=[outfile.txt] --output=body # body形式は別のソフトで読める
383
384
# Dump
385
volatility -f [image] --profile=[OS Profile] dlldump -p [pid] -D [Directory]
386
volatility -f [image] --profile=[OS Profile] procdump -p [pid] -D [Directory]
387
volatility -f [image] --profile=[OS Profile] dumpfiles -r .evtx$ --ignore-case -D [Directory]
388
procdump -p [pid] --dump-dir=/tmp
389
photorec /d [Directory] [image]
390
391
# Timeline
392
volatility -f [image] --profile=[OS Profile] timeliner --output-file=timeliner.body --output=body
393
394
 # bodyファイルは結合できる
395
 cat [BodyFile.1] [BodyFile.2] [BodyFile.3] > [BodyFile]
396
397
 # mactime
398
 mactime --help
399
 mactime -b [BodyFile] -d -z UTC
400
401
# Vad
402
volatility -f [image] --profile=[OS Profile] -p [pid] vadinfo
403
volatility -f [image] --profile=[OS Profile] -p vaddump -D [Directory]
404
405
# Strings
406
strings -td -a [image] >> strings.txt # "FREE MEMORY"という単語がなんかしらないがよく使うらしい
407
strings -td -el -a [image] >> strings.txt
408
409
volatility -f [image] --profile=[OS Profile] strings -s strings.txt > [out.txt]
410
411
grep [string] out.txt # IPアドレス等で引っ掛けて -A -B のオプションでその前後を出力して調査
412
413
# Malware Check
414
volatility -f [image] --profile=[OS Profile] ldrmodules -p [pid]
415
volatility -f [image] --profile=[OS Profile] malfind -p [pid]
416
417
# Yarascan
418
volatility -f [image] --profile=[OS Profile] yarascan --yara-rules="[strings]"
419
volatility -f [image] --profile=[OS Profile] yarascan -p [pid] --yara-rules="[binary code]"
420
volatility -f [image] --profile=[OS Profile] yarascan -p [pid] --yara-rules="[strings]"
421
422
# Misc
423
volatility -f [image] --profile=[OS Profile] objtypescan # Object Acan
424
volatility -f [image] --profile=[OS Profile] Volshell    # Volshell
425
volatility -f [image] --profile=[OS Profile] iehistory   # IEの履歴
426
```
427
428
429
# FileSystem
430
431
## ファイルシステムソムリエ
432
433
Gentoo metalog - ファイルシステムソムリエになる話
434
http://gentoo.hatenablog.com/entry/2016/06/17/020107
435
436
Linux ファイルシステムを理解したい
437
https://www.kimullaa.com/entry/2019/12/01/130347
438
439
440
441
## [FATファイルシステム](http://memes.sakura.ne.jp/memes/?page_id=2390)
442
443
FATファイルシステム(その1)
444
http://memes.sakura.ne.jp/memes/?page_id=2303
445
446
FATファイルシステム(その2)
447
http://memes.sakura.ne.jp/memes/?page_id=2402
448
449
Qiita - FAT12,FAT16の構造(予約領域編)
450
https://qiita.com/iria_piyo/items/d949b93bc056a8c370d6
451
452
453
454
## FAT16
455
456
参考 - ねんどろいど伊401に時報を喋らせるガジェットを作ってみた
457
http://tech.recruit-mp.co.jp/gadget/pic-inside-i401/
458
459
460
461
## NTFS
462
463
### VSS削除後の復元
464
465
https://github.com/mnrkbys/vss_carver
466
467
### USNジャーナル(ファイルのwriteの記録)
468
469
CDI 山崎さんのUSNジャーナルの分析ツールの発表。クオリティが半端ないw
470
471
本家
472
https://github.com/simsong/bulk_extractor
473
474
カービングツール
475
https://www.kazamiya.net/bulk_extractor-rec
476
477
分析ツール
478
https://www.kazamiya.net/usn_analytics/
479
480
資料はこちら
481
https://www.jpcert.or.jp/event/jsac2018.html
482
483
>シグネチャとして固定部分(ヘッダ:USN_RECORD_V2)/ レコード長 / ファイル名の長さを使用している。
484
485
Python script to parse the NTFS USN Journal
486
https://github.com/PoorBillionaire/USN-Journal-Parser
487
488
489
490
491
492
## ext
493
494
Qiita - 知っておきたいLinuxファイルシステムの概念
495
https://qiita.com/Rairaiden/items/539d429729d5819de0aa
496
497
498
499
500
501
502
503
504
505
506
507
# Magic Number
508
509
trid(コマンドかオンラインでファイルを判別するツール)
510
http://mark0.net/onlinetrid.aspx
511
512
File Signature Database
513
http://www.filesignatures.net/index.php?page=search
514
515
http://www.astro.keele.ac.uk/oldusers/rno/Computing/File_magic.html
516
517
## 実行形式
518
519
| ファイルフォーマット | HEX     | ASCII | Note |
520
|----------------------|---------|-------|------|
521
| ELF                  | 7F      |       |
522
| PE(.exe .dll .ocx .scr .cpl .com .fon) | 4D 5A   | MZ    | 頭の方(0x80~0xf0のあたり)が 50 40 00 00 4C 01 で32bit 50 40 00 00 64 86 で64bit PE(50 40)から始まっているので、見つけやすい 
523
| Javaクラスファイル   | CA FE BA BE |   |
524
| gzip                 | 1F 8B   |       |
525
| Compress(.Z)         | 1F 9D   |       |
526
| Bzip(.bz)            | 42 5a   | BZ    |
527
| zip                  | 50 4B   | PK    |
528
| TAR (pre-POSIX)      |         | (a filename) |
529
| TAR (POSIX)          | 75 73 74 61 72  | ustar |
530
| zip                  | 50 4B 03 04 | PK | 終端は PK 0x05 0x06 の後ろに18Byte コメントが付けられるので可変長ではある
531
| zlib                 | 78 9c | | 78 DA や 78 01 の場合も?ある
532
| LHA(lh0)             | ?? ?? 2D 6C 68 30 2D | ??-lh0- |
533
| LHA(lh4)             | ?? ?? 2D 6C 68 34 2D | ??-lh4- |
534
| LHA(lh5)             | ?? ?? 2D 6C 68 35 2D | ??-lh5- |
535
| 7z                   | 37 7A BC AF 27 1C | 7z |
536
| xz                   | fd 37 7a 58 5a 00 | ?7zXZ | 
537
| cab                  | 4d 53 43 46 | MSCF | 
538
| RAR                  | 52 61 72 21 | Rar! |
539
| Jpeg                 | FF D8 FF E0 ?? ?? 4A 46 49 46 | ??????JFIF | 終端は FF D9 "・ル"
540
| PNG                  | 89 50 4E 47 | ?PNG → 臼NG | 終端は 00 00 00 00 49 45 4E 44 AE 42 60 82 "IENDョB`"
541
| WebP                 | 52 49 46 46 ?? ?? ?? ?? 57 45 42 50 | RIFF????WEBP | ????はファイルサイズ
542
| HEIF(HEIC)           | ?? ?? ?? ?? 66 74 79 70 | ??????ftypmif1????mif1heichevc | ftypとheicという文字が見えるとHEIFっぽい
543
| GIF(89a)             | 47 49 46 38 39 61 | GIF89a | 終端は 3B
544
| GIF(87a)             | 47 49 46 38 37 61 | GIF87a | 
545
| BMP                  | 42 4D   | BM    |
546
| BGP                  | 42 50 47 fb 20 00 | BGP    |
547
| TIFF                 | 49 49 または 4d 4d | II または MM | 「4D 4D」なら上位から下位バイトへ読み、「49 49」なら下位から上位バイトで読みます
548
| Postscript           | 25 21   | %!    |
549
| Microsoft Offic e    | D0 CF 11 E0 A1 B1 1A E1 ||
550
| PDF                  | 25 50 44 46 2D | %PDF-バージョン番号 |
551
| wav                  | 52 49 46 46 | RIFF
552
| swf                  | 43 57 53 または 46 53 57 | CSW または FSW
553
| wma                  | 30 26   | 0&
554
| pgp public ring      | 99 00   |       |
555
| pgp security ring    | 95 01   |       | 
556
| pgp security ring    | 95 00   |       | 
557
| pgp encrypted data   | a6 00   |       |
558
| pcap(tcpdump)        | d4 c3 b2 a1 | ヤテイ。 |
559
560
561
# Repair
562
563
文字化けリペア
564
>=?ISO-2022-JP?B?GyRCJD8hIxsoQg==?= のような件名など
565
From, Subjectなどの読めないヘッダを修復
566
>>http://purl.org/net/masaka/mr/mime.php
567
568
>$B$3$l$O(JJIS$B$NJ8$G$9!#(Jのような文字化け
569
文字化けしている本文の修復
570
>>http://purl.org/net/masaka/mr/jmr.php
571
572
>&#12371;&#12435;...のような、 '&#' と ';' に数字が挟まれたコードが連続する本文
573
Unicode文字参照になっている本文の解読
574
>>http://purl.org/net/masaka/mr/r2u.php
575
576
pcapリペア
577
http://f00l.de/hacking/pcapfix.php
578
579
zipリペア
580
http://www.gigafree.net/utility/archive/diskinternalsziprepair.html
581
582
----
583
584
Foremost ファイル復元方法(Linux編)
585
http://brand-jin.tk/?p=463
586
587
foremostというバイナリファイルの中からファイルを復元できるツール
588
https://github.com/kira924age/CTF/tree/master/SECCON2014%E3%82%AA%E3%83%B3%E3%83%A9%E3%82%A4%E3%83%B3%E4%BA%88%E9%81%B8(%E6%97%A5%E6%9C%AC%E8%AA%9E)/%E6%8D%8F%E9%80%A0%E3%81%95%E3%82%8C%E3%81%9F%E5%A5%91%E7%B4%84%E6%9B%B8%E3%82%92%E6%9A%B4%E3%81%91
589
590
俺的備忘録 〜なんかいろいろ〜 - バイナリやファイル、ディスクから中のデータを抽出・復元する『foremost』コマンド
591
https://orebibou.com/2017/04/%e3%83%90%e3%82%a4%e3%83%8a%e3%83%aa%e3%82%84%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%80%81%e3%83%87%e3%82%a3%e3%82%b9%e3%82%af%e3%81%8b%e3%82%89%e4%b8%ad%e3%81%ae%e3%83%87%e3%83%bc%e3%82%bf%e3%82%92/
592
593
```
594
$ ./foremst -t all -i Timestamp.dd
595
```
596
597
「PhotoRec」の使い方 ファイル復元ソフト
598
https://pctrouble.net/software/photorec.html
599
600
601
602
603
604
605
# ファイル解析
606
607
rga: ripgrep, but also search in PDFs, E-Books, Office documents, zip, tar.gz, etc.
608
https://phiresky.github.io/blog/2019/rga--ripgrep-for-zip-targz-docx-odt-epub-jpg/
609
610
>これが全般的に使えるんじゃないかと気になっている
611
>pdfやdocx、sqlite、画像や動画のメタデータなどを全部grepできるツール
612
613
## pdfの解析
614
615
PDF中の画像ファイルのみを抽出する
616
https://qiita.com/aokomoriuta/items/066b760a28da461531b6
617
618
>libre Office Draw でpdfが編集できる
619
620
peepdf - PDF Analysis Tool
621
http://eternal-todo.com/tools/peepdf-pdf-analysis-tool
622
623
> Kali Linux に同梱されている
624
625
>かわろぐ - peepdf を使って攻撃コードの入ったPDFを解析してみた
626
>http://blog.kawa-xxx.jp/entry/2016/09/19/165709
627
628
PDF Stream Dumper [使用例](http://ameblo.jp/norio001/entry-11372965347.html)
629
http://sandsprite.com/blogs/index.php?uid=7&pid=57
630
631
PDFからテキストを抽出するプログラム
632
https://osdn.jp/users/mocchi_2012/pf/mocchi_stack_room/wiki/extract_pdf
633
634
>pdfファイル中のstream~endstream間は、zlib圧縮されてたりするのだが、展開くれて、json形式で出力してくれる。
635
636
プログラムモグモグ - 詳細PDF入門 ー 実装して学ぼう!PDFファイルの構造とその書き方読み方 
637
http://itchyny.hatenablog.com/entry/2015/09/16/100000
638
639
corkami - PDFのトリックに関するレジュメ - エンコーディング,構成,JavaScriptなど 
640
https://code.google.com/p/corkami/wiki/PDFTricks
641
642
pdfcrack
643
http://pdfcrack.sourceforge.net/
644
645
>あと[辞書](https://wiki.skullsecurity.org/index.php?title=Passwords)
646
647
evince
648
https://ja.wikipedia.org/wiki/Evince
649
650
>コピー禁止とか無視できたりする
651
652
653
654
655
656
657
## pngの解析
658
659
[pngcheck](https://www.google.co.jp/search?&hl=ja&lr=lang_ja&q=pngcheck&cad=h)
660
661
662
663
## Office形式のファイル解析
664
665
OfficeMalScanner
666
http://www.reconstructer.org/
667
668
73spica's Blog - EKOPARTY CTF 2016 Write-up
669
http://73spica.tech/blog/ekoparty-ctf-2016-write-up/
670
671
Github - MalwareCantFly/Vba2Graph (VBAの解析・可視化)
672
https://github.com/MalwareCantFly/Vba2Graph
673
674
## zlibの解析
675
676
展開は、以下でできる。
677
678
```
679
$ cat src.bin |openssl zlib -d >dest.bin
680
```
681
682
zpipeでも可
683
684
```
685
$ zpipe < src.bin > dest.bin    #圧縮
686
$ zpipe -d < src.bin > dest.bin #伸張
687
```
688
689
pythonシェル芸だとこう
690
691
```python
692
python -c 'import zlib; print zlib.decompress(open("File").read())'
693
```
694
695
696
697
バイナリからzlib圧縮データを探す 
698
http://teraapi.blogspot.jp/2012/05/zlib.html
699
700
```
701
よくある: 
702
78 01, 78 5e, 78 9c, 78 da 
703
704
稀 :
705
08 1d, 08 5b, 08 99, 08 d7, 18 19, 18 57, 18 95, 18 d3, 
706
 28 15, 28 53, 28 91, 28 cf, 38 11, 38 4f, 38 8d, 38 cb, 
707
 48 0d, 48 4b, 48 89, 48 c7, 58 09, 58 47, 58 85, 58 c3, 
708
 68 05, 68 43, 68 81, 68 de 
709
710
極稀:
711
08 3c, 08 7a, 08 b8, 08 f6, 18 38, 18 76, 18 b4, 18 f2, 
712
 28 34, 28 72, 28 b0, 28 ee, 38 30, 38 6e, 38 ac, 38 ea, 
713
 48 2c, 48 6a, 48 a8, 48 e6, 58 28, 58 66, 58 a4, 58 e2, 
714
 68 24, 68 62, 68 bf, 68 fd, 78 3f, 78 7d, 78 bb, 78 f9  
715
```
716
717
### 引数のファイルに含まれるzlib圧縮部分を抽出・展開してファイルに保存する
718
719
自作ツール。CentOSで動作確認済み。Kali Linuxだとopensslでzlibのdecodeが出来なかったので、たぶん、Debian でも動かないかも。
720
まぁ、zpipeで代替すれば、どの環境でも行けるはず。
721
ちなみに、動作はめっちゃ遅い。
722
723
attachment:zlib_extraction.sh
724
725
```bash
726
#!/bin/bash
727
728
# zlib_extraction.sh ver 2.0
729
# 引数のファイルに含まれるzlib圧縮部分を抽出・展開してファイルに保存する
730
# 2015.10.06 kanata 
731
732
if [ ! -f "${1}" ]
733
then
734
  echo "file open error ($1)"
735
  exit 1
736
fi
737
738
if echo "${2}" |egrep '(BOOST|boost|Boost)' >/dev/null
739
then
740
  MODE="BOOST_MODE"
741
else
742
  MODE="NORMAL_MODE"
743
fi
744
745
746
FILESIZE=`ls -l ${1}|awk '{print $5}'`
747
ZLIBPART="${1##*/}"
748
ZLIBPART="${ZLIBPART%.*}"
749
I="0"
750
FORK_COUNT="0"
751
752
if [ "${MODE}" = "NORMAL_MODE" ]
753
then
754
  #--------------#
755
  # シリアル処理 #
756
  #--------------#
757
  while [ "${I}" -lt "${FILESIZE}" ]
758
  do
759
    ZLIBPART_FILE="${ZLIBPART}_${I}.bin"
760
    cat ${1} | dd bs=1 skip=${I} | openssl zlib -d > ${ZLIBPART_FILE} 2>/dev/null
761
762
    if [ -s ${ZLIBPART_FILE} ]
763
    then
764
      file ${ZLIBPART_FILE}
765
    else
766
      rm -f ${ZLIBPART_FILE}
767
    fi
768
769
    echo -ne "checking.. "`printf "%d/%d" "${I}" "${FILESIZE}"`" \r"
770
    I=$(( I + 1 ))
771
  done
772
773
else
774
  #----------#
775
  # 並列処理 #
776
  #----------#
777
  while [ "${I}" -lt "${FILESIZE}" ]
778
  do
779
    ZLIBPART_FILE="${ZLIBPART}_${I}.bin"
780
    ( cat ${1} | dd bs=1 skip=${I} | openssl zlib -d > ${ZLIBPART_FILE} 2>/dev/null ; if [ -s ${ZLIBPART_FILE} ] ; then file ${ZLIBPART_FILE} ; else rm -f ${ZLIBPART_FILE} ; fi )&
781
782
    # 並列実行時のサブシェルが増大していくのを抑止
783
    # 同時35多重までに抑止 25回に1度チェック ( 数値を弄ってチューニングできます )
784
    if [ $(( I % 25 )) -eq "0" ] ; then FORK_COUNT=`ps -u |fgrep -c ${0}` ; fi
785
    while  [ "${FORK_COUNT}" -gt "35" ] 
786
    do
787
      printf "[WARNING] SubProcess Exceed Limit. fork:%s offset:%s\n" ${FORK_COUNT} ${I}
788
      FORK_COUNT=`ps -u |fgrep -c ${0}`
789
    done
790
791
    echo -ne "checking.. "`printf "%d/%d" "${I}" "${FILESIZE}"`" \r"
792
    I=$(( I + 1 ))
793
  done
794
795
fi
796
797
exit 0
798
```
799
800
### その他の展開方法
801
802
zlib.exe - zlib でデータを圧縮/展開するだけのプログラム
803
http://cetus.sakura.ne.jp/softlab/toolbox2/#zlibexe
804
805
各プログラム言語でのコーディング方法サンプル - Zlib Decompress
806
http://swiftapi.com/api/Zlib_Decompress
807
808
```python
809
$ python -c 'import zlib; print zlib.decompress(open("/directory/file").read())'
810
```
811
812
813
## DXアーカイブ(data.dxa)の展開
814
815
henteko - 2012TeResAI(DXアーカイブの展開ができる)
816
https://github.com/henteko/2012TeResAI/tree/master/2012TeResAI/2012teresAI/DX%20lib/DxLib_VC/Tool/DXArchive
817
818
## Macの.DS_Storeの解析
819
820
Python .DS_Store parser
821
https://github.com/gehaxelt/Python-dsstore
822
823
## PEファイルフォーマット
824
825
PE(Portable Executable)ファイルフォーマットの基本構造 めも
826
https://task4233.dev/article/20200101_pefile.html#pe-portable-executable-format
827
828
829
830
831
832
833
834
# 動画解析
835
836
## 動画差分
837
838
動画のフレームごとの差を求めて変化してた場合に保存するプログラム
839
https://github.com/teatime13/search_movie_diff
840
841
## 比較明合成
842
843
[SiriusComp](http://phaku.net/siriuscomp/)を使う
844
845
## テンプレートマッチング
846
847
Qiita - SECCON 2018 Online CTF Needle in a haystack テンプレートマッチングで照明点灯判定を自動化する
848
https://qiita.com/DoranekoSystems/items/f2fd95fb9ff4ddea369f
849
850
851
852
# Memo
853
854
アンタイ・フォレンジック伝道者の独り言 - NTFS 代替データストリームとは?
855
http://port139.hatenablog.com/entries/2005/09/08
856
857
FOCA - 文書のスキャンでメタデータと隠された情報を検索するためのツール
858
https://www.elevenpaths.com/labstools/foca/
859
860
φ(・・*)ゞ ウーン カーネルとか弄ったりのメモ - ext4:ディスクレイアウト調査中めも1
861
http://kernhack.hatenablog.com/entry/2014/01/28/230808
862
863
俺的備忘録 〜なんかいろいろ〜  - fuseを使ってファイルシステムをモニタリングできる『loggedfs』
864
https://orebibou.com/2017/04/fuse%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%b7%e3%82%b9%e3%83%86%e3%83%a0%e3%82%92%e3%83%a2%e3%83%8b%e3%82%bf%e3%83%aa%e3%83%b3%e3%82%b0%e3%81%a7%e3%81%8d/
865
866
> CTFでのバイナリ実行の挙動を追いかけるのに便利そう
867
868
Visualizing ELF binaries
869
https://reverseengineering.stackexchange.com/questions/6003/visualizing-elf-binaries
870
871
Ubuntu で $ rm ~/.bashrc を実行してしまった - Linuxで誤って削除したファイルの復活の話
872
https://blog.fenrir-inc.com/jp/2017/10/resurrected_rm_files.html
873
874
Automate Linux Swap Analysis: swap_digger - Linux Swap解析ツール(Bashスクリプト)。SwapからLinuxアカウント情報、ウェブアカウント情報、BASIC認証、WiFi SSID・鍵等が取得可能。フォレンジック調査・ペンテスト用。
875
https://n0where.net/automate-linux-swap-analysis-swap_digger/
876
877
SANS DFIR Windows Forensic Analysis POSTER
878
https://www.sans.org/security-resources/posters/windows-forensic-analysis/170/download
879
880
Shi0shishi0 - Defcon DFIR CTF 2018 Writeup(HR Server + File Server) 
881
http://ecoha0630.hatenablog.com/entry/2018/11/22/180306
882
883
Windows 10 Timeline 解析記事のメモ
884
https://soji256.hatenablog.jp/entry/2019/10/05/153559?utm_source=feed
885
886
DFIR や Malware 解析などについての記事まとめ(2019年10月~2019月12月)
887
https://soji256.hatenablog.jp/entry/2020/01/16/082000
888
889
Windowsイベントログ解析ツール「Hayabusa」を使ってみる
890
https://itib.hatenablog.com/entry/2021/12/31/222946
891
892
競技セキュリティまとめのまとめ
893
https://blog.hamayanhamayan.com/entry/2023/02/22/085938