-
Notifications
You must be signed in to change notification settings - Fork 125
Expand file tree
/
Copy pathRakefile
More file actions
164 lines (147 loc) · 5.92 KB
/
Copy pathRakefile
File metadata and controls
164 lines (147 loc) · 5.92 KB
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
require 'resque/tasks'
require './jobs/jobq.rb'
require 'rake/testtask'
require 'data_mapper'
Rake::TestTask.new do |t|
#ENV['RACK_ENV'] = 'test'
t.pattern = "tests/*_spec.rb"
t.verbose
end
desc 'Setup test database'
namespace :db do
desc 'create, setup schema, and load defaults into db. do this on clean install'
task :setup => [:create, :upgrade, :provision_defaults]
desc 'create and setup schema'
task :clean => [:create, :upgrade]
desc 'destroy db, create db, setup schema, load defaults'
task :reset => [:destroy, :create, :upgrade, :provision_defaults]
desc 'destroy db, create db, setup schema'
task :reset_clean => [:destroy, :create, :upgrade]
task :create do
if ENV['RACK_ENV'].nil?
ENV['RACK_ENV'] = 'development'
end
puts "setting up database for environment: #{ENV['RACK_ENV']}"
config = YAML.load_file('config/database.yml')
config = config[ENV['RACK_ENV']]
user, password, host = config['user'], config['password'], config['hostname']
database = config['database']
charset = config['charset'] || ENV['CHARSET'] || 'utf8'
collation = config['collation'] || ENV['COLLATION'] || 'utf8_unicode_ci'
# create database in mysql for datamapper
query = [
'mysql', "--user=#{user}", "--password='#{password}'", "--host=#{host} -e", "CREATE DATABASE #{database} DEFAULT CHARACTER SET #{charset} DEFAULT COLLATE #{collation}".inspect
]
begin
system(query.compact.join(' '))
rescue
raise 'Something went wrong. double check your config/database.yml file and manually test access to mysql.'
end
end
task :destroy do
if ENV['RACK_ENV'].nil?
ENV['RACK_ENV'] = 'development'
end
puts "destroying database for environment: #{ENV['RACK_ENV']}"
config = YAML.load_file('config/database.yml')
config = config[ENV['RACK_ENV']]
user, password, host = config['user'], config['password'], config['hostname']
database = config['database']
charset = config['charset'] || ENV['CHARSET'] || 'utf8'
collation = config['collation'] || ENV['COLLATION'] || 'utf8_unicode_ci'
# destroy database in mysql for datamapper
query = [
'mysql', "--user=#{user}", "--password='#{password}'", "--host=#{host} -e", "DROP DATABASE #{database}".inspect
]
begin
system(query.compact.join(' '))
rescue
raise 'Something went wrong. double check your config/database.yml file and manually test access to mysql.'
end
end
task :provision_defaults do
config = YAML.load_file('config/database.yml')
config = config[ENV['RACK_ENV']]
user, password, host = config['user'], config['password'], config['hostname']
database = config['database']
puts '[*] Setting up default settings ...'
# Create Default Settings
query = [
'mysql', "--user=#{user}", "--password='#{password}'", "--host=#{host}", "--database=#{database}", "-e INSERT INTO settings (maxtasktime) VALUES ('68400')".inspect
]
begin
system(query.compact.join(' '))
rescue
raise 'Error in creating default settings'
end
puts '[*] Setting up default customer ...'
# Create Default customer
query = [
'mysql', "--user=#{user}", "--password='#{password}'", "--host=#{host}", "--database=#{database}", "-e INSERT INTO customers (name, description) VALUES ('Acme Corp', 'Default Customer')".inspect
]
begin
system(query.compact.join(' '))
rescue
raise 'Error in creating default customer'
end
system('gunzip -k control/wordlists/password.gz')
puts '[*] Settings up default wordlist ...'
# Create Default Wordlist
query = [
'mysql', "--user=#{user}", "--password='#{password}'", "--host=#{host}", "--database=#{database}", "-e INSERT INTO wordlists (name, path, size) VALUES ('DEFAULT WORDLIST', 'control/wordlists/password', '3546')".inspect
]
begin
system(query.compact.join(' '))
rescue
raise 'Error in creating default wordlist'
end
# Create Default Task Dictionary
puts '[*] Setting up default dictionary'
query = [
'mysql', "--user=#{user}", "--password='#{password}'", "--host=#{host}", "--database=#{database}", "-e INSERT INTO tasks (name, wl_id, hc_attackmode, hc_rule) VALUES ('Basic Dictionary', '1', 'dictionary', 'none')".inspect
]
begin
system(query.compact.join(" "))
rescue
raise 'Error in creating default dictionary task'
end
# Create Default Dictionary + Rule Task
puts '[*] Setting up default dictionary + rule task'
query = [
'mysql', "--user=#{user}", "--password='#{password}'", "--host=#{host}", "--database=#{database}", "-e INSERT INTO tasks (name, wl_id, hc_attackmode, hc_rule) VALUES ('Basic Dictionary + Best64 Rules', '1', 'dictionary', 'best64.rule')".inspect
]
begin
system(query.compact.join(' '))
rescue
raise 'Error in creating default dictionary task + rule'
end
# Create Default Mask task
puts '[*] Setting up default mask task'
query = [
'mysql', "--user=#{user}", "--password='#{password}'", "--host=#{host}", "--database=#{database}", "-e INSERT INTO tasks (name, hc_attackmode, hc_mask) VALUES ('Lower Alpha 7char', 'maskmode', '?l?l?l?l?l?l?l')".inspect
]
begin
system(query.compact.join(' '))
rescue
raise 'Error in creating default mask task'
end
# Create Default Raw Brute
puts '[*] Setting up default bute task'
query = [
'mysql', "--user=#{user}", "--password='#{password}'", "--host=#{host}", "--database=#{database}", "-e INSERT INTO tasks (name, hc_attackmode) VALUES ('Raw Brute', 'bruteforce')".inspect
]
begin
system(query.compact.join(' '))
rescue
raise 'Error in creating default bute taski'
end
end
desc 'Perform non destructive auto migration'
task :upgrade do
if ENV['RACK_ENV'].nil?
ENV['RACK_ENV'] = 'development'
end
DataMapper.repository.auto_upgrade!
puts "db:auto:upgrade executed"
end
end