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

Run custom box using mech #45

Open
stolzoffd9 opened this issue Jul 14, 2018 · 11 comments
Open

Run custom box using mech #45

stolzoffd9 opened this issue Jul 14, 2018 · 11 comments

Comments

@stolzoffd9
Copy link

stolzoffd9 commented Jul 14, 2018

Hi,

I have created .box using packer and i have stored it on my local system. How can use it using mech

error what i am getting.

$ mech init windows_2008_r2_vmware.box
Initializing mech
A Mechfile has been initialized and placed in this directory. You
are now ready to mech up your first virtual environment!

$ mech up
Provided box name is not valid
Loading metadata for box 'windows_2008_r2_vmware'
Bad response from HashiCorp's Vagrant Cloud API: 404 Client Error: Not Found for url: https://app.vagrantup.com/windows_2008_r2_vmware/boxes/boxes

$ mech start
Provided box name is not valid
Loading metadata for box 'windows_2008_r2_vmware'
Bad response from HashiCorp's Vagrant Cloud API: 404 Client Error: Not Found for url: https://app.vagrantup.com/windows_2008_r2_vmware/boxes/boxes

@stolzoffd9 stolzoffd9 changed the title metasploitable 3 Run custom box using mech Jul 14, 2018
@Kronuz
Copy link
Collaborator

Kronuz commented Jul 14, 2018

I haven’t tried this too much, but I think you need to give it the name as well (during init). Create a new directory and inside it do:

mech init windows_2008_r2 /some/path/to/windows_2008_r2_vmware

Please let me know if this works.

@dynomite567
Copy link

Hi, I have attempted this. I can say that this does not work, even with the --name option.

Simply put, the same output occurs:

$ mech init --name=metasploitable3-ub1404 /path/to/the/metasploitable3-ub1404-vmware.box
Initializing mech
A Mechfile has been initialized and placed in this directory. You
are now ready to mech up your first virtual environment!

$ mech up
Provided box name is not valid
Loading metadata for box 'metasploitable3-ub1404-vmware'
Bad response from HashiCorp's Vagrant Cloud API: 404 Client Error: Not Found for url: https://app.vagrantup.com/metasploitable3-ub1404-vmware/boxes/boxes

And for without the --name option,

$ mech init metasploitable3-ub1404 ~/mech/metasploitable3-ub1404-vmware.box
Initializing mech
A Mechfile has been initialized and placed in this directory. You
are now ready to mech up your first virtual environment!

$ mech up
Provided box name is not valid
Loading metadata for box 'metasploitable3-ub1404'
Bad response from HashiCorp's Vagrant Cloud API: 404 Client Error: Not Found for url: https://app.vagrantup.com/metasploitable3-ub1404/boxes/boxes

Here is the generated Mechfile (ran without --name):

$ cat Mechfile
{
  "box": "metasploitable3-ub1404",
  "file": "/path/to/the/metasploitable3-ub1404-vmware.box",
  "name": null
}

@espoelstra
Copy link

You should use mech box add NAME PATH before attempting to mech init NAME. They have done a great job of keeping the CLI interface very similar to Vagrant for most operations.

See https://github.com/mechboxes/mech/blob/master/mech/mech.py#L206 for syntax or use mech box --help to see the options.

@espoelstra
Copy link

espoelstra commented Apr 8, 2019

It appears there is an issue with the tar syntax on Ubuntu 18.04, mech tries to use *.vmx but without --wildcards it gets interpreted as a filename and fails.

mech box add eval-win10 /projects/github/boxcutter-windows/box/vmware/eval-win10x64-enterprise-nocm-1.0.4.box
Checking box 'eval-win10' integrity...
tar: Pattern matching characters used in file names
tar: Use --wildcards to enable pattern matching, or --no-wildcards to suppress this warning
tar: *.vmx: Not found in archive
tar: Exiting with failure status due to previous errors

But a vmx file IS there.

tar --list -f /projects/github/boxcutter-windows/box/vmware/eval-win10x64-enterprise-nocm-1.0.4.box
Vagrantfile
disk-s001.vmdk
disk-s002.vmdk
disk-s003.vmdk
disk-s004.vmdk
disk-s005.vmdk
disk-s006.vmdk
disk-s007.vmdk
disk-s008.vmdk
disk-s009.vmdk
disk-s010.vmdk
disk-s011.vmdk
disk.vmdk
eval-win10x64-enterprise.nvram
eval-win10x64-enterprise.vmsd
eval-win10x64-enterprise.vmx
eval-win10x64-enterprise.vmxf
metadata.json

@espoelstra
Copy link

It looks like this should be working from a glance at this function, but I haven't fully stepped through it yet. https://github.com/mechboxes/mech/blob/master/mech/utils.py#L324

@espoelstra
Copy link

OK, it looks like the \b--wildcards\b isn't matching properly in the tar --help subprocess output, though removing the \b bits seems to have fixed it in my case and I was able to get the box properly added.

This was under Python 3.6.8 on Ubuntu 18.04 (using Pyenv to manage versions but that shouldn't matter in this case).

@espoelstra
Copy link

Urrggggh, got the box added, but had to supply a path to the box again when doing mech init instead of just mech init JUST_ADDED_BOX_NAME so it was mech init NAME PATH, though I used the ~/.mech/boxes/NAME/FILENAME.box as the PATH, but it still won't let me mech up even though it successfully creates a Mechfile in the directory.

@espoelstra
Copy link

Looks like this project is currently lacking any unit or integration tests which makes trying to troubleshoot a game of cat and mouse and quite likely to lead to unintended side effects if any changes are made to how things work. I was really excited about having a Python alternative to Vagrant that doesn't cost a bunch of money, but not having any tests makes it very hard to recommend or even to try to contribute because I'll have no idea what I'm breaking when I try to fix things.

@espoelstra
Copy link

So it looks like the trouble is related to local mech box add NOT properly going through the extraction of the VMX file and other bits to the ~/.mech/boxes/BOXNAME/ path so when trying to bring it up by name it doesn't have a VMX to reference and match against. If I find some more time I'll take a look deeper, but for now I'm off to manually start some VMs with vmrun.

@network-shark
Copy link

@espoelstra Do you have a pull request for this issue . I would try it :) . It seems that there is an issue with some freebsd images . I can't import them . Than I started to build my own box , but now I can't add it .... .

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

No branches or pull requests

6 participants
@Kronuz @network-shark @espoelstra @dynomite567 @stolzoffd9 and others