ronin 2.0.5 → 2.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +3 -3
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +5 -1
  5. data/ChangeLog.md +56 -1
  6. data/Gemfile +66 -29
  7. data/README.md +162 -17
  8. data/Rakefile +9 -0
  9. data/data/completions/ronin +655 -0
  10. data/data/templates/dns_proxy.rb.erb +35 -0
  11. data/gemspec.yml +27 -13
  12. data/lib/ronin/cli/binary_template.rb +124 -0
  13. data/lib/ronin/cli/commands/archive.rb +104 -0
  14. data/lib/ronin/cli/commands/banner_grab.rb +2 -0
  15. data/lib/ronin/cli/commands/bitflip.rb +1 -1
  16. data/lib/ronin/cli/commands/bitsquat.rb +119 -0
  17. data/lib/ronin/cli/commands/cert_dump.rb +20 -4
  18. data/lib/ronin/cli/commands/cert_gen.rb +9 -19
  19. data/lib/ronin/cli/commands/cert_grab.rb +4 -3
  20. data/lib/ronin/cli/commands/completion.rb +115 -0
  21. data/lib/ronin/cli/commands/dns_proxy.rb +235 -0
  22. data/lib/ronin/cli/commands/http.rb +80 -8
  23. data/lib/ronin/cli/commands/ip.rb +101 -0
  24. data/lib/ronin/cli/commands/iprange.rb +25 -8
  25. data/lib/ronin/cli/commands/netcat.rb +2 -0
  26. data/lib/ronin/cli/commands/new/dns_listener.rb +37 -0
  27. data/lib/ronin/cli/commands/new/dns_proxy.rb +99 -0
  28. data/lib/ronin/cli/commands/new/exploit.rb +34 -0
  29. data/lib/ronin/cli/commands/new/http_listener.rb +37 -0
  30. data/lib/ronin/cli/commands/new/nokogiri.rb +33 -0
  31. data/lib/ronin/cli/commands/new/payload.rb +34 -0
  32. data/lib/ronin/cli/commands/new/project.rb +1 -1
  33. data/lib/ronin/cli/commands/new/script.rb +1 -1
  34. data/lib/ronin/cli/commands/new/web_app.rb +37 -0
  35. data/lib/ronin/cli/commands/new/web_server.rb +37 -0
  36. data/lib/ronin/cli/commands/new/web_spider.rb +37 -0
  37. data/lib/ronin/cli/commands/new.rb +3 -1
  38. data/lib/ronin/cli/commands/pack.rb +339 -0
  39. data/lib/ronin/cli/commands/public_suffix_list.rb +2 -0
  40. data/lib/ronin/cli/commands/tld_list.rb +2 -0
  41. data/lib/ronin/cli/commands/unarchive.rb +128 -0
  42. data/lib/ronin/cli/commands/unhexdump.rb +3 -1
  43. data/lib/ronin/cli/commands/unpack.rb +195 -0
  44. data/lib/ronin/cli/commands/url.rb +2 -0
  45. data/lib/ronin/cli/http_shell.rb +25 -0
  46. data/lib/ronin/cli.rb +10 -0
  47. data/lib/ronin/version.rb +1 -1
  48. data/man/ronin-archive.1.md +49 -0
  49. data/man/ronin-asn.1 +60 -77
  50. data/man/ronin-asn.1.md +25 -21
  51. data/man/ronin-banner-grab.1 +10 -21
  52. data/man/ronin-banner-grab.1.md +9 -5
  53. data/man/ronin-bitflip.1 +35 -61
  54. data/man/ronin-bitflip.1.md +30 -26
  55. data/man/ronin-bitsquat.1 +40 -0
  56. data/man/ronin-bitsquat.1.md +43 -0
  57. data/man/ronin-cert-dump.1 +44 -54
  58. data/man/ronin-cert-dump.1.md +18 -14
  59. data/man/ronin-cert-gen.1 +73 -94
  60. data/man/ronin-cert-gen.1.md +38 -34
  61. data/man/ronin-cert-grab.1 +29 -37
  62. data/man/ronin-cert-grab.1.md +12 -8
  63. data/man/ronin-completion.1 +78 -0
  64. data/man/ronin-completion.1.md +80 -0
  65. data/man/ronin-decode.1 +32 -63
  66. data/man/ronin-decode.1.md +29 -25
  67. data/man/ronin-decrypt.1 +42 -57
  68. data/man/ronin-decrypt.1.md +20 -16
  69. data/man/ronin-dns-proxy.1 +100 -0
  70. data/man/ronin-dns-proxy.1.md +70 -0
  71. data/man/ronin-dns.1 +10 -21
  72. data/man/ronin-dns.1.md +9 -5
  73. data/man/ronin-email-addr.1 +27 -40
  74. data/man/ronin-email-addr.1.md +15 -11
  75. data/man/ronin-encode.1 +93 -63
  76. data/man/ronin-encode.1.md +64 -26
  77. data/man/ronin-encrypt.1 +42 -57
  78. data/man/ronin-encrypt.1.md +20 -16
  79. data/man/ronin-entropy.1 +11 -21
  80. data/man/ronin-entropy.1.md +8 -4
  81. data/man/ronin-escape.1 +22 -46
  82. data/man/ronin-escape.1.md +22 -18
  83. data/man/ronin-extract.1 +74 -149
  84. data/man/ronin-extract.1.md +73 -69
  85. data/man/ronin-grep.1 +77 -155
  86. data/man/ronin-grep.1.md +76 -72
  87. data/man/ronin-help.1 +3 -14
  88. data/man/ronin-help.1.md +2 -2
  89. data/man/ronin-hexdump.1 +249 -265
  90. data/man/ronin-hexdump.1.md +93 -89
  91. data/man/ronin-highlight.1 +8 -18
  92. data/man/ronin-highlight.1.md +8 -4
  93. data/man/ronin-hmac.1 +17 -30
  94. data/man/ronin-hmac.1.md +14 -10
  95. data/man/ronin-homoglyph.1 +11 -22
  96. data/man/ronin-homoglyph.1.md +10 -6
  97. data/man/ronin-host.1 +23 -47
  98. data/man/ronin-host.1.md +22 -18
  99. data/man/ronin-http.1 +40 -69
  100. data/man/ronin-http.1.md +40 -30
  101. data/man/ronin-ip.1 +70 -80
  102. data/man/ronin-ip.1.md +44 -28
  103. data/man/ronin-iprange.1 +14 -22
  104. data/man/ronin-iprange.1.md +12 -5
  105. data/man/ronin-irb.1 +9 -17
  106. data/man/ronin-irb.1.md +7 -3
  107. data/man/ronin-md5.1 +13 -24
  108. data/man/ronin-md5.1.md +11 -7
  109. data/man/ronin-netcat.1 +25 -51
  110. data/man/ronin-netcat.1.md +25 -21
  111. data/man/ronin-new-dns-proxy.1 +45 -0
  112. data/man/ronin-new-dns-proxy.1.md +44 -0
  113. data/man/ronin-new-project.1 +32 -45
  114. data/man/ronin-new-project.1.md +11 -11
  115. data/man/ronin-new-script.1 +10 -22
  116. data/man/ronin-new-script.1.md +4 -4
  117. data/man/ronin-new.1 +56 -31
  118. data/man/ronin-new.1.md +48 -8
  119. data/man/ronin-pack.1 +977 -0
  120. data/man/ronin-pack.1.md +929 -0
  121. data/man/ronin-proxy.1 +37 -63
  122. data/man/ronin-proxy.1.md +29 -25
  123. data/man/ronin-public-suffix-list.1 +16 -32
  124. data/man/ronin-public-suffix-list.1.md +13 -9
  125. data/man/ronin-quote.1 +17 -36
  126. data/man/ronin-quote.1.md +17 -13
  127. data/man/ronin-rot.1 +26 -39
  128. data/man/ronin-rot.1.md +15 -11
  129. data/man/ronin-sha1.1 +13 -24
  130. data/man/ronin-sha1.1.md +11 -7
  131. data/man/ronin-sha256.1 +13 -24
  132. data/man/ronin-sha256.1.md +11 -7
  133. data/man/ronin-sha512.1 +13 -24
  134. data/man/ronin-sha512.1.md +11 -7
  135. data/man/ronin-strings.1 +30 -55
  136. data/man/ronin-strings.1.md +27 -23
  137. data/man/ronin-tips.1 +8 -16
  138. data/man/ronin-tips.1.md +7 -3
  139. data/man/ronin-tld-list.1 +16 -32
  140. data/man/ronin-tld-list.1.md +13 -9
  141. data/man/ronin-typo.1 +14 -28
  142. data/man/ronin-typo.1.md +13 -9
  143. data/man/ronin-typosquat.1 +15 -32
  144. data/man/ronin-typosquat.1.md +15 -11
  145. data/man/ronin-unarchive.1.md +41 -0
  146. data/man/ronin-unescape.1 +22 -46
  147. data/man/ronin-unescape.1.md +22 -18
  148. data/man/ronin-unhexdump.1 +81 -91
  149. data/man/ronin-unhexdump.1.md +16 -12
  150. data/man/ronin-unpack.1 +978 -0
  151. data/man/ronin-unpack.1.md +920 -0
  152. data/man/ronin-unquote.1 +17 -36
  153. data/man/ronin-unquote.1.md +17 -13
  154. data/man/ronin-url.1 +19 -40
  155. data/man/ronin-url.1.md +19 -15
  156. data/man/ronin-xor.1 +14 -28
  157. data/man/ronin-xor.1.md +13 -9
  158. data/man/ronin.1 +208 -29
  159. data/man/ronin.1.md +156 -11
  160. data/scripts/setup +58 -0
  161. metadata +162 -73
  162. data/lib/ronin/config.rb +0 -95
  163. /data/data/{new → templates}/project/.gitignore +0 -0
  164. /data/data/{new → templates}/project/.ruby-version.erb +0 -0
  165. /data/data/{new → templates}/project/Dockerfile.erb +0 -0
  166. /data/data/{new → templates}/project/Gemfile.erb +0 -0
  167. /data/data/{new → templates}/project/Rakefile +0 -0
  168. /data/data/{new → templates}/project/project.rb.erb +0 -0
  169. /data/data/{new → templates}/script.rb.erb +0 -0
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'ronin/dns/proxy'
4
+
5
+ Ronin::DNS::Proxy.run(<%= @host.inspect %>, <%= @port.inspect %>) do |server|
6
+ # server.add_rule :A, 'example.com', '10.0.0.1'
7
+ # server.add_rule :AAAA, 'example.com', 'dead:beef::1'
8
+
9
+ # return multiple values:
10
+ #
11
+ # server.add_rule :A, 'ftp.example.com', ['10.0.0.42', '10.0.0.43']
12
+
13
+ # match a query using a regex:
14
+ #
15
+ # server.add_rule :TXT, /^spf\./, "v=spf1 include:10.0.0.1 ~all"
16
+
17
+ # return an error for a valid hostname:
18
+ #
19
+ # server.add_rule :A, 'updates.example.com', :ServFail
20
+
21
+ # define a dynamic rule:
22
+ #
23
+ # server.add_rule :CNAME, /^www\./, do |type,name,transaction|
24
+ # # append '.hax' to the domain name
25
+ # names = name.split('.').push('hax')
26
+ #
27
+ # transaction.respond!(names)
28
+ # end
29
+
30
+ # return MX records:
31
+ #
32
+ # server.add_rule :MX, 'example.com', do |type,name,transaction|
33
+ # transaction.respond!(10, Resolv::DNS::Name.create('email.evil.com' ))
34
+ # end
35
+ end
data/gemspec.yml CHANGED
@@ -2,12 +2,12 @@ name: ronin
2
2
  summary: A Ruby toolkit for security research and development.
