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
data/app/scanning.rb ADDED
@@ -0,0 +1,173 @@
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
+ # param validations
22
+ require 'ronin/app/validations/recon_params'
23
+ require 'ronin/app/validations/nmap_params'
24
+ require 'ronin/app/validations/masscan_params'
25
+ require 'ronin/app/validations/spider_params'
26
+ require 'ronin/app/validations/vulns_params'
27
+
28
+ # helpers
29
+ require 'ronin/app/helpers/html'
30
+
31
+ # worker classes
32
+ require './workers/nmap'
33
+ require './workers/masscan'
34
+ require './workers/spider'
35
+ require './workers/recon'
36
+ require './workers/vulns'
37
+
38
+ #
39
+ # App class containing routes for scanning.
40
+ #
41
+ class App < Sinatra::Base
42
+
43
+ include Ronin::App
44
+ include Pagy::Backend
45
+
46
+ configure do
47
+ enable :sessions
48
+ register Sinatra::Flash
49
+ helpers Sinatra::ContentFor
50
+ helpers Helpers::HTML
51
+ end
52
+
53
+ configure :development do
54
+ register Sinatra::Reloader
55
+ end
56
+
57
+ helpers do
58
+ include Pagy::Frontend
59
+ end
60
+
61
+ get '/recon' do
62
+ erb :recon
63
+ end
64
+
65
+ post '/recon' do
66
+ result = Validations::ReconParams.call(params)
67
+
68
+ if result.success?
69
+ @jid = Workers::Recon.perform_async(result.to_h)
70
+
71
+ scope = result[:scope]
72
+
73
+ flash[:success] = "Recon of #{scope.join(', ')} enqueued"
74
+ redirect '/recon'
75
+ else
76
+ @params = params
77
+ @errors = result.errors
78
+
79
+ flash[:danger] = 'Failed to submit recon request!'
80
+ halt 400, erb(:recon)
81
+ end
82
+ end
83
+
84
+ get '/nmap' do
85
+ erb :nmap
86
+ end
87
+
88
+ post '/nmap' do
89
+ result = Validations::NmapParams.call(params)
90
+
91
+ if result.success?
92
+ @jid = Workers::Nmap.perform_async(result.to_h)
93
+
94
+ targets = result[:targets]
95
+
96
+ flash[:success] = "Scan of #{targets.join(',')} enqueued"
97
+ redirect '/nmap'
98
+ else
99
+ @params = params
100
+ @errors = result.errors
101
+
102
+ flash[:danger] = 'Failed to submit nmap scan!'
103
+ halt 400, erb(:nmap)
104
+ end
105
+ end
106
+
107
+ get '/masscan' do
108
+ erb :masscan
109
+ end
110
+
111
+ post '/masscan' do
112
+ result = Validations::MasscanParams.call(params)
113
+
114
+ if result.success?
115
+ @jid = Workers::Masscan.perform_async(result.to_h)
116
+
117
+ targets = result[:ips]
118
+
119
+ flash[:success] = "Scan of #{targets.join(',')} enqueued"
120
+ redirect '/masscan'
121
+ else
122
+ @errors = result.errors
123
+
124
+ flash[:danger] = 'Failed to submit masscan scan!'
125
+ halt 400, erb(:masscan)
126
+ end
127
+ end
128
+
129
+ get '/spider' do
130
+ erb :spider
131
+ end
132
+
133
+ post '/spider' do
134
+ result = Validations::SpiderParams.call(params)
135
+
136
+ if result.success?
137
+ @jid = Workers::Spider.perform_async(result.to_h)
138
+
139
+ type = result[:type]
140
+ target = result[:target]
141
+
142
+ flash[:success] = "Web spider of #{type} #{target} enqueued"
143
+ redirect '/spider'
144
+ else
145
+ @errors = result.errors
146
+
147
+ flash[:danger] = 'Failed to submit spider scan!'
148
+ halt 400, erb(:spider)
149
+ end
150
+ end
151
+
152
+ get '/vulns' do
153
+ erb :vulns
154
+ end
155
+
156
+ post '/vulns' do
157
+ result = Validations::VulnsParams.call(params)
158
+
159
+ if result.success?
160
+ @jid = Workers::Vulns.perform_async(result.to_h)
161
+
162
+ url = result[:url]
163
+
164
+ flash[:success] = "Vulnerabilities scanner of URL #{url} enqueued"
165
+ redirect '/vulns'
166
+ else
167
+ @errors = result.errors
168
+
169
+ flash[:danger] = 'Failed to submit vulnerabilities scan!'
170
+ halt 400, erb(:vulns)
171
+ end
172
+ end
173
+ end
data/app.rb ADDED
@@ -0,0 +1,372 @@
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
+ $LOAD_PATH.unshift(File.join(__dir__,'lib'))
22
+
23
+ # classes
24
+ require 'sinatra/base'
25
+ require 'sinatra/content_for'
26
+ require 'sinatra/flash'
27
+ require 'sinatra/reloader'
28
+
29
+ # configuration
30
+ require './config/database'
31
+ require './config/sidekiq'
32
+
33
+ # ronin libraries
34
+ require 'ronin/repos'
35
+ require 'ronin/payloads'
36
+ require 'ronin/exploits'
37
+ require 'ronin/support/encoding'
38
+
39
+ # param validations
40
+ require 'ronin/app/validations/install_repo_params'
41
+ require 'ronin/app/validations/import_params'
42
+
43
+ # schema builders
44
+ require 'ronin/app/schemas/payloads/encoders/encode_schema'
45
+ require 'ronin/app/schemas/payloads/build_schema'
46
+
47
+ # helpers
48
+ require 'ronin/app/helpers/html'
49
+
50
+ # worker classes
51
+ require './workers/install_repo'
52
+ require './workers/update_repo'
53
+ require './workers/update_repos'
54
+ require './workers/remove_repo'
55
+ require './workers/purge_repos'
56
+ require './workers/import'
57
+
58
+ require 'ronin/app/version'
59
+ require 'sidekiq/api'
60
+
61
+ # others
62
+ require 'pagy'
63
+ require 'pagy/extras/bulma'
64
+
65
+ #
66
+ # Main app class.
67
+ #
68
+ class App < Sinatra::Base
69
+
70
+ include Ronin::App
71
+ include Pagy::Backend
72
+
73
+ configure do
74
+ enable :sessions
75
+ enable :method_override
76
+ register Sinatra::Flash
77
+ helpers Sinatra::ContentFor
78
+ helpers Helpers::HTML
79
+ end
80
+
81
+ configure :development do
82
+ register Sinatra::Reloader
83
+ end
84
+
85
+ helpers do
86
+ include Pagy::Frontend
87
+ end
88
+
89
+ after do
90
+ ActiveRecord::Base.connection_handler.clear_active_connections!
91
+ end
92
+
93
+ get '/' do
94
+ erb :index
95
+ end
96
+
97
+ get '/repos' do
98
+ @repos = Ronin::Repos.cache_dir
99
+
100
+ erb :"repos/index"
101
+ end
102
+
103
+ get '/repos/install' do
104
+ erb :"repos/install"
105
+ end
106
+
107
+ post '/repos/install' do
108
+ result = Validations::InstallRepoParams.call(params)
109
+
110
+ if result.success?
111
+ Workers::InstallRepo.perform_async(result[:uri],result[:name])
112
+
113
+ flash[:success] = "Installing repo at #{result[:uri]}"
114
+ redirect '/repos'
115
+ else
116
+ @errors = result.errors
117
+
118
+ flash[:danger] = 'Failed to install repo!'
119
+ halt 400, erb(:"repos/install")
120
+ end
121
+ end
122
+
123
+ post '/repos/update' do
124
+ Workers::UpdateRepos.perform_async
125
+
126
+ flash[:success] = 'All repos will be updated'
127
+ redirect '/repos'
128
+ end
129
+
130
+ delete '/repos' do
131
+ Workers::PurgeRepos.perform_async
132
+
133
+ flash[:success] = 'All repos will be purged'
134
+ redirect '/repos'
135
+ end
136
+
137
+ get '/repos/:name' do
138
+ @repos = Ronin::Repos.cache_dir
139
+
140
+ begin
141
+ @repo = @repos[params[:name]]
142
+
143
+ erb :"repos/show"
144
+ rescue Ronin::Repos::RepositoryNotFound
145
+ halt 404
146
+ end
147
+ end
148
+
149
+ post '/repos/:name/update' do
150
+ @repo = Ronin::Repos.cache_dir[params[:name]]
151
+
152
+ Workers::UpdateRepo.perform_async(@repo.name)
153
+
154
+ flash[:success] = "Repo #{@repo.name} enqueued for update"
155
+ redirect "/repos/#{params[:name]}"
156
+ rescue Ronin::Repos::RepositoryNotFound
157
+ halt 404
158
+ end
159
+
160
+ delete '/repos/:name' do
161
+ @repo = Ronin::Repos.cache_dir[params[:name]]
162
+
163
+ Workers::RemoveRepo.perform_async(@repo.name)
164
+
165
+ flash[:success] = "Repo #{@repo.name} enqueued for removal"
166
+ redirect '/repos'
167
+ rescue Ronin::Repos::RepositoryNotFound
168
+ halt 404
169
+ end
170
+
171
+ get '/payloads' do
172
+ @payloads = Ronin::Payloads.list_files
173
+
174
+ erb :"payloads/index"
175
+ end
176
+
177
+ get '/payloads/encoders' do
178
+ @payload_encoders = Ronin::Payloads::Encoders.list_files
179
+
180
+ erb :"payloads/encoders/index"
181
+ end
182
+
183
+ get %r{/payloads/encoders/encode/(?<encoder_id>[a-z0-9_-]+(?:/[a-z0-9_-]+)*)} do
184
+ @encoder_class = Ronin::Payloads::Encoders.load_class(params[:encoder_id])
185
+ @encoder = @encoder_class.new
186
+
187
+ erb :"payloads/encoders/encode"
188
+ rescue Ronin::Core::ClassRegistry::ClassNotFound
189
+ halt 404
190
+ end
191
+
192
+ post %r{/payloads/encoders/encode/(?<encoder_id>[a-z0-9_-]+(?:/[a-z0-9_-]+)*)} do
193
+ @encoder_class = Ronin::Payloads::Encoders.load_class(params[:encoder_id])
194
+ @encoder = @encoder_class.new
195
+
196
+ form_schema = Schemas::Payloads::Encoders::EncodeSchema(@encoder_class)
197
+ result = form_schema.call(params)
198
+
199
+ if result.success?
200
+ encoder_params = result[:params].to_h
201
+ encoder_params.compact!
202
+
203
+ begin
204
+ @encoder.params = encoder_params
205
+ rescue Ronin::Core::Params::ParamError => error
206
+ flash[:error] = "Failed to set params: #{error.message}"
207
+
208
+ halt 400, erb(:"payloads/encoders/encode")
209
+ end
210
+
211
+ begin
212
+ @encoder.validate
213
+ rescue => error
214
+ flash[:error] = "Failed to encode encoder: #{error.message}"
215
+
216
+ halt 500, erb(:"payloads/encoders/encode")
217
+ end
218
+
219
+ @encoded_data = @encoder.encode(result[:data])
220
+
221
+ erb :"payloads/encoders/encode"
222
+ else
223
+ @params = params
224
+ @errors = result.errors
225
+
226
+ halt 400, erb(:"payloads/encoders/encode")
227
+ end
228
+ rescue Ronin::Core::ClassRegistry::ClassNotFound
229
+ halt 404
230
+ end
231
+
232
+ get %r{/payloads/encoders/(?<encoder_id>[a-z0-9_-]+(?:/[a-z0-9_-]+)*)} do
233
+ @encoder = Ronin::Payloads::Encoders.load_class(params[:encoder_id])
234
+
235
+ erb :"payloads/encoders/show"
236
+ rescue Ronin::Core::ClassRegistry::ClassNotFound
237
+ halt 404
238
+ end
239
+
240
+ get %r{/payloads/build/(?<payload_id>[a-z0-9_-]+(?:/[a-z0-9_-]+)*)} do
241
+ @payload_class = Ronin::Payloads.load_class(params[:payload_id])
242
+ @payload = @payload_class.new
243
+
244
+ erb :"payloads/build"
245
+ rescue Ronin::Core::ClassRegistry::ClassNotFound
246
+ halt 404
247
+ end
248
+
249
+ post %r{/payloads/build/(?<payload_id>[a-z0-9_-]+(?:/[a-z0-9_-]+)*)} do
250
+ @payload_class = Ronin::Payloads.load_class(params[:payload_id])
251
+ @payload = @payload_class.new
252
+
253
+ form_schema = Schemas::Payloads::BuildSchema(@payload_class)
254
+ result = form_schema.call(params)
255
+
256
+ if result.success?
257
+ payload_params = result[:params].to_h
258
+ payload_params.compact!
259
+
260
+ begin
261
+ @payload.params = payload_params
262
+ rescue Ronin::Core::Params::ParamError => error
263
+ flash[:error] = "Failed to set params: #{error.message}"
264
+
265
+ halt 400, erb(:"payloads/build")
266
+ end
267
+
268
+ begin
269
+ @payload.perform_validate
270
+ @payload.perform_build
271
+ rescue => error
272
+ flash[:error] = "Failed to build payload: #{error.message}"
273
+
274
+ halt 500, erb(:"payloads/build")
275
+ end
276
+
277
+ @built_payload = @payload.to_s
278
+
279
+ erb :"payloads/build"
280
+ else
281
+ @params = params
282
+ @errors = result.errors
283
+
284
+ halt 400, erb(:"payloads/build")
285
+ end
286
+ rescue Ronin::Core::ClassRegistry::ClassNotFound
287
+ halt 404
288
+ end
289
+
290
+ get %r{/payloads/(?<payload_id>[a-z0-9_-]+(?:/[a-z0-9_-]+)*)} do
291
+ @payload = Ronin::Payloads.load_class(params[:payload_id])
292
+
293
+ erb :"payloads/show"
294
+ rescue Ronin::Core::ClassRegistry::ClassNotFound
295
+ halt 404
296
+ end
297
+
298
+ get '/exploits' do
299
+ @exploits = Ronin::Exploits.list_files
300
+
301
+ erb :"exploits/index"
302
+ end
303
+
304
+ get %r{/exploits/(?<exploit_id>[A-Za-z0-9_-]+(?:/[A-Za-z0-9_-]+)*)} do
305
+ @exploit = Ronin::Exploits.load_class(params[:exploit_id])
306
+
307
+ erb :"exploits/show"
308
+ rescue Ronin::Core::ClassRegistry::ClassNotFound
309
+ halt 404
310
+ end
311
+
312
+ get '/import' do
313
+ erb :import
314
+ end
315
+
316
+ post '/import' do
317
+ result = Validations::ImportParams.call(params)
318
+
319
+ if result.success?
320
+ @jid = Workers::Import.perform_async(result.to_h)
321
+
322
+ type = result[:type]
323
+ path = result[:path]
324
+
325
+ flash[:success] = "Import of #{type} file #{path} enqueued"
326
+ redirect '/import'
327
+ else
328
+ @errors = result.errors
329
+
330
+ flash[:danger] = 'Failed to submit import job!'
331
+ halt 400, erb(:import)
332
+ end
333
+ end
334
+
335
+ get '/about' do
336
+ @lockfile = Bundler::LockfileParser.new(File.read(Bundler.default_lockfile))
337
+
338
+ erb :about
339
+ end
340
+
341
+ get '/queue' do
342
+ @workers = Sidekiq::Workers.new.map do |_process_id, _thread_id, worker|
343
+ payload = JSON.parse(worker["payload"])
344
+ {
345
+ queue: worker["queue"],
346
+ class: payload["class"],
347
+ args: payload["args"],
348
+ created_at: Time.at(payload["created_at"]),
349
+ enqueued_at: Time.at(payload["enqueued_at"]),
350
+ run_at: Time.at(worker["run_at"])
351
+ }
352
+ end
353
+
354
+ erb :queue
355
+ end
356
+
357
+ private
358
+
359
+ #
360
+ # Returns the hash of variables used to initialize the Pagy object.
361
+ #
362
+ def pagy_get_vars(collection, vars)
363
+ {
364
+ count: collection.count,
365
+ page: params["page"],
366
+ items: vars[:items] || 25
367
+ }
368
+ end
369
+ end
370
+
371
+ require './app/db'
372
+ require './app/scanning'
data/bin/ronin-app ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # ronin-app - a local web app for Ronin.
5
+ #
6
+ # Copyright (C) 2023 Hal Brodigan (postmodern.mod3@gmail.com)
7
+ #
8
+ # ronin-app is free software: you can redistribute it and/or modify
9
+ # it under the terms of the GNU Affero General Public License as published by
10
+ # the Free Software Foundation, either version 3 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # ronin-app is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU Affero General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU Affero General Public License
19
+ # along with ronin-app. If not, see <http://www.gnu.org/licenses/>.
20
+ #
21
+
22
+ root = File.expand_path(File.join(__dir__,'..'))
23
+ if File.file?(File.join(root,'Gemfile.lock'))
24
+ Dir.chdir(root) do
25
+ require 'bundler/setup'
26
+ rescue LoadError => e
27
+ warn e.message
28
+ warn "Run `gem install bundler` to install Bundler"
29
+ exit(-1)
30
+ end
31
+ end
32
+
33
+ require 'ronin/app/cli'
34
+ Ronin::App::CLI.start
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ require 'ronin/db'
3
+
4
+ database = if ENV['DATABASE_URL'] then ENV['DATABASE_URL']
5
+ elsif ENV['DATABASE_NAME'] then ENV['DATABASE_NAME'].to_sym
6
+ else :default
7
+ end
8
+
9
+ pool_size = if ENV['DB_POOL'] then ENV['DB_POOL'].to_i
10
+ else 4
11
+ end
12
+
13
+ Ronin::DB.connect(database, pool: pool_size)
14
+
15
+ at_exit do
16
+ ActiveRecord::Base.connection_pool.disconnect!
17
+ end
data/config/puma.rb ADDED
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Puma can serve each request in a thread from an internal thread pool.
4
+ # The `threads` method setting takes two numbers a minimum and maximum.
5
+ # Any libraries that use thread pools should be configured to match
6
+ # the maximum value specified for Puma. Default is set to 5 threads for minimum
7
+ # and maximum, this matches the default thread size of Active Record.
8
+ #
9
+ threads_count = ENV.fetch('PUMA_THREADS',4).to_i
10
+ threads threads_count, threads_count
11
+
12
+ host = ENV.fetch('HOST','localhost')
13
+ port = ENV.fetch('PORT',1337)
14
+
15
+ # Default to running on localhost:1337 since this is a local web ap.
16
+ bind "tcp://#{host}:#{port}"
17
+
18
+ # Specifies the number of `workers` to boot in clustered mode.
19
+ # Workers are forked webserver processes. If using threads and workers together
20
+ # the concurrency of the application would be max `threads` * `workers`.
21
+ # Workers do not work on JRuby or Windows (both of which do not support
22
+ # processes).
23
+ #
24
+ workers ENV.fetch('PUMA_WORKERS',1).to_i
data/config/redis.rb ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ require 'redis'
3
+
4
+ $redis = Redis.new(url: "redis://#{ENV['REDIS_HOST']}:#{ENV['REDIS_PORT']}")
data/config/sidekiq.rb ADDED
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+ require 'sidekiq'
3
+ require 'redis/namespace'
4
+
5
+ require_relative '../lib/middleware/sidekiq/active_record_connection_pool'
6
+
7
+ redis_config = {
8
+ url: "redis://#{ENV['REDIS_HOST']}:#{ENV['REDIS_PORT']}"
9
+ }
10
+
11
+ Sidekiq.configure_server do |config|
12
+ config.redis = redis_config
13
+
14
+ config.server_middleware do |chain|
15
+ chain.add Middleware::Sidekiq::ActiveRecordConnectionPool
16
+ end
17
+ end
18
+
19
+ Sidekiq.configure_client do |config|
20
+ config.redis = redis_config
21
+ end
22
+
23
+ Sidekiq.strict_args!(false)
@@ -0,0 +1,12 @@
1
+ :verbose: true
2
+ :pidfile: ./tmp/sidekiq.pid
3
+ :logfile: ./log/sidekiq.log
4
+ :concurrency: 4
5
+ :queues:
6
+ - default
7
+ - repos
8
+ - recon
9
+ - scan
10
+ - import
11
+ - spider
12
+ - vulns
data/config.ru ADDED
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-app - a local web app for Ronin.
4
+ #
5
+ # Copyright (C) 2023 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 './app'
22
+ require 'sidekiq'
23
+ require 'sidekiq/web'
24
+
25
+ Sidekiq.configure_client do |config|
26
+ config.redis = {url: "redis://#{ENV['REDIS_HOST']}:#{ENV['REDIS_PORT']}"}
27
+ end
28
+
29
+ # give Sidekiq::Web it's own unique rack.session cookie
30
+ Sidekiq::Web.use Rack::Session::Cookie, path: '/sidekiq',
31
+ secret: SecureRandom.hex(40)
32
+
33
+ run Rack::URLMap.new('/' => App, '/sidekiq' => Sidekiq::Web)