2017-06-06 21:46:22 +02:00
#
# Cookbook:: metasploitable
# Recipe:: drupal
#
# Copyright:: 2017, Rapid7, All Rights Reserved.
include_recipe 'metasploitable::apache'
include_recipe 'metasploitable::mysql'
include_recipe 'metasploitable::php_545'
drupal_tar = " drupal- #{ node [ :drupal ] [ :version ] } .tar.gz "
coder_tar = " coder-7.x-2.5.tar.gz "
2017-07-31 22:48:27 +02:00
files_path = File . join ( Chef :: Config [ :file_cache_path ] , 'cookbooks' , 'metasploitable' , 'files' , 'drupal' )
2017-06-06 21:46:22 +02:00
remote_file " #{ Chef :: Config [ :file_cache_path ] } / #{ drupal_tar } " do
source " #{ node [ :drupal ] [ :download_url ] } / #{ drupal_tar } "
2017-08-21 23:12:02 +02:00
mode '0644'
2017-06-06 21:46:22 +02:00
end
remote_file " #{ Chef :: Config [ :file_cache_path ] } / #{ coder_tar } " do
source " #{ node [ :drupal ] [ :download_url ] } / #{ coder_tar } "
2017-08-21 23:12:02 +02:00
mode '0644'
2017-06-06 21:46:22 +02:00
end
directory node [ :drupal ] [ :install_dir ] do
owner 'www-data'
group 'www-data'
recursive true
mode '0755'
end
log " debug logging " do
message " #{ Dir [ " #{ node [ :drupal ] [ :install_dir ] } /* " ] } "
level :info
end
execute 'untar drupal' do
cwd node [ :drupal ] [ :install_dir ]
command " tar xvzf #{ Chef :: Config [ :file_cache_path ] } / #{ drupal_tar } --strip-components 1 "
only_if { Dir [ " #{ node [ :drupal ] [ :install_dir ] } /* " ] . empty? }
end
execute 'untar default site' do
cwd node [ :drupal ] [ :sites_dir ]
2017-07-31 22:48:27 +02:00
command " tar xvzf #{ File . join ( files_path , 'default_site.tar.gz' ) } "
2017-06-06 21:46:22 +02:00
not_if { :: File . exists? ( File . join ( node [ :drupal ] [ :default_site_dir ] , 'settings.php' ) ) }
not_if { :: File . directory? ( File . join ( node [ :drupal ] [ :default_site_dir ] , 'files' ) ) }
end
execute 'untar coder module' do
cwd File . join ( node [ :drupal ] [ :all_site_dir ] , 'modules' )
command " tar xvzf #{ Chef :: Config [ :file_cache_path ] } / #{ coder_tar } "
not_if { :: File . directory? ( File . join ( node [ :drupal ] [ :all_site_dir ] , 'modules' , 'coder' ) ) }
end
execute " set permissions " do
command " chown -R www-data:www-data #{ node [ :drupal ] [ :install_dir ] } "
end
bash " create drupal database and inject data " do
code <<-EOH
mysql - h 127 . 0 . 0 . 1 - - user = " root " - - password = " sploitme " - - execute = " CREATE DATABASE drupal; "
mysql - h 127 . 0 . 0 . 1 - - user = " root " - - password = " sploitme " - - execute = " GRANT SELECT, INSERT, DELETE, CREATE, DROP, INDEX, ALTER ON drupal.* TO 'root'@'localhost' IDENTIFIED BY 'sploitme'; "
2017-07-31 22:48:27 +02:00
mysql - h 127 . 0 . 0 . 1 - - user = " root " - - password = " sploitme " drupal < #{File.join(files_path, 'drupal.sql')}
2017-06-06 21:46:22 +02:00
EOH
not_if " mysql -h 127.0.0.1 --user= \" root \" --password= \" sploitme \" --execute= \" SHOW DATABASES LIKE 'drupal' \" | grep -c drupal "
end
2017-07-20 23:38:18 +02:00
# This step is necessary because Drupal rewrites our 5_of_hearts.png,
# which causes the metadata to be lost.
cookbook_file '/var/www/html/drupal/sites/default/files/styles/large/public/field/image/5_of_hearts.png' do
source 'flags/5_of_hearts.png'
mode '777'
end
cookbook_file '/var/www/html/drupal/sites/default/files/field/image/5_of_hearts.png' do
source 'flags/5_of_hearts.png'
mode '777'
end