Class: Pastenum::Github

Inherits:
Target
  • Object
show all
Defined in:
lib/pastenum/targets/github.rb

Instance Attribute Summary

Attributes inherited from Target

#dork, #max_pages, #raw, #raw_url, #results, #vendor, #verbose

Instance Method Summary collapse

Methods inherited from Target

#summary, #verify_ssl_mode, #verify_ssl_mode=

Constructor Details

#initialize(dork) ⇒ Github

Returns a new instance of Github.



16
17
18
19
20
21
22
# File 'lib/pastenum/targets/github.rb', line 16

def initialize(dork)
  @dork = URI.escape(dork)
  @vendor = "https://github.com/"
  @raw_url = "https://raw.github.com/gist/"
  
  super
end

Instance Method Details

#searchObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/pastenum/targets/github.rb', line 24

def search
  puts "[*] Searching Github".green if @verbose
  current_page = 1
  page_numbers.times do
    print ".".green if @verbose
    page = @agent.get("https://github.com/search?langOverride=&language=&q=#{@dork}&repo=&start_value=#{current_page}&type=Code&x=21&y=22")
    page.links.each do |link|
      if link.href.match(/\/blob/)
        if @raw
          matchdata = link.href.match(/([a-zA-Z0-9\-_\.]+\/[a-zA-Z0-9\-_\.]+)\/(blob)\/([a-z0-9]+)/)
          address = "https://raw.github.com/#{matchdata[1]}/#{matchdata[3]}/"
          @results << address
        else
          @results << "https://github.com#{link.href.split("#").first}"
        end
      end
      current_page += 1
    end
  end
  puts "\n" if @verbose
  return @results.uniq! 
end