Skip to content

Commit 26b60e4

Browse files
authored
Merge pull request #11 from lalithr95/implement-privilege-escalation
Implement privilege escalation
2 parents 575658e + c7597f5 commit 26b60e4

File tree

5 files changed

+113
-7
lines changed

5 files changed

+113
-7
lines changed

lib/API_Fuzzer.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
require 'API_Fuzzer/redirect_check'
1111
require 'API_Fuzzer/idor_check'
1212
require 'API_Fuzzer/rate_limit_check'
13+
require 'API_Fuzzer/csrf_check'
14+
require 'API_Fuzzer/privilege_escalation_check'
1315

1416
module API_Fuzzer
1517
# Scans all the checks
@@ -24,6 +26,8 @@ def self.scan(options = {})
2426
vulnerabilities << API_Fuzzer::RedirectCheck.scan(options)
2527
vulnerabilities << API_Fuzzer::IdorCheck.scan(options)
2628
vulnerabilities << API_Fuzzer::RateLimitCheck.scan(options)
29+
vulnerabilities << API_Fuzzer::CsrfCheck.scan(options)
30+
vulnerabilities << API_Fuzzer::PrivilegeEscalationCheck.scan(options)
2731
API_Fuzzer::XxeCheck.scan(options)
2832
vulnerabilities.uniq.flatten
2933
end

lib/API_Fuzzer/csrf_check.rb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,30 @@ def scan(options = {})
1111
@url = options[:url] || nil
1212
@params = options[:params] || {}
1313
@cookies = options[:cookies] || {}
14+
@methods = options[:method] || [:get]
15+
@headers = options[:headers] || {}
1416
@json = options[:json] || false
1517
@vulnerabilities = []
1618

17-
validate_csrf
19+
fuzz_csrf
20+
@vulnerabilities.uniq { |vuln| vuln.description }
21+
rescue Exception => e
22+
Rails.logger.info e.message
23+
end
24+
25+
def fuzz_csrf
26+
@vulnerabilities << API_Fuzzer::Vulnerability.new(
27+
type: 'MEDIUM',
28+
value: 'No Cross-site request forgery protection found in API',
29+
description: "Cross-site request forgery vulnerability in GET #{@url}"
30+
) if @methods.map(&:downcase).include?(:get)
1831
end
1932

2033
def validate_csrf
2134
params = @params
2235
headers = request.headers
2336
matched_headers = headers.keys.select { |header| VALID_CSRF_HEADERS.any? { |exp| header.match(exp) } }
2437
matched_param = params.keys.select { |param| VALID_CSRF_PARAMS.any? { |exp| param.match(exp) } }
25-
26-
2738
end
2839
end
2940
end

lib/API_Fuzzer/idor_check.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def fuzz_without_session
3333
method: method
3434
)
3535

36+
fuzz_sensitive_files(response, method)
3637
fuzz_match(response, response_without_session, method)
3738
end
3839
end
@@ -44,6 +45,18 @@ def fuzz_match(resp, resp_without_session, method)
4445
description: "Possible IDOR in #{method} #{@url}"
4546
) if resp.body.to_s == resp_without_session.body.to_s
4647
end
48+
49+
def fuzz_sensitive_files(response, method)
50+
file_url = /^((https?:\/\/)?(www\.)?([\da-z\.-]+)\.([a-z\.]{2,6})\/[\w \.-]+?\.(pdf|doc|docs|rtf)([a-zA-Z0-9=?]*?))$/
51+
flagged_url = response.body.to_s.scan(file_url) || []
52+
flagged_url.each do |url|
53+
@vulnerabilities << API_Fuzzer::Vulnerability.new(
54+
type: 'MEDIUM',
55+
value: "File #{url} can be accessed without proper permissions",
56+
description: "Access control violation in #{method} #{url}"
57+
)
58+
end
59+
end
4760
end
4861
end
4962
end
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
require 'API_Fuzzer/vulnerability'
2+
require 'API_Fuzzer/error'
3+
require 'API_Fuzzer/request'
4+
5+
module API_Fuzzer
6+
class PrivilegeEscalationCheck
7+
class << self
8+
def scan(options = {})
9+
@url = options[:url]
10+
@params = options[:params] || {}
11+
@headers = options[:headers] || {}
12+
@methods = options[:method] || []
13+
@cookies = options[:cookies] || {}
14+
15+
@vulnerabilities = []
16+
fuzz_privileges
17+
@vulnerabilities.uniq { |vuln| vuln.description }
18+
rescue Exception => e
19+
Rails.logger.info e.message
20+
end
21+
22+
def fuzz_privileges
23+
id = /\A\d+\z/
24+
uri = URI(@url)
25+
path = uri.path
26+
query = uri.query
27+
url = @url
28+
base_uri = query.nil? ? path : [path, query].join("?")
29+
fragments = base_uri.split(/[\/,?,&]/) - ['']
30+
fragments.each do |fragment|
31+
if fragment.match(/\A(\w)+=(\w)*\z/)
32+
key, value = fragment.split("=")
33+
if value.match(id)
34+
value = value.to_i
35+
value += 1
36+
url = url.gsub(fragment, [key, value].join("=")).chomp
37+
fuzz_identity(url, @params)
38+
end
39+
elsif fragment.match(id)
40+
value = fragment.to_i
41+
value += 1
42+
url = url.gsub(fragment, value.to_s).chomp if url
43+
fuzz_identity(url, @params, url)
44+
end
45+
end
46+
return if @params.empty?
47+
48+
parameters = @params
49+
parameters.keys.each do |parameter|
50+
value = parameters[parameter]
51+
if value.match(id)
52+
value = value.to_i
53+
value += 1
54+
info = [parameter, value].join(" ")
55+
fuzz_identity(@url, parameters.merge(parameter, value), info)
56+
end
57+
end
58+
end
59+
60+
def fuzz_identity(url, params, value)
61+
@methods.each do |method|
62+
response = API_Fuzzer::Request.send_api_request(
63+
url: url,
64+
method: method,
65+
params: @params,
66+
cookies: @cookies,
67+
headers: @headers
68+
)
69+
@vulnerabilities << API_Fuzzer::Vulnerability.new(
70+
type: 'HIGH',
71+
value: "ID in #{value} parameter is vulnerable to Privilege Escalation vulnerability.",
72+
description: "Privilege Escalation vulnerability in #{method} #{url}"
73+
) if response.code == 200
74+
end
75+
end
76+
end
77+
end
78+
end

rules/info.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
---
22
rules:
3-
4-
-
3+
4+
-
55
#Server
66
description: Information Disclosure of Server version
77
match: server
88
-
99
# Powered-by Header
1010
description: Information Disclosure through x-powered-by
1111
match: x-powered-by
12-
12+
1313
-
1414
# ASP.NET MVC version
1515
description: Information Disclosure of APS.NET MVC version
1616
match: x-aspnetmvc-version
17-
17+
1818
-
1919
# ASP.NET version
2020
description: Information Disclosure of ASP.NET version

0 commit comments

Comments
 (0)