Top Banner
Vulnerable Active Record A tale of SQL Injection in PHP Framework [email protected] fb.com/index.htmli linkedin.com/in/pich4ya Pichaya Morimoto Thailand PHP User Group Meetup January 28, 2015
13

Vulnerable Active Record: A tale of SQL Injection in PHP Framework

Jul 16, 2015

Download

Technology

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Vulnerable Active Record: A tale of SQL Injection in PHP Framework

Vulnerable Active RecordA tale of SQL Injection in PHP Framework

[email protected]/index.htmlilinkedin.com/in/pich4ya

Pichaya MorimotoThailand PHP User Group Meetup

January 28, 2015

Page 2: Vulnerable Active Record: A tale of SQL Injection in PHP Framework

★ What is Active Record ?★ Secure by Design ?★ Case Studies★ Exploitation★ Input Validation ★ Defence-in-Depth★ Conclusion

Overview

Page 3: Vulnerable Active Record: A tale of SQL Injection in PHP Framework

Active record pattern is an approach to accessing data in a database. A database table or view is wrapped into a class. Thus, an object instance is tied to row(s) in the table.

PHP frameworks also bundle their own ORM implementing the active record pattern. For example, Laravel (Eloquent), CakePHP, Symfony (Doctrine), CodeIgniter and Yii.

$query = $this->db->select('title, content, date');$query->from('table1');$query->where('id', $id);$query->get();

Source: https://en.wikipedia.org/wiki/Active_record_pattern

What is Active Record ?

Page 4: Vulnerable Active Record: A tale of SQL Injection in PHP Framework

Secure by Design ?

That’s Magic !

Page 5: Vulnerable Active Record: A tale of SQL Injection in PHP Framework

Case Study #1

Get rows from table ‘news’ and order by user input ‘sort’

PHP Framework: CodeIgniter 2.2

Page 6: Vulnerable Active Record: A tale of SQL Injection in PHP Framework

Hacker is here, where is SQLi ?

SQLMap == FailedAcunetix == FailedHavij == Failed‘ or ‘1’=’1 , union all select blah blah blah == Failed

Page 7: Vulnerable Active Record: A tale of SQL Injection in PHP Framework

SQL Injection Pwnage

Pwned !

What if error message is turned off, is it still vulnerable? Ads: http://slideshare.net/pichayaa/sql-injection-owaspthailand

Page 8: Vulnerable Active Record: A tale of SQL Injection in PHP Framework

Stand back I know secure coding!

No more SQL Injection

withType Validation !

Page 9: Vulnerable Active Record: A tale of SQL Injection in PHP Framework

Case Study #2

Secure Coding !!

Page 10: Vulnerable Active Record: A tale of SQL Injection in PHP Framework

Keep calm and Think Again

Numeric = [Integer, Double, Hex, ...]

id value above is hex encoded of “1 and 1>2 union select CHAR(32,58,32),user(),database(),version(),concat_ws(0x3a,username,password) from ci220news_db” + data field is varchar type ***

Page 11: Vulnerable Active Record: A tale of SQL Injection in PHP Framework

A list of security techniques that should be included in every software development project.

★ Parameterize Queries★ Implement Logging, Error Handling and Intrusion Detection★ Leverage Security Features of Frameworks and Security Libraries

and more.. https://www.owasp.org /index.php/OWASP_Proactive_Controls

OWASP Proactive Controls

ProTip: PHP is not allowed to parameterize ‘Order By’ clause ;)Because it isn’t data, it is a column name!

Page 12: Vulnerable Active Record: A tale of SQL Injection in PHP Framework

A layered approach to security can be implemented at any level of a complete information security strategy.★ Secure Coding in software requirement★ OS Hardening, reduce attack surface★ Perimeter Security (Network Firewall, IPS/IDS)★ Centralized Log Server / SIEM★ Patch / Vulnerability Management System★ Incident Response Plans★ Web Application Firewall

Source: http://techrepublic.com/blog/it-security/understanding-layered-security-and-defense-in-depth/

Defence-in-Depth

Page 13: Vulnerable Active Record: A tale of SQL Injection in PHP Framework

Security Today !==

Security Tomorrow

Conclusion

http://framework.zend.com/security/advisory/ZF2014-04http://bakery.cakephp.org/articles/markstory/2013/04/28/security_release_-_cakephp_1_2_12_1_3_16_2_2_8_and_2_3_4