diff --git a/app/views/tutorials/gauntlt.html.erb b/app/views/tutorials/gauntlt.html.erb
new file mode 100644
index 0000000..bf2a098
--- /dev/null
+++ b/app/views/tutorials/gauntlt.html.erb
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+ Gauntlet
+
+
+
+
+ Gauntlt is a tool used for unit testing leveraging third-party tools. We've baked this into Railsgoat so that you can play with it.
To learn more about this tool, please visit their site at: <%= link_to "Gauntlet Github Repository", "https://github.com/gauntlt/gauntlt", {:style =>"color: rgb(181, 121, 158);"} %>
+
+ All *.attack files are contained under the gauntlt_scripts directory. We have provided a simple.attack file that demonstrates the tool works. If errors occur, please submit a bug through our github powered issue tracking system.
+
+
+ To run this tool type this via the command line:
$ gauntlt
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/views/tutorials/guard.html.erb b/app/views/tutorials/guard.html.erb
index a657301..b74d67c 100755
--- a/app/views/tutorials/guard.html.erb
+++ b/app/views/tutorials/guard.html.erb
@@ -21,7 +21,6 @@
\ No newline at end of file
From f9bbbe0a549fd0bd5ab54f2c8f4259353c55c615 Mon Sep 17 00:00:00 2001
From: cktricky
Date: Mon, 14 Oct 2013 08:44:09 -0400
Subject: [PATCH 016/149] oops
---
app/views/tutorials/guard.html.erb.orig | 33 -------------------------
1 file changed, 33 deletions(-)
delete mode 100755 app/views/tutorials/guard.html.erb.orig
diff --git a/app/views/tutorials/guard.html.erb.orig b/app/views/tutorials/guard.html.erb.orig
deleted file mode 100755
index f0ff6d1..0000000
--- a/app/views/tutorials/guard.html.erb.orig
+++ /dev/null
@@ -1,33 +0,0 @@
-
-
-
-
-
-
-
- Using Guard with Brakeman and Bundle-Audit
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
From 64f2ad9f9e4cf7435d2a8281ed2b612ab81d8ff5 Mon Sep 17 00:00:00 2001
From: cktricky
Date: Mon, 14 Oct 2013 08:46:21 -0400
Subject: [PATCH 017/149] very minor sidebar change
---
app/views/tutorials/gauntlt.html.erb | 1 +
1 file changed, 1 insertion(+)
diff --git a/app/views/tutorials/gauntlt.html.erb b/app/views/tutorials/gauntlt.html.erb
index bf2a098..27f9e8d 100644
--- a/app/views/tutorials/gauntlt.html.erb
+++ b/app/views/tutorials/gauntlt.html.erb
@@ -29,6 +29,7 @@
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index a58b21e..6aaa2c7 100755
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,84 +1,85 @@
Railsgoat::Application.routes.draw do
-get "login" => "sessions#new"
-get "signup" => "users#new"
-get "logout" => "sessions#destroy"
+ get "login" => "sessions#new"
+ get "signup" => "users#new"
+ get "logout" => "sessions#destroy"
-resources :sessions do
+ resources :sessions do
-end
-
-resources :users do
- get "account_settings"
-
- resources :retirement do
- end
-
- resources :paid_time_off do
- end
-
- resources :work_info do
- end
-
- resources :performance do
-
- end
-
- resources :benefit_forms do
-
end
- resources :messages do
+ resources :users do
+ get "account_settings"
+
+ resources :retirement do
+ end
+
+ resources :paid_time_off do
+ end
+
+ resources :work_info do
+ end
+
+ resources :performance do
+
+ end
+
+ resources :benefit_forms do
+
+ end
+
+ resources :messages do
+ end
+
end
-
-end
-get "download" => "benefit_forms#download"
-post "upload" => "benefit_forms#upload"
+ get "download" => "benefit_forms#download"
+ post "upload" => "benefit_forms#upload"
-resources :tutorials do
- collection do
- get "credentials"
- get "injection"
- get "xss"
- get "broken_auth"
- get "insecure_dor"
- get "csrf"
- get "misconfig"
- get "crypto"
- get "url_access"
- get "ssl_tls"
- get "redirects"
- get "guard"
- get "info_disclosure"
- get "mass_assignment"
- get "constantize"
- get "gauntlt"
+ resources :tutorials do
+ collection do
+ get "credentials"
+ get "injection"
+ get "xss"
+ get "broken_auth"
+ get "insecure_dor"
+ get "csrf"
+ get "misconfig"
+ get "crypto"
+ get "url_access"
+ get "insecure_components"
+ get "ssl_tls"
+ get "redirects"
+ get "guard"
+ get "info_disclosure"
+ get "mass_assignment"
+ get "constantize"
+ get "gauntlt"
+ end
end
-end
-resources :schedule do
- collection do
- get "get_pto_schedule"
+ resources :schedule do
+ collection do
+ get "get_pto_schedule"
+ end
+
end
-
-end
-resources :admin do
- get "dashboard"
- get "get_user"
- post "delete_user"
- put "update_user"
- get "get_all_users"
-end
-
-resources :dashboard do
- collection do
- get "home"
+ resources :admin do
+ get "dashboard"
+ get "get_user"
+ post "delete_user"
+ put "update_user"
+ get "get_all_users"
+ end
+
+ resources :dashboard do
+ collection do
+ get "home"
+ end
end
-end
-root :to => "sessions#new"
+ root :to => "sessions#new"
-end
+end
\ No newline at end of file
From 9cbdbf01e5cceb6df7c858d66bcd03b3ba984b16 Mon Sep 17 00:00:00 2001
From: cktricky
Date: Wed, 13 Nov 2013 12:19:33 -0500
Subject: [PATCH 035/149] should fix conflicts
---
config/routes.rb | 31 ++-----------------------------
1 file changed, 2 insertions(+), 29 deletions(-)
diff --git a/config/routes.rb b/config/routes.rb
index d4142bc..39206f2 100755
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -45,7 +45,7 @@ Railsgoat::Application.routes.draw do
get "insecure_dor"
get "csrf"
get "misconfig"
- get "crypto"
+ get "exposure"
get "url_access"
get "insecure_components"
get "ssl_tls"
@@ -57,39 +57,12 @@ Railsgoat::Application.routes.draw do
get "gauntlt"
end
end
-<<<<<<< HEAD
-
-end
-
-get "download" => "benefit_forms#download"
-post "upload" => "benefit_forms#upload"
-
-resources :tutorials do
- collection do
- get "credentials"
- get "injection"
- get "xss"
- get "broken_auth"
- get "insecure_dor"
- get "csrf"
- get "misconfig"
- get "exposure"
- get "url_access"
- get "ssl_tls"
- get "redirects"
- get "guard"
- get "info_disclosure"
- get "mass_assignment"
- get "constantize"
- get "gauntlt"
-=======
resources :schedule do
collection do
get "get_pto_schedule"
end
->>>>>>> f0ca17df79bce4b15917780924ceef8407300fbb
end
resources :admin do
@@ -109,4 +82,4 @@ resources :tutorials do
root :to => "sessions#new"
-end
+end
\ No newline at end of file
From 665ccb21678ff54c37c51607291797ce0040bd75 Mon Sep 17 00:00:00 2001
From: cktricky
Date: Wed, 13 Nov 2013 14:01:29 -0500
Subject: [PATCH 036/149] removed orig file and also began encryption related
stuff for ssn(s)
---
app/models/benefits.rb.orig | 33 ---------------------------------
app/models/work_info.rb | 8 ++++++--
2 files changed, 6 insertions(+), 35 deletions(-)
delete mode 100644 app/models/benefits.rb.orig
diff --git a/app/models/benefits.rb.orig b/app/models/benefits.rb.orig
deleted file mode 100644
index 38ad1ff..0000000
--- a/app/models/benefits.rb.orig
+++ /dev/null
@@ -1,33 +0,0 @@
-class Benefits < ActiveRecord::Base
- attr_accessor :backup
-
- def self.save(file, backup=false)
- data_path = Rails.root.join("public", "data")
- full_file_name = "#{data_path}/#{file.original_filename}"
- f = File.open(full_file_name, "w+")
- f.write file.read
- f.close
- make_backup(file, data_path, full_file_name) if backup == "true"
- end
-
-<<<<<<< HEAD
- def self.make_backup(*params)
- if File.exists?(full_file_name)
- system("cp #{full_file_name} #{data_path}/bak#{Time.now.to_i}_#{file.original_filename}")
- end
- end
-=======
- def self.make_backup(file, data_path, full_file_name)
- if File.exists?(full_file_name)
- system("cp #{full_file_name} #{data_path}/bak#{Time.now.to_i}_#{file.original_filename}")
- end
- end
->>>>>>> bd066068ff2fd63a0edeede010167cfa63a03aff
-
-=begin
- def self.make_backup(file, data_path, full_file_name)
- FileUtils.cp "#{full_file_name}", "#{data_path}/bak#{Time.now.to_i}_#{file.original_filename}"
- end
-=end
-
-end
diff --git a/app/models/work_info.rb b/app/models/work_info.rb
index c3b70b6..364ea3f 100644
--- a/app/models/work_info.rb
+++ b/app/models/work_info.rb
@@ -8,10 +8,14 @@ class WorkInfo < ActiveRecord::Base
"***-**-" << self.SSN[-4,4]
end
- def encrypt_ssn
+ def encrypt_ssn(data)
end
- def decrypt_ssn
+ def decrypt_ssn(encrypted_data)
+ end
+
+ def cipher_mode
+ 'aes-256-cbc'
end
end
From d9956caec1991fc36fbfb5b2df8d9a4f4cb57d87 Mon Sep 17 00:00:00 2001
From: cktricky
Date: Wed, 13 Nov 2013 14:18:25 -0500
Subject: [PATCH 037/149] removed orig file
---
app/models/performance.rb.orig | 14 --------------
1 file changed, 14 deletions(-)
delete mode 100644 app/models/performance.rb.orig
diff --git a/app/models/performance.rb.orig b/app/models/performance.rb.orig
deleted file mode 100644
index 772aaf0..0000000
--- a/app/models/performance.rb.orig
+++ /dev/null
@@ -1,14 +0,0 @@
-class Performance < ActiveRecord::Base
- attr_accessible :comments, :date_submitted, :reviewer, :score
- belongs_to :user
-
- def reviewer_name
-<<<<<<< HEAD
- u = User.find_by_id(self.reviewer)
- u.full_name if u.respond_to?('full_name')
-=======
- u = User.find_by_id(self.reviewer)
- u.full_name if u.respond_to?('fullname')
->>>>>>> 289716b24c7c4a1d72fcf1cf16fdc003e96e728c
- end
-end
From 91e6797b40cc34fe982e48f075a667845d5b3c83 Mon Sep 17 00:00:00 2001
From: Mike McCabe
Date: Wed, 13 Nov 2013 18:23:04 -0500
Subject: [PATCH 038/149] adding broken functionality for A7
---
app/controllers/admin_controller.rb | 8 +++++++-
app/controllers/application_controller.rb | 2 +-
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb
index 5926b40..d7a29c7 100755
--- a/app/controllers/admin_controller.rb
+++ b/app/controllers/admin_controller.rb
@@ -1,6 +1,6 @@
class AdminController < ApplicationController
- # before_filter :administrative
+ before_filter :administrative, :if => :admin_param
skip_before_filter :has_info
def dashboard
@@ -45,4 +45,10 @@ class AdminController < ApplicationController
end
end
+
+ private
+
+ def admin_param
+ params[:admin_id] != '1'
+ end
end
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index a0ef5cf..9d5628d 100755
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -23,7 +23,7 @@ class ApplicationController < ActionController::Base
def administrative
if not is_admin?
- reset_session
+ #reset_session
redirect_to root_url
end
end
From af8776a3eaaea2167366f00c0a8d165d95fb34ec Mon Sep 17 00:00:00 2001
From: Mike McCabe
Date: Wed, 13 Nov 2013 18:23:29 -0500
Subject: [PATCH 039/149] halfway done A7
---
app/controllers/tutorials_controller.rb | 3 +
app/views/layouts/tutorial/_sidebar.html.erb | 8 +-
.../_access_control_first.html.erb | 107 ++++++++++++++++++
app/views/tutorials/access_control.html.erb | 17 +++
config/routes.rb | 1 +
5 files changed, 132 insertions(+), 4 deletions(-)
create mode 100644 app/views/layouts/tutorial/access_control/_access_control_first.html.erb
create mode 100644 app/views/tutorials/access_control.html.erb
diff --git a/app/controllers/tutorials_controller.rb b/app/controllers/tutorials_controller.rb
index fb4d61d..0b88a9e 100755
--- a/app/controllers/tutorials_controller.rb
+++ b/app/controllers/tutorials_controller.rb
@@ -64,6 +64,9 @@ class TutorialsController < ApplicationController
def insecure_components
end
+
+ def access_control
+ end
def crypto
end
diff --git a/app/views/layouts/tutorial/_sidebar.html.erb b/app/views/layouts/tutorial/_sidebar.html.erb
index 10e885f..acfdfd7 100755
--- a/app/views/layouts/tutorial/_sidebar.html.erb
+++ b/app/views/layouts/tutorial/_sidebar.html.erb
@@ -57,12 +57,12 @@
A6 Exposure
<% end %>
-
- <%= link_to url_access_tutorials_path do %>
+
+ <%= link_to access_control_tutorials_path do %>
- A7 Access
+ A7 Access Control
<% end %>
@@ -73,7 +73,7 @@
A8 CSRF
<% end %>
-
+
<%= link_to insecure_components_tutorials_path do %>
diff --git a/app/views/layouts/tutorial/access_control/_access_control_first.html.erb b/app/views/layouts/tutorial/access_control/_access_control_first.html.erb
new file mode 100644
index 0000000..cce74f4
--- /dev/null
+++ b/app/views/layouts/tutorial/access_control/_access_control_first.html.erb
@@ -0,0 +1,107 @@
+
+ Many web applications check URL access rights before rendering protected links and buttons. However, applications need to perform similar access control checks each time these pages are accessed, or attackers will be able to forge URLs to access these hidden pages anyway.
+
+ Rails provides the ability to apply before_filter(s) which run prior to rendering content to the user. This is helpful when restricting access to content based on the user's role. Currently, the methods to apply a before_filter already exist in the application controller but were forgotten when creating the administrative functionality. Notice an asbsence of the before_filter within app/controllers/admin_controller.rb
+
+ I bet there is some admin functionality in here :-)
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/views/tutorials/access_control.html.erb b/app/views/tutorials/access_control.html.erb
new file mode 100644
index 0000000..6796302
--- /dev/null
+++ b/app/views/tutorials/access_control.html.erb
@@ -0,0 +1,17 @@
+
+
+
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index 39206f2..800d3d7 100755
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -48,6 +48,7 @@ Railsgoat::Application.routes.draw do
get "exposure"
get "url_access"
get "insecure_components"
+ get "access_control"
get "ssl_tls"
get "redirects"
get "guard"
From efcb7b8c4bee1d55f953bc2b60d1f8ab0b23756e Mon Sep 17 00:00:00 2001
From: cktricky
Date: Wed, 13 Nov 2013 18:24:26 -0500
Subject: [PATCH 040/149] working on encryption
---
app/models/key_management.rb | 5 +++
app/models/work_info.rb | 32 ++++++++++++++++---
config/initializers/key.rb | 5 +++
.../20131113200708_create_key_managements.rb | 10 ++++++
db/schema.rb | 9 +++++-
db/seeds.rb | 31 +++++++++++++++---
spec/models/key_management_spec.rb | 5 +++
7 files changed, 88 insertions(+), 9 deletions(-)
create mode 100644 app/models/key_management.rb
create mode 100644 config/initializers/key.rb
create mode 100644 db/migrate/20131113200708_create_key_managements.rb
create mode 100644 spec/models/key_management_spec.rb
diff --git a/app/models/key_management.rb b/app/models/key_management.rb
new file mode 100644
index 0000000..80bf527
--- /dev/null
+++ b/app/models/key_management.rb
@@ -0,0 +1,5 @@
+class KeyManagement < ActiveRecord::Base
+ attr_accessible :iv, :user_id
+ belongs_to :work_info
+
+end
diff --git a/app/models/work_info.rb b/app/models/work_info.rb
index 364ea3f..f1fb5fd 100644
--- a/app/models/work_info.rb
+++ b/app/models/work_info.rb
@@ -1,20 +1,44 @@
class WorkInfo < ActiveRecord::Base
attr_accessible :DoB, :SSN, :bonuses, :income, :years_worked
belongs_to :user
- #before_save :encrypt_ssn
+ has_one :key_management, :foreign_key => :user_id, :primary_key => :user_id, :dependent => :destroy
+ before_save :encrypt_ssn
+
# We should probably use this
def last_four
"***-**-" << self.SSN[-4,4]
end
- def encrypt_ssn(data)
+ def encrypt_ssn
+ aes = OpenSSL::Cipher::Cipher.new(cipher_type)
+ aes.encrypt
+ aes.key = key
+ aes.iv = iv if iv != nil
+ self.encrypted_ssn = aes.update(self.SSN) + aes.final
+ self.SSN = nil
end
- def decrypt_ssn(encrypted_data)
+ def decrypt_ssn
+ aes = OpenSSL::Cipher::Cipher.new(cipher_type)
+ aes.decrypt
+ aes.key = key
+ aes.iv = iv if iv != nil
+ aes.update(self.encrypted_ssn) + aes.final
end
- def cipher_mode
+ def key
+ raise "Key Missing" if !(KEY)
+ KEY
+ end
+
+ def iv
+ "asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf"
+ #self.key_management.iv
+ #raise "No IV for this User" if !(key_management.iv)
+ end
+
+ def cipher_type
'aes-256-cbc'
end
diff --git a/config/initializers/key.rb b/config/initializers/key.rb
new file mode 100644
index 0000000..5f43875
--- /dev/null
+++ b/config/initializers/key.rb
@@ -0,0 +1,5 @@
+if Rails.env.production?
+ # Specify env variable/location/etc. to retrieve key from
+elsif Rails.env.development?
+ KEY = "123456789101112123456789101112123456789101112"
+end
\ No newline at end of file
diff --git a/db/migrate/20131113200708_create_key_managements.rb b/db/migrate/20131113200708_create_key_managements.rb
new file mode 100644
index 0000000..96ce247
--- /dev/null
+++ b/db/migrate/20131113200708_create_key_managements.rb
@@ -0,0 +1,10 @@
+class CreateKeyManagements < ActiveRecord::Migration
+ def change
+ create_table :key_managements do |t|
+ t.string :iv
+ t.integer :user_id
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index e98c34e..b7ded3a 100755
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,13 +11,20 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20131112235256) do
+ActiveRecord::Schema.define(:version => 20131113200708) do
create_table "benefits", :force => true do |t|
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
+ create_table "key_managements", :force => true do |t|
+ t.string "iv"
+ t.integer "user_id"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
create_table "messages", :force => true do |t|
t.integer "creator_id"
t.integer "receiver_id"
diff --git a/db/seeds.rb b/db/seeds.rb
index 3533d20..8583174 100755
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -184,6 +184,21 @@ paid_time_off = [
}
]
+ key_mgmt = [
+ {
+ :user_id => 2,
+ },
+ {
+ :user_id => 3,
+ },
+ {
+ :user_id => 4,
+ },
+ {
+ :user_id => 5,
+ }
+ ]
+
performance = [
{
:user_id => 2,
@@ -289,12 +304,12 @@ schedule.each do |event|
sched.save
end
-work_info.each do |wi|
- info = WorkInfo.new(wi.reject {|k| k == :user_id})
- info.user_id = wi[:user_id]
- info.save
+key_mgmt.each do |key|
+ KeyManagement.create(:user_id => key[:user_id], :iv => Digest::SHA2.new.to_s)
end
+
+
performance.each do |perf|
p = Performance.new(perf.reject {|k| k == :user_id})
p.user_id = perf[:user_id]
@@ -306,3 +321,11 @@ messages.each do |message|
m.creator_id = message[:creator_id]
m.save
end
+
+
+work_info.each do |wi|
+ info = WorkInfo.new(wi.reject {|k| k == :user_id})
+ info.user_id = wi[:user_id]
+ info.save
+end
+
diff --git a/spec/models/key_management_spec.rb b/spec/models/key_management_spec.rb
new file mode 100644
index 0000000..dd0b900
--- /dev/null
+++ b/spec/models/key_management_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe KeyManagement do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
From 4be667b6068c2b82231b6d939e020105dd8f552a Mon Sep 17 00:00:00 2001
From: cktricky
Date: Wed, 13 Nov 2013 19:02:37 -0500
Subject: [PATCH 041/149] working
---
app/controllers/admin_controller.rb | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb
index d7a29c7..d43dd81 100755
--- a/app/controllers/admin_controller.rb
+++ b/app/controllers/admin_controller.rb
@@ -1,6 +1,6 @@
class AdminController < ApplicationController
- before_filter :administrative, :if => :admin_param
+ #before_filter :administrative
skip_before_filter :has_info
def dashboard
@@ -45,10 +45,4 @@ class AdminController < ApplicationController
end
end
-
- private
-
- def admin_param
- params[:admin_id] != '1'
- end
end
From aeabbcf8c6d31005cd99a1074cf3d51e21cba31d Mon Sep 17 00:00:00 2001
From: Mike McCabe
Date: Wed, 13 Nov 2013 19:14:07 -0500
Subject: [PATCH 042/149] A7 - switching the var used in the view so that
non-admins can view the admin panel
---
app/views/admin/dashboard.html.erb | 2 +-
app/views/layouts/admin/_get_user.html.erb | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/app/views/admin/dashboard.html.erb b/app/views/admin/dashboard.html.erb
index 3e1466c..da2c845 100755
--- a/app/views/admin/dashboard.html.erb
+++ b/app/views/admin/dashboard.html.erb
@@ -59,7 +59,7 @@ function makeActive(){
};
function loadTable(){
- $("#userDataTable").load("/admin/"+ <%=current_user.user_id %> + "/get_all_users")
+ $("#userDataTable").load("/admin/"+ <%= params[:admin_id] %> + "/get_all_users")
};
$(document).ready(
diff --git a/app/views/layouts/admin/_get_user.html.erb b/app/views/layouts/admin/_get_user.html.erb
index eda97d7..9557b7d 100755
--- a/app/views/layouts/admin/_get_user.html.erb
+++ b/app/views/layouts/admin/_get_user.html.erb
@@ -83,7 +83,7 @@ $('#delete_button').click(function() {
$("#editAcct").modal('hide');
$.ajax({
- url: "/admin/" + <%= @user.user_id %> + "/delete_user.json",
+ url: "/admin/" + <%= params[:admin_id] %> + "/delete_user.json",
type: "POST",
success: function(response) {
$('#success').show(500).delay(1500).fadeOut();
From 2629565f216608e74bcc23d6ccd3a591534fda37 Mon Sep 17 00:00:00 2001
From: Mike McCabe
Date: Wed, 13 Nov 2013 19:34:04 -0500
Subject: [PATCH 043/149] fixing a small typo :)
---
db/seeds.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/db/seeds.rb b/db/seeds.rb
index 8583174..c8e5bfb 100755
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -33,8 +33,8 @@ users = [
{
:email => "mike@metacorp.com",
:admin => false,
- :password => "motorcross1445",
- :password_confirmation => "motorcross1445",
+ :password => "motocross1445",
+ :password_confirmation => "motocross1445",
:first_name => "Mike",
:last_name => "McCabe",
:user_id =>4
From 235b6418d0e07f666a2531e04c0b1d887dd6b655 Mon Sep 17 00:00:00 2001
From: Mike McCabe
Date: Wed, 13 Nov 2013 19:35:12 -0500
Subject: [PATCH 044/149] A7 adding before filter to see if admin or admin_id
is 1
---
app/controllers/admin_controller.rb | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb
index d43dd81..1a671f7 100755
--- a/app/controllers/admin_controller.rb
+++ b/app/controllers/admin_controller.rb
@@ -1,6 +1,6 @@
class AdminController < ApplicationController
- #before_filter :administrative
+ before_filter :administrative, :if => :admin_param
skip_before_filter :has_info
def dashboard
@@ -44,5 +44,11 @@ class AdminController < ApplicationController
format.json { render :json => { :msg => message ? "success" : "failure"} }
end
end
+
+ private
+
+ def admin_param
+ params[:id] == '1'
+ end
end
From b605a42812eba6ce87b94b9bb82d4b76dd0330f6 Mon Sep 17 00:00:00 2001
From: cktricky
Date: Wed, 13 Nov 2013 19:51:42 -0500
Subject: [PATCH 045/149] got the code kicked off so we can encrypt SSN(s) in
the database
---
app/models/user.rb | 2 ++
app/models/work_info.rb | 9 ++++----
app/views/work_info/index.html.erb | 3 +++
db/seeds.rb | 35 ++++++++++--------------------
4 files changed, 21 insertions(+), 28 deletions(-)
diff --git a/app/models/user.rb b/app/models/user.rb
index d84909c..b0204b9 100755
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -24,6 +24,8 @@ class User < ActiveRecord::Base
build_retirement(POPULATE_RETIREMENTS.shuffle.first)
build_paid_time_off(POPULATE_PAID_TIME_OFF.shuffle.first).schedule.build(POPULATE_SCHEDULE.shuffle.first)
build_work_info(POPULATE_WORK_INFO.shuffle.first)
+ # Uncomment below line to use encrypted SSN(s)
+ #work_info.build_key_management(:iv => SecureRandom.hex(32))
performance.build(POPULATE_PERFORMANCE.shuffle.first)
end
diff --git a/app/models/work_info.rb b/app/models/work_info.rb
index f1fb5fd..c8e30d8 100644
--- a/app/models/work_info.rb
+++ b/app/models/work_info.rb
@@ -2,12 +2,12 @@ class WorkInfo < ActiveRecord::Base
attr_accessible :DoB, :SSN, :bonuses, :income, :years_worked
belongs_to :user
has_one :key_management, :foreign_key => :user_id, :primary_key => :user_id, :dependent => :destroy
- before_save :encrypt_ssn
+ #before_save :encrypt_ssn
# We should probably use this
def last_four
- "***-**-" << self.SSN[-4,4]
+ "***-**-" << self.decrypt_ssn[-4,4]
end
def encrypt_ssn
@@ -33,9 +33,8 @@ class WorkInfo < ActiveRecord::Base
end
def iv
- "asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf"
- #self.key_management.iv
- #raise "No IV for this User" if !(key_management.iv)
+ raise "No IV for this User" if !(self.key_management.iv)
+ self.key_management.iv
end
def cipher_type
diff --git a/app/views/work_info/index.html.erb b/app/views/work_info/index.html.erb
index 1b429b5..96fb928 100644
--- a/app/views/work_info/index.html.erb
+++ b/app/views/work_info/index.html.erb
@@ -28,6 +28,9 @@
<%= @user.work_info.bonuses %>
<%= @user.work_info.years_worked %>
<%= @user.work_info.SSN %>
+
+
+
<%= @user.work_info.DoB %>
diff --git a/db/seeds.rb b/db/seeds.rb
index 8583174..7a46893 100755
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -184,21 +184,6 @@ paid_time_off = [
}
]
- key_mgmt = [
- {
- :user_id => 2,
- },
- {
- :user_id => 3,
- },
- {
- :user_id => 4,
- },
- {
- :user_id => 5,
- }
- ]
-
performance = [
{
:user_id => 2,
@@ -304,12 +289,6 @@ schedule.each do |event|
sched.save
end
-key_mgmt.each do |key|
- KeyManagement.create(:user_id => key[:user_id], :iv => Digest::SHA2.new.to_s)
-end
-
-
-
performance.each do |perf|
p = Performance.new(perf.reject {|k| k == :user_id})
p.user_id = perf[:user_id]
@@ -322,10 +301,20 @@ messages.each do |message|
m.save
end
-
work_info.each do |wi|
- info = WorkInfo.new(wi.reject {|k| k == :user_id})
+ info = WorkInfo.new(wi.reject {|k| k == :user_id } )
info.user_id = wi[:user_id]
info.save
end
+
+=begin
+work_info.each do |wi|
+ list = [:user_id, :SSN]
+ info = WorkInfo.new(wi.reject {|k| list.include?(k)})
+ info.user_id = wi[:user_id]
+ info.build_key_management({:user_id => wi[:user_id], :iv => SecureRandom.hex(32) })
+ info.SSN = wi[:SSN]
+ info.save
+end
+=end
From e826adadbc0b5fa63d4179602ccd98be952b5d42 Mon Sep 17 00:00:00 2001
From: Mike McCabe
Date: Wed, 13 Nov 2013 19:55:49 -0500
Subject: [PATCH 046/149] removing empty spec
---
spec/models/key_management_spec.rb | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/spec/models/key_management_spec.rb b/spec/models/key_management_spec.rb
index dd0b900..335cafc 100644
--- a/spec/models/key_management_spec.rb
+++ b/spec/models/key_management_spec.rb
@@ -1,5 +1 @@
-require 'spec_helper'
-
-describe KeyManagement do
- pending "add some examples to (or delete) #{__FILE__}"
-end
+require 'spec_helper'
\ No newline at end of file
From e764efe1d4b083c7c11278936ea74d58d5d707af Mon Sep 17 00:00:00 2001
From: cktricky
Date: Thu, 14 Nov 2013 09:39:57 -0500
Subject: [PATCH 047/149] working on A6 tutorial write-up now that the code is
working
---
.../layouts/tutorial/exposure/_ssn.html.erb | 69 ++++++++++++++-----
1 file changed, 51 insertions(+), 18 deletions(-)
diff --git a/app/views/layouts/tutorial/exposure/_ssn.html.erb b/app/views/layouts/tutorial/exposure/_ssn.html.erb
index 0890a3e..4e64a01 100644
--- a/app/views/layouts/tutorial/exposure/_ssn.html.erb
+++ b/app/views/layouts/tutorial/exposure/_ssn.html.erb
@@ -36,20 +36,13 @@
The Railsgoat application stores user's Social Security Numbers in plain-text within the database and because of this, it fails to adequately protect these numbers from theft. Additionally, the user's full SSN is sent back to the user within an HTTP response from the application.
- The WorkInfo model (app/models/work_info.rb) is missing code to encrypt this data prior to storage. Additionally, while code exists to render only the last 4 numbers of an SSN, at no time is it used.
+ The WorkInfo model (app/models/work_info.rb) is missing code to encrypt this data prior to storage. Additionally, while code exists to render only the last 4 numbers of an SSN (shown below), at no time is it used.
- class WorkInfo < ActiveRecord::Base
- attr_accessible :DoB, :SSN, :bonuses, :income, :years_worked
- belongs_to :user
-
# We should probably use this
def last_four
- "***-**-" << self.SSN[-4,4]
+ "***-**-" << self.decrypt_ssn[-4,4]
end
-
- end
-
@@ -72,15 +65,55 @@
Only authorized users can access decrypted copies of the data
Use a strong algorithm
Strong key is generated, protected from unauthorized access, and key change is planned for.
- One additional item to note with rails specifically, the framework makes it easy to determine the type of environment running, example:
-
- Rails.env.production?
-
- ...or
-
- Rails.env.development?
-
- This allows developers to easily create different keys for development and production and should be considered an asset to utilize. While development keys are usually stored within the source code of most rails applications, and developers with access to the repo can download those keys, the same should NOT hold true for production keys.
+
+
+
+ In the following code, we demonstrate switching from the storage of full SSN(s) in clear-text to storing them in the AES-256 encrypted format. The first thing to do is build the encrypt and decrypt functions. These can be found within app/models/work_info.rb.
+
+
+ def encrypt_ssn
+ aes = OpenSSL::Cipher::Cipher.new(cipher_type)
+ aes.encrypt
+ aes.key = key
+ aes.iv = iv if iv != nil
+ self.encrypted_ssn = aes.update(self.SSN) + aes.final
+ self.SSN = nil
+ end
+
+ def decrypt_ssn
+ aes = OpenSSL::Cipher::Cipher.new(cipher_type)
+ aes.decrypt
+ aes.key = key
+ aes.iv = iv if iv != nil
+ aes.update(self.encrypted_ssn) + aes.final
+ end
+
+ def key
+ raise "Key Missing" if !(KEY)
+ KEY
+ end
+
+ def iv
+ raise "No IV for this User" if !(self.key_management.iv)
+ self.key_management.iv
+ end
+
+ def cipher_type
+ 'aes-256-cbc'
+ end
+
+
+ Also within the WorkInfo model, we add the following line of code...
+
+
+ before_save :encrypt_ssn
+
+
+ The remaining pieces are:
+
We "seed" the database with per-user initialization vectors (IV) and store them within the key_management table
+
Separate production and development encryption keys. Production keys should be stored in an HSM, environment variable, etc. but never within the source code. Development keys are irrelevant if not being used for real data
+
Change the view where SSNs are called and rendered to the user so that the "last_four" method is called instead
+
For new user's who are registering, we create an initialization specific to their account
Change the view where SSNs are called and rendered to the user so that the "last_four" method is called instead
For new user's who are registering, we create an initialization specific to their account
+
+ # SEED DATA
+ work_info.each do |wi|
+ list = [:user_id, :SSN]
+ info = WorkInfo.new(wi.reject {|k| list.include?(k)})
+ info.user_id = wi[:user_id]
+ info.build_key_management({:user_id => wi[:user_id], :iv => SecureRandom.hex(32) })
+ info.SSN = wi[:SSN]
+ info.save
+ end
+
+
+ # SEPARATE PROD AND DEV KEYS (config/initializers/key.rb)
+ if Rails.env.production?
+ # Specify env variable/location/etc. to retrieve key from
+ elsif Rails.env.development?
+ KEY = "123456789101112123456789101112123456789101112"
+ end
+
+
+ # CHANGE VIEW TO CALL LAST FOUR METHOD (app/views/work_info/index.html.erb)
+ <%= CGI.unescapeHTML("<td class="ssn"><%= @user.work_info.last_four %></td>") %>
+
+
+ def build_benefits_data
+ build_retirement(POPULATE_RETIREMENTS.shuffle.first)
+ build_paid_time_off(POPULATE_PAID_TIME_OFF.shuffle.first).schedule.build(POPULATE_SCHEDULE.shuffle.first)
+ build_work_info(POPULATE_WORK_INFO.shuffle.first)
+ # Uncomment below line to use encrypted SSN(s)
+ work_info.build_key_management(:iv => SecureRandom.hex(32))
+ performance.build(POPULATE_PERFORMANCE.shuffle.first)
+ end
+
- Rails provides the ability to apply before_filter(s) which run prior to rendering content to the user. This is helpful when restricting access to content based on the user's role. Currently, the methods to apply a before_filter already exist in the application controller but were forgotten when creating the administrative functionality. Notice an asbsence of the before_filter within app/controllers/admin_controller.rb
+ Rails provides the ability to apply before_filter(s) which run prior to rendering content to the user. This is helpful when restricting access to content based on the user's role. These filters can be skipped on certain actions or controllers and entirely if certain conditions are met. In this case, the before_filter is being skipped if the admin_id param is equal to 1.
- Request the following URL /admin/1/dashboard and have fun :-)
+ Request the following URL: /admin/1/dashboard and have fun :-)
Failure to Restrict URL Access - SOLUTION
- The code is already available to restrict access to the admin controller by role within app/controllers/application_controller.rb:
+ The code is already available to restrict access to the admin controller by role within app/controllers/application_controller.rb. The additional condition that if the admin_id param equals 1 means the filter can be circumvented by an attacker. The way to fix this issue is to enforce the filter on all access requests to the admin dashboard as follows:
- helper_method :current_user, :is_admin?
-
- def is_admin?
- current_user.admin if current_user
- end
-
- def administrative
- if not is_admin?
- reset_session
- redirect_to root_url
- end
- end
-
-
- Then add the following line within app/controllers/admin_controller.rb
-
- The application stores and returns full social security numbers. The clear-text storage of this value within the database falls under <%= link_to "Insecure Cryptographic Storage", crypto_tutorials_path, {:style => "color: rgb(181, 121, 158)"}%>. However, the other failure here is that the application returns this full SSN value within the response for the user's Work Info page. Although a portion of the SSN value is obfuscated using JavaScript (when rendered in the browser), any attacker who has positioned themselves to sniff this traffic or read the user's browser cache can extract the full value from the source.
-
- A model method to return only the last four digits already exists. The following code was taken from the WorkInfo model - app/models/work_info.rb:
-
-
-
- <%= @good_code_1%>
-
-
-
- Essentially, this takes the SSN string from the DB, retrieves only the last four characters in the string, and concatenates the last four characters with asterisks. Because this occurs at the model level, the view page never calls the full SSN value and therefore the user's browser never receives the full SSN. The view code would need to change from...
-
-
-
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index 800d3d7..dac6707 100755
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -52,7 +52,6 @@ Railsgoat::Application.routes.draw do
get "ssl_tls"
get "redirects"
get "guard"
- get "info_disclosure"
get "mass_assignment"
get "constantize"
get "gauntlt"
diff --git a/spec/vulnerabilities/info_disclosure_spec.rb b/spec/vulnerabilities/sensitive_data_exposure.rb
similarity index 91%
rename from spec/vulnerabilities/info_disclosure_spec.rb
rename to spec/vulnerabilities/sensitive_data_exposure.rb
index ce0bd2a..bc1e72e 100644
--- a/spec/vulnerabilities/info_disclosure_spec.rb
+++ b/spec/vulnerabilities/sensitive_data_exposure.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-feature 'sensitive information disclosure' do
+feature 'sensitive data exposure' do
before do
UserFixture.reset_all_users
@normal_user = UserFixture.normal_user
From 3ec9765ca3f4f37fc33144b7bdf8275d9dcdcb57 Mon Sep 17 00:00:00 2001
From: Mike McCabe
Date: Thu, 14 Nov 2013 11:24:15 -0500
Subject: [PATCH 054/149] small update to A7
---
.../tutorial/access_control/_access_control_first.html.erb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/app/views/layouts/tutorial/access_control/_access_control_first.html.erb b/app/views/layouts/tutorial/access_control/_access_control_first.html.erb
index 832abb1..7dd02ed 100644
--- a/app/views/layouts/tutorial/access_control/_access_control_first.html.erb
+++ b/app/views/layouts/tutorial/access_control/_access_control_first.html.erb
@@ -66,13 +66,13 @@
Failure to Restrict URL Access - SOLUTION
- The code is already available to restrict access to the admin controller by role within app/controllers/application_controller.rb. The additional condition that if the admin_id param equals 1 means the filter can be circumvented by an attacker. The way to fix this issue is to enforce the filter on all access requests to the admin dashboard as follows:
+ The code is already available to restrict access to the admin controller by role within app/controllers/application_controller.rb. The additional condition that if the admin_id param equals 1 means the filter can be circumvented by an attacker. The way to fix this issue is to remove the conditional and enforce the filter on all access requests to the admin dashboard as follows:
From 0075ca7a9c7b61078732510a77729553e472a96b Mon Sep 17 00:00:00 2001
From: Mike McCabe
Date: Thu, 14 Nov 2013 12:32:53 -0500
Subject: [PATCH 056/149] lowering rack version for dos
---
Gemfile | 2 +-
Gemfile.lock | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/Gemfile b/Gemfile
index 219755b..74972e1 100755
--- a/Gemfile
+++ b/Gemfile
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
#don't upgrade
gem 'rails', '3.2.11'
-gem 'rack', '1.4.3'
+gem 'rack', '1.4.0'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
diff --git a/Gemfile.lock b/Gemfile.lock
index 4c937ea..0d34071 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -167,7 +167,7 @@ GEM
coderay (~> 1.0)
method_source (~> 0.8)
slop (~> 3.4)
- rack (1.4.3)
+ rack (1.4.0)
rack-cache (1.2)
rack (>= 0.4)
rack-livereload (0.3.15)
@@ -293,7 +293,7 @@ DEPENDENCIES
poltergeist
powder
pry
- rack (= 1.4.3)
+ rack (= 1.4.0)
rack-livereload
rails (= 3.2.11)
rb-fsevent
From 53dcc75f740e92c288480ffe3712ac4a58384546 Mon Sep 17 00:00:00 2001
From: cktricky
Date: Thu, 14 Nov 2013 15:05:00 -0500
Subject: [PATCH 057/149] I think there was a subtle bug in the intentional
security bypass within the admin controller
---
app/controllers/admin_controller.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb
index 1a671f7..d7efbdb 100755
--- a/app/controllers/admin_controller.rb
+++ b/app/controllers/admin_controller.rb
@@ -48,7 +48,7 @@ class AdminController < ApplicationController
private
def admin_param
- params[:id] == '1'
+ params[:admin_id] != '1'
end
end
From cae21708798bf39f043cde388fab998174585875 Mon Sep 17 00:00:00 2001
From: James Espinosa
Date: Thu, 14 Nov 2013 08:11:58 -0600
Subject: [PATCH 058/149] Remove unnecessary README.rdoc file
---
README.rdoc | 261 ----------------------------------------------------
1 file changed, 261 deletions(-)
delete mode 100755 README.rdoc
diff --git a/README.rdoc b/README.rdoc
deleted file mode 100755
index 3e1c15c..0000000
--- a/README.rdoc
+++ /dev/null
@@ -1,261 +0,0 @@
-== Welcome to Rails
-
-Rails is a web-application framework that includes everything needed to create
-database-backed web applications according to the Model-View-Control pattern.
-
-This pattern splits the view (also called the presentation) into "dumb"
-templates that are primarily responsible for inserting pre-built data in between
-HTML tags. The model contains the "smart" domain objects (such as Account,
-Product, Person, Post) that holds all the business logic and knows how to
-persist themselves to a database. The controller handles the incoming requests
-(such as Save New Account, Update Product, Show Post) by manipulating the model
-and directing data to the view.
-
-In Rails, the model is handled by what's called an object-relational mapping
-layer entitled Active Record. This layer allows you to present the data from
-database rows as objects and embellish these data objects with business logic
-methods. You can read more about Active Record in
-link:files/vendor/rails/activerecord/README.html.
-
-The controller and view are handled by the Action Pack, which handles both
-layers by its two parts: Action View and Action Controller. These two layers
-are bundled in a single package due to their heavy interdependence. This is
-unlike the relationship between the Active Record and Action Pack that is much
-more separate. Each of these packages can be used independently outside of
-Rails. You can read more about Action Pack in
-link:files/vendor/rails/actionpack/README.html.
-
-
-== Getting Started
-
-1. At the command prompt, create a new Rails application:
- rails new myapp (where myapp is the application name)
-
-2. Change directory to myapp and start the web server:
- cd myapp; rails server (run with --help for options)
-
-3. Go to http://localhost:3000/ and you'll see:
- "Welcome aboard: You're riding Ruby on Rails!"
-
-4. Follow the guidelines to start developing your application. You can find
-the following resources handy:
-
-* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
-* Ruby on Rails Tutorial Book: http://www.railstutorial.org/
-
-
-== Debugging Rails
-
-Sometimes your application goes wrong. Fortunately there are a lot of tools that
-will help you debug it and get it back on the rails.
-
-First area to check is the application log files. Have "tail -f" commands
-running on the server.log and development.log. Rails will automatically display
-debugging and runtime information to these files. Debugging info will also be
-shown in the browser on requests from 127.0.0.1.
-
-You can also log your own messages directly into the log file from your code
-using the Ruby logger class from inside your controllers. Example:
-
- class WeblogController < ActionController::Base
- def destroy
- @weblog = Weblog.find(params[:id])
- @weblog.destroy
- logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
- end
- end
-
-The result will be a message in your log file along the lines of:
-
- Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
-
-More information on how to use the logger is at http://www.ruby-doc.org/core/
-
-Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
-several books available online as well:
-
-* Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
-* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
-
-These two books will bring you up to speed on the Ruby language and also on
-programming in general.
-
-
-== Debugger
-
-Debugger support is available through the debugger command when you start your
-Mongrel or WEBrick server with --debugger. This means that you can break out of
-execution at any point in the code, investigate and change the model, and then,
-resume execution! You need to install ruby-debug to run the server in debugging
-mode. With gems, use sudo gem install ruby-debug. Example:
-
- class WeblogController < ActionController::Base
- def index
- @posts = Post.all
- debugger
- end
- end
-
-So the controller will accept the action, run the first line, then present you
-with a IRB prompt in the server window. Here you can do things like:
-
- >> @posts.inspect
- => "[#nil, "body"=>nil, "id"=>"1"}>,
- #"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
- >> @posts.first.title = "hello from a debugger"
- => "hello from a debugger"
-
-...and even better, you can examine how your runtime objects actually work:
-
- >> f = @posts.first
- => #nil, "body"=>nil, "id"=>"1"}>
- >> f.
- Display all 152 possibilities? (y or n)
-
-Finally, when you're ready to resume execution, you can enter "cont".
-
-
-== Console
-
-The console is a Ruby shell, which allows you to interact with your
-application's domain model. Here you'll have all parts of the application
-configured, just like it is when the application is running. You can inspect
-domain models, change values, and save to the database. Starting the script
-without arguments will launch it in the development environment.
-
-To start the console, run rails console from the application
-directory.
-
-Options:
-
-* Passing the -s, --sandbox argument will rollback any modifications
- made to the database.
-* Passing an environment name as an argument will load the corresponding
- environment. Example: rails console production.
-
-To reload your controllers and models after launching the console run
-reload!
-
-More information about irb can be found at:
-link:http://www.rubycentral.org/pickaxe/irb.html
-
-
-== dbconsole
-
-You can go to the command line of your database directly through rails
-dbconsole. You would be connected to the database with the credentials
-defined in database.yml. Starting the script without arguments will connect you
-to the development database. Passing an argument will connect you to a different
-database, like rails dbconsole production. Currently works for MySQL,
-PostgreSQL and SQLite 3.
-
-== Description of Contents
-
-The default directory structure of a generated Ruby on Rails application:
-
- |-- app
- | |-- assets
- | | |-- images
- | | |-- javascripts
- | | `-- stylesheets
- | |-- controllers
- | |-- helpers
- | |-- mailers
- | |-- models
- | `-- views
- | `-- layouts
- |-- config
- | |-- environments
- | |-- initializers
- | `-- locales
- |-- db
- |-- doc
- |-- lib
- | |-- assets
- | `-- tasks
- |-- log
- |-- public
- |-- script
- |-- test
- | |-- fixtures
- | |-- functional
- | |-- integration
- | |-- performance
- | `-- unit
- |-- tmp
- | `-- cache
- | `-- assets
- `-- vendor
- |-- assets
- | |-- javascripts
- | `-- stylesheets
- `-- plugins
-
-app
- Holds all the code that's specific to this particular application.
-
-app/assets
- Contains subdirectories for images, stylesheets, and JavaScript files.
-
-app/controllers
- Holds controllers that should be named like weblogs_controller.rb for
- automated URL mapping. All controllers should descend from
- ApplicationController which itself descends from ActionController::Base.
-
-app/models
- Holds models that should be named like post.rb. Models descend from
- ActiveRecord::Base by default.
-
-app/views
- Holds the template files for the view that should be named like
- weblogs/index.html.erb for the WeblogsController#index action. All views use
- eRuby syntax by default.
-
-app/views/layouts
- Holds the template files for layouts to be used with views. This models the
- common header/footer method of wrapping views. In your views, define a layout
- using the layout :default and create a file named default.html.erb.
- Inside default.html.erb, call <% yield %> to render the view using this
- layout.
-
-app/helpers
- Holds view helpers that should be named like weblogs_helper.rb. These are
- generated for you automatically when using generators for controllers.
- Helpers can be used to wrap functionality for your views into methods.
-
-config
- Configuration files for the Rails environment, the routing map, the database,
- and other dependencies.
-
-db
- Contains the database schema in schema.rb. db/migrate contains all the
- sequence of Migrations for your schema.
-
-doc
- This directory is where your application documentation will be stored when
- generated using rake doc:app
-
-lib
- Application specific libraries. Basically, any kind of custom code that
- doesn't belong under controllers, models, or helpers. This directory is in
- the load path.
-
-public
- The directory available for the web server. Also contains the dispatchers and the
- default HTML files. This should be set as the DOCUMENT_ROOT of your web
- server.
-
-script
- Helper scripts for automation and generation.
-
-test
- Unit and functional tests along with fixtures. When using the rails generate
- command, template test files will be generated for you and placed in this
- directory.
-
-vendor
- External libraries that the application depends on. Also includes the plugins
- subdirectory. If the app has frozen rails, those gems also go here, under
- vendor/rails/. This directory is in the load path.
From 64bdc001611bee0ba7da8d7765f7d42b4331957a Mon Sep 17 00:00:00 2001
From: James Espinosa
Date: Thu, 14 Nov 2013 08:13:58 -0600
Subject: [PATCH 059/149] Add minor changes to README.md file
---
README.md | 121 +++++++++++++++++++++++++++++++-----------------------
1 file changed, 69 insertions(+), 52 deletions(-)
diff --git a/README.md b/README.md
index 10fe978..ad52e61 100755
--- a/README.md
+++ b/README.md
@@ -1,78 +1,95 @@
-## Getting Started ##
-#### With Ruby, Rubygems, Git, and Bundler installed ####
+# RailsGoat [](https://travis-ci.org/OWASP/railsgoat) [](https://codeclimate.com/github/OWASP/railsgoat)
- git clone https://github.com/OWASP/railsgoat.git
+RailsGoat is a vulnerable version of the Ruby on Rails Framework. It includes vulnerabilities from the OWASP Top 10, as well as some "extras" that the initial project contributors felt worthwhile to share. This project is designed to educate both developers, as well as security professionals.
- cd railsgoat
+## Getting Started
- rvm use 1.9.3@railsgoat --create # https://rvm.io/
+Requirements: **Ruby 1.9.3**
- bundle
+To begin, install the Ruby Version Manager (RVM):
- rake db:setup
+```
+$ curl -L https://get.rvm.io | bash -s stable --autolibs=3 --ruby=1.9.3
+```
- rails s
+After installing the package, clone this repo:
- open http://0.0.0.0:3000
+```
+$ git clone git@github.com:OWASP/railsgoat.git
+```
- Start hacking!!!
+Navigate into the directory and accept the notice by typing `yes`:
+```
+*****************************************************************************************************
+* NOTICE *
+*****************************************************************************************************
+* RVM has encountered a new or modified .rvmrc file in the current directory, this is a shell *
+* script and therefore may contain any shell commands. *
+* *
+* Examine the contents of this file carefully to be sure the contents are safe before trusting it! *
+* Do you wish to trust '/path/to/railsgoat/.rvmrc'? *
+* Choose v[view] below to view the contents *
+*****************************************************************************************************
+y[es], n[o], v[iew], c[cancel]>
+```
-### Running Capybara Tests ###
+Install the project dependencies:
-RailsGoat now includes a set of _failing_ Capybara RSpecs, each one indicating a separate vulnerability exists
-in the application.
+```
+$ bundle install
+```
-To run them, though, you'll first need to [install PhantomJS](https://github.com/jonleighton/poltergeist#installing-phantomjs),
-which is required by the Poltergeist Capybara driver. Then just rake:
+If you receive an error, make sure you have `bundler` installed:
- rake training
+```
+$ gem install bundler
+```
-NOTE: As vulnerabilities are fixed in the application, these specs won't change from to passing but to _pending_.
+Initialize the database:
-### Developer Note ###
+```
+$ rake db:setup
+```
-As changes are made to the application, the Capybara RSpecs can be used to verify the vulnerabilities
-in the application are still intact. To use them in this way, and have them _pass_ instead of fail,
-set the `RAILSGOAT_MAINTAINER` environment variable.
+Start the WEBrick HTTP Server:
-
-Conversion to the OWASP Top 10, 2013 is under way.
+```
+$ rails server
+```
-You can view progress within the top-10-2013 branch.
+Open your favorite browser, navigate to `http://localhost:3000` and start hacking!
+
+## Capybara Tests
+
+RailsGoat now includes a set of failing Capybara RSpecs, each one indicating that a separate vulnerability exists in the application. To run them, you first need to install [PhantomJS](https://github.com/jonleighton/poltergeist#installing-phantomjs), which is required by the Poltergeist Capybara driver. Upon installation, simply run the following rake task:
+
+```
+$ rake training
+```
+
+Please note, as vulnerabilities are fixed in the application, these specs will not change to `passing`, but to `pending`.
+
+## Contributing
+
+As changes are made to the application, the Capybara RSpecs can be used to verify that the vulnerabilities in the application are still intact. To use them in this way, and have them `pass` instead of `fail`, set the `RAILSGOAT_MAINTAINER` environment variable.
+
+Conversion to the OWASP Top 10, 2013 is under way. You can view progress within the `top-10-2013` branch.
+
+```
+$ git fetch origin
+$ git checkout top-10-2013
+```
- git fetch origin
- git checkout top-10-2013
Then proceed with browsing the site as normal :thumbsup:
-
-### Build Info ###
-
-[](https://codeclimate.com/github/OWASP/railsgoat)
-
-[](https://travis-ci.org/OWASP/railsgoat)
-
-### License Stuff ###
+# License
The MIT License (MIT)
-Copyright (c) 2013 The Open Web Application Security Project
+Copyright (c) 2013 The Open Web Application Security Project
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-
-
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
From 69078aa4048f0261ed7aca79fd5dce5ffe7619a9 Mon Sep 17 00:00:00 2001
From: James Espinosa
Date: Thu, 14 Nov 2013 13:37:56 -0600
Subject: [PATCH 060/149] Add minor text and typo changes
---
README.md | 22 +++++++++++-----------
spec/support/capybara_shared.rb | 23 +++++++++++------------
2 files changed, 22 insertions(+), 23 deletions(-)
diff --git a/README.md b/README.md
index ad52e61..680cbd0 100755
--- a/README.md
+++ b/README.md
@@ -20,16 +20,16 @@ $ git clone git@github.com:OWASP/railsgoat.git
Navigate into the directory and accept the notice by typing `yes`:
```
-*****************************************************************************************************
-* NOTICE *
-*****************************************************************************************************
-* RVM has encountered a new or modified .rvmrc file in the current directory, this is a shell *
-* script and therefore may contain any shell commands. *
-* *
-* Examine the contents of this file carefully to be sure the contents are safe before trusting it! *
-* Do you wish to trust '/path/to/railsgoat/.rvmrc'? *
-* Choose v[view] below to view the contents *
-*****************************************************************************************************
+****************************************************************************************************
+* NOTICE *
+****************************************************************************************************
+* RVM has encountered a new or modified .rvmrc file in the current directory, this is a shell *
+* script and therefore may contain any shell commands. *
+* *
+* Examine the contents of this file carefully to be sure the contents are safe before trusting it! *
+* Do you wish to trust '/path/to/railsgoat/.rvmrc'? *
+* Choose v[view] below to view the contents *
+****************************************************************************************************
y[es], n[o], v[iew], c[cancel]>
```
@@ -67,7 +67,7 @@ RailsGoat now includes a set of failing Capybara RSpecs, each one indicating tha
$ rake training
```
-Please note, as vulnerabilities are fixed in the application, these specs will not change to `passing`, but to `pending`.
+NOTE: As vulnerabilities are fixed in the application, these specs will not change to `passing`, but to `pending`.
## Contributing
diff --git a/spec/support/capybara_shared.rb b/spec/support/capybara_shared.rb
index 8606ce4..a0866c6 100644
--- a/spec/support/capybara_shared.rb
+++ b/spec/support/capybara_shared.rb
@@ -15,20 +15,19 @@ def verifying_fixed?
******************************************************************************
You are running the RailsGoat Capybara Specs in Training mode. These specs
- are supposed to fail, indicating vulnerabilities exist. They contain
- spoilers, so do not read the code in spec/vulnerabilities if your goal is to
- learn more about patching the vulnerabilities. You should fix the
- vulnerabilities in the application in order to get these specs to pass**.
- You can use them to measure your progress.
+ are supposed to fail, indicating vulnerabilities exist. They contain spoilers,
+ so do not read the code in spec/vulnerabilities if your goal is to learn more
+ about patching the vulnerabilities. You should fix the vulnerabilities in the
+ application in order to get these specs to pass**. You can use them to measure
+ your progress.
- These same specs will pass if you set the #{maintainer_env_name} ENV
- variable.
+ These same specs will pass if you set the #{maintainer_env_name} ENV variable.
+
+ **NOTE: The RSpec pending feature is used to toggle the outcome of these specs
+ between Training mode and RailsGoat Maintainer mode. When the vulnerabilities
+ are removed, the specs will not "pass," but rather go into a "pending" state.
+ ******************************************************************************
- **NOTE: The RSpec pending feature is used to toggle the outcome of these
- specs between Training mode and RailsGoat Maintainer mode, so when the
- vulnerabilities are removed, these specs actually won't 'pass' but go into
- a 'pending' state.
-******************************************************************************
NOTICE
$displayed_spec_notice = true
end
From ab22759bbf5e436c397c93c4c64e769cff46e948 Mon Sep 17 00:00:00 2001
From: Al Snow
Date: Mon, 18 Nov 2013 11:13:34 -0500
Subject: [PATCH 061/149] Rebuilt Gemfile.lock file
---
Gemfile.lock | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/Gemfile.lock b/Gemfile.lock
index 0d34071..991949d 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -29,7 +29,7 @@ GEM
i18n (~> 0.6)
multi_json (~> 1.0)
addressable (2.3.5)
- arel (3.0.2)
+ arel (3.0.3)
aruba (0.5.3)
childprocess (>= 0.3.6)
cucumber (>= 1.1.1)
@@ -73,7 +73,7 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.6.3)
- cucumber (1.3.9)
+ cucumber (1.3.10)
builder (>= 2.1.2)
diff-lcs (>= 1.1.3)
gherkin (~> 2.12)
@@ -103,7 +103,7 @@ GEM
trollop
gherkin (2.12.2)
multi_json (~> 1.3)
- guard (2.2.3)
+ guard (2.2.4)
formatador (>= 0.2.4)
listen (~> 2.1)
lumberjack (~> 1.0)
@@ -119,7 +119,7 @@ GEM
guard-rspec (4.0.4)
guard (>= 2.1.1)
rspec (~> 2.14)
- guard-shell (0.5.1)
+ guard-shell (0.5.2)
guard (>= 1.1.0)
haml (4.0.4)
tilt
@@ -234,7 +234,7 @@ GEM
slim (2.0.2)
temple (~> 0.6.6)
tilt (>= 1.3.3, < 2.1)
- slop (3.4.6)
+ slop (3.4.7)
sprockets (2.2.2)
hike (~> 1.2)
multi_json (~> 1.0)
From 209d2440a82a7d096e5a8cc0f5cb86e8dfb4f161 Mon Sep 17 00:00:00 2001
From: Al Snow
Date: Sat, 23 Nov 2013 16:00:32 -0500
Subject: [PATCH 062/149] Upgrade .rvmrc to 1.9.3-p484; Rebuilt Gemfile.lock
file
---
.rvmrc | 2 +-
Gemfile.lock | 1 -
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/.rvmrc b/.rvmrc
index bf053af..d816235 100755
--- a/.rvmrc
+++ b/.rvmrc
@@ -1 +1 @@
-rvm use 1.9.3@railsgoat --create
+rvm use 1.9.3-p484@railsgoat --create
diff --git a/Gemfile.lock b/Gemfile.lock
index 991949d..7551790 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -97,7 +97,6 @@ GEM
thor (>= 0.13.6)
formatador (0.2.4)
gauntlt (1.0.6)
- aruba
cucumber
nokogiri (~> 1.5.0)
trollop
From c7515af6ab6d014e0d1d22687212f68b7d5b6d5d Mon Sep 17 00:00:00 2001
From: Mike McCabe
Date: Sat, 23 Nov 2013 16:04:48 -0500
Subject: [PATCH 063/149] adding basic forgot password controller and views
---
app/controllers/users_controller.rb | 26 +++++++++++++++++++-
app/views/sessions/new.html.erb | 1 +
app/views/users/forgot_password.html.erb | 30 ++++++++++++++++++++++++
config/routes.rb | 1 +
4 files changed, 57 insertions(+), 1 deletion(-)
create mode 100644 app/views/users/forgot_password.html.erb
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 665c12c..81a0e52 100755
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -1,7 +1,19 @@
+require
class UsersController < ApplicationController
skip_before_filter :has_info
- skip_before_filter :authenticated, :only => [:new, :create]
+ skip_before_filter :authenticated, :only => [:new, :create, :forgot_password]
+
+ def forgot_password
+ @user = User.find_by_email(params[:email]) unless params[:email].nil?
+
+ if @user && password_reset_mailer_setup(@user)
+ flash[:success] = "Password reset email sent to #{params[:email]}"
+ redirect_to :login
+ else
+ flash[:error] = "There was an issue sending password reset email to #{params[:email]}".html_safe unless params[:email].nil?
+ end
+ end
def new
@user = User.new
@@ -52,4 +64,16 @@ class UsersController < ApplicationController
end
end
+ private
+
+ def password_reset_mailer_setup(user)
+ token = generate_token(user.id, user.email)
+ #reset_password_mailer(user.email, token)
+ end
+
+ def generate_token(id, email)
+ hash = Digest::MD5.hexdigest(email)
+ "#{id}~#{hash}"
+ end
+
end
\ No newline at end of file
diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb
index 481763a..a7c9932 100755
--- a/app/views/sessions/new.html.erb
+++ b/app/views/sessions/new.html.erb
@@ -22,6 +22,7 @@
\ No newline at end of file
diff --git a/app/views/users/forgot_password.html.erb b/app/views/users/forgot_password.html.erb
index 81c54ec..cd4616d 100644
--- a/app/views/users/forgot_password.html.erb
+++ b/app/views/users/forgot_password.html.erb
@@ -1,30 +1,32 @@
-
MetaCorp
-
A GoatGroup Company
+
MetaCorp
+
A GoatGroup Company
-
-
-
- <%= form_tag "forgot_password", :class=> "signup-wrapper" do %>
-
+
+
-
Forgot Password
-
Fill out the form below to reset your password.
-
+
+ <%= form_tag "forgot_password", :class=> "signup-wrapper" do %>
-
\ No newline at end of file
diff --git a/app/views/user_mailer/forgot_password.html.erb b/app/views/user_mailer/forgot_password.html.erb
index a9f5913..ca2fe76 100644
--- a/app/views/user_mailer/forgot_password.html.erb
+++ b/app/views/user_mailer/forgot_password.html.erb
@@ -6,8 +6,17 @@
Need help logging in?
- To reset your RailsGoat password, simply click on the
- following link and follow the instructions: <%= @token %>.
+ A password reset was requested for your user account.
+
+
+ To reset your MetaCorp password, simply click on the
+ following link and follow the instructions:
+
+
+ <%= link_to "Click here to reset your password", @url %>
+
+
+ If you don't want to change your password, you can ignore this email.
Thanks, and have a great day!
diff --git a/app/views/user_mailer/forgot_password.text.erb b/app/views/user_mailer/forgot_password.text.erb
index cdc672e..92067db 100644
--- a/app/views/user_mailer/forgot_password.text.erb
+++ b/app/views/user_mailer/forgot_password.text.erb
@@ -1,7 +1,13 @@
Need help logging in?
==========================================================
-To reset your RailsGoat password, simply click on the
-following link and follow the instructions: <%= @token %>.
+A password reset was requested for your user account.
+
+To reset your MetaCorp password, simply copy the
+following link and follow the instructions:
+
+<%= @url %>
+
+If you don't want to change your password, you can ignore this email.
Thanks, and have a great day!
\ No newline at end of file
diff --git a/app/views/users/forgot_password.html.erb b/app/views/users/forgot_password.html.erb
index 6e7408a..be3d8a3 100644
--- a/app/views/users/forgot_password.html.erb
+++ b/app/views/users/forgot_password.html.erb
@@ -19,7 +19,7 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index 2383276..6dfde00 100755
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -58,6 +58,7 @@ Railsgoat::Application.routes.draw do
get "mass_assignment"
get "constantize"
get "gauntlt"
+ get "logic_flaws"
end
end
From e49b43f89996dcafa3f512bd97813379081e3e87 Mon Sep 17 00:00:00 2001
From: cktricky
Date: Wed, 12 Mar 2014 20:28:59 -0400
Subject: [PATCH 122/149] added the verbose model attributes finding under the
exposure section within the tutorials
---
.../_model_attributes_exposure.html.erb | 144 ++++++++++++++++++
app/views/tutorials/exposure.html.erb | 6 +
2 files changed, 150 insertions(+)
create mode 100644 app/views/layouts/tutorial/exposure/_model_attributes_exposure.html.erb
diff --git a/app/views/layouts/tutorial/exposure/_model_attributes_exposure.html.erb b/app/views/layouts/tutorial/exposure/_model_attributes_exposure.html.erb
new file mode 100644
index 0000000..a5d4dd0
--- /dev/null
+++ b/app/views/layouts/tutorial/exposure/_model_attributes_exposure.html.erb
@@ -0,0 +1,144 @@
+
+
+
+ A6 - Sensitive Data Exposure - Model Attributes Exposure
+
+ The application's API returns a model object (user or users). Using respond_with, the API returns the full model object. It is simple but exposes information such as the user's password and other user attributes that you may wish to keep invisible.
+
+ Within app/controllers/api/v1/users_controller.rb:
+
+
+ def index
+ # We removed the .as_json code from the model, just seemed like extra work.
+ # dunno, maybe useful at a later time?
+ #respond_with @user.admin ? User.all.as_json : @user.as_json
+
+ respond_with @user.admin ? User.all : @user
+ end
+
+ def show
+ respond_with @user.as_json
+ end
+
+
+ The as_json method referenced in the comments section of the index action exists within the user model in order to override and safely protect our model from only rendering certain attributes. It is unused (commented out), app/models/user.rb:
+
+
+ # Instead of the entire user object being returned, we can use this to filter.
+ def as_json
+ super(only: [:user_id, :email, :first_name, :last_name])
+ end
+
+
+ When utilizing the method that most tutorials describe or advocate when rendering model objects via JSON in an API (unsafe), the response looks like this:
+
Use the API and review the data returned. Additional information on exploiting the API available under the Extras > Logic Flaws Section.
+
Model Attributes Exposure - SOLUTION
+
+ Uncomment the as_json method within the user model. Additionally, call .as_json on any User model object you would like to return via the API or other means. Example:
+
+ Upon uncommenting the as_json method within the User model, the as_json method will ensure the API output only returns those attributes you have allowed in the following code:
+
+
\ No newline at end of file
diff --git a/config/environments/development.rb b/config/environments/development.rb
index 39b0f53..9ff11cf 100755
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -28,6 +28,9 @@ Railsgoat::Application.configure do
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
+
+ # Tired of caching causing issues
+ config.middleware.delete Rack::ETag
# Do not compress assets
config.assets.compress = false
From 3a5818c493e406935dbe3cb6caa286503a3cfe69 Mon Sep 17 00:00:00 2001
From: cktricky
Date: Sat, 15 Mar 2014 22:30:31 -0400
Subject: [PATCH 136/149] the basics of a working remember-me-logic-flaw
completed :-)
---
app/controllers/pay_controller.rb | 12 +++++++++++-
app/models/pay.rb | 2 +-
app/views/pay/index.html.erb | 27 +++++++++------------------
3 files changed, 21 insertions(+), 20 deletions(-)
diff --git a/app/controllers/pay_controller.rb b/app/controllers/pay_controller.rb
index b7ca2d5..30368f1 100644
--- a/app/controllers/pay_controller.rb
+++ b/app/controllers/pay_controller.rb
@@ -13,7 +13,7 @@ class PayController < ApplicationController
pay.user_id = current_user.user_id
msg = true if pay.save!
respond_to do |format|
- format.json {render :json => {:msg => :world} }
+ format.json {render :json => {:msg => msg } }
end
end
@@ -23,4 +23,14 @@ class PayController < ApplicationController
end
end
+ def destroy
+ pay = Pay.find_by_id(params[:id])
+ if pay.present? and pay.destroy
+ flash[:success] = "Successfully Deleted Entry"
+ else
+ flash[:error] = "Unable to process that request at this time"
+ end
+ redirect_to user_pay_index_path
+ end
+
end
diff --git a/app/models/pay.rb b/app/models/pay.rb
index a1ee601..74116a3 100644
--- a/app/models/pay.rb
+++ b/app/models/pay.rb
@@ -15,7 +15,7 @@ class Pay < ActiveRecord::Base
before_save :encrypt_bank_account_num
def as_json
- super(only: [:bank_account_num, :bank_routing_num, :percent_of_deposit])
+ super(only: [:bank_account_num, :bank_routing_num, :percent_of_deposit, :id])
end
def encrypt_bank_account_num
diff --git a/app/views/pay/index.html.erb b/app/views/pay/index.html.erb
index c9bb2e9..74c6a8a 100644
--- a/app/views/pay/index.html.erb
+++ b/app/views/pay/index.html.erb
@@ -97,23 +97,7 @@
-
+
@@ -132,6 +116,13 @@
\ No newline at end of file
From d11617f2720451a0c016c4db86f736506da32fab Mon Sep 17 00:00:00 2001
From: cktricky
Date: Sun, 16 Mar 2014 16:10:12 -0400
Subject: [PATCH 139/149] while the pay page could use further refinement from
a visual aspect, it is completely working and ready for a tutorial
---
app/views/pay/index.html.erb | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/app/views/pay/index.html.erb b/app/views/pay/index.html.erb
index 324a108..3895d4b 100644
--- a/app/views/pay/index.html.erb
+++ b/app/views/pay/index.html.erb
@@ -82,13 +82,18 @@
-
- Bank Account Number
+
+ Encrypted Bank Account Number
+ <%=link_to "#", { :style => "color:#AA6F93", :id => "encrypted_acct_question"} do %>
+
+
+
+ <% end %>
Bank Routing Number
-
+
Percentage of Deposit
@@ -267,6 +272,14 @@ $("#dd_form_btn").click(function(event) {
});
});
+$("#encrypted_acct_question").click(function(event) {
+ event.preventDefault();
+ alert("For your safety your account number is stored encrypted as well as presented to you \nin an encrypted form.\n\n" +
+ "For your convenience, you can decrypt your bank account number at any time using our\n" +
+ "conveniently located decryption function."
+ )
+});
+
/*
Make the sidebar element "Pay" active.
*/
From 8140cb3a1b834346a47ede4aec02490e459d0063 Mon Sep 17 00:00:00 2001
From: cktricky
Date: Sun, 16 Mar 2014 16:19:07 -0400
Subject: [PATCH 140/149] added the basic template of a tutorial guide for the
newly added logic flaw, now I have to fill it out :-( (j/k)
---
.../_insecure_crypto_reuse.html.erb | 70 +++++++++++++++++++
app/views/tutorials/logic_flaws.html.erb | 5 ++
2 files changed, 75 insertions(+)
create mode 100644 app/views/layouts/tutorial/logic_flaws/_insecure_crypto_reuse.html.erb
diff --git a/app/views/layouts/tutorial/logic_flaws/_insecure_crypto_reuse.html.erb b/app/views/layouts/tutorial/logic_flaws/_insecure_crypto_reuse.html.erb
new file mode 100644
index 0000000..d7ce9f3
--- /dev/null
+++ b/app/views/layouts/tutorial/logic_flaws/_insecure_crypto_reuse.html.erb
@@ -0,0 +1,70 @@
+
+ The Railsgoat application allows employees of Metacorp to choose the Remember Me option at login, which creates a cookie named auth-token. The encryption routine used to generate the auth-token allows the application to extract a user ID. When decrypted, a user ID is extracted and the user is authorized appropriately. This same encryption routine is used elsewhere in the application in a manner such that a clever attacker can generate an auth_token cookie with whatever user ID they prefer and authorize to the application as a different user.
+
@@ -30,7 +32,63 @@
- insert bug info
+
+ Within the file lib/encryption.rb, there are two encryption related methods that we have exposed:
+
+
+ # Added a re-usable encryption routine, shouldn't be an issue!
+ def self.encrypt_sensitive_value(val="")
+ aes = OpenSSL::Cipher::Cipher.new(cipher_type)
+ aes.encrypt
+ aes.key = key
+ aes.iv = iv if iv != nil
+ new_val = aes.update("#{val}") + aes.final
+ Base64.strict_encode64(new_val).encode('utf-8')
+ end
+
+ def self.decrypt_sensitive_value(val="")
+ aes = OpenSSL::Cipher::Cipher.new(cipher_type)
+ aes.decrypt
+ aes.key = key
+ aes.iv = iv if iv != nil
+ decoded = Base64.strict_decode64("#{val}")
+ aes.update("#{decoded}") + aes.final
+ end
+
+
+ We have placed this code under the lib directory so that we have a re-usable encryption routine. This code is used to generate a user's auth_token cookie responsible for authorization and access. However, we've also used this same code when encrypting a user's bank account number. This means, a user can enter in any value they would like and will receive it's encrypted equivalent back from the application. Essentially, a user has the ability to generate the auth_token cookie for any user ID and authorize as that user.
+ Within the app/models/pay.rb file we have a before hook that will save a user's bank account number as an encrypted value:
+
+ Additionally, we render that encrypted value (purposefully) when the show action is created within the app/controllers/pay_controller.rb file:
+
+
+ def show
+ respond_to do |format|
+ format.json { render :json => {:user => current_user.pay.as_json} }
+ end
+ end
+
+
+ Lastly, we re-use this same routine within the following code is used to create a user's auth_token cookie upon sign-up or creation (app/models/user.rb):
+
+
+ before_create { generate_token(:auth_token) }
+
+ def generate_token(column)
+ begin
+ self[column] = Encryption.encrypt_sensitive_value(self.user_id)
+ end while User.exists?(column => self[column])
+ end
+
@@ -45,9 +103,13 @@
Insecure Encryption Re-use ATTACK:
- insert attack
+
+ Navigate to the Pay section of the application. Enter your bank account number but use the number 1 as your bank account number. Once the information is entered and submitted, you'll see the encrypted value of your bank account number (1) returned. URL encode the special characters (+ and ==) and use this value as your auth_token cookie. Navigate to your dashboard and you'll have the ability to access administrative functionality.
+
Insecure Encryption Re-use SOLUTION:
- insert solution
+
+ Create an entirely new encryption routine or create the SHA1 hash with a different salt.
+
@@ -61,7 +123,7 @@
- insert hint
+ My "Remember Me" cookie looks familiar, almost like one of those values you get when you enter your bank account number.