-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMFTExtractor.go
executable file
·208 lines (159 loc) · 7.15 KB
/
MFTExtractor.go
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
package main
import (
//"C"
//"database/sql"
"flag"
"log"
"math"
"strings"
"time"
EWFLogger "github.com/aarsakian/EWF_Reader/logger"
ntfslib "github.com/aarsakian/MFTExtractor/FS/NTFS"
"github.com/aarsakian/MFTExtractor/FS/NTFS/MFT"
UsnJrnl "github.com/aarsakian/MFTExtractor/FS/NTFS/usnjrnl"
"github.com/aarsakian/MFTExtractor/disk"
"github.com/aarsakian/MFTExtractor/exporter"
"github.com/aarsakian/MFTExtractor/filtermanager"
"github.com/aarsakian/MFTExtractor/filters"
MFTExtractorLogger "github.com/aarsakian/MFTExtractor/logger"
"github.com/aarsakian/MFTExtractor/reporter"
"github.com/aarsakian/MFTExtractor/tree"
"github.com/aarsakian/MFTExtractor/utils"
VMDKLogger "github.com/aarsakian/VMDK_Reader/logger"
)
func checkErr(err error, msg string) {
if err != nil {
log.Fatalln(msg, err)
}
}
func main() {
//dbmap := initDb()
//defer dbmap.Db.Close()
// save2DB := flag.Bool("db", false, "bool if set an sqlite file will be created, each table will corresponed to an MFT attribute")
var location string
inputfile := flag.String("MFT", "", "absolute path to the MFT file")
evidencefile := flag.String("evidence", "", "path to image file (EWF formats are supported)")
vmdkfile := flag.String("vmdk", "", "path to vmdk file (Sparse formats are supported)")
flag.StringVar(&location, "location", "", "the path to export files")
MFTSelectedEntries := flag.String("entries", "", "select particular MFT entries, use comma as a seperator.")
showFileName := flag.String("showfilename", "", "show the name of the filename attribute of each MFT record choices: Any, Win32, Dos")
exportFiles := flag.String("filenames", "", "files to export use comma for each file")
exportFilesPath := flag.String("path", "", "base path of files to exported must be absolute e.g. C:\\MYFILES\\ABC translates to MYFILES\\ABC")
isResident := flag.Bool("resident", false, "check whether entry is resident")
fromMFTEntry := flag.Int("fromEntry", -1, "select entry to start parsing")
toMFTEntry := flag.Int("toEntry", math.MaxUint32, "select entry to end parsing")
showRunList := flag.Bool("runlist", false, "show runlist of MFT record attributes")
showFileSize := flag.Bool("filesize", false, "show file size of a record holding a file")
showVCNs := flag.Bool("vcns", false, "show the vncs of non resident attributes")
showAttributes := flag.String("attributes", "", "show attributes (write any for all attributes)")
showTimestamps := flag.Bool("timestamps", false, "show all timestamps")
showIndex := flag.Bool("index", false, "show index structures")
physicalDrive := flag.Int("physicaldrive", -1, "select disk drive number for extraction of non resident files")
partitionNum := flag.Int("partition", -1, "select partition number")
buildtree := flag.Bool("tree", false, "reconstrut entries tree")
showtree := flag.Bool("showtree", false, "show tree")
showParent := flag.Bool("parent", false, "show information about parent record")
showUsnjrnl := flag.Bool("showusn", false, "show information about usnjrnl records")
showFull := flag.Bool("showfull", false, "show full information about record")
orphans := flag.Bool("orphans", false, "show information only for orphan records")
deleted := flag.Bool("deleted", false, "show deleted records")
listPartitions := flag.Bool("listpartitions", false, "list partitions")
fileExtensions := flag.String("extensions", "", "search MFT records by extensions use , for each extension")
collectUnallocated := flag.Bool("unallocated", false, "collect unallocated area of a file system")
hashFiles := flag.String("hash", "", "select hash md5 or sha1 for exported files.")
logactive := flag.Bool("log", false, "enable logging")
showPath := flag.Bool("showpath", false, "show the full path of the selected files.")
strategy := flag.String("strategy", "overwrite", "what strategy will use for files sharing the same file name supported is use Id default is ovewrite.")
usnjrnl := flag.Bool("usnjrnl", false, "show information about changes to files and folders.")
flag.Parse() //ready to parse
var records MFT.Records
var usnjrnlRecords UsnJrnl.Records
var fileNamesToExport []string
entries := utils.GetEntriesInt(*MFTSelectedEntries)
if *usnjrnl {
fileNamesToExport = append(fileNamesToExport, "$UsnJrnl")
}
recordsTree := tree.Tree{}
rp := reporter.Reporter{
ShowFileName: *showFileName,
ShowAttributes: *showAttributes,
ShowTimestamps: *showTimestamps,
IsResident: *isResident,
ShowFull: *showFull,
ShowRunList: *showRunList,
ShowFileSize: *showFileSize,
ShowVCNs: *showVCNs,
ShowIndex: *showIndex,
ShowParent: *showParent,
ShowPath: *showPath,
ShowUSNJRNL: *showUsnjrnl,
ShowTree: *showtree,
}
if *logactive {
now := time.Now()
logfilename := "logs" + now.Format("2006-01-02T15_04_05") + ".txt"
MFTExtractorLogger.InitializeLogger(*logactive, logfilename)
VMDKLogger.InitializeLogger(*logactive, logfilename)
EWFLogger.InitializeLogger(*logactive, logfilename)
}
exp := exporter.Exporter{Location: location, Hash: *hashFiles, Strategy: *strategy}
flm := filtermanager.FilterManager{}
if *exportFiles != "" {
fileNamesToExport = append(fileNamesToExport, utils.GetEntries(*exportFiles)...)
flm.Register(filters.FoldersFilter{Include: false})
flm.Register(filters.NameFilter{Filenames: fileNamesToExport})
}
if *fileExtensions != "" {
flm.Register(filters.ExtensionsFilter{Extensions: strings.Split(*fileExtensions, ",")})
}
if *exportFilesPath != "" {
flm.Register(filters.PathFilter{NamePath: *exportFilesPath})
}
if *orphans {
flm.Register(filters.OrphansFilter{Include: *orphans})
}
if *deleted {
flm.Register(filters.DeletedFilter{Include: *deleted})
}
if *evidencefile != "" || *physicalDrive != -1 || *vmdkfile != "" {
physicalDisk := new(disk.Disk)
physicalDisk.Initialize(*evidencefile, *physicalDrive, *vmdkfile)
recordsPerPartition := physicalDisk.Process(*partitionNum, entries, *fromMFTEntry, *toMFTEntry)
defer physicalDisk.Close()
if *listPartitions {
physicalDisk.ListPartitions()
}
if *collectUnallocated {
exp.ExportUnallocated(*physicalDisk)
}
for partitionId, records := range recordsPerPartition {
records = flm.ApplyFilters(records)
if location != "" {
exp.ExportRecords(records, *physicalDisk, partitionId)
if *hashFiles != "" {
exp.HashFiles(records)
}
}
if *usnjrnl {
usnjrnlRecords = UsnJrnl.Process(records, *physicalDisk, partitionId)
}
if *buildtree {
recordsTree.Build(records)
}
rp.Show(records, usnjrnlRecords, partitionId, recordsTree)
}
} else if *inputfile != "Disk MFT" {
data, fsize, err := utils.ReadFile(*inputfile)
if err != nil {
return
}
var ntfs ntfslib.NTFS
ntfs.MFTTable = &MFT.MFTTable{Size: fsize}
ntfs.ProcessMFT(data, entries, *fromMFTEntry, *toMFTEntry)
records = flm.ApplyFilters(ntfs.MFTTable.Records)
if *buildtree {
recordsTree.Build(records)
}
rp.Show(records, usnjrnlRecords, 0, recordsTree)
}
} //ends for