Ruby 安装某些软件时,如何导入已下载的gems?
我使用的是Kali Linux,它预先安装了很多用ruby编写的软件(如metasploit、beef),今天我想在编写自己的脚本时导入一个ssh gem,但我失败了,因为它是基本的,没有安装,但我看到用ruby编写的软件也导入了它。而且运行良好,它们是如何工作的 在我的系统中找到:Ruby 安装某些软件时,如何导入已下载的gems?,ruby,Ruby,我使用的是Kali Linux,它预先安装了很多用ruby编写的软件(如metasploit、beef),今天我想在编写自己的脚本时导入一个ssh gem,但我失败了,因为它是基本的,没有安装,但我看到用ruby编写的软件也导入了它。而且运行良好,它们是如何工作的 在我的系统中找到: root@kali:/home# find / -type f -iname *ssh*.rb /usr/share/metasploit-framework/modules/post/linux/manage/
root@kali:/home# find / -type f -iname *ssh*.rb
/usr/share/metasploit-framework/modules/post/linux/manage/sshkey_persistence.rb
/usr/share/metasploit-framework/modules/post/multi/gather/ssh_creds.rb
/usr/share/metasploit-framework/modules/auxiliary/dos/windows/ssh/sysax_sshd_kexchange.rb
/usr/share/metasploit-framework/modules/auxiliary/scanner/ssh/ssh_login_pubkey.rb
/usr/share/metasploit-framework/modules/auxiliary/scanner/ssh/ssh_identify_pubkeys.rb
/usr/share/metasploit-framework/modules/auxiliary/scanner/ssh/ssh_enumusers.rb
/usr/share/metasploit-framework/modules/auxiliary/scanner/ssh/ssh_version.rb
/usr/share/metasploit-framework/modules/auxiliary/scanner/ssh/ssh_login.rb
/usr/share/metasploit-framework/modules/auxiliary/fuzzers/ssh/ssh_version_2.rb
/usr/share/metasploit-framework/modules/auxiliary/fuzzers/ssh/ssh_version_15.rb
/usr/share/metasploit-framework/modules/auxiliary/fuzzers/ssh/ssh_version_corrupt.rb
/usr/share/metasploit-framework/modules/auxiliary/fuzzers/ssh/ssh_kexinit_corrupt.rb
/usr/share/metasploit-framework/modules/exploits/linux/ssh/symantec_smg_ssh.rb
/usr/share/metasploit-framework/modules/exploits/linux/ssh/mercurial_ssh_exec.rb
/usr/share/metasploit-framework/modules/exploits/windows/ssh/freesshd_key_exchange.rb
/usr/share/metasploit-framework/modules/exploits/windows/ssh/freesshd_authbypass.rb
/usr/share/metasploit-framework/modules/exploits/windows/ssh/sysax_ssh_username.rb
/usr/share/metasploit-framework/modules/exploits/windows/ssh/securecrt_ssh1.rb
/usr/share/metasploit-framework/modules/exploits/apple_ios/ssh/cydia_default_ssh.rb
/usr/share/metasploit-framework/modules/exploits/multi/ssh/sshexec.rb
/usr/share/metasploit-framework/vendor/bundle/ruby/2.3.0/gems/dnsruby-1.60.2/test/tc_sshfp.rb
/usr/share/metasploit-framework/vendor/bundle/ruby/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/resource/SSHFP.rb
/usr/share/metasploit-framework/vendor/bundle/ruby/2.3.0/gems/rex-socket-0.1.10/lib/rex/socket/ssh_factory.rb
/usr/share/metasploit-framework/vendor/bundle/ruby/2.3.0/gems/net-ssh-4.2.0/lib/net/ssh.rb
/usr/share/metasploit-framework/vendor/bundle/ruby/2.3.0/gems/net-ssh-4.2.0/support/ssh_tunnel_bug.rb
/usr/share/metasploit-framework/vendor/bundle/ruby/2.3.0/gems/metasploit-credential-2.0.12/spec/models/metasploit/credential/ssh_key_spec.rb
/usr/share/metasploit-framework/vendor/bundle/ruby/2.3.0/gems/metasploit-credential-2.0.12/spec/factories/metasploit/credential/ssh_keys.rb
/usr/share/metasploit-framework/vendor/bundle/ruby/2.3.0/gems/metasploit-credential-2.0.12/app/models/metasploit/credential/ssh_key.rb
/usr/share/metasploit-framework/vendor/bundle/ruby/2.3.0/gems/metasploit-credential-2.0.12/db/migrate/20161107203710_create_index_on_private_data_and_type_for_ssh_key.rb
/usr/share/metasploit-framework/vendor/bundle/ruby/2.3.0/gems/sshkey-1.9.0/test/sshkey_test.rb
/usr/share/metasploit-framework/vendor/bundle/ruby/2.3.0/gems/sshkey-1.9.0/lib/sshkey.rb
/usr/share/metasploit-framework/lib/msf/core/exploit/ssh.rb
/usr/share/metasploit-framework/lib/metasploit/framework/login_scanner/ssh.rb
/usr/share/metasploit-framework/scripts/meterpreter/win32-sshclient.rb
/usr/share/metasploit-framework/scripts/meterpreter/win32-sshserver.rb
我还看到他们有一个导入Net:SSH的模块:
root@kali:/home# cat /usr/share/metasploit-framework/modules/auxiliary/scanner/ssh/ssh_login.rb
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
require 'net/ssh'
require 'net/ssh/command_stream'
require 'metasploit/framework/login_scanner/ssh'
require 'metasploit/framework/credential_collection'
...
...
...
但当我使用它时:
root@kali:/home# irb
irb(main):001:0> require 'net/ssh'
LoadError: cannot load such file -- net/ssh
from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from (irb):1
from /usr/bin/irb:11:in `<main>'
irb(main):002:0>
root@kali:/home#irb
irb(主):001:0>需要“net/ssh”
LoadError:无法加载这样的文件--net/ssh
来自/usr/lib/ruby/2.3.0/rubygems/core\u ext/kernel\u require.rb:55:in'require'
来自/usr/lib/ruby/2.3.0/rubygems/core\u ext/kernel\u require.rb:55:in'require'
来自(irb):1
from/usr/bin/irb:11:in`'
irb(主要):002:0>
我可以在脚本中使用它而不使用gem安装吗
无论如何,感谢那些给我建议的人,我希望你有一个快乐的一天~你可以设置
GEM\u PATH
环境变量(使用ruby
或irb
):
也可以在脚本的代码中进行设置:
#!/usr/env/ruby
Gem.paths = { 'GEM_HOME' => "/usr/share/metasploit-framework/vendor/bundle/ruby/2.3.0/" }
require 'net/ssh'
您可以使用:
bundle-install--path=.bundle
进行安装,然后根据需要发布整个产品。metasploit从/usr/share/metasploit-framework/vendor/bundle/ruby/2.3.0/gems/net-ssh-4.2.0/lib/net/ssh.rb获得该产品。您试图从“/usr/lib/ruby/2.3.0/gems/2.3.0”获取它的地方metasploit正在维护自己的捆绑包(可能是为了确保版本控制)如果你想在标准安装下使用irb中的这个库,你应该安装Gem。主要问题是,出于某种原因,我想在不使用网络的情况下使用本地Gem。哦,是的,对不起$LOAD\u PATH
实际上不适用于gems。您需要使用GEM_HOME
/GEM_PATH
来代替-请查看更新的答案。它可以工作!!!!!!!我非常感谢你。!!!你不知道我现在多么想给你一个大大的拥抱,哈哈,没问题。:-)
#!/usr/env/ruby
Gem.paths = { 'GEM_HOME' => "/usr/share/metasploit-framework/vendor/bundle/ruby/2.3.0/" }
require 'net/ssh'