class Pastenum::Gist

Public Class Methods

new(dork) click to toggle source
Calls superclass method Pastenum::Target::new
# File lib/pastenum/targets/gist.rb, line 5
def initialize(dork)
  @dork = URI.escape(dork)
  @vendor = "https://gist.github.com/"
  @raw_url = "https://raw.github.com/gist/"
  
  super
end

Public Instance Methods

Private Instance Methods

page_numbers() click to toggle source

TODO: This is very inefficient. This is double fetch reading.

# File lib/pastenum/targets/gist.rb, line 46
def page_numbers
  page_num = 1
  next_page = true
  
  print "[*] Parsing pages:".green if @verbose
  while next_page && page_num < @max_pages

    print "#".green if @verbose
    begin
      page = @agent.get("https://gist.github.com/search?page=#{page_num}&q=#{@dork}")
    rescue
      raise TargetUnreachable, "[!] ERROR: Can not load gist.github - Check Connectivity"
    end
    
    # Find the link with the -> arrow, is it enabled?
    # //div[@class='pagination']
    pagination_parsed = false
    
    page.links.each do |link|
      if link.href.match(/\/search\?page\=/)
        if link.text.match(/#x2192/)
          page_num += 1
        else
          next_page = false
        end
        pagination_parsed = true
      end
    end
    
    #handle single page of results
    next_page = false unless pagination_parsed
    
  end
  
  return page_num
  
end