3
3
  description:
4
4
  Ronin is a free and Open Source Ruby toolkit for security research and
5
- development.Ronin contains many different CLI commands and Ruby libraries for
5
+ development. Ronin contains many different CLI commands and Ruby libraries for
6
6
  a variety of security tasks, such as encoding/decoding data, filter
7
7
  IPs/hosts/URLs, querying ASNs, querying DNS, HTTP, scanning for web
8
8
  vulnerabilities, spidering websites, install 3rd party repositories of
9
9
  exploits and/or payloads, run exploits, generating new exploits, managing
10
- local databases, fuzzing data, and much more.
10
+ local databases, fuzzing data, perform recon, and much more.
11
11
 
12
12
  license: GPL-3.0
13
13
  authors: Postmodern
@@ -37,16 +37,20 @@ metadata:
37
37
  rubygems_mfa_required: 'true'
38
38
 
39
39
  generated_files:
40
+ - data/completions/ronin
40
41
  - man/ronin.1
41
42
  - man/ronin-asn.1
42
43
  - man/ronin-banner-grab.1
43
44
  - man/ronin-bitflip.1
45
+ - man/ronin-bitsquat.1
44
46
  - man/ronin-cert-dump.1
45
47
  - man/ronin-cert-gen.1
46
48
  - man/ronin-cert-grab.1
49
+ - man/ronin-completion.1
47
50
  - man/ronin-decode.1
48
51
  - man/ronin-decrypt.1
49
52
  - man/ronin-dns.1
53
+ - man/ronin-dns-proxy.1
50
54
  - man/ronin-email-addr.1
51
55
  - man/ronin-encrypt.1
52
56
  - man/ronin-encode.1
@@ -67,8 +71,10 @@ generated_files:
67
71
  - man/ronin-md5.1
68
72
  - man/ronin-netcat.1
69
73
  - man/ronin-new.1
74
+ - man/ronin-new-dns-proxy.1
70
75
  - man/ronin-new-project.1
71
76
  - man/ronin-new-script.1
77
+ - man/ronin-pack.1
72
78
  - man/ronin-proxy.1
73
79
  - man/ronin-public-suffix-list.1
74
80
  - man/ronin-quote.1
@@ -83,30 +89,38 @@ generated_files:
83
89
  - man/ronin-typosquat.1
84
90
  - man/ronin-unescape.1
85
91
  - man/ronin-unhexdump.1
92
+ - man/ronin-unpack.1
86
93
  - man/ronin-unquote.1
87
94
  - man/ronin-url.1
88
95
  - man/ronin-xor.1
89
96
 
90
- required_ruby_version: ">= 3.0.0"
97
+ required_ruby_version: ">= 3.1.0"
91
98
 
92
99
  dependencies:
93
100
  # Library dependencies:
94
101
  open_namespace: ~> 0.4
95
102
  rouge: ~> 3.0
96
103
  async-io: ~> 1.0
97
- wordlist: ~> 1.0, >= 1.0.3
104
+ wordlist: ~> 1.1
98
105
  # Ronin dependencies:
99
- ronin-support: ~> 1.0, >= 1.0.3
100
- ronin-core: ~> 0.1, >= 0.1.2
101
- ronin-repos: ~> 0.1
102
- ronin-db: ~> 0.1
103
- ronin-fuzzer: ~> 0.1
104
- ronin-web: ~> 1.0, >= 1.0.1
106
+ ronin-support: ~> 1.1.0.rc1
107
+ ronin-dns-proxy: ~> 0.1.0.rc1
108
+ ronin-core: ~> 0.2.0.rc1
109
+ ronin-repos: ~> 0.2.0.rc1
110
+ ronin-wordlists: ~> 0.1.0.rc1
111
+ ronin-db: ~> 0.2.0.rc1
112
+ ronin-listener: ~> 0.1.0.rc1
113
+ ronin-nmap: ~> 0.1.0.rc1
114
+ ronin-masscan: ~> 0.1.0.rc1
115
+ ronin-recon: ~> 0.1.0.rc1
116
+ ronin-fuzzer: ~> 0.2.0.rc1
117
+ ronin-web: ~> 2.0.0.rc1
105
118
  ronin-code-asm: ~> 1.0
106
119
  ronin-code-sql: ~> 2.0
107
- ronin-payloads: ~> 0.1, >= 0.1.1
108
- ronin-exploits: ~> 1.0, >= 1.0.1
109
- ronin-vulns: ~> 0.1, >= 0.1.2
120
+ ronin-payloads: ~> 0.2.0.rc1
121
+ ronin-exploits: ~> 1.1.0.rc1
122
+ ronin-vulns: ~> 0.2.0.rc1
123
+ ronin-app: ~> 0.1.0.rc1
110
124
 
111
125
  development_dependencies:
112
126
  bundler: ~> 2.0
@@ -0,0 +1,124 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright (c) 2006-2023 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 'ronin/support/binary/template'
20
+
21
+ module Ronin
22
+ class CLI
23
+ #
24
+ # Module for commands that uses [Ronin::Support::Binary::Template].
25
+ #
26
+ # [Ronin::Support::Binary::Template]: https://ronin-rb.dev/docs/ronin-support/Ronin/Support/Binary/Template.html
27
+ #
28
+ # @since 2.1.0
29
+ #
30
+ module BinaryTemplate
31
+ #
32
+ # Adds the `--endian`, `--arch`, and `--os` options to the command
33
+ # class including {BinaryTemplate}.
34
+ #
35
+ # @param [Class<Command>] command
36
+ # The command class including {BinaryTemplate}.
37
+ #
38
+ def self.included(command)
39
+ command.option :endian, short: '-E',
40
+ value: {
41
+ type: [:little, :big, :net]
42
+ },
43
+ desc: 'Sets the endianness'
44
+
45
+ command.option :arch, short: '-A',
46
+ value: {
47
+ type: [
48
+ :x86, :x86_64,
49
+ :ppc, :ppc64,
50
+ :mips, :mips_le, :mips_be,
51
+ :mips64, :mips64_le, :mips64_be,
52
+ :arm, :arm_le, :arm_be,
53
+ :arm64, :arm64_le, :arm64_be
54
+ ]
55
+ },
56
+ desc: 'Sets the architecture'
57
+
58
+ command.option :os, short: '-O',
59
+ value: {
60
+ type: [
61
+ :linux,
62
+ :macos,
63
+ :windows,
64
+ :android,
65
+ :apple_ios,
66
+ :bsd,
67
+ :freebsd,
68
+ :openbsd,
69
+ :netbsd
70
+ ]
71
+ },
72
+ desc: 'Sets the OS'
73
+ end
74
+
75
+ #
76
+ # Parses a type string.
77
+ #
78
+ # @param [String] string
79
+ # The raw type signature to parse.
80
+ #
81
+ # @return [Symbol, (Symbol, Integer)]
82
+ # The parsed type signature.
83
+ #
84
+ def parse_type(string)
85
+ unless (match = string.match(/\A(?<type>[a-z0-9_]+)(?:\[(?<array_size>\d*)\])?\z/))
86
+ print_error "invalid type: #{string}"
87
+ exit(-1)
88
+ end
89
+
90
+ type = match[:type].to_sym
91
+ array_size = match[:array_size]
92
+
93
+ if array_size && array_size.empty?
94
+ # unbounded array
95
+ type = (type..)
96
+ elsif array_size
97
+ # sized array
98
+ type = [type, array_size.to_i]
99
+ end
100
+
101
+ return type
102
+ end
103
+
104
+ #
105
+ # Builds a binary template for the given types and for the optional
106
+ # `--endian`, `--arch`, and `--os` options.
107
+ #
108
+ # @param [Array<Symbol, (Symbol, Integer)>] types
109
+ # The types for each field in the binary template.
110
+ #
111
+ # @return [Ronin::Support::Binary::Template]
112
+ # The binary template.
113
+ #
114
+ def build_template(types)
115
+ Support::Binary::Template.new(types, endian: options[:endian],
116
+ arch: options[:arch],
117
+ os: options[:os])
118
+ rescue ArgumentError => error
119
+ print_error(error.message)
120
+ exit(1)
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,104 @@
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 'ronin/cli/file_processor_command'
20
+ require 'ronin/support/archive'
21
+
22
+ module Ronin
23
+ class CLI
24
+ module Commands
25
+ #
26
+ # Archive the files.
27
+ #
28
+ # ## Usage
29
+ #
30
+ # ronin archive [option] [FILE ...]
31
+ #
32
+ # ## Options
33
+ #
34
+ # -f, --format tar|zip Archive format
35
+ # -o, --output PATH Archived file path
36
+ #
37
+ # ## Arguments
38
+ #
39
+ # FILE ... Optional file(s) to archive
40
+ #
41
+ # @since 2.1.0
42
+ #
43
+ class Archive < FileProcessorCommand
44
+
45
+ usage '[options] [FILE ...]'
46
+
47
+ option :format, short: '-f',
48
+ value: {
49
+ type: [:tar, :zip]
50
+ },
51
+ desc: 'Archive format'
52
+
53
+ option :output, short: '-o',
54
+ value: {
55
+ type: String,
56
+ usage: 'PATH'
57
+ },
58
+ desc: 'Archived file path'
59
+
60
+ description 'Archive the data'
61
+
62
+ man_page 'ronin-archive.1'
63
+
64
+ # Mapping of archive file extensions and their formats.
65
+ ARCHIVE_FORMATS = {
66
+ '.tar' => :tar,
67
+ '.zip' => :zip
68
+ }
69
+
70
+ #
71
+ # Runs the `archive` sub-command.
72
+ #
73
+ # @param [Array<String>] files
74
+ # File arguments.
75
+ #
76
+ def run(*files)
77
+ unless (output = options[:output])
78
+ print_error "must specify the --output option"
79
+ exit(-1)
80
+ end
81
+
82
+ format = options.fetch(:format) do
83
+ ARCHIVE_FORMATS.fetch(File.extname(output)) do
84
+ print_error "must either specify --format or a .tar or .zip output file"
85
+ exit(1)
86
+ end
87
+ end
88
+
89
+ unless files.empty?
90
+ Ronin::Support::Archive.send(format,output) do |archive|
91
+ files.each do |file|
92
+ archive.add_file(file) do |io|
93
+ File.open(file, 'rb') do |opened_file|
94
+ io.write(opened_file.readpartial(4096)) until opened_file.eof?
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
@@ -45,6 +45,8 @@ module Ronin
45
45
 
46
46
  include HostAndPort
47
47
 
48
+ command_name 'banner-grab'
49
+
48
50
  usage '[options] {HOST:PORT} ...'
49
51
 
50
52
  option :with_host_port, desc: 'Print the service with the banner'
@@ -18,7 +18,7 @@
18
18
 
19
19
  require 'ronin/cli/value_processor_command'
20
20
  require 'ronin/cli/char_set_options'
21
- require 'ronin/support/binary/core_ext/string'
21
+ require 'ronin/support/binary/bit_flip/core_ext/string'
22
22
  require 'ronin/support/encoding/hex'
23
23
 
24
24
  require 'chars'
@@ -0,0 +1,119 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright (c) 2006-2023 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 'ronin/cli/value_processor_command'
20
+
21
+ require 'ronin/support/binary/bit_flip/core_ext/string'
22
+ require 'ronin/support/text/patterns/network'
23
+ require 'ronin/support/network/host'
24
+
25
+ module Ronin
26
+ class CLI
27
+ module Commands
28
+ #
29
+ # Finds bit-flips of a domain.
30
+ #
31
+ # ## Usage
32
+ #
33
+ # ronin bitsquat [options] [DOMAIN ...]
34
+ #
35
+ # ## Options
36
+ #
37
+ # -f, --file FILE Optional file to read values from
38
+ # --has-addresses Print bitsquat domains with addresses
39
+ # --registered Print bitsquat domains that are already registered
40
+ # --unregistered Print bitsquat domains that can be registered
41
+ # -h, --help Print help information
42
+ #
43
+ # ## Arguments
44
+ #
45
+ # [DOMAIN ...] The domain to bit-flip
46
+ #
47
+ class Bitsquat < ValueProcessorCommand
48
+
49
+ usage '[options] [DOMAIN ...]'
50
+
51
+ option :has_addresses, desc: 'Print bitsquat domains with addresses'
52
+
53
+ option :registered, desc: 'Print bitsquat domains that are already registered'
54
+
55
+ option :unregistered, desc: 'Print bitsquat domains that can be registered'
56
+
57
+ argument :domain, required: false,
58
+ repeats: true,
59
+ desc: 'The domain to bit-flip'
60
+
61
+ description "Finds bit-flips of a domain"
62
+
63
+ man_page 'ronin-bitsquat.1'
64
+
65
+ # Regular expression for a valid host name.
66
+ VALID_HOST_NAME = /\A#{Support::Text::Patterns::HOST_NAME}\z/
67
+
68
+ #
69
+ # Queries the bit-flips of a domain.
70
+ #
71
+ # @param [String] domain
72
+ # The string to bit-flip and query.
73
+ #
74
+ def process_value(domain)
75
+ if options[:has_addresses]
76
+ each_bit_squat(domain) do |host|
77
+ puts host if host.has_addresses?
78
+ end
79
+ elsif options[:registered]
80
+ each_bit_squat(domain) do |host|
81
+ puts host if host.registered?
82
+ end
83
+ elsif options[:unregistered]
84
+ each_bit_squat(domain) do |host|
85
+ puts host if host.unregistered?
86
+ end
87
+ else
88
+ each_bit_squat(domain) do |host|
89
+ puts host
90
+ end
91
+ end
92
+ end
93
+
94
+ #
95
+ # Enumerates over each bitsquat of the domain.
96
+ #
97
+ # @param [String] domain
98
+ # The domain to check for bitsquats.
99
+ #
100
+ # @yield [bitsquat_host]
101
+ # The given block will be passed each bitsquatted domain variant.
102
+ #
103
+ # @yieldparam [Ronin::Support::Network::Host] bitsquat_host
104
+ # A host object for the bitsquatted domain variant.
105
+ #
106
+ def each_bit_squat(domain)
107
+ domain.each_bit_flip do |bit_flipped|
108
+ bit_flipped.force_encoding(Encoding::UTF_8)
109
+
110
+ if bit_flipped.valid_encoding? && bit_flipped =~ VALID_HOST_NAME
111
+ yield Support::Network::Host.new(bit_flipped)
112
+ end
113
+ end
114
+ end
115
+
116
+ end
117
+ end
118
+ end
119
+ end
@@ -19,7 +19,7 @@
19
19
  require 'ronin/cli/value_processor_command'
