codesake-dawn 0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +18 -0
- data/.rvmrc +48 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +54 -0
- data/Rakefile +64 -0
- data/Roadmap.md +44 -0
- data/bin/dawn +106 -0
- data/codesake_dawn.gemspec +25 -0
- data/lib/codesake-dawn.rb +7 -0
- data/lib/codesake/dawn/engine.rb +144 -0
- data/lib/codesake/dawn/kb/basic_check.rb +93 -0
- data/lib/codesake/dawn/kb/cve_2011_2931.rb +32 -0
- data/lib/codesake/dawn/kb/cve_2012_2660.rb +30 -0
- data/lib/codesake/dawn/kb/cve_2012_2661.rb +29 -0
- data/lib/codesake/dawn/kb/cve_2012_2694.rb +31 -0
- data/lib/codesake/dawn/kb/cve_2012_2695.rb +29 -0
- data/lib/codesake/dawn/kb/cve_2012_3465.rb +28 -0
- data/lib/codesake/dawn/kb/cve_2012_6496.rb +30 -0
- data/lib/codesake/dawn/kb/cve_2012_6497.rb +30 -0
- data/lib/codesake/dawn/kb/cve_2013_0155.rb +30 -0
- data/lib/codesake/dawn/kb/cve_2013_0269.rb +29 -0
- data/lib/codesake/dawn/kb/cve_2013_0333.rb +33 -0
- data/lib/codesake/dawn/kb/cve_2013_1800.rb +28 -0
- data/lib/codesake/dawn/kb/cve_2013_1855.rb +20 -0
- data/lib/codesake/dawn/kb/cve_2013_1857.rb +22 -0
- data/lib/codesake/dawn/kb/dependency_check.rb +39 -0
- data/lib/codesake/dawn/kb/not_revised_code.rb +24 -0
- data/lib/codesake/dawn/kb/pattern_match_check.rb +60 -0
- data/lib/codesake/dawn/knowledge_base.rb +105 -0
- data/lib/codesake/dawn/rails.rb +17 -0
- data/lib/codesake/dawn/sinatra.rb +14 -0
- data/lib/codesake/dawn/version.rb +5 -0
- data/spec/lib/dawn/codesake_knowledgebase_spec.rb +100 -0
- data/spec/lib/dawn/codesake_sinatra_engine_spec.rb +80 -0
- data/spec/lib/kb/codesake_cve_2013_1800_spec.rb +66 -0
- data/spec/lib/kb/codesake_cve_2013_1855_spec.rb +16 -0
- data/spec/lib/kb/cve_2011_2931_spec.rb +7 -0
- data/spec/lib/kb/cve_2012_2660_spec.rb +9 -0
- data/spec/lib/kb/cve_2012_2661_spec.rb +7 -0
- data/spec/lib/kb/cve_2012_2694_spec.rb +7 -0
- data/spec/lib/kb/cve_2012_2695_spec.rb +7 -0
- data/spec/lib/kb/cve_2012_3465_spec.rb +7 -0
- data/spec/lib/kb/cve_2012_6496_spec.rb +7 -0
- data/spec/lib/kb/cve_2012_6497_spec.rb +7 -0
- data/spec/lib/kb/cve_2013_0155_spec.rb +7 -0
- data/spec/lib/kb/cve_2013_0269_spec.rb +7 -0
- data/spec/lib/kb/cve_2013_0333_spec.rb +7 -0
- data/spec/lib/kb/cve_2013_1857_spec.rb +13 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/hello_world_3.0.19/.gitignore +4 -0
- data/spec/support/hello_world_3.0.19/Gemfile +31 -0
- data/spec/support/hello_world_3.0.19/README +256 -0
- data/spec/support/hello_world_3.0.19/Rakefile +7 -0
- data/spec/support/hello_world_3.0.19/app/controllers/application_controller.rb +3 -0
- data/spec/support/hello_world_3.0.19/app/helpers/application_helper.rb +2 -0
- data/spec/support/hello_world_3.0.19/app/views/layouts/application.html.erb +14 -0
- data/spec/support/hello_world_3.0.19/config.ru +4 -0
- data/spec/support/hello_world_3.0.19/config/application.rb +42 -0
- data/spec/support/hello_world_3.0.19/config/boot.rb +6 -0
- data/spec/support/hello_world_3.0.19/config/database.yml +22 -0
- data/spec/support/hello_world_3.0.19/config/environment.rb +5 -0
- data/spec/support/hello_world_3.0.19/config/environments/development.rb +26 -0
- data/spec/support/hello_world_3.0.19/config/environments/production.rb +49 -0
- data/spec/support/hello_world_3.0.19/config/environments/test.rb +35 -0
- data/spec/support/hello_world_3.0.19/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/support/hello_world_3.0.19/config/initializers/inflections.rb +10 -0
- data/spec/support/hello_world_3.0.19/config/initializers/mime_types.rb +5 -0
- data/spec/support/hello_world_3.0.19/config/initializers/secret_token.rb +7 -0
- data/spec/support/hello_world_3.0.19/config/initializers/session_store.rb +8 -0
- data/spec/support/hello_world_3.0.19/config/locales/en.yml +5 -0
- data/spec/support/hello_world_3.0.19/config/routes.rb +58 -0
- data/spec/support/hello_world_3.0.19/db/seeds.rb +7 -0
- data/spec/support/hello_world_3.0.19/lib/tasks/.gitkeep +0 -0
- data/spec/support/hello_world_3.0.19/public/404.html +26 -0
- data/spec/support/hello_world_3.0.19/public/422.html +26 -0
- data/spec/support/hello_world_3.0.19/public/500.html +26 -0
- data/spec/support/hello_world_3.0.19/public/favicon.ico +0 -0
- data/spec/support/hello_world_3.0.19/public/images/rails.png +0 -0
- data/spec/support/hello_world_3.0.19/public/index.html +239 -0
- data/spec/support/hello_world_3.0.19/public/javascripts/application.js +2 -0
- data/spec/support/hello_world_3.0.19/public/javascripts/controls.js +965 -0
- data/spec/support/hello_world_3.0.19/public/javascripts/dragdrop.js +974 -0
- data/spec/support/hello_world_3.0.19/public/javascripts/effects.js +1123 -0
- data/spec/support/hello_world_3.0.19/public/javascripts/prototype.js +6001 -0
- data/spec/support/hello_world_3.0.19/public/javascripts/rails.js +202 -0
- data/spec/support/hello_world_3.0.19/public/robots.txt +5 -0
- data/spec/support/hello_world_3.0.19/public/stylesheets/.gitkeep +0 -0
- data/spec/support/hello_world_3.0.19/script/rails +6 -0
- data/spec/support/hello_world_3.0.19/test/performance/browsing_test.rb +9 -0
- data/spec/support/hello_world_3.0.19/test/test_helper.rb +13 -0
- data/spec/support/hello_world_3.0.19/vendor/plugins/.gitkeep +0 -0
- data/spec/support/hello_world_3.1.0/.gitignore +5 -0
- data/spec/support/hello_world_3.1.0/Gemfile +33 -0
- data/spec/support/hello_world_3.1.0/README +261 -0
- data/spec/support/hello_world_3.1.0/Rakefile +7 -0
- data/spec/support/hello_world_3.1.0/app/assets/images/rails.png +0 -0
- data/spec/support/hello_world_3.1.0/app/assets/javascripts/application.js +9 -0
- data/spec/support/hello_world_3.1.0/app/assets/stylesheets/application.css +7 -0
- data/spec/support/hello_world_3.1.0/app/controllers/application_controller.rb +3 -0
- data/spec/support/hello_world_3.1.0/app/helpers/application_helper.rb +2 -0
- data/spec/support/hello_world_3.1.0/app/mailers/.gitkeep +0 -0
- data/spec/support/hello_world_3.1.0/app/models/.gitkeep +0 -0
- data/spec/support/hello_world_3.1.0/app/views/layouts/application.html.erb +14 -0
- data/spec/support/hello_world_3.1.0/config.ru +4 -0
- data/spec/support/hello_world_3.1.0/config/application.rb +48 -0
- data/spec/support/hello_world_3.1.0/config/boot.rb +6 -0
- data/spec/support/hello_world_3.1.0/config/database.yml +25 -0
- data/spec/support/hello_world_3.1.0/config/environment.rb +5 -0
- data/spec/support/hello_world_3.1.0/config/environments/development.rb +30 -0
- data/spec/support/hello_world_3.1.0/config/environments/production.rb +60 -0
- data/spec/support/hello_world_3.1.0/config/environments/test.rb +42 -0
- data/spec/support/hello_world_3.1.0/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/support/hello_world_3.1.0/config/initializers/inflections.rb +10 -0
- data/spec/support/hello_world_3.1.0/config/initializers/mime_types.rb +5 -0
- data/spec/support/hello_world_3.1.0/config/initializers/secret_token.rb +7 -0
- data/spec/support/hello_world_3.1.0/config/initializers/session_store.rb +8 -0
- data/spec/support/hello_world_3.1.0/config/initializers/wrap_parameters.rb +14 -0
- data/spec/support/hello_world_3.1.0/config/locales/en.yml +5 -0
- data/spec/support/hello_world_3.1.0/config/routes.rb +58 -0
- data/spec/support/hello_world_3.1.0/db/seeds.rb +7 -0
- data/spec/support/hello_world_3.1.0/lib/assets/.gitkeep +0 -0
- data/spec/support/hello_world_3.1.0/lib/tasks/.gitkeep +0 -0
- data/spec/support/hello_world_3.1.0/log/.gitkeep +0 -0
- data/spec/support/hello_world_3.1.0/public/404.html +26 -0
- data/spec/support/hello_world_3.1.0/public/422.html +26 -0
- data/spec/support/hello_world_3.1.0/public/500.html +26 -0
- data/spec/support/hello_world_3.1.0/public/favicon.ico +0 -0
- data/spec/support/hello_world_3.1.0/public/index.html +241 -0
- data/spec/support/hello_world_3.1.0/public/robots.txt +5 -0
- data/spec/support/hello_world_3.1.0/script/rails +6 -0
- data/spec/support/hello_world_3.1.0/test/fixtures/.gitkeep +0 -0
- data/spec/support/hello_world_3.1.0/test/functional/.gitkeep +0 -0
- data/spec/support/hello_world_3.1.0/test/integration/.gitkeep +0 -0
- data/spec/support/hello_world_3.1.0/test/performance/browsing_test.rb +12 -0
- data/spec/support/hello_world_3.1.0/test/test_helper.rb +13 -0
- data/spec/support/hello_world_3.1.0/test/unit/.gitkeep +0 -0
- data/spec/support/hello_world_3.1.0/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/support/hello_world_3.1.0/vendor/plugins/.gitkeep +0 -0
- data/spec/support/hello_world_3.2.13/.gitignore +15 -0
- data/spec/support/hello_world_3.2.13/Gemfile +38 -0
- data/spec/support/hello_world_3.2.13/README.rdoc +261 -0
- data/spec/support/hello_world_3.2.13/Rakefile +7 -0
- data/spec/support/hello_world_3.2.13/app/assets/images/rails.png +0 -0
- data/spec/support/hello_world_3.2.13/app/assets/javascripts/application.js +15 -0
- data/spec/support/hello_world_3.2.13/app/assets/stylesheets/application.css +13 -0
- data/spec/support/hello_world_3.2.13/app/controllers/application_controller.rb +3 -0
- data/spec/support/hello_world_3.2.13/app/helpers/application_helper.rb +2 -0
- data/spec/support/hello_world_3.2.13/app/mailers/.gitkeep +0 -0
- data/spec/support/hello_world_3.2.13/app/models/.gitkeep +0 -0
- data/spec/support/hello_world_3.2.13/app/views/layouts/application.html.erb +14 -0
- data/spec/support/hello_world_3.2.13/config.ru +4 -0
- data/spec/support/hello_world_3.2.13/config/application.rb +62 -0
- data/spec/support/hello_world_3.2.13/config/boot.rb +6 -0
- data/spec/support/hello_world_3.2.13/config/database.yml +25 -0
- data/spec/support/hello_world_3.2.13/config/environment.rb +5 -0
- data/spec/support/hello_world_3.2.13/config/environments/development.rb +37 -0
- data/spec/support/hello_world_3.2.13/config/environments/production.rb +67 -0
- data/spec/support/hello_world_3.2.13/config/environments/test.rb +37 -0
- data/spec/support/hello_world_3.2.13/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/support/hello_world_3.2.13/config/initializers/inflections.rb +15 -0
- data/spec/support/hello_world_3.2.13/config/initializers/mime_types.rb +5 -0
- data/spec/support/hello_world_3.2.13/config/initializers/secret_token.rb +7 -0
- data/spec/support/hello_world_3.2.13/config/initializers/session_store.rb +8 -0
- data/spec/support/hello_world_3.2.13/config/initializers/wrap_parameters.rb +14 -0
- data/spec/support/hello_world_3.2.13/config/locales/en.yml +5 -0
- data/spec/support/hello_world_3.2.13/config/routes.rb +58 -0
- data/spec/support/hello_world_3.2.13/db/seeds.rb +7 -0
- data/spec/support/hello_world_3.2.13/lib/assets/.gitkeep +0 -0
- data/spec/support/hello_world_3.2.13/lib/tasks/.gitkeep +0 -0
- data/spec/support/hello_world_3.2.13/log/.gitkeep +0 -0
- data/spec/support/hello_world_3.2.13/public/404.html +26 -0
- data/spec/support/hello_world_3.2.13/public/422.html +26 -0
- data/spec/support/hello_world_3.2.13/public/500.html +25 -0
- data/spec/support/hello_world_3.2.13/public/favicon.ico +0 -0
- data/spec/support/hello_world_3.2.13/public/index.html +241 -0
- data/spec/support/hello_world_3.2.13/public/robots.txt +5 -0
- data/spec/support/hello_world_3.2.13/script/rails +6 -0
- data/spec/support/hello_world_3.2.13/test/fixtures/.gitkeep +0 -0
- data/spec/support/hello_world_3.2.13/test/functional/.gitkeep +0 -0
- data/spec/support/hello_world_3.2.13/test/integration/.gitkeep +0 -0
- data/spec/support/hello_world_3.2.13/test/performance/browsing_test.rb +12 -0
- data/spec/support/hello_world_3.2.13/test/test_helper.rb +13 -0
- data/spec/support/hello_world_3.2.13/test/unit/.gitkeep +0 -0
- data/spec/support/hello_world_3.2.13/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/support/hello_world_3.2.13/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/support/hello_world_3.2.13/vendor/plugins/.gitkeep +0 -0
- data/spec/support/lorem.txt +23 -0
- data/spec/support/sinatra-safe/.gems +4 -0
- data/spec/support/sinatra-safe/.gitignore +6 -0
- data/spec/support/sinatra-safe/Gemfile +18 -0
- data/spec/support/sinatra-safe/MIT-LICENSE +20 -0
- data/spec/support/sinatra-safe/README.rdoc +35 -0
- data/spec/support/sinatra-safe/Rakefile +32 -0
- data/spec/support/sinatra-safe/application.rb +23 -0
- data/spec/support/sinatra-safe/config.ru +11 -0
- data/spec/support/sinatra-safe/environment.rb +25 -0
- data/spec/support/sinatra-safe/lib/profile.rb +11 -0
- data/spec/support/sinatra-safe/public/main.css +52 -0
- data/spec/support/sinatra-safe/script/console +16 -0
- data/spec/support/sinatra-safe/views/layout.haml +14 -0
- data/spec/support/sinatra-safe/views/root.haml +4 -0
- data/spec/support/sinatra-vulnerable/.gems +4 -0
- data/spec/support/sinatra-vulnerable/.gitignore +6 -0
- data/spec/support/sinatra-vulnerable/Gemfile +17 -0
- data/spec/support/sinatra-vulnerable/MIT-LICENSE +20 -0
- data/spec/support/sinatra-vulnerable/README.rdoc +35 -0
- data/spec/support/sinatra-vulnerable/Rakefile +32 -0
- data/spec/support/sinatra-vulnerable/application.rb +28 -0
- data/spec/support/sinatra-vulnerable/config.ru +11 -0
- data/spec/support/sinatra-vulnerable/environment.rb +25 -0
- data/spec/support/sinatra-vulnerable/lib/profile.rb +11 -0
- data/spec/support/sinatra-vulnerable/public/main.css +52 -0
- data/spec/support/sinatra-vulnerable/script/console +16 -0
- data/spec/support/sinatra-vulnerable/views/layout.haml +14 -0
- data/spec/support/sinatra-vulnerable/views/root.haml +4 -0
- metadata +519 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Codesake
|
|
2
|
+
module Dawn
|
|
3
|
+
module Kb
|
|
4
|
+
class CVE_2013_1855
|
|
5
|
+
include PatternMatchCheck
|
|
6
|
+
|
|
7
|
+
def initialize
|
|
8
|
+
super({
|
|
9
|
+
:fixes_version => ['2.3.18', '3.2.13', '3.1.12'],
|
|
10
|
+
:attack_pattern => ["sanitize_css"],
|
|
11
|
+
:name=>'CVE-2013-1855',
|
|
12
|
+
:applies=>["rails"],
|
|
13
|
+
:kind => Codesake::Dawn::KnowledgeBase::PATTERN_MATCH_CHECK,
|
|
14
|
+
:aux_links => ["https://groups.google.com/d/msg/rubyonrails-security/4_QHo4BqnN8/_RrdfKk12I4J"]
|
|
15
|
+
})
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Codesake
|
|
2
|
+
module Dawn
|
|
3
|
+
module Kb
|
|
4
|
+
# Automatically created with rake on 2013-05-02
|
|
5
|
+
class CVE_2013_1857
|
|
6
|
+
include PatternMatchCheck
|
|
7
|
+
|
|
8
|
+
def initialize
|
|
9
|
+
super({
|
|
10
|
+
:fixes_version => ['2.3.18', '3.2.13', '3.1.12'],
|
|
11
|
+
:attack_pattern => ["sanitize"],
|
|
12
|
+
:name=>'CVE-2013-1857',
|
|
13
|
+
:applies=>["rails"],
|
|
14
|
+
:kind => Codesake::Dawn::KnowledgeBase::PATTERN_MATCH_CHECK,
|
|
15
|
+
:aux_links => [ "https://groups.google.com/d/msg/rubyonrails-security/zAAU7vGTPvI/1vZDWXqBuXgJ" ]
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module Codesake
|
|
2
|
+
module Dawn
|
|
3
|
+
module Kb
|
|
4
|
+
module DependencyCheck
|
|
5
|
+
include BasicCheck
|
|
6
|
+
|
|
7
|
+
attr_accessor :dependencies
|
|
8
|
+
attr_accessor :fixed_dependency
|
|
9
|
+
attr_accessor :aux_mitigation_gem
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def vuln?
|
|
13
|
+
ret = false
|
|
14
|
+
@mitigated = false
|
|
15
|
+
message = ""
|
|
16
|
+
|
|
17
|
+
@dependencies.each do |dep|
|
|
18
|
+
# don't care about gem version when it mitigates a vulnerability... this can be risky, maybe I would reconsider in the future.
|
|
19
|
+
@mitigated = true if dep[:name] == @aux_mitigation_gem[:name] unless @aux_mitigation_gem.nil?
|
|
20
|
+
|
|
21
|
+
if dep[:name] == @fixed_dependency[:name] and is_vulnerable_version?(dep[:version], @fixed_dependency[:version])
|
|
22
|
+
ret = true
|
|
23
|
+
message = "Vulnerable #{dep[:name]} gem version found: #{dep[:version]}"
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
if ret and @mitigated
|
|
28
|
+
ret = false
|
|
29
|
+
message += "Vulnerability has been mitigated by gem #{@aux_mitigation_gem[:name]}. Don't remove it from your Gemfile"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
self.evidences << message unless message.empty?
|
|
33
|
+
|
|
34
|
+
ret
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module Codesake
|
|
2
|
+
module Dawn
|
|
3
|
+
module Kb
|
|
4
|
+
class NotRevisedCode
|
|
5
|
+
include PatternMatchCheck
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def initialize
|
|
9
|
+
super({:name=>"Not revised code",
|
|
10
|
+
:cvss=>"",
|
|
11
|
+
:release_date=>nil,
|
|
12
|
+
:cwe=>"",
|
|
13
|
+
:owasp=>"",
|
|
14
|
+
:applies=>["sinatra", "rails", "padrino"],
|
|
15
|
+
:kind=>Codesake::Dawn::KnowledgeBase::PATTERN_MATCH_CHECK,
|
|
16
|
+
:message=>"Analyzing comments, it seems your code is waiting from some review from you. Please consider take action before putting it in production.\nThis check will analyze the source code looking for the following patterns: XXX, TO_CHECK, CHECKME, CHECK and FIXME",
|
|
17
|
+
:mitigation=>"Please review the file fixing the issue.",
|
|
18
|
+
:attack_pattern => ["XXX", "TO_CHECK", "CHECKME", "CHECK", "FIXME"]
|
|
19
|
+
})
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
module Codesake
|
|
2
|
+
module Dawn
|
|
3
|
+
module Kb
|
|
4
|
+
module PatternMatchCheck
|
|
5
|
+
include BasicCheck
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
attr_reader :attack_pattern
|
|
9
|
+
attr_accessor :root_dir
|
|
10
|
+
|
|
11
|
+
def initialize(options={})
|
|
12
|
+
super(options)
|
|
13
|
+
@attack_pattern = options[:attack_pattern]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def vuln?
|
|
17
|
+
Dir.glob(File.join("#{root_dir}", "*")).each do |filename|
|
|
18
|
+
matches = run(load_file(filename))
|
|
19
|
+
@evidences << {:filename=>filename, :matches=>matches} unless matches.empty?
|
|
20
|
+
end
|
|
21
|
+
return ! @evidences.empty?
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
def string_to_array(par)
|
|
26
|
+
return par if par.class == Array
|
|
27
|
+
%w(par)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def load_file(filename)
|
|
31
|
+
return [] unless File.exists?(filename) and File.file?(filename)
|
|
32
|
+
|
|
33
|
+
f = File.open(filename)
|
|
34
|
+
lines = f.readlines
|
|
35
|
+
f.close
|
|
36
|
+
|
|
37
|
+
lines
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def run(lines)
|
|
41
|
+
hits = []
|
|
42
|
+
|
|
43
|
+
patterns = string_to_array(@attack_pattern)
|
|
44
|
+
|
|
45
|
+
patterns.each do |pat|
|
|
46
|
+
|
|
47
|
+
regex=/#{pat}/
|
|
48
|
+
|
|
49
|
+
lines.each_with_index do |line,i|
|
|
50
|
+
hits << {:match=>line, :line=>i} unless (regex =~ line).nil?
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
hits
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Core KB
|
|
2
|
+
require "codesake/dawn/kb/basic_check"
|
|
3
|
+
require "codesake/dawn/kb/pattern_match_check"
|
|
4
|
+
require "codesake/dawn/kb/dependency_check"
|
|
5
|
+
|
|
6
|
+
# Q&A related checks
|
|
7
|
+
require "codesake/dawn/kb/not_revised_code"
|
|
8
|
+
|
|
9
|
+
# CVE - 2011
|
|
10
|
+
require "codesake/dawn/kb/cve_2011_2931"
|
|
11
|
+
|
|
12
|
+
# CVE - 2012
|
|
13
|
+
require "codesake/dawn/kb/cve_2012_2660"
|
|
14
|
+
require "codesake/dawn/kb/cve_2012_2661"
|
|
15
|
+
require "codesake/dawn/kb/cve_2012_2694"
|
|
16
|
+
require "codesake/dawn/kb/cve_2012_2695"
|
|
17
|
+
require "codesake/dawn/kb/cve_2012_3465"
|
|
18
|
+
require "codesake/dawn/kb/cve_2012_6496"
|
|
19
|
+
require "codesake/dawn/kb/cve_2012_6497"
|
|
20
|
+
|
|
21
|
+
# CVE - 2013
|
|
22
|
+
require "codesake/dawn/kb/cve_2013_1855"
|
|
23
|
+
require "codesake/dawn/kb/cve_2013_1857"
|
|
24
|
+
require "codesake/dawn/kb/cve_2013_1800"
|
|
25
|
+
require "codesake/dawn/kb/cve_2013_0333"
|
|
26
|
+
require "codesake/dawn/kb/cve_2013_0269"
|
|
27
|
+
require "codesake/dawn/kb/cve_2013_0155"
|
|
28
|
+
|
|
29
|
+
module Codesake
|
|
30
|
+
module Dawn
|
|
31
|
+
# XXX: Check if it best using a singleton here
|
|
32
|
+
class KnowledgeBase
|
|
33
|
+
|
|
34
|
+
DEPENDENCY_CHECK = :dependency_check
|
|
35
|
+
PATTERN_MATCH_CHECK = :pattern_match_check
|
|
36
|
+
|
|
37
|
+
def initialize
|
|
38
|
+
@security_checks = Codesake::Dawn::KnowledgeBase.load_security_checks
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.find(checks=nil, name)
|
|
42
|
+
return nil if name.nil? or name.empty?
|
|
43
|
+
checks = Codesake::Dawn::KnowledgeBase.load_security_checks if checks.nil?
|
|
44
|
+
|
|
45
|
+
checks.each do |sc|
|
|
46
|
+
return sc if sc.name == name
|
|
47
|
+
end
|
|
48
|
+
nil
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def find(name)
|
|
52
|
+
Codesake::Dawn::KnowledgeBase.find(@security_checks, name)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def all
|
|
56
|
+
@security_checks
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def all_by_mvc(mvc)
|
|
60
|
+
ret = []
|
|
61
|
+
@security_checks.each do |sc|
|
|
62
|
+
ret << sc if sc.applies_to?(mvc)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def all_sinatra_checks
|
|
68
|
+
self.all_by_mvc(:sinatra)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def all_rails_checks
|
|
72
|
+
self.all_by_mvc(:rails)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def all_padrino_checks
|
|
76
|
+
self.all_by_mvc(:padrino)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def all_rack_checks
|
|
80
|
+
self.all_by_mvc(:rack)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def self.load_security_checks
|
|
84
|
+
[
|
|
85
|
+
Codesake::Dawn::Kb::NotRevisedCode.new,
|
|
86
|
+
Codesake::Dawn::Kb::CVE_2011_2931.new,
|
|
87
|
+
Codesake::Dawn::Kb::CVE_2012_2660.new,
|
|
88
|
+
Codesake::Dawn::Kb::CVE_2012_2661.new,
|
|
89
|
+
Codesake::Dawn::Kb::CVE_2012_2694.new,
|
|
90
|
+
Codesake::Dawn::Kb::CVE_2012_2695.new,
|
|
91
|
+
Codesake::Dawn::Kb::CVE_2012_3465.new,
|
|
92
|
+
Codesake::Dawn::Kb::CVE_2012_6496.new,
|
|
93
|
+
Codesake::Dawn::Kb::CVE_2012_6497.new,
|
|
94
|
+
Codesake::Dawn::Kb::CVE_2013_1855.new,
|
|
95
|
+
Codesake::Dawn::Kb::CVE_2013_1800.new,
|
|
96
|
+
Codesake::Dawn::Kb::CVE_2013_0333.new,
|
|
97
|
+
Codesake::Dawn::Kb::CVE_2013_0269.new,
|
|
98
|
+
Codesake::Dawn::Kb::CVE_2013_1857.new,
|
|
99
|
+
Codesake::Dawn::Kb::CVE_2013_0155.new,
|
|
100
|
+
]
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "The Codesake Dawn knowledge base" do
|
|
4
|
+
let (:kb) {Codesake::Dawn::KnowledgeBase.new}
|
|
5
|
+
it "must not be empty" do
|
|
6
|
+
kb.all.size.should_not == 0
|
|
7
|
+
|
|
8
|
+
end
|
|
9
|
+
it "must have a find method" do
|
|
10
|
+
kb.should respond_to(:find)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "must have an all_by_mvc method" do
|
|
14
|
+
kb.should respond_to(:all_by_mvc)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
it "will return a nil object if it doesn't find a particular security check" do
|
|
19
|
+
kb.find("A non existant security check name").should be_nil
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "must have at least a test for sinatra" do
|
|
23
|
+
kb.all_by_mvc("sinatra").size.should > 0
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# KB Content
|
|
27
|
+
it "must have test for CVE_2013_1855" do
|
|
28
|
+
sc = kb.find("CVE-2013-1855")
|
|
29
|
+
sc.should_not be_nil
|
|
30
|
+
sc.class.should == Codesake::Dawn::Kb::CVE_2013_1855
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
it "must have test for CVE_2013_0333" do
|
|
35
|
+
sc = kb.find("CVE-2013-0333")
|
|
36
|
+
sc.should_not be_nil
|
|
37
|
+
sc.class.should == Codesake::Dawn::Kb::CVE_2013_0333
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "must have test for CVE_2013_1857" do
|
|
41
|
+
sc = kb.find("CVE-2013-1857")
|
|
42
|
+
sc.should_not be_nil
|
|
43
|
+
sc.class.should == Codesake::Dawn::Kb::CVE_2013_1857
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "must have test for CVE_2012_2660" do
|
|
47
|
+
sc = kb.find("CVE-2012-2660")
|
|
48
|
+
sc.should_not be_nil
|
|
49
|
+
sc.class.should == Codesake::Dawn::Kb::CVE_2012_2660
|
|
50
|
+
end
|
|
51
|
+
it "must have test for CVE_2012_2661" do
|
|
52
|
+
sc = kb.find("CVE-2012-2661")
|
|
53
|
+
sc.should_not be_nil
|
|
54
|
+
sc.class.should == Codesake::Dawn::Kb::CVE_2012_2661
|
|
55
|
+
end
|
|
56
|
+
it "must have test for CVE_2012_2694" do
|
|
57
|
+
sc = kb.find("CVE-2012-2694")
|
|
58
|
+
sc.should_not be_nil
|
|
59
|
+
sc.class.should == Codesake::Dawn::Kb::CVE_2012_2694
|
|
60
|
+
end
|
|
61
|
+
it "must have test for CVE_2012_2695" do
|
|
62
|
+
sc = kb.find("CVE-2012-2695")
|
|
63
|
+
sc.should_not be_nil
|
|
64
|
+
sc.class.should == Codesake::Dawn::Kb::CVE_2012_2695
|
|
65
|
+
end
|
|
66
|
+
it "must have test for CVE_2012_6496" do
|
|
67
|
+
sc = kb.find("CVE-2012-6496")
|
|
68
|
+
sc.should_not be_nil
|
|
69
|
+
sc.class.should == Codesake::Dawn::Kb::CVE_2012_6496
|
|
70
|
+
end
|
|
71
|
+
it "must have test for CVE_2012_6497" do
|
|
72
|
+
sc = kb.find("CVE-2012-6496")
|
|
73
|
+
sc.should_not be_nil
|
|
74
|
+
sc.class.should == Codesake::Dawn::Kb::CVE_2012_6496
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "must have test for CVE_2013_0269" do
|
|
78
|
+
sc = kb.find("CVE-2013-0269")
|
|
79
|
+
sc.should_not be_nil
|
|
80
|
+
sc.class.should == Codesake::Dawn::Kb::CVE_2013_0269
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "must have test for CVE_2013_0155" do
|
|
84
|
+
sc = kb.find("CVE-2013-0155")
|
|
85
|
+
sc.should_not be_nil
|
|
86
|
+
sc.class.should == Codesake::Dawn::Kb::CVE_2013_0155
|
|
87
|
+
end
|
|
88
|
+
it "must have test for CVE_2011_2931" do
|
|
89
|
+
sc = kb.find("CVE-2011-2931")
|
|
90
|
+
sc.should_not be_nil
|
|
91
|
+
sc.class.should == Codesake::Dawn::Kb::CVE_2011_2931
|
|
92
|
+
end
|
|
93
|
+
it "must have test for CVE_2012_3465" do
|
|
94
|
+
sc = kb.find("CVE-2012-3465")
|
|
95
|
+
sc.should_not be_nil
|
|
96
|
+
sc.class.should == Codesake::Dawn::Kb::CVE_2012_3465
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "The Codesake::Dawn engine for sinatra applications" do
|
|
4
|
+
before(:all) {@engine= Codesake::Dawn::Sinatra.new('./spec/support/sinatra-safe')}
|
|
5
|
+
|
|
6
|
+
it "has a proper name" do
|
|
7
|
+
@engine.name.should == "sinatra"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "has a valid target" do
|
|
11
|
+
@engine.target.should == "./spec/support/sinatra-safe"
|
|
12
|
+
@engine.target_is_dir?.should be_true
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "has a good Gemfile.lock" do
|
|
16
|
+
@engine.has_gemfile_lock?.should be_true
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "detects a sinatra 1.4.2" do
|
|
20
|
+
@engine.mvc_version.should == "1.4.2"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "has some check in the knowledge base" do
|
|
24
|
+
@engine.checks.should_not be_nil
|
|
25
|
+
@engine.checks.should_not be_empty
|
|
26
|
+
end
|
|
27
|
+
it "has check for CVE-2013-1800" do
|
|
28
|
+
Codesake::Dawn::KnowledgeBase.find(@engine.checks, "CVE-2013-1800").should_not be_nil
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "applies all checks" do
|
|
32
|
+
@engine.apply_all.should be_true
|
|
33
|
+
end
|
|
34
|
+
it "applies check for CVE-2013-1800" do
|
|
35
|
+
@engine.apply("CVE-2013-1800").should be_true
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "applies check for \"Not revised code\"" do
|
|
39
|
+
@engine.apply("Not revised code").should be_true
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
describe "applied to sinatra-safe application" do
|
|
43
|
+
it "reports it's not vulnerable to CVE-2013-1800" do
|
|
44
|
+
@engine.is_vulnerable_to?("CVE-2013-1800").should be_false
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "reports it's not vulnerable to \"Not revised code\"" do
|
|
48
|
+
@engine.is_vulnerable_to?("Not revised code").should be_false
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "reports it has no vulnerabilities" do
|
|
52
|
+
@engine.vulnerabilities.should be_empty
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe "applied do the sinatra-vulnerable application do" do
|
|
57
|
+
before (:all) {@engine= Codesake::Dawn::Sinatra.new('./spec/support/sinatra-vulnerable')}
|
|
58
|
+
it "has a valid target" do
|
|
59
|
+
@engine.target.should == "./spec/support/sinatra-vulnerable"
|
|
60
|
+
@engine.target_is_dir?.should be_true
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "reports it's vulnerable to CVE-2013-1800" do
|
|
64
|
+
@engine.is_vulnerable_to?("CVE-2013-1800").should be_true
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "reports it's vulnerable to \"Not revised code\"" do
|
|
68
|
+
@engine.is_vulnerable_to?("Not revised code").should be_true
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "reports it has vulnerabilities" do
|
|
72
|
+
@engine.vulnerabilities.should_not be_empty
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "applies automagically all the tests if no test has been applied" do
|
|
76
|
+
e2 = Codesake::Dawn::Sinatra.new('./spec/support/sinatra-vulnerable')
|
|
77
|
+
e2.vulnerabilities.should_not be_empty
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|