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

The SSH connection was unexpectedly closed by the remote end. #610

Open
RamH101 opened this issue Oct 11, 2023 · 5 comments
Open

The SSH connection was unexpectedly closed by the remote end. #610

RamH101 opened this issue Oct 11, 2023 · 5 comments

Comments

@RamH101
Copy link

RamH101 commented Oct 11, 2023

when creating the local metasploitable workspace i got the following error messege:The SSH connection was unexpectedly closed by the remote end. This usually indicates that SSH within the guest machine was unable to
properly start up. Please boot the VM in GUI mode to check whether
it is booting properly.i dont think that its my vagrant version because to other people with this version the downloading process of metasploitable seemed to be smooth.i used this vagrant version because with 2.3.7 version of vagrant i got this error messege:
Shell:Cmd
Command: hostname
Message: Digest initialization failed: initialization error**

OS: Windows10 22H2
Packer Version:1.9.4
Vagrant Version:2.3.8dev tools amd64 windows
VirtualBox Version:7.0

PS C:\WINDOWS\system32> mkdir metasploitable3-workspace >> cd metasploitable3-workspace

Invoke-WebRequest -Uri "https://raw.githubusercontent.com/rapid7/metasploitable3/master/Vagrantfile" -OutFile "Vagrantfile"
vagrant up

Directory: C:\WINDOWS\system32

Mode LastWriteTime Length Name


d----- 10/11/2023 9:17 PM metasploitable3-workspace
Bringing machine 'ub1404' up with 'virtualbox' provider...
Bringing machine 'win2k8' up with 'virtualbox' provider...
==> ub1404: Importing base box 'rapid7/metasploitable3-ub1404'...
==> ub1404: Matching MAC address for NAT networking...
==> ub1404: Checking if box 'rapid7/metasploitable3-ub1404' version '0.1.12-weekly' is up to date...
==> ub1404: Setting the name of the VM: Metasploitable3-ub1404
==> ub1404: Clearing any previously set network interfaces...
==> ub1404: Preparing network interfaces based on configuration...
ub1404: Adapter 1: nat
ub1404: Adapter 2: hostonly
==> ub1404: Forwarding ports...
ub1404: 22 (guest) => 2222 (host) (adapter 1)
==> ub1404: Running 'pre-boot' VM customizations...
==> ub1404: Booting VM...
==> ub1404: Waiting for machine to boot. This may take a few minutes...
ub1404: SSH address: 127.0.0.1:2222
ub1404: SSH username: vagrant
ub1404: SSH auth method: password
ub1404:
ub1404: Inserting generated public key within guest...
ub1404: Removing insecure key from the guest if it's present...
ub1404: Key inserted! Disconnecting and reconnecting using new SSH key...
==> ub1404: Machine booted and ready!
==> ub1404: Checking for guest additions in VM...
ub1404: No guest additions were detected on the base box for this VM! Guest
ub1404: additions are required for forwarded ports, shared folders, host only
ub1404: networking, and more. If SSH fails on this machine, please install
ub1404: the guest additions and repackage the box to continue.
ub1404:
ub1404: This is not an error message; everything may continue to work properly,
ub1404: in which case you may ignore this message.
==> ub1404: Setting hostname...
The SSH connection was unexpectedly closed by the remote end. This
usually indicates that SSH within the guest machine was unable to
properly start up. Please boot the VM in GUI mode to check whether
it is booting properly.

@jmartin-tech
Copy link
Contributor

This error suggests vagrant may have changed the requirements for configuring a hostname on a launched VM.

Try removing the hostname configuration lines from the Vagrantfile:

diff --git a/Vagrantfile b/Vagrantfile
index a23fb97..ff935b7 100644
--- a/Vagrantfile
+++ b/Vagrantfile
@@ -5,7 +5,6 @@ Vagrant.configure("2") do |config|
   config.vm.synced_folder '.', '/vagrant', disabled: true
   config.vm.define "ub1404" do |ub1404|
     ub1404.vm.box = "rapid7/metasploitable3-ub1404"
-    ub1404.vm.hostname = "metasploitable3-ub1404"
     config.ssh.username = 'vagrant'
     config.ssh.password = 'vagrant'

@@ -20,7 +19,6 @@ Vagrant.configure("2") do |config|
   config.vm.define "win2k8" do |win2k8|
     # Base configuration for the VM and provisioner
     win2k8.vm.box = "rapid7/metasploitable3-win2k8"
-    win2k8.vm.hostname = "metasploitable3-win2k8"
     win2k8.vm.communicator = "winrm"
     win2k8.winrm.retry_limit = 60
     win2k8.winrm.retry_delay = 10

Further testing is needed to determine what versions are impacted and if this change should be applied to the projects Vagrantfile.

@RamH101
Copy link
Author

RamH101 commented Oct 13, 2023

@jmartin-tech Hey! Thank you for answering,i tried removing the hostname configuration lines from the vagrant file but now when i run vagrant up d897f69(d897f69 is the vagrant environment id) i get the following error:There is a syntax error in the following Vagrantfile. The syntax error
message is reproduced below for convenience: C:/WINDOWS/system32/metasploitable3-workspace/Vagrantfile:12: syntax error, unexpected `end', expecting end-of-input end

i uploaded a picture of the output and another picture that shows the vagrantfile in notepad++

notepad++

vagrant output

@jmartin-tech
Copy link
Contributor

jmartin-tech commented Oct 13, 2023

@RamH101, your Vagrantfile is significantly modified, only the two *.vm.hostname = lines should have needed to be removed to at least get the ub1404 vm to start.

Based on the image posted your changes resulted in syntax that does in fact contain an mis-matched end on line 12 as the following lines that are part of the ub1404 config are also removed:

Vagrant.configure("2") do |config|
  config.vm.synced_folder '.', '/vagrant', disabled: true
  config.vm.define "ub1404" do |ub1404|
    config.ssh.username = 'vagrant'
    config.ssh.password = 'vagrant'

After some testing recent on Window I suspect there are some additional changes needed to launch the VMs on a windows host.

Testing with env versions of:
OS: Windows 10 22H2
Vagrant: 2.3.4
Virtualbox: 7.0.6

I ran into hashicorp/vagrant#8878 for some reason and need to use the workaround offered of adding the following early in the Vagrantfile to get both the VMs to start on windows.

class VagrantPlugins::ProviderVirtualBox::Action::Network
  def dhcp_server_matches_config?(dhcp_server, config)
    true
  end
end

Another known issue that can occur with the Vagrantfile, can be a need to change the network config for the ub1404 vm to be an IP that is valid on your local host only network the hardcoded value is not always in the same network mask as the host if configured to provide.

@jmartin-tech
Copy link
Contributor

jmartin-tech commented Oct 13, 2023

@RamH101, please note all these items are drift in the configuration file due to upstream changes in vagrant and virtualbox tooling and not necessarily a bug in the metasploitable3 project.

The quick-start is an initial guideline for utilizing the published pre-built VM available in VagrantCloud. Best efforts are made to maintain the files for current versions and the project appreciates the report you have made here.

@RamH101
Copy link
Author

RamH101 commented Oct 15, 2023

@jmartin-tech Hey again! Thank you for all of your help so far,Now i get the following two errors in powershell(this is the output): PS C:\WINDOWS\system32\metasploitable3-workspace> vagrant up
Bringing machine 'ub1404' up with 'virtualbox' provider...
Bringing machine 'win2k8' up with 'virtualbox' provider...
==> ub1404: Importing base box 'rapid7/metasploitable3-ub1404'...
==> ub1404: Matching MAC address for NAT networking...
==> ub1404: Checking if box 'rapid7/metasploitable3-ub1404' version '0.1.12-weekly' is up to date...
D:/HashiCorp/Vagrant/embedded/gems/gems/log4r-1.1.10/lib/log4r/repository.rb:65: warning: Exception in finalizer #<Tempfile::Remover:0x000002a69c1ccc68 @pid=24328, @tmpfile=#<File:C:/Users/ramw1/AppData/Local/Temp/vagrant-load-metadata20231015-24328-tp7lqg (closed)>>
D:/HashiCorp/Vagrant/embedded/mingw64/lib/ruby/3.1.0/tempfile.rb:265:in unlink': Permission denied @ apply2files - C:/Users/ramw1/AppData/Local/Temp/vagrant-load-metadata20231015-24328-tp7lqg (Errno::EACCES) from D:/HashiCorp/Vagrant/embedded/mingw64/lib/ruby/3.1.0/tempfile.rb:265:in call'
from D:/HashiCorp/Vagrant/embedded/gems/gems/log4r-1.1.10/lib/log4r/repository.rb:65:in block (2 levels) in reassign_any_children' from D:/HashiCorp/Vagrant/embedded/gems/gems/log4r-1.1.10/lib/log4r/repository.rb:63:in each'
from D:/HashiCorp/Vagrant/embedded/gems/gems/log4r-1.1.10/lib/log4r/repository.rb:63:in block in reassign_any_children' from D:/HashiCorp/Vagrant/embedded/mingw64/lib/ruby/3.1.0/monitor.rb:202:in synchronize'
from D:/HashiCorp/Vagrant/embedded/mingw64/lib/ruby/3.1.0/monitor.rb:202:in mon_synchronize' from D:/HashiCorp/Vagrant/embedded/gems/gems/log4r-1.1.10/lib/log4r/repository.rb:62:in reassign_any_children'
from D:/HashiCorp/Vagrant/embedded/gems/gems/log4r-1.1.10/lib/log4r/logger.rb:68:in deal_with_inheritance' from D:/HashiCorp/Vagrant/embedded/gems/gems/log4r-1.1.10/lib/log4r/logger.rb:36:in initialize'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/runner.rb:17:in new' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/runner.rb:17:in initialize'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/builtin/call.rb:37:in new' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/builtin/call.rb:37:in call'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:48:in call' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:127:in block in finalize_action'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:48:in call' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/builder.rb:180:in call'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/runner.rb:101:in block in run' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/util/busy.rb:19:in busy'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/runner.rb:101:in run' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/builtin/call.rb:53:in call'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:48:in call' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:127:in block in finalize_action'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:48:in call' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/builder.rb:180:in call'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/runner.rb:101:in block in run' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/util/busy.rb:19:in busy'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/runner.rb:101:in run' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/builtin/call.rb:53:in call'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:48:in call' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/builtin/box_check_outdated.rb:95:in call'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:48:in call' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/builtin/config_validate.rb:25:in call'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:48:in call' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/plugins/providers/virtualbox/action/check_virtualbox.rb:20:in call'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:48:in call' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/builtin/env_set.rb:19:in call'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:48:in call' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:127:in block in finalize_action'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:48:in call' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/plugins/providers/virtualbox/action/match_mac_address.rb:22:in call'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:48:in call' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/plugins/providers/virtualbox/action/discard_state.rb:15:in call'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:48:in call' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/plugins/providers/virtualbox/action/import.rb:78:in import'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/plugins/providers/virtualbox/action/import.rb:13:in call' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:48:in call'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/plugins/providers/virtualbox/action/prepare_clone_snapshot.rb:17:in call' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:48:in call'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/builtin/prepare_clone.rb:15:in call' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:48:in call'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/plugins/providers/virtualbox/action/customize.rb:40:in call' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:48:in call'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/plugins/providers/virtualbox/action/check_accessible.rb:18:in call' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:48:in call'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:127:in block in finalize_action' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:48:in call'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/builder.rb:180:in call' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/runner.rb:101:in block in run'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/util/busy.rb:19:in busy' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/runner.rb:101:in run'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/builtin/call.rb:53:in call' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:48:in call'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/builtin/config_validate.rb:25:in call' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:48:in call'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:127:in block in finalize_action' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:48:in call'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/builtin/handle_box.rb:56:in call' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:48:in call'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:127:in block in finalize_action' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:48:in call'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/builder.rb:180:in call' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/runner.rb:101:in block in run'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/util/busy.rb:19:in busy' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/runner.rb:101:in run'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/builtin/call.rb:53:in call' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:48:in call'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/plugins/providers/virtualbox/action/check_virtualbox.rb:20:in call' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/warden.rb:48:in call'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/builder.rb:180:in call' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/runner.rb:101:in block in run'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/util/busy.rb:19:in busy' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/action/runner.rb:101:in run'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/machine.rb:248:in action_raw' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/machine.rb:217:in block in action'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/environment.rb:631:in lock' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/machine.rb:203:in call'
from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/machine.rb:203:in action' from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.3.8.dev/lib/vagrant/batch_action.rb:86:in block (2 levels) in run'
from D:/HashiCorp/Vagrant/embedded/gems/gems/logging-2.3.1/lib/logging/diagnostic_context.rb:474:in `block in create_with_logging_context'
==> ub1404: Setting the name of the VM: Metasploitable3-ub1404
==> ub1404: Clearing any previously set network interfaces...
==> ub1404: Preparing network interfaces based on configuration...
ub1404: Adapter 1: nat
ub1404: Adapter 2: hostonly
==> ub1404: Forwarding ports...
ub1404: 22 (guest) => 2222 (host) (adapter 1)
==> ub1404: Running 'pre-boot' VM customizations...
==> ub1404: Booting VM...
==> ub1404: Waiting for machine to boot. This may take a few minutes...
ub1404: SSH address: 127.0.0.1:2222
ub1404: SSH username: vagrant
ub1404: SSH auth method: password
ub1404:
ub1404: Inserting generated public key within guest...
ub1404: Removing insecure key from the guest if it's present...
ub1404: Key inserted! Disconnecting and reconnecting using new SSH key...
==> ub1404: Machine booted and ready!
==> ub1404: Checking for guest additions in VM...
ub1404: No guest additions were detected on the base box for this VM! Guest
ub1404: additions are required for forwarded ports, shared folders, host only
ub1404: networking, and more. If SSH fails on this machine, please install
ub1404: the guest additions and repackage the box to continue.
ub1404:
ub1404: This is not an error message; everything may continue to work properly,
ub1404: in which case you may ignore this message.
==> ub1404: Configuring and enabling network interfaces...
The SSH connection was unexpectedly closed by the remote end. This
usually indicates that SSH within the guest machine was unable to
properly start up. Please boot the VM in GUI mode to check whether
it is booting properly.

here's the vagrant file:
‏‏צילום מסך (381)
by the way i understand that i manipulated the vagrant file last time in a really stupid way because i am a noob :)

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

2 participants