finished the first instance of broken auth and sess mgmt

This commit is contained in:
Ken Johnson
2013-05-23 20:06:24 -04:00
parent c71ef0ccfd
commit dbbb2ce651
4 changed files with 37 additions and 6 deletions
+3
View File
@@ -6,6 +6,7 @@ class SessionsController < ApplicationController
redirect_to home_dashboard_index_path if current_user redirect_to home_dashboard_index_path if current_user
end end
def create def create
begin begin
@@ -17,6 +18,8 @@ class SessionsController < ApplicationController
session[:id] = user.id if User.where(:id => user.id).exists? session[:id] = user.id if User.where(:id => user.id).exists?
redirect_to home_dashboard_index_path redirect_to home_dashboard_index_path
else else
# Removed this code, just doesn't seem specific enough!
# flash[:error] = "Either your username and password is incorrect"
flash[:error] = e.message flash[:error] = e.message
render "new" render "new"
end end
+3 -2
View File
@@ -9,6 +9,7 @@ class User < ActiveRecord::Base
validates_uniqueness_of :email validates_uniqueness_of :email
validates_format_of :email, :with => /.+@.+\..+/i validates_format_of :email, :with => /.+@.+\..+/i
def self.authenticate(email, password) def self.authenticate(email, password)
auth = nil auth = nil
user = find_by_email(email) user = find_by_email(email)
@@ -23,6 +24,6 @@ class User < ActiveRecord::Base
raise "#{email} doesn't exist!" raise "#{email} doesn't exist!"
end end
return auth return auth
end end
end end
@@ -90,7 +90,31 @@
</div> </div>
<div class="accordion-body collapse" id="collapseThree" style="height: 0px;"> <div class="accordion-body collapse" id="collapseThree" style="height: 0px;">
<div class="accordion-inner"> <div class="accordion-inner">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor <p>
<b> Username and Password Enumeration - SOLUTION</b>
</p>
<p> Within /app/controllers/sessions_controller.rb</p>
<pre class="ruby">
def create
begin
user = User.authenticate(params[:email], params[:password])
rescue Exception => e
end
if user
session[:id] = user.id if User.where(:id => user.id).exists?
redirect_to home_dashboard_index_path
else
flash[:error] = "Either your username and password is incorrect" #e.message
render "new"
end
end
</pre>
<p class="desc">
Although this fix is neither systemic nor does it address the problematic code at its core (within the user model), it does provide a quick solution. On line 12, we comment out the "e.message code" and instead provide a very generic error message that lacks specificity on what credential was incorrectly entered.
</p>
</div> </div>
</div> </div>
</div> </div>
@@ -104,8 +128,11 @@
</div> </div>
<div class="accordion-body collapse" id="collapseFour" style="height: 0px;"> <div class="accordion-body collapse" id="collapseFour" style="height: 0px;">
<div class="accordion-inner"> <div class="accordion-inner">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor <p class="desc">
</div> Enter an email address that wouldn't likely exist into the login form. Analyze the result.<br/><br/>
Can you leverage this to gain unauthorized access?
</p>
</div>
</div> </div>
</div> </div>
</div> </div>
@@ -31,7 +31,7 @@
<div class="accordion-body collapse" id="collapseTwo" style="height: 0px;"> <div class="accordion-body collapse" id="collapseTwo" style="height: 0px;">
<div class="accordion-inner"> <div class="accordion-inner">
<p><b>Cross-Site Request Forgery (CSRF) - The following code was taken from: /app/controllers/application_controller.rb and /app/views/layouts/application.html.erb</b></p> <p><b>Cross-Site Request Forgery (CSRF) - The following code was taken from: /app/controllers/application_controller.rb and /app/views/layouts/application.html.erb</b></p>
<p>application_controller.rb<<p> <p>application_controller.rb<p>
<p> <p>
<pre class="ruby"> <pre class="ruby">
# Our security guy keep talking about sea-surfing, cool story bro. # Our security guy keep talking about sea-surfing, cool story bro.