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

Implement views, routes and worker for RoninVulns #64

Merged
merged 18 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 11 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
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ gem 'ronin-db-activerecord', '~> 0.2', github: 'ronin-rb/ronin-db-activerecord',

gem 'ronin-payloads', '~> 0.1', github: 'ronin-rb/ronin-payloads'
# gem 'ronin-exploits', '~> 1.0', github: 'ronin-rb/ronin-exploits'
# gem 'ronin-vulns', '~> 0.1', github: 'ronin-rb/ronin-vulns'
gem 'ronin-vulns', '~> 0.2', github: 'ronin-rb/ronin-vulns',
branch: '0.2.0'
gem 'ronin-web', '~> 1.0', github: 'ronin-rb/ronin-web'
postmodern marked this conversation as resolved.
Show resolved Hide resolved
gem 'ronin-web-spider', '~> 0.2', github: 'ronin-rb/ronin-web-spider',
branch: '0.2.0'
gem 'ronin-recon', '~> 0.1', github: 'ronin-rb/ronin-recon'
Expand Down
24 changes: 24 additions & 0 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
require 'ronin/app/validations/masscan_params'
require 'ronin/app/validations/import_params'
require 'ronin/app/validations/spider_params'
require 'ronin/app/validations/vulns_params'

# schema builders
require 'ronin/app/schemas/payloads/encoders/encode_schema'
Expand All @@ -62,6 +63,7 @@
require './workers/import'
require './workers/spider'
require './workers/recon'
require './workers/vulns'
postmodern marked this conversation as resolved.
Show resolved Hide resolved

require 'ronin/app/version'
require 'sidekiq/api'
Expand Down Expand Up @@ -774,6 +776,28 @@ class App < Sinatra::Base
end
end

get '/vulns' do
erb :vulns
end

post '/vulns' do
result = Validations::VulnsParams.call(params)

if result.success?
@jid = Workers::Vulns.perform_async(result.to_h)

url = result[:url]

flash[:success] = "Vulnerabilities scanner of URL #{url} enqueued"
redirect '/vulns'
else
@errors = result.errors

flash[:danger] = 'Failed to submit vulnerabilities scan!'
halt 400, erb(:vulns)
end
end

get '/about' do
@lockfile = Bundler::LockfileParser.new(File.read(Bundler.default_lockfile))

Expand Down
3 changes: 2 additions & 1 deletion gemspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ dependencies:
ronin-db: ~> 0.2
ronin-payloads: ~> 0.1
ronin-exploits: ~> 1.0
ronin-vulns: ~> 0.1
ronin-vulns: ~> 0.2
ronin-web: ~> 1.0
ronin-web-spider: ~> 0.2
ronin-nmap: ~> 0.1
ronin-masscan: ~> 0.1
Expand Down
78 changes: 78 additions & 0 deletions lib/ronin/app/validations/vulns_params.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# frozen_string_literal: true
#
# ronin-app - a local web app for Ronin.
#
# Copyright (C) 2023 Hal Brodigan ([email protected])
#
# ronin-app is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ronin-app 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with ronin-app. If not, see <http://www.gnu.org/licenses/>.
#

require 'dry/validation'
require 'ronin/app/types/spider'

module Ronin
module App
module Validations
#
# Validations for form params submitted to `POST /vulns`.
#
class VulnsParams < Dry::Validation::Contract

params do
required(:url).filled(:string)

optional(:lfi).hash do
optional(:os).maybe(:string)
postmodern marked this conversation as resolved.
Show resolved Hide resolved
optional(:depth).maybe(:integer)
optional(:filter_bypass).maybe(:string)
postmodern marked this conversation as resolved.
Show resolved Hide resolved
end

optional(:rfi).hash do
optional(:filter_bypass).maybe(:string)
postmodern marked this conversation as resolved.
Show resolved Hide resolved
optional(:test_script_url).maybe(:string)
end

optional(:sqli).hash do
optional(:escape_quote).maybe(:bool)
optional(:escape_parens).maybe(:bool)
optional(:terminate).maybe(:bool)
end

optional(:ssti).hash do
optional(:escape).maybe(:string) # ?
postmodern marked this conversation as resolved.
Show resolved Hide resolved
optional(:test).maybe(:string) # ?
postmodern marked this conversation as resolved.
Show resolved Hide resolved
end

