Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ronin defang command #249

Merged
merged 7 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Commands:
completion
decode, dec
decrypt
defang
dns
dns-proxy
email-addr
Expand Down Expand Up @@ -508,6 +509,13 @@ $ ronin refang hxxps://www[.]evil[.]com/foo/bar/baz
https://www.evil.com/foo/bar/baz
```

Defangs 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
Expand Down
1 change: 1 addition & 0 deletions gemspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
84 changes: 84 additions & 0 deletions lib/ronin/cli/commands/defang.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# frozen_string_literal: true
#
# 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
# 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 <https://www.gnu.org/licenses/>.
#

require_relative '../value_processor_command'

require 'ronin/support/network/defang'

module Ronin
class CLI
module Commands
#
# Defangs 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 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
59 changes: 59 additions & 0 deletions man/ronin-defang.1.md
Original file line number Diff line number Diff line change
@@ -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

Defangs 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

Defangs a URL:

ronin defang https://www.evil.com/foo/bar/baz

Defangs a hostname:

ronin defang www.example.com

Defangs a IP address:

ronin defang 192.168.1.1

Defangs a file of URLs, hostnames, or IP addresses:

ronin defang --file urls.txt

## AUTHOR

Postmodern <[email protected]>

## SEE ALSO

[ronin-refang](ronin-refang.1.md)
42 changes: 42 additions & 0 deletions spec/cli/commands/defang_spec.rb
Original file line number Diff line number Diff line change
@@ -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(:url) { 'https://www.evil.com/foo/bar/baz' }
let(:defanged) { 'hxxps[://]www[.]evil[.]com/foo/bar/baz' }

it "must print the defanged URL" do
expect {
subject.process_value(url)
}.to output("#{defanged}#{$/}").to_stdout
end
end

context "when given a refanged hostname value" do
let(:host) { 'www.example.com' }
let(:defanged) { 'www[.]example[.]com' }

it "must print the defanged hostname" do
expect {
subject.process_value(host)
}.to output("#{defanged}#{$/}").to_stdout
end
end

context "when given a refanged IP address value" do
let(:ip) { '192.168.1.1' }
let(:defanged) { '192[.]168[.]1[.]1' }

it "must print the defanged IP address" do
expect {
subject.process_value(ip)
}.to output("#{defanged}#{$/}").to_stdout
end
end
end
end