From 9360d8376c0eae6c8e5e6a9a02f0e363ed09764c Mon Sep 17 00:00:00 2001 From: wchen-r7 Date: Wed, 5 Apr 2017 15:54:14 -0500 Subject: [PATCH] Use upstart script --- .../metasploitable/files/sinatra/Gemfile | 5 ++-- .../metasploitable/files/sinatra/README.txt | 2 +- .../files/sinatra/{start.rb => server.rb} | 7 +++++ .../metasploitable/files/sinatra/sinatra.conf | 5 ++++ .../metasploitable/files/sinatra/sinatra.sh | 2 +- .../metasploitable/recipes/sinatra.rb | 27 +++++-------------- 6 files changed, 23 insertions(+), 25 deletions(-) rename chef/cookbooks/metasploitable/files/sinatra/{start.rb => server.rb} (74%) create mode 100644 chef/cookbooks/metasploitable/files/sinatra/sinatra.conf diff --git a/chef/cookbooks/metasploitable/files/sinatra/Gemfile b/chef/cookbooks/metasploitable/files/sinatra/Gemfile index d5ba5fc..9e129f4 100644 --- a/chef/cookbooks/metasploitable/files/sinatra/Gemfile +++ b/chef/cookbooks/metasploitable/files/sinatra/Gemfile @@ -1,6 +1,5 @@ source 'https://rubygems.org' -gem 'rack', '1.6.5' -gem 'sinatra', '1.4.8' -gem 'erubis' +gem 'rack', '2.0.1' +gem 'sinatra', '2.0.0rc2' gem 'erubis' gem 'activesupport' diff --git a/chef/cookbooks/metasploitable/files/sinatra/README.txt b/chef/cookbooks/metasploitable/files/sinatra/README.txt index 588c13c..1ad1eab 100644 --- a/chef/cookbooks/metasploitable/files/sinatra/README.txt +++ b/chef/cookbooks/metasploitable/files/sinatra/README.txt @@ -28,4 +28,4 @@ And then finally: $ ruby start.rb -The server should start on port 8080. +The server should start on port 8181. diff --git a/chef/cookbooks/metasploitable/files/sinatra/start.rb b/chef/cookbooks/metasploitable/files/sinatra/server.rb similarity index 74% rename from chef/cookbooks/metasploitable/files/sinatra/start.rb rename to chef/cookbooks/metasploitable/files/sinatra/server.rb index df0b465..6e48811 100644 --- a/chef/cookbooks/metasploitable/files/sinatra/start.rb +++ b/chef/cookbooks/metasploitable/files/sinatra/server.rb @@ -3,6 +3,7 @@ require 'sinatra' require 'erubis' require 'active_support' +require 'webrick' MYSECRET = 'a7aebc287bba0ee4e64f947415a94e5f' @@ -10,6 +11,12 @@ set :environment, :development set :bind, '0.0.0.0' set :port, 8181 +# These settings are specific for Sinatra 2.0.0rc2 +set :logging, false +set :quiet, true +dev_null = WEBrick::Log::new("/dev/null", 7) +set :server_settings, {:Logger => dev_null, :AccessLog => dev_null} + use Rack::Session::Cookie, :key => "_metasploitable", :path => "/", diff --git a/chef/cookbooks/metasploitable/files/sinatra/sinatra.conf b/chef/cookbooks/metasploitable/files/sinatra/sinatra.conf new file mode 100644 index 0000000..b090155 --- /dev/null +++ b/chef/cookbooks/metasploitable/files/sinatra/sinatra.conf @@ -0,0 +1,5 @@ +description 'Run vulnerable Sinatra' +author 'metasploitable3' + +start on runlevel [2345] +exec "/opt/sinatra/start.sh" diff --git a/chef/cookbooks/metasploitable/files/sinatra/sinatra.sh b/chef/cookbooks/metasploitable/files/sinatra/sinatra.sh index 71de83a..fdceaea 100644 --- a/chef/cookbooks/metasploitable/files/sinatra/sinatra.sh +++ b/chef/cookbooks/metasploitable/files/sinatra/sinatra.sh @@ -12,7 +12,7 @@ case "$1" in start) - /opt/sinatra/start.rb + /opt/sinatra/start.sh ;; *) echo "Usage: start {start}" >&2 diff --git a/chef/cookbooks/metasploitable/recipes/sinatra.rb b/chef/cookbooks/metasploitable/recipes/sinatra.rb index 4bafebf..72098d2 100644 --- a/chef/cookbooks/metasploitable/recipes/sinatra.rb +++ b/chef/cookbooks/metasploitable/recipes/sinatra.rb @@ -9,43 +9,30 @@ include_recipe 'metasploitable::sinatra' apt_repository 'rvm' do - uri 'ppa:rael-gc/rvm' + uri 'ppa:brightbox/ruby-ng' end -package 'rvm' +package 'ruby2.3' -bash 'run rvm.sh' do - code <<-EOH - source /etc/profile.d/rvm.sh - rvmsudo rvm install ruby-2.3.1 - rvm --default use 2.3.1 - gem install bundler - EOH -end +package 'bundler' directory '/opt/sinatra' do mode '0777' end -['Gemfile', 'README.txt', 'check.rb', 'poc.rb', 'start.rb'].each do |fname| +['Gemfile', 'README.txt', 'check.rb', 'poc.rb', 'start.sh', 'server.rb'].each do |fname| cookbook_file "/opt/sinatra/#{fname}" do source "sinatra/#{fname}" mode '0777' end end -bash 'bundle install sinatra' do - code <<-EOH - cd /opt/sinatra - bundle install - EOH -end - -cookbook_file '/etc/init.d/sinatra' do - source 'sinatra/sinatra.sh' +cookbook_file '/etc/init/sinatra.conf' do + source 'sinatra/sinatra.conf' mode '0777' end service 'sinatra' do + supports restart: false, start: true, reload: false, status: false action [:enable, :start] end