SlideShare a Scribd company logo
1 of 19
Todd Keup ::
magnifisites.com
What Every Webmaster
Should Know About Code
Installation
Cracking and Hacking
Todd Keup
@toddkeup
Todd Keup ::
magnifisites.com
Cracker versus hacker
Todd Keup ::
magnifisites.com
Overview
• Motivation
• Tools of the trade
• Common attacks
• Defending yourself
Todd Keup ::
magnifisites.com
Motivation
• Drop links or cookies
• Steal logins, blackmail people
• Building botnets
• Redirect advertising
• Crush competition
• Steal credit cards
• Abuse your server (email, attacks, etc.)
Todd Keup ::
magnifisites.com
Tools of the trade
• Basic hacking became easier
• Portscanners, evil software suites are
available to the public
• SARA, brutus, etc.: endless list
Todd Keup ::
magnifisites.com
Common attacks
• SQL injection
• Additional software problems
• How to protect yourself
• Your checklist
Todd Keup ::
magnifisites.com
SQL Injection
• How it looks
• What happens when it succeeds
• Recovery
– Cleanup
– Plugging the hole (prevention)
• Monitoring and discovery
Todd Keup ::
magnifisites.com
SQL Injection
Todd Keup ::
magnifisites.com
SQL Injection
<form method="post" action="process">
Username: <input name="username" type="text" value="">
Password: <input name="password" type="password" value="">
<input name="submitform" type="submit" value="Submit">
</form>
Incorrectly filtered escape characters
query = "SELECT * FROM users WHERE
name = '" + username + "' AND pass = '" + password + "';"
Todd Keup ::
magnifisites.com
SQL Injection
Incorrectly filtered escape characters
query = "SELECT * FROM users WHERE
name = '" + username + "' AND pass = '" + password + "';"
Renders:
query = "SELECT * FROM users WHERE
name = '' OR 1=1 -- '' AND pass = 'doesNotMatter';"
Todd Keup ::
magnifisites.com
SQL Injection
Incorrectly filtered escape characters
<?php
$offset = $_GET['start'];
$query = "SELECT id, name FROM products ORDER BY name
LIMIT 20 OFFSET $offset;";
$result = pg_query($connection, $query);
?>
// cracker encodes the following into the "start" value of the url
0;
insert into pg_shadow(usename,usesysid,usesuper,usecatupd,passwd)
select 'cracker', usesysid, 'yes','yes','jack'
from pg_shadow where usename='postgres'; --
Todd Keup ::
magnifisites.com
SQL Injection
Incorrectly filtered escape characters
query = "UPDATE users SET pwd='$pwd' WHERE uid='$uid';";
// user enters: ' OR name LIKE '%admin%'; -- ' and it renders:
UPDATE users SET pwd='abc' WHERE uid='me' OR name LIKE '%admin%'; -- ';
Incorrect type handling
query = "SELECT * FROM students WHERE id = " + expectedInteger + ";"
// user enters: 1;DROP TABLE students
SELECT * FROM students WHERE id = 1;DROP TABLE students;
Todd Keup ::
magnifisites.com
SQL Injection
Image courtesy of http://xkcd.com/327/
Todd Keup ::
magnifisites.com
SQL Injection
Cleanup, aisle nine
Check your access logs
Check file modification time
Revert to backup?
Change passwords
Patch the hole
Todd Keup ::
magnifisites.com
SQL Injection
Casting a type value
$ticket = (integer) $_POST['ticketnumber'];
Properly filtering data
$query =
sprintf(
"SELECT * FROM Users WHERE user='%s' AND pass='%s'",
mysql_real_escape_string($user),
mysql_real_escape_string($pass)
);
mysql_query($query);
Todd Keup ::
magnifisites.com
SQL Injection
Monitor and Discover
Audit your site regularly
• Log form submissions
• Monitor changes to user files
• Use your system tools
• Use the same tools crackers employ
• Identify access patterns of automated tools
• Blacklist hosts that initiate attacks
Todd Keup ::
magnifisites.com
SQL Injection
Monitor and Discover
• Never connect to the database as a
superuser or as the database owner.
• Check expected data type
• Escape user supplied values
• Do not print out any database specific
information, especially about the schema
• Do not dump raw errors to the display
Todd Keup ::
magnifisites.com
Botnets
Todd Keup ::
magnifisites.com
Thank You
Todd Keup
todd@magnifisites.com
@toddkeup

