From a66ff125d94d8085354a3696487f3dfe00475801 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Wed, 19 Apr 2017 16:25:46 -0500 Subject: [PATCH 1/4] Add readme_app. Also moved ruby installs out into its own recipe and included that in readme_app and sinatra recipes. --- Vagrantfile | 1 + .../files/readme_app/readme_app | 40 +++++++++++++++++++ .../metasploitable/recipes/readme_app.rb | 33 +++++++++++++++ .../metasploitable/recipes/ruby23.rb | 15 +++++++ .../metasploitable/recipes/sinatra.rb | 9 +---- 5 files changed, 90 insertions(+), 8 deletions(-) create mode 100644 chef/cookbooks/metasploitable/files/readme_app/readme_app create mode 100644 chef/cookbooks/metasploitable/recipes/readme_app.rb create mode 100644 chef/cookbooks/metasploitable/recipes/ruby23.rb diff --git a/Vagrantfile b/Vagrantfile index 1174f08..ac31814 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -169,6 +169,7 @@ Vagrant.configure("2") do |config| chef.add_recipe "metasploitable::docker" chef.add_recipe "metasploitable::samba" chef.add_recipe "metasploitable::unrealircd" + chef.add_recipe "metasploitable::readme_app" end end end diff --git a/chef/cookbooks/metasploitable/files/readme_app/readme_app b/chef/cookbooks/metasploitable/files/readme_app/readme_app new file mode 100644 index 0000000..377babf --- /dev/null +++ b/chef/cookbooks/metasploitable/files/readme_app/readme_app @@ -0,0 +1,40 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: readme_app +# Required-Start: $local_fs +# Required-Stop: $local_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# X-Interactive: false +# Short-Description: Init script for readme_app +# Description: Start/stop readme_app +### END INIT INFO + +DESC="readme_app" +NAME=readme_app +#DAEMON= + +do_start() +{ + echo "Starting readme_app."; + cd /opt/readme_app + rails s & +} + +do_stop() +{ + echo "Stopping readme_app." + killall ruby +} + + +case "$1" in + start) + do_start + ;; + stop) + do_stop + ;; +esac + +exit 0 \ No newline at end of file diff --git a/chef/cookbooks/metasploitable/recipes/readme_app.rb b/chef/cookbooks/metasploitable/recipes/readme_app.rb new file mode 100644 index 0000000..5f0d09a --- /dev/null +++ b/chef/cookbooks/metasploitable/recipes/readme_app.rb @@ -0,0 +1,33 @@ +# +# Cookbook:: metasploitable +# Recipe:: readme_app +# +# Copyright:: 2017, Rapid7, All Rights Reserved. +# +# + +include_recipe 'metasploitable::ruby23' + +package 'git' + +directory '/opt/readme_app' do + mode '0777' +end + +bash "clone the readme app and install gems" do + code <<-EOH + cd /opt/ + git clone https://github.com/jbarnett-r7/metasploitable3-readme.git readme_app + cd readme_app + bundle install + EOH +end + +cookbook_file '/etc/init.d/readme_app' do + source 'readme_app/readme_app' + mode '760' +end + +service 'readme_app' do + action [:enable, :start] +end diff --git a/chef/cookbooks/metasploitable/recipes/ruby23.rb b/chef/cookbooks/metasploitable/recipes/ruby23.rb new file mode 100644 index 0000000..04ac236 --- /dev/null +++ b/chef/cookbooks/metasploitable/recipes/ruby23.rb @@ -0,0 +1,15 @@ +# +# Cookbook:: metasploitable +# Recipe:: ruby23 +# +# Copyright:: 2017, Rapid7, All Rights Reserved. +# +# + +execute 'apt-get update' do + command 'apt-get update' +end + +package 'ruby2.3' +package 'ruby2.3-dev' +package 'bundler' diff --git a/chef/cookbooks/metasploitable/recipes/sinatra.rb b/chef/cookbooks/metasploitable/recipes/sinatra.rb index 72098d2..b3acf12 100644 --- a/chef/cookbooks/metasploitable/recipes/sinatra.rb +++ b/chef/cookbooks/metasploitable/recipes/sinatra.rb @@ -7,14 +7,7 @@ # include_recipe 'metasploitable::sinatra' - -apt_repository 'rvm' do - uri 'ppa:brightbox/ruby-ng' -end - -package 'ruby2.3' - -package 'bundler' +include_recipe 'metasploitable::ruby23' directory '/opt/sinatra' do mode '0777' From 6462446b44f98fd767337e9641cd9b3dc88fb444 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Thu, 20 Apr 2017 13:43:11 -0500 Subject: [PATCH 2/4] Fix bundle install and startup errors. --- .../metasploitable/recipes/readme_app.rb | 15 ++++++++++----- chef/cookbooks/metasploitable/recipes/ruby23.rb | 4 ++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/chef/cookbooks/metasploitable/recipes/readme_app.rb b/chef/cookbooks/metasploitable/recipes/readme_app.rb index 5f0d09a..ba2f400 100644 --- a/chef/cookbooks/metasploitable/recipes/readme_app.rb +++ b/chef/cookbooks/metasploitable/recipes/readme_app.rb @@ -9,6 +9,7 @@ include_recipe 'metasploitable::ruby23' package 'git' +package 'nodejs' directory '/opt/readme_app' do mode '0777' @@ -18,16 +19,20 @@ bash "clone the readme app and install gems" do code <<-EOH cd /opt/ git clone https://github.com/jbarnett-r7/metasploitable3-readme.git readme_app - cd readme_app - bundle install EOH end -cookbook_file '/etc/init.d/readme_app' do - source 'readme_app/readme_app' - mode '760' +cookbook_file '/opt/readme_app/start.sh' do + source 'readme_app/start.sh' + mode '0777' +end + +cookbook_file '/etc/init/readme_app.conf' do + source 'readme_app/readme_app.conf' + mode '0777' end service 'readme_app' do + supports restart: false, start: true, reload: false, status: false action [:enable, :start] end diff --git a/chef/cookbooks/metasploitable/recipes/ruby23.rb b/chef/cookbooks/metasploitable/recipes/ruby23.rb index 04ac236..46eaabf 100644 --- a/chef/cookbooks/metasploitable/recipes/ruby23.rb +++ b/chef/cookbooks/metasploitable/recipes/ruby23.rb @@ -6,6 +6,10 @@ # # +apt_repository 'rvm' do + uri 'ppa:brightbox/ruby-ng' +end + execute 'apt-get update' do command 'apt-get update' end From 1c2cea73f2e746aee5f58e4e2842d8e4f98c54d5 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Thu, 20 Apr 2017 14:44:26 -0500 Subject: [PATCH 3/4] Add missing files. --- .../metasploitable/files/readme_app/readme_app.conf | 5 +++++ chef/cookbooks/metasploitable/files/readme_app/start.sh | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 chef/cookbooks/metasploitable/files/readme_app/readme_app.conf create mode 100644 chef/cookbooks/metasploitable/files/readme_app/start.sh diff --git a/chef/cookbooks/metasploitable/files/readme_app/readme_app.conf b/chef/cookbooks/metasploitable/files/readme_app/readme_app.conf new file mode 100644 index 0000000..f76b220 --- /dev/null +++ b/chef/cookbooks/metasploitable/files/readme_app/readme_app.conf @@ -0,0 +1,5 @@ +description 'Run ReadMe App' +author 'metasploitable3' + +start on runlevel [2345] +exec "/opt/readme_app/start.sh" diff --git a/chef/cookbooks/metasploitable/files/readme_app/start.sh b/chef/cookbooks/metasploitable/files/readme_app/start.sh new file mode 100644 index 0000000..9c3efa7 --- /dev/null +++ b/chef/cookbooks/metasploitable/files/readme_app/start.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +cd /opt/readme_app +bundle install +rails s -b 0.0.0.0 From 27634d321b33e0d1cb5f42fe7066d070a12d5a1c Mon Sep 17 00:00:00 2001 From: wchen-r7 Date: Thu, 20 Apr 2017 15:14:38 -0500 Subject: [PATCH 4/4] change port to 3500 because 3000 is occupied by the bot --- chef/cookbooks/metasploitable/files/readme_app/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chef/cookbooks/metasploitable/files/readme_app/start.sh b/chef/cookbooks/metasploitable/files/readme_app/start.sh index 9c3efa7..2e54d87 100644 --- a/chef/cookbooks/metasploitable/files/readme_app/start.sh +++ b/chef/cookbooks/metasploitable/files/readme_app/start.sh @@ -2,4 +2,4 @@ cd /opt/readme_app bundle install -rails s -b 0.0.0.0 +rails s -b 0.0.0.0 -p 3500