diff --git a/lib/rapid7/nexpose.rb b/lib/rapid7/nexpose.rb
index 3c3033da15..080c81241c 100644
--- a/lib/rapid7/nexpose.rb
+++ b/lib/rapid7/nexpose.rb
@@ -24,6 +24,18 @@ require 'uri'
module Nexpose
+module Sanitize
+ def replace_entities(str)
+ ret = str.dup
+ ret.gsub!(/&/, "&")
+ ret.gsub!(/'/, "'")
+ ret.gsub!(/"/, """)
+ ret.gsub!(/, "<")
+ ret.gsub!(/>/, ">")
+ ret
+ end
+end
+
class APIError < ::RuntimeError
attr_accessor :req, :reason
def initialize(req, reason = '')
@@ -489,10 +501,17 @@ class IPRange
attr_reader :to;
def initialize(from, to = nil)
-
@from = from
@to = to
+ end
+ include Sanitize
+ def to_xml
+ if (to and not to.empty?)
+ return %Q{}
+ else
+ return %Q{}
+ end
end
end
@@ -504,9 +523,12 @@ class HostName
attr_reader :hostname
def initialize(hostname)
-
@hostname = hostname
+ end
+ include Sanitize
+ def to_xml
+ "#{replace_entities(hostname)}"
end
end
@@ -892,107 +914,45 @@ class Site
xml = ''
- xml += ' '
-
+ xml << ' '
@site_config.hosts.each do |h|
-
- if (h.class.to_s == "Nexpose::IPRange")
- if (h.to and not h.to.empty?)
- xml += ' '
- else
- xml += ' '
- end
-
- elsif (h.class.to_s == "Nexpose::HostName")
-
- xml += ' ' + h.hostname + ''
-
- end
-
+ xml << h.to_xml if h.respond_to? :to_xml
end
- xml +=' '
+ xml << ''
- xml += ' '
+ xml << ''
@site_config.credentials.each do |c|
- xml += ' '
-
-
- if (c.isblob)
- xml += c.securityblob
- end
-
- xml += ''
-
+ xml << c.to_xml if c.respond_to? :to_xml
end
- xml += ' '
+ xml << ' '
- xml += ' '
+ xml << ' '
@site_config.alerts.each do |a|
-
- case a.type
- when :smtp
- xml += ' '
- a.recipients.each do |r|
- xml += ' ' + r + ''
- end
- xml += ' '
- xml += ' '
-
- when :snmp
- xml += ' '
- xml += ' '
- xml += ' '
-
- when :syslog
- xml += ' '
- xml += ' '
- xml += ' '
- end
+ xml << a.to_xml if a.respond_to? :to_xml
end
+ xml << ' '
- xml += ' '
+ xml << ' '
- xml += ' '
-
- xml += ' '
+ xml << ' '
@site_config.scanConfig.schedules.each do |s|
- xml += ' '
+ xml << ' '
end
- xml += ' '
+ xml << ' '
- xml += ' '
+ xml << ' '
@site_config.scanConfig.scanTriggers.each do |s|
if (s.class.to_s == "Nexpose::AutoUpdate")
- xml += ' '
+ xml << ' '
end
end
- xml += ' '
+ xml << ' '
- xml += ' '
+ xml << ' '
- xml += ' '
+ xml << ' '
return xml
end
@@ -1002,7 +962,6 @@ end
# Object that represents administrative credentials to be used during a scan. When retrived from an existing site configuration the credentials will be returned as a security blob and can only be passed back as is during a Site Save operation. This object can only be used to create a new set of credentials.
#
class AdminCredentials
-
# Security blob for an existing set of credentials
attr_reader :securityblob
# Designates if this object contains user defined credentials or a security blob
@@ -1052,9 +1011,25 @@ class AdminCredentials
@securityblob = securityblob
end
+ include Sanitize
+ def to_xml
+ xml = ''
+ xml << ''
+ xml << replace_entities(securityblob) if (isblob)
+ xml << ''
+ xml
+ end
end
+
# === Description
# Object that represents an SMTP (Email) Alert.
#
@@ -1096,6 +1071,20 @@ class SmtpAlert
@vulnFilter = vulnFilter
end
+ include Sanitize
+ def to_xml
+ xml = "}
+ recipients.each do |recpt|
+ xml << "#{replace_entities(recpt)}"
+ end
+ xml << vulnFilter.to_xml
+ xml << ""
+ xml
+ end
end
# === Description
@@ -1131,6 +1120,18 @@ class SnmpAlert
@vulnFilter = vulnFilter
end
+ include Sanitize
+ def to_xml
+ xml = "}
+ xml << vulnFilter.to_xml
+ xml << ""
+ xml
+ end
+
end
# === Description
@@ -1164,6 +1165,17 @@ class SyslogAlert
@vulnFilter = vulnFilter
end
+ include Sanitize
+ def to_xml
+ xml = "}
+ xml << vulnFilter.to_xml
+ xml << ""
+ xml
+ end
+
end
# TODO: review
@@ -1196,11 +1208,20 @@ class VulnFilter
attr_reader :severityThreshold
def initialize(typeMask, severityThreshold, maxAlerts = -1)
-
@typeMask = typeMask
@maxAlerts = maxAlerts
@severityThreshold = severityThreshold
+ end
+ include Sanitize
+ def to_xml
+ xml = ""
+
+ xml
end
end