Advertisement
Guest User

Untitled

a guest
May 26th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.20 KB | None | 0 0
  1. #
  2. # The NeXpose API
  3. #
  4. =begin
  5.  
  6. Copyright (C) 2009-2011, Rapid7 LLC
  7. All rights reserved.
  8.  
  9. Redistribution and use in source and binary forms, with or without modification,
  10. are permitted provided that the following conditions are met:
  11.  
  12.     * Redistributions of source code must retain the above copyright notice,
  13.       this list of conditions and the following disclaimer.
  14.  
  15.     * Redistributions in binary form must reproduce the above copyright notice,
  16.       this list of conditions and the following disclaimer in the documentation
  17.       and/or other materials provided with the distribution.
  18.  
  19.     * Neither the name of Rapid7 LLC nor the names of its contributors
  20.       may be used to endorse or promote products derived from this software
  21.       without specific prior written permission.
  22.  
  23. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  27. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33.  
  34. =end
  35.  
  36. #
  37. # WARNING! This code makes an SSL connection to the NeXpose server, but does NOT
  38. #          verify the certificate at this time. This can be a security issue if
  39. #          an attacker is able to man-in-the-middle the connection between the
  40. #          Metasploit console and the NeXpose server. In the common case of
  41. #          running NeXpose and Metasploit on the same host, this is a low risk.
  42. #
  43.  
  44. #
  45. # WARNING! This code is still rough and going through substantive changes. While
  46. #          you can build tools using this library today, keep in mind that method
  47. #          names and parameters may change in the future.
  48. #
  49.  
  50. require 'date'
  51. require 'rexml/document'
  52. require 'net/https'
  53. require 'net/http'
  54. require 'uri'
  55. require 'rex/mime'
  56. require File.expand_path(File.join(File.dirname(__FILE__), 'nexpose/error'))
  57. require File.expand_path(File.join(File.dirname(__FILE__), 'nexpose/connection'))
  58.  
  59. module Nexpose
  60.  
  61.     # TODO add
  62.     def self.site_device_scan(connection, site_id, device_array, host_array, debug = false)
  63.  
  64.         request_xml = '<SiteDevicesScanRequest session-id="' + connection.session_id.to_s + '" site-id="' + site_id.to_s + '">'
  65.         request_xml += '<Devices>'
  66.         device_array.each do |d|
  67.             request_xml += '<device id="' + d.to_s + '"/>'
  68.         end
  69.         request_xml += '</Devices>'
  70.         request_xml += '<Hosts>'
  71.         # The host array can only by single IP addresses for now. TODO: Expand to full API Spec.
  72.         host_array.each do |h|
  73.             request_xml += '<range from="' + h.to_s + '"/>'
  74.         end
  75.         request_xml += '</Hosts>'
  76.         request_xml += '</SiteDevicesScanRequest>'
  77.  
  78.         r = connection.execute(request_xml)
  79.         r.success ? {:engine_id => r.attributes['engine_id'], :scan_id => r.attributes['scan-id']} : nil
  80.     end
  81.  
  82.     # === Description
  83.     # TODO
  84.     def self.getAttribute(attribute, xml)
  85.         value = ''
  86.         #@value = substr(substr(strstr(strstr(@xml,@attribute),'"'),1),0,strpos(substr(strstr(strstr(@xml,@attribute),'"'),1),'"'))
  87.         yvalue
  88.     end
  89.  
  90.     # === Description
  91.     # Returns an ISO 8601 formatted date/time stamp. All dates in NeXpose must use this format.
  92.     def self.get_iso_8601_date(int_date)
  93.         #@date_mod = date('Ymd\THis000', @int_date)
  94.         date_mod = ''
  95.         return date_mod
  96.     end
  97.  
  98.     # ==== Description
  99.     # Echos the last XML API request and response for the specified object.  (Useful for debugging)
  100.     def self.printXML(object)
  101.         puts "request" + object.request_xml.to_s
  102.         puts "response is " + object.response_xml.to_s
  103.     end
  104.  
  105.  
  106.     def self.testa(ip, port, user, passwd)
  107.         nsc = Connection.new(ip, user, passwd, port)
  108.  
  109.         nsc.login
  110.         site_listing = SiteListing.new(nsc)
  111.  
  112.         site_listing.sites.each do |site|
  113.             puts "name is #{site.site_name}"
  114.             puts "id is #{site.id}"
  115.         end
  116.     end
  117.  
  118. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement