dorothy2 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,296 @@
1
+ # Copyright (C) 2010-2013 marco riccardi.
2
+ # This file is part of Dorothy - http://www.honeynet.it/dorothy
3
+ # See the file 'LICENSE' for copying permission.
4
+
5
+ module Dorothy
6
+
7
+ module DoroConfig
8
+
9
+ extend self
10
+
11
+ def init_home(home)
12
+ puts "INIT".yellow + " Creating Directoy structure in #{home}"
13
+ Dir.mkdir(home)
14
+ unless Util.exists?("#{home}/opt")
15
+ Dir.mkdir("#{home}/opt")
16
+ Dir.mkdir("#{home}/opt/bins")
17
+ Dir.mkdir("#{home}/opt/analyzed")
18
+ end
19
+ unless Util.exists?("#{home}/etc")
20
+ Dir.mkdir("#{home}/etc")
21
+ Dir.mkdir("#{home}/etc/geo")
22
+ end
23
+ unless Util.exists?("#{home}/var")
24
+ Dir.mkdir("#{home}/var")
25
+ Dir.mkdir("#{home}/var/log")
26
+ end
27
+ puts "INIT".yellow + " Done"
28
+ end
29
+
30
+ def create
31
+
32
+ puts "
33
+ [WARNING]".red + " It seems that the Dorothy configuration file is not present,
34
+ please answer to the following question in order to create it now.
35
+ "
36
+
37
+ correct = false
38
+
39
+ until correct
40
+
41
+ conf = Hash.new
42
+ conf["sandbox"] = Hash.new
43
+ conf["env"] = Hash.new
44
+ conf["dorothive"] = Hash.new
45
+ conf["nam"] = Hash.new
46
+ conf["virustotal"] = Hash.new
47
+ conf["esx"] = Hash.new
48
+
49
+
50
+ ################################################
51
+ ###DOROTHY ENVIRONMENT
52
+ ################################################
53
+
54
+ puts "\n######### [" + " Dorothy Environment settings ".red + "] #########"
55
+
56
+ puts "Please insert the home folder for dorothy [#{HOME}]"
57
+ conf["env"]["home"] = (t = gets.chop).empty? ? HOME : t
58
+
59
+ home = conf["env"]["home"]
60
+
61
+ unless Util.exists?(home)
62
+ self.init_home(home)
63
+ end
64
+
65
+
66
+
67
+
68
+ puts "The Dorothy home directory is #{home}"
69
+
70
+ conf["env"]["pidfile"] = "#{home}/var/dorothy.pid"
71
+ conf["env"]["pidfile_parser"] = "#{home}/var/doroParser.pid"
72
+ conf["env"]["analysis_dir"] = "#{home}/opt/analyzed" # TODO if doesn't exist, create it. -> Dir.mkdir("mynewdir")
73
+ conf["env"]["geoip"] = "#{home}/etc/geo/GeoLiteCity.dat"
74
+ conf["env"]["geoasn"] = "#{home}/etc/geo/GeoIPASNum.dat"
75
+
76
+ conf["env"]["dtimeout"] = 3600
77
+
78
+ conf["env"]["logfile"] = "#{home}/var/log/dorothy.log"
79
+ conf["env"]["logfile_parser"] = "#{home}/var/log/parser.log"
80
+ conf["env"]["loglevel"] = 0
81
+ conf["env"]["logage"] = "weekly"
82
+
83
+ conf["env"]["testmode"] = true
84
+
85
+
86
+
87
+ ######################################################
88
+ ###DOROTHIVE
89
+ ######################################################
90
+
91
+ puts "\n######### [" + " Dorothive (Dorothy DB) settings ".red + "] #########"
92
+
93
+ puts "DB hostname/IP address [localhost]:"
94
+ conf["dorothive"]["dbhost"] = (t = gets.chop).empty? ? "localhost" : t
95
+
96
+ puts "DB Name [dorothive]:"
97
+ conf["dorothive"]["dbname"] = (t = gets.chop).empty? ? "dorothive" : t
98
+
99
+ puts "DB Username [dorothy]:"
100
+ conf["dorothive"]["dbuser"] = (t = gets.chop).empty? ? "dorothy" : t
101
+
102
+ puts "DB Password"
103
+ conf["dorothive"]["dbpass"] = gets.chop
104
+
105
+ conf["dorothive"]["ddl"] = "#{HOME}/etc/ddl/dorothive.ddl"
106
+
107
+
108
+ ######################################################
109
+ ###ESX
110
+ ######################################################
111
+
112
+ puts "######### [" + " ESX Environment settings ".red + "] #########"
113
+
114
+ puts "Please insert the IP address of your ESX server"
115
+ conf["esx"]["host"] = gets.chop
116
+
117
+ puts "Please insert the ESX username"
118
+ conf["esx"]["user"] = gets.chop
119
+
120
+ puts "Please insert the ESX password"
121
+ conf["esx"]["pass"] = gets.chop
122
+
123
+ #################################################
124
+ ###SANDBOX
125
+ ################################################
126
+
127
+ puts "\n######### [" + " Sandbox configuration settings ".red + "] #########"
128
+
129
+ puts "Insert the time (seconds) that the Sandbox should be run before it's reverted [60]"
130
+ conf["sandbox"]["sleeptime"] = (t = gets.chop).empty? ? 60 : t
131
+
132
+ puts "Insert the time (seconds) when Dorothy should take the first screenshot [1]"
133
+ conf["sandbox"]["screen1time"] = (t = gets.chop).empty? ? 1 : t
134
+
135
+ puts "Insert the time (seconds) when Dorothy should take the second screenshot [15]"
136
+ conf["sandbox"]["screen2time"] = (t = gets.chop).empty? ? 15 : t
137
+
138
+ ######################################################
139
+ ###NAM
140
+ ######################################################
141
+
142
+ puts "\n######### [" + " Network Analysis Module (NAM) configuration ".red + "] #########"
143
+
144
+ puts "Please insert the information of the host that you will use for sniffing the Sandbox traffic"
145
+
146
+ puts "IP Address:"
147
+ conf["nam"]["host"] = gets.chop
148
+
149
+ puts "Network interface for the network sniffing: [eth0]"
150
+ conf["nam"]["interface"] = (t = gets.chop).empty? ? "eth0" : t
151
+
152
+ puts "Username [dorothy] :"
153
+ conf["nam"]["user"] = (t = gets.chop).empty? ? "dorothy" : t
154
+
155
+ puts "SSH Port [22] :"
156
+ conf["nam"]["port"] = (t = gets.chop).empty? ? 22 : t
157
+
158
+ puts "Password:"
159
+ conf["nam"]["pass"] = gets.chop
160
+
161
+ puts "Folder where to store PCAP files [~/pcaps]"
162
+ conf["nam"]["pcaphome"] = (t = gets.chop).empty? ? "~/pcaps" : t
163
+
164
+
165
+ ######################################################
166
+ ###VIRUS TOTAL
167
+ ######################################################
168
+
169
+ puts "\n######### [" + " Virus Total API ".red + "] #########"
170
+
171
+ puts "In order to retrieve Virus signatures, Dorothy needs to contact VirusTotal,\n please enter your VT API key here, if you don't have one yet, go here (or press enter):\nhttps://www.virustotal.com/en/#dlg-join "
172
+ conf["virustotal"]["vtapikey"] = gets.chop
173
+
174
+ puts "\n######### [" + " Configuration finished ".yellow + "] #########"
175
+ puts "Confirm? [y]"
176
+
177
+ t = gets.chop
178
+ if t.empty? || t == "y" || t == "yes"
179
+ File.open("#{File.expand_path("~")}/.dorothy.yml", 'w+') {|f| f.write(conf.to_yaml) }
180
+ FileUtils.ln_s("#{File.expand_path("~")}/.dorothy.yml", "#{home}/etc/dorothy.yml")
181
+ correct = true
182
+ puts "Configuration file has been saved in ~/.dorothy.conf and a symlink has been created in\n#{home}/etc/dorothy.yml for an easier edit. You can either modify such file directly."
183
+ puts "\n######### [" + " Now you can restart dorothy, enjoy! ".yellow + "] #########"
184
+ else
185
+ puts "Please reinsert the info"
186
+ correct = false
187
+ end
188
+
189
+ end
190
+
191
+ end
192
+
193
+ def create_sandbox(sboxfile)
194
+
195
+ correct = false
196
+
197
+ until correct
198
+
199
+ conf = Hash.new
200
+
201
+ finished = false
202
+
203
+ until finished
204
+ puts "Please insert a unique name for your Sandbox (Must be the same name of the one it has in the ESX library) e.g. WinXP1"
205
+ name = gets.chop
206
+ conf[name] = Hash.new
207
+
208
+ puts "Please insert the type of the sandbox (virtual|phisical|mobile-virtual|external) [virtual]"
209
+ conf[name]["type"] = (t = gets.chop).empty? ? "virtual" : t
210
+ puts ">" + conf[name]["type"]
211
+
212
+ puts "Please insert the OS name [Windows]"
213
+ conf[name]["os"] = (t = gets.chop).empty? ? "Windows" : t
214
+ puts ">" + conf[name]["os"]
215
+
216
+ puts "Please insert the OS version [XP SP2]"
217
+ conf[name]["version"] = (t = gets.chop).empty? ? "XP SP2" : t
218
+ puts ">" + conf[name]["version"]
219
+
220
+ puts "Please insert the OS language [eng]"
221
+ conf[name]["os_lang"] = (t = gets.chop).empty? ? "eng" : t
222
+ puts ">" + conf[name]["os_lang"]
223
+
224
+ puts "Please insert the Sandbox ipaddress"
225
+ conf[name]["ipaddress"] = gets.chop
226
+ puts ">" + conf[name]["ipaddress"]
227
+
228
+
229
+ puts "Please insert the Sandbox username [administrator]"
230
+ conf[name]["username"] = (t = gets.chop).empty? ? "administrator" : t
231
+ puts ">" + conf[name]["username"]
232
+
233
+ puts "Please insert the Sandbox password"
234
+ conf[name]["password"] = gets.chop
235
+ puts ">" + conf[name]["password"]
236
+
237
+ puts "Sandbox configured. Want you to configure another one? [n]"
238
+ t = gets.chop
239
+
240
+ if t == "y" || t == "yes"
241
+ finished = false
242
+ else
243
+ finished = true
244
+ end
245
+
246
+
247
+ end
248
+
249
+ puts "Configuration finished"
250
+ puts "Confirm? [y]"
251
+ t = gets.chop
252
+ puts t
253
+
254
+ if t.empty? || t == "y" || t == "yes"
255
+ File.open(sboxfile, 'w+') {|f| f.write(conf.to_yaml) }
256
+ correct = true
257
+ puts "Configuration file has been saved in #{sboxfile}\nYou can either modify such file directly. Enjoy!"
258
+ else
259
+ puts "Please reinsert the info"
260
+ correct = false
261
+ end
262
+
263
+ end
264
+ end
265
+
266
+ #This method will populate the dorothive table sandboxes
267
+ def init_sandbox(file="../etc/sandboxes.yml")
268
+ conf = YAML.load_file(file)
269
+
270
+ db = Insertdb.new
271
+ db.begin_t
272
+
273
+ LOGGER.warn "INIT", "Waring, the SandBox table is gonna be flushed, and updated with the new file"
274
+ db.flush_table("sandboxes")
275
+
276
+ conf.each_key do |sbox|
277
+ LOGGER.info "INIT", "Inserting #{sbox}"
278
+ values = conf[sbox].values_at("type", "os", "version", "os_lang", "ipaddress", "username", "password")
279
+ values.insert(0, "default")
280
+ values.insert(1, sbox)
281
+ values.push("default")
282
+
283
+ unless db.insert("sandboxes", values) #no it isn't, insert it
284
+ LOGGER.fatal "INIT", " ERROR-DB, please redo the operation"
285
+ db.rollback
286
+ next
287
+ end
288
+ end
289
+
290
+ db.commit
291
+ db.close
292
+ LOGGER.info "INIT", "Sandboxes correctly inserted into the database"
293
+
294
+ end
295
+ end
296
+ end
@@ -0,0 +1,43 @@
1
+ # Copyright (C) 2010-2013 marco riccardi.
2
+ # This file is part of Dorothy - http://www.honeynet.it/dorothy
3
+ # See the file 'LICENSE' for copying permission.
4
+
5
+ module Dorothy
6
+ #The original Logger has a little bug that prevent me to add the progname while using warn,error,etc methods
7
+ class DoroLogger < Logger
8
+ def initialize(logdev, shift_age = 0, shift_size = 1048576)
9
+
10
+ if logdev != STDOUT
11
+ unless Util.exists? logdev
12
+ FileUtils.touch(logdev)
13
+ end
14
+ end
15
+
16
+ super(logdev, shift_age, shift_size)
17
+ @formatter = proc do |severity, datetime, progname, msg|
18
+ "[#{datetime.strftime('%d/%m/%Y %H:%M:%S')}] #{severity =~ /ERROR|FATAL/ ? severity.red : severity} [#{progname.yellow}] #{msg}\n"
19
+ end
20
+ end
21
+
22
+ def debug(progname, text, &block)
23
+ add(DEBUG, text, progname, &block)
24
+ end
25
+
26
+ def warn(progname, text, &block)
27
+ add(WARN, text, progname, &block)
28
+ end
29
+
30
+ def error(progname, text, &block)
31
+ add(ERROR, text, progname, &block)
32
+ end
33
+
34
+ def fatal(progname, text, &block)
35
+ add(FATAL, text, progname, &block)
36
+ end
37
+
38
+ def info(progname, text, &block)
39
+ add(INFO, text, progname, &block)
40
+ end
41
+ end
42
+
43
+ end