Class: Pastenum::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/pastenum/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/pastenum/cli.rb', line 14

def initialize  
  options = {}
  
  options[:pastebin] = true
  options[:gist] = true
  options[:github] = true
  options[:pastie] = true
  options[:pastee] = true
  
  options[:raw] = Pastenum::Defaults::Raw
  options[:onion] = false
  options[:test] = false
  options[:verbose] = Pastenum::Defaults::Verbose
  options[:maxpages] = Pastenum::Defaults::MaxPages
  options[:tos] = false
  options[:ssl_verify] = true
  
  opt_parser = OptionParser.new do |opt|
    opt.banner = "Usage: pastenum [OPTIONS] \"search string\""
    opt.separator ""
    opt.separator "Sources::"
    
    opt.on("","--[no-]pastebin","Search Pastebin.com (Gscraper)","  Default: #{options[:pastebin]}") do |value|
      options[:pastebin] = value
    end
    
    opt.on("","--[no-]gist","Search Gist.github.com","  Default: #{options[:gist]}") do |value|
      options[:gist] = value
    end
    
    opt.on("","--[no-]github","Search github.com","  Default: #{options[:github]}") do |value|
      options[:github] = value
    end
    
    opt.on("","--[no-]pastie","Search pastie.org (Gscraper)","  Default: #{options[:pastie]}") do |value|
      options[:pastie] = value
    end
    
    opt.on("","--[no-]pastee","Search pastee.org (Gscraper)","  Default: #{options[:pastie]}") do |value|
      options[:pastee] = value
    end
    
    opt.separator "Report Output:: (Default output to STDOUT)"
    
    opt.on("-H","--html-report","Create an html iframed (report.html) ") do
      options[:report] = true
    end
  
    opt.on("-J", "--json-report", "Create a JSON file (report.json) ") do
      options[:json] = true
    end 


    opt.separator "Options::"
    
    opt.on("-r","--[no-]raw","use 'raw' urls instead if available" ,"  Default: #{options[:raw]}") do |value|
      options[:raw] = value
    end
    
    opt.on("-m","--maxpages=","maximum number of search results pages to iterate through" ,"  Default: #{options[:maxpages]}") do |value|
      options[:maxpages] = value
    end
    
    opt.on("-x", "--tos", "Acknowledge Google INC. 'Terms of Service'") do 
      options[:tos] = true
    end
=begin        
    opt.on("-o","--onion","use tor-network socks mode?") do
      options[:onion] = true
    end
  
    opt.on("-t", "--test", "Run Test suite") do 
      options[:test] = v
    end 
=end  
    opt.on("-V", "--[no-]ssl-verify", "Verify SSL certificates","  Default: #{options[:ssl_verify]}") do |value|
      options[:ssl_verify] = value
    end
    
    opt.on("-v", "--verbose", "Run verbosely") do 
      options[:verbose] = true
    end
  
    opt.on_tail("-h","--help","Display this screen") do
      puts opt_parser
      exit 0
    end
    
  
  end

  #Verify the options
  begin
    raise unless ARGV.size > 0
    opt_parser.parse!
  
  #If options fail display help
  #rescue Exception => e  
  #  puts e.message  
  #  puts e.backtrace.inspect  
  rescue 
    puts opt_parser
    exit
  end
  
  dork = ARGV[0]
  
  if options[:onion]
    session.set_tor
    puts "Fetching Tor Exit IP"
    session.tor_check
    ensure_tor = ask("Are you protected? [NO/yes]")
    exit 1 if ensure_tor != 'yes'
  end
  
  if !(options[:tos])
    puts "You are using Gscraper, a non-compliant Google Search API screen scraping utility.".red
    puts ""
    puts "*** Google Terms of Service: March 1, 2012 "
    puts " [..] This license is for the sole purpose of enabling you to "
    puts " use and enjoy the benefit of the Services as provided by Google,"
    puts " in the manner permitted by these terms. [..] *** "
    puts ""
    ensure_tos = ask("Do you want to continue? [NO/yes]")
    exit 1 if ensure_tos != 'yes'
  end 

  if options[:verbose]
    puts "++++++++++++++++++++++++++++++++++++++++++++++".green
    puts "+ Pastie Enum".green
    puts "+ Version #{VERSION}".green
    puts "++++++++++++++++++++++++++++++++++++++++++++++\n".green
  end
  
  @gist = Pastenum::Gist.new(dork)
  @github = Pastenum::Github.new(dork)
  @pastebin = Pastenum::Pastebin.new(dork)
  @pastie = Pastenum::Pastie.new(dork)
  @pastee = Pastenum::Pastee.new(dork)
  
  if options[:gist]
    
    @gist.verbose = options[:verbose]
    @gist.max_pages = options[:maxpages]
    @gist.verify_ssl_mode = OpenSSL::SSL::VERIFY_NONE unless options[:ssl_verify]
    @gist.search
    @gist.summary
    if options[:raw]
      @gist.results.each { |hit| puts "#{@gist.raw_url}#{hit}" } if !options[:report] && !options[:json]
    else  
      @gist.results.each { |hit| puts "#{@gist.vendor}#{hit}" } if !options[:report] && !options[:json]
    end 
  end
  
  if options[:github]
    @github.verbose = options[:verbose]
    @github.max_pages = options[:maxpages]
    @github.verify_ssl_mode = OpenSSL::SSL::VERIFY_NONE unless options[:ssl_verify]
    @github.raw = true if options[:raw]
    @github.search
    @github.summary 
    
    puts @github.results if !options[:report] && !options[:json]
  end
  
  if options[:pastebin]
    @pastebin.verbose = options[:verbose]
    @pastebin.max_pages = options[:maxpages]
    @pastebin.search
    @pastebin.summary
    
    if options[:raw]
      @pastebin.results.each { |hit| puts "#{@pastebin.raw_url}#{hit}" } if !options[:report] && !options[:json]
    else  
      @pastebin.results.each { |hit| puts "http://pastebin.com/#{hit}" } if !options[:report] && !options[:json]
    end 
  end

  if options[:pastie]
    @pastie.verbose = options[:verbose]
    @pastie.max_pages = 2
    @pastie.raw = true if options[:raw]
    @pastie.search
    @pastie.summary
    puts @pastie.results if !options[:report] && !options[:json]
  end
  
  if options[:pastee]
    @pastee.verbose = options[:verbose]
    @pastee.max_pages = 2
    @pastee.search
    @pastee.summary
    puts @pastee.results if !options[:report] && !options[:json]
  end
  
  
  if options[:report]
    Pastenum::Report.new(dork, @pastie.results, @pastee.results, @pastebin.results, @github.results, @gist.results).to_file
  end
  
  if options[:json]
    Pastenum::JSON.new(dork, [@gist, @github, @pastebin, @pastie, @pastee]).to_file
  end

end

Class Method Details

.invokeObject



9
10
11
# File 'lib/pastenum/cli.rb', line 9

def self.invoke
  self.new
end