A Beginner's Guide To Security With Ruby On Rails In BSD

2y ago
23 Views
2 Downloads
2.06 MB
49 Pages
Last View : 17d ago
Last Download : 3m ago
Upload by : Aarya Seiber
Transcription

A Beginner's Guideto SecuritywithRuby on Rails in BSDCorey Benninger

What's on Tap?Ruby on RailsBSDSecurity

What's on Tap?Better able to securelydevelop, harden, andmaintain Rails basedapplications.

Where's the BSD?

Where's the BSD?

Why Ruby on RailsSimplicity - SecurityDon't Repeat Yourself (DRY)Convention over Configuration

DEFENSE (in Depth)

Why I'm Here

Getting the Goods Ruby – interpreted scripting language Gems – the “apt-get” for Ruby packages Rails – a framework written in Ruby for developingweb applications

Getting the Goods Openbsd 3.9–Install Ruby (pkg add ruby-1.8.4p1.tgz)–Download RubyGems (ruby setup.rb)–Install Rails (gem install rails --includedependencies)V isit http://www.rubyonrails.org/downfor more install details

Getting the Goods Mac OS X 10.4–OS X pre 10.4.6 ships with broken Ruby–Ruby, Rails, and RubyGems will ship with OS X 10.5–The Developer Tools – Xcode 2.0 or newer–GNU readlineV isit http://hivelogic.com/articles/2005/12/01/ruby rails lighttpd mysql tigerfor more install details

Getting the Goods Mac OS X 10.4–A lternatively, download LocomotiveV isit http://locomotive.raaum.org todownload Locomotive

Getting the Goods FreeBSD 5.5 (or later)–pkg add -r rubygem-railsV nFreeBSDfor more install details

Romancing the Gems Gems are retrieved from http://gems.rubyforge.org– /sources.rbNo SSL(confidentiality, integrity, and authenticity)

Romancing the Gems RubyGems version 0.8.11 and later supports addingcryptographic signatures to gems.V isithttp://docs.rubygems.org/read/chapter/21for more install details

Romancing the Gems Install the gems using the "HighSe c urity" policy.–gem install SomeGem-0.2.0.gem -PHighSecuritygem must be signed signing cert must be valid signing cert must be trusted

Romancing the Gems Trusted Gem Certs–/root/.gem/trust/cert- SHA1(email) .pemGEM Cert Directory is set to be readable by all. /root should notbe in order to restrict read access.# ls -al /root/total 36drwx-----drwxr-xr-xdrwxr-xr-x3 root14 root3 rootwheelwheelwheel.gem

These Go to Eleven Gems will typically keep older versions of e sure to update Applications afterpackage updates

all float on ok When “Floating on Gems”, check version number inc o nfig/e nviro nme nt.rb.– RA ILS GEM V ERSION '1.1.6'When “Bound to Gems”, (files in ve ndo r/rails), makesure to rake and freeze your gems.–rake rails:freeze:gems

No Soup For You Default Rails setup leaves weak file permissions. File Permissions–Read all to DB Config–Read/Write all to Log files# Lock down key fileschown owner : webserver config/database.ymlchmod 640 config/database.ymlchown owner : webserver log/*.logchmod 660 log/*.log

Run Away Run your web server with the least neededpermissions.–sudo -u www ruby scripts/server

No Soup For You Using defaults, Ruby will need to write to“tmp/sessions”.chown this directory to your ruby process. DONOT CHMOD 777!

Things That Never Die Rails does not expire sessions on the server side.#NOTE: session expire is a client side settingclass ApplicationController ActionController::Basesession :session expires 1.hour.from nowend

Things That Never Die Rails does not expire sessions on the server side.#Solution: Roll Your Own Clean Upclass SessionCleanerdef self.remove stale estroy all( ['updated on ?', 20.minutes.ago] )endendCode From Peter Donald /

Soft Baked Cookies?def create new idrequire ‘digest/md5′md5 Digest::MD5::newnow Time::nowmd5.update(now.to nd(0)))md5.update(String( ))md5.update(’foobar’)@new session truemd5.hexdigestendprivate :create new id

