rails_pwnerer 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1 @@
1
+ v0.1. Initial release. Supports 'den00b' to setup the environment.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2007 Massachusetts Institute of Technology
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/Manifest ADDED
@@ -0,0 +1,17 @@
1
+ bin/rpwn
2
+ CHANGELOG
3
+ lib/pwnage/base/dirs.rb
4
+ lib/pwnage/base/gems.rb
5
+ lib/pwnage/base/packages.rb
6
+ lib/pwnage/base/startup.rb
7
+ lib/pwnage/base.rb
8
+ lib/pwnage/executor.rb
9
+ lib/pwnage/scaffolds/dirs.rb
10
+ lib/pwnage/scaffolds/gems.rb
11
+ lib/pwnage/scaffolds/hook_mongrels.rb
12
+ lib/pwnage/scaffolds/packages.rb
13
+ lib/rails_pwnage.rb
14
+ LICENSE
15
+ Manifest
16
+ README
17
+ RUBYFORGE
data/README ADDED
@@ -0,0 +1,9 @@
1
+ This is the ruby driver for the Trusted Execution Module prototype produced at MIT. The best feature of the
2
+ ruby driver is the very powerful DSL (domain-specific language) that TEM procedures are compiled from.
3
+
4
+ This work is not ready for publication. If you come across this document and/or software, please do not use or
5
+ distribute it until this notice is removed.
6
+
7
+ Running coverage tests:
8
+ gem install rcov
9
+ rcov -Ilib test/*.rb
data/RUBYFORGE ADDED
@@ -0,0 +1,22 @@
1
+ Quickstart for Rubyforge:
2
+
3
+ 1) Install the rubyforge gem
4
+ gem install rubyforge
5
+
6
+ 2) Save your rubyforge.org login information
7
+ rubyforge setup
8
+
9
+ 3) Get a login cookie
10
+ rubyforge login
11
+
12
+ 4) Get project configuration from rubyforge
13
+ rubyforge config rails-pwnage
14
+
15
+ 5) Create a package to release under
16
+ rubyforge create_package rails-pwnage rails_pwnage
17
+
18
+ 6) Install the echoe gem (required for building this gem)
19
+ gem install echoe
20
+
21
+ 7) Release the gem (finally!)
22
+ rake release
data/bin/rpwn ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'rails_pwnage'
4
+
5
+ RailsPwnage::Executor.go ARGV
@@ -0,0 +1,27 @@
1
+ module RailsPwnage::Base
2
+ # initializes the module in UNIX mode
3
+ def self._setup_unix
4
+ #SUDO_PREFIX = 'sudo '
5
+ end
6
+
7
+ # initializes the module in Windows mode
8
+ def self._setup_windows
9
+ #SUDO_PREFIX = ''
10
+ end
11
+
12
+ # dispatch to the right initializer based on Ruby's platform
13
+ if RUBY_PLATFORM =~ /win/ && !(RUBY_PLATFORM =~ /darwin/)
14
+ self._setup_windows
15
+ else
16
+ self._setup_unix
17
+ end
18
+
19
+ # unrolls a collection
20
+ def unroll_collection(arg, &proc)
21
+ if arg.kind_of? String
22
+ yield arg
23
+ else
24
+ arg.each { |i| unroll_collection(i, &proc) }
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ # extends Base with directory-related functions
2
+
3
+ require 'etc'
4
+
5
+ module RailsPwnage::Base
6
+ # runs the associated block within a certain directory
7
+ def self.with_dir(dir)
8
+ old_dir = Dir.pwd()
9
+ Dir.chdir(dir)
10
+
11
+ begin
12
+ yield
13
+ ensure
14
+ Dir.chdir(old_dir)
15
+ end
16
+ end
17
+
18
+ # gets the UID associated with the username
19
+ def self.uid_for_username(name)
20
+ passwd_entry = getpwnam(name)
21
+ return (passwd_entry.nil?) ? nil : passwd_entry.uid
22
+ end
23
+ end
@@ -0,0 +1,30 @@
1
+ # extends Base with gem-related functions
2
+
3
+ module RailsPwnage::Base
4
+ # TODO: use the Gem API instead of the command line
5
+
6
+ def install_gem(gem_name)
7
+ system "gem install #{gem_name}"
8
+ end
9
+
10
+ def upgrade_gem(gem_name)
11
+ system "gem update #{gem_name.nil ? '' : gem_name}"
12
+ end
13
+
14
+ # update the metadata for all the gems
15
+ def update_gems()
16
+ system "gem update --system"
17
+ # patch Ubuntu's broken rubygems installation
18
+ system "cp /usr/bin/gem1.8 /usr/bin/gem"
19
+ end
20
+ end
21
+
22
+ module RailsPwnage::Base
23
+ def install_gems(gem_names)
24
+ unroll_collection(gem_names) { |n| install_gem(n) }
25
+ end
26
+
27
+ def upgrade_gems(gem_names)
28
+ unroll_collection(gem_names) { |n| upgrade_gem(n) }
29
+ end
30
+ end
@@ -0,0 +1,28 @@
1
+ # extends Base with OS package-related functions
2
+
3
+ module RailsPwnage::Base
4
+ # TODO: this works for debian-only
5
+
6
+ def install_package(package_name)
7
+ system "apt-get install -y #{package_name}"
8
+ end
9
+
10
+ def upgrade_package(package_name)
11
+ system "apt-get upgrade -y #{package_name.nil ? '' : package_name}"
12
+ end
13
+
14
+ # update the metadata for all the packages
15
+ def update_packages()
16
+ system "apt-get update"
17
+ end
18
+ end
19
+
20
+ module RailsPwnage::Base
21
+ def install_packages(package_names)
22
+ unroll_collection(package_names) { |n| install_package(n) }
23
+ end
24
+
25
+ def upgrade_packages(package_names)
26
+ unroll_collection(package_names) { |n| update_package(n) }
27
+ end
28
+ end
@@ -0,0 +1,19 @@
1
+ # extends Base with OS startup-related functions
2
+
3
+ require 'fileutils'
4
+
5
+ module RailsPwnage::Base
6
+ # TODO: make this work w/o initd (OSX, Windows)
7
+
8
+ # hooks a script into the boot sequence
9
+ def hook_boot_script(script_location)
10
+ # copy the script to /etc/init.d and chmod +x
11
+ script_name = File.basename(script_location)
12
+ target_script = '/etc/init.d/' + script_name
13
+ FileUtils.cp(script_location, target_script)
14
+ File.chmod(0755, target_script)
15
+
16
+ # add to boot sequence
17
+ system "update-rc.d #{script_name} defaults"
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ class RailsPwnage::Executor
2
+ include RailsPwnage::Scaffolds
3
+
4
+ # standalone runner
5
+ def run(args)
6
+ case args[0]
7
+ when 'dirs'
8
+ Dirs.go
9
+ when 'gems'
10
+ Gems.go
11
+ when 'packages'
12
+ Packages.go
13
+ when 'mongrels'
14
+ HookMongrels.go
15
+
16
+ when 'den00b'
17
+ Packages.go
18
+ Gems.go
19
+ Dirs.go
20
+ HookMongrels.go
21
+ end
22
+ end
23
+
24
+
25
+ # stand-alone launcher
26
+ def self.go(args)
27
+ self.new.run(args)
28
+ end
29
+ end
@@ -0,0 +1,21 @@
1
+ # sets up the required directory structure
2
+
3
+ class RailsPwnage::Scaffolds::Dirs
4
+ include RailsPwnage::Base
5
+
6
+ # runner
7
+ def run
8
+ with_dir('/') do
9
+ Dir.mkdir('prod')
10
+ Dir.mkdir('prod/apps')
11
+ File.chown(uid_for_username('victor'), nil, 'prod/apps')
12
+ Dir.mkdir('prod/config')
13
+ File.chown(uid_for_username('victor'), nil, 'prod/config')
14
+ end
15
+ end
16
+
17
+ # standalone runner
18
+ def self.go
19
+ self.new.run
20
+ end
21
+ end
@@ -0,0 +1,31 @@
1
+ # installs the required gems
2
+
3
+ class RailsPwnage::Scaffolds::Gems
4
+ include RailsPwnage::Base
5
+
6
+
7
+ def install_servers
8
+ install_gems %w(rails mongrel mongrel_cluster)
9
+ end
10
+
11
+ def install_dbi
12
+ install_gems %w(mysql sqlite3-ruby)
13
+ end
14
+
15
+ def install_tools
16
+ # TODO: an application should have its own tools
17
+ install_gems %w(rmagick mechanize sys-proctable)
18
+ end
19
+
20
+ # runner
21
+ def run
22
+ update_gems
23
+ install_servers
24
+ install_tools
25
+ end
26
+
27
+ # standalone runner
28
+ def self.go
29
+ self.new.run
30
+ end
31
+ end
@@ -0,0 +1,37 @@
1
+ # sets up mongrel_cluster to startup at boot time
2
+
3
+ class RailsPwnage::Scaffolds::HookMongrels
4
+ include RailsPwnage::Base
5
+
6
+ # compute the path to mongrel_cluster
7
+ def path_to_gem
8
+ # TODO: use the rubygems API instead of this hack
9
+
10
+ # look for lib/init.rb in mongrel_cluster (hopefully this won't break)
11
+ output = `gem which 'mongrel_cluster/init'`
12
+ # now lock down the path
13
+ output.split.last.gsub!('lib/mongrel_cluster/init.rb', '')
14
+ end
15
+
16
+ # add mongrel_cluster to the startup
17
+ def hook_bootscript
18
+ mongrel_script = self.path_to_gem + 'resources/mongrel_cluster'
19
+ hook_boot_script mongrel_script
20
+ end
21
+
22
+ # build the configuration
23
+ def make_config
24
+ Dir.mkdir('/etc/mongrel_cluster')
25
+ end
26
+
27
+ # runner
28
+ def run
29
+ make_config
30
+ hook_bootscript
31
+ end
32
+
33
+ # standalone runner
34
+ def self.go
35
+ self.new.run
36
+ end
37
+ end
@@ -0,0 +1,35 @@
1
+ # installs the required OS packages
2
+
3
+ class RailsPwnage::Scaffolds::Packages
4
+ include RailsPwnage::Base
5
+
6
+ def install_tools
7
+ install_packages %w(openssh-server subversion libmagick10-dev)
8
+ end
9
+
10
+ def install_ruby
11
+ install_packages %w(build-essential ruby rubygems irb)
12
+ end
13
+
14
+ def install_mysql
15
+ install_packages %w(mysql-client mysql-server libmysqlclient15-dev)
16
+ end
17
+
18
+ def install_balancer
19
+ install_packages %w(nginx)
20
+ end
21
+
22
+ # runner
23
+ def run
24
+ update_packages
25
+ install_tools
26
+ install_ruby
27
+ install_mysql
28
+ install_balancer
29
+ end
30
+
31
+ # standalone runner
32
+ def self.go
33
+ self.new.run
34
+ end
35
+ end
@@ -0,0 +1,18 @@
1
+ module RailsPwnage
2
+ end
3
+
4
+ module RailsPwnage::Scaffolds
5
+ end
6
+
7
+ require 'pwnage/base.rb'
8
+ require 'pwnage/base/dirs.rb'
9
+ require 'pwnage/base/gems.rb'
10
+ require 'pwnage/base/packages.rb'
11
+ require 'pwnage/base/startup.rb'
12
+
13
+ require 'pwnage/executor.rb'
14
+
15
+ require 'pwnage/scaffolds/dirs.rb'
16
+ require 'pwnage/scaffolds/gems.rb'
17
+ require 'pwnage/scaffolds/hook_mongrels.rb'
18
+ require 'pwnage/scaffolds/packages.rb'
@@ -0,0 +1,52 @@
1
+
2
+ # Gem::Specification for Rails_pwnerer-0.1
3
+ # Originally generated by Echoe
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = %q{rails_pwnerer}
7
+ s.version = "0.1"
8
+
9
+ s.specification_version = 2 if s.respond_to? :specification_version=
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.authors = ["Victor Costan"]
13
+ s.date = %q{2008-04-13}
14
+ s.default_executable = %q{rpwn}
15
+ s.description = %q{Rails deployment tool/hack.}
16
+ s.email = %q{victor@costan.us}
17
+ s.executables = ["rpwn"]
18
+ s.extra_rdoc_files = ["bin/rpwn", "CHANGELOG", "lib/pwnage/base/dirs.rb", "lib/pwnage/base/gems.rb", "lib/pwnage/base/packages.rb", "lib/pwnage/base/startup.rb", "lib/pwnage/base.rb", "lib/pwnage/executor.rb", "lib/pwnage/scaffolds/dirs.rb", "lib/pwnage/scaffolds/gems.rb", "lib/pwnage/scaffolds/hook_mongrels.rb", "lib/pwnage/scaffolds/packages.rb", "lib/rails_pwnage.rb", "LICENSE", "README"]
19
+ s.files = ["bin/rpwn", "CHANGELOG", "lib/pwnage/base/dirs.rb", "lib/pwnage/base/gems.rb", "lib/pwnage/base/packages.rb", "lib/pwnage/base/startup.rb", "lib/pwnage/base.rb", "lib/pwnage/executor.rb", "lib/pwnage/scaffolds/dirs.rb", "lib/pwnage/scaffolds/gems.rb", "lib/pwnage/scaffolds/hook_mongrels.rb", "lib/pwnage/scaffolds/packages.rb", "lib/rails_pwnage.rb", "LICENSE", "Manifest", "README", "RUBYFORGE", "rails_pwnerer.gemspec"]
20
+ s.has_rdoc = true
21
+ s.homepage = %q{http://www.costan.us/rails_pwnage}
22
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rails_pwnerer", "--main", "README"]
23
+ s.require_paths = ["lib"]
24
+ s.rubyforge_project = %q{rails-pwnage}
25
+ s.rubygems_version = %q{1.1.0}
26
+ s.summary = %q{Rails deployment tool/hack.}
27
+ end
28
+
29
+
30
+ # # Original Rakefile source (requires the Echoe gem):
31
+ #
32
+ # require 'rubygems'
33
+ # gem 'echoe'
34
+ # require 'echoe'
35
+ #
36
+ # Echoe.new('rails_pwnerer') do |p|
37
+ # p.project = 'rails-pwnage' # rubyforge project
38
+ #
39
+ # p.author = 'Victor Costan'
40
+ # p.email = 'victor@costan.us'
41
+ # p.summary = 'Rails deployment tool/hack.'
42
+ # p.url = 'http://www.costan.us/rails_pwnage'
43
+ # # p.dependencies = ['rails >=2.0']
44
+ #
45
+ # p.need_tar_gz = false
46
+ # p.rdoc_pattern = /^(lib|bin|tasks|ext)|^BUILD|^README|^CHANGELOG|^TODO|^LICENSE|^COPYING$/
47
+ # end
48
+ #
49
+ # if $0 == __FILE__
50
+ # Rake.application = Rake::Application.new
51
+ # Rake.application.run
52
+ # end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_pwnerer
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - Victor Costan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-04-13 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Rails deployment tool/hack.
17
+ email: victor@costan.us
18
+ executables:
19
+ - rpwn
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - bin/rpwn
24
+ - CHANGELOG
25
+ - lib/pwnage/base/dirs.rb
26
+ - lib/pwnage/base/gems.rb
27
+ - lib/pwnage/base/packages.rb
28
+ - lib/pwnage/base/startup.rb
29
+ - lib/pwnage/base.rb
30
+ - lib/pwnage/executor.rb
31
+ - lib/pwnage/scaffolds/dirs.rb
32
+ - lib/pwnage/scaffolds/gems.rb
33
+ - lib/pwnage/scaffolds/hook_mongrels.rb
34
+ - lib/pwnage/scaffolds/packages.rb
35
+ - lib/rails_pwnage.rb
36
+ - LICENSE
37
+ - README
38
+ files:
39
+ - bin/rpwn
40
+ - CHANGELOG
41
+ - lib/pwnage/base/dirs.rb
42
+ - lib/pwnage/base/gems.rb
43
+ - lib/pwnage/base/packages.rb
44
+ - lib/pwnage/base/startup.rb
45
+ - lib/pwnage/base.rb
46
+ - lib/pwnage/executor.rb
47
+ - lib/pwnage/scaffolds/dirs.rb
48
+ - lib/pwnage/scaffolds/gems.rb
49
+ - lib/pwnage/scaffolds/hook_mongrels.rb
50
+ - lib/pwnage/scaffolds/packages.rb
51
+ - lib/rails_pwnage.rb
52
+ - LICENSE
53
+ - Manifest
54
+ - README
55
+ - RUBYFORGE
56
+ - rails_pwnerer.gemspec
57
+ has_rdoc: true
58
+ homepage: http://www.costan.us/rails_pwnage
59
+ post_install_message:
60
+ rdoc_options:
61
+ - --line-numbers
62
+ - --inline-source
63
+ - --title
64
+ - Rails_pwnerer
65
+ - --main
66
+ - README
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ requirements: []
82
+
83
+ rubyforge_project: rails-pwnage
84
+ rubygems_version: 1.1.0
85
+ signing_key:
86
+ specification_version: 2
87
+ summary: Rails deployment tool/hack.
88
+ test_files: []
89
+