ronin-app 0.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +7 -0
  2. data/.dockerignore +3 -0
  3. data/.document +6 -0
  4. data/.env.dev +1 -0
  5. data/.github/workflows/ruby.yml +44 -0
  6. data/.gitignore +16 -0
  7. data/.rspec +1 -0
  8. data/.rubocop.yml +26 -0
  9. data/.ruby-version +1 -0
  10. data/.yardopts +1 -0
  11. data/CONTRIBUTING.md +34 -0
  12. data/COPYING.txt +661 -0
  13. data/ChangeLog.md +38 -0
  14. data/Dockerfile +27 -0
  15. data/Gemfile +61 -0
  16. data/Procfile +2 -0
  17. data/Procfile.dev +2 -0
  18. data/README.md +215 -0
  19. data/Rakefile +44 -0
  20. data/app/db.rb +680 -0
  21. data/app/scanning.rb +173 -0
  22. data/app.rb +372 -0
  23. data/bin/ronin-app +34 -0
  24. data/config/database.rb +17 -0
  25. data/config/puma.rb +24 -0
  26. data/config/redis.rb +4 -0
  27. data/config/sidekiq.rb +23 -0
  28. data/config/sidekiq.yml +12 -0
  29. data/config.ru +33 -0
  30. data/docker-compose.yml +45 -0
  31. data/etc/systemd/user/ronin-app-sidekiq.1.service +17 -0
  32. data/etc/systemd/user/ronin-app-web.1.service +18 -0
  33. data/etc/systemd/user/ronin-app.target +5 -0
  34. data/gemspec.yml +55 -0
  35. data/lib/middleware/sidekiq/active_record_connection_pool.rb +47 -0
  36. data/lib/ronin/app/cli.rb +197 -0
  37. data/lib/ronin/app/helpers/html.rb +71 -0
  38. data/lib/ronin/app/root.rb +28 -0
  39. data/lib/ronin/app/schemas/params_schema.rb +66 -0
  40. data/lib/ronin/app/schemas/payloads/build_schema.rb +56 -0
  41. data/lib/ronin/app/schemas/payloads/encoders/encode_schema.rb +60 -0
  42. data/lib/ronin/app/types/import.rb +35 -0
  43. data/lib/ronin/app/types/nmap.rb +81 -0
  44. data/lib/ronin/app/types/spider.rb +49 -0
  45. data/lib/ronin/app/types/vulns.rb +69 -0
  46. data/lib/ronin/app/types.rb +66 -0
  47. data/lib/ronin/app/validations/import_params.rb +71 -0
  48. data/lib/ronin/app/validations/install_repo_params.rb +78 -0
  49. data/lib/ronin/app/validations/masscan_params.rb +122 -0
  50. data/lib/ronin/app/validations/nmap_params.rb +183 -0
  51. data/lib/ronin/app/validations/recon_params.rb +86 -0
  52. data/lib/ronin/app/validations/spider_params.rb +103 -0
  53. data/lib/ronin/app/validations/vulns_params.rb +83 -0
  54. data/lib/ronin/app/version.rb +26 -0
  55. data/log/.gitkeep +0 -0
  56. data/man/ronin-app.1 +63 -0
  57. data/man/ronin-app.1.md +61 -0
  58. data/public/images/favicon.png +0 -0
  59. data/public/images/favicon.svg +78 -0
  60. data/public/images/logo.svg +78 -0
  61. data/public/images/sidekiq.svg +24 -0
  62. data/public/javascript/app.js +60 -0
  63. data/public/javascript/notes.js +28 -0
  64. data/public/javascript/tabs.js +40 -0
  65. data/public/stylesheets/app.css +216 -0
  66. data/public/stylesheets/bulma.min.css +1 -0
  67. data/ronin-app.gemspec +63 -0
  68. data/scripts/console +7 -0
  69. data/scripts/server +134 -0
  70. data/scripts/setup +447 -0
  71. data/scripts/update +55 -0
  72. data/tmp/.gitkeep +0 -0
  73. data/views/_authors.erb +62 -0
  74. data/views/_delete.erb +4 -0
  75. data/views/_delete_all.erb +4 -0
  76. data/views/_encoding_tabs.erb +25 -0
  77. data/views/_notes.erb +33 -0
  78. data/views/_pagination.erb +1 -0
  79. data/views/_param_fields.erb +66 -0
  80. data/views/_params.erb +35 -0
  81. data/views/about.erb +30 -0
  82. data/views/db/advisories/index.erb +30 -0
  83. data/views/db/advisories/show.erb +105 -0
  84. data/views/db/asns/index.erb +19 -0
  85. data/views/db/asns/show.erb +61 -0
  86. data/views/db/credentials/index.erb +30 -0
  87. data/views/db/credentials/show.erb +51 -0
  88. data/views/db/email_addresses/index.erb +30 -0
  89. data/views/db/email_addresses/show.erb +44 -0
  90. data/views/db/host_names/index.erb +30 -0
  91. data/views/db/host_names/show.erb +52 -0
  92. data/views/db/ip_addresses/index.erb +19 -0
  93. data/views/db/ip_addresses/show.erb +98 -0
  94. data/views/db/mac_addresses/index.erb +19 -0
  95. data/views/db/mac_addresses/show.erb +62 -0
  96. data/views/db/open_ports/index.erb +19 -0
  97. data/views/db/open_ports/show.erb +87 -0
  98. data/views/db/organizations/departments/show.erb +82 -0
  99. data/views/db/organizations/index.erb +28 -0
  100. data/views/db/organizations/members/show.erb +87 -0
  101. data/views/db/organizations/show.erb +111 -0
  102. data/views/db/oses/index.erb +19 -0
  103. data/views/db/oses/show.erb +46 -0
  104. data/views/db/passwords/index.erb +30 -0
  105. data/views/db/passwords/show.erb +52 -0
  106. data/views/db/people/index.erb +31 -0
  107. data/views/db/people/show.erb +120 -0
  108. data/views/db/phone_numbers/index.erb +30 -0
  109. data/views/db/phone_numbers/show.erb +63 -0
  110. data/views/db/ports/index.erb +30 -0
  111. data/views/db/ports/show.erb +70 -0
  112. data/views/db/services/index.erb +30 -0
  113. data/views/db/services/show.erb +65 -0
  114. data/views/db/software/index.erb +19 -0
  115. data/views/db/software/show.erb +52 -0
  116. data/views/db/software_vendors/index.erb +19 -0
  117. data/views/db/software_vendors/show.erb +36 -0
  118. data/views/db/street_addresses/index.erb +19 -0
  119. data/views/db/street_addresses/show.erb +63 -0
  120. data/views/db/url_query_param_names/index.erb +19 -0
  121. data/views/db/url_query_param_names/show.erb +50 -0
  122. data/views/db/url_schemes/index.erb +19 -0
  123. data/views/db/url_schemes/show.erb +36 -0
  124. data/views/db/urls/index.erb +30 -0
  125. data/views/db/urls/show.erb +103 -0
  126. data/views/db/user_names/index.erb +30 -0
  127. data/views/db/user_names/show.erb +48 -0
  128. data/views/db/vulns/index.erb +19 -0
  129. data/views/db/vulns/show.erb +104 -0
  130. data/views/db.erb +152 -0
  131. data/views/exploits/index.erb +9 -0
  132. data/views/exploits/show.erb +100 -0
  133. data/views/import.erb +30 -0
  134. data/views/index.erb +7 -0
  135. data/views/layout.erb +98 -0
  136. data/views/masscan.erb +459 -0
  137. data/views/nmap.erb +1009 -0
  138. data/views/payloads/build.erb +19 -0
  139. data/views/payloads/encoders/encode.erb +35 -0
  140. data/views/payloads/encoders/index.erb +9 -0
  141. data/views/payloads/encoders/show.erb +47 -0
  142. data/views/payloads/index.erb +9 -0
  143. data/views/payloads/show.erb +47 -0
  144. data/views/queue.erb +28 -0
  145. data/views/recon.erb +55 -0
  146. data/views/repos/index.erb +30 -0
  147. data/views/repos/install.erb +45 -0
  148. data/views/repos/show.erb +39 -0
  149. data/views/spider.erb +372 -0
  150. data/views/vulns.erb +214 -0
  151. data/workers/import.rb +96 -0
  152. data/workers/install_repo.rb +40 -0
  153. data/workers/masscan.rb +135 -0
  154. data/workers/nmap.rb +216 -0
  155. data/workers/purge_repos.rb +40 -0
  156. data/workers/recon.rb +95 -0
  157. data/workers/remove_repo.rb +40 -0
  158. data/workers/spider.rb +148 -0
  159. data/workers/update_repo.rb +42 -0
  160. data/workers/update_repos.rb +40 -0
  161. data/workers/vulns.rb +111 -0
  162. data/workers.rb +37 -0
  163. metadata +538 -0
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-app - a local web app for Ronin.
4
+ #
5
+ # Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
6
+ #
7
+ # ronin-app is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-app 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 Affero General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with ronin-app. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'ronin/app/types'
22
+
23
+ module Ronin
24
+ module App
25
+ module Types
26
+ #
27
+ # Types for {Validations::ImportParams} and {Workers::Import}.
28
+ #
29
+ module Import
30
+ # The type of file type
31
+ TypeType = Types::String.enum('nmap', 'masscan')
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-app - a local web app for Ronin.
4
+ #
5
+ # Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
6
+ #
7
+ # ronin-app is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-app 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 Affero General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with ronin-app. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'ronin/app/types'
22
+
23
+ require 'nmap/command'
24
+
25
+ module Ronin
26
+ module App
27
+ module Types
28
+ module Nmap
29
+ # Represents a time value.
30
+ Time = Types::String.constrained(format: ::Nmap::Command::Time::REGEXP)
31
+
32
+ # Represents a hex string for the `--data` option (ex: `123ABC`).
33
+ HexString = Types::String.constrained(format: ::Nmap::Command::HexString::REGEXP)
34
+
35
+ # Represents a port number (ex: `80`).
36
+ Port = Types::String.constrained(format: ::Nmap::Command::Port::REGEXP)
37
+
38
+ # Represent a port-range (ex: `80` or `1-80`).
39
+ PortRange = Types::String.constrained(format: ::Nmap::Command::PortRange::REGEXP)
40
+
41
+ # Represent a comma separated list of port-ranges (ex: `1-80,443`).
42
+ PortRangeList = Types::String.constrained(format: ::Nmap::Command::PortRangeList::REGEXP)
43
+
44
+ # Represents a protocol list for the `-PO` option.
45
+ ProtocolList = PortRangeList
46
+
47
+ # Represents a single flag value for the `--scanflags` option.
48
+ ScanFlag = Types::Symbol.enum(
49
+ urg: 'urg',
50
+ ack: 'ack',
51
+ psh: 'psh',
52
+ rst: 'rst',
53
+ syn: 'syn',
54
+ fin: 'fin'
55
+ )
56
+
57
+ # Represents `--scanflags` value.
58
+ ScanFlags = Types::Array.of(ScanFlag)
59
+
60
+ # Represents a value for the `--nsock-engine` option.
61
+ NsockEngine = Types::String.enum(
62
+ 'iocp',
63
+ 'epoll',
64
+ 'kqueue',
65
+ 'poll',
66
+ 'select'
67
+ )
68
+
69
+ # Represents a value for the `--timing-template` option.
70
+ TimingTemplate = Types::String.enum(
71
+ 'paranoid',
72
+ 'sneaky',
73
+ 'polite',
74
+ 'normal',
75
+ 'aggressive',
76
+ 'insane'
77
+ )
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-app - a local web app for Ronin.
4
+ #
5
+ # Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
6
+ #
7
+ # ronin-app is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-app 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 Affero General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with ronin-app. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'ronin/app/types'
22
+
23
+ module Ronin
24
+ module App
25
+ module Types
26
+ #
27
+ # Types for {Validations::SpiderParams}.
28
+ #
29
+ module Spider
30
+ # The type of web spider targets
31
+ TargetType = Types::String.enum('host', 'domain', 'site')
32
+
33
+ # Represents a list of hosts.
34
+ HostList = Types::List
35
+
36
+ # Represents a comma separated list of ports.
37
+ PortList = Types::Array.of(Types::Integer).constructor do |value|
38
+ value.split(/(?:,\s*|\s+)/).map(&:to_i)
39
+ end
40
+
41
+ # Represents a list of URLs.
42
+ URLList = Types::List
43
+
44
+ # Represents a list of file exts.
45
+ ExtList = Types::List
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-app - a local web app for Ronin.
4
+ #
5
+ # Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
6
+ #
7
+ # ronin-app is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-app 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 Affero General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with ronin-app. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'ronin/app/types'
22
+
23
+ module Ronin
24
+ module App
25
+ module Types
26
+ #
27
+ # Types for {Validations::VulnsParams}.
28
+ #
29
+ module Vulns
30
+ module LFI
31
+ # The type of OS
32
+ OSType = Types::Symbol.enum(
33
+ unix: 'unix',
34
+ windows: 'windows'
35
+ )
36
+
37
+ # The lfi filter bypass technique type
38
+ FilterBypassType = Types::Symbol.enum(
39
+ null_byte: 'null_byte',
40
+ double_escape: 'double_escape',
41
+ base64: 'base64',
42
+ rot13: 'rot13',
43
+ zlib: 'zlib'
44
+ )
45
+ end
46
+
47
+ module RFI
48
+ # The rfi filter bypass technique type
49
+ FilterBypassType = Types::Symbol.enum(
50
+ null_byte: 'null_byte',
51
+ double_encode: 'double_encode',
52
+ suffix_escape: 'suffix_escape'
53
+ )
54
+ end
55
+
56
+ module SSTI
57
+ # The type of SSTI escape expression
58
+ EscapeType = Types::Symbol.enum(
59
+ double_curly_braces: 'double_curly_braces',
60
+ dollar_curly_braces: 'dollar_curly_braces',
61
+ dollar_double_curly_braces: 'dollar_double_curly_braces',
62
+ pound_curly_braces: 'pound_curly_braces',
63
+ angle_brackets_percent: 'angle_brackets_percent'
64
+ )
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-app - a local web app for Ronin.
4
+ #
5
+ # Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
6
+ #
7
+ # ronin-app is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-app 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 Affero General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with ronin-app. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'dry/types'
22
+
23
+ module Ronin
24
+ module App
25
+ #
26
+ # Types used by `ronin-app`.
27
+ #
28
+ module Types
29
+ include Dry::Types()
30
+
31
+ # Represents an Array of argument values.
32
+ Args = Types::Array.of(Types::String).constructor do |value|
33
+ value.split
34
+ end
35
+
36
+ # Represents a space or comma separated list of values.
37
+ List = Types::Array.of(Types::String).constructor do |value|
38
+ value.split(/(?:,\s*|\s+)/)
39
+ end
40
+
41
+ # Represents a comma separated list of values.
42
+ CommaSeparatedList = Types::Array.of(Types::String).constructor do |value|
43
+ value.split(/,\s*/)
44
+ end
45
+
46
+ # Represents an HTTP method name.
47
+ HTTPMethod = Types::String.enum(
48
+ 'COPY',
49
+ 'DELETE',
50
+ 'GET',
51
+ 'HEAD',
52
+ 'LOCK',
53
+ 'MKCOL',
54
+ 'MOVE',
55
+ 'OPTIONS',
56
+ 'PATCH',
57
+ 'POST',
58
+ 'PROPFIND',
59
+ 'PROPPATCH',
60
+ 'PUT',
61
+ 'TRACE',
62
+ 'UNLOCK'
63
+ )
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-app - a local web app for Ronin.
4
+ #
5
+ # Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
6
+ #
7
+ # ronin-app is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-app 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 Affero General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with ronin-app. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'ronin/app/types/import'
22
+
23
+ require 'dry/validation'
24
+ require 'set'
25
+
26
+ require 'masscan/output_file'
27
+
28
+ module Ronin
29
+ module App
30
+ module Validations
31
+ #
32
+ # Validations for the form params submitted to `POST /import`.
33
+ #
34
+ class ImportParams < Dry::Validation::Contract
35
+
36
+ params do
37
+ required(:type).filled(Types::Import::TypeType)
38
+ required(:path).filled(:string)
39
+ end
40
+
41
+ # Mapping of `type` values to their set of valid file extension names.
42
+ VALID_FILE_EXTS = {
43
+ 'nmap' => Set['.xml'],
44
+ 'masscan' => Masscan::OutputFile::FILE_FORMATS.keys.to_set
45
+ }
46
+
47
+ rule(:path) do
48
+ valid_file_exts = VALID_FILE_EXTS.fetch(values[:type])
49
+
50
+ unless valid_file_exts.include?(File.extname(value))
51
+ key.failure("#{values[:type]} file path must end with #{valid_file_exts.join(', ')}")
52
+ end
53
+ end
54
+
55
+ #
56
+ # Initializes and calls the validation contract.
57
+ #
58
+ # @param [Hash{String => Object}] params
59
+ # The HTTP params to validate.
60
+ #
61
+ # @return [Dry::Validation::Result]
62
+ # The validation result.
63
+ #
64
+ def self.call(params)
65
+ new.call(params)
66
+ end
67
+
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-app - a local web app for Ronin.
4
+ #
5
+ # Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
6
+ #
7
+ # ronin-app is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-app 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 Affero General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with ronin-app. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'dry/validation'
22
+
23
+ require 'uri'
24
+
25
+ module Ronin
26
+ module App
27
+ module Validations
28
+ #
29
+ # Validations for form params submitted to `POST /repos/install`.
30
+ #
31
+ class InstallRepoParams < Dry::Validation::Contract
32
+
33
+ params do
34
+ required(:uri).filled(:string)
35
+ optional(:name).maybe(:string)
36
+ end
37
+
38
+ # Regular expression that matches `https://`, `http://`, `ssh://`, and
39
+ # `git://` URIs.
40
+ URI_REGEX = URI::DEFAULT_PARSER.make_regexp(%w[https http git ssh])
41
+
42
+ # Regular expression that matches both `https://` URIs and
43
+ # `git@host.com:path/to/repo.git` URIs.
44
+ GIT_URI_REGEX = %r{\A(?:#{URI_REGEX}|[^@]+@[A-Za-z0-9._-]+(?::\d+)?:[A-Za-z0-9./_-]+)\z}
45
+
46
+ rule(:uri) do
47
+ unless value =~ GIT_URI_REGEX
48
+ key.failure('URI must be a https:// or a git@host:path/to/repo.git URI')
49
+ end
50
+ end
51
+
52
+ # Regular expression that matches an alpha-numeric name containing
53
+ # dashes and/or underscores.
54
+ NAME_REGEX = /\A[A-Za-z0-9_-]+\z/
55
+
56
+ rule(:name) do
57
+ if value && value !~ NAME_REGEX
58
+ key.failure('repo name must only contain alpha-numeric, dashes, and underscores')
59
+ end
60
+ end
61
+
62
+ #
63
+ # Initializes and calls the validation contract.
64
+ #
65
+ # @param [Hash{String => Object}] params
66
+ # The HTTP params to validate.
67
+ #
68
+ # @return [Dry::Validation::Result]
69
+ # The validation result.
70
+ #
71
+ def self.call(params)
72
+ new.call(params)
73
+ end
74
+
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,122 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-app - a local web app for Ronin.
4
+ #
5
+ # Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
6
+ #
7
+ # ronin-app is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-app 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 Affero General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with ronin-app. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'dry/validation'
22
+ require 'ronin/app/types'
23
+
24
+ require 'masscan/command'
25
+
26
+ module Ronin
27
+ module App
28
+ module Validations
29
+ #
30
+ # Validations for the form params submitted to `POST /masscan`.
31
+ #
32
+ class MasscanParams < Dry::Validation::Contract
33
+
34
+ params do
35
+ required(:ips).filled(Types::Args).each(:filled?)
36
+ required(:ports).filled(:string)
37
+
38
+ optional(:banners).maybe(:bool)
39
+ optional(:rate).maybe(:integer)
40
+ optional(:config_file).maybe(:string)
41
+ optional(:adapter).maybe(:string)
42
+ optional(:adapter_ip).maybe(:string)
43
+ optional(:adapter_port).maybe(:string)
44
+ optional(:adapter_mac).maybe(:string)
45
+ optional(:adapter_vlan).maybe(:string)
46
+ optional(:router_mac).maybe(:string)
47
+ optional(:ping).maybe(:bool)
48
+ optional(:exclude).maybe(:string)
49
+ optional(:exclude_file).maybe(:string)
50
+ optional(:include_file).maybe(:string)
51
+ optional(:pcap_payloads).maybe(:string)
52
+ optional(:nmap_payloads).maybe(:string)
53
+ optional(:http_method).maybe(Types::HTTPMethod)
54
+ optional(:http_url).maybe(:string)
55
+ optional(:http_version).maybe(:string)
56
+ optional(:http_host).maybe(:string)
57
+ optional(:http_user_agent).maybe(:string)
58
+ optional(:http_field).maybe(:string)
59
+ optional(:http_cookie).maybe(:string)
60
+ optional(:http_payload).maybe(:string)
61
+ optional(:open_only).maybe(:bool)
62
+ optional(:pcap).maybe(:string)
63
+ optional(:packet_trace).maybe(:bool)
64
+ optional(:pfring).maybe(:bool)
65
+ optional(:shards).maybe(:string)
66
+ optional(:seed).maybe(:integer)
67
+ optional(:ttl).maybe(:integer)
68
+ optional(:wait).maybe(:integer)
69
+ optional(:retries).maybe(:integer)
70
+
71
+ before(:value_coercer) do |result|
72
+ result.to_h.reject { |key,value| value.empty? }
73
+ end
74
+ end
75
+
76
+ rule(:ports) do
77
+ if value && value !~ ::Masscan::Command::PortList::REGEXP
78
+ key.failure("invalid masscan port list")
79
+ end
80
+ end
81
+
82
+ rule(:adapter_port) do
83
+ if value && value !~ ::Masscan::Command::PortRange::REGEXP
84
+ key.failure('invalid port or port range')
85
+ end
86
+ end
87
+
88
+ rule(:router_mac) do
89
+ if value && value !~ ::Masscan::Command::MACAddress::REGEXP
90
+ key.failure('invalid MAC address')
91
+ end
92
+ end
93
+
94
+ rule(:exclude) do
95
+ if value && value !~ ::Masscan::Command::Target::REGEXP
96
+ key.failure('invalid IP or IP range')
97
+ end
98
+ end
99
+
100
+ rule(:shards) do
101
+ if value && value !~ ::Masscan::Command::Shards::REGEXP
102
+ key.failure('invalid shards value')
103
+ end
104
+ end
105
+
106
+ #
107
+ # Initializes and calls the validation contract.
108
+ #
109
+ # @param [Hash{String => Object}] params
110
+ # The HTTP params to validate.
111
+ #
112
+ # @return [Dry::Validation::Result]
113
+ # The validation result.
114
+ #
115
+ def self.call(params)
116
+ new.call(params)
117
+ end
118
+
119
+ end
120
+ end
121
+ end
122
+ end