Soft Baked Cookies? Server Date and Time sent in response headers (except millisecondswould be unknown)PID is generally a limited rangeIn 1995 Netscape’s implementation of SSL (using time, PID, parentPID) was cracked“foobar” string adds no security if this is not changedMersenne Twister algorithm alone is known to be cryptographicallyinsecureTed Dziuba has more details at:http://epsilondelta.net/2006/05/17/

Hello Cleveland! Rocking Security Features–Protects against SQL Injection–Simple Validation and HTML Encoding Functions

Dirty Injections SQL Injection can allow an attacker full access toyour database or worse.––Example: Non-Checked input could lead to the followingSQL Statement.SELECT * FROM users WHERE username 'admin' AND password '' OR 1 1 --';

Escaped for Your Pleasure ActiveRecord with built in SQL Injection Protection–book Book.find(params[:id])–settings Setting.find(:all,:conditions [“uid ?”, user.id])

Escaped for Your Pleasure BUT DON'T DO THIS!!!–book Book.find(:all:limit #{session[:pref].id})–settings Setting.find(:all,:conditions [“username '#{params[:id]}')This is a slide of what NOT to do.Use Rails bind variable instead of #{.}with A ctiveRecords to avoid SQL Injection.

Escaped for Your PleasureData will be automatically truncated to match fieldlength. Alternatively, it is easy to validate lengths of user input. validates length of :phone, :within 5.16, :message "Invalid Phone NumberLength"

Validate Me Rails comes with a number of input validations builtin.–validates length of–validates presence of–validates format of–validates uniqueness of

Validate Mevalidates length of :phone, :within 5.16validates format of :phone, :with / [ \/\() 0-9] /, :message "Invalid PhoneNumber"validates format of :url, :with / (http https):\/\/[a-z0-9] ([\-\.]{1}[a-z09] )*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)? /ix

Money Back Guarantee

Veni Vidi XSSdi Cross-Site Scripting is the web's new number onebad guy.Probably the best site about XSShttp://ha.ckers.org

Veni Vidi XSSdi Cross-Site Scripting (XSS) will take advantage of aflaw in a website to run unexpected code on avictim's web browser.

It's not just for breakfast anymore. XSS is not limited to stealing cookie/session data.–Force a user to browse and submit data–Cause a browser to scan an internal network–Call vulnerable 3rd party controls–Attacker has endless possibilities for exploit payloads.

Veni Vidi XSSdi Any user input, when redisplayed back to the sameor other users, should be properly encoded to avoidallowing an attacker to write their ownHTML/Javascript code.

Ruby to the Rexsscue Use the “h” html escape method when writing userdata back out. % for comment in @post.comments % % h comment.body % % end %

Ruby to the RexsscueBefore HTML Encoding:Watch me steal your cookie: script alert(document.cookie) /script After HTML Encoding:Watch me steal your ript>

Ruby to the Rexsscue Safe ERB–Plug-in that will ensure all strings written through rhtmltemplates are checked or escaped before written out.(Ruby's built in “ SAFE” can not be properly used withRails.)Shinya K asatani wrote Safe ERBwhich can be found athttp://wiki.rubyonrails.org/rails/pages/Safe ERB

Checking the AJAX Rails has a built in check for XML Http Requests.–request.xhr? simply checks for header “X-RequestedWith XMLHttpRequest”. This can be forged by anattacker.

Would you like fries with that? Bulk database assignments, like “create” and “new”,can add data for any column in a table.

Would you like fries with that? Black List Column Exclusion– attr protected :approved, :is adminWhite List Column Exclusion–attr accessible :username, :password

We're Safer “Contrary to popular belief, buffer overflow exploits do not occur incustom web applications. While technically possible, the truth is that theyare just not seen in the real world.” - Jeremiah Grossman (Mar 2006)Ruby is an interpreted, strongly typed dynamiclanguage without direct memory access.Pure Ruby code will not contain buffer overflows.Looking for that warm fuzzy feeling?http://www.owasp.org/index.php/Buffer hbusting buffer overflow.pdf

But not Safe A buffer overflow could exists in the interpreter.Using “RubyInline” you could embed C code in withRuby.require 'rubygems'require gem 'RubyInline'class selfinline do builder builder.c "int badcopy(char *input[]) {char buffer[10];strcpy(buffer, input[]);return 0;} "endend

haeY haeY haeY Rails is single threaded. It can only handle onerequest at a time.Reverse Proxy to the Performance Rescue

haeY haeY haeY Response Splitting–Attacker will try to forge response headers to split aresponse and craft malicious content.–Validate filenames, cookies, and other data that may beused in response headers (particularly watch out fornewline characters like %0D and %0A).

. for all the fish Validate Installs (if possible)Lockdown File Permissions (restrict reads)Validate User Input ("validates." methods)Properly Escape Output (Safe ERB)Expire SessionsUse Bind Variables in ActiveRecords

A Beginner's Guide to Security with Ruby on Rails in BSD Corey Benninger. What's on Tap? Ruby on Rails BSD Security. . Openbsd 3.9 – Install Ruby (pkg_add ruby-1.8.4p1.tgz) . for more install details. Getting the Goods

Related Documents:

2 FIVB Sports Development Department Beach Volleyball Drill-book TABLE OF CONTENTS 22 WARM-UP DRILLS LEVEL PAGES DRILL 1.1 VOLESTE (beginner) 10 DRILL 1.2 SINGLE TWO BALL JUGGLE (beginner) 11 DRILL 1.3 TWO BALL JUGGLE IN PAIRS (beginner) 12 DRILL 1.4 THROW PASS AND CATCH (beginner) 13 DRILL 1.5 SKYBALL AND CATCH (beginner) 14 DRILL 1.6 SERVE AND JOG (beginner) 15

Group Piano Course Late Beginner (ages 8 10) Alfred’s Basic Late Beginner (ages 10 11) Chord Approach Adult Piano Course OR All-In-One Adult Piano Course Young Beginner (ages 5 7) Prep Course Beginner (ages 7 9) Alfred’s Basic For the youngest beginner, ages 4–6 Music for Little Mozarts, Books 1–4 lead into Prep Level C. 2

GraceLink Sabbath School Curriculum USA NON-USA Periodical Code Single Copy Single 1 Yr Single 1 Yr Beginner Beginner Student EBQ 10.99 26.48 33.48 Beginner Leader/Teacher EBT 24.59 60.00 67.00 Beginner Memory Verse EBM

Hunter SEAFORD: JJ Boys & Girls 7 - 8 Beginner 51 - 60lb - A: 5 1: Arredondo Hunter: SEAFORD KB: Boys & Girls 7 - 8 Beginner 51 - 60lb - B 13: 4 Arredondo: Mason SEAFORD: JJ Boys 9 - 10 Beginner 61 - 70lb: 15 3: Arredondo Mason: SEAFORD KB: Boys 9 - 10 Beginner 61 - 70lb 5: 6 Ashirmamatov: Shahriyor MIDWOOD: JJ Boys 9 - 10 Intermediate 60lb .

White Christmas Beginner Piano Level 1 Sheet Music Download white christmas beginner piano level 1 sheet music pdf now available in our library. We give you 2 pages partial preview of white christmas beginner piano level 1 sheet music that you can try for free. This music notes has been

Present the characteristics of mentoring and coaching for beginner teachers. b. Describe the needs for training in coaching skills for beginner teacher men-tors based on the Kansas Coaching Model (2007) by Jim Knight and Adult Learning Principles (1994) by Malcolm Knowles. c. Describe the training areas that beginner teacher mentors need in .

Independent Personal Pronouns Personal Pronouns in Hebrew Person, Gender, Number Singular Person, Gender, Number Plural 3ms (he, it) א ִוה 3mp (they) Sֵה ,הַָּ֫ ֵה 3fs (she, it) א O ה 3fp (they) Uֵה , הַָּ֫ ֵה 2ms (you) הָּ תַא2mp (you all) Sֶּ תַא 2fs (you) ְ תַא 2fp (you

work/products (Beading, Candles, Carving, Food Products, Soap, Weaving, etc.) ⃝I understand that if my work contains Indigenous visual representation that it is a reflection of the Indigenous culture of my native region. ⃝To the best of my knowledge, my work/products fall within Craft Council standards and expectations with respect to