Win10系统在vmware/virtualbox上使用packer和vagrant安装Metasploitable3

Win10系统在vmware/virtualbox上使用packer和vagrant安装Metasploitable3

安装时可以选用vmware/virtualbox运行下载的.iso,或者virtualbox运行下载的.box(未展示)。

Installation win10 - vmware-iso / virtualbox-iso

Preparation: metasploitable3, packer, vmware/[virtualbox, vagrant, vagrant-reload].
注:若使用 vitualbox-iso, 须在C盘安装 virtualbox, packer, vagrant.

在powershell里面cd到metasploitable3目录下,输入

packer build --only=vmware-iso ./packer/templates/windows_2008_r2.json   # vmawre
.\build.ps1 windows2008  # powershell - virtualbox

其中在这一步会出现很多问题。

https://github.com/rapid7/metasploitable3 中的packer/templates出了很多问题,可能是因为packer的版本不匹配,听说packer v1.5.3可以解决这个问题,但没有尝试,以下是自己遇到的问题的记录。

  • 问题一

    在使用https://github.com/rapid7/metasploitable3中直接下载的packer -> templates 时,
    如果安装vmware-iso版本,会显示:

    unknown configuration key: '"iso_checksum_type"'
    

    如果安装virtualbox-iso版本,会显示:

    Deprecated configuration key: 'iso_checksum_type'. Please call `packer fix`
    against your template to update your template to be compatible with the current
    version of Packer. Visit https://www.packer.io/docs/commands/fix/ for more
    detail.
    

    于是使用packer fix 文件夹packer\templates 中的windows_2008_r2.json, ubuntu_1404.json, 文件夹packer\templates\pro 中的windows_2008_r2_pro.json, ubuntu_1404_pro.json

  • 问题二

    如果安装vmware-iso版本,会显示:

    Failed to parse file as legacy JSON template: if you are using an HCL template, check your file extensions; they should be either *.pkr.hcl or *.pkr.json; see the docs for more details: https://www.packer.io/docs/templates/hcl_templates.
    Original error: Error parsing JSON: invalid character 'ÿ' looking for beginning of value
    At line 1, column 1 (offset 1):
      1: �
          ^
    

    如果安装virtualbox-iso版本,会显示与上面同样错误,并加上以下提示:

    Error building the Vagrant box using Packer. Please check the output above for any error messages.
    所在位置 D:\Virtual Machines\Metasploitable3\metasploitable3\build.ps1:157 字符: 10
    +          throw "Error building the Vagrant box using Packer. Please c ...
    +          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : OperationStopped: (Error building ...error messages.:String) [], Runtime
       Exception
        + FullyQualifiedErrorId : Error building the Vagrant box using Packer. Please check the output abo
       ve for any error messages.
    

    查询一番有说linux的LF没有换成windows的CRLF(我打开文件,原本即是CRLF,确定更换后问题没有改变),也有可能是编码没设为UTF-8,于是对于packer fix的两个windows文件(fix的另外两个linux忽略)都进行了更换。

  • 问题三

    如果安装vmware-iso版本,会显示:

    Warning: Warning when preparing build: "vmware-iso"
    
    Your vmx data contains the following variable(s), which Packer normally sets
    when it generates its own default vmx template. This may cause your build to
    fail or behave unpredictably: numvcpus, memsize, scsi0.virtualDev
    
    
    vmware-iso: output will be in this color.
    
    ==> vmware-iso: Retrieving ISO
    ==> vmware-iso: Trying http://download.microsoft.com/download/7/5/E/75EC4E54-5B02-42D6-8879-D8D3A25FBEF7/7601.17514.101119-1850_x64fre_server_eval_en-us-GRMSXEVAL_EN_DVD.iso
    ==> vmware-iso: Trying http://download.microsoft.com/download/7/5/E/75EC4E54-5B02-42D6-8879-D8D3A25FBEF7/7601.17514.101119-1850_x64fre_server_eval_en-us-GRMSXEVAL_EN_DVD.iso?checksum=md5%3A4263be2cf3c59177c45085c0a7bc6ca5
    ==> vmware-iso: Download failed bad response code: 404
    ==> vmware-iso: error downloading ISO: [bad response code: 404]
    Build 'vmware-iso' errored after 1 second 859 milliseconds: error downloading ISO: [bad response code: 404]
    
    ==> Wait completed after 1 second 859 milliseconds
    
    ==> Some builds didn't complete successfully and had errors:
    --> vmware-iso: error downloading ISO: [bad response code: 404]
    
    ==> Builds finished but no artifacts were created.
    

    如果安装virtualbox-iso版本,会显示:

    virtualbox-iso: output will be in this color.
    
    ==> virtualbox-iso: Retrieving Guest additions
    ==> virtualbox-iso: Trying C:\Program Files\Oracle\VirtualBox/VBoxGuestAdditions.iso
    ==> virtualbox-iso: Trying file://C:/Program%20Files/Oracle/VirtualBox/VBoxGuestAdditions.iso
    ==> virtualbox-iso: file://C:/Program%20Files/Oracle/VirtualBox/VBoxGuestAdditions.iso => C:/Program Files/Oracle/VirtualBox/VBoxGuestAdditions.iso
    ==> virtualbox-iso: Retrieving ISO
    ... # same as above except 'virtualbo-iso' rather than 'vmware-iso'
    # And some more info
    Error building the Vagrant box using Packer. Please check the output above for any error messages.
    所在位置 D:\Virtual Machines\Metasploitable3\metasploitable3\build.ps1:157 字符: 10
    +          throw "Error building the Vagrant box using Packer. Please c ...
    +          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : OperationStopped: (Error building ...error messages.:String) [], Runtime Exception
        + FullyQualifiedErrorId : Error building the Vagrant box using Packer. Please check the output above for any error messages.
    

    报错汇总:vmware: 含有已有默认数据的部分vmx data(后文忽略了);Retrieving ISO : 404
    virtualbox:Retrieving ISO : 404Error building the Vagrant box using Packer - 文件位置:metasploitable3\build.ps1:157 字符: 10。

    先看错误Error building the Vagrant box using Packer用Packer搭建时出现问题,源于从未修改的metasploitable3\build.ps1:157 字符: 10,代码如下:

    If ($(Test-Path "packer\builds\$($os_full)_virtualbox_$boxversion.box") -eq $True) {
    
            Write-Host "It looks like the Vagrant box already exists. Skipping the Packer build."
        
        } else {
    
            cmd.exe /c $packer build --only=virtualbox-iso packer\templates\$os_full.json
    
            if($?) {
              Write-Host "Box successfully built by Packer."
            } else {
             throw "Error building the Vagrant box using Packer. Please check the output above for any error messages."
            }
        }
    

    但其实这应该和 Retrieving ISO : 404 是同一个问题。可以看到两个渠道都有的很明显的 Retrieving ISO : 404 的错误,在一处CSDN博客Metasploitable3 + VMware 安装教程上发现了重要的有关404的消息:文件windows_2008_r2.json中的下载链接(windows Server 2008 r2.iso的iso_url: http://download.microsoft.com/download/7/5/E/75EC4E54-5B02-42D6-8879-D8D3A25FBEF7/7601.17514.101119-1850_x64fre_server_eval_en-us-GRMSXEVAL_EN_DVD.iso , iso_checksum: 4263be2cf3c59177c45085c0a7bc6ca5 )已经被微软官方移除了,无法使用。

Microsoft removed
所以在网上寻找windows_2008_r2.iso并下载至本地(注意各种虚拟机iso等类型映像和文件的管理),并改变windows_2008_r2.json中的iso_url, iso_checksum。

此时输入packer build --only=vmware-iso ./packer/templates/windows_2008_r2.json.\build.ps1 windows2008,成功。之后都用vmware进行iso安装方法的操作,virtualbox的iso安装方法大致相同。

注:因为这里从powershell启动,不要关闭窗口。如果没有迁移映像文件,每次关闭powershell后,虚拟机文件都会被删除。

迁移vmx

在powershell仍在运行过程中,vmware会在metasploitable3文件夹中产生如下新文件夹,复制output-vmware-iso文件夹并可以选择改名。在关闭powershell之后,图中文件夹会自动删除,复制的文件夹被保留,之后用vmware进行虚拟机扫描即可。

vmware会在metasploitable文件夹中产生如下新文件夹:
vm-iso files

Operation

我选择的iso版本初次进入界面如下。

win2k8
加载好之后会显示桌面,我们可以通过CTRL+ALT+DELETE登录、切换用户如下图。
win2k8-user

其中用户vagrant的用户名和密码相同:vagrant。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值