解决Metasploit调用Nessus报错问题

news2024/9/21 0:49:05

问题描述

Error while running command nessus_scan_new: undefined method `[]’ for nil:NilClass

在这里插入图片描述

解决方法

发现报错,经过网上查询解决方法
在这里插入图片描述
在Nessus服务器执行,下面的版本号可能有所不同,更加自己的情况更改,需要管理员身份执行。

curl "https://raw.githubusercontent.com/QKaiser/nessus_rest-ruby/nessus-protected-api-support/lib/nessus_rest.rb" > /usr/share/metasploit-framework/vendor/bundle/ruby/版本号/gems/nessus_rest-0.1.6/lib/nessus_rest.rb

可能会遇到打不开的情况下,这个时候可以用一台能打开网址的电脑,将内容复制下来粘贴到一个文本文档中,然后将名称命名为nessus_rest.rbNessus服务器中的文件替换掉(建议将原文件改名,然后再将新建的文件放入目标文件夹中即可,以免有问题可以改回来)

https://raw.githubusercontent.com/QKaiser/nessus_rest-ruby/nessus-protected-api-support/lib/nessus_rest.rb

Ps:遇到打不开的童鞋,我把打开的内容贴在文章的最后方便大家直接复制。
然后退出msfconsole,在重新进入msfconsole,加载nessus

exit
msfconsole
load nessus

这个时候发现问题已经解决,能正常执行nessus_scan_new命令
在这里插入图片描述

nessus_rest.rb内容

#!/usr/bin/env ruby
# coding: utf-8
# = nessus_rest.rb: communicate with Nessus(6+) over JSON REST interface
#
# Author:: Vlatko Kosturjak
#
# (C) Vlatko Kosturjak, Kost. Distributed under MIT license.
# 
# == What is this library? 
# 
# This library is used for communication with Nessus over JSON REST interface. 
# You can start, stop, pause and resume scan. Watch progress and status of scan, 
# download report, etc.
#
# == Requirements
# 
# Required libraries are standard Ruby libraries: uri, net/https and json. 
#
# == Usage:
# 
#   require 'nessus_rest'
#
#   n=NessusREST::Client.new ({:url=>'https://localhost:8834', :username=>'user', :password=> 'password'})
#   qs=n.scan_quick_template('basic','name-of-scan','localhost')
#   scanid=qs['scan']['id']
#   n.scan_wait4finish(scanid)
#   n.report_download_file(scanid,'csv','myscanreport.csv')
#

require 'openssl'
require 'uri'
require 'net/http'
require 'net/https'
require 'json'

# NessusREST module - for all stuff regarding Nessus REST JSON
# 

module NessusREST
  # Client class implementation of Nessus (6+) JSON REST protocol. 
  # Class which uses standard JSON lib to parse nessus JSON REST replies. 
  # 
  # == Typical Usage:
  #
  #   require 'nessus_rest'
  #
  #   n=NessusREST::Client.new ({:url=>'https://localhost:8834', :username=>'user', :password=> 'password'})
  #   qs=n.scan_quick_template('basic','name-of-scan','localhost')
  #   scanid=qs['scan']['id']
  #   n.scan_wait4finish(scanid)
  #   n.report_download_file(scanid,'csv','myscanreport.csv')
  #
  class Client
    attr_accessor :quick_defaults
    attr_accessor :defsleep, :httpsleep, :httpretry, :ssl_use, :ssl_verify, :autologin
    attr_reader :x_cookie

    class << self
      @connection
      @token
    end

    # initialize quick scan defaults: these will be used when not specifying defaults
    #
    # Usage: 
    # 
    #  n.init_quick_defaults()
    def init_quick_defaults
      @quick_defaults=Hash.new
      @quick_defaults['enabled']=false
      @quick_defaults['launch']='ONETIME'
      @quick_defaults['launch_now']=true
      @quick_defaults['description']='Created with nessus_rest'
    end
     
    # initialize object: try to connect to Nessus Scanner using URL, user and password
    # (or any other defaults)
    #
    # Usage:
    #
    #  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')
    def initialize(params={})
      # defaults
      @nessusurl = params.fetch(:url,'https://127.0.0.1:8834/')
      @username = params.fetch(:username,'nessus')
      @password = params.fetch(:password,'nessus')
      @ssl_verify = params.fetch(:ssl_verify,false)
      @ssl_use = params.fetch(:ssl_use,true)
      @autologin = params.fetch(:autologin, true)
      @defsleep = params.fetch(:defsleep, 1)
      @httpretry = params.fetch(:httpretry, 3)
      @httpsleep = params.fetch(:httpsleep, 1)

      init_quick_defaults()

      uri = URI.parse(@nessusurl)
      @connection = Net::HTTP.new(uri.host, uri.port)
      @connection.use_ssl = @ssl_use

      if @ssl_verify
        @connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
      else
        @connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
      end
        
      yield @connection if block_given?
        authenticate(@username, @password) if @autologin
    end
 
    # Tries to authenticate to the Nessus REST JSON interface
    #
    # returns: true if logged in, false if not
    #
    # Usage:
    #
    #  n=NessusREST::Client.new (:url=>'https://localhost:8834', :autologin=>false)
    #  if n.authenticate('user','pass')
    #	puts "Logged in"
    #  else
    #	puts "Error"
    #  end
    def authenticate(username, password)
      @username = username
      @password = password
      authdefault
    end
    alias_method :login, :authenticate

    # Tries to authenticate to the Nessus REST JSON interface
    #
    # returns: true if logged in, false if not
    #
    # Usage:
    #
    #  n=NessusREST::Client.new (:url=>'https://localhost:8834', :autologin=>false, 
    #     :username=>'nessususer', :password=>'nessuspassword')
    #  if n.authdefault
    #	puts "Logged in"
    #  else
    #	puts "Error"
    #  end
    def authdefault
      payload = {
        :username => @username,
        :password => @password,
        :json => 1,
        :authenticationmethod => true
      }
      res = http_post(:uri=>"/session", :data=>payload)
      if res['token']
        @token = "token=#{res['token']}"
        # Starting from Nessus 7.x, Tenable protects some endpoints with a custom header
        # so that they can only be called from the user interface (supposedly).
        res = http_get({:uri=>"/nessus6.js", :raw_content=> true})
        @api_token = res.scan(/([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})/).first.last
        @x_cookie = {'X-Cookie'=>@token, 'X-API-Token'=> @api_token}
        return true
      else
        false
      end
    end

    # checks if we're logged in correctly
    #
    # returns: true if logged in, false if not
    #
    # Usage:
    #
    #  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')
    #  if n.authenticated
    #	puts "Logged in"
    #  else
    #	puts "Error"
    #  end
    def authenticated
      if (@token && @token.include?('token='))
        return true
      else
        return false
      end
    end

    # try to get server properties
    #
    # returns: JSON parsed object with server properties
    #
    # Usage:
    #
    #  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')
    #  pp n.get_server_properties
    def get_server_properties
      http_get(:uri=>"/server/properties", :fields=>x_cookie)
    end
    alias_method :server_properties, :get_server_properties
  
    # Add user to server
    #
    # returns: JSON parsed object
    #
    # Usage:
    #
    #  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')
    #  pp n.user_add('user','password','16','local')
    #
    # Reference:
    # https://localhost:8834/api#/resources/users/create
    def user_add(username, password, permissions, type)
      payload = {
        :username => username, 
        :password => password, 
        :permissions => permissions, 
        :type => type, 
        :json => 1
      }
      http_post(:uri=>"/users", :fields=>x_cookie, :data=>payload)
    end
      
    # delete user with user_id
    #
    # returns: result code
    #
    # Usage:
    #
    #  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')
    #  puts n.user_delete(1)
    def user_delete(user_id)
      res = http_delete(:uri=>"/users/#{user_id}", :fields=>x_cookie)
      return res.code
    end
      
    # change password for user_id
    #
    # returns: result code
    #
    # Usage:
    #
    #  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')
    #  puts n.user_chpasswd(1,'newPassword')
    def user_chpasswd(user_id, password)
      payload = {
        :password => password, 
        :json => 1
      }
      res = http_put(:uri=>"/users/#{user_id}/chpasswd", :data=>payload, :fields=>x_cookie)
      return res.code
    end
      
    # logout from the server
    #
    # returns: result code
    #
    # Usage:
    #
    #  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')
    #  puts n.user_logout
    def user_logout
      res = http_delete(:uri=>"/session", :fields=>x_cookie)
      return res.code
    end
    alias_method :logout, :user_logout

    # Get List of Policies
    #
    # returns: JSON parsed object with list of policies
    #
    # Usage:
    #
    #  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')
    #  pp n.list_policies
    def list_policies
      http_get(:uri=>"/policies", :fields=>x_cookie)
    end

    # Get List of Users
    #
    # returns: JSON parsed object with list of users
    #
    # Usage:
    #
    #  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')
    #  pp n.list_users
    def list_users
      http_get(:uri=>"/users", :fields=>x_cookie)
    end

    # Get List of Folders
    #
    # returns: JSON parsed object with list of folders
    #
    # Usage:
    #
    #  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')
    #  pp n.list_folders
    def list_folders
      http_get(:uri=>"/folders", :fields=>x_cookie)
    end

    # Get List of Scanners
    #
    # returns: JSON parsed object with list of scanners
    #
    # Usage:
    #
    #  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')
    #  pp n.list_scanners
    def list_scanners
      http_get(:uri=>"/scanners", :fields=>x_cookie)
    end

    # Get List of Families
    #
    # returns: JSON parsed object with list of families
    #
    # Usage:
    #
    #  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')
    #  pp n.list_families
    def list_families
      http_get(:uri=>"/plugins/families", :fields=>x_cookie)
    end

    # Get List of Plugins
    #
    # returns: JSON parsed object with list of plugins
    #
    # Usage:
    #
    #  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')
    #  pp n.list_plugins
    def list_plugins(family_id)
      http_get(:uri=>"/plugins/families/#{family_id}", :fields=>x_cookie)
    end

    # Get List of Templates
    #
    # returns: JSON parsed object with list of templates
    #
    # Usage:
    #
    #  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')
    #  pp n.list_templates
    def list_templates(type)
      res = http_get(:uri=>"/editor/#{type}/templates", :fields=>x_cookie)
    end

    def plugin_details(plugin_id)
      http_get(:uri=>"/plugins/plugin/#{plugin_id}", :fields=>x_cookie)
    end

    # check if logged in user is administrator
    #
    # returns: boolean value depending if user is administrator or not
    #
    # Usage:
    #
    #  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')
    #  if n.is_admin
    #	puts "Administrator"
    #  else
    #	puts "NOT administrator"
    #  end
    def is_admin
      res = http_get(:uri=>"/session", :fields=>x_cookie)
      if res['permissions'] == 128
        return true
      else
        return false
      end
    end

    # Get server status
    #
    # returns: JSON parsed object with server status
    #
    # Usage:
    #
    #  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')
    #  pp n.server_status
    def server_status
      http_get(:uri=>"/server/status", :fields=>x_cookie)
    end

    def scan_create(uuid, settings)
      payload = {
	:uuid => uuid, 
	:settings => settings,
	:json => 1
      }.to_json
      http_post(:uri=>"/scans", :body=>payload, :fields=>x_cookie, :ctype=>'application/json')
    end

    def scan_launch(scan_id)
      http_post(:uri=>"/scans/#{scan_id}/launch", :fields=>x_cookie)
    end

    # Get List of Scans
    #
    # returns: JSON parsed object with list of scans
    #
    # Usage:
    #
    #  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')
    #  pp n.scan_list
    def scan_list
      http_get(:uri=>"/scans", :fields=>x_cookie)
    end
    alias_method :list_scans, :scan_list

    def scan_details(scan_id)
      http_get(:uri=>"/scans/#{scan_id}", :fields=>x_cookie)
    end

    def scan_pause(scan_id)
      http_post(:uri=>"/scans/#{scan_id}/pause", :fields=>x_cookie)
    end

    def scan_resume(scan_id)
      http_post(:uri=>"/scans/#{scan_id}/resume", :fields=>x_cookie)
    end

    def scan_stop(scan_id)
      http_post(:uri=>"/scans/#{scan_id}/stop", :fields=>x_cookie)
    end

    def scan_export(scan_id, format)
      payload = {
        :format => format
      }.to_json
      http_post(:uri=>"/scans/#{scan_id}/export", :body=>payload, :ctype=>'application/json', :fields=>x_cookie)
    end

    def scan_export_status(scan_id, file_id)
      request = Net::HTTP::Get.new("/scans/#{scan_id}/export/#{file_id}/status")
      request.add_field("X-Cookie", @token)
      res = @connection.request(request)
      res = JSON.parse(res.body)
      return res
    end

    # delete scan with scan_id
    #
    # returns: boolean (true if deleted)
    #
    # Usage:
    #
    #  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')
    #  puts n.scan_delete(1)
    def scan_delete(scan_id)
      res = http_delete(:uri=>"/scans/#{scan_id}", :fields=>x_cookie)
      if res.code == 200 then
        return true
      end
      return false
    end

    def policy_delete(policy_id)
      res = http_delete(:uri=>"/policies/#{policy_id}", :fields=>x_cookie)
      return res.code
    end

    # Get template by type and uuid. Type can be 'policy' or 'scan'
    #
    # returns: JSON parsed object with template
    #
    # Usage:
    #
    #  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')
    #  pp n.editor_templates('scan',uuid)
    def editor_templates (type, uuid)
      res = http_get(:uri=>"/editor/#{type}/templates/#{uuid}", :fields=>x_cookie)
    end

    # Performs scan with templatename provided (name, title or uuid of scan).
    # Name is your scan name and targets are targets for scan
    #
    # returns: JSON parsed object with scan info
    #
    # Usage:
    #
    #   require 'nessus_rest'
    #
    #   n=NessusREST::Client.new ({:url=>'https://localhost:8834', :username=>'user', :password=> 'password'})
    #   qs=n.scan_quick_template('basic','name-of-scan','localhost')
    #   scanid=qs['scan']['id']
    #   n.scan_wait4finish(scanid)
    #   n.report_download_file(scanid,'csv','myscanreport.csv')
    #
    def scan_quick_template (templatename, name, targets)
      templates=list_templates('scan')['templates'].select do |temp| 
        temp['uuid'] == templatename or temp['name'] == templatename or temp['title'] == templatename
      end
      if templates.nil? then
        return nil
      end
      tuuid=templates.first['uuid']
      et=editor_templates('scan',tuuid)
      et.merge!(@quick_defaults)
      et['name']=name
      et['text_targets']=targets
      sc=scan_create(tuuid,et)
    end

    # Performs scan with scan policy provided (uuid of policy or policy name).
    # Name is your scan name and targets are targets for scan
    #
    # returns: JSON parsed object with scan info
    #
    # Usage:
    #
    #   require 'nessus_rest'
    #
    #   n=NessusREST::Client.new ({:url=>'https://localhost:8834', :username=>'user', :password=> 'password'})
    #   qs=n.scan_quick_policy('myscanpolicy','name-of-scan','localhost')
    #   scanid=qs['scan']['id']
    #   n.scan_wait4finish(scanid)
    #   n.report_download_file(scanid,'nessus','myscanreport.nessus')
    #
    def scan_quick_policy (policyname, name, targets)
      policies=list_policies['policies'].select do |pol|
        pol['id'] == policyname or pol['name'] == policyname
      end
      if policies.nil? then
	return nil
      end
      policy = policies.first
      tuuid=policy['template_uuid']
      et=Hash.new
      et.merge!(@quick_defaults)
      et['name']=name
      et['policy_id'] = policy['id']
      et['text_targets']=targets
      sc=scan_create(tuuid,et)
    end

    def scan_status(scan_id)
      sd=scan_details(scan_id)
      if not sd['error'].nil?
        return 'error'
      end
      return sd['info']['status']
    end

    def scan_finished?(scan_id)
      ss=scan_status(scan_id)
      if ss == 'completed' or ss == 'canceled' or ss == 'imported' then
        return true
      end
      return false
    end

    def scan_wait4finish(scan_id)
      while not scan_finished?(scan_id) do
        # puts scan_status(scan_id)
        sleep @defsleep
      end
    end

    # Get host details from the scan
    #
    # returns: JSON parsed object with host details
    #
    # Usage:
    #
    #  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')
    #  pp n.host_detail(123, 1234)
    def host_detail(scan_id, host_id)
      res = http_get(:uri=>"/scans/#{scan_id}/hosts/#{host_id}", :fields=>x_cookie)
    end

    def report_download(scan_id, file_id)
      res = http_get(:uri=>"/scans/#{scan_id}/export/#{file_id}/download", :raw_content=> true, :fields=>x_cookie)
    end

    def report_download_quick(scan_id, format) 
      se=scan_export(scan_id,format)
      # ready, loading
      while (status = scan_export_status(scan_id,se['file'])['status']) != "ready" do
        # puts status
        if status.nil? or status == '' then
          return nil
        end
        sleep @defsleep
      end
      rf=report_download(scan_id,se['file'])
      return rf
    end

    def report_download_file(scan_id, format, outputfn)
      report_content=report_download_quick(scan_id, format)
      File.open(outputfn, 'w') do |f| 
        f.write(report_content)
      end
    end

    #
    # private?
    #

    # Perform HTTP put method with uri, data and fields
    #
    # returns: HTTP result object
    #
    # Usage:
    #
    #  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')
    #  payload = {
    #    :password => password, 
    #    :json => 1
    #  }
    #  res = n.http_put(:uri=>"/users/#{user_id}/chpasswd", :data=>payload, :fields=>n.x_cookie)
    #  puts res.code 
    def http_put(opts={})
      ret=http_put_low(opts)
      if ret.is_a?(Hash) and ret.has_key?('error') and ret['error']=='Invalid Credentials' then
	authdefault
	ret=http_put_low(opts)
	return ret
      else
	return ret
      end
    end

    def http_put_low(opts={})
      uri    = opts[:uri]
      data   = opts[:data]
      fields = opts[:fields] || {}
      res    = nil
      tries  = @httpretry

      req = Net::HTTP::Put.new(uri)
      req.set_form_data(data) unless (data.nil? || data.empty?)
      fields.each_pair do |name, value|
        req.add_field(name, value)
      end

      begin
	tries -= 1
        res = @connection.request(req)
      rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
	if tries>0
	  sleep @httpsleep
	  retry
	else
	  return res
	end
      rescue URI::InvalidURIError
        return res
      end

      res
    end

    # Perform HTTP delete method with uri, data and fields
    #
    # returns: HTTP result object
    #
    # Usage:
    #
    #  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')
    #  res = n.http_delete(:uri=>"/session", :fields=>n.x_cookie)
    #  puts res.code
    def http_delete(opts={})
      ret=http_delete_low(opts)
      if ret.is_a?(Hash) and ret.has_key?('error') and ret['error']=='Invalid Credentials' then
	authdefault
	ret=http_delete_low(opts)
	return ret
      else
	return ret
      end
    end

    def http_delete_low(opts={})
      uri    = opts[:uri]
      fields = opts[:fields] || {}
      res    = nil
      tries  = @httpretry

      req = Net::HTTP::Delete.new(uri)

      fields.each_pair do |name, value|
        req.add_field(name, value)
      end

      begin
	tries -= 1
        res = @connection.request(req)
      rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
	if tries>0
	  sleep @httpsleep
	  retry
	else
	  return res
	end
      rescue URI::InvalidURIError
        return res
      end

      res
    end

    # Perform HTTP get method with uri and fields
    #
    # returns: JSON parsed object (if JSON parseable)
    #
    # Usage:
    #
    #  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')
    #  pp n.http_get(:uri=>"/users", :fields=>n.x_cookie)
    def http_get(opts={})
      raw_content = opts[:raw_content] || false
      ret=http_get_low(opts)
      if !raw_content then
	if ret.is_a?(Hash) and ret.has_key?('error') and ret['error']=='Invalid Credentials' then
          authdefault
          ret=http_get_low(opts)
          return ret
        else
          return ret
	end
      else
	return ret
      end
    end

    def http_get_low(opts={})
      uri    = opts[:uri]
      fields = opts[:fields] || {}
      raw_content = opts[:raw_content] || false
      json   = {}
      tries  = @httpretry

      req = Net::HTTP::Get.new(uri)
      fields.each_pair do |name, value|
        req.add_field(name, value)
      end

      begin
        tries -= 1
        res = @connection.request(req)
      rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
        if tries>0
          sleep @httpsleep
          retry
        else
          return json
        end
      rescue URI::InvalidURIError
        return json
      end
      if !raw_content
        parse_json(res.body)
      else
        res.body
      end
    end

    # Perform HTTP post method with uri, data, body and fields
    #
    # returns: JSON parsed object (if JSON parseable)
    #
    # Usage:
    #
    #  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')
    #  pp n.http_post(:uri=>"/scans/#{scan_id}/launch", :fields=>n.x_cookie)
    def http_post(opts={})
      if opts.has_key?(:authenticationmethod) then
        # i know authzmethod = opts.delete(:authorizationmethod) is short, but not readable
        authzmethod = opts[:authenticationmethod]
        opts.delete(:authenticationmethod)
      end
      ret=http_post_low(opts)
      if ret.is_a?(Hash) and ret.has_key?('error') and ret['error']=='Invalid Credentials' then
	if not authzmethod
          authdefault
	  ret=http_post_low(opts)
	  return ret
        end
      else
	return ret
      end
    end

    def http_post_low(opts={})
      uri    = opts[:uri]
      data   = opts[:data]
      fields = opts[:fields] || {}
      body   = opts[:body]
      ctype  = opts[:ctype]
      json   = {}
      tries  = @httpretry

      req = Net::HTTP::Post.new(uri)
      req.set_form_data(data) unless (data.nil? || data.empty?)
      req.body = body unless (body.nil? || body.empty?)
      req['Content-Type'] = ctype unless (ctype.nil? || ctype.empty?)
      fields.each_pair do |name, value|
        req.add_field(name, value)
      end

      begin
	tries -= 1
        res = @connection.request(req)
      rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
	if tries>0
          sleep @httpsleep
	  retry
	else
	  return json
	end
      rescue URI::InvalidURIError
        return json
      end

      parse_json(res.body)
    end

    # Perform JSON parsing of body
    #
    # returns: JSON parsed object (if JSON parseable)
    #
    def parse_json(body)
      buf = {}

      begin
        buf = JSON.parse(body)
      rescue JSON::ParserError
      end

      buf
    end

  end # of Client class
end # of NessusREST module

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2109401.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Vue2 day-01

目录 一. Vue 是什么&#xff1f; 1.1 什么是渐进式 1.2 自底向上逐层应用 二. 相关概念 2.1 为什么学习vue 2.2 库和框架区别 2.3 三大主流框架 三. vue基本使用 3.1 体验vue的使用 3.2 相关知识分析 3.3 插值表达式{{}} 3.4 vue-devtools 四. 指令 4.1 v-cloak…

深信服EasyConnect-Docker部署方式

一、项目简介 让深信服开发的非自由的 VPN 软件 EasyConnect 或 aTrust 运行在 docker 中&#xff0c;提供 socks5 和 http 代理服务和网关供宿主机连接使用。 项目地址&#xff1a; https://github.com/docker-easyconnect/docker-easyconnect 二、图形界面版 EasyConnect&…

Oceanbase 数据库审计

数据加密和访问控制可以大幅降低安全风险&#xff0c;但对于具备权限的用户&#xff0c;仍然需要记录其操作&#xff0c;以防止用户登录信息泄露&#xff0c;或者访问权限被滥用。审计功能可以加强企业对数据安全、合规等方面的要求&#xff0c;是跟踪用户行为最主要的工具。 目…

浏览器百科:网页存储篇-Session storage应用实例(九)

1.引言 在前面的文章中&#xff0c;我们详细介绍了如何在 Chrome 浏览器中打开并使用 Session storage 窗格&#xff0c;进行数据的查看、编辑和管理。作为网页存储技术的重要组成部分&#xff0c;sessionStorage在提升用户体验和数据管理能力方面发挥了重要作用。在本篇《浏览…

NAT技术-将多个内部网络设备映射到一个公共IP地址

问题&#xff1a; 今天上课的时候老师让我们在VMware填同一个子网ip 192.168.196.0&#xff0c;然后给我们的linux镜像都是同一个压缩包&#xff0c;结果我们的静态ip地址都是同一个。 192.168.196.0下面有256个ip地址&#xff0c;范围是192.168.196.0到192.168.196.255。我们…

CP-Net:用于生物细胞解析的实例感知部分分割网络|文献速递--基于深度学习的医学影像病灶分割

Title 题目 CP-Net: Instance-aware part segmentation network for biological cell parsing CP-Net&#xff1a;用于生物细胞解析的实例感知部分分割网络 01 文献速递介绍 实例分割是计算机视觉中的一个经典任务&#xff0c;用于识别图像中每个像素的对象类别&#xff0…

基于Android Studio 实现通讯录—原创

目录 一、项目演示 二、开发环境 三、项目详情 四、项目完整源码 一、项目演示 基于Android Studio 实现通讯录—原创 二、开发环境 三、项目详情 1.启动页 这段代码是一个简单的Android应用程序启动活动&#xff08;Activity&#xff09;&#xff0c;具体功能如下&#xf…

【看雪-注册安全分析报告】

前言 由于网站注册入口容易被黑客攻击&#xff0c;存在如下安全问题&#xff1a; 暴力破解密码&#xff0c;造成用户信息泄露短信盗刷的安全问题&#xff0c;影响业务及导致用户投诉带来经济损失&#xff0c;尤其是后付费客户&#xff0c;风险巨大&#xff0c;造成亏损无底洞…

学习 SSM框架 项目总结

通过指导老师发布的学习SSM框架项目&#xff0c;这次我深刻体会到了SSM整体项目之间的紧连关系。 以下是我自己学习过程中总结出来的经验。 SSM框架 配置 导入核心 spring 组件坐标 将spring相关组件坐标&#xff0c;导入到 pom 文件中 <!--spring、springMVC--><…

集成电路学习:什么是RTOS实时操作系统

RTOS&#xff1a;实时操作系统 RTOS&#xff0c;全称Real Time Operating System&#xff0c;即实时操作系统&#xff0c;是一种专为满足实时控制需求而设计的操作系统。它能够在外部事件或数据产生时&#xff0c;以足够快的速度进行处理&#xff0c;并在规定的时间内控制生产过…

UE5.3 新学到的一些性能测试合计(曼巴学习笔记)

一.简单命令行 stat FPS stat unit //增加GPU渲染时间和变量 stat unitgraph //追加了图表显示 二.查看GPU的消耗。调试GPU渲染用的高级命令 可以记录这一刻各个部分的占用情况,只能看当前的 1.在编辑器下&#xff0c;ctrlShift, 。 2.输入命令行&#xff0c;pr…

硬件-经典的TL431三端稳压管

文章目录 一&#xff1a;TL431三端稳压管1.1 器件说明1.2 电路分析1.3 把TL431设计成一个可调电压源的电路1.4 常用型号1.5 阅读手册1.6 2.5V 电压基准应用电路道友&#xff1a;努力的意义&#xff0c;不在于一定会让你取得多大的成就&#xff0c;只是让你在平凡的日子里&#…

虚幻5|知识点(1)寻找查看旋转,击打敌人后朝向主角

举例说明&#xff0c;我们想让角色一直朝着摄像头&#xff0c;我们控制角色任意位置&#xff0c;都能自行旋转都能朝向摄像头 下面是敌人一直朝向角色&#xff0c;无论主角走向哪个位置&#xff0c;敌人都能朝向主角 start是获取敌人的位置向量大小&#xff0c;Target是获取主…

【复杂系统系列(中级)】复杂系统科学的层级与不确定性方程【代码模拟】

【通俗理解】复杂系统科学的层级与不确定性方程 关键词提炼 #复杂系统科学 #层级结构 #不确定性 #上行因果 #下行因果 #初值敏感 #混沌现象 第一节&#xff1a;层级与不确定性方程的类比与核心概念【尽可能通俗】 1.1 层级与不确定性方程的类比 复杂系统科学的层级与不确定…

游戏玩家新宠:高性能远程控制解决方案

如果你出差一些存在公司电脑上的数据急需用到&#xff0c;这时候有一个远程控制工具就非常方便了。如果你担心一些远程控制软件的安全问题&#xff0c;那就从正规渠道下载&#xff0c;比如向日葵远程控制官网下载就可以得到它官方的软件。我今天给你分享一些安全可靠的远程控制…

基于STELLA系统动态模拟技术及在农业、生态环境等科学领域中的实践应用

STELLA是一种用户友好的计算机软件。通过绘画出一个系统的形象图形&#xff0c;并给这个系统提供数学公式和输入数据&#xff0c;从而建立模型。依据专业兴趣&#xff0c;STELLA可以用来建立各种各样的农业、生态、环境等方面的系统动态模型&#xff0c;为科研、教学、管理服务…

基于C++实现一个房贷计算小程序(含代码)

房贷计算程序&#xff0c;主要实现以下功能&#xff1a; 用户友好的界面&#xff1a;使用文本菜单来引导用户选择功能。支持不同还款频率&#xff1a;例如每季度还款、每半年还款等。支持贷款提前还款&#xff1a;计算提前还款对总支付利息的影响。详细的还款计划表&#xff1…

(二)ASP.NET Core WebAPI项目的启动地址设置

上一篇介绍了ASP.NET Core WebAPI项目创建&#xff0c;可参考&#xff1a; 1.webAPI的访问地址 1) 启动时&#xff0c;选择CoreWebAPI(项目名称)运行项目 可以看到打开浏览器后的地址是&#xff1a;applicationUrl"\"launchUrl 2) 启动时&#xff0c;选择IIS Expre…

C++mutable

文章目录 Claude 讲解基本用法mutable的常见用途注意事项 ChatGpt 讲解1. 基本概念2. 使用示例解释&#xff1a; 3. 适用场景4. 注意事项 lambda 讲解基本语法示例捕获方式使用场景 mutable 和 labmda 一起使用代码&#xff1a;代码分析&#xff1a;输出结果&#xff1a; 在C编…

(详细文档!)JavaSwing图书管理系统+mysql数据库

目 录 1.项目概述及需求分析................................ 1 2.系统设计......................................... 1 2.1程序总体设计......................................... 1 2.2数据库设计........................................... 2 2.3公共模块设计...…