optional(:open_redirect).hash do
optional(:test_url).maybe(:string)
end
end

#
# Initializes and calls the validation contract.
#
# @param [Hash{String => Object}] params
# The HTTP params to validate.
#
# @return [Dry::Validation::Result]
# The validation result.
#
def self.call(params)
new.call(params)
end

end
end
end
end
postmodern marked this conversation as resolved.
Show resolved Hide resolved
23 changes: 23 additions & 0 deletions spec/validations/vulns_params_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'spec_helper'
require 'ronin/app/validations/vulns_params'

describe Ronin::App::Validations::VulnsParams do
describe "rules" do
describe ":url" do
it "must require a :url key" do
result = subject.call({})

expect(result).to be_failure
expect(result.errors[:url]).to eq(["is missing"])
end
end
end

describe ".call" do
subject { described_class }

it "must initialize #{described_class} and call #call" do
expect(subject.call({})).to be_kind_of(Dry::Validation::Result)
end
end
end
17 changes: 17 additions & 0 deletions spec/workers/vulns_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'spec_helper'
require './workers/nmap'

describe Workers::Nmap do
describe "Params" do
subject { described_class::Params }

describe ":url" do
it "must require :url key" do
result = subject.call({})

expect(result).to be_failure
expect(result.errors[:targets]).to eq(["is missing"])
end
end
end
end
1 change: 1 addition & 0 deletions views/layout.erb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<a href="/import" class="navbar-item">import</a>
<a href="/spider" class="navbar-item">spider</a>
<a href="/recon" class="navbar-item">recon</a>
<a href="/vulns" class="navbar-item">vulns</a>
<a href="/queue" class="navbar-item">queue</a>
<a href="/about" class="navbar-item">about</a>
</div>
Expand Down
182 changes: 182 additions & 0 deletions views/vulns.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
<h1>Vulnerabilities</h1>

<form id="recon" action="/vulns" method="post">
<div class="field">
<label class="label is-required">URL</label>

<div class="control">
<% if @errors && @errors[:url] %>
<input class="input is-danger" name="url" required><%=h params[:url] %></input>

<% @errors[:url].each do |error| %>
<p class="help is-danger"><%=h error %></p>
<% end %>
<% else %>
<input class="input" name="url" placeholder="https://example.com" required><%=h params[:url] %></input>
<% end %>
</div>
</div>

<div class="field">
<button type="submit" class="button is-primary">Scan</button>
</div>

<div class="advanced">
<a class="advanced-toggle">Advanced Options</a>

<div class="advanced-content">
<h3>LFI</h3>

<div class="field">
<label class="label">Os</label>

<div class="control">
<% if @errors && @errors.dig(:lfi, :os) %>
<input class="input is-danger" type="text" name="lfi[os]" value="<%=hattr params.dig(:lfi, :os) %>">

<% @errors[:lfi][:os].each do |error| %>
<p class="help is-danger"><%=h error %></p>
<% end %>
<% else %>
<input class="input" type="text" name="lfi[os]" placeholder=":unix" value="<%=hattr params.dig(:lfi, :os) %>">
<% end %>
</div>
</div>

<div class="field">
<label class="label">Depth</label>

<div class="control">
<% if @errors && @errors.dig(:lfi, :depth) %>
<input class="input is-danger" type="text" name="lfi[depth]" value="<%=hattr params.dig(:lfi, :depth) %>">

<% @errors[:lfi][:depth].each do |error| %>
<p class="help is-danger"><%=h error %></p>
<% end %>
<% else %>
<input class="input" type="text" name="lfi[depth]" placeholder="6" value="<%=hattr params.dig(:lfi, :depth) %>">
<% end %>
</div>
</div>

<div class="field">
<label class="label">Filter Bypass</label>

<div class="control">
<% if @errors && @errors.dig(:rfi, :filter_bypass) %>
<input class="input is-danger" type="text" name="lfi[filter_bypass]" value="<%=hattr params.dig(:lfi, :filter_bypass) %>">

