class Sqreen::PayloadCreator
Create a payload from a given query
Template elements are made of sections and subsections. This class is able to send the full content of section or only the required subsections as needed.
The payload will always be outputed as a Hash of section => subsection.
Constants
- FULL_SECTIONS
- METHODS
Attributes
framework[R]
Public Class Methods
new(framework)
click to toggle source
# File lib/sqreen/payload_creator.rb, line 21 def initialize(framework) @framework = framework end
Public Instance Methods
payload(query)
click to toggle source
# File lib/sqreen/payload_creator.rb, line 36 def payload(query) self.query = query ret = {} METHODS.each_key do |section| ret = fill(section, ret, @framework) end ret end
query=(keys)
click to toggle source
# File lib/sqreen/payload_creator.rb, line 25 def query=(keys) @sections = {} keys.each do |key| section, subsection = key.split('.', 2) @sections[section] = true if subsection.nil? next if @sections[section] == true @sections[section] ||= [] @sections[section].push(subsection) end end
Protected Instance Methods
fields(section, framework)
click to toggle source
# File lib/sqreen/payload_creator.rb, line 99 def fields(section, framework) out = {} object = section_object(section, framework) remove = [] @sections[section].each do |key| meth = METHODS[section][key] invoke(out, key, object, meth || key, remove) end remove.each { |k| @sections[section].delete(k) } Hash[out] end
fill(key, base, framework)
click to toggle source
# File lib/sqreen/payload_creator.rb, line 47 def fill(key, base, framework) subsection = @sections[key] return base if subsection.nil? if subsection == true return base.merge!(key => full_section(key, framework)) end return base if subsection.empty? base[key] = fields(key, framework) base end
full_section(section, framework)
click to toggle source
# File lib/sqreen/payload_creator.rb, line 92 def full_section(section, framework) # fast path prevent initializing a HeaderSection return framework.ip_headers if section == 'headers' so = section_object(section, framework) so.send(FULL_SECTIONS[section]) end
invoke(out, key, object, method, remove)
click to toggle source
# File lib/sqreen/payload_creator.rb, line 111 def invoke(out, key, object, method, remove) out[key] = if object.respond_to?(:[]) object[method] else object.send(method) end rescue NoMethodError => e remove.push(key) Sqreen::RemoteException.record(e) end
section_headers(framework)
click to toggle source
# File lib/sqreen/payload_creator.rb, line 122 def section_headers(framework) Sqreen::PayloadCreator::HeaderSection.new(framework) end
section_object(section, framework)
click to toggle source
# File lib/sqreen/payload_creator.rb, line 86 def section_object(section, framework) return RuntimeInfos if section == 'local' return HeaderSection.new(framework) if section == 'headers' framework end