metasploit_data_models 0.6.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (211) hide show
  1. data/.gitignore +24 -0
  2. data/.rspec +3 -0
  3. data/.simplecov +38 -0
  4. data/.yardopts +4 -0
  5. data/Gemfile +27 -0
  6. data/LICENSE +27 -0
  7. data/README.md +72 -0
  8. data/Rakefile +53 -0
  9. data/app/models/mdm/api_key.rb +20 -0
  10. data/app/models/mdm/client.rb +9 -0
  11. data/app/models/mdm/cred.rb +80 -0
  12. data/app/models/mdm/event.rb +30 -0
  13. data/app/models/mdm/exploit_attempt.rb +14 -0
  14. data/app/models/mdm/exploited_host.rb +11 -0
  15. data/app/models/mdm/host.rb +134 -0
  16. data/app/models/mdm/host_detail.rb +15 -0
  17. data/app/models/mdm/host_tag.rb +13 -0
  18. data/app/models/mdm/imported_cred.rb +10 -0
  19. data/app/models/mdm/listener.rb +24 -0
  20. data/app/models/mdm/loot.rb +63 -0
  21. data/app/models/mdm/macro.rb +20 -0
  22. data/app/models/mdm/mod_ref.rb +3 -0
  23. data/app/models/mdm/module_action.rb +24 -0
  24. data/app/models/mdm/module_arch.rb +24 -0
  25. data/app/models/mdm/module_author.rb +25 -0
  26. data/app/models/mdm/module_detail.rb +59 -0
  27. data/app/models/mdm/module_mixin.rb +24 -0
  28. data/app/models/mdm/module_platform.rb +24 -0
  29. data/app/models/mdm/module_ref.rb +24 -0
  30. data/app/models/mdm/module_target.rb +26 -0
  31. data/app/models/mdm/nexpose_console.rb +20 -0
  32. data/app/models/mdm/note.rb +49 -0
  33. data/app/models/mdm/profile.rb +9 -0
  34. data/app/models/mdm/ref.rb +14 -0
  35. data/app/models/mdm/report.rb +50 -0
  36. data/app/models/mdm/report_template.rb +27 -0
  37. data/app/models/mdm/route.rb +9 -0
  38. data/app/models/mdm/service.rb +56 -0
  39. data/app/models/mdm/session.rb +48 -0
  40. data/app/models/mdm/session_event.rb +9 -0
  41. data/app/models/mdm/tag.rb +46 -0
  42. data/app/models/mdm/task.rb +41 -0
  43. data/app/models/mdm/user.rb +25 -0
  44. data/app/models/mdm/vuln.rb +60 -0
  45. data/app/models/mdm/vuln_attempt.rb +15 -0
  46. data/app/models/mdm/vuln_detail.rb +14 -0
  47. data/app/models/mdm/vuln_ref.rb +13 -0
  48. data/app/models/mdm/web_form.rb +16 -0
  49. data/app/models/mdm/web_page.rb +16 -0
  50. data/app/models/mdm/web_site.rb +47 -0
  51. data/app/models/mdm/web_vuln.rb +190 -0
  52. data/app/models/mdm/wmap_request.rb +3 -0
  53. data/app/models/mdm/wmap_target.rb +3 -0
  54. data/app/models/mdm/workspace.rb +196 -0
  55. data/bin/mdm_console +68 -0
  56. data/console_db.yml +9 -0
  57. data/db/migrate/000_create_tables.rb +79 -0
  58. data/db/migrate/001_add_wmap_tables.rb +35 -0
  59. data/db/migrate/002_add_workspaces.rb +36 -0
  60. data/db/migrate/003_move_notes.rb +20 -0
  61. data/db/migrate/004_add_events_table.rb +16 -0
  62. data/db/migrate/005_expand_info.rb +58 -0
  63. data/db/migrate/006_add_timestamps.rb +26 -0
  64. data/db/migrate/007_add_loots.rb +20 -0
  65. data/db/migrate/008_create_users.rb +16 -0
  66. data/db/migrate/009_add_loots_ctype.rb +10 -0
  67. data/db/migrate/010_add_alert_fields.rb +16 -0
  68. data/db/migrate/011_add_reports.rb +19 -0
  69. data/db/migrate/012_add_tasks.rb +24 -0
  70. data/db/migrate/013_add_tasks_result.rb +10 -0
  71. data/db/migrate/014_add_loots_fields.rb +12 -0
  72. data/db/migrate/015_rename_user.rb +16 -0
  73. data/db/migrate/016_add_host_purpose.rb +10 -0
  74. data/db/migrate/017_expand_info2.rb +58 -0
  75. data/db/migrate/018_add_workspace_user_info.rb +29 -0
  76. data/db/migrate/019_add_workspace_desc.rb +23 -0
  77. data/db/migrate/020_add_user_preferences.rb +11 -0
  78. data/db/migrate/021_standardize_info_and_data.rb +18 -0
  79. data/db/migrate/022_enlarge_event_info.rb +10 -0
  80. data/db/migrate/023_add_report_downloaded_at.rb +10 -0
  81. data/db/migrate/024_convert_service_info_to_text.rb +12 -0
  82. data/db/migrate/025_add_user_admin.rb +19 -0
  83. data/db/migrate/026_add_creds_table.rb +19 -0
  84. data/db/migrate/20100819123300_migrate_cred_data.rb +154 -0
  85. data/db/migrate/20100824151500_add_exploited_table.rb +16 -0
  86. data/db/migrate/20100908001428_add_owner_to_workspaces.rb +9 -0
  87. data/db/migrate/20100911122000_add_report_templates.rb +18 -0
  88. data/db/migrate/20100916151530_require_admin_flag.rb +15 -0
  89. data/db/migrate/20100916175000_add_campaigns_and_templates.rb +61 -0
  90. data/db/migrate/20100920012100_add_generate_exe_column.rb +8 -0
  91. data/db/migrate/20100926214000_add_template_prefs.rb +11 -0
  92. data/db/migrate/20101001000000_add_web_tables.rb +57 -0
  93. data/db/migrate/20101002000000_add_query.rb +10 -0
  94. data/db/migrate/20101007000000_add_vuln_info.rb +15 -0
  95. data/db/migrate/20101008111800_add_clients_to_campaigns.rb +10 -0
  96. data/db/migrate/20101009023300_add_campaign_attachments.rb +15 -0
  97. data/db/migrate/20101104135100_add_imported_creds.rb +17 -0
  98. data/db/migrate/20101203000000_fix_web_tables.rb +34 -0
  99. data/db/migrate/20101203000001_expand_host_comment.rb +12 -0
  100. data/db/migrate/20101206212033_add_limit_to_network_to_workspaces.rb +9 -0
  101. data/db/migrate/20110112154300_add_module_uuid_to_tasks.rb +9 -0
  102. data/db/migrate/20110204112800_add_host_tags.rb +28 -0
  103. data/db/migrate/20110317144932_add_session_table.rb +110 -0
  104. data/db/migrate/20110414180600_add_local_id_to_session_table.rb +11 -0
  105. data/db/migrate/20110415175705_add_routes_table.rb +18 -0
  106. data/db/migrate/20110422000000_convert_binary.rb +72 -0
  107. data/db/migrate/20110425095900_add_last_seen_to_sessions.rb +8 -0
  108. data/db/migrate/20110513143900_track_successful_exploits.rb +31 -0
  109. data/db/migrate/20110517160800_rename_and_prune_nessus_vulns.rb +26 -0
  110. data/db/migrate/20110527000000_add_task_id_to_reports_table.rb +11 -0
  111. data/db/migrate/20110527000001_add_api_keys_table.rb +12 -0
  112. data/db/migrate/20110606000001_add_macros_table.rb +16 -0
  113. data/db/migrate/20110622000000_add_settings_to_tasks_table.rb +12 -0
  114. data/db/migrate/20110624000001_add_listeners_table.rb +19 -0
  115. data/db/migrate/20110625000001_add_macro_to_listeners_table.rb +12 -0
  116. data/db/migrate/20110630000001_add_nexpose_consoles_table.rb +21 -0
  117. data/db/migrate/20110630000002_add_name_to_nexpose_consoles_table.rb +12 -0
  118. data/db/migrate/20110717000001_add_profiles_table.rb +15 -0
  119. data/db/migrate/20110727163801_expand_cred_ptype_column.rb +9 -0
  120. data/db/migrate/20110730000001_add_initial_indexes.rb +85 -0
  121. data/db/migrate/20110812000001_prune_indexes.rb +23 -0
  122. data/db/migrate/20110922000000_expand_notes.rb +9 -0
  123. data/db/migrate/20110928101300_add_mod_ref_table.rb +17 -0
  124. data/db/migrate/20111011110000_add_display_name_to_reports_table.rb +24 -0
  125. data/db/migrate/20111203000000_inet_columns.rb +13 -0
  126. data/db/migrate/20111204000000_more_inet_columns.rb +17 -0
  127. data/db/migrate/20111210000000_add_scope_to_hosts.rb +9 -0
  128. data/db/migrate/20120126110000_add_virtual_host_to_hosts.rb +9 -0
  129. data/db/migrate/20120411173220_rename_workspace_members.rb +9 -0
  130. data/db/migrate/20120601152442_add_counter_caches_to_hosts.rb +21 -0
  131. data/db/migrate/20120625000000_add_vuln_details.rb +34 -0
  132. data/db/migrate/20120625000001_add_host_details.rb +16 -0
  133. data/db/migrate/20120625000002_expand_details.rb +16 -0
  134. data/db/migrate/20120625000003_expand_details2.rb +24 -0
  135. data/db/migrate/20120625000004_add_vuln_attempts.rb +19 -0
  136. data/db/migrate/20120625000005_add_vuln_and_host_counter_caches.rb +14 -0
  137. data/db/migrate/20120625000006_add_module_details.rb +118 -0
  138. data/db/migrate/20120625000007_add_exploit_attempts.rb +26 -0
  139. data/db/migrate/20120625000008_add_fail_message.rb +12 -0
  140. data/db/migrate/20120718202805_add_owner_and_payload_to_web_vulns.rb +13 -0
  141. data/db/migrate/20130228214900_change_required_columns_to_null_false_in_web_vulns.rb +35 -0
  142. data/lib/mdm.rb +12 -0
  143. data/lib/mdm/host/operating_system_normalization.rb +984 -0
  144. data/lib/metasploit_data_models.rb +60 -0
  145. data/lib/metasploit_data_models/base64_serializer.rb +103 -0
  146. data/lib/metasploit_data_models/engine.rb +23 -0
  147. data/lib/metasploit_data_models/serialized_prefs.rb +23 -0
  148. data/lib/metasploit_data_models/validators/ip_format_validator.rb +13 -0
  149. data/lib/metasploit_data_models/validators/password_is_strong_validator.rb +70 -0
  150. data/lib/metasploit_data_models/version.rb +8 -0
  151. data/lib/tasks/yard.rake +26 -0
  152. data/metasploit_data_models.gemspec +31 -0
  153. data/script/rails +8 -0
  154. data/spec/app/models/mdm/module_action_spec.rb +38 -0
  155. data/spec/app/models/mdm/module_arch_spec.rb +38 -0
  156. data/spec/app/models/mdm/module_author_spec.rb +50 -0
  157. data/spec/app/models/mdm/module_detail_spec.rb +291 -0
  158. data/spec/app/models/mdm/module_mixin_spec.rb +38 -0
  159. data/spec/app/models/mdm/module_platform_spec.rb +38 -0
  160. data/spec/app/models/mdm/module_ref_spec.rb +38 -0
  161. data/spec/app/models/mdm/module_target_spec.rb +41 -0
  162. data/spec/app/models/mdm/web_vuln_spec.rb +126 -0
  163. data/spec/dummy/Rakefile +7 -0
  164. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  165. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  166. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  167. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  168. data/spec/dummy/app/mailers/.gitkeep +0 -0
  169. data/spec/dummy/app/models/.gitkeep +0 -0
  170. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  171. data/spec/dummy/config.ru +4 -0
  172. data/spec/dummy/config/application.rb +61 -0
  173. data/spec/dummy/config/boot.rb +10 -0
  174. data/spec/dummy/config/database.yml.example +22 -0
  175. data/spec/dummy/config/environment.rb +5 -0
  176. data/spec/dummy/config/environments/development.rb +37 -0
  177. data/spec/dummy/config/environments/production.rb +67 -0
  178. data/spec/dummy/config/environments/test.rb +37 -0
  179. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  180. data/spec/dummy/config/initializers/inflections.rb +15 -0
  181. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  182. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  183. data/spec/dummy/config/initializers/session_store.rb +8 -0
  184. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  185. data/spec/dummy/config/routes.rb +2 -0
  186. data/spec/dummy/db/schema.rb +638 -0
  187. data/spec/dummy/lib/assets/.gitkeep +0 -0
  188. data/spec/dummy/log/.gitkeep +0 -0
  189. data/spec/dummy/public/404.html +26 -0
  190. data/spec/dummy/public/422.html +26 -0
  191. data/spec/dummy/public/500.html +25 -0
  192. data/spec/dummy/public/favicon.ico +0 -0
  193. data/spec/dummy/script/rails +6 -0
  194. data/spec/factories/mdm/addresses.rb +7 -0
  195. data/spec/factories/mdm/hosts.rb +18 -0
  196. data/spec/factories/mdm/module_actions.rb +14 -0
  197. data/spec/factories/mdm/module_archs.rb +14 -0
  198. data/spec/factories/mdm/module_authors.rb +22 -0
  199. data/spec/factories/mdm/module_details.rb +9 -0
  200. data/spec/factories/mdm/module_mixins.rb +14 -0
  201. data/spec/factories/mdm/module_platforms.rb +14 -0
  202. data/spec/factories/mdm/module_refs.rb +14 -0
  203. data/spec/factories/mdm/module_targets.rb +19 -0
  204. data/spec/factories/mdm/services.rb +35 -0
  205. data/spec/factories/mdm/users.rb +22 -0
  206. data/spec/factories/mdm/web_sites.rb +8 -0
  207. data/spec/factories/mdm/web_vulns.rb +64 -0
  208. data/spec/factories/mdm/workspaces.rb +23 -0
  209. data/spec/lib/base64_serializer_spec.rb +174 -0
  210. data/spec/spec_helper.rb +36 -0
  211. metadata +433 -0
data/bin/mdm_console ADDED
@@ -0,0 +1,68 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ def mdm_banner
4
+ banner = {}
5
+ banner[:color] = "\e[34m"
6
+ banner[:text] = <<-BANNER
7
+ _______ _______________________ _______ _______ _ _______ __________________
8
+ ( ) ____ \\__ __/ ___ ) ____ \\ ____ ) \\ ( ___ )\\__ __/\\__ __/
9
+ | () () | ( \\/ ) ( | ( ) | ( \\/ ( )| ( | ( ) | ) ( ) (
10
+ | || || | (__ | | | (___) | (_____| (____)| | | | | | | | | |
11
+ | |(_)| | __) | | | ___ |_____ ) _____) | | | | | | | | |
12
+ | | | | ( | | | ( ) | ) | ( | | | | | | | | | |
13
+ | ) ( | (____/\\ | | | ) ( |\\____) | ) | (____/\\ (___) |___) (___ | |
14
+ |/ \\|_______/ )_( |/ \\|_______)/ (_______/_______)\\_______/ )_(
15
+
16
+
17
+ ______ _______________________ _______ _______ ______ _______ _ _______
18
+ ( __ \\( ___ )__ __/ ___ ) ) ___ ) __ \\( ____ \\ \\ ( ____ \\
19
+ | ( \\ ) ( ) | ) ( | ( ) | () () | ( ) | ( \\ ) ( \\/ ( | ( \\/
20
+ | | ) | (___) | | | | (___) | || || | | | | | ) | (__ | | | (_____
21
+ | | | | ___ | | | | ___ | |(_)| | | | | | | | __) | | (_____ )
22
+ | | ) | ( ) | | | | ( ) | | | | | | | | ) | ( | | ) |
23
+ | (__/ ) ) ( | | | | ) ( | ) ( | (___) | (__/ ) (____/\\ (____/Y\\____) |
24
+ (______/|/ \\| )_( |/ \\|/ \\|_______)______/(_______/_______|_______)
25
+ BANNER
26
+ banner
27
+ end
28
+
29
+ def db_info_file
30
+ hidden_file = "#{Dir.home}/.mdm.yml"
31
+ if File.readable?(hidden_file)
32
+ pro_path = YAML.load_file(hidden_file)['pro_path']
33
+ return "#{pro_path}/ui/config/database.yml"
34
+ elsif !ARGV[0].blank?
35
+ return ARGV[0]
36
+ else
37
+ warn "No YAML file of DB info available"
38
+ exit
39
+ end
40
+ end
41
+
42
+ begin
43
+ require 'pry'
44
+ require "metasploit_data_models"
45
+
46
+ # Set up a DB connection, preferring one from Pro if it's in the normal place
47
+ # Otherwise get from ARGV[0]
48
+
49
+ if File.readable?(db_info_file)
50
+ connection_info = YAML.load_file(db_info_file)
51
+ ActiveRecord::Base.establish_connection(connection_info['development'])
52
+ else
53
+ warn "Can't access DB -- check file path."
54
+ exit
55
+ end
56
+
57
+ MetasploitDataModels.require_models
58
+
59
+ puts "\n\n\n#{mdm_banner[:color]}#{mdm_banner[:text]}\e[0m\n\n\n"
60
+
61
+ Pry.config.prompt = proc { |obj, nest_level, _| "mdm:#{nest_level}> " }
62
+
63
+ Pry.start
64
+ exit
65
+ rescue LoadError
66
+ warn "Unable to load Pry"
67
+ end
68
+
data/console_db.yml ADDED
@@ -0,0 +1,9 @@
1
+ development:
2
+ adapter: postgresql
3
+ database: msf3_dev
4
+ host: localhost
5
+ port: 5432
6
+ username: msf3
7
+ password: pass123
8
+ pool: 5
9
+ timeout: 5
@@ -0,0 +1,79 @@
1
+ class CreateTables < ActiveRecord::Migration
2
+
3
+ def self.up
4
+
5
+ create_table :hosts do |t|
6
+ t.timestamp :created
7
+ t.string :address, :limit => 16 # unique
8
+ t.string :address6
9
+ t.string :mac
10
+ t.string :comm
11
+ t.string :name
12
+ t.string :state
13
+ t.string :info, :limit => 1024
14
+ t.string :os_name
15
+ t.string :os_flavor
16
+ t.string :os_sp
17
+ t.string :os_lang
18
+ t.string :arch
19
+ end
20
+
21
+ add_index :hosts, :address, :unique => true
22
+
23
+ create_table :clients do |t|
24
+ t.integer :host_id
25
+ t.timestamp :created
26
+ t.string :ua_string, :limit => 1024, :null => false
27
+ t.string :ua_name, :limit => 64
28
+ t.string :ua_ver, :limit => 32
29
+ end
30
+
31
+ create_table :services do |t|
32
+ t.integer :host_id
33
+ t.timestamp :created
34
+ t.integer :port, :null => false
35
+ t.string :proto, :limit => 16, :null => false
36
+ t.string :state
37
+ t.string :name
38
+ t.string :info, :limit => 1024
39
+ end
40
+
41
+ create_table :vulns do |t|
42
+ t.integer :host_id
43
+ t.integer :service_id
44
+ t.timestamp :created
45
+ t.string :name
46
+ t.text :data
47
+ end
48
+
49
+ create_table :refs do |t|
50
+ t.integer :ref_id
51
+ t.timestamp :created
52
+ t.string :name, :limit => 512
53
+ end
54
+
55
+ create_table :vulns_refs, :id => false do |t|
56
+ t.integer :ref_id
57
+ t.integer :vuln_id
58
+ end
59
+
60
+ create_table :notes do |t|
61
+ t.integer :host_id
62
+ t.timestamp :created
63
+ t.string :ntype, :limit => 512
64
+ t.text :data
65
+ end
66
+
67
+ end
68
+
69
+ def self.down
70
+ drop_table :hosts
71
+ drop_table :clients
72
+ drop_table :services
73
+ drop_table :vulns
74
+ drop_table :refs
75
+ drop_table :vulns_refs
76
+ drop_table :notes
77
+ end
78
+
79
+ end
@@ -0,0 +1,35 @@
1
+ class AddWmapTables < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :wmap_targets do |t|
4
+ t.string :host # vhost
5
+ t.string :address, :limit => 16 # unique
6
+ t.string :address6
7
+ t.integer :port
8
+ t.integer :ssl
9
+ t.integer :selected
10
+ end
11
+
12
+ create_table :wmap_requests do |t|
13
+ t.string :host # vhost
14
+ t.string :address, :limit => 16 # unique
15
+ t.string :address6
16
+ t.integer :port
17
+ t.integer :ssl
18
+ t.string :meth, :limit => 32
19
+ t.text :path
20
+ t.text :headers
21
+ t.text :query
22
+ t.text :body
23
+ t.string :respcode, :limit => 16
24
+ t.text :resphead
25
+ t.text :response
26
+ t.timestamp :created
27
+ end
28
+ end
29
+
30
+ def self.down
31
+ drop_table :wmap_targets
32
+ drop_table :wmap_requests
33
+ end
34
+ end
35
+
@@ -0,0 +1,36 @@
1
+ class AddWorkspaces < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ create_table :workspaces do |t|
5
+ t.string :name
6
+ t.timestamps
7
+ end
8
+
9
+ change_table :hosts do |t|
10
+ t.integer :workspace_id, :required => true
11
+ end
12
+
13
+ remove_index :hosts, :column => :address
14
+
15
+ #
16
+ # This was broken after 018_add_workspace_user_info was introduced
17
+ # because of the new boundary column. For some reason, the
18
+ # find_or_create_by_name that .default eventually calls here tries to
19
+ # create a record with the boundary field that doesn't exist yet.
20
+ # See #1724
21
+ #
22
+ #w = Msf::DBManager::Workspace.default
23
+ #Msf::DBManager::Host.update_all ["workspace_id = ?", w.id]
24
+ end
25
+
26
+ def self.down
27
+ drop_table :workspaces
28
+
29
+ change_table :hosts do |t|
30
+ t.remove :workspace_id
31
+ end
32
+
33
+ add_index :hosts, :address, :unique => true
34
+ end
35
+
36
+ end
@@ -0,0 +1,20 @@
1
+ class MoveNotes < ActiveRecord::Migration
2
+ def self.up
3
+ # Remove the host requirement. We'll add the column back in below.
4
+ remove_column :notes, :host_id
5
+ change_table :notes do |t|
6
+ t.integer :workspace_id, :null => false, :default => 1
7
+ t.integer :service_id
8
+ t.integer :host_id
9
+ end
10
+ end
11
+
12
+ def self.down
13
+ remove_column :notes, :workspace_id
14
+ remove_column :notes, :service_id
15
+ change_table :notes do |t|
16
+ t.integer :host_id, :null => false
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,16 @@
1
+ class AddEventsTable < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :events do |t|
4
+ t.integer :workspace_id
5
+ t.integer :host_id
6
+ t.timestamp :created_at
7
+ t.string :user
8
+ t.string :name
9
+ t.string :info
10
+ end
11
+ end
12
+ def self.down
13
+ drop_table :events
14
+ end
15
+ end
16
+
@@ -0,0 +1,58 @@
1
+ class ExpandInfo < ActiveRecord::Migration
2
+ def self.up
3
+ remove_column :events, :info
4
+ change_table :events do |t|
5
+ t.string :info, :limit => 4096
6
+ end
7
+
8
+ remove_column :notes, :data
9
+ change_table :notes do |t|
10
+ t.string :data, :limit => 4096
11
+ end
12
+
13
+ remove_column :vulns, :data
14
+ change_table :vulns do |t|
15
+ t.string :data, :limit => 4096
16
+ end
17
+
18
+ remove_column :hosts, :info
19
+ change_table :hosts do |t|
20
+ t.string :info, :limit => 4096
21
+ end
22
+
23
+ remove_column :services, :info
24
+ change_table :services do |t|
25
+ t.string :info, :limit => 4096
26
+ end
27
+ end
28
+
29
+ def self.down
30
+
31
+ remove_column :events, :info
32
+ change_table :events do |t|
33
+ t.string :info
34
+ end
35
+
36
+ remove_column :notes, :data
37
+ change_table :notes do |t|
38
+ t.string :data, :limit => 1024
39
+ end
40
+
41
+ remove_column :hosts, :info
42
+ change_table :hosts do |t|
43
+ t.string :info, :limit => 1024
44
+ end
45
+
46
+ remove_column :vulns, :data
47
+ change_table :hosts do |t|
48
+ t.string :data, :limit => 1024
49
+ end
50
+
51
+ remove_column :services, :info
52
+ change_table :services do |t|
53
+ t.string :info, :limit => 1024
54
+ end
55
+
56
+ end
57
+ end
58
+
@@ -0,0 +1,26 @@
1
+
2
+ # Adds 'created_at' and 'updated_at' columns to every primary table.
3
+ #
4
+ class AddTimestamps < ActiveRecord::Migration
5
+
6
+ @@TABLES_NEEDING_RENAME = [:clients, :hosts, :notes, :refs, :services, :vulns, :wmap_requests]
7
+ @@TABLES_NEEDING_CREATED_AT = [:wmap_targets]
8
+ @@TABLES_NEEDING_UPDATED_AT = [:clients, :events, :hosts, :notes, :refs, :services, :vulns, :wmap_requests, :wmap_targets]
9
+
10
+ def self.up
11
+ @@TABLES_NEEDING_RENAME.each { |t| rename_column t, :created, :created_at }
12
+
13
+ @@TABLES_NEEDING_CREATED_AT.each { |t| add_column t, :created_at, :datetime }
14
+
15
+ @@TABLES_NEEDING_UPDATED_AT.each { |t| add_column t, :updated_at, :datetime }
16
+ end
17
+
18
+ def self.down
19
+ @@TABLES_NEEDING_RENAME.each { |t| rename_column t, :created_at, :created }
20
+
21
+ @@TABLES_NEEDING_CREATED_AT.each { |t| remove_column t, :created_at }
22
+
23
+ @@TABLES_NEEDING_UPDATED_AT.each { |t| remove_column t, :updated_at }
24
+ end
25
+ end
26
+
@@ -0,0 +1,20 @@
1
+ class AddLoots < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ create_table :loots do |t|
5
+ t.integer :workspace_id, :null => false, :default => 1
6
+ t.integer :host_id
7
+ t.integer :service_id
8
+ t.string :ltype, :limit => 512
9
+ t.string :path, :limit => 1024
10
+ t.text :data
11
+ t.timestamps
12
+ end
13
+ end
14
+
15
+ def self.down
16
+ drop_table :loots
17
+ end
18
+
19
+ end
20
+
@@ -0,0 +1,16 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :users do |t|
4
+ t.string :username
5
+ t.string :crypted_password
6
+ t.string :password_salt
7
+ t.string :persistence_token
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ drop_table :users
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ class AddLootsCtype < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :loots, :content_type, :string
4
+ end
5
+
6
+ def self.down
7
+ remove_column :loots, :content_type
8
+ end
9
+ end
10
+
@@ -0,0 +1,16 @@
1
+ class AddAlertFields < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :notes, :critical, :boolean
4
+ add_column :notes, :seen, :boolean
5
+ add_column :events, :critical, :boolean
6
+ add_column :events, :seen, :boolean
7
+ end
8
+
9
+ def self.down
10
+ remove_column :notes, :critical
11
+ remove_column :notes, :seen
12
+ remove_column :events, :critical
13
+ remove_column :events, :seen
14
+ end
15
+ end
16
+
@@ -0,0 +1,19 @@
1
+ class AddReports < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ create_table :reports do |t|
5
+ t.integer :workspace_id, :null => false, :default => 1
6
+ t.string :created_by
7
+ t.string :rtype
8
+ t.string :path, :limit => 1024
9
+ t.text :options
10
+ t.timestamps
11
+ end
12
+ end
13
+
14
+ def self.down
15
+ drop_table :reports
16
+ end
17
+
18
+ end
19
+