Skip to content

Commit 698793b

Browse files
authored
Merge pull request #7 from lalithr95/redirect-check
implement redirect check
2 parents c68cf6f + 0bf2fb5 commit 698793b

File tree

4 files changed

+109
-1
lines changed

4 files changed

+109
-1
lines changed

app/controllers/ping_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ def index
1010
render json: { status: :ok }
1111
end
1212

13+
def pong
14+
render json: { status: :ok }
15+
end
16+
1317
private
1418

1519
def body

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
API_Fuzzer::Engine.routes.draw do
22
get '/ping/:id' => 'ping#index'
3+
get '/ping' => 'ping#pong'
34
end

lib/API_Fuzzer/redirect_check.rb

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
require 'API_Fuzzer/vulnerability'
2+
require 'API_Fuzzer/error'
3+
require 'API_Fuzzer/request'
4+
require 'uri'
5+
6+
module API_Fuzzer
7+
class RedirectCheck
8+
REDIRECT_URL = 'http://127.0.0.1:3000/ping'
9+
ALLOWED_METHODS = [:get, :post]
10+
class << self
11+
def scan(options = {})
12+
@url = options[:url]
13+
@params = options[:params] || {}
14+
@cookies = options[:cookies] || {}
15+
@json = options[:json] || false
16+
17+
@vulnerabilities = []
18+
fuzz_payload
19+
return @vulnerabilities.uniq { |vuln| vuln.description }
20+
rescue Exception => e
21+
@vulnerabilities << API_Fuzzer::Error.new(
22+
description: e.message,
23+
status: 'ERROR',
24+
value: e.backtrace
25+
)
26+
end
27+
28+
def fuzz_payload
29+
uri = URI(@url)
30+
path = uri.path
31+
query = uri.query
32+
# base_uri = query.nil? ? path : [path, query].join("?")
33+
fragments = path.split(/[\/,?,&]/) - ['']
34+
fragments << query.split('&')
35+
fragments.flatten!
36+
fragments.each do |fragment|
37+
if fragment.match(/\A(\w+)=(.?*)\z/) && valid_url?($2)
38+
url = @url.gsub($2, REDIRECT_URL).chomp
39+
fuzz_fragment(url)
40+
elsif valid_url?(fragment)
41+
url = @url.gsub(fragment, REDIRECT_URL)
42+
fuzz_fragment(url)
43+
end
44+
end
45+
return if @params.empty?
46+
47+
@params.keys.each do |parameter|
48+
fuzz_each_parameter(parameter) if valid_url? @params[parameter]
49+
end
50+
end
51+
52+
def fuzz_fragment(url)
53+
ALLOWED_METHODS.each do |method|
54+
begin
55+
response = API_Fuzzer::Request.send_api_request(
56+
url: url,
57+
method: method,
58+
cookies: @cookies,
59+
params: @params
60+
)
61+
62+
@vulnerabilities << API_Fuzzer::Vulnerability.new(
63+
description: "Possible Open Redirect vulnerability in #{method} #{url}",
64+
parameter: "URL: #{url}",
65+
value: "[PAYLOAD] #{url.gsub(REDIRECT_URL, 'PAYLOAD_URL')}",
66+
type: 'MEDIUM'
67+
) if response.headers['Location'] =~ /#{REDIRECT_URL}/
68+
rescue Exception => e
69+
puts e.message
70+
end
71+
end
72+
end
73+
74+
def fuzz_each_parameter(parameter)
75+
params = @params
76+
params[parameter] = REDIRECT_URL
77+
ALLOWED_METHODS.each do |method|
78+
begin
79+
response = API_Fuzzer::Request.send_api_request(
80+
url: @url,
81+
method: method,
82+
cookies: @cookies,
83+
params: params
84+
)
85+
86+
@vulnerabilities << API_Fuzzer::Vulnerability.new(
87+
description: "Possible Open Redirect vulnerability in #{method} #{url}",
88+
parameter: "Parameter: #{parameter}",
89+
value: "[PAYLOAD] #{params.to_s.gsub(REDIRECT_URL, 'PAYLOAD_URL')}",
90+
type: 'MEDIUM'
91+
) if response.headers['LOCATION'] =~ /#{REDIRECT_URL}/
92+
rescue Exception => e
93+
puts e.message
94+
end
95+
end
96+
end
97+
98+
def valid_url? url
99+
url =~ URI.regexp
100+
end
101+
end
102+
end
103+
end

lib/API_Fuzzer/sql_check.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def self.fuzz_each_fragment(url, payload)
7070
method: method,
7171
cookies: @cookies
7272
)
73-
73+
7474
@vulnerabilities << API_Fuzzer::Error.new(description: "#{method} #{@url}", status: response.status, value: response.body) unless success?(response)
7575
body = ''
7676
if response_json?(response)

0 commit comments

Comments
 (0)