metasploit-framework icon indicating copy to clipboard operation
metasploit-framework copied to clipboard

hosts command doesn't expand `~` correctly

Open rossja opened this issue 5 years ago • 3 comments
trafficstars

When using the -o option to the hosts command, passing a directory of ~/testing/hosts.csv failed with the following error:

msf5 > hosts -c address,os_family,os_name -O 1 -o ~/testing/hosts.csv
[*] Wrote hosts to ~/testing/hosts.csv
[-] Error while running command hosts: No such file or directory @ rb_sysopen - ~/testing/hosts.csv

Call stack:
/usr/share/metasploit-framework/lib/msf/ui/console/command_dispatcher/db.rb:580:in `initialize'
/usr/share/metasploit-framework/lib/msf/ui/console/command_dispatcher/db.rb:580:in `open'
/usr/share/metasploit-framework/lib/msf/ui/console/command_dispatcher/db.rb:580:in `cmd_hosts'
/usr/share/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:523:in `run_command'
/usr/share/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:474:in `block in run_single'
/usr/share/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:468:in `each'
/usr/share/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:468:in `run_single'
/usr/share/metasploit-framework/lib/rex/ui/text/shell.rb:158:in `run'
/usr/share/metasploit-framework/lib/metasploit/framework/command/console.rb:48:in `start'
/usr/share/metasploit-framework/lib/metasploit/framework/command/base.rb:82:in `start'
/usr/bin/msfconsole:23:in `<main>'

Changing the output directory to /root/testing/hosts.csv worked. I wouldn't normally care, but immediately prior to this I had dumped the services out using a similar command, and it had worked, so it was weird that one command resolved ~ correctly and one didn't:

msf5 > services -c name,port,info -O 1 -o ~/testing/services.csv
[*] Wrote services to /root/testing/services.csv

rossja avatar Sep 16 '20 14:09 rossja

Many commands are like this, unfortunately. See #13948.

wvu avatar Sep 16 '20 20:09 wvu

@adfoster-r7 just a heads up since you closed some recent related issues that this appears to still be an issue on the latest release.

gwillcox-r7 avatar Feb 07 '22 22:02 gwillcox-r7

@gwillcox-r7 Thanks! :+1:

adfoster-r7 avatar Feb 08 '22 00:02 adfoster-r7