-
Notifications
You must be signed in to change notification settings - Fork 2
/
inMediasRes.go
387 lines (317 loc) · 11 KB
/
inMediasRes.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
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
// Marius Genheimer 2019, https://dissectingmalwa.re
package main
import (
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"encoding/hex"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"strconv"
"time"
ui "github.com/gizak/termui/v3"
"github.com/gizak/termui/v3/widgets"
"github.com/glaslos/ssdeep"
"github.com/h2non/filetype"
"github.com/pkg/browser"
"github.com/weldpua2008/go-dialog"
)
func check(e error) {
if e != nil {
panic(e)
}
}
func ioReader(file string) io.ReaderAt {
r, err := os.Open(file)
check(err)
return r
}
//func elfAnalysis() (imp []string, sym []elf.ImportedSymbol) {
//
// f := ioReader(os.Args[1])
// _elf, err := elf.NewFile(f)
// check(err)
//
// // Read and decode ELF identifier
// var ident [16]uint8
// f.ReadAt(ident[0:], 0)
// check(err)
//
// if ident[0] != '\x7f' || ident[1] != 'E' || ident[2] != 'L' || ident[3] != 'F' {
// if ident[0] != '\x4D' || ident[1] != 'M' || ident[2] != 'Z'{
// PEAnalysis()
// }
//
// else {
// os.Exit(1)
// }
// }
//
// imp, err = _elf.ImportedLibraries()
// sym, err = _elf.ImportedSymbols()
//
// return imp, sym
//
//}
//func PEAnalysis() {
//}
func processCommand(cmd string, sha256h string, hnk *widgets.Paragraph) {
switch cmd {
case ": vt":
{
vtURL := "https://virustotal.com/gui/file/" + sha256h
browser.OpenURL(vtURL)
}
case ": ha":
{
haURL := "https://www.hybrid-analysis.com/search?query=" + sha256h
browser.OpenURL(haURL)
}
case ": ms":
{
msURL := "https://malshare.com/search.php?query=" + sha256h
browser.OpenURL(msURL)
}
case ": honk":
{
ui.Render(hnk)
}
default:
{
d := dialog.New(dialog.AUTO, 0)
d.Msgbox("Command not recognized. Type \"help\" to see available commands")
}
}
}
func hashfilemd5(filePath string) (string, error) {
var returnMD5String string
file, err := os.Open(filePath)
if err != nil {
return returnMD5String, err
}
defer file.Close()
hash := md5.New()
if _, err := io.Copy(hash, file); err != nil {
return returnMD5String, err
}
hashInBytes := hash.Sum(nil)[:16]
returnMD5String = hex.EncodeToString(hashInBytes)
return returnMD5String, nil
}
func hashfilesha1(filePath string) (string, error) {
var returnSHA1String string
file, err := os.Open(filePath)
if err != nil {
return returnSHA1String, err
}
defer file.Close()
hash := sha1.New()
if _, err := io.Copy(hash, file); err != nil {
return returnSHA1String, err
}
hashInBytes := hash.Sum(nil)[:20]
returnSHA1String = hex.EncodeToString(hashInBytes)
return returnSHA1String, nil
}
func hashfilesha256(filePath string) (string, error) {
var returnSHA256String string
file, err := os.Open(filePath)
if err != nil {
return returnSHA256String, err
}
defer file.Close()
hash := sha256.New()
if _, err := io.Copy(hash, file); err != nil {
return returnSHA256String, err
}
hashInBytes := hash.Sum(nil)[:32]
returnSHA256String = hex.EncodeToString(hashInBytes)
return returnSHA256String, nil
}
func main() {
if err := ui.Init(); err != nil {
log.Fatalf("failed to initialize termui: %v", err)
}
defer ui.Close()
filename := os.Args[1]
// Header Paragraph
headerBox := widgets.NewParagraph()
headerBox.Title = "Filename: " + filename
headerBox.Text = " ____ __ ___ ___ ___ ____\n"
headerBox.Text += " / _/__ / |/ /__ ___/ (_)__ ____ / _ \\/ __/__ Kickstart your static analysis process | Press q to quit\n"
headerBox.Text += " _/ // _ \\/ /|_/ / -_) _ / / _ `(_-</ , _/ _/(_-< Marius Genheimer (@f0wlsec), 2019 | Press r to create a report\n"
headerBox.Text += " /___/_//_/_/ /_/\\__/\\_,_/_/\\_,_/___/_/|_/___/___/ https://dissectingmalwa.re | Don't forget to honk\n"
headerBox.SetRect(0, 0, 150, 7)
headerBox.TextStyle.Fg = ui.ColorCyan
headerBox.BorderStyle.Fg = ui.ColorCyan
hashBox := widgets.NewParagraph()
hashBox.SetRect(0, 7, 95, 13)
hashBox.Title = "Hashes"
hashBox.TextStyle.Fg = ui.ColorWhite
hashBox.BorderStyle.Fg = ui.ColorCyan
// generate file hashes
md5hash, err := hashfilemd5(filename)
sha1hash, err := hashfilesha1(filename)
sha256hash, err := hashfilesha256(filename)
ssdeephash, err := ssdeep.FuzzyFilename(filename)
if err == nil {
hashBox.Text = "MD5: " + " " + md5hash + "\n"
hashBox.Text += "SHA1: " + " " + sha1hash + "\n"
hashBox.Text += "SHA256: " + " " + sha256hash + "\n"
hashBox.Text += "SSDEEP: " + " " + ssdeephash + "\n"
}
fileInfoBox := widgets.NewParagraph()
fileInfoBox.SetRect(95, 7, 150, 13)
fileInfoBox.Title = "File"
fileInfoBox.TextStyle.Fg = ui.ColorWhite
fileInfoBox.BorderStyle.Fg = ui.ColorCyan
filestat, err := os.Stat(filename)
filesize := filestat.Size()
filemodtime := filestat.ModTime()
buf, err := ioutil.ReadFile(filename)
kind, err := filetype.Match(buf)
if kind == filetype.Unknown {
fmt.Println("Unknown file type")
return
}
fileInfoBox.Text = "Size: " + " " + strconv.FormatInt(filesize, 10) + " (" + strconv.FormatInt(filesize/1024.0, 10) + " KiB)" + "\n"
fileInfoBox.Text += "Type: " + " " + kind.MIME.Type + " / " + "\n"
fileInfoBox.Text += "Compiler/Linker: " + "\n"
fileInfoBox.Text += "Date modified: " + " " + filemodtime.Format("2006-01-02 15:04:05") + "\n"
sectionBox := widgets.NewList()
sectionBox.SetRect(0, 13, 30, 23)
sectionBox.Title = "Sections"
sectionBox.TextStyle.Fg = ui.ColorWhite
sectionBox.BorderStyle.Fg = ui.ColorCyan
stringsBox := widgets.NewList()
stringsBox.SetRect(30, 13, 100, 23)
stringsBox.Title = "Strings"
stringsBox.TextStyle.Fg = ui.ColorWhite
stringsBox.BorderStyle.Fg = ui.ColorCyan
urlBox := widgets.NewList()
urlBox.SetRect(100, 13, 150, 23)
urlBox.Title = "URLs/IPs"
urlBox.TextStyle.Fg = ui.ColorWhite
urlBox.BorderStyle.Fg = ui.ColorCyan
entropyBox := widgets.NewPlot()
entropyBox.SetRect(0, 23, 50, 36)
entropyBox.Title = "Entropy"
entropyBox.BorderStyle.Fg = ui.ColorCyan
sandBox := widgets.NewList()
services := []string{
"\n\n VirusTotal [vt]\n",
" Hybrid-Analysis [ha]\n",
" Malshare [ms]\n",
" VirusShare [vs]\n",
}
sandBox.SetRect(50, 23, 80, 36)
sandBox.Title = "Analysis Services"
sandBox.Rows = services
sandBox.TextStyle.Fg = ui.ColorWhite
sandBox.BorderStyle.Fg = ui.ColorCyan
yaraBox := widgets.NewList()
yaraBox.SetRect(80, 23, 125, 36)
yaraBox.Title = "YARA Matches"
yaraBox.TextStyle.Fg = ui.ColorWhite
yaraBox.BorderStyle.Fg = ui.ColorCyan
extrasBox := widgets.NewParagraph()
extrasBox.SetRect(125, 23, 150, 36)
extrasBox.Title = "Extras"
extrasBox.TextStyle.Fg = ui.ColorWhite
extrasBox.BorderStyle.Fg = ui.ColorCyan
fileHeaderBox := widgets.NewParagraph()
fileHeaderBox.SetRect(0, 36, 50, 47)
fileHeaderBox.Title = "Executable Header"
fileHeaderBox.TextStyle.Fg = ui.ColorWhite
fileHeaderBox.BorderStyle.Fg = ui.ColorCyan
//var impList []string
//var symList []elf.ImportedSymbol
//impList, symList = elfAnalysis()
importsBox := widgets.NewList()
importsBox.SetRect(50, 36, 100, 47)
importsBox.Title = "Imports"
//importsBox.Rows = impList
importsBox.TextStyle.Fg = ui.ColorWhite
importsBox.BorderStyle.Fg = ui.ColorCyan
symbolsBox := widgets.NewList()
symbolsBox.SetRect(100, 36, 150, 47)
symbolsBox.Title = "Symbols"
//symbolsBox.Rows =
symbolsBox.TextStyle.Fg = ui.ColorWhite
symbolsBox.BorderStyle.Fg = ui.ColorCyan
cmdBox := widgets.NewParagraph()
cmdBox.SetRect(0, 47, 150, 50)
cmdBox.Title = "Commandline"
cmdBox.Text = ": "
cmdBox.TextStyle.Fg = ui.ColorWhite
cmdBox.BorderStyle.Fg = ui.ColorCyan
honk := widgets.NewParagraph()
honk.SetRect(0, 0, 150, 50)
honk.Title = "InMediasREs - Honk!"
honk.Text = "Press ESC to quit\n\n\n\n\n\n\n\n\n\n\n\n\n _...--.\n"
honk.Text += " _____......----' .'\n"
honk.Text += " _..-'' .'\n"
honk.Text += " .' ./\n"
honk.Text += " _.--._.' .' |\n"
honk.Text += " .-' .-.' /\n"
honk.Text += " .' _.-. . \\ ' \n"
honk.Text += " .' .' .' _ .-. / `./ : _ _ ___ _ _ _ __\n"
honk.Text += " .' .' .' _ .-. / `./ : | || |/ _ \\| \\| | |/ /\n"
honk.Text += " .' .' .' _ .-. / `./ : | __ | (_) | .` | ' < \n"
honk.Text += " .' .' .' .--' `. | \\ |`. | .' |_||_|\\___/|_|\\_|_|\\_\\ \n"
honk.Text += " _.' .' .' `.' `-' \\ / |.' .'\n"
honk.Text += " _.' .-' .' `-. ` .'\n"
honk.Text += " .' .' .' `-.._ _ _ _ .-. :\n"
honk.Text += " / /o _.-' .--' .' \\ |\n"
honk.Text += " .'-.__..-' /.. .` / .'\n"
honk.Text += " .' . ' /.'/.' / |\n"
honk.Text += " `---' _.' '\n"
honk.Text += " /.' .'\n"
honk.Text += " /.'/.'\n"
honk.TextStyle.Fg = ui.ColorCyan
honk.BorderStyle.Fg = ui.ColorCyan
//Render Boxes
ui.Render(headerBox, hashBox, fileInfoBox, sectionBox, stringsBox, urlBox, entropyBox, sandBox, yaraBox, fileHeaderBox, importsBox, symbolsBox, extrasBox, cmdBox)
tickerCount := 1
tickerCount++
uiEvents := ui.PollEvents()
ticker := time.NewTicker(time.Second).C
for {
select {
case e := <-uiEvents:
switch e.ID {
case "<C-q>":
return
case "<Escape>":
ui.Render(headerBox, hashBox, fileInfoBox, sectionBox, stringsBox, urlBox, entropyBox, sandBox, yaraBox, fileHeaderBox, importsBox, symbolsBox, extrasBox, cmdBox)
case "<Space>":
cmdBox.Text += " "
ui.Render(cmdBox)
case "<Backspace>":
sz := len(cmdBox.Text)
if sz > 2 {
cmdBox.Text = cmdBox.Text[:sz-1]
}
ui.Render(cmdBox)
case "<Enter>":
processCommand(cmdBox.Text, sha256hash, honk)
cmdBox.Text = ": "
ui.Render(cmdBox)
case "<MouseLeft>":
case "<MouseRelease>":
case "<MouseRight>":
case "<MouseMiddle>":
case "<MouseWheelUp>":
case "<MouseWheelDown>":
default:
cmdBox.Text += e.ID
ui.Render(cmdBox)
}
case <-ticker:
tickerCount++
}
}
}