Class: Snackhack2::Robots

Inherits:
Object
  • Object
show all
Defined in:
lib/snackhack2/robots.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site, save_file: true) ⇒ Robots

Returns a new instance of Robots.



6
7
8
9
10
# File 'lib/snackhack2/robots.rb', line 6

def initialize(site, save_file: true)
  @site = site
  @http = Snackhack2::get(File.join(@site, "robots.txt"))
  @save_file = save_file
end

Instance Attribute Details

#save_fileObject (readonly)

Returns the value of attribute save_file.



12
13
14
# File 'lib/snackhack2/robots.rb', line 12

def save_file
  @save_file
end

Instance Method Details

#allow_robotsObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/snackhack2/robots.rb', line 38

def allow_robots
  allow_dir = []
  if @http.code == 200
    body = @http.body.lines
    body.each do |l|
      allow_dir << l.split('Allow: ')[1] if l.match(/Allow:/)
    end
  else
    puts "[+] Not giving code 200.\n"
  end
  open_links = []
  allow_dir.each do |path|
    link = Snackhack2::get(File.join(@site, path.strip))
    if link.code == 200
      valid_links = "#{@site}#{path}"
      open_links << valid_links
    end
  end
  open_links
end

#disallow_robotsObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/snackhack2/robots.rb', line 59

def disallow_robots
  disallow_dir = []
  if @http.code == 200
    body = @http.body.lines
    body.each do |l|
      disallow_dir << l.split('Disallow: ')[1] if l.match(/Disallow:/)
    end
  else
    puts "[+] Not giving code 200.\n"
  end
  open_links = []
  disallow_dir.each do |path|
    link = Snackhack2::get(File.join(@site, path.strip))
    if link.code == 200
      valid_links = "#{@site}#{path}"
      open_links << valid_links
    end
  rescue StandardError
  end
  open_links
end

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/snackhack2/robots.rb', line 14

def run
  save_txt_file = ''
  allow    = allow_robots
  disallow = disallow_robots
  if @save_file
    save_txt_file += "ALLOW:\n\n"
    unless allow.empty?
      allow.each do |list|
        save_txt_file += list
      end
    end
    save_txt_file += "DISALLOW:\n\n"
    unless disallow.empty?
      disallow.each do |list|
        save_txt_file += list
      end
    end
  else
    puts allow
    puts disallow
  end
  Snackhack2::file_save(@site, "robots", save_txt_file) if @save_file
end