Class: Snackhack2::BannerGrabber

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site, port: 443, save_file: true) ⇒ BannerGrabber

Returns a new instance of BannerGrabber.



8
9
10
11
12
13
# File 'lib/snackhack2/bannergrabber.rb', line 8

def initialize(site, port: 443, save_file: true)
  @site    = site
  @port    = port
  @headers = Snackhack2::get(@site).headers
  @save_file = save_file
end

Instance Attribute Details

#save_fileObject

Returns the value of attribute save_file.



6
7
8
# File 'lib/snackhack2/bannergrabber.rb', line 6

def save_file
  @save_file
end

#siteObject

Returns the value of attribute site.



6
7
8
# File 'lib/snackhack2/bannergrabber.rb', line 6

def site
  @site
end

Instance Method Details

#apache2Object



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/snackhack2/bannergrabber.rb', line 50

def apache2
  if @headers['server'].match(/Apache/)
    puts "[+] Server is running Apache2... Now checking #{File.join(@site, "server-status")}..."
    apache = Snackhack2::get(File.join(@site, "server-status"))
    if apache.code == 200
      puts "Check #{@site}/server-status"
    else
      puts "[+] Response Code: #{apache.code}...\n\n"
    end
  else
    puts "Apache2 is not found...\n\n"
  end
end

#curlObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/snackhack2/bannergrabber.rb', line 38

def curl
  servers = ''
  cmd = `curl -s -I #{@site.gsub('https://', '')}`
  version = cmd.split('Server: ')[1].split("\n")[0].strip
  if @save_file
    servers += version.to_s
  else
    puts "Banner: #{cmd.split('Server: ')[1].split("\n")[0]}"
  end
  Snackhack2::file_save(@site, "serverversion", servers) if @save_file
end

#headersObject



71
72
73
74
# File 'lib/snackhack2/bannergrabber.rb', line 71

def headers
  h = Snackhack2::get(@site).headers
  puts "[+] Server Version: #{h['server']}..."
end

#nginxObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/snackhack2/bannergrabber.rb', line 26

def nginx
  if @headers['server'].match(/nginx/)
    puts "[+] Server is running NGINX... Now checking if #{File.join(@site, "nginx_status")} is valid..."
    nginx = Snackhack2::get(File.join(@site, "nginx_status"))
    if nginx.code == 200
      puts "Check #{@site}/nginx_status"
    else
      puts "Response code: #{nginx.code}"
    end
  end
end

#runObject



19
20
21
22
23
24
# File 'lib/snackhack2/bannergrabber.rb', line 19

def run
  nginx
  apache2
  wordpress
  headers
end

#serverObject



76
77
78
# File 'lib/snackhack2/bannergrabber.rb', line 76

def server
  @headers['server']
end

#wordpressObject



64
65
66
67
68
69
# File 'lib/snackhack2/bannergrabber.rb', line 64

def wordpress
  wp = Snackhack2::get(@site).body
  return unless wp.match(/wp-content/)

  puts "[+] Wordpress found [+]\n\n\n"
end