More Related Content

What's hot

How to make your users not want to murder you
How to make your users not want to murder youHow to make your users not want to murder you
How to make your users not want to murder youjoe_mcmahon
 
Bug bounty null_owasp_2k17
Bug bounty null_owasp_2k17Bug bounty null_owasp_2k17
Bug bounty null_owasp_2k17Sagar M Parmar
 
6.2. Hacking most popular websites
6.2. Hacking most popular websites6.2. Hacking most popular websites
6.2. Hacking most popular websitesdefconmoscow
 
Javascript Security
Javascript SecurityJavascript Security
Javascript Securityjgrahamc
 
Web Security Horror Stories
Web Security Horror StoriesWeb Security Horror Stories
Web Security Horror StoriesSimon Willison
 
Bug Bounty #Defconlucknow2016
Bug Bounty #Defconlucknow2016Bug Bounty #Defconlucknow2016
Bug Bounty #Defconlucknow2016Shubham Gupta
 
Mitigating CSRF with two lines of codes
Mitigating CSRF with two lines of codesMitigating CSRF with two lines of codes
Mitigating CSRF with two lines of codesMinhaz A V
 
ADBMS (MySql) tiny project
ADBMS (MySql) tiny projectADBMS (MySql) tiny project
ADBMS (MySql) tiny projectDeepak Upadhyay
 

What's hot (10)

How to make your users not want to murder you
How to make your users not want to murder youHow to make your users not want to murder you
How to make your users not want to murder you
 
Bug Bounty for - Beginners
Bug Bounty for - BeginnersBug Bounty for - Beginners
Bug Bounty for - Beginners
 
Bug bounty null_owasp_2k17
Bug bounty null_owasp_2k17Bug bounty null_owasp_2k17
Bug bounty null_owasp_2k17
 
PHPUG Presentation
PHPUG PresentationPHPUG Presentation
PHPUG Presentation
 
6.2. Hacking most popular websites
6.2. Hacking most popular websites6.2. Hacking most popular websites
6.2. Hacking most popular websites
 
Javascript Security
Javascript SecurityJavascript Security
Javascript Security
 
Web Security Horror Stories
Web Security Horror StoriesWeb Security Horror Stories
Web Security Horror Stories
 
Bug Bounty #Defconlucknow2016
Bug Bounty #Defconlucknow2016Bug Bounty #Defconlucknow2016
Bug Bounty #Defconlucknow2016
 
Mitigating CSRF with two lines of codes
Mitigating CSRF with two lines of codesMitigating CSRF with two lines of codes
Mitigating CSRF with two lines of codes
 
ADBMS (MySql) tiny project
ADBMS (MySql) tiny projectADBMS (MySql) tiny project
ADBMS (MySql) tiny project
 

Similar to Pubcon Las Vegas 2012 SQL Injection

How to discover 1352 Wordpress plugin 0days in one hour (not really)
How to discover 1352 Wordpress plugin 0days in one hour (not really)How to discover 1352 Wordpress plugin 0days in one hour (not really)
How to discover 1352 Wordpress plugin 0days in one hour (not really)Larry Cashdollar
 
Hacking sites for fun and profit
Hacking sites for fun and profitHacking sites for fun and profit
Hacking sites for fun and profitDavid Stockton
 
hackcon2013-Dirty Little Secrets They Didn't Teach You In Pentesting Class v2
hackcon2013-Dirty Little Secrets They Didn't Teach You In Pentesting Class v2hackcon2013-Dirty Little Secrets They Didn't Teach You In Pentesting Class v2
hackcon2013-Dirty Little Secrets They Didn't Teach You In Pentesting Class v2Chris Gates
 
Practical Secure Coding Workshop - {DECIPHER} Hackathon
Practical Secure Coding Workshop - {DECIPHER} HackathonPractical Secure Coding Workshop - {DECIPHER} Hackathon
Practical Secure Coding Workshop - {DECIPHER} HackathonStefan Streichsbier
 
Sql injection - security testing
Sql injection - security testingSql injection - security testing
Sql injection - security testingNapendra Singh
 
Secure WordPress Development Practices
Secure WordPress Development PracticesSecure WordPress Development Practices
Secure WordPress Development PracticesBrandon Dove
 
