Seguridad en aplicaciones Web
-
Upload
ernesto-jimenez -
Category
Technology
-
view
11.028 -
download
6
description
Transcript of Seguridad en aplicaciones Web
![Page 2: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/2.jpg)
Sobre esta charla
![Page 3: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/3.jpg)
¿De qué vamos a hablar?
![Page 4: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/4.jpg)
SQL Injections
![Page 5: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/5.jpg)
class User < ActiveRecord::Base def self.authenticate(login, password) return User.find(:first, :conditions => "login = '#{login}' AND crypted_password = '#{encrypt(password)}'") endend
User.authenticate("blabla' OR 'x' = 'x') OR ('x' = 'x", 'lo_que_sea')# => SELECT * FROM users WHERE (login = 'blabla' OR 'x' = 'x') OR ('x' = 'x' AND crypted_password = '4123oijsjdir32josidjr032') LIMIT 1;
User.authenticate("blabla' OR admin = 1) OR ('x' = 'x", 'lo_que_sea')# => SELECT * FROM users WHERE (login = 'blabla' OR admin = 1) OR ('x' = 'x' AND crypted_password = '4123oijsjdir32josidjr032') LIMIT 1;
SQL Injections
![Page 6: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/6.jpg)
SQL Injectionsclass User < ActiveRecord::Base def self.authenticate(login, password) return User.find(:first, :conditions => [ "login = ? AND crypted_password = ?", login, encrypt(password) ]) endend
class User < ActiveRecord::Base def self.authenticate(login, password) return User.find(:first, :conditions => { :login => login, :crypted_password => encrypt(password) }) endend
![Page 7: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/7.jpg)
:conditions => “x = #{x}”deja que Rails escape los parámetros de las consultas
![Page 8: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/8.jpg)
Asignación masiva
![Page 9: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/9.jpg)
Asignación masivaclass UsersController < ApplicationController def create @user = User.create(params[:user]) endend
<% from_for :user, :url => users_path do |f| %> <label>email: <%= f.text_field :email %> </label> <label>password: <%= f.text_field :password %> </label> <%= submit_tag 'Registrarse' %><% end %>
![Page 10: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/10.jpg)
Asignación masivaclass UsersController < ApplicationController def create @user = User.create(params[:user]) endend
![Page 11: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/11.jpg)
Asignación masivaclass UsersController < ApplicationController def create @user = User.create(params[:user]) endend
post :create, :user => { :email => '[email protected]', :password => 'xxxx'}# => Usuario creado con los parámetros del formulario
post :create, :user => { :email => '[email protected]', :password => 'xxxx', :admin => true}# => Escalada de privilegios!
![Page 12: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/12.jpg)
Asignación masivaclass User < ActiveRecord::Base has_many :postsend
class Post < ActiveRecord::Base belongs_to :userend
post :create, :user => { :email => '[email protected]', :password => 'xxxx', :post_ids => [1,2,3]}# => Se proclama autor de los posts 1, 2 y 3!
![Page 13: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/13.jpg)
Asignación masivaclass User < ActiveRecord::Base attr_protected :adminend
user = User.new( :email => '[email protected]', :password => 'xxxx', :admin => true)user.admin # => falseuser.attributes = { :email => '[email protected]', :admin => true }user.admin # => false
user.admin = trueuser.admin # => true
![Page 14: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/14.jpg)
Asignación masivaclass User < ActiveRecord::Base attr_accessible :email, :passwordend
user = User.new( :email => '[email protected]', :password => 'xxxx', :admin => true)user.admin # => falseuser.attributes = { :email => '[email protected]', :admin => true }user.admin # => false
user.admin = trueuser.admin # => true
![Page 15: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/15.jpg)
attr_protectedattr_accessible
no introduzcas vulnerabilidades por olvidos
![Page 16: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/16.jpg)
Cross Site Scripting
![Page 17: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/17.jpg)
Cross Site Scripting<div class="comentario"> <%= @comment.body %></div>
post :create, :comment => { :body => "<script> /* Javascript malintencionado */</script>" }# => <div class="comment"> <script> /* Javascript malintencionado */ </script> </div>
![Page 18: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/18.jpg)
Cross Site Scripting<div class="comentario"> <%= sanitize @comment.body %></div>
post :create, :comment => { :body => "<script> /* Javascript malintencionado */</script>" }# => <div class="comment"> <script> /* Javascript malintencionado */ </script> </div>
![Page 19: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/19.jpg)
Cross Site Scripting<div class="comentario"> <%=h @comment.body %></div>
post :create, :comment => { :body => "<script> /* Javascript malintencionado */</script>" }# => <div class="comment"> <script> /* Javascript malintencionado */ </script> </div>
![Page 20: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/20.jpg)
sanitizeFunciona con listas negras y no lo detecta todo
![Page 21: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/21.jpg)
hbueeeeno, pero... ¿qué pasa si te olvidas uno?
¡¡¡es muy fácil olvidarse una letra!!!
![Page 22: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/22.jpg)
sanitiza antes de guardar
![Page 23: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/23.jpg)
Cross Site Request Forgery
![Page 24: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/24.jpg)
Cross Site Request Forgery<img src=”http://web.com/nuevo_pass?pass=robado” />
![Page 25: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/25.jpg)
Cross Site Request ForgeryNo es un problema en Rails 2.0
![Page 26: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/26.jpg)
Accesos no autorizados
![Page 27: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/27.jpg)
Accesos no autorizadosclass DraftsController < ApplicationController def show @draft = Draft.find(params[:id]) end
def destroy @draft = Draft.destroy(params[:id]) endend
# => Cualquier usuario puede ver y eliminar los borradores
![Page 28: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/28.jpg)
Accesos no autorizadosclass DraftsController < ApplicationController def show @draft = current_user.drafts.find(params[:id]) end
def destroy @draft = current_user.drafts.destroy(params[:id]) endend
# => Solo el autor del borrador puede verlos y borrarlos
![Page 29: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/29.jpg)
Acciones públicas
![Page 30: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/30.jpg)
Acciones públicas# Ejemplo muy chorra :)class UsersController < ApplicationController def invite current_user.invitations.create(params[:email],) send_email end def send_email UserMailer.deliver_email(params[:email], params[:body]) endend
get :send_email, :email => '[email protected]', :body => 'Compra V14GR4! http://www.pastillitaazul.com'# => El código de send_mail se ejecuta aunque luego de error
![Page 31: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/31.jpg)
Acciones públicas# Ejemplo muy chorra :)class UsersController < ApplicationController def invite current_user.invitations.create(params[:email],) send_email end protected def send_email UserMailer.deliver_email(params[:email], params[:body]) endend
![Page 32: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/32.jpg)
algunos consejos
![Page 33: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/33.jpg)
jamás te fíes de lo que recibes en el servidor
![Page 34: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/34.jpg)
ten cuidado con los datos que recibes, pero también con los
que envías
![Page 35: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/35.jpg)
controla las interfaces de tus cotroladores y
modelos
![Page 36: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/36.jpg)
no filtres con listas negras
![Page 37: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/37.jpg)
no tengas miedo de escribir tests que prueben la seguridad
def test_should_avoid_xss_from_search_query get :search, :q => '<script id="injection">alert();</script>' assert_no_tag :script, :attributes => {:id => 'injection' } end
![Page 38: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/38.jpg)
algunas herramientas
![Page 39: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/39.jpg)
FireBug
![Page 40: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/40.jpg)
Cookie Editor
![Page 41: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/41.jpg)
Tamper Data
![Page 42: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/42.jpg)
CURL
![Page 43: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/43.jpg)
WWW::Mechanize
![Page 44: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/44.jpg)
require 'rubygems'require 'mechanize'
agent = WWW::Mechanize.new
page = agent.get 'http://www.gmail.com'form = page.forms.firstform.Email = '***your gmail account***'form.Passwd = '***your password***'page = agent.submit form
page = agent.get page.search("//meta").first.attributes['href'].gsub(/'/,'')page = agent.get page.uri.to_s.sub(/\?.*$/, "?ui=html&zy=n")page.search("//tr[@bgcolor='#ffffff']") do |row| from, subject = *row.search("//b/text()") url = page.uri.to_s.sub(/ui.*$/, row.search("//a").first.attributes["href"]) puts "From: #{from}\nSubject: #{subject}\nLink: #{url}\n\n"
email = agent.get url # ..end
![Page 45: Seguridad en aplicaciones Web](https://reader034.fdocuments.co/reader034/viewer/2022051818/549410fbb47959744d8b4a46/html5/thumbnails/45.jpg)
¿Preguntas?