Skip to content

Commit eca649a

Browse files
moozzipostmodern
andauthored
Add ronin defang command (#249)
--------- Co-authored-by: Postmodern <[email protected]>
1 parent 2054e08 commit eca649a

File tree

5 files changed

+194
-0
lines changed

5 files changed

+194
-0
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ Commands:
8383
completion
8484
decode, dec
8585
decrypt
86+
defang
8687
dns
8788
dns-proxy
8889
email-addr
@@ -508,6 +509,13 @@ $ ronin refang hxxps://www[.]evil[.]com/foo/bar/baz
508509
https://www.evil.com/foo/bar/baz
509510
```
510511

512+
Defangs a URL:
513+
514+
```shell
515+
$ ronin defang https://www.evil.com/foo/bar/baz
516+
hxxps://www[.]evil[.]com/foo/bar/baz
517+
```
518+
511519
Query the ASN of an IP address:
512520

513521
```shell

gemspec.yml

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ generated_files:
4949
- man/ronin-completion.1
5050
- man/ronin-decode.1
5151
- man/ronin-decrypt.1
52+
- man/ronin-defang.1
5253
- man/ronin-dns.1
5354
- man/ronin-dns-proxy.1
5455
- man/ronin-email-addr.1

lib/ronin/cli/commands/defang.rb

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# frozen_string_literal: true
2+
#
3+
# Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
4+
#
5+
# Ronin is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# Ronin 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 General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with Ronin. If not, see <https://www.gnu.org/licenses/>.
17+
#
18+
19+
require_relative '../value_processor_command'
20+
21+
require 'ronin/support/network/defang'
22+
23+
module Ronin
24+
class CLI
25+
module Commands
26+
#
27+
# Defangs a URL, hostname, or IP address.
28+
#
29+
# ## Usage
30+
#
31+
# ronin defang [options] [{URL | HOST | IP} ...]
32+
#
33+
# ## Options
34+
#
35+
# -f, --file FILE Optional file to read values from
36+
# -h, --help Print help information
37+
#
38+
# ## Arguments
39+
#
40+
# [URL | HOST | IP ...] A URL, hostname, or IP address
41+
#
42+
# ## Examples
43+
#
44+
# ronin defang https://www.evil.com/foo/bar/baz
45+
# ronin defang www.example.com
46+
# ronin defang 192.168.1.1
47+
# ronin defang --file urls.txt
48+
#
49+
# @since 2.2.0
50+
#
51+
class Defang < ValueProcessorCommand
52+
53+
usage '[options] [{URL | HOST | IP} ...]'
54+
55+
argument :value, required: false,
56+
repeats: true,
57+
usage: 'URL | HOST | IP',
58+
desc: 'A URL, hostname, or IP address'
59+
60+
examples [
61+
'https://www.evil.com/foo/bar/baz',
62+
'www.example.com',
63+
'192.168.1.1',
64+
'--file urls.txt'
65+
]
66+
67+
description 'Defangs a URLs, hostnames, or IP addresses'
68+
69+
man_page 'ronin-defang.1'
70+
71+
#
72+
# Defangs a URL, hostname, or IP address.
73+
#
74+
# @param [String] value
75+
# The value to defang.
76+
#
77+
def process_value(value)
78+
puts Support::Network::Defang.defang(value)
79+
end
80+
81+
end
82+
end
83+
end
84+
end

man/ronin-defang.1.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# ronin-defang 1 "2025-01-01" Ronin "User Manuals"
2+
3+
## NAME
4+
5+
ronin-defang - Defangs a URLs, hostnames, or IP addresses
6+
7+
## SYNOPSIS
8+
9+
`ronin defang` [*options*] [{*URL* \| *HOST* \| *IP*} ...]
10+
11+
## DESCRIPTION
12+
13+
Defangs URL(s), hostname(s), or IP address(es).
14+
15+
## ARGUMENTS
16+
17+
*URL*
18+
: A URL argument to defang
19+
(ex: `https://www.evil.com/foo/bar/baz`).
20+
21+
*HOST*
22+
: A hostname argument to defang (ex: `www.example.com`).
23+
24+
*IP*
25+
: A IP address argument to defang (ex: `192.168.1.1`).
26+
27+
## OPTIONS
28+
29+
`-f`, `--file` *FILE*
30+
: The optional file to read values from.
31+
32+
`-h`, `--help`
33+
: Print help information.
34+
35+
## EXAMPLES
36+
37+
Defangs a URL:
38+
39+
ronin defang https://www.evil.com/foo/bar/baz
40+
41+
Defangs a hostname:
42+
43+
ronin defang www.example.com
44+
45+
Defangs a IP address:
46+
47+
ronin defang 192.168.1.1
48+
49+
Defangs a file of URLs, hostnames, or IP addresses:
50+
51+
ronin defang --file urls.txt
52+
53+
## AUTHOR
54+
55+
Postmodern <[email protected]>
56+
57+
## SEE ALSO
58+
59+
[ronin-refang](ronin-refang.1.md)

spec/cli/commands/defang_spec.rb

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
require 'spec_helper'
2+
require 'ronin/cli/commands/defang'
3+
require_relative 'man_page_example'
4+
5+
describe Ronin::CLI::Commands::Defang do
6+
include_examples "man_page"
7+
8+
describe "#process_value" do
9+
context "when given a refanged URL value" do
10+
let(:url) { 'https://www.evil.com/foo/bar/baz' }
11+
let(:defanged) { 'hxxps[://]www[.]evil[.]com/foo/bar/baz' }
12+
13+
it "must print the defanged URL" do
14+
expect {
15+
subject.process_value(url)
16+
}.to output("#{defanged}#{$/}").to_stdout
17+
end
18+
end
19+
20+
context "when given a refanged hostname value" do
21+
let(:host) { 'www.example.com' }
22+
let(:defanged) { 'www[.]example[.]com' }
23+
24+
it "must print the defanged hostname" do
25+
expect {
26+
subject.process_value(host)
27+
}.to output("#{defanged}#{$/}").to_stdout
28+
end
29+
end
30+
31+
context "when given a refanged IP address value" do
32+
let(:ip) { '192.168.1.1' }
33+
let(:defanged) { '192[.]168[.]1[.]1' }
34+
35+
it "must print the defanged IP address" do
36+
expect {
37+
subject.process_value(ip)
38+
}.to output("#{defanged}#{$/}").to_stdout
39+
end
40+
end
41+
end
42+
end

0 commit comments

Comments
 (0)