xanthus 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/xanthus.rb +1 -0
- data/lib/xanthus/configuration.rb +3 -0
- data/lib/xanthus/init.rb +1 -1
- data/lib/xanthus/job.rb +36 -20
- data/lib/xanthus/script.rb +31 -0
- data/lib/xanthus/version.rb +1 -1
- data/lib/xanthus/virtual_machine.rb +42 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b32bb667df960d2a565943f27d57c28462cfc37e6ffd8e56f1fddb817afa828
|
4
|
+
data.tar.gz: 772ac67b093aae2ee190481888405b97f08639494a86266c4017750b0da89fcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2f02645f8141275b74adf7b1b70c3a36609fc9172be148a949ed1b0c1acb18bec134eb13e9ed7717cf098f6fda40289a82b38066f650d49c0c2abcaac56a924
|
7
|
+
data.tar.gz: 379c8d188ac86ee7abf532ef43f05458f541033abe4d97a4087c5026a72c01dd1c0db5da1b03bffbe0822cc9315b624db7e3dae30f654c12746851eac7c3ca6d
|
data/lib/xanthus.rb
CHANGED
@@ -61,6 +61,9 @@ Seed: #{@seed}
|
|
61
61
|
yield(config)
|
62
62
|
puts "Running experiment #{config.name} with seed #{config.seed}."
|
63
63
|
srand config.seed
|
64
|
+
config.vms.each do |k, v|
|
65
|
+
v.generate_box config
|
66
|
+
end
|
64
67
|
config.github_conf.init(config) unless config.github_conf.nil?
|
65
68
|
config.jobs.each do |name,job|
|
66
69
|
for i in 0..(job.iterations-1) do
|
data/lib/xanthus/init.rb
CHANGED
@@ -110,7 +110,7 @@ It is very cool and interesting!
|
|
110
110
|
config.job :normal_spade do |job|
|
111
111
|
job.iterations = 2
|
112
112
|
job.tasks = {spade: [:pre, :spade_start, :normal, :spade_stop, :post]}
|
113
|
-
job.outputs = {spade: {trace: '/tmp/
|
113
|
+
job.outputs = {spade: {trace: '/tmp/audit_cdm.avro'}}
|
114
114
|
end
|
115
115
|
|
116
116
|
config.job :attack_spade do |job|
|
data/lib/xanthus/job.rb
CHANGED
@@ -7,12 +7,16 @@ module Xanthus
|
|
7
7
|
attr_accessor :tasks
|
8
8
|
attr_accessor :outputs
|
9
9
|
attr_accessor :inputs
|
10
|
+
attr_accessor :pre_instructions
|
11
|
+
attr_accessor :post_instructions
|
10
12
|
|
11
13
|
def initialize
|
12
14
|
@iterations = 0
|
13
15
|
@tasks = Hash.new
|
14
16
|
@outputs = Hash.new
|
15
17
|
@inputs = Hash.new
|
18
|
+
@pre_instructions = nil
|
19
|
+
@post_instructions = nil
|
16
20
|
end
|
17
21
|
|
18
22
|
def output_script outputs
|
@@ -25,26 +29,6 @@ module Xanthus
|
|
25
29
|
|
26
30
|
def setup_env machine, scripts, config
|
27
31
|
puts 'Setting up task on machine '+machine.to_s+'...'
|
28
|
-
script = ''
|
29
|
-
scripts.each do |t|
|
30
|
-
v = eval(config.scripts[t])
|
31
|
-
if v.kind_of?(Array)
|
32
|
-
v.each do |w|
|
33
|
-
script+=w+"\n"
|
34
|
-
end
|
35
|
-
else
|
36
|
-
script+=v
|
37
|
-
end
|
38
|
-
end
|
39
|
-
script += self.output_script(@outputs[machine]) unless @outputs[machine].nil?
|
40
|
-
|
41
|
-
script_to_clean = script
|
42
|
-
script = ''
|
43
|
-
script_to_clean.each_line do |s|
|
44
|
-
script += s.strip + "\n" unless s=="\n"
|
45
|
-
end
|
46
|
-
script = script.gsub "\n\n", "\n"
|
47
|
-
|
48
32
|
FileUtils.mkdir_p machine.to_s
|
49
33
|
Dir.chdir machine.to_s do
|
50
34
|
if !@inputs[machine].nil?
|
@@ -57,18 +41,47 @@ module Xanthus
|
|
57
41
|
File.open('Vagrantfile', 'w+') do |f|
|
58
42
|
f.write(config.vms[machine].to_vagrant)
|
59
43
|
end
|
44
|
+
script = Script.new(scripts, config).to_s
|
45
|
+
script += self.output_script(@outputs[machine]) unless @outputs[machine].nil?
|
60
46
|
File.open('provision.sh', 'w+') do |f|
|
61
47
|
f.write(script)
|
62
48
|
end
|
63
49
|
end
|
64
50
|
end
|
65
51
|
|
52
|
+
def host_scripts config
|
53
|
+
puts 'Setting up host scripts...'
|
54
|
+
if !@pre_instructions.nil?
|
55
|
+
script = Script.new(@pre_instructions, config).to_s
|
56
|
+
File.open('pre.sh', 'w+') do |f|
|
57
|
+
f.write(script)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
if !@post_instructions.nil?
|
62
|
+
script = Script.new(@post_instructions, config).to_s
|
63
|
+
File.open('post.sh', 'w+') do |f|
|
64
|
+
f.write(script)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def execute_pre_instructions
|
70
|
+
puts 'Running pre instructions...'
|
71
|
+
system('sh', './pre.sh')
|
72
|
+
end
|
73
|
+
|
66
74
|
def run machine
|
67
75
|
Dir.chdir machine.to_s do
|
68
76
|
system('vagrant', 'up')
|
69
77
|
end
|
70
78
|
end
|
71
79
|
|
80
|
+
def execute_post_instructions
|
81
|
+
puts 'Running post instructions...'
|
82
|
+
system('sh', './post.sh')
|
83
|
+
end
|
84
|
+
|
72
85
|
def halt machine
|
73
86
|
Dir.chdir machine.to_s do
|
74
87
|
system('vagrant', 'halt')
|
@@ -86,12 +99,15 @@ module Xanthus
|
|
86
99
|
puts "Running job #{name.to_s}-#{iteration.to_s}..."
|
87
100
|
FileUtils.mkdir_p 'tmp'
|
88
101
|
Dir.chdir 'tmp' do
|
102
|
+
self.host_scripts config
|
89
103
|
@tasks.each do |machine, templates|
|
90
104
|
self.setup_env machine, templates, config
|
91
105
|
end
|
106
|
+
self.execute_pre_instructions unless @pre_instructions.nil?
|
92
107
|
@tasks.each do |machine, templates|
|
93
108
|
self.run machine
|
94
109
|
end
|
110
|
+
self.execute_post_instructions unless @post_instructions.nil?
|
95
111
|
@tasks.each do |machine, templates|
|
96
112
|
self.halt machine
|
97
113
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Xanthus
|
2
|
+
class Script
|
3
|
+
attr_accessor :script
|
4
|
+
|
5
|
+
|
6
|
+
def initialize array, config
|
7
|
+
script = ''
|
8
|
+
array.each do |t|
|
9
|
+
v = eval(config.scripts[t])
|
10
|
+
if v.kind_of?(Array)
|
11
|
+
v.each do |w|
|
12
|
+
script+=w+"\n"
|
13
|
+
end
|
14
|
+
else
|
15
|
+
script+=v
|
16
|
+
end
|
17
|
+
end
|
18
|
+
script_to_clean = script
|
19
|
+
script = ''
|
20
|
+
script_to_clean.each_line do |s|
|
21
|
+
script += s.strip + "\n" unless s=="\n"
|
22
|
+
end
|
23
|
+
script = script.gsub "\n\n", "\n"
|
24
|
+
@script = script
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_s
|
28
|
+
@script
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/xanthus/version.rb
CHANGED
@@ -8,6 +8,9 @@ module Xanthus
|
|
8
8
|
attr_accessor :memory
|
9
9
|
attr_accessor :ip
|
10
10
|
attr_accessor :gui
|
11
|
+
attr_accessor :boxing
|
12
|
+
attr_accessor :ssh_username
|
13
|
+
attr_accessor :ssh_key_path
|
11
14
|
|
12
15
|
def initialize
|
13
16
|
@name = :default
|
@@ -18,15 +21,25 @@ module Xanthus
|
|
18
21
|
@cpus = 2
|
19
22
|
@cpu_cap = 70
|
20
23
|
@gui = false
|
24
|
+
@boxing = nil
|
25
|
+
@ssh_username = nil
|
26
|
+
@ssh_key_path = nil
|
21
27
|
end
|
22
28
|
|
23
29
|
def to_vagrant
|
24
|
-
%Q{
|
30
|
+
script = %Q{
|
25
31
|
Vagrant.configure(2) do |config|
|
26
32
|
config.vm.box = "#{@box}"
|
27
33
|
config.vm.box_version = "#{@version}"
|
28
34
|
config.vm.network "private_network", ip: "#{@ip}"
|
29
|
-
|
35
|
+
}
|
36
|
+
script += %Q{
|
37
|
+
config.ssh.username = "#{@ssh_username}"
|
38
|
+
} unless ssh_username.nil?
|
39
|
+
script += %Q{
|
40
|
+
config.ssh.private_key_path = "#{@ssh_key_path}"
|
41
|
+
} unless ssh_key_path.nil?
|
42
|
+
script += %Q{
|
30
43
|
config.vm.provider "virtualbox" do |vb|
|
31
44
|
vb.gui = #{@gui}
|
32
45
|
vb.memory = #{@memory}
|
@@ -37,6 +50,33 @@ Vagrant.configure(2) do |config|
|
|
37
50
|
config.vm.provision "shell", path: "provision.sh"
|
38
51
|
end
|
39
52
|
}
|
53
|
+
return script
|
54
|
+
end
|
55
|
+
|
56
|
+
def generate_box config
|
57
|
+
return unless !boxing.nil?
|
58
|
+
puts 'Generating box...'
|
59
|
+
|
60
|
+
FileUtils.mkdir_p 'boxing'
|
61
|
+
Dir.chdir 'boxing' do
|
62
|
+
File.open('Vagrantfile', 'w+') do |f|
|
63
|
+
f.write(self.to_vagrant)
|
64
|
+
end
|
65
|
+
|
66
|
+
script = Script.new(boxing, config).to_s
|
67
|
+
File.open('provision.sh', 'w+') do |f|
|
68
|
+
f.write(script)
|
69
|
+
end
|
70
|
+
|
71
|
+
system('vagrant', 'up')
|
72
|
+
system('vagrant', 'halt')
|
73
|
+
system('vagrant', 'package', '--output', "#{name}.box")
|
74
|
+
puts "#{name}.box created."
|
75
|
+
system('vagrant', 'box', 'add', '--force', "local/#{name}", "#{name}.box")
|
76
|
+
system('vagrant', 'destroy', '-f')
|
77
|
+
@box = "local/#{name}"
|
78
|
+
@version = '0'
|
79
|
+
end
|
40
80
|
end
|
41
81
|
end
|
42
82
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xanthus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Pasquier
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-03-
|
12
|
+
date: 2019-03-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- lib/xanthus/github.rb
|
57
57
|
- lib/xanthus/init.rb
|
58
58
|
- lib/xanthus/job.rb
|
59
|
+
- lib/xanthus/script.rb
|
59
60
|
- lib/xanthus/version.rb
|
60
61
|
- lib/xanthus/virtual_machine.rb
|
61
62
|
homepage: http://camflow.org
|