lab 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -12,16 +12,20 @@ SUPPORTED VM TECHNOLOGIES:
12
12
  NOTE: The lab libraries have only been tested with linux as a host, porting to windows is not planned at this time.
13
13
 
14
14
  Implemented:
15
- - workstation (Tested against 7.x)
16
- - remote_workstation (Tested against 7.x)
17
- - virtualbox (Tested against 4.x)
18
- - remote_esx (VMware ESX Host Agent 4.1.0 build-348481)
15
+
16
+ - workstation (Tested against 7.x)
17
+ - remote_workstation (Tested against 7.x)
18
+ - virtualbox (Tested against 4.x)
19
+ - remote_esx (VMware ESX Host Agent 4.1.0 build-348481)
19
20
 
20
21
  Partially Implemented:
21
- - amazon_ec2 (via fog gem)
22
- - dynagen
22
+
23
+ - amazon_ec2 (via fog gem)
24
+ - dynagen
25
+ - vsphere
23
26
 
24
27
  Need Implementation:
28
+
25
29
  - qemu
26
30
  - qemudo
27
31
  - others?
@@ -31,9 +35,18 @@ PLATFORM SUPPORT:
31
35
  You will need to have this code running on a linux box, Currently this has only been run / tested on Ubuntu 9.04 -> 10.04, though it should run on any linux with an ssh client and the dependencies below. Remote VM Hosts will need to be linux as well, though other platforms may work (untested). If you're interested in porting it to windows, please contact me (jcran).
32
36
 
33
37
  Platform Dependencies:
34
- - whatever vm software is necessary for the driver you're using (see SUPPORTED VM TECHNOLOGIES above)
35
- - net/scp - the gem (net-scp). Required to copy files to/from the devices in the case that tools are not installed. Not necessary if tools are installed.
36
- - fog - require to use the amazon_ec2 driver
38
+
39
+ Currently the gem must be run on a linux host with access to the vm
40
+ tech you're automating. For instance, if you want to automate a
41
+ workstation VM, you'll need to run the lab code on the Linux VMWare
42
+ Workstation Host. You can work around this by using the
43
+ remote_workstation driver, which shells (using ssh) into the remote host
44
+ and runs the commands. Note that both systems must be running linux.
45
+
46
+ CONFIGURING:
47
+ ============
48
+
49
+ Take a look at the example configuration files in config/.
37
50
 
38
51
  STANDALONE API:
39
52
  ===============
@@ -48,11 +61,10 @@ You must first create a yaml file which describes your vm. See data/lab/test_tar
48
61
  require 'vm_controller'
49
62
  vm_controller = ::Lab::Controllers::VmController.new(YAML.load_file(lab_def))
50
63
  vm_controller['vm1'].start
51
- vm_controller['vm1'].snapshot("clean")
64
+ vm_controller['vm1'].create_snapshot("clean")
52
65
  vm_controller['vm1'].run_command("rm /etc/resolv.conf")
53
66
  vm_controller['vm1'].open_uri("http://autopwn:8080")
54
- vm_controller['vm1'].revert("clean")
55
- vm_controller['vm1'].revert("clean")
67
+ vm_controller['vm1'].revert_snapshot("clean")
56
68
  </pre>
57
69
  METASPLOIT MSFCONSOLE LAB PLUGIN:
58
70
  =================================
@@ -36,4 +36,9 @@ Gem::Specification.new do |s|
36
36
  # util/console.rb
37
37
  s.add_runtime_dependency "pry"
38
38
 
39
+ ##
40
+ ## UI Dependencies
41
+ ##
42
+ s.add_runtime_dependency "sinatra"
43
+
39
44
  end
@@ -20,7 +20,7 @@ class RemoteEsxiDriver < VmDriver
20
20
 
21
21
  @user = filter_command(config['user'])
22
22
  @host = filter_command(config['host'])
23
- @port = config['port']
23
+ @port = config['port']
24
24
  end
25
25
 
26
26
  def start
@@ -47,6 +47,10 @@ class RemoteEsxiDriver < VmDriver
47
47
  remote_system_command("vim-cmd vmsvc/power.reset #{@vmid}")
48
48
  end
49
49
 
50
+ def query_snapshots
51
+ get_snapshots
52
+ end
53
+
50
54
  def create_snapshot(snapshot)
51
55
  snapshot = filter_input(snapshot)
52
56
 
@@ -71,8 +75,8 @@ class RemoteEsxiDriver < VmDriver
71
75
  end
72
76
  end
73
77
 
