dorothy2 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,231 @@
1
+ # Dorothy2
2
+
3
+ A malware/botnet analysis framework written in Ruby.
4
+
5
+
6
+ ##Introduction
7
+
8
+ Dorothy2 is a framework created for mass malware analysis. Currently, it is mainly based on analyzing the network behavior of a virtual machine where a suspicious executable was executed.
9
+ However, static binary analysis and system behavior analysis will be shortly introduced in the next version.
10
+
11
+ Dorothy2 is a continuation of my degree's final project (Dorothy: inside the Storm [1] ) that I presented on Feb 2009.
12
+ The main framework's structure remained almost the same, and it has been fully detailed in my degree's final project or in this short paper [2]. More information about the whole project can be found on the Italian Honeyproject website [3].
13
+
14
+
15
+ The framework is manly composed by four big elements that can be even executed separately:
16
+
17
+ * The Dorothy analysis engine (this gem)
18
+ * The Network analysis module (included in this module, but still not working perfectly at the time of this writing)
19
+ * The Webgui (Coded in Rails by Andrea Valerio, and not yet included in this gem)
20
+ * The Java Dorothy Drone (Mainly coded by Patrizia Martemucci and Domenico Chiarito, but not part of this gem and not publicly available.)
21
+
22
+ The first three modules are (or will be soon) publicly released under GPL 2/3 license as tribute to the the Honeynet Project Alliance[4].
23
+ All the information generated by the framework - i.e. binary info, timestamps, dissected network analysis - are stored into a postgres DB (Dorothive) in order to be used for further analysis.
24
+ A no-SQL database (CouchDB) is also used to mass strore all the traffic dumps thanks to the pcapr/xtractr[5] technology.
25
+
26
+ I started to code this project in late 2009 while learning Ruby at the same time. Since then, I´ve been changing/improving it as long as my Ruby coding skills were improving. Because of that, you may find some parts of code not-really-tidy :)
27
+
28
+ [1] https://www.honeynet.it/wp-content/uploads/Dorothy/The_Dorothy_Project.pdf
29
+ [2] http://www.honeynet.it/wp-content/uploads/Dorothy/EC2ND-Dorothy.pdf
30
+ [3] http://www.honeynet.it
31
+ [4] http://www.honeynet.org
32
+ [5] https://code.google.com/p/pcapr/wiki/Xtractr
33
+
34
+ ##Requirements
35
+
36
+ >WARNING:
37
+ The current version of Dorothy only utilizes VMWare ESX5 as its Virtual Sandbox Module (VSM). Thus, the free version of ESXi is not supported due to its limitations in using the
38
+ vSphere 5 API.
39
+ However, the overall framework could be easily customized in order to use another virtualization engine. Dorothy2 is
40
+ very modular,and any customization or modification is very welcome.
41
+
42
+ Dorothy needs the following software (not expressly in the same host) in order to be executed:
43
+
44
+ * VMWare ESX >= 5.0 (tip: if you download ESXi, you can evaluate ESX for 30 days)
45
+ * Ruby 1.8.7
46
+ * Postgres >= 9.0
47
+ * At least one Windows virtual machine
48
+ * One unix-like machine dedicated to the Network Analysis Engine(NAM) (tcpdump/ssh needed)
49
+ * [pcapr-local](https://github.com/mudynamics/pcapr-local ) (only used by doroParser)
50
+ * MaxMind libraries (only used by doroParser)
51
+
52
+
53
+ ## Installation
54
+
55
+ It is recommended to follow this step2step process:
56
+
57
+ 1. Set your ESX environment
58
+ * Sample setup
59
+ 2. Install the required software
60
+ 3. Install Dorothy and libmagic libraries
61
+ 4. Start Dorothy, and configure it
62
+ 5. Use Dorothy
63
+
64
+ ### 1. Set your ESX environment
65
+ 1. Basic configuration (ssh)
66
+ * From vSphere:
67
+
68
+ Configuration->Security Profile->Services->Proprieties->SSH->Options->Start and Stop with host->Start->OK
69
+
70
+ 2. Configure two separate virtual networks, one dedicated exclusively to the SandBoxes (See Sample Setups)
71
+
72
+ 3. Configure the Windows VMs used for sandboxing
73
+
74
+ * Disable Windows firewall (preferred)
75
+ * VMWare Tools must be installed in the Windows guest system.
76
+ * Configure a static IP
77
+ * After configuring everything on the Guest OS, create a snapshot of the sandbox VM from vSphere console. Dorothy will use it when reverting the VM after a binary execution.
78
+
79
+ 3. Configure the unix VM dedicated to the NAM
80
+ * Configure the NIC on the virtual machine that will be used for the network sniffing purpose (NAM).
81
+ >The vSwitch where the vNIC resides must allow the promisc mode, to enable it from vSphere:
82
+
83
+ >Configuration->Networking->Proprieties on the vistualSwitch used for the analysis->Double click on the virtual network used for the analysis->Securiry->Tick "Promiscuous Mode", then select "Accept" from the list menu.
84
+
85
+ * Install tcpdump and sudo
86
+
87
+ #apt-get install tcpdump sudo
88
+
89
+ * Create a dedicated user for dorothy (e.g. "dorothy")
90
+
91
+ #useradd dorothy
92
+ * Add dorothy's user permission to execute/kill tcpdump to the sudoers file:
93
+
94
+ #visudo
95
+ add the following line:
96
+ dorothy ALL = NOPASSWD: /usr/sbin/tcpdump, /bin/kill
97
+
98
+ #### * Sample Setups
99
+ 1. Basic setup
100
+ > In the following example, the Dorothy gem is installed in the same host where Dorothive (the DB) resides.
101
+ > This setup is strongly recommended
102
+
103
+ >![dorothy.basicsetup](http://www.honeynet.it/wp-content/uploads/2011/04/Dorothy-Basic.pdf)
104
+
105
+ 2. Advanced setup
106
+ > This setup is recommended if Dorothy is going to be installed in a Corporate environment.
107
+ > By leveraging a private VPN, all the sandbox traffics exits from the Corporate network with an external IP addresses.
108
+
109
+ >![dorothy.basicsetup](http://www.honeynet.it/wp-content/uploads/2011/04/Setup-Advanced.pdf)
110
+
111
+ ### 2. Install the required software
112
+
113
+
114
+ 1. Install postgres
115
+
116
+ $sudo apt-get install postgresql-9.1
117
+ or
118
+
119
+ http://www.postgresql.org/download/
120
+
121
+ 2. Configure a dedicated postgres user for Dorothy (or use root user instead, up to you :)
122
+
123
+ 3. Install the following packages
124
+
125
+ $sudo apt-get install ruby1.8 rubygems postgresql-server-dev-9.1 libxml2-dev libxslt1-dev libmagic-dev
126
+
127
+ >For OSX users: all the above software are available through mac ports. A tip for libmagic: use brew instead:
128
+ >
129
+ $ brew install libmagic
130
+ $ brew link libmagic
131
+
132
+ Add a user dedicated to dorothy (or use the root one, up to you :)
133
+
134
+ ### 3. Install Dorothy gem
135
+
136
+ *Install Dorothy gem
137
+
138
+ $ sudo gem install dorothy2
139
+
140
+ ### 4. Start Dorothy, and configure it!
141
+
142
+ 0. Install MaxMind libraries
143
+ * [GeoLiteCity](http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz)
144
+ * [GeoLite ASN](http://download.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz)
145
+ * Copy GeoLiteCity.dat and GeoIPASNum.dat into Dorothy's etc/geo/ folder
146
+
147
+ 1. Start Dorothy
148
+
149
+ $ dorothy_start -v
150
+ The following message should appear
151
+
152
+ [WARNING] It seems that the Dorothy configuration file is not present,
153
+ please answer to the following question in order to create it now.
154
+
155
+ 2. Follow the instruction to configure
156
+ * The environment variables (db, esx server, etc)
157
+ * The Dorothy sources (where to get new binaries)
158
+ * The ESX Virtual machines used for the analysis
159
+
160
+ The first time you execute Dorothy, it will ask you to fill those information in order to create the required configuration files into the etc/ folder. However, you are free to modify/create such files directly - configuration example files can be found there too.
161
+
162
+ ###5. Use Dorothy
163
+ 1. Copy a .exe or .bat file into $yourdorothyhome/opt/bins/manual/
164
+ 2. Execute dorothy with the malwarefolder source type (if you left the default one)
165
+
166
+ $ dorothy_start -v -s malwarefolder
167
+
168
+
169
+ ## Usage
170
+
171
+ Usage:
172
+ $./dorothy_start [options]
173
+ where [options] are:
174
+ --verbose, -v: Enable verbose mode
175
+ --infoflow, -i: Print the analysis flow
176
+ --source, -s <s>: Choose a source (from the ones defined in etc/sources.yml)
177
+ --daemon, -d: Stay in the background, by constantly pooling datasources
178
+ --SandboxUpdate, -S: Update Dorothive with the new Sandbox file
179
+ --DorothiveInit, -D: (RE)Install the Dorothy Database (Dorothive)
180
+ --help, -h: Show this message
181
+
182
+
183
+ >Example
184
+
185
+ > $dorothy_start -v -s malwarefolder
186
+ > $dorothy_stop
187
+
188
+ ###6. Debugging problems
189
+
190
+ I recognize that setting up Dorothy is not the easiest task of the world.
191
+ By considering that the whole framework consists in the union of several 3rd pats, it is very likely that one of them will fail during the process.
192
+ Below there are some tips about how understand the root-cause of your crash.
193
+
194
+ 1. Execute the Dorothy UnitTest (tc_dorothy_full.rb) that resides in its gem home directory
195
+
196
+ >Example
197
+
198
+ $cd /opt/local/lib/ruby/gems/1.8/gems/dorothy2-0.0.1/test/
199
+ $ruby tc_dorothy_full.rb
200
+
201
+ 2. Set the verbose flag (-v) while executing dorothy
202
+
203
+ > $dorothy_start -v -s malwarefolder
204
+
205
+ 3. Drop an email to info at honeynet.it with the output of your errors :)
206
+
207
+ ------------------------------------------
208
+
209
+ ## Contributing
210
+
211
+ 1. Fork it
212
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
213
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
214
+ 4. Push to the branch (`git push origin my-new-feature`)
215
+ 5. Create new Pull Request
216
+
217
+ Every contribution is more than welcome!
218
+ For any help, please don't hesitate in contacting us at :
219
+ info at honeynet.it
220
+
221
+ ## License
222
+
223
+ Dorothy is copyrighted by Marco Riccardi and is licensed under the
224
+ following GNU General Public License version 3.
225
+
226
+ GNU GENERAL PUBLIC LICENSE
227
+ Version 3, 29 June 2007
228
+
229
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
230
+ Everyone is permitted to copy and distribute verbatim copies
231
+ of this license document, but changing it is not allowed.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/dorothy_start ADDED
@@ -0,0 +1,176 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright (C) 2010-2013 marco riccardi.
4
+ # This file is part of Dorothy - http://www.honeynet.it/dorothy
5
+ # See the file 'LICENSE' for copying permission.
6
+
7
+ require 'rubygems'
8
+ require 'trollop'
9
+ require 'dorothy2' #comment for testing/developmnet
10
+
11
+ #load '../lib/dorothy2.rb' #uncomment for testing/developmnet
12
+
13
+ include Dorothy
14
+
15
+
16
+ opts = Trollop.options do
17
+ banner <<-EOS
18
+
19
+ ####################################################
20
+ ## ##
21
+ ## The Dorothy Malware Analysis Framework 2.0 ##
22
+ ## ##
23
+ ####################################################
24
+
25
+ marco.riccardi@honeynet.it
26
+ www.honeynet.it/dorothy
27
+
28
+
29
+ Usage:
30
+ dorothy_start [options]
31
+ where [options] are:
32
+ EOS
33
+
34
+
35
+ opt :verbose, "Enable verbose mode"
36
+ opt :infoflow, "Print the analysis flow"
37
+ opt :source, "Choose a source (from the ones defined in etc/sources.yml)", :type => :string
38
+ opt :daemon, "Stay in the backround, by constantly pooling datasources"
39
+ opt :SandboxUpdate, "Update Dorothive with the new Sandbox file"
40
+ opt :DorothiveInit, "(RE)Install the Dorothy Database (Dorothive)"
41
+
42
+ end
43
+
44
+ if opts[:infoflow]
45
+ puts "
46
+ The Dorothy Malware Analysis Framework 2.0
47
+ ---------------Execution Flow-------------
48
+ #0) Fetch new malwares
49
+ #1) Start VM
50
+ #2) Copy File to VM
51
+ #3) Start Sniffer
52
+ #4) Execute file into VM
53
+ #5) Make screenshot
54
+ #6) Wait X minutes (configure X in the conf file)
55
+ #7) Stop Sniffer
56
+ #8) Download Screenshot and trafficdump
57
+ #9) Try to retreive malware info from VirusTotal
58
+ #10) Insert data into Dorothy-DB
59
+ ------------------------------------------
60
+ "
61
+ exit(0)
62
+ end
63
+
64
+ puts "
65
+
66
+ ####################################################
67
+ ## ##
68
+ ## The Dorothy Malware Analysis Framework 2.0 ##
69
+ ## ##
70
+ ####################################################
71
+
72
+ "
73
+
74
+ #VARS
75
+ HOME = File.expand_path("..",File.dirname(__FILE__))
76
+ VERBOSE = (opts[:verbose] ? true : false)
77
+ daemon = (opts[:daemon] ? true : false)
78
+
79
+ #DEFAULT CONF FILES
80
+ #conf = HOME + '/etc/dorothy.yml'
81
+
82
+ conf = "#{File.expand_path("~")}/.dorothy.yml"
83
+
84
+ #LOAD ENV
85
+ if Util.exists?(conf)
86
+ DoroSettings.load!(conf)
87
+ else
88
+ DoroConfig.create
89
+ exit(0)
90
+ end
91
+
92
+ #Logging
93
+ logout = (daemon ? DoroSettings.env[:logfile] : STDOUT)
94
+ LOGGER = DoroLogger.new(logout, DoroSettings.env[:logage])
95
+ LOGGER.sev_threshold = DoroSettings.env[:loglevel]
96
+
97
+ home = DoroSettings.env[:home]
98
+ #check homefolder
99
+ unless Util.exists?(home)
100
+ DoroConfig.init_home(home)
101
+ end
102
+
103
+ sfile = home + '/etc/sources.yml'
104
+ sboxfile = home + '/etc/sandboxes.yml'
105
+
106
+ #INIT DB Connector
107
+ begin
108
+ db = Insertdb.new
109
+ rescue => e
110
+ if e.inspect =~ /exist/
111
+ puts "WARNING".yellow + " The database doesn't exist yet. Press Enter to load the ddl into the DB"
112
+ gets
113
+ Util.init_db(true)
114
+ exit(0)
115
+ else
116
+ puts "ERROR".red + " Can't connect to the database"
117
+ puts e
118
+ exit(0)
119
+ end
120
+ end
121
+
122
+
123
+ if opts[:DorothiveInit]
124
+ Util.init_db
125
+ exit(0)
126
+ end
127
+
128
+ if opts[:SandboxUpdate]
129
+ puts "[Dorothy]".yellow + " Loading #{sboxfile} into Dorothive"
130
+ DoroConfig.init_sandbox(sboxfile)
131
+ puts "[Dorothy]".yellow + " Done."
132
+ exit(0)
133
+ end
134
+
135
+ if Util.exists?(sfile)
136
+ sources = YAML.load_file(sfile)
137
+ #check if all the source directories exist
138
+ sources.keys.each do |s|
139
+ unless Util.exists?("#{sources[s]["localdir"]}")
140
+ LOGGER.warn "INIT", "Warning, the source's localdir #{s} doesn't exist yet, I'm going to create it"
141
+ Dir.mkdir("#{sources[s]["localdir"]}")
142
+ end
143
+ end
144
+ else
145
+ puts "[WARNING]".red + " A source file doesn't exist, please crate one into #{home}/etc. See the example file in #{HOME}/etc/sandboxes.yml.example"
146
+ exit(0)
147
+ end
148
+
149
+ unless Util.exists?(sboxfile)
150
+ puts "[WARNING]".red + " There is no sandbox configured yet. Please do it now."
151
+ DoroConfig.create_sandbox(sboxfile)
152
+ DoroConfig.init_sandbox(sboxfile)
153
+ end
154
+
155
+ #Check DB sandbox data
156
+ if db.table_empty?("sandboxes")
157
+ puts "[WARNING]".red + " No sandbox found in Dorothive, the DB will be filled with " + sboxfile
158
+ DoroConfig.init_sandbox(sboxfile)
159
+ end
160
+
161
+ if opts[:source] && !sources.key?(opts[:source])
162
+ puts "[WARNING]".red + " The selected source is not yet configured.\nThe available sources are: "
163
+ puts sources.keys
164
+ exit(0)
165
+ end
166
+
167
+ db.close
168
+
169
+ begin
170
+ Dorothy.start sources[opts[:source]], daemon
171
+ rescue => e
172
+ LOGGER.error "Dorothy", "An error occurred: " + $!
173
+ LOGGER.debug "Dorothy", "#{e.inspect} --BACKTRACE: #{e.backtrace}"
174
+ LOGGER.error "Dorothy", "Dorothy has been stopped"
175
+ end
176
+
data/bin/dorothy_stop ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright (C) 2013 marco riccardi.
4
+ # This file is part of Dorothy - http://www.honeynet.it/dorothy
5
+ # See the file 'LICENSE' for copying permission.
6
+
7
+
8
+
9
+ require 'rubygems'
10
+ require 'trollop'
11
+ require 'dorothy2'
12
+
13
+ #load '../lib/dorothy2.rb'
14
+
15
+ include Dorothy
16
+
17
+ conf = "#{File.expand_path("~")}/.dorothy.yml"
18
+ DoroSettings.load!(conf)
19
+
20
+ #Logging
21
+
22
+ LOGGER = DoroLogger.new(DoroSettings.env[:logfile], DoroSettings.env[:logage])
23
+ LOGGER.sev_threshold = DoroSettings.env[:loglevel]
24
+
25
+
26
+ Dorothy.stop
27
+
28
+
data/bin/dparser_start ADDED
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright (C) 2013 marco riccardi.
4
+ # This file is part of Dorothy - http://www.honeynet.it/dorothy
5
+ # See the file 'LICENSE' for copying permission.
6
+
7
+ require 'rubygems'
8
+ require 'trollop'
9
+ require 'dorothy2'
10
+ require 'doroParser'
11
+
12
+ load '../lib/doroParser'
13
+
14
+ include DoroParser
15
+
16
+
17
+
18
+ opts = Trollop.options do
19
+ banner <<-EOS
20
+
21
+ The Dorothy Malware Analysis Framework 2.0
22
+
23
+ www.honeynet.it
24
+
25
+ Usage:
26
+ "do-dissector.rb" [options]
27
+ where [options] are:
28
+ EOS
29
+
30
+
31
+ opt :verbose, "Enable verbose mode"
32
+ opt :nonetbios, "Hide Netbios communication"
33
+ opt :daemon, "Stay in the backroud, by constantly pooling datasources"
34
+
35
+ end
36
+
37
+ def get_time
38
+ time = Time.new
39
+ return time.utc.strftime("%Y-%m-%d %H:%M:%S")
40
+ end
41
+
42
+
43
+ NONETBIOS = opts[:nonetbios] ? true : false
44
+ VERBOSE = opts[:verbose] ? true : false
45
+ daemon = opts[:daemon] ? true : false
46
+
47
+
48
+ conf = "#{File.expand_path("~")}/.dorothy.yml"
49
+ DoroSettings.load!(conf)
50
+
51
+ #Logging
52
+ logout = (daemon ? DoroSettings.env[:logfile_parser] : STDOUT)
53
+ LOGGER = DoroLogger.new(logout, DoroSettings.env[:logage])
54
+ LOGGER.sev_threshold = DoroSettings.env[:loglevel]
55
+
56
+ begin
57
+ DoroParser.start daemon
58
+ rescue => e
59
+ LOGGER.error "Parser", "An error occurred: " + $!
60
+ LOGGER.debug "Parser", "#{e.inspect} --BACKTRACE: #{e.backtrace}"
61
+ LOGGER.error "Parser", "Dorothy-Parser has been stopped"
62
+ end
63
+
64
+
65
+
66
+
data/bin/dparser_stop ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright (C) 2013 marco riccardi.
4
+ # This file is part of Dorothy - http://www.honeynet.it/dorothy
5
+ # See the file 'LICENSE' for copying permission.
6
+
7
+
8
+ require 'rubygems'
9
+ require 'trollop'
10
+ require 'dorothy2'
11
+ require 'doroParser'
12
+
13
+ #load '../lib/doroParser'
14
+
15
+ include DoroParser
16
+
17
+
18
+ #Logging
19
+ LOGGER_PARSER = DoroLogger.new(LOGFILE_PARSER, LOGAGE)
20
+ LOGGER_PARSER.sev_threshold = LOGLEVEL
21
+
22
+ DoroParser.stop
23
+
data/dorothy2.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dorothy2/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "dorothy2"
8
+ gem.version = Dorothy2::VERSION
9
+ gem.authors = ["marco riccardi"]
10
+ gem.email = ["marco.riccardi@honeynet.it"]
11
+ gem.description = %q{A malware/botnet analysis framework written in Ruby.}
12
+ gem.summary = %q{More info at http://www.honeynet.it}
13
+ gem.homepage = "https://github.com/m4rco-/dorothy2"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.add_dependency(%q<net-scp>, [">= 1.0.4"])
20
+ gem.add_dependency(%q<net-ssh>, [">= 2.2.1"])
21
+ gem.add_dependency(%q<trollop>, [">= 1.16.2"])
22
+ gem.add_dependency(%q<rest-client>, [">= 1.6.1"])
23
+ gem.add_dependency(%q<mime-types>, [">= 1.16"])
24
+ gem.add_dependency(%q<colored>, [">= 1.2"])
25
+ gem.add_dependency(%q<ruby-pg>, [">= 0.7.9.2008.01.28"])
26
+ gem.add_dependency(%q<virustotal>, [">= 2.0.0"])
27
+ gem.add_dependency(%q<rbvmomi>, [">= 1.3.0"])
28
+ gem.add_dependency(%q<ruby-filemagic>, [">= 0.4.2"])
29
+
30
+ end