Oggi parliamo di sicurezza: parliamo di Brakeman!
Brakeman è un Security Vulnerability Scanner per Ruby on Rails.
Dopo averlo installato con un
gem install brakeman
ed eventualmente aver fatto un rehash
rbenv rehash
disporremo del comando brakeman.
Eseguendolo all’interno della directory del proprio progetto in Rails ci verrà fornito l’output di una analisi di sicurezza e vulnerabilità della nostra applicazione.
Un esempio di output è il seguente:
$ brakeman
Loading scanner...
[Notice] Detected Rails 3 application
Processing application in /Users/claudio/Progetti/xxxxx
Processing configuration...
[Notice] Escaping HTML by default
Processing gems...
Processing initializers...
Processing libs...
Processing routes...
Processing templates...
Processing data flow in templates...
Processing models...
Processing controllers...
Processing data flow in controllers...
Indexing call sites...
Running checks in parallel...
- CheckBasicAuth
- CheckCrossSiteScripting
- CheckContentTag
- CheckDefaultRoutes
- CheckDigestDoS
- CheckEscapeFunction
- CheckEvaluation
- CheckExecute
- CheckFileAccess
- CheckFilterSkipping
- CheckForgerySetting
- CheckJRubyXML
- CheckJSONParsing
- CheckLinkTo
- CheckLinkToHref
- CheckMailTo
- CheckMassAssignment
- CheckModelAttributes
- CheckModelSerialize
- CheckNestedAttributes
- CheckQuoteTableName
- CheckRedirect
- CheckRender
- CheckResponseSplitting
- CheckSafeBufferManipulation
- CheckSanitizeMethods
- CheckSelectTag
- CheckSelectVulnerability
- CheckSend
- CheckSendFile
- CheckSessionSettings
- CheckSingleQuotes
- CheckSkipBeforeFilter
- CheckSQL
- CheckStripTags
- CheckSymbolDoS
- CheckTranslateBug
- CheckUnsafeReflection
- CheckValidationRegex
- CheckWithoutProtection
- CheckYAMLLoad
- CheckYAMLParsing
Checks finished, collecting results...
Generating report...
+BRAKEMAN REPORT+
Application path: /Users/claudio/Progetti/xxxxxx
Rails version: 3.2.8
Brakeman version: 1.9.4
Started at 2013-03-27 21:58:02 +0100
Duration: 4.805979 seconds
Checks run: BasicAuth, ContentTag, CrossSiteScripting, DefaultRoutes, DigestDoS, EscapeFunction, Evaluation, Execute, FileAccess, FilterSkipping, ForgerySetting, JRubyXML, JSONParsing, LinkTo, LinkToHref, MailTo, MassAssignment, ModelAttributes, ModelSerialize, NestedAttributes, QuoteTableName, Redirect, Render, ResponseSplitting, SQL, SafeBufferManipulation, SanitizeMethods, SelectTag, SelectVulnerability, Send, SendFile, SessionSettings, SingleQuotes, SkipBeforeFilter, StripTags, SymbolDoS, TranslateBug, UnsafeReflection, ValidationRegex, WithoutProtection, YAMLLoad, YAMLParsing
+SUMMARY+
+-------------------+---------+
| Scanned/Reported | Total |
+-------------------+---------+
| Controllers | 19 |
| Models | 22 |
| Templates | 106 |
| Errors | 0 |
| Security Warnings | 22 (12) |
+-------------------+---------+
+-----------------------+-------+
| Warning Type | Total |
+-----------------------+-------+
| Attribute Restriction | 1 |
| Default Routes | 1 |
| Denial of Service | 1 |
| Mass Assignment | 10 |
| Redirect | 2 |
| Remote Code Execution | 2 |
| SQL Injection | 4 |
| Session Setting | 1 |
+-----------------------+-------+
+SECURITY WARNINGS+
+------------+---------------------------+---------------------------------------------+-----------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->>
| Confidence | Class | Method | Warning Type | Message >>
+------------+---------------------------+---------------------------------------------+-----------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->>
| High | | | Default Routes | All public methods in controllers are available as actions in routes.rb near line 163 >>
| High | ContactController | submit | Mass Assignment | Unprotected mass assignment near line 7: ContactRequest.new(+params[:contact_request]+) >>
| High | CartController | add | Redirect | Possible unprotected redirect near line 24: redirect_to(+params[:last_url]+) >>
| High | Mobile::ProductController | xxxxxxxxxxxx | Redirect | Possible unprotected redirect near line 28: redirect_to(+params[:back_url]+) >>
| High | | | Remote Code Execution | json gem version 1.7.5 has a remote code vulnerablity: upgrade to 1.7.7 >>
| High | | | Remote Code Execution | Rails 3.2.8 has a remote code execution vulnerability: upgrade to 3.2.11 or disable XML parsing >>
| High | | | SQL Injection | All versions of Rails before 3.0.18, 3.1.9, and 3.2.10 contain a SQL Injection Vulnerability: CVE-2012-5664; Upgrade to 3.2.10, 3.1.9, 3.0.18 >>
| High | | | SQL Injection | All versions of Rails before 3.0.19, 3.1.10, and 3.2.11 contain a SQL Injection Vulnerability: CVE-2013-0155; Upgrade to 3.2.11, 3.1.10, 3.0.19 >>
| High | CartController | remove | SQL Injection | Possible SQL injection near line 36: CartLine.where(+params[:line_id]+) >>
| High | Mobile::xxxxxxxxxxxx | index | SQL Injection | Possible SQL injection near line 10: Product.where("name LIKE '%#{+params[:name]+}%' AND published = ? ", true) >>
| High | | | Session Setting | Session secret should not be included in version control near line 7 >>
| Medium | | | Denial of Service | Rails 3.2.8 has a denial of service vulnerability in ActiveRecord: upgrade to 3.2.13 or patch >>
| Weak | Article | xxxxxxxxxxxxxxxxxxxxxxxxxx | Mass Assignment | Unprotected mass assignment near line 39: Article.new(:code => ((local row)[0]), :title => ((local row)[1]), :sku => ((local row)[2]), :size => ((local row)[3]), :published =>>
| Weak | CartController | add | Mass Assignment | Unprotected mass assignment near line 18: CartLine.create(:cart_id => ((Cart.find_by_customer_id(current_customer.id) or Cart.create(:customer_id => (current_customer.id), :d>>
| Weak | CartController | checkout | Mass Assignment | Unprotected mass assignment near line 49: Order.create(:date => (DateTime.now), :customer_id => (current_customer.id), :total_items => 0, :total_price => 0, :note => (+params>>
| Weak | CartController | checkout | Mass Assignment | Unprotected mass assignment near line 57: OrderLine.create(:order => (+Order.create(:date => (DateTime.now), :customer_id => (current_customer.id), :total_items => 0, :total_>>
| Weak | Customer | Customer.xxxxxxxxxxxxxxxxxx | Mass Assignment | Unprotected mass assignment near line 27: Customer.create(:name => ((local row)[1]), :code => ((local row)[0]), :email => (("" or ((local row)[0] + "@maw.it"))), :agent => (+>>
| Weak | xxxxxxxxxxxxxxxxxxxxxxxx | xxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxx | Mass Assignment | Unprotected mass assignment near line 20: CustomerDiscountCategory.create(:customer => (Customer.find_by_code((local row)[0])), :discount_category => ((DiscountCategory.find_>>
| Weak | Mobile::CartController | add | Mass Assignment | Unprotected mass assignment near line 30: CartLine.create(:cart_id => ((Cart.find_by_customer_id(session[:customer_id]) or Cart.create(:customer_id => (session[:customer_id])>>
| Weak | Mobile::CartController | checkout | Mass Assignment | Unprotected mass assignment near line 65: OrderLine.create(:order => (+Order.create(:date => (DateTime.now), :customer_id => (session[:customer_id]), :total_items => 0, :tota>>
| Weak | xxxxxxxxxxxx | SpecialPrice.xxxxxxxxxxxxxxxxxx | Mass Assignment | Unprotected mass assignment near line 20: SpecialPrice.create(:customer => (Customer.find_by_code((local row)[0])), :product => (+Article.find_by_sku((local row)[1]).product+>>
+------------+---------------------------+---------------------------------------------+-----------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->>
Model Warnings:
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------->>
| Confidence | Model | Warning >>
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------->>
| High | Agent, Article, Browsable, Cart, CartLine, Category, Ckeditor::Asset, Ckeditor::AttachmentFile, Ckeditor::Picture, ContactRequest, Customer, CustomerDiscountCategory, DiscountCategory, News, Order, OrderLine, Page, Product, ProductAttachment, SpecialPrice, Word | Attribut>>
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------->>
Dopo una analisi dell’output capiamo cosa effettuare per migliorare la sicurezza del nostro applicativo.
E’ possibile anche generare report in vari formati, come in html o json:
brakeman -o output.html
brakeman -o output.json
Per maggiori informazioni e opzioni consultate la pagina del progetto Brakeman