安装某些软件时,如何导入已下载的gem?

时间:2019-05-06 14:08:17

标签: 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/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> 

我可以在不使用gem install的情况下在脚本中使用它吗?

无论如何,谢谢那些给我建议的人,希望你过得开心〜

1 个答案:

答案 0 :(得分:0)

您可以设置GEM_PATH环境变量(使用rubyirb):

GEM_PATH=/usr/share/metasploit-framework/vendor/bundle/ruby/2.3.0/ ruby -e 'require "net/ssh"'

或者您可以在脚本代码中进行设置:

#!/usr/env/ruby

Gem.paths = { 'GEM_HOME' => "/usr/share/metasploit-framework/vendor/bundle/ruby/2.3.0/" }

require 'net/ssh'