74
- # If we got here, the snapshot didn't exist
75
- raise "Invalid Snapshot Name"
78
+ # If we got here, we couldn't make it happen
79
+ raise "Unable to revert"
76
80
  end
77
81
 
78
82
  def delete_snapshot(snapshot, remove_children=false)
@@ -1,3 +1,3 @@
1
1
  module Lab
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
@@ -15,6 +15,7 @@ class Vm
15
15
  attr_accessor :credentials
16
16
  attr_accessor :tools
17
17
  attr_accessor :type
18
+ attr_accessor :notes
18
19
  attr_accessor :os
19
20
  attr_accessor :arch
20
21
  attr_accessor :machine_tags
@@ -37,7 +38,6 @@ class Vm
37
38
  ## modifiers - can be anything in the modifiers directory
38
39
  ## machine_tags - list of strings associated with the machine (not individual snapshots)
39
40
  ## snapshots - list of snapshots
40
-
41
41
 
42
42
  def initialize(config = {})
43
43
 
@@ -58,6 +58,7 @@ class Vm
58
58
 
59
59
  @location = filter_input(config['location'])
60
60
  @description = config['description']
61
+ @notes = config['notes']
61
62
  @tools = config['tools']
62
63
  @os = config['os']
63
64
  @arch = config['arch']
@@ -182,6 +183,10 @@ class Vm
182
183
  def resume
183
184
  @driver.resume
184
185
  end
186
+
187
+ def query_snapshots
188
+ @driver.query_snapshots
189
+ end
185
190
 
186
191
  def create_snapshot(snapshot)
187
192
  @driver.create_snapshot(snapshot)