Hacking sites for fun and profit
Hacking sites for fun and profitHacking sites for fun and profit
Hacking sites for fun and profitDavid Stockton
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
Oracle database threats - LAOUC Webinar
Oracle database threats - LAOUC WebinarOracle database threats - LAOUC Webinar
Oracle database threats - LAOUC WebinarOsama Mustafa
 
Dirty Little Secrets They Didn't Teach You In Pentest Class v2
Dirty Little Secrets They Didn't Teach You In Pentest Class v2Dirty Little Secrets They Didn't Teach You In Pentest Class v2
Dirty Little Secrets They Didn't Teach You In Pentest Class v2Rob Fuller
 
Dirty Little Secrets They Didn't Teach You In Pentest Class v2
Dirty Little Secrets They Didn't Teach You In Pentest Class v2Dirty Little Secrets They Didn't Teach You In Pentest Class v2
Dirty Little Secrets They Didn't Teach You In Pentest Class v2Chris Gates
 
Hacking sites for fun and profit
Hacking sites for fun and profitHacking sites for fun and profit
Hacking sites for fun and profitDavid Stockton
 
OWASP Top 10 vs Drupal - OWASP Benelux 2012
OWASP Top 10 vs Drupal - OWASP Benelux 2012OWASP Top 10 vs Drupal - OWASP Benelux 2012
OWASP Top 10 vs Drupal - OWASP Benelux 2012ZIONSECURITY
 
Intro to Php Security
Intro to Php SecurityIntro to Php Security
Intro to Php SecurityDave Ross
 
SQL Injections - 2016 - Huntington Beach
SQL Injections - 2016 - Huntington BeachSQL Injections - 2016 - Huntington Beach
SQL Injections - 2016 - Huntington BeachJeff Prom
 

Similar to Pubcon Las Vegas 2012 SQL Injection (20)

Hack through Injections
Hack through InjectionsHack through Injections
Hack through Injections
 
Not so blind SQL Injection
Not so blind SQL InjectionNot so blind SQL Injection
Not so blind SQL Injection
 
Code injection
Code injectionCode injection
Code injection
 
Web Security 101
Web Security 101Web Security 101
Web Security 101
 
How to discover 1352 Wordpress plugin 0days in one hour (not really)
How to discover 1352 Wordpress plugin 0days in one hour (not really)How to discover 1352 Wordpress plugin 0days in one hour (not really)
How to discover 1352 Wordpress plugin 0days in one hour (not really)
 
Hacking sites for fun and profit
Hacking sites for fun and profitHacking sites for fun and profit
Hacking sites for fun and profit
 
hackcon2013-Dirty Little Secrets They Didn't Teach You In Pentesting Class v2
hackcon2013-Dirty Little Secrets They Didn't Teach You In Pentesting Class v2hackcon2013-Dirty Little Secrets They Didn't Teach You In Pentesting Class v2
hackcon2013-Dirty Little Secrets They Didn't Teach You In Pentesting Class v2
 
Practical Secure Coding Workshop - {DECIPHER} Hackathon
Practical Secure Coding Workshop - {DECIPHER} HackathonPractical Secure Coding Workshop - {DECIPHER} Hackathon
Practical Secure Coding Workshop - {DECIPHER} Hackathon
 
Sql Injection
Sql InjectionSql Injection
Sql Injection
 
Sql injection - security testing
Sql injection - security testingSql injection - security testing
Sql injection - security testing
 
Secure WordPress Development Practices
Secure WordPress Development PracticesSecure WordPress Development Practices
Secure WordPress Development Practices
 
Hacking sites for fun and profit
Hacking sites for fun and profitHacking sites for fun and profit
Hacking sites for fun and profit
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
Oracle database threats - LAOUC Webinar
Oracle database threats - LAOUC WebinarOracle database threats - LAOUC Webinar
Oracle database threats - LAOUC Webinar
 
Dirty Little Secrets They Didn't Teach You In Pentest Class v2
Dirty Little Secrets They Didn't Teach You In Pentest Class v2Dirty Little Secrets They Didn't Teach You In Pentest Class v2
Dirty Little Secrets They Didn't Teach You In Pentest Class v2
 
