API_Fuzzer 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4bfb4ac33d3645e0761c280d9f19a840b699915d
4
+ data.tar.gz: 41324f4fc3abbcbbb473b377588062a13dcdf9c7
5
+ SHA512:
6
+ metadata.gz: c37f7f1ee1db7c3c5a5e362e30690f13d48d83edafadb36ebc4e792092d6012c48b1903e7ae578d684b54ddc24ea8d48fc49a324be86d7522bdf4cfea23f57af
7
+ data.tar.gz: 44c7746344cd9ec5746265757444f46c93f514d71721ce16b68ea41ced33fdf5ed8022fdda881d06b205161e514838231cf01f6ca0ee28aec9e1e0c0795161e5
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .byebug_history
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'API_Fuzzer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "API_Fuzzer"
8
+ spec.version = APIFuzzer::VERSION
9
+ spec.authors = ["Lalith Rallabhandi"]
10
+ spec.email = ["lalithr95@gmail.com"]
11
+
12
+ spec.summary = %q{APIFuzzer gem builds api for finding security issues through a fuzzer}
13
+ spec.description = %q{APIFuzzer gem builds api for finding security issues through a fuzzer}
14
+ spec.homepage = "https://github.com/lalithr95/API-Fuzzer"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+
20
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency 'http', '~> 2.0'
26
+ spec.add_dependency 'activesupport'
27
+ spec.add_dependency 'rails', '>= 4.2'
28
+ spec.add_development_dependency "bundler", "~> 1.12"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "minitest", "~> 5.0"
31
+ end
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at lalith.rallabhandi@shopify.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in API_Fuzzer.gemspec
4
+
5
+ gem 'http'
6
+ gem 'builder'
7
+
8
+ group :development do
9
+ gem 'byebug'
10
+ end
11
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Lalith Rallabhandi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,91 @@
1
+ # API Fuzzer
2
+
3
+ `API_Fuzzer` gem accepts a API request as input and returns vulnerabilities possible in the API. Following are the main check involved in API_Fuzzer gem
4
+
5
+ - Cross-site scripting vulnerability
6
+ - SQL injection
7
+ - Blind SQL injection
8
+ - XML External entity vulnerability
9
+ - IDOR (in specific cases)
10
+ - API Rate Limiting
11
+ - Open redirect vulnerabilities
12
+ - Information Disclosure flaws
13
+ - Info leakage through headers
14
+ - Cross-site request forgery vulnerability
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ ```ruby
21
+ gem 'API_Fuzzer'
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install API_Fuzzer
31
+
32
+ ## Usage
33
+
34
+ Run `bin/console`
35
+
36
+ Lets say you have following endpoint
37
+
38
+ ```
39
+ POST /api/v2/credit_cards/123
40
+
41
+ Host: test.host.com
42
+ User-Agent: Mozilla Firefox
43
+ Auth: Basic Adnjefnef443nr4jh4h
44
+ { credit_card: '4242424242424242', expiry: '07/17', cvv: '123', name: 'First name' }
45
+ ```
46
+
47
+ API_Fuzzer module comes with static method `scan` and accepts above request
48
+ ```ruby
49
+ require 'API_Fuzzer'
50
+
51
+ options = {
52
+ url: 'http://test.host.com/api/v2/credit_cards/123',
53
+ params: {
54
+ credit_card: '4242424242424242',
55
+ expiry: '07/17',
56
+ cvv: '123',
57
+ name: 'First name'
58
+ },
59
+ method: ['POST'],
60
+ headers: {
61
+ 'Host' => 'test.host.com',
62
+ 'User-Agent' => 'Mozilla Firefox',
63
+ 'Auth' => 'Basic Adnjefnef443nr4jh4h'
64
+ }
65
+ }
66
+ vulnerabilities = API_Fuzzer.scan(options)
67
+ ```
68
+ `vulnerabilites` is an array of vulnerability, each distinguished with impact type, title and description.
69
+
70
+
71
+ Above Ruby code can be painful for writing ruby script for each request. [Fuzzapi](https://github.com/lalithr95/Fuzzapi) is a rails application which integrates and bundles API_Fuzzer and brings UI changes to easily scan API endpoints.
72
+
73
+ ## Development
74
+
75
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
76
+
77
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
78
+
79
+ If you have any issue, we would be happy to help. You can create an issue in repository or contact any of following twitter handles
80
+ @abhijeth, @srini0x00, @lalithr95
81
+
82
+ ## Contributing
83
+
84
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/API_Fuzzer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
85
+
86
+
87
+ ## License
88
+
89
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
90
+
91
+ Copyrights [Fuzzdb](https://github.com/fuzzdb-project/fuzzdb) for fuzzing payloads
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,22 @@
1
+ class PingController < ActionController::Base
2
+ def index
3
+ @scan = Scan.find(params[:id])
4
+ @scan.vulnerabilities.create!(
5
+ status: 'HIGH',
6
+ class_type: 'Vulnerability',
7
+ description: "Possible XXE vulnerability in #{@scan.url}",
8
+ value: body
9
+ ) if @scan
10
+ render json: { status: :ok }
11
+ end
12
+
13
+ def pong
14
+ render json: { status: :ok }
15
+ end
16
+
17
+ private
18
+
19
+ def body
20
+ @scan.parameters.gsub(/\>\s*[a-zA-Z0-9]*\s*\<\//, '>&xxe;<')
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "API_Fuzzer"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,4 @@
1
+ API_Fuzzer::Engine.routes.draw do
2
+ get '/ping/:id' => 'ping#index'
3
+ get '/ping' => 'ping#pong'
4
+ end
@@ -0,0 +1,43 @@
1
+ require 'API_Fuzzer/version'
2
+ require 'API_Fuzzer/header_info'
3
+ require 'API_Fuzzer/resource_info'
4
+ require 'API_Fuzzer/sql_check'
5
+ require 'API_Fuzzer/sql_blind_check'
6
+ require 'API_Fuzzer/xss_check'
7
+ require 'API_Fuzzer/request'
8
+ require 'API_Fuzzer/engine'
9
+ require 'API_Fuzzer/xxe_check'
10
+ require 'API_Fuzzer/redirect_check'
11
+ require 'API_Fuzzer/idor_check'
12
+ require 'API_Fuzzer/rate_limit_check'
13
+ require 'API_Fuzzer/csrf_check'
14
+ require 'API_Fuzzer/privilege_escalation_check'
15
+
16
+ module API_Fuzzer
17
+ # Scans all the checks
18
+ def self.scan(options = {})
19
+ vulnerabilities = []
20
+ options.freeze
21
+
22
+ vulnerabilities << static_analysis(options)
23
+ vulnerabilities << API_Fuzzer::XssCheck.scan(options)
24
+ vulnerabilities << API_Fuzzer::SqlCheck.scan(options)
25
+ vulnerabilities << API_Fuzzer::SqlBlindCheck.scan(options)
26
+ vulnerabilities << API_Fuzzer::RedirectCheck.scan(options)
27
+ vulnerabilities << API_Fuzzer::IdorCheck.scan(options)
28
+ vulnerabilities << API_Fuzzer::RateLimitCheck.scan(options)
29
+ vulnerabilities << API_Fuzzer::CsrfCheck.scan(options)
30
+ vulnerabilities << API_Fuzzer::PrivilegeEscalationCheck.scan(options)
31
+ API_Fuzzer::XxeCheck.scan(options)
32
+ vulnerabilities.uniq.flatten
33
+ end
34
+
35
+ def self.static_analysis(options = {})
36
+ response = API_Fuzzer::Request.send_api_request(url: options[:url], cookies: options[:cookies])
37
+ issues = []
38
+
39
+ issues << API_Fuzzer::ResourceInfo.scan(response)
40
+ issues << API_Fuzzer::HeaderInfo.scan(response)
41
+ issues
42
+ end
43
+ end
@@ -0,0 +1,41 @@
1
+ require 'API_Fuzzer/vulnerability'
2
+ require 'API_Fuzzer/error'
3
+ require 'API_Fuzzer/request'
4
+
5
+ module API_Fuzzer
6
+ class CsrfCheck
7
+ VALID_CSRF_PARAMS = ['csrf', 'token', 'authenticity_token', 'csrf_token'].map(&:downcase)
8
+ VALID_CSRF_HEADERS = ['X-CSRF', 'CSRF-Token'].map(&:downcase)
9
+ class << self
10
+ def scan(options = {})
11
+ @url = options[:url] || nil
12
+ @params = options[:params] || {}
13
+ @cookies = options[:cookies] || {}
14
+ @methods = options[:method] || [:get]
15
+ @headers = options[:headers] || {}
16
+ @json = options[:json] || false
17
+ @vulnerabilities = []
18
+
19
+ fuzz_csrf
20
+ @vulnerabilities.uniq { |vuln| vuln.description }
21
+ rescue Exception => e
22
+ Rails.logger.info e.message
23
+ end
24
+
25
+ def fuzz_csrf
26
+ @vulnerabilities << API_Fuzzer::Vulnerability.new(
27
+ type: 'MEDIUM',
28
+ value: 'No Cross-site request forgery protection found in API',
29
+ description: "Cross-site request forgery vulnerability in GET #{@url}"
30
+ ) if @methods.map(&:downcase).include?(:get)
31
+ end
32
+
33
+ def validate_csrf
34
+ params = @params
35
+ headers = request.headers
36
+ matched_headers = headers.keys.select { |header| VALID_CSRF_HEADERS.any? { |exp| header.match(exp) } }
37
+ matched_param = params.keys.select { |param| VALID_CSRF_PARAMS.any? { |exp| param.match(exp) } }
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,5 @@
1
+ require 'rails'
2
+
3
+ module API_Fuzzer
4
+ class Engine < ::Rails::Engine; end
5
+ end
@@ -0,0 +1,11 @@
1
+ module API_Fuzzer
2
+ class Error
3
+ attr_accessor :description, :status, :value
4
+
5
+ def initialize(options = {})
6
+ @description = options.delete(:description) || nil
7
+ @status = options.delete(:status)
8
+ @value = options.delete(:value)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,50 @@
1
+ require 'yaml'
2
+ require 'API_Fuzzer/vulnerability'
3
+
4
+ module API_Fuzzer
5
+
6
+ class InvalidResponse < StandardError; end
7
+
8
+ class HeaderInfo
9
+
10
+ class << self
11
+ def scan(response)
12
+ @response = response
13
+ @headers = @response.headers
14
+ load_header_rules
15
+ scan_headers
16
+ raise InvalidResponse, "Invalid response argument passed" unless @response
17
+ end
18
+
19
+ def scan_headers
20
+ @vulnerabilities = []
21
+
22
+ @rules.each do |rule|
23
+ name = rule['name']
24
+ header_keys = @headers.keys.map { |key| key.downcase }
25
+ if header_keys.include? name
26
+ unless /#{rule['match']}/.match(@headers[name])
27
+ @vulnerabilities << API_Fuzzer::Vulnerability.new(
28
+ description: rule['description'],
29
+ value: [name, @headers[name]].join(" "),
30
+ type: 'LOW'
31
+ )
32
+ end
33
+ else
34
+ @vulnerabilities << API_Fuzzer::Vulnerability.new(
35
+ description: rule['description'],
36
+ value: [name, @headers[name]].join(" "),
37
+ type: 'LOW'
38
+ )
39
+ end
40
+ end
41
+ @vulnerabilities
42
+ end
43
+
44
+ def load_header_rules
45
+ info_rules = File.expand_path('../../../rules', __FILE__)
46
+ @rules = YAML::load_file(File.join(info_rules, "headers.yml"))['rules']
47
+ end
48
+ end
49
+ end
50
+ end