xanthus 0.1.2 → 0.2.2
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.
- checksums.yaml +4 -4
- data/README.md +78 -13
- data/bin/xanthus +6 -6
- data/lib/xanthus.rb +3 -0
- data/lib/xanthus/configuration.rb +23 -2
- data/lib/xanthus/dataverse.rb +179 -0
- data/lib/xanthus/github.rb +4 -12
- data/lib/xanthus/init.rb +13 -4
- data/lib/xanthus/job.rb +45 -23
- data/lib/xanthus/repository.rb +28 -0
- data/lib/xanthus/script.rb +31 -0
- data/lib/xanthus/version.rb +1 -1
- data/lib/xanthus/virtual_machine.rb +77 -4
- metadata +24 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1e934c54b27464d154b647f06871839495ab2428cf02b67d8f4bd0576ea1d14
|
4
|
+
data.tar.gz: 7a2b8393da895f4245549ea4efcae28da51909eaba66063996ec4c2ceff0bc4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 450d6bdbed6611b7a05414efe5224db488106c00e1ea3c750b3ce8f33e782ad7ae7ca095454b16b3813237418e97aa0193737f8bef1129288e066b8d3dbe4d77
|
7
|
+
data.tar.gz: d4f4182433af9d21818aeddfefd0116fd383d3945902811c9627e5e923cfa2fde322ddf7bf30af4e9a4105902e35987dce5a0402f15a6a6578c8ab02b79d4ab2
|
data/README.md
CHANGED
@@ -181,12 +181,6 @@ The user must provide such a script.
|
|
181
181
|
In our case, we automatically generate attack scripts using `wget-attack-script-gen.py`.
|
182
182
|
`Xanthus` allows users to provide logic to generate scripts or simply provide scripts to run during the experiment.
|
183
183
|
|
184
|
-
## Xanthus
|
185
|
-
|
186
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/xanthus`. To experiment with that code, run `bin/console` for an interactive prompt.
|
187
|
-
|
188
|
-
TODO: Delete this and the text above, and describe your gem
|
189
|
-
|
190
184
|
### Installation
|
191
185
|
|
192
186
|
Add this line to your application's Gemfile:
|
@@ -205,18 +199,89 @@ Or install it yourself as:
|
|
205
199
|
|
206
200
|
### Usage
|
207
201
|
|
208
|
-
|
202
|
+
```
|
203
|
+
xanthus version | return Xanthus version number.
|
204
|
+
xanthus dependencies | installation instructions for system dependencies.
|
205
|
+
xanthus init <project name> | initialize a new project.
|
206
|
+
xanthus run | run .xanthus file in the current folder.
|
207
|
+
```
|
209
208
|
|
210
209
|
### Development
|
211
210
|
|
212
|
-
|
213
|
-
|
214
|
-
|
211
|
+
To add more features in `Xanthus`,
|
212
|
+
clone this repository
|
213
|
+
```
|
214
|
+
git clone https://github.com/tfjmp/xanthus
|
215
|
+
cd xanthus
|
216
|
+
```
|
217
|
+
and build the gem by running
|
218
|
+
```
|
219
|
+
gem build xanthus
|
220
|
+
```
|
221
|
+
To install this gem locally on your machine, you can also run
|
222
|
+
```
|
223
|
+
gem install xanthus
|
224
|
+
```
|
225
|
+
After you add a new feature (and test it yourself), you can release a new version of `Xanthus`.
|
226
|
+
First, please update the version number in `lib/xanthus/version.rb`, tag the repository `git tag -a x.x.x -m 'x.x.x'`, and push the tag `git push --tags`.
|
227
|
+
Then you can run
|
228
|
+
```
|
229
|
+
gem push xanthus-x.x.x.gem
|
230
|
+
```
|
231
|
+
This last step publishes the gem at [https://rubygems.org/gems/xanthus](https://rubygems.org/gems/xanthus).
|
215
232
|
|
216
|
-
###
|
233
|
+
### Contribution
|
217
234
|
|
218
|
-
|
235
|
+
We welcome bug reports and pull requests on GitHub at https://github.com/[USERNAME]/xanthus.
|
219
236
|
|
220
237
|
### License
|
221
238
|
|
222
|
-
|
239
|
+
This gem is available as an open source project under the [MIT License](https://opensource.org/licenses/MIT).
|
240
|
+
|
241
|
+
### Issues and Solutions with VirtualBox
|
242
|
+
VirtualBox Guest Additions is not as well designed as we may hope. If you encountered the following error:
|
243
|
+
```
|
244
|
+
Vagrant was unable to mount VirtualBox shared folders. This is usually
|
245
|
+
because the filesystem "vboxsf" is not available. This filesystem is
|
246
|
+
made available via the VirtualBox Guest Additions and kernel module.
|
247
|
+
Please verify that these guest additions are properly installed in the
|
248
|
+
guest. This is not a bug in Vagrant and is usually caused by a faulty
|
249
|
+
Vagrant box. For context, the command attempted was:
|
250
|
+
|
251
|
+
mount -t vboxsf -o uid=900,gid=900 vagrant /vagrant
|
252
|
+
|
253
|
+
The error output from the command was:
|
254
|
+
|
255
|
+
/sbin/mount.vboxsf: mounting failed with the error: No such device
|
256
|
+
```
|
257
|
+
It is most likely the fault of incompatible GA between the VM and the host. Even though the script might have stop, the VM is still booted. You can `vagrant ssh` into the VM and manually input the following two commands:
|
258
|
+
```
|
259
|
+
sudo apt-get -y install dkms build-essential linux-headers-$(uname -r) virtualbox-guest-additions-iso
|
260
|
+
sudo /opt/VBoxGuestAdditions*/init/vboxadd setup
|
261
|
+
```
|
262
|
+
After this, you may encounter this error:
|
263
|
+
```
|
264
|
+
...
|
265
|
+
==> default: Machine booted and ready!
|
266
|
+
[default] GuestAdditions seems to be installed (6.0.20) correctly, but not running.
|
267
|
+
bash: line 4: setup: command not found
|
268
|
+
==> default: Checking for guest additions in VM...
|
269
|
+
The following SSH command responded with a non-zero exit status.
|
270
|
+
Vagrant assumes that this means the command failed!
|
271
|
+
|
272
|
+
setup
|
273
|
+
|
274
|
+
Stdout from the command:
|
275
|
+
|
276
|
+
|
277
|
+
|
278
|
+
Stderr from the command:
|
279
|
+
|
280
|
+
bash: line 4: setup: command not found
|
281
|
+
```
|
282
|
+
Please add the following into the Vagrant script:
|
283
|
+
```
|
284
|
+
if Vagrant.has_plugin?("vagrant-vbguest")
|
285
|
+
config.vbguest.auto_update = false
|
286
|
+
end
|
287
|
+
```
|
data/bin/xanthus
CHANGED
@@ -7,17 +7,17 @@ param1 = ARGV[1]
|
|
7
7
|
|
8
8
|
if (instruction == 'version')
|
9
9
|
Xanthus.version
|
10
|
-
elsif (instruction == 'init')
|
10
|
+
elsif (instruction == 'init' && !param1.nil?)
|
11
11
|
Xanthus::Init.init param1
|
12
12
|
elsif (instruction == 'run')
|
13
13
|
load('./.xanthus')
|
14
14
|
elsif (instruction == 'help')
|
15
|
-
puts 'xanthus version | return version number.'
|
16
|
-
puts 'xanthus
|
17
|
-
puts 'xanthus init <project name> |
|
18
|
-
puts 'xanthus run | run .xanthus file
|
15
|
+
puts 'xanthus version | return Xanthus version number.'
|
16
|
+
puts 'xanthus dependencies | installation instructions for system dependencies.'
|
17
|
+
puts 'xanthus init <project name> | initialize a new project.'
|
18
|
+
puts 'xanthus run | run .xanthus file in the current folder.'
|
19
19
|
elsif (instruction == 'dependencies')
|
20
|
-
puts 'You need to install the following software on your system for
|
20
|
+
puts 'You need to install the following software on your system for Xanthus to run:'
|
21
21
|
puts 'git (see https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)'
|
22
22
|
puts 'git lfs (see https://help.github.com/en/articles/installing-git-large-file-storage)'
|
23
23
|
puts 'virtualbox (see https://www.virtualbox.org/wiki/Downloads)'
|
data/lib/xanthus.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
require "xanthus/version"
|
2
2
|
require "xanthus/init"
|
3
|
+
require "xanthus/script"
|
3
4
|
require "xanthus/virtual_machine"
|
4
5
|
require "xanthus/job"
|
5
6
|
require "xanthus/default"
|
7
|
+
require "xanthus/repository"
|
6
8
|
require "xanthus/github"
|
9
|
+
require "xanthus/dataverse"
|
7
10
|
require "xanthus/configuration"
|
8
11
|
|
9
12
|
module Xanthus
|
@@ -2,6 +2,8 @@ module Xanthus
|
|
2
2
|
class Configuration
|
3
3
|
attr_accessor :name
|
4
4
|
attr_accessor :authors
|
5
|
+
attr_accessor :affiliation
|
6
|
+
attr_accessor :email
|
5
7
|
attr_accessor :description
|
6
8
|
attr_accessor :seed
|
7
9
|
attr_accessor :params
|
@@ -9,6 +11,7 @@ module Xanthus
|
|
9
11
|
attr_accessor :scripts
|
10
12
|
attr_accessor :jobs
|
11
13
|
attr_accessor :github_conf
|
14
|
+
attr_accessor :dataverse_conf
|
12
15
|
|
13
16
|
def initialize
|
14
17
|
@params = Hash.new
|
@@ -41,13 +44,21 @@ module Xanthus
|
|
41
44
|
@github_conf = github
|
42
45
|
end
|
43
46
|
|
47
|
+
def dataverse
|
48
|
+
dataverse = Dataverse.new
|
49
|
+
yield(dataverse)
|
50
|
+
@dataverse_conf = dataverse
|
51
|
+
end
|
52
|
+
|
44
53
|
def to_readme_md
|
45
54
|
%Q{
|
46
55
|
# #{@name}
|
47
56
|
|
48
|
-
|
57
|
+
authors: #{@authors}
|
58
|
+
affiliation: #{@affiliation}
|
59
|
+
email: #{@email}
|
49
60
|
|
50
|
-
|
61
|
+
seed: #{@seed}
|
51
62
|
|
52
63
|
## Description
|
53
64
|
|
@@ -61,12 +72,22 @@ Seed: #{@seed}
|
|
61
72
|
yield(config)
|
62
73
|
puts "Running experiment #{config.name} with seed #{config.seed}."
|
63
74
|
srand config.seed
|
75
|
+
config.vms.each do |k, v|
|
76
|
+
v.generate_box config
|
77
|
+
end
|
78
|
+
|
79
|
+
# initializing storage backends
|
64
80
|
config.github_conf.init(config) unless config.github_conf.nil?
|
81
|
+
config.dataverse_conf.init(config) unless config.dataverse_conf.nil?
|
82
|
+
|
83
|
+
# executing jobs
|
65
84
|
config.jobs.each do |name,job|
|
66
85
|
for i in 0..(job.iterations-1) do
|
67
86
|
job.execute config, i
|
68
87
|
end
|
69
88
|
end
|
89
|
+
|
90
|
+
# finalizing storage backends
|
70
91
|
config.github_conf.tag unless config.github_conf.nil?
|
71
92
|
config.github_conf.clean unless config.github_conf.nil?
|
72
93
|
end
|
@@ -0,0 +1,179 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Xanthus
|
5
|
+
class Dataverse < Repository
|
6
|
+
attr_accessor :server
|
7
|
+
attr_accessor :repo
|
8
|
+
attr_accessor :token
|
9
|
+
attr_accessor :dataset_name
|
10
|
+
attr_accessor :author
|
11
|
+
attr_accessor :affiliation
|
12
|
+
attr_accessor :email
|
13
|
+
attr_accessor :description
|
14
|
+
attr_accessor :subject
|
15
|
+
attr_accessor :doi
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
super
|
19
|
+
@server = 'default_server'
|
20
|
+
@repo = 'default_repo'
|
21
|
+
@token = 'default_token'
|
22
|
+
@dataset_name = 'default_name'
|
23
|
+
@author = 'default_author'
|
24
|
+
@affiliation = 'default_affiliation'
|
25
|
+
@email = 'default_email'
|
26
|
+
@description = 'default_description'
|
27
|
+
@subject = 'default_subject'
|
28
|
+
@doi = 'not_set'
|
29
|
+
end
|
30
|
+
|
31
|
+
def dataset_json
|
32
|
+
json = %Q{
|
33
|
+
{
|
34
|
+
"datasetVersion": {
|
35
|
+
"metadataBlocks": {
|
36
|
+
"citation": {
|
37
|
+
"fields": [
|
38
|
+
{
|
39
|
+
"value": "#{@dataset_name}",
|
40
|
+
"typeClass": "primitive",
|
41
|
+
"multiple": false,
|
42
|
+
"typeName": "title"
|
43
|
+
},
|
44
|
+
{
|
45
|
+
"value": [
|
46
|
+
{
|
47
|
+
"authorName": {
|
48
|
+
"value": "#{@author}",
|
49
|
+
"typeClass": "primitive",
|
50
|
+
"multiple": false,
|
51
|
+
"typeName": "authorName"
|
52
|
+
},
|
53
|
+
"authorAffiliation": {
|
54
|
+
"value": "#{@affiliation}",
|
55
|
+
"typeClass": "primitive",
|
56
|
+
"multiple": false,
|
57
|
+
"typeName": "authorAffiliation"
|
58
|
+
}
|
59
|
+
}
|
60
|
+
],
|
61
|
+
"typeClass": "compound",
|
62
|
+
"multiple": true,
|
63
|
+
"typeName": "author"
|
64
|
+
},
|
65
|
+
{
|
66
|
+
"value": [
|
67
|
+
{ "datasetContactEmail" : {
|
68
|
+
"typeClass": "primitive",
|
69
|
+
"multiple": false,
|
70
|
+
"typeName": "datasetContactEmail",
|
71
|
+
"value" : "#{@email}"
|
72
|
+
},
|
73
|
+
"datasetContactName" : {
|
74
|
+
"typeClass": "primitive",
|
75
|
+
"multiple": false,
|
76
|
+
"typeName": "datasetContactName",
|
77
|
+
"value": "#{@author}"
|
78
|
+
}
|
79
|
+
}],
|
80
|
+
"typeClass": "compound",
|
81
|
+
"multiple": true,
|
82
|
+
"typeName": "datasetContact"
|
83
|
+
},
|
84
|
+
{
|
85
|
+
"value": [ {
|
86
|
+
"dsDescriptionValue":{
|
87
|
+
"value": "#{@description.gsub(/\r/," ").gsub(/\n/," ")}",
|
88
|
+
"multiple":false,
|
89
|
+
"typeClass": "primitive",
|
90
|
+
"typeName": "dsDescriptionValue"
|
91
|
+
}}],
|
92
|
+
"typeClass": "compound",
|
93
|
+
"multiple": true,
|
94
|
+
"typeName": "dsDescription"
|
95
|
+
},
|
96
|
+
{
|
97
|
+
"value": [
|
98
|
+
"#{@subject}"
|
99
|
+
],
|
100
|
+
"typeClass": "controlledVocabulary",
|
101
|
+
"multiple": true,
|
102
|
+
"typeName": "subject"
|
103
|
+
}
|
104
|
+
],
|
105
|
+
"displayName": "Citation Metadata"
|
106
|
+
}
|
107
|
+
}
|
108
|
+
}
|
109
|
+
}
|
110
|
+
}
|
111
|
+
return json
|
112
|
+
end
|
113
|
+
|
114
|
+
def create_dataset
|
115
|
+
Dir.chdir 'dataverse_dataset' do
|
116
|
+
File.open('dataset.json', 'w+') do |f|
|
117
|
+
f.write(self.dataset_json)
|
118
|
+
end
|
119
|
+
puts "Creating dataverse #{@dataset_name} in #{@repo} at #{@server}..."
|
120
|
+
output = `curl --speed-time 15 --speed-limit 1000 --retry 50 --retry-max-time 0 -H X-Dataverse-key:#{@token} -X POST #{@server}/api/dataverses/#{@repo}/datasets --upload-file dataset.json`
|
121
|
+
puts output # needed to escape curl output
|
122
|
+
parsed = JSON.parse(output)
|
123
|
+
@doi = parsed['data']['persistentId']
|
124
|
+
puts "Dataverse #{@doi} created."
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def init config
|
129
|
+
# initialize with config information
|
130
|
+
@author = config.authors
|
131
|
+
@affiliation = config.affiliation
|
132
|
+
@email = config.email
|
133
|
+
@description = config.description
|
134
|
+
@dataset_name = config.name+'-'+Time.now.strftime("%Y-%m-%d_%H-%M")
|
135
|
+
|
136
|
+
FileUtils.mkdir_p 'dataverse_dataset'
|
137
|
+
self.create_dataset
|
138
|
+
Dir.chdir 'dataverse_dataset' do
|
139
|
+
FileUtils.mkdir_p 'repo'
|
140
|
+
Dir.chdir 'repo' do
|
141
|
+
self.xanthus_file
|
142
|
+
self.readme_file config
|
143
|
+
self.inputs_file config
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def add_file_to_dataverse name, description, folder
|
149
|
+
output = `curl --speed-time 15 --speed-limit 1000 --retry 50 --retry-max-time 0 -H X-Dataverse-key:#{@token} -X POST -F "file=@#{name}" -F 'jsonData={"description":"#{description}","directoryLabel":"#{folder}","categories":["Data"], "restrict":"false"}' "#{@server}/api/datasets/:persistentId/add?persistentId=#{@doi}"`
|
150
|
+
puts output
|
151
|
+
end
|
152
|
+
|
153
|
+
def xanthus_file
|
154
|
+
self.prepare_xanthus_file
|
155
|
+
self.add_file_to_dataverse '.xanthus', 'xanthus file used to generate the data.', 'metadata'
|
156
|
+
end
|
157
|
+
|
158
|
+
def readme_file config
|
159
|
+
self.prepare_readme_file config
|
160
|
+
self.add_file_to_dataverse 'README.md', 'readme describing the dataset.', 'metadata'
|
161
|
+
end
|
162
|
+
|
163
|
+
def inputs_file config
|
164
|
+
config.jobs.each do |name,job|
|
165
|
+
job.inputs.each do |k, files|
|
166
|
+
files.each do |file|
|
167
|
+
system('cp', '-f', "../../#{file}", "#{file}")
|
168
|
+
self.add_file_to_dataverse file, 'Job input file.', 'metadata'
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def add content
|
175
|
+
self.add_file_to_dataverse content, "#{content} is a Xanthus generated file (check metadata for description)", 'data'
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
179
|
+
end
|
data/lib/xanthus/github.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
|
3
3
|
module Xanthus
|
4
|
-
class GitHub
|
4
|
+
class GitHub < Repository
|
5
5
|
attr_accessor :repo
|
6
6
|
attr_accessor :token
|
7
7
|
attr_accessor :folder
|
8
8
|
|
9
9
|
def initialize
|
10
|
+
super
|
10
11
|
@repo = ''
|
11
12
|
@token = ''
|
12
13
|
@folder = Time.now.strftime("%Y-%m-%d_%H-%M")
|
@@ -20,23 +21,14 @@ module Xanthus
|
|
20
21
|
end
|
21
22
|
|
22
23
|
def xanthus_file
|
23
|
-
|
24
|
-
File.readlines('../../.xanthus').each do |line|
|
25
|
-
script += line unless line.include? 'github.token'
|
26
|
-
script += "\t\tgithub.token = 'REMOVED'\n" unless !line.include? 'github.token'
|
27
|
-
end
|
28
|
-
File.open('.xanthus', 'w+') do |f|
|
29
|
-
f.write(script)
|
30
|
-
end
|
24
|
+
self.prepare_xanthus_file
|
31
25
|
system('git', 'add', '.xanthus')
|
32
26
|
system('git', 'commit', '-m', "[Xanthus] :horse: pushed #{@folder}/.xanthus :horse:")
|
33
27
|
system('git', 'push', "https://#{@token}@github.com/#{@repo}", 'master')
|
34
28
|
end
|
35
29
|
|
36
30
|
def readme_file config
|
37
|
-
|
38
|
-
f.write(config.to_readme_md)
|
39
|
-
end
|
31
|
+
self.prepare_readme_file config
|
40
32
|
system('git', 'add', 'README.md')
|
41
33
|
system('git', 'commit', '-m', "[Xanthus] :horse: pushed #{@folder}/README.md :horse:")
|
42
34
|
system('git', 'push', "https://#{@token}@github.com/#{@repo}", 'master')
|
data/lib/xanthus/init.rb
CHANGED
@@ -17,6 +17,8 @@ module Xanthus
|
|
17
17
|
Xanthus.configure do |config|
|
18
18
|
config.name = '#{@@name}'
|
19
19
|
config.authors = 'John Doe'
|
20
|
+
config.affiliation = 'Somewhere University'
|
21
|
+
config.email = 'john.doe@somewhere.edu'
|
20
22
|
config.description = %q{
|
21
23
|
Describe my super experiment.
|
22
24
|
|
@@ -110,7 +112,7 @@ It is very cool and interesting!
|
|
110
112
|
config.job :normal_spade do |job|
|
111
113
|
job.iterations = 2
|
112
114
|
job.tasks = {spade: [:pre, :spade_start, :normal, :spade_stop, :post]}
|
113
|
-
job.outputs = {spade: {trace: '/tmp/
|
115
|
+
job.outputs = {spade: {trace: '/tmp/audit_cdm.avro'}}
|
114
116
|
end
|
115
117
|
|
116
118
|
config.job :attack_spade do |job|
|
@@ -119,10 +121,17 @@ It is very cool and interesting!
|
|
119
121
|
job.outputs = {spade: {trace: '/tmp/audit_cdm.avro'}}
|
120
122
|
end
|
121
123
|
|
122
|
-
config.
|
123
|
-
|
124
|
-
|
124
|
+
config.dataverse do |dataverse|
|
125
|
+
dataverse.server = <ADD DATAVERSE BASE URL>
|
126
|
+
dataverse.repo = <PROVIDE DATAVERSE NAME>
|
127
|
+
dataverse.token = <PROVIDE DATAVERSE TOKEN>
|
128
|
+
dataverse.subject = <PROVIDE DATAVERSE SUBJECT (e.g. engineering)>
|
125
129
|
end
|
130
|
+
|
131
|
+
# config.github do |github|
|
132
|
+
# github.repo = '<ADD GITHUB REPO user/name>'
|
133
|
+
# github.token = '<ADD GITHUB TOKEN>'
|
134
|
+
# end
|
126
135
|
end
|
127
136
|
}
|
128
137
|
file.write(script)
|
data/lib/xanthus/job.rb
CHANGED
@@ -7,44 +7,28 @@ 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
|
-
def output_script outputs
|
19
|
-
script =
|
22
|
+
def output_script machine, outputs
|
23
|
+
script = "vagrant plugin install vagrant-scp\n"
|
20
24
|
outputs.each do |name, path|
|
21
|
-
script += "
|
25
|
+
script += "vagrant scp :#{path} output/#{name}.data\n"
|
22
26
|
end
|
23
27
|
return script
|
24
28
|
end
|
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,52 @@ 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
|
60
45
|
File.open('provision.sh', 'w+') do |f|
|
61
46
|
f.write(script)
|
62
47
|
end
|
48
|
+
script = 'echo "nothing to do"'
|
49
|
+
script = self.output_script(machine, @outputs[machine]) unless @outputs[machine].nil?
|
50
|
+
File.open('before_halt.sh', 'w+') do |f|
|
51
|
+
f.write(script)
|
52
|
+
end
|
53
|
+
system('chmod', '+x', 'before_halt.sh')
|
63
54
|
end
|
64
55
|
end
|
65
56
|
|
57
|
+
def host_scripts config
|
58
|
+
puts 'Setting up host scripts...'
|
59
|
+
if !@pre_instructions.nil?
|
60
|
+
script = Script.new(@pre_instructions, config).to_s
|
61
|
+
File.open('pre.sh', 'w+') do |f|
|
62
|
+
f.write(script)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
if !@post_instructions.nil?
|
67
|
+
script = Script.new(@post_instructions, config).to_s
|
68
|
+
File.open('post.sh', 'w+') do |f|
|
69
|
+
f.write(script)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def execute_pre_instructions
|
75
|
+
puts 'Running pre instructions...'
|
76
|
+
system('sh', './pre.sh')
|
77
|
+
end
|
78
|
+
|
66
79
|
def run machine
|
67
80
|
Dir.chdir machine.to_s do
|
68
81
|
system('vagrant', 'up')
|
69
82
|
end
|
70
83
|
end
|
71
84
|
|
85
|
+
def execute_post_instructions
|
86
|
+
puts 'Running post instructions...'
|
87
|
+
system('sh', './post.sh')
|
88
|
+
end
|
89
|
+
|
72
90
|
def halt machine
|
73
91
|
Dir.chdir machine.to_s do
|
74
92
|
system('vagrant', 'halt')
|
@@ -86,12 +104,15 @@ module Xanthus
|
|
86
104
|
puts "Running job #{name.to_s}-#{iteration.to_s}..."
|
87
105
|
FileUtils.mkdir_p 'tmp'
|
88
106
|
Dir.chdir 'tmp' do
|
107
|
+
self.host_scripts config
|
89
108
|
@tasks.each do |machine, templates|
|
90
109
|
self.setup_env machine, templates, config
|
91
110
|
end
|
111
|
+
self.execute_pre_instructions unless @pre_instructions.nil?
|
92
112
|
@tasks.each do |machine, templates|
|
93
113
|
self.run machine
|
94
114
|
end
|
115
|
+
self.execute_post_instructions unless @post_instructions.nil?
|
95
116
|
@tasks.each do |machine, templates|
|
96
117
|
self.halt machine
|
97
118
|
end
|
@@ -104,6 +125,7 @@ module Xanthus
|
|
104
125
|
system('rm', '-rf', "#{name.to_s}-#{iteration.to_s}")
|
105
126
|
config.github_conf.add("#{name.to_s}-#{iteration.to_s}.tar.gz") unless config.github_conf.nil?
|
106
127
|
config.github_conf.push unless config.github_conf.nil?
|
128
|
+
config.dataverse_conf.add("#{name.to_s}-#{iteration.to_s}.tar.gz") unless config.dataverse_conf.nil?
|
107
129
|
puts "Job #{name.to_s}-#{iteration.to_s} done."
|
108
130
|
end
|
109
131
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Xanthus
|
2
|
+
class Repository
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
end
|
6
|
+
|
7
|
+
def prepare_xanthus_file
|
8
|
+
script = ''
|
9
|
+
File.readlines('../../.xanthus').each do |line|
|
10
|
+
script += line unless line.include?('github.token') || line.include?('dataverse.token')
|
11
|
+
|
12
|
+
# remove github token
|
13
|
+
script += "\t\t# github.token = 'REMOVED'\n" unless !line.include? 'github.token'
|
14
|
+
# remove dataverse token
|
15
|
+
script += "\t\t# dataverse.token = 'REMOVED'\n" unless !line.include? 'dataverse.token'
|
16
|
+
end
|
17
|
+
File.open('.xanthus', 'w+') do |f|
|
18
|
+
f.write(script)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def prepare_readme_file config
|
23
|
+
File.open('README.md', 'w+') do |f|
|
24
|
+
f.write(config.to_readme_md)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
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,17 @@ 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
|
14
|
+
attr_accessor :on_aws
|
15
|
+
attr_accessor :aws_env_key_id
|
16
|
+
attr_accessor :aws_env_key_secret
|
17
|
+
attr_accessor :aws_key_pair_name
|
18
|
+
attr_accessor :aws_region
|
19
|
+
attr_accessor :aws_ami
|
20
|
+
attr_accessor :aws_instance_type
|
21
|
+
attr_accessor :aws_security_group
|
11
22
|
|
12
23
|
def initialize
|
13
24
|
@name = :default
|
@@ -18,25 +29,87 @@ module Xanthus
|
|
18
29
|
@cpus = 2
|
19
30
|
@cpu_cap = 70
|
20
31
|
@gui = false
|
32
|
+
@boxing = nil
|
33
|
+
@ssh_username = nil
|
34
|
+
@ssh_key_path = nil
|
21
35
|
end
|
22
36
|
|
23
37
|
def to_vagrant
|
24
|
-
%Q{
|
38
|
+
script = %Q{
|
25
39
|
Vagrant.configure(2) do |config|
|
26
40
|
config.vm.box = "#{@box}"
|
27
41
|
config.vm.box_version = "#{@version}"
|
28
42
|
config.vm.network "private_network", ip: "#{@ip}"
|
29
|
-
|
30
|
-
|
43
|
+
}
|
44
|
+
script += %Q{
|
45
|
+
if Vagrant.has_plugin?("vagrant-vbguest")
|
46
|
+
config.vbguest.auto_update = false
|
47
|
+
end
|
48
|
+
}
|
49
|
+
script += %Q{
|
50
|
+
config.vm.synced_folder ".", "/vagrant", disabled: false, type: 'rsync'
|
51
|
+
} unless !@on_aws
|
52
|
+
script += %Q{
|
53
|
+
config.ssh.username = "#{@ssh_username}"
|
54
|
+
} unless ssh_username.nil?
|
55
|
+
script += %Q{
|
56
|
+
config.ssh.private_key_path = "#{@ssh_key_path}"
|
57
|
+
} unless ssh_key_path.nil?
|
58
|
+
script += %Q{
|
59
|
+
config.vm.provider "virtualbox" do |vb, override|
|
31
60
|
vb.gui = #{@gui}
|
32
61
|
vb.memory = #{@memory}
|
33
62
|
vb.customize ["modifyvm", :id, "--cpuexecutioncap", "#{@cpu_cap}"]
|
34
63
|
vb.cpus = #{@cpus}
|
35
64
|
vb.name = "#{@name}"
|
36
65
|
end
|
37
|
-
|
66
|
+
} unless @on_aws
|
67
|
+
script += %Q{
|
68
|
+
config.vm.provider "aws" do |aws, override|
|
69
|
+
aws.access_key_id = ENV['#{@aws_env_key_id}']
|
70
|
+
aws.secret_access_key = ENV['#{@aws_env_key_secret}']
|
71
|
+
aws.keypair_name = '#{@aws_key_pair_name}'
|
72
|
+
aws.region = '#{@aws_region}'
|
73
|
+
aws.ami = '#{@aws_ami}'
|
74
|
+
aws.instance_type = '#{@aws_instance_type}'
|
75
|
+
aws.security_groups = ['#{@aws_security_group}']
|
76
|
+
end
|
77
|
+
} unless !@on_aws
|
78
|
+
script += %Q{ config.vm.provision "shell", path: "provision.sh"
|
79
|
+
|
80
|
+
config.trigger.before :halt do |trigger|
|
81
|
+
trigger.info = "Retrieving data before halt..."
|
82
|
+
trigger.run = {path: "before_halt.sh"}
|
83
|
+
end
|
38
84
|
end
|
39
85
|
}
|
86
|
+
return script
|
87
|
+
end
|
88
|
+
|
89
|
+
def generate_box config
|
90
|
+
return unless !boxing.nil?
|
91
|
+
puts 'Generating box...'
|
92
|
+
|
93
|
+
FileUtils.mkdir_p 'boxing'
|
94
|
+
Dir.chdir 'boxing' do
|
95
|
+
File.open('Vagrantfile', 'w+') do |f|
|
96
|
+
f.write(self.to_vagrant)
|
97
|
+
end
|
98
|
+
|
99
|
+
script = Script.new(boxing, config).to_s
|
100
|
+
File.open('provision.sh', 'w+') do |f|
|
101
|
+
f.write(script)
|
102
|
+
end
|
103
|
+
|
104
|
+
system('vagrant', 'up')
|
105
|
+
system('vagrant', 'halt')
|
106
|
+
system('vagrant', 'package', '--output', "#{name}.box")
|
107
|
+
puts "#{name}.box created."
|
108
|
+
system('vagrant', 'box', 'add', '--force', "local/#{name}", "#{name}.box")
|
109
|
+
system('vagrant', 'destroy', '-f')
|
110
|
+
@box = "local/#{name}"
|
111
|
+
@version = '0'
|
112
|
+
end
|
40
113
|
end
|
41
114
|
end
|
42
115
|
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.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Pasquier
|
@@ -9,34 +9,48 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-06-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '2.3'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '2.3'
|
14
28
|
- !ruby/object:Gem::Dependency
|
15
29
|
name: bundler
|
16
30
|
requirement: !ruby/object:Gem::Requirement
|
17
31
|
requirements:
|
18
|
-
- - "
|
32
|
+
- - "~>"
|
19
33
|
- !ruby/object:Gem::Version
|
20
34
|
version: '2.0'
|
21
35
|
type: :development
|
22
36
|
prerelease: false
|
23
37
|
version_requirements: !ruby/object:Gem::Requirement
|
24
38
|
requirements:
|
25
|
-
- - "
|
39
|
+
- - "~>"
|
26
40
|
- !ruby/object:Gem::Version
|
27
41
|
version: '2.0'
|
28
42
|
- !ruby/object:Gem::Dependency
|
29
43
|
name: rake
|
30
44
|
requirement: !ruby/object:Gem::Requirement
|
31
45
|
requirements:
|
32
|
-
- - "
|
46
|
+
- - "~>"
|
33
47
|
- !ruby/object:Gem::Version
|
34
48
|
version: '10.0'
|
35
49
|
type: :development
|
36
50
|
prerelease: false
|
37
51
|
version_requirements: !ruby/object:Gem::Requirement
|
38
52
|
requirements:
|
39
|
-
- - "
|
53
|
+
- - "~>"
|
40
54
|
- !ruby/object:Gem::Version
|
41
55
|
version: '10.0'
|
42
56
|
description: Automated intrusion detection dataset generation framework.
|
@@ -52,10 +66,13 @@ files:
|
|
52
66
|
- bin/xanthus
|
53
67
|
- lib/xanthus.rb
|
54
68
|
- lib/xanthus/configuration.rb
|
69
|
+
- lib/xanthus/dataverse.rb
|
55
70
|
- lib/xanthus/default.rb
|
56
71
|
- lib/xanthus/github.rb
|
57
72
|
- lib/xanthus/init.rb
|
58
73
|
- lib/xanthus/job.rb
|
74
|
+
- lib/xanthus/repository.rb
|
75
|
+
- lib/xanthus/script.rb
|
59
76
|
- lib/xanthus/version.rb
|
60
77
|
- lib/xanthus/virtual_machine.rb
|
61
78
|
homepage: http://camflow.org
|
@@ -77,8 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
94
|
- !ruby/object:Gem::Version
|
78
95
|
version: '0'
|
79
96
|
requirements: []
|
80
|
-
|
81
|
-
rubygems_version: 2.7.6
|
97
|
+
rubygems_version: 3.0.3
|
82
98
|
signing_key:
|
83
99
|
specification_version: 4
|
84
100
|
summary: Automated intrusion detection dataset generation framework.
|