Dirty Little Secrets They Didn't Teach You In Pentest Class v2
Dirty Little Secrets They Didn't Teach You In Pentest Class v2Dirty Little Secrets They Didn't Teach You In Pentest Class v2
Dirty Little Secrets They Didn't Teach You In Pentest Class v2
 
Hacking sites for fun and profit
Hacking sites for fun and profitHacking sites for fun and profit
Hacking sites for fun and profit
 
OWASP Top 10 vs Drupal - OWASP Benelux 2012
OWASP Top 10 vs Drupal - OWASP Benelux 2012OWASP Top 10 vs Drupal - OWASP Benelux 2012
OWASP Top 10 vs Drupal - OWASP Benelux 2012
 
Intro to Php Security
Intro to Php SecurityIntro to Php Security
Intro to Php Security
 
SQL Injections - 2016 - Huntington Beach
SQL Injections - 2016 - Huntington BeachSQL Injections - 2016 - Huntington Beach
SQL Injections - 2016 - Huntington Beach
 

Recently uploaded

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 

Recently uploaded (20)

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 

Pubcon Las Vegas 2012 SQL Injection

  • 1. Todd Keup :: magnifisites.com What Every Webmaster Should Know About Code Installation Cracking and Hacking Todd Keup @toddkeup
  • 3. Todd Keup :: magnifisites.com Overview • Motivation • Tools of the trade • Common attacks • Defending yourself
  • 4. Todd Keup :: magnifisites.com Motivation • Drop links or cookies • Steal logins, blackmail people • Building botnets • Redirect advertising • Crush competition • Steal credit cards • Abuse your server (email, attacks, etc.)
  • 5. Todd Keup :: magnifisites.com Tools of the trade • Basic hacking became easier • Portscanners, evil software suites are available to the public • SARA, brutus, etc.: endless list
  • 6. Todd Keup :: magnifisites.com Common attacks • SQL injection • Additional software problems • How to protect yourself • Your checklist
  • 7. Todd Keup :: magnifisites.com SQL Injection • How it looks • What happens when it succeeds • Recovery – Cleanup – Plugging the hole (prevention) • Monitoring and discovery
  • 9. Todd Keup :: magnifisites.com SQL Injection <form method="post" action="process"> Username: <input name="username" type="text" value=""> Password: <input name="password" type="password" value=""> <input name="submitform" type="submit" value="Submit"> </form> Incorrectly filtered escape characters query = "SELECT * FROM users WHERE name = '" + username + "' AND pass = '" + password + "';"
  • 10. Todd Keup :: magnifisites.com SQL Injection Incorrectly filtered escape characters query = "SELECT * FROM users WHERE name = '" + username + "' AND pass = '" + password + "';" Renders: query = "SELECT * FROM users WHERE name = '' OR 1=1 -- '' AND pass = 'doesNotMatter';"
  • 11. Todd Keup :: magnifisites.com SQL Injection Incorrectly filtered escape characters <?php $offset = $_GET['start']; $query = "SELECT id, name FROM products ORDER BY name LIMIT 20 OFFSET $offset;"; $result = pg_query($connection, $query); ?> // cracker encodes the following into the "start" value of the url 0; insert into pg_shadow(usename,usesysid,usesuper,usecatupd,passwd) select 'cracker', usesysid, 'yes','yes','jack' from pg_shadow where usename='postgres'; --
  • 12. Todd Keup :: magnifisites.com SQL Injection Incorrectly filtered escape characters query = "UPDATE users SET pwd='$pwd' WHERE uid='$uid';"; // user enters: ' OR name LIKE '%admin%'; -- ' and it renders: UPDATE users SET pwd='abc' WHERE uid='me' OR name LIKE '%admin%'; -- '; Incorrect type handling query = "SELECT * FROM students WHERE id = " + expectedInteger + ";" // user enters: 1;DROP TABLE students SELECT * FROM students WHERE id = 1;DROP TABLE students;
  • 13. Todd Keup :: magnifisites.com SQL Injection Image courtesy of http://xkcd.com/327/
  • 14. Todd Keup :: magnifisites.com SQL Injection Cleanup, aisle nine Check your access logs Check file modification time Revert to backup? Change passwords Patch the hole
  • 15. Todd Keup :: magnifisites.com SQL Injection Casting a type value $ticket = (integer) $_POST['ticketnumber']; Properly filtering data $query = sprintf( "SELECT * FROM Users WHERE user='%s' AND pass='%s'", mysql_real_escape_string($user), mysql_real_escape_string($pass) ); mysql_query($query);
  • 16. Todd Keup :: magnifisites.com SQL Injection Monitor and Discover Audit your site regularly • Log form submissions • Monitor changes to user files • Use your system tools • Use the same tools crackers employ • Identify access patterns of automated tools • Blacklist hosts that initiate attacks
  • 17. Todd Keup :: magnifisites.com SQL Injection Monitor and Discover • Never connect to the database as a superuser or as the database owner. • Check expected data type • Escape user supplied values • Do not print out any database specific information, especially about the schema • Do not dump raw errors to the display
  • 19. Todd Keup :: magnifisites.com Thank You Todd Keup todd@magnifisites.com @toddkeup