<% @errors[:lfi][:filter_bypass].each do |error| %>
<p class="help is-danger"><%=h error %></p>
<% end %>
<% else %>
<input class="input" type="text" name="lfi[filter_bypass]" placeholder=":nullbyte, :double_escape, :base64, :rot13 or :zlib" value="<%=hattr params.dig(:lfi, :filter_bypass) %>">
<% end %>
</div>
</div>

<h3>RFI</h3>

<div class="field">
<label class="label">Filter Bypass</label>

<div class="control">
<% if @errors && @errors.dig(:rfi, :filter_bypass) %>
<input class="input is-danger" type="text" name="rfi[filter_bypass]" value="<%=hattr params.dig(:rfi, :filter_bypass) %>">

<% @errors[:rfi][:filter_bypass].each do |error| %>
<p class="help is-danger"><%=h error %></p>
<% end %>
<% else %>
<input class="input" type="text" name="rfi[filter_bypass]" placeholder=":double_encode, :suffix_escape or :null_byte" value="<%=hattr params.dig(:rfi, :filter_bypass) %>">
<% end %>
</div>
</div>

<div class="field">
<label class="label">Test Script URL</label>

<div class="control">
<% if @errors && @errors.dig(:rfi, :test_script_url) %>
<input class="input is-danger" type="text" name="rfi[test_script_url]" value="<%=hattr params.dig(:rfi, :test_script_url)%>">

<% @errors[:rfi][:test_script_url].each do |error| %>
<p class="help is-danger"><%=h error %></p>
<% end %>
<% else %>
<input class="input" type="text" name="rfi[test_script_url]" value="<%=hattr params.dig(:rfi, :test_script_url) %>">
<% end %>
</div>
</div>

<h3>SQLI</h3>

<div class="field">
<label class="has-text-weight-semibold">Escape Quote: </label>
<input class="checkbox" type="checkbox" name="sqli[escape_quote]"<%= " checked" if params.dig(:sqli, :terminate) %>
</div>

<div class="field">
<label class="has-text-weight-semibold">Escape Parens: </label>
<input class="checkbox" type="checkbox" name="sqli[escape_parens]"<%= " checked" if params.dig(:sqli, :terminate) %>
</div>

<div class="field">
<label class="has-text-weight-semibold">Terminate: </label>
<input class="checkbox" type="checkbox" name="sqli[terminate]"<%= " checked" if params.dig(:sqli, :terminate) %>
</div>

<h3>SSTI</h3>

<div class="field">
<label class="label">Escape</label>

<div class="control">
<% if @errors && @errors.dig(:ssti, :escape) %>
<input class="input is-danger" type="text" name="ssti[escape]" value="<%=hattr params.dig(:ssti, :escape) %>">

<% @errors[:ssti][:escape].each do |error| %>
<p class="help is-danger"><%=h error %></p>
<% end %>
<% else %>
<input class="input" type="text" name="ssti[escape]" value="<%=hattr params.dig(:ssti, :escape) %>">
<% end %>
</div>
</div>

<div class="field">
<label class="label">Test</label>

<div class="control">
<% if @errors && @errors.dig(:ssti, :test) %>
<input class="input is-danger" type="text" name="ssti[test]" value="<%=hattr params.dig(:ssti, :test)%>">

<% @errors[:ssti][:test].each do |error| %>
<p class="help is-danger"><%=h error %></p>
<% end %>
<% else %>
<input class="input" type="text" name="ssti[test]" value="<%=hattr params.dig(:ssti, :test)%>">
<% end %>
</div>
</div>

<h3>Open Redirect</h3>

<div class="field">
<label class="label">Test URL</label>

<div class="control">
<% if @errors && @errors.dig(:open_redirect, :test_url) %>
<input class="input is-danger" type="text" name="open_redirect[test_url]" value="<%=hattr params.dig(:open_redirect, :test_url)%>">

<% @errors[:open_redirect][:test_url].each do |error| %>
<p class="help is-danger"><%=h error %></p>
<% end %>
<% else %>
<input class="input" type="text" name="open_redirect[test_url]" value="<%=hattr params.dig(:open_redirect, :test_url)%>">
<% end %>
</div>
</div>
</div>
</div>
</form>
1 change: 1 addition & 0 deletions workers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@
require './workers/import'
require './workers/spider'
require './workers/recon'
require './workers/vulns'
Loading