20
20
  require 'ronin/cli/host_and_port'
21
21
  require 'ronin/support/crypto/cert'
22
- require 'ronin/support/network/ssl/mixin'
22
+ require 'ronin/support/network/ssl'
23
23
 
24
24
  require 'command_kit/printing/indent'
25
25
  require 'command_kit/printing/fields'
@@ -59,12 +59,13 @@ module Ronin
59
59
  #
60
60
  class CertDump < ValueProcessorCommand
61
61
 
62
- include Support::Network::SSL::Mixin
63
62
  include CommandKit::Printing::Indent
64
63
  include CommandKit::Printing::Fields
65
64
  include CommandKit::Printing::Lists
66
65
  include HostAndPort
67
66
 
67
+ command_name 'cert-dump'
68
+
68
69
  usage '[options] {HOST:PORT | URL | FILE} ...'
69
70
 
70
71
  option :common_name, short: '-C',
@@ -104,11 +105,11 @@ module Ronin
104
105
  when /\A[^:]+:\d+\z/
105
106
  host, port = host_and_port(value)
106
107
 
107
- print_cert(ssl_cert(host,port))
108
+ grab_cert(host,port)
108
109
  when /\Ahttps:/
109
110
  host, port = host_and_port_from_url(value)
110
111
 
111
- print_cert(ssl_cert(host,port))
112
+ grab_cert(host,port)
112
113
  else
113
114
  unless File.file?(value)
114
115
  print_error "no such file or directory: #{value}"
@@ -121,6 +122,21 @@ module Ronin
121
122
  end
122
123
  end
123
124
 
125
+ #
126
+ # Gets the certs from the host and port, and then print it.
127
+ #
128
+ # @param [String] host
129
+ #
130
+ # @param [Integer] port
131
+ #
132
+ # @since 2.1.0
133
+ #
134
+ def grab_cert(host,port)
135
+ cert = Support::Network::SSL.get_cert(host,port)
136
+
137
+ print_cert(cert)
138
+ end
139
+
124
140
  #
125
141
  # Prints the certificate.
126
142
  #
@@ -18,7 +18,9 @@
18
18
 
19
19
  require 'ronin/cli/command'
20
20
  require 'ronin/support/crypto/cert'
21
+ require 'ronin/support/crypto/key'
21
22
  require 'ronin/support/crypto/key/rsa'
23
+ require 'ronin/support/crypto/key/dsa'
22
24
  require 'ronin/support/crypto/key/ec'
