Skip to content

Commit 00b3f41

Browse files
committed
Extracted CLI::Text from CLI::Printing (closes #92).
1 parent 5a43098 commit 00b3f41

File tree

3 files changed

+90
-180
lines changed

3 files changed

+90
-180
lines changed

lib/ronin/vulns/cli/printing.rb

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
# along with ronin-vulns. If not, see <https://www.gnu.org/licenses/>.
1919
#
2020

21-
require 'ronin/core/cli/logging'
21+
require_relative 'text'
2222

23+
require 'ronin/core/cli/logging'
2324
require 'command_kit/printing/indent'
2425

2526
module Ronin
@@ -32,62 +33,10 @@ class CLI
3233
# @since 0.2.0
3334
#
3435
module Printing
36+
include Text
3537
include Core::CLI::Logging
3638
include CommandKit::Printing::Indent
3739

38-
# Known vulnerability types and their printable names.
39-
VULN_TYPES = {
40-
command_injection: 'Command Injection',
41-
open_redirect: 'Open Redirect',
42-
reflected_xss: 'reflected XSS',
43-
44-
lfi: 'LFI',
45-
rfi: 'RFI',
46-
sqli: 'SQLi',
47-
ssti: 'SSTI'
48-
}
49-
50-
#
51-
# Returns the printable vulnerability type for the vulnerability object.
52-
#
53-
# @param [Vuln] vuln
54-
#
55-
# @return [String]
56-
#
57-
def vuln_type(vuln)
58-
VULN_TYPES.fetch(vuln.class.vuln_type)
59-
end
60-
61-
#
62-
# Determines the param type that the web vulnerability occurs in.
63-
#
64-
# @param [WebVuln] vuln
65-
#
66-
# @return [String, nil]
67-
#
68-
def vuln_param_type(vuln)
69-
if vuln.query_param then 'query param'
70-
elsif vuln.header_name then 'Header'
71-
elsif vuln.cookie_param then 'Cookie param'
72-
elsif vuln.form_param then 'form param'
73-
end
74-
end
75-
76-
#
77-
# Determines the param name that the web vulnerability occurs in.
78-
#
79-
# @param [WebVuln] vuln
80-
#
81-
# @return [String, nil]
82-
#
83-
def vuln_param_name(vuln)
84-
if vuln.query_param then vuln.query_param
85-
elsif vuln.header_name then vuln.header_name
86-
elsif vuln.cookie_param then vuln.cookie_param
87-
elsif vuln.form_param then vuln.form_param
88-
end
89-
end
90-
9140
#
9241
# Prints a log message about a newly discovered web vulnerability.
9342
#

lib/ronin/vulns/cli/text.rb

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# frozen_string_literal: true
2+
#
3+
# ronin-vulns - A Ruby library for blind vulnerability testing.
4+
#
5+
# Copyright (c) 2022-2025 Hal Brodigan (postmodern.mod3 at gmail.com)
6+
#
7+
# ronin-vulns is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Lesser General Public License as published
9+
# by the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# ronin-vulns is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Lesser General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Lesser General Public License
18+
# along with ronin-vulns. If not, see <https://www.gnu.org/licenses/>.
19+
#
20+
21+
module Ronin
22+
module Vulns
23+
class CLI
24+
#
25+
# Methods for generating displayable text.
26+
#
27+
# @since 0.3.0
28+
#
29+
module Text
30+
# Known vulnerability types and their display names.
31+
VULN_TYPES = {
32+
command_injection: 'Command Injection',
33+
open_redirect: 'Open Redirect',
34+
reflected_xss: 'reflected XSS',
35+
36+
lfi: 'LFI',
37+
rfi: 'RFI',
38+
sqli: 'SQLi',
39+
ssti: 'SSTI'
40+
}
41+
42+
#
43+
# Returns the vulnerability type display name for the vulnerability
44+
# object.
45+
#
46+
# @param [Vuln] vuln
47+
#
48+
# @return [String]
49+
#
50+
def vuln_type(vuln)
51+
VULN_TYPES.fetch(vuln.class.vuln_type)
52+
end
53+
54+
#
55+
# Determines the param type display name that the web vulnerability
56+
# occurs in.
57+
#
58+
# @param [WebVuln] vuln
59+
#
60+
# @return [String, nil]
61+
#
62+
def vuln_param_type(vuln)
63+
if vuln.query_param then 'query param'
64+
elsif vuln.header_name then 'Header'
65+
elsif vuln.cookie_param then 'Cookie param'
66+
elsif vuln.form_param then 'form param'
67+
end
68+
end
69+
70+
#
71+
# Determines the param name that the web vulnerability occurs in.
72+
#
73+
# @param [WebVuln] vuln
74+
#
75+
# @return [String, nil]
76+
#
77+
def vuln_param_name(vuln)
78+
if vuln.query_param then vuln.query_param
79+
elsif vuln.header_name then vuln.header_name
80+
elsif vuln.cookie_param then vuln.cookie_param
81+
elsif vuln.form_param then vuln.form_param
82+
end
83+
end
84+
end
85+
end
86+
end
87+
end

spec/cli/printing_spec.rb

Lines changed: 0 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -23,132 +23,6 @@ class TestCommand < Ronin::Vulns::CLI::Command
2323
let(:command_class) { TestCLIPrinting::TestCommand }
2424
subject { command_class.new }
2525

26-
describe "#vuln_type" do
27-
context "when given a Ronin::Vulns::LFI object" do
28-
let(:vuln) { Ronin::Vulns::LFI.new(url) }
29-
30-
it "must return 'LFI'" do
31-
expect(subject.vuln_type(vuln)).to eq('LFI')
32-
end
33-
end
34-
35-
context "when given a Ronin::Vulns::RFI object" do
36-
let(:vuln) { Ronin::Vulns::RFI.new(url) }
37-
38-
it "must return 'RFI'" do
39-
expect(subject.vuln_type(vuln)).to eq('RFI')
40-
end
41-
end
42-
43-
context "when given a Ronin::Vulns::SQLI object" do
44-
let(:vuln) { Ronin::Vulns::SQLI.new(url) }
45-
46-
it "must return 'SQLi'" do
47-
expect(subject.vuln_type(vuln)).to eq('SQLi')
48-
end
49-
end
50-
51-
context "when given a Ronin::Vulns::SSTI object" do
52-
let(:vuln) { Ronin::Vulns::SSTI.new(url) }
53-
54-
it "must return 'SSTI'" do
55-
expect(subject.vuln_type(vuln)).to eq('SSTI')
56-
end
57-
end
58-
59-
context "when given a Ronin::Vulns::OpenRedirect object" do
60-
let(:vuln) { Ronin::Vulns::OpenRedirect.new(url) }
61-
62-
it "must return 'Open Redirect'" do
63-
expect(subject.vuln_type(vuln)).to eq('Open Redirect')
64-
end
65-
end
66-
67-
context "when given a Ronin::Vulns::ReflectedXSS object" do
68-
let(:vuln) { Ronin::Vulns::ReflectedXSS.new(url) }
69-
70-
it "must return 'reflected XSS'" do
71-
expect(subject.vuln_type(vuln)).to eq('reflected XSS')
72-
end
73-
end
74-
end
75-
76-
describe "#vuln_param_type" do
77-
context "and the #query_param attribute is set" do
78-
let(:query_param) { 'id' }
79-
let(:vuln) { Ronin::Vulns::WebVuln.new(url, query_param: query_param) }
80-
81-
it "must return 'query param''" do
82-
expect(subject.vuln_param_type(vuln)).to eq("query param")
83-
end
84-
end
85-
86-
context "and the #header_name attribute is set" do
87-
let(:header_name) { 'X-Foo' }
88-
let(:vuln) { Ronin::Vulns::LFI.new(url, header_name: header_name) }
89-
90-
it "must return 'Header'" do
91-
expect(subject.vuln_param_type(vuln)).to eq("Header")
92-
end
93-
end
94-
95-
context "and the #cookie_param attribute is set" do
96-
let(:cookie_param) { 'X-Foo' }
97-
let(:vuln) { Ronin::Vulns::LFI.new(url, cookie_param: cookie_param) }
98-
99-
it "must return 'Cookie param'" do
100-
expect(subject.vuln_param_type(vuln)).to eq("Cookie param")
101-
end
102-
end
103-
104-
context "and the #form_param attribute is set" do
105-
let(:form_param) { 'X-Foo' }
106-
let(:vuln) { Ronin::Vulns::LFI.new(url, form_param: form_param) }
107-
108-
it "must return 'form param'" do
109-
expect(subject.vuln_param_type(vuln)).to eq("form param")
110-
end
111-
end
112-
end
113-
114-
describe "#vuln_param_name" do
115-
context "and the #query_param attribute is set" do
116-
let(:query_param) { 'id' }
117-
let(:vuln) { Ronin::Vulns::WebVuln.new(url, query_param: query_param) }
118-
119-
it "must return the vuln's #query_param" do
120-
expect(subject.vuln_param_name(vuln)).to eq(query_param)
121-
end
122-
end
123-
124-
context "and the #header_name attribute is set" do
125-
let(:header_name) { 'X-Foo' }
126-
let(:vuln) { Ronin::Vulns::LFI.new(url, header_name: header_name) }
127-
128-
it "must return the vuln's #header_name" do
129-
expect(subject.vuln_param_name(vuln)).to eq(header_name)
130-
end
131-
end
132-
133-
context "and the #cookie_param attribute is set" do
134-
let(:cookie_param) { 'X-Foo' }
135-
let(:vuln) { Ronin::Vulns::LFI.new(url, cookie_param: cookie_param) }
136-
137-
it "must return the vuln's #cookie_param" do
138-
expect(subject.vuln_param_name(vuln)).to eq(cookie_param)
139-
end
140-
end
141-
142-
context "and the #form_param attribute is set" do
143-
let(:form_param) { 'X-Foo' }
144-
let(:vuln) { Ronin::Vulns::LFI.new(url, form_param: form_param) }
145-
146-
it "must return the vuln's #form_param" do
147-
expect(subject.vuln_param_name(vuln)).to eq(form_param)
148-
end
149-
end
150-
end
151-
15226
describe "#log_vuln" do
15327
context "when given a Ronin::Vulns::LFI object" do
15428
context "and the #query_param attribute is set" do

0 commit comments

Comments
 (0)