Skip to content

Commit f77193f

Browse files
committed
Add a URI::HTTP#vulns/has_vulns? core-ext methods
1 parent 3737209 commit f77193f

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

lib/ronin/vulns/core_ext/uri/http.rb

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# frozen_string_literal: true
2+
#
3+
# Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
4+
#
5+
# ronin-support is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU Lesser General Public License as published
7+
# by the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# ronin-support is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU Lesser General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU Lesser General Public License
16+
# along with ronin-support. If not, see <https://www.gnu.org/licenses/>.
17+
#
18+
19+
require_relative "../../../vulns/url_scanner"
20+
21+
module URI
22+
#
23+
# Provides helper methods for HTTP
24+
#
25+
# ## Core-Ext Methods
26+
#
27+
# * { URI::HTTP#vulns }
28+
# * { URI::HTTP#has_vulns? }
29+
#
30+
# @api public
31+
#
32+
class HTTP
33+
34+
#
35+
# Return all vulnerabilities found for URI
36+
#
37+
# @param [Hash{Symbol => Object}] kwargs
38+
# Additional keyword arguments for
39+
# {Ronin::Vulns::URLScanner.scan}.
40+
#
41+
# @return [Array<LFI, RFI, SQLI, SSTI, ReflectedXSS, OpenRedirect>]
42+
# All discovered Web vulnerabilities
43+
#
44+
def vulns(**kwargs)
45+
Ronin::Vulns::URLScanner.scan(self, **kwargs)
46+
end
47+
48+
#
49+
# Checks if the URI contains any vulnerabilities
50+
#
51+
# @param [Hash{Symbol => Object}] kwargs
52+
# Additional keyword arguments for
53+
# {Ronin::Vulns::URLScanner.test}.
54+
#
55+
# @return [Boolean]
56+
#
57+
# @example
58+
# URI('https://example.com/').has_vulns?
59+
# # => true
60+
#
61+
# @see Ronin::Vulns::URLScanner.test
62+
#
63+
def has_vulns?(**kwargs)
64+
Ronin::Vulns::URLScanner.test(self, **kwargs) != nil
65+
end
66+
end
67+
end

spec/core_ext/uri/http_spec.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
require 'spec_helper'
2+
require 'ronin/vulns/core_ext/uri/http'
3+
4+
describe URI::HTTP do
5+
let(:url) { 'https://example.com/' }
6+
7+
subject { URI(url) }
8+
9+
let(:web_vuln1) { Ronin::Vulns::LFI.new(url) }
10+
let(:web_vuln2) { Ronin::Vulns::SQLI.new(url) }
11+
12+
describe "#vulns" do
13+
context "when URI contains vulnerabilities" do
14+
it "must return array with vulnerabilities" do
15+
expect(Ronin::Vulns::URLScanner).to receive(:scan).and_return([web_vuln1, web_vuln2])
16+
17+
expect(subject.vulns).to match_array([web_vuln1, web_vuln2])
18+
end
19+
end
20+
21+
context "when URI does not contain any vulnerabilities" do
22+
it "must return an empty array" do
23+
expect(Ronin::Vulns::URLScanner).to receive(:scan).and_return([])
24+
25+
expect(subject.vulns).to be_empty
26+
end
27+
end
28+
end
29+
30+
describe "#has_vulns?" do
31+
context "when URI contains vulnerabilities" do
32+
it "must return true" do
33+
expect(Ronin::Vulns::URLScanner).to receive(:test).and_return(web_vuln1)
34+
35+
expect(subject.has_vulns?).to be(true)
36+
end
37+
end
38+
39+
context "when URI does not contain any vulnerabilities" do
40+
it "must return false" do
41+
expect(Ronin::Vulns::URLScanner).to receive(:test).and_return(nil)
42+
43+
expect(subject.has_vulns?).to be(false)
44+
end
45+
end
46+
end
47+
end

0 commit comments

Comments
 (0)