From cc30878813e272f7d18a29cbe700bde95375cd5e Mon Sep 17 00:00:00 2001 From: AI-Mozi Date: Mon, 25 Nov 2024 08:51:16 +0100 Subject: [PATCH 1/7] Add `ronin defang` command --- README.md | 8 +++ gemspec.yml | 1 + lib/ronin/cli/commands/defang.rb | 84 ++++++++++++++++++++++++++++++++ man/ronin-defang.1.md | 59 ++++++++++++++++++++++ spec/cli/commands/defang_spec.rb | 42 ++++++++++++++++ 5 files changed, 194 insertions(+) create mode 100644 lib/ronin/cli/commands/defang.rb create mode 100644 man/ronin-defang.1.md create mode 100644 spec/cli/commands/defang_spec.rb diff --git a/README.md b/README.md index 820d85d9a..d62100895 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,7 @@ Commands: public-suffix-list quote refang + defang rot sha1 sha256 @@ -508,6 +509,13 @@ $ ronin refang hxxps://www[.]evil[.]com/foo/bar/baz https://www.evil.com/foo/bar/baz ``` +De-fangs a URL: + +```shell +$ ronin defang https://www.evil.com/foo/bar/baz +hxxps://www[.]evil[.]com/foo/bar/baz +``` + Query the ASN of an IP address: ```shell diff --git a/gemspec.yml b/gemspec.yml index 191ff9002..c0ab1ea58 100644 --- a/gemspec.yml +++ b/gemspec.yml @@ -79,6 +79,7 @@ generated_files: - man/ronin-public-suffix-list.1 - man/ronin-quote.1 - man/ronin-refang.1 + - man/ronin-defang.1 - man/ronin-rot.1 - man/ronin-sha1.1 - man/ronin-sha256.1 diff --git a/lib/ronin/cli/commands/defang.rb b/lib/ronin/cli/commands/defang.rb new file mode 100644 index 000000000..bc3271230 --- /dev/null +++ b/lib/ronin/cli/commands/defang.rb @@ -0,0 +1,84 @@ +# frozen_string_literal: true +# +# Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com) +# +# Ronin is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ronin is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ronin. If not, see . +# + +require_relative '../value_processor_command' + +require 'ronin/support/network/defang' + +module Ronin + class CLI + module Commands + # + # De-fangs a URL, hostname, or IP address. + # + # ## Usage + # + # ronin defang [options] [{URL | HOST | IP} ...] + # + # ## Options + # + # -f, --file FILE Optional file to read values from + # -h, --help Print help information + # + # ## Arguments + # + # [URL | HOST | IP ...] A URL, hostname, or IP address + # + # ## Examples + # + # ronin defang https://www.evil.com/foo/bar/baz + # ronin defang www.example.com + # ronin defang 192.168.1.1 + # ronin defang --file urls.txt + # + # @since 2.2.0 + # + class Defang < ValueProcessorCommand + + usage '[options] [{URL | HOST | IP} ...]' + + argument :value, required: false, + repeats: true, + usage: 'URL | HOST | IP', + desc: 'A refanged URL, hostname, or IP address' + + examples [ + 'https://www.evil.com/foo/bar/baz', + 'www.example.com', + '192.168.1.1', + '--file urls.txt' + ] + + description 'Defangs a URLs, hostnames, or IP addresses' + + man_page 'ronin-defang.1' + + # + # Defangs a URL, hostname, or IP address. + # + # @param [String] value + # The value to defang. + # + def process_value(value) + puts Support::Network::Defang.defang(value) + end + + end + end + end +end diff --git a/man/ronin-defang.1.md b/man/ronin-defang.1.md new file mode 100644 index 000000000..f9370e6d6 --- /dev/null +++ b/man/ronin-defang.1.md @@ -0,0 +1,59 @@ +# ronin-defang 1 "2025-01-01" Ronin "User Manuals" + +## NAME + +ronin-defang - Defangs a URLs, hostnames, or IP addresses + +## SYNOPSIS + +`ronin defang` [*options*] [{*URL* \| *HOST* \| *IP*} ...] + +## DESCRIPTION + +De-fangs URL(s), hostname(s), or IP address(es). + +## ARGUMENTS + +*URL* +: A URL argument to defang + (ex: `https://www.evil.com/foo/bar/baz`). + +*HOST* +: A hostname argument to defang (ex: `www.example.com`). + +*IP* +: A IP address argument to defang (ex: `192.168.1.1`). + +## OPTIONS + +`-f`, `--file` *FILE* +: The optional file to read values from. + +`-h`, `--help` +: Print help information. + +## EXAMPLES + +De-fangs a URL: + + ronin defang https://www.evil.com/foo/bar/baz + +De-fangs a hostname: + + ronin defang www.example.com + +De-fangs a IP address: + + ronin defang 192.168.1.1 + +De-fangs a file of URLs, hostnames, or IP addresses: + + ronin defang --file urls.txt + +## AUTHOR + +Postmodern + +## SEE ALSO + +[ronin-refang](ronin-refang.1.md) diff --git a/spec/cli/commands/defang_spec.rb b/spec/cli/commands/defang_spec.rb new file mode 100644 index 000000000..54e5a2b14 --- /dev/null +++ b/spec/cli/commands/defang_spec.rb @@ -0,0 +1,42 @@ +require 'spec_helper' +require 'ronin/cli/commands/defang' +require_relative 'man_page_example' + +describe Ronin::CLI::Commands::Defang do + include_examples "man_page" + + describe "#process_value" do + context "when given a refanged URL value" do + let(:refanged) { 'https://www.evil.com/foo/bar/baz' } + let(:defanged) { 'hxxps[://]www[.]evil[.]com/foo/bar/baz' } + + it "must print the de-fanged URL" do + expect { + subject.process_value(refanged) + }.to output("#{defanged}#{$/}").to_stdout + end + end + + context "when given a refanged hostname value" do + let(:refanged) { 'www.example.com' } + let(:defanged) { 'www[.]example[.]com' } + + it "must print the de-fanged hostname" do + expect { + subject.process_value(refanged) + }.to output("#{defanged}#{$/}").to_stdout + end + end + + context "when given a refanged IP address value" do + let(:refanged) { '192.168.1.1' } + let(:defanged) { '192[.]168[.]1[.]1' } + + it "must print the de-fanged IP address" do + expect { + subject.process_value(refanged) + }.to output("#{defanged}#{$/}").to_stdout + end + end + end +end From 26c0189bc345e6b693aa8c13420958b4fc4e8cbd Mon Sep 17 00:00:00 2001 From: Postmodern Date: Mon, 25 Nov 2024 17:13:51 -0800 Subject: [PATCH 2/7] Update README.md * Command list should be alphabetic. * "Defang" instead of "De-fang". --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d62100895..0a63131c5 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ Commands: completion decode, dec decrypt + defang dns dns-proxy email-addr @@ -110,7 +111,6 @@ Commands: public-suffix-list quote refang - defang rot sha1 sha256 @@ -509,7 +509,7 @@ $ ronin refang hxxps://www[.]evil[.]com/foo/bar/baz https://www.evil.com/foo/bar/baz ``` -De-fangs a URL: +Defangs a URL: ```shell $ ronin defang https://www.evil.com/foo/bar/baz From db143b9d4680b162844667b8e06402c46c9cbf68 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Mon, 25 Nov 2024 17:14:34 -0800 Subject: [PATCH 3/7] Update gemspec.yml * Keep the `generated_files` list alphabetic. --- gemspec.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gemspec.yml b/gemspec.yml index c0ab1ea58..15ac19089 100644 --- a/gemspec.yml +++ b/gemspec.yml @@ -49,6 +49,7 @@ generated_files: - man/ronin-completion.1 - man/ronin-decode.1 - man/ronin-decrypt.1 + - man/ronin-defang.1 - man/ronin-dns.1 - man/ronin-dns-proxy.1 - man/ronin-email-addr.1 @@ -79,7 +80,6 @@ generated_files: - man/ronin-public-suffix-list.1 - man/ronin-quote.1 - man/ronin-refang.1 - - man/ronin-defang.1 - man/ronin-rot.1 - man/ronin-sha1.1 - man/ronin-sha256.1 From 9b2708fcdbeecd2d1d0e3b1d32931653e9cdaebf Mon Sep 17 00:00:00 2001 From: Postmodern Date: Mon, 25 Nov 2024 17:15:35 -0800 Subject: [PATCH 4/7] Update defang.rb * Wording changes. --- lib/ronin/cli/commands/defang.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ronin/cli/commands/defang.rb b/lib/ronin/cli/commands/defang.rb index bc3271230..24c79a618 100644 --- a/lib/ronin/cli/commands/defang.rb +++ b/lib/ronin/cli/commands/defang.rb @@ -24,7 +24,7 @@ module Ronin class CLI module Commands # - # De-fangs a URL, hostname, or IP address. + # Defangs a URL, hostname, or IP address. # # ## Usage # @@ -55,7 +55,7 @@ class Defang < ValueProcessorCommand argument :value, required: false, repeats: true, usage: 'URL | HOST | IP', - desc: 'A refanged URL, hostname, or IP address' + desc: 'A URL, hostname, or IP address' examples [ 'https://www.evil.com/foo/bar/baz', From 138fd5c056a0ceeab924373966653df53a951263 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Mon, 25 Nov 2024 17:16:25 -0800 Subject: [PATCH 5/7] Update defang.rb * Updated the copyright years. --- lib/ronin/cli/commands/defang.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ronin/cli/commands/defang.rb b/lib/ronin/cli/commands/defang.rb index 24c79a618..65ab6f514 100644 --- a/lib/ronin/cli/commands/defang.rb +++ b/lib/ronin/cli/commands/defang.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true # -# Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com) +# Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com) # # Ronin is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by From 271f75b560dde1b79911c3c4cbbc9915bd97281c Mon Sep 17 00:00:00 2001 From: Postmodern Date: Mon, 25 Nov 2024 17:17:19 -0800 Subject: [PATCH 6/7] Update ronin-defang.1.md * Wording. --- man/ronin-defang.1.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/man/ronin-defang.1.md b/man/ronin-defang.1.md index f9370e6d6..5cf057755 100644 --- a/man/ronin-defang.1.md +++ b/man/ronin-defang.1.md @@ -10,7 +10,7 @@ ronin-defang - Defangs a URLs, hostnames, or IP addresses ## DESCRIPTION -De-fangs URL(s), hostname(s), or IP address(es). +Defangs URL(s), hostname(s), or IP address(es). ## ARGUMENTS @@ -34,19 +34,19 @@ De-fangs URL(s), hostname(s), or IP address(es). ## EXAMPLES -De-fangs a URL: +Defangs a URL: ronin defang https://www.evil.com/foo/bar/baz -De-fangs a hostname: +Defangs a hostname: ronin defang www.example.com -De-fangs a IP address: +Defangs a IP address: ronin defang 192.168.1.1 -De-fangs a file of URLs, hostnames, or IP addresses: +Defangs a file of URLs, hostnames, or IP addresses: ronin defang --file urls.txt From 97b913c03d7d5075d5cffafdc3d8f333a4ec9eb0 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Mon, 25 Nov 2024 17:19:10 -0800 Subject: [PATCH 7/7] Update defang_spec.rb * Use better local variable names. * Wording in spec descriptions. --- spec/cli/commands/defang_spec.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/cli/commands/defang_spec.rb b/spec/cli/commands/defang_spec.rb index 54e5a2b14..611b27ae2 100644 --- a/spec/cli/commands/defang_spec.rb +++ b/spec/cli/commands/defang_spec.rb @@ -7,34 +7,34 @@ describe "#process_value" do context "when given a refanged URL value" do - let(:refanged) { 'https://www.evil.com/foo/bar/baz' } + let(:url) { 'https://www.evil.com/foo/bar/baz' } let(:defanged) { 'hxxps[://]www[.]evil[.]com/foo/bar/baz' } - it "must print the de-fanged URL" do + it "must print the defanged URL" do expect { - subject.process_value(refanged) + subject.process_value(url) }.to output("#{defanged}#{$/}").to_stdout end end context "when given a refanged hostname value" do - let(:refanged) { 'www.example.com' } + let(:host) { 'www.example.com' } let(:defanged) { 'www[.]example[.]com' } - it "must print the de-fanged hostname" do + it "must print the defanged hostname" do expect { - subject.process_value(refanged) + subject.process_value(host) }.to output("#{defanged}#{$/}").to_stdout end end context "when given a refanged IP address value" do - let(:refanged) { '192.168.1.1' } + let(:ip) { '192.168.1.1' } let(:defanged) { '192[.]168[.]1[.]1' } - it "must print the de-fanged IP address" do + it "must print the defanged IP address" do expect { - subject.process_value(refanged) + subject.process_value(ip) }.to output("#{defanged}#{$/}").to_stdout end end