23
25
  require 'ronin/support/text/patterns'
24
26
 
@@ -47,7 +49,7 @@ module Ronin
47
49
  # -L, --locality NAME The locality for the certificate
48
50
  # -S, --state XX The two-letter State (ST) code for the certificate
49
51
  # -C, --country XX The two-letter Country (C) code for the certificate
50
- # -t, --key-type rsa|ec The signing key type
52
+ # -t, --key-type rsa|dsa|ec The signing key type
51
53
  # --generate-key PATH Generates and saves a random key (Default: key.pem)
52
54
  # -k, --key-file FILE Loads the signing key from the FILE
53
55
  # -H sha256|sha1|md5, The hash algorithm to use for signing (Default: sha256)
@@ -70,6 +72,8 @@ module Ronin
70
72
 
71
73
  include Core::CLI::Logging
72
74
 
75
+ command_name 'cert-gen'
76
+
73
77
  option :version, value: {
74
78
  type: Integer,
75
79
  usage: 'NUM',
@@ -149,7 +153,7 @@ module Ronin
149
153
 
150
154
  option :key_type, short: '-t',
151
155
  value: {
152
- type: [:rsa, :ec]
156
+ type: [:rsa, :dsa, :ec]
153
157
  },
154
158
  desc: 'The signing key type'
155
159
 
@@ -245,6 +249,7 @@ module Ronin
245
249
  state: options[:state],
246
250
  country: options[:country]
247
251
  },
252
+ ca: options[:ca],
248
253
  extensions: extensions
249
254
  )
250
255
 
@@ -287,11 +292,13 @@ module Ronin
287
292
  # The `--key-type` key class.
288
293
  #
289
294
  # @return [Class<Ronin::Support::Key::RSA>,
295
+ # Class<Ronin::Support::Key::DSA>,
290
296
  # Class<Ronin::Support::Key::EC>, nil]
291
297
  #
292
298
  def key_class
293
299
  case options[:key_type]
294
300
  when :rsa then Support::Crypto::Key::RSA
301
+ when :dsa then Support::Crypto::Key::DSA
295
302
  when :ec then Support::Crypto::Key::EC
296
303
  end
297
304
  end
@@ -348,10 +355,6 @@ module Ronin
348
355
  def extensions
349
356
  exts = {}
350
357
 
351
- if (ext = basic_constraints_ext)
352
- exts['basicConstraints'] = ext
353
- end
354
-
355
358
  if (ext = subject_alt_name_ext)
356
359
  exts['subjectAltName'] = ext
357
360
  end
@@ -359,19 +362,6 @@ module Ronin
359
362
  exts unless exts.empty?
360
363
  end
361
364
 
362
- #
363
- # Builds the `basicConstraints` extension.
364
- #
365
- # @return [(String, Boolean), nil]
366
- #
367
- def basic_constraints_ext
368
- if options[:ca]
369
- ['CA:TRUE', true]
370
- elsif options[:ca_key] || options[:ca_cert]
371
- ['CA:FALSE', true]
372
- end
373
- end
374
-
375
365
  IP_REGEXP = Support::Text::Patterns::IP
376
366
 
377
367
  #
@@ -18,7 +18,7 @@
18
18
 
19
19
  require 'ronin/cli/value_processor_command'
20
20
  require 'ronin/cli/host_and_port'
21
- require 'ronin/support/network/ssl/mixin'
21
+ require 'ronin/support/network/ssl'
22
22
 
23
23
  require 'uri'
24
24
 
@@ -51,7 +51,8 @@ module Ronin
51
51
  class CertGrab < ValueProcessorCommand
52
52
 
53
53
  include HostAndPort
54
- include Support::Network::SSL::Mixin
54
+
55
+ command_name 'cert-grab'
55
56
 
56
57
  usage '[options] {HOST:PORT | URL} ...'
57
58
 
@@ -116,7 +117,7 @@ module Ronin
116
117
  # The port to connect to.
117
118
  #
118
119
  def grab_cert(host,port)
119
- cert = ssl_cert(host,port)
120
+ cert = Support::Network::SSL.get_cert(host,port)
120
121
 
121
122
  cert.save(cert_file_for(host,port))
122
123
  end