Editor's Notes

  1. Good Morning! I want to thank Brett Tabke and his organization for all their hard work in putting a conference like this together. Each time I attend I find myself a beneficiary of the knowledge shared at this gathering. Thanks Brett, for the opportunity to not only be here, but to be here once again as a speaker. I would also like to thank my good friend Ralf Schwoebel for volunteering to facilitate this session as well as my esteemed panel of peers. But most of all thank you for being here today. I am honored by your presence and the privilege to share what I am able regarding CSS and HTML coding today. For those of you that are familiar with the WebmasterWorld web site and the forums at WebmasterWorld, I am an active member and one of the moderators of the PHP Server Side Scripting Forum. I go by the nickname “coopster” and I want you to know that I would absolutely love the opportunity to make your personal acquaintance today. I am approachable and friendly. Please don&apos;t hesitate to introduce yourself.
  2. What is cracking? What is a cracker? What is hacking? What is a hacker? A cracker is a saltine or soda cracker which is a thin, usually square tidbit made from white flour, shortening, yeast, and baking soda, with most varieties lightly sprinkled with coarse salt. And a hacker is an evil computer programmer with nasty intentions. Correct? RFC 1392 Internet Users&apos; Glossary defines: cracker: an individual who attempts to access computer systems without authorization. These individuals are often malicious, as opposed to hackers, and have many means at their disposal for breaking into a system. hacker : A person who delights in having an intimate understanding of the internal workings of a system, computers and computer networks in particular. The term is often misused in a pejorative context, where &quot;cracker&quot; would be the correct term. Over the years the terms have become synonymous and it is a thorn in the side for some programmers. You see, hackers were once recognized as legitimate computer programmers with exceptional skill and good intentions. These white hat code monkeys often refer to programming as hacking, or hacking code, and were proud to be identified as a hacker. Much like a lumberjack might hack wood. As a matter of fact, the original definition for hacker is “one who makes furniture with an ax.” It is the work you perform to make a living. Alas, times have changed. And the terms cracking and hacking have merged into one notorious concept … malicious computer programming. Computer programmers and lumberjacks around the world feel they have been wronged :) Paul Bunyan is not happy. Most programmers nowadays understand that culture has merged these two definitions and accept the fact. But if you ever get one that goes off the deep end when you call him or her a hacker you now know why. By the way, the primary difference between the two is motivation.
  3. What can I do to defend myself ? I will show you ways to protect yourself.
  4. What motivates a cracker? Money Destruction; defacement of websites Extract intellectual property Access customer account information and other data Site administrator passwords which allows full control of the web application Host malicious scripts leading site visitors to download malware SEO gains; inserting links, tracking cookies, etc. Fun. Showing off to peers that share the same lack of ethics and morals.
  5. Tools of the trade include scanner tools which are readily available (meaning free download) to run and install. All a cracker has to do is point the software at your web site. Many crackers will use botnets (compromised computers) and proxy servers to hide their tracks; more on this later.
  6. A very common exploit is SQL Injection and most often they target Open Source Software installations such as Wordpress, phpMyAdmin, Joomla, bulletin boards, etc. Other common attack points include additional software pre-installed on your server.
  7. We are going to take you step-by-step through an SQL Injection. For some of you this may be the first time you have even heard the term so we want to take a moment to show you what it looks like because a picture speaks a thousand words …
  8. Standard login … look familiar? Probably. Most of us use a login similar to this each day. How about this next one, paging? Did you ever think that paging could cause you problems?
  9. The HTML for the standard login form. And on the server side we see how the form value is not filtered and then used in a query.
  10. First you must know that the double dashes here represent standard SQL comment syntax. MySQL has extended the standard syntax for this comment style and requires the second dash to be followed by at least one whitespace or control character (such as a space, tab, newline, and so on). The query will ask for all records because a boolean true value is found in the WHERE clause. Everything after the comment is ignored.
  11. Let&apos;s go back to that paging for a moment. In this case the database connection on the server side has a user that has ability to create other users. See how easy it might be to create a superuser in PostgreSQL? Unescaped input is so dangerous. The zero and semicolon terminate the first statement. Known vulnerabilities are compromised on the database server and the cracker has now added a superuser profile.
  12. Updates can also be compromised. In this example a malicious user goes from resetting their password to gaining privileges. Removing entire tables is possible too. Here the query is expecting an integer for the id value but since the programmer did not properly validate and allows a string to be passed to the query we end up losing our table.
  13. Points of interest: According to PrivacyRights.org SQL Injection contributed to 83% of all successful hacking related data breaches since 2005. A recent study by Imperva discovered an average of almost 71 SQL injection attempts per hour with maximum spikes of 1,300 per hour. Attackers are using much more complex variants now to evade the old &apos;or 1=1&apos;; attempts.
  14. Now what do I do? Cleanup and plug the hole. The faster you can do the latter, the better off you are. However, you may need to do the first before you can do the last. If you find this is not necessary then by all means get your preventive measures in place first! If you find a file has been modified and you didn&apos;t modify it, examine it. Compare it to your last known good copy. If it was a database table entry, check the last update on that entry. Fix the content being delivered to your public visitors, especially if there has been a JavaScript trojan injected into your html documents. Your damage assessment may require you to revert to a last known copy. This is where versioning systems come in extremely handy! Do not forget to change your passwords! Disclaimer: this list is not extensive.
  15. Patching your code might require casting values to types you expect. Here is an example of casting a user-supplied ticket number. Of course, you would probably want to validate more than what you see here. For example, a zip code or date value. You know what it should look like, how many digits in what position, etc. So help your user format as you expect and then validate what has been supplied. The next option shows an example of escaping the data (and casting at the same time) for a MySQL query.
  16. How do I know a compromise has occurred? Oh you&apos;ll know. Remember the motivation discussion earlier? Defaced web site, odd links showing up, new pages, trojan viruses being delivered to end users, etc. Discovery is best when done by monitoring. Monitoring allows you to plug holes you discover first. And hopefully you won&apos;t have to discover compromises later! You can log your form submissions and especially those that are modifying sensitive files or tables, like your users table if you are using a database. If an admin profile is added or updated you might trigger an email or text message yourself. Use your system tools like logwatch. And the same tools used for cracking can be used for prevention. As a matter of fact, many of them were first developed for use in this manner! An example of this is SQLmap, which is one of many free sophisticated SQL detection engines readily available. SQLmap, slqninja, Havij, Pangolin, etc. Identify access patterns of automated tools. You can create and deploy a blacklist of hosts that initiate SQL injection attacks if you would like.
  17. More avoidance techniques: Always use customized users with very limited privileges for database connections. Never trust user-supplied input. Validate everything. If you are expecting an integer value, check for it! Cast it to the proper data type if necessary. And escape the data using string escape functions that are specific to the database to which you are connecting. For example, MySQL is different than DB2. Never dump raw database information to the display such as column (field) names, table names or database names. And structure your application to handle any raw errors and provide user-friendly error messages instead. No, &quot;The Microsoft Sequel Server is temporary unavailable&quot; is not an appropriate message.
  18. Pause for a moment to share some information regarding botnets … Guess which country has the most compromised computers in the world? United States accounts for 58%, followed by Sweden, China, Great Britain and Vietnam. Germany did make the list but tied with the European Union at 1%. A recent study showed that The SQLi attacks observed since July originated from 3,845 hosts. However, the distribution of activity between them is uneven: The top three hosts accounted for 23% of the attacks, and the next seven sources accounted for 18% of the attacks. However, five of these seven hosts are Akamai proxies, so the traffic was just routed through them from the attacker-controlled hosts. (source: Imperva, Anatomy of an SQL Injection Attack)