Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converted to Chef provisioning #174

Open
wants to merge 84 commits into
base: master
Choose a base branch
from
Open

Converted to Chef provisioning #174

wants to merge 84 commits into from

Conversation

Chan9390
Copy link
Contributor

@Chan9390 Chan9390 commented Aug 4, 2017

This PR converts the provisioning from shell to chef-solo in packer. As there is an issue with chef-solo provisioning in packer, a Vagrantfile is included under /versions/chef folder which does the same but using vagrant.

To test the vagrant build, the files (Vagrantfile and windows_2008_r2.json) should be manually moved to the metasploitable3 folder and replace the default ones.

Verification:

  • Move and replace the Vagrantfile and windows_2008_r2.json file in the main folder with those present in the /versions/chef folder
  • Build the base box using packer build --only=virtualbox-iso windows_2008_r2.json. Verify the system comes up successfully.
  • Add the base box using the command vagrant box add mtest windows_2008_r2_virtualbox.box
  • Try starting the system using vagrant up

Chan9390 added 30 commits July 28, 2017 07:08
commit 9d6666fbb9f066179e17030808bd02e3ad27a2c0
Author: Chan9390 <[email protected]>
Date:   Fri Jul 28 18:20:46 2017 +0530

    Removed cmd /c from commands

commit ef6abe66f4a79e150c9d85a0a38896b061bc5def
Author: Chan9390 <[email protected]>
Date:   Fri Jul 28 07:14:52 2017 +0530

    Added certificates
   - Updated to powershell resource
   - Added vagrant ssh
    - Converted to chef

    - Enabled RDP
   - Updated registry entries to chef resources
   - Updated registry entries
   - Updated user groups
   - Added users
   - Converted to batch resource
   - Setup IIS
   - Converted to chef
   - Added Apache Struts
   - Converted to chef
   - Added scripts to start glassfish
   - Added GlassFish
   - Converted to chef
   - Added jenkins
   - Converted to chef
   - Added code to start WAMP
   - Added WAMP
Squashed commit of the following:
   - Moved ruby
   - Moved java
   - Moved tomcat
   - Moved jdk8
   - Moved vcredist
   - Moved 7zip
   - Moved 7zip
Squashed commit of the following:
   - Added everything to default
   - put everything to default
   - Linked jenkins to java and jdk8
   - Linked backdoors to iis and wamp
   - Linked flags to iis and wamp
   - Linked ftp to iis
   - Linked rails to devkit
   - Linked devkit to 7zip and ruby
   - Linked struts to tomcat and java
   - Linked axis2 to tomcat
   - Linked elasticsearch to 7zip and jdk8
   - Linked mysql to wordpress and wamp
   - Linked webdav to wamp
   - Linked wordpress to 7zip and vcredist
   - Linked wamp to vcredist
   - Linked jmx to openjdk6
   - Linked openjdk to 7zip
   - Linked tomcat to jdk8
   - Updated wamp
   - Updated openjdk6
   - Updated glassfish
   - Updated devkit
   - Updated axis2
   - Updated vagrant_ssh
   - Updated elasticsearch
Copy link
Contributor

@Sliim Sliim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some execute / batch resources make the metasploitable cookbook not idempotent.


file 'C:\Program Files\Apache Software Foundation\tomcat\apache-tomcat-8.0.33\conf\tomcat-users.xml' do
action :delete
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not idempotent, the cookbook_file resource will override this file you don't need to delete it.


directory 'C:\vagrant' do
recursive true
action :delete
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you trying to remove a shared folder?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. If the folder C:\vagrant exists in the packer build, some issues occur when starting the box using vagrant.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm ok, I think this can be dangerous if user mounted a local directory to the guest at C:\vagrant.. no?

# Copyright:: 2017, The Authors, All Rights Reserved.

execute 'Closed port 445 for SMB' do
command 'netsh advfirewall firewall add rule name="Closed port 445 for SMB" dir=in action=block protocol=TCP localport=445'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happen if the rule already exists?

end

execute 'Starting service' do
command '"C:\Program Files\elasticsearch-1.1.1\bin\service.bat" start'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using actions [:enable, :start] for windows_service[elasticsearch-service-x64] resource? instead of this execute?

action :run
end

powershell_script 'Test response' do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

???


cookbook_file 'C:\Windows\three_of_spades.png' do
source 'flags/three_of_spades.png'
action :create
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you use the mode, owner, group etc.. attributes instead of the batch resource below?

action :create
end

file 'C:\inetpub\wwwroot\iisstart.htm' do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this here? In the flags recipe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

action [:enable, :start]
end

ruby_block 'Sleep for 15 secs' do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strange..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glassfish installation runs at the background and it needs some time to get installed. So I had introduced a time delay using ruby block resource.

action :create
end

windows_service 'wampapache' do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shoukd use resource notifications instead of a service stop/start
https://docs.chef.io/resource_common.html#notifications

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants