class OffensiveComputing::MalwareSearch

Attributes

Public Class Methods

new(username, password) click to toggle source
# File lib/offensivecomputing/offensivecomputing.rb, line 11
def initialize(username, password)
        # login and get a cookie
        # handle failures
        params = {'edit[name]' => username, 'edit[pass]' => password, 'edit[form_id]' => 'user_login_block'}
        @cookie = nil
        @referer = @@baseurl
        _post("?q=node&destination=node&op=Log+in", params)
end

Public Instance Methods

_get(path, params=nil) click to toggle source
# File lib/offensivecomputing/offensivecomputing.rb, line 48
def _get(path, params=nil)
        url = URI.parse "#{@@baseurl}/#{path}"
        data = nil
        path = url.path
        if params and params.length > 0
                data = params.map { |k,v|
                        "#{k}=#{v}".gsub(/([^ a-zA-Z0-9_.-=]+)/) do
                                '%' + $1.unpack('H2' * $1.bytesize).join('%').upcase
                        end.tr(' ', '+')
                }.join("&")
        end
        if data and url.query
                path += "?#{url.query}&#{data}"
        elsif data
                path += "?#{data}"
        elsif url.query
                path += "?#{url.query}"
        end
        request = Net::HTTP::Get.new(path)
        _request(request, url)
end
_post(path, params=nil) click to toggle source
# File lib/offensivecomputing/offensivecomputing.rb, line 36
def _post(path, params=nil)
        url = URI.parse "#{@@baseurl}/#{path}"
        path = url.path
        if url.query
                path += "?"+url.query
        end
        #puts path
        request = Net::HTTP::Post.new(path)
        request.set_form_data(params) if params
        _request(request, url)
end
_request(request, url) click to toggle source
# File lib/offensivecomputing/offensivecomputing.rb, line 20
def _request(request, url)
        request.add_field("User-Agent", @@user_agent)
        request.add_field("Referer", @referer)
        request.add_field("Cookie", @cookie) if @cookie

        http = Net::HTTP.new(url.host, url.port)
        if url.scheme == 'https'
                http.use_ssl = true
                http.verify_mode = OpenSSL::SSL::VERIFY_NONE
                http.verify_depth = 5
        end
        resp = http.request(request)
        @cookie = resp.header["set-cookie"].split(/[,; ]+/).find_all{|x| x=~ /PHPSESSID/}.last if resp.header["set-cookie"]
        resp.body
end
download(malwareresult,filename=nil) click to toggle source
# File lib/offensivecomputing/offensivecomputing.rb, line 137
def download(malwareresult,filename=nil)
        if malwareresult.respond_to? :dlurl and malwareresult.dlurl
                doc = _get(malwareresult.dlurl)
                if filename
                        File.open(filename,'w') do |f|
                                f.write(doc)
                        end
                end
                doc
        end
end