forked from wolfvan/YaraRET
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
185 lines (140 loc) · 5.69 KB
/
main.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
/*
Open Source Initiative OSI - The MIT License (MIT):Licensing
The MIT License (MIT)
Copyright (c) 2013 DutchCoders <http://github.com/dutchcoders/>
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package main
import (
"fmt"
"log"
"os"
docopt "github.com/docopt/docopt-go"
)
var rawdisk string
var totIndex string
var verbose bool
var OutputFile = ""
var vtiAPI = ""
var historyFile = ""
var totrawdisk string
var footersupport []string
var headersupport []string
var maxSizeDump = "50000"
var maxsize string
var filetype string
var dataSelected string
var xor bool
var workspace string
var supported = []string{"threegp","sevenzip","amazonkindleupdate","appleworks5","appleworks6","avi","bmp","bzip","canonraw","crx","dalvik","dat","dba","deb","dmg","doc","elf64","flac","flash","gif","gzip","is","javaclass","jpg","kodakcineon","macho","microsoftOffice","midi","mkv","mp3","mpeg","ost","pcap","pcapng","pdf","pe","png","pds","pst","pyc","rar","rpm","rtf","tape","tar","tarzip","tiff","utf8","vmdk","wasm","wav","woff","xar","xml","xz","zip","zlib"}
var hashlist []string
type newResult1 struct {
Rule string
}
var resultsMagicINIT []result
type ioc struct {
rule string
Data string
OffsetHeader uint64
match bool
indexMatch int
domain bool
}
type ssdeepSlice struct {
Name string
Ssdeep string
}
type stats struct {
rule string
total int
}
type unMarshal struct {
newresult newResult
}
var Footer string
var sliceIOC []ioc
var sliceIOCmatched []ioc
type newResult struct {
Rule string `json:"Rule"`
OffsetHeader uint64 `json:"OffsetHeader"`
OffsetFooter uint64 `json:"OffsetFooter"`
Data []byte `json:"Data"`
Yara []string `json:"Yara"`
Ioc string `json:"Ioc"`
Index int `json:"Index"`
Ssdeep string `json:"Ssdeep"`
Hash string `json:"Hash"`
Size uint64 `json:"Size"`
Comment string `json:"Comment"`
Tag string `json:"Tag"`
Entropy int64 `json:"Entropy"`
}
var sliceNewResults []newResult
var sliceSet []newResult
var magicPath string = "./magicrules/"
func main() {
usage := `YaraRET - Carving binaries with Yara & Radare.
Usage:
yararet rawdisk <rawdisk> yarafile <yarafile> maxsize <maxsize>
yararet rawdisk <rawdisk> ioc <ioc>
yararet rawdisk <rawdisk> ioc <ioc> maxsize <maxsize> [ --xor]
yararet rawdisk <rawdisk> hash <hash> filetype <filetype> [ --sections ] [ --vti ]
yararet rawdisk <rawdisk> ioc <ioc> maxsize <maxsize> filetype <filetype> [ --xor]
yararet -h | --help
yararet rawdisk <rawdisk> shell
yararet --version
Options:
-h --help Show this screen.
-s --shell Runs interactive shell
`
version := "1.0"
arguments, _ := docopt.Parse(usage, nil, true, version, false)
totrawdisk = arguments["<rawdisk>"].(string)
fmt.Println("\n\n██╗ ██╗ █████╗ ██████╗ █████╗ ██████╗ ███████╗████████╗\n╚██╗ ██╔╝██╔══██╗██╔══██╗██╔══██╗██╔══██╗██╔════╝╚══██╔══╝\n ╚████╔╝ ███████║██████╔╝███████║██████╔╝█████╗ ██║ \n ╚██╔╝ ██╔══██║██╔══██╗██╔══██║██╔══██╗██╔══╝ ██║ \n ██║ ██║ ██║██║ ██║██║ ██║██║ ██║███████╗ ██║ \n ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ ╚═╝\n\n")
dir, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
workspace = dir
if arguments["shell"].(bool) {
rawdisk := arguments["<rawdisk>"].(string)
runShell(rawdisk)
}
if arguments["hash"].(bool) {
rawdisk := arguments["<rawdisk>"].(string)
filetype = arguments["<filetype>"].(string)
hashes := arguments["<hash>"].(string)
runHash(rawdisk, filetype, hashes)
}
if arguments["ioc"].(bool) {
rawdisk := arguments["<rawdisk>"].(string)
maxsize = arguments["<maxsize>"].(string)
ioc := arguments["<ioc>"].(string)
//filetype = arguments["<filetype>"].(string)
xor = arguments["--xor"].(bool)
filetype := "pyc"
searchOpenIOCCmd(rawdisk, ioc, maxsize, filetype)
}
if arguments["yarafile"].(bool) {
rawdisk := arguments["<rawdisk>"].(string)
yarafile := arguments["<yarafile>"].(string)
maxsize = arguments["<maxsize>"].(string)
//filetype = arguments["<filetype>"].(string)
//filetype = arguments["<filetype>"].(string)
extractFromYara(rawdisk, yarafile, maxsize, filetype)
}
}