@@ -0,0 +1,11 @@
1
+ super-simple CCDC monitoring tool
2
+
3
+ setup:
4
+ - install some rubies (use rvm, it's super awesome)
5
+ - $ git clone
6
+ - $ gem install sinatra
7
+ - $ rackup
8
+ - browse to :9292
9
+ - read the code and realize i'm scannin yer networkz
10
+
11
+ screenshot: http://www.pentestify.com/x/omgeasymon.png
@@ -0,0 +1,13 @@
1
+ require './labmon'
2
+ require './helpers'
3
+
4
+ root_dir = File.dirname(__FILE__)
5
+
6
+ set :environment, :production
7
+ set :root, root_dir
8
+ set :app_file, File.join(root_dir, 'labmon.rb')
9
+ set :public_folder, root_dir + '/public'
10
+ set :logging, true
11
+ set :run, false
12
+
13
+ run Sinatra::Application
@@ -0,0 +1,21 @@
1
+ require 'sinatra/base'
2
+
3
+ module Sinatra
4
+ module HTMLEscapeHelper
5
+ def h(text)
6
+ Rack::Utils.escape_html(text)
7
+ end
8
+ end
9
+ helpers HTMLEscapeHelper
10
+
11
+ module InputBouncer
12
+ def verify_as_ip_or_hostname(param)
13
+ return unless param # possible this could be called on a nil parameter
14
+ # First pass scan for anything not alphanum or . or -
15
+ redirect "/exception" if param =~ /[^a-zA-Z0-9\x2e\x2d]/
16
+ # Now test for nice formatting.
17
+ redirect "/exception" if !(param =~ /^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$/)
18
+ end
19
+ end
20
+ register InputBouncer
21
+ end
@@ -0,0 +1,56 @@
1
+ require 'sinatra'
2
+ require 'lab'
3
+
4
+ before do
5
+ ## Basic blacklisting of metacharacters
6
+ redirect to "/exception" if request.path_info =~ /\;|\|/
7
+ @controller = Lab::Controllers::VmController.new
8
+ if File.exist? "config.txt"
9
+ @controller.from_file(File.open("config.txt").read.strip)
10
+ end
11
+ end
12
+
13
+ get '/' do
14
+ redirect to "/list"
15
+ end
16
+
17
+ get '/exception' do
18
+ "sorry, that's not allowed, request contains bad data"
19
+ end
20
+
21
+ get '/list' do
22
+ erb :list
23
+ end
24
+
25
+ get '/show' do
26
+ redirect to '/list'
27
+ end
28
+
29
+ get '/show/:hostname' do
30
+ # Get the watcher
31
+ hostname = params[:hostname]
32
+ @vm = @controller[hostname]
33
+ erb :show
34
+ end
35
+
36
+ get '/start/:hostname' do
37
+ hostname = params[:hostname]
38
+ @vm = @controller[hostname]
39
+ @vm.start
40
+ redirect to "/show/#{hostname}"
41
+ end
42
+
43
+ get '/stop/:hostname' do
44
+ hostname = params[:hostname]
45
+ @vm = @controller[hostname]
46
+ @vm.stop
47
+ redirect to "/show/#{hostname}"
48
+ end
49
+
50
+ get '/revert_snapshot/:hostname' do
51
+ hostname = params[:hostname]
52
+ snapshot = params[:snapshot] || "clean"
53
+ @vm = @controller[hostname]
54
+ @vm.revert_snapshot snapshot
55
+ redirect to "/show/#{hostname}"
56
+ end
File without changes
@@ -0,0 +1 @@
1
+ <h1> LabMon </h1>
@@ -0,0 +1,5 @@
1
+ <html>
2
+ <body>
3
+ <%= yield %>
4
+ </body>
5
+ </html>
@@ -0,0 +1,7 @@
1
+ <h1> LabMon </h1>
2
+
3
+ <ul>
4
+ <% @controller.each do |vm| %>
5
+ <li> <a href=show/<%=vm.hostname%>><%=vm.hostname%></a> - <%= vm.description %> </li>
6
+ <% end %>
7
+ </ul>
@@ -0,0 +1,31 @@
1
+ <h1> LabMon </h1>
2
+
3
+ <ul>
4
+ <li> Hostname: <%= @vm.hostname %> </ll>
5
+ <li> Description: <%= @vm.description %> </li>
6
+ <li> Notes: <%= @vm.notes %> </li>
7
+ <li> Running: <%= @vm.running? %> </li>
8
+ <li> Tags: <%= @vm.machine_tags.join(", ") unless @vm.snapshots.nil? %></li>
9
+ <li> Snapshots: <%= @vm.snapshots.join(", ") unless @vm.snapshots.nil? %></li>
10
+ </ul>
11
+
12
+ <table>
13
+ <tr>
14
+ <td>
15
+ <form name=start_vm action="/start/<%=@vm.hostname%>">
16
+ <input type=submit value="Start">
17
+ </form>
18
+ </td>
19
+ <td>
20
+ <form name=stop_vm action="/stop/<%=@vm.hostname%>">
21
+ <input type=submit value="Stop">
22
+ </form>
23
+ </td>
24
+ <td>
25
+ <form name=revert_snapshot action="/revert_snapshot/<%=@vm.hostname%>">
26
+ <input type=text value="clean">
27
+ <input type=submit value="Revert">
28
+ </form>
29
+ <td>
30
+ </tr>
31
+ </table
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-11 00:00:00.000000000 Z
12
+ date: 2012-04-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: net-ssh
16
- requirement: &19870120 !ruby/object:Gem::Requirement
16
+ requirement: &19051940 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *19870120
24
+ version_requirements: *19051940
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: net-scp
27
- requirement: &19869140 !ruby/object:Gem::Requirement
27
+ requirement: &18994720 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *19869140
35
+ version_requirements: *18994720
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rbvmomi
38
- requirement: &19868260 !ruby/object:Gem::Requirement
38
+ requirement: &18992980 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *19868260
46
+ version_requirements: *18992980
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: fog
49
- requirement: &19867600 !ruby/object:Gem::Requirement
49
+ requirement: &18992340 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *19867600
57
+ version_requirements: *18992340
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: pry
60
- requirement: &19865900 !ruby/object:Gem::Requirement
60
+ requirement: &18991460 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,18 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *19865900
68
+ version_requirements: *18991460
69
+ - !ruby/object:Gem::Dependency
70
+ name: sinatra
71
+ requirement: &18990620 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *18990620
69
80
  description: ! 'Start/Stop/Revert and do other cool stuff w/ Vmware, Virtualbox, and
70
81
  ESXi vms. This gem wraps common CLI utilities and other gems to create a common
71
82
  inteface for vms. '
@@ -113,6 +124,15 @@ files:
113
124
  - lib/lab/vm.rb
114
125
  - lib/lab/vm_controller.rb
115
126
  - test/.gitkeep
127
+ - ui/README
128
+ - ui/config.ru
129
+ - ui/helpers.rb
130
+ - ui/labmon.rb
131
+ - ui/log/.gitkeep
132
+ - ui/views/index.erb
133
+ - ui/views/layout.erb
134
+ - ui/views/list.erb
135
+ - ui/views/show.erb
116
136
  - util/console.rb
117
137
  homepage: http://www.github.com/rapid7/lab/wiki
118
138
  licenses: []