SlideShare a Scribd company logo
Prepared Statement
올바르게 사용해보기
SELECT name
FROM cnu_dept_computer
JOIN argos
ON cnu_dept_computer.sid=argos.member_sid
AND sid=201704150; name='허강준'
ARGOS / DaeChoongCon@CNU0x00000FF @0x00000FF
1st_DCCon_0706_2019
Recommended_For =
DB를 이용한 프로그래밍에 입문하신 분들
어느정도 감을 잡고 좀 더 안전한 코딩을 원하시는 분들
조그만 실수 하나까지 바로잡고 싶으신 분들
// PHP와 SQL을 알고 있거나 막 배웠다면 더욱 잘 이해 가능
2
ARGOS / DaeChoongCon@CNU
Contents =
Array (
[0] => “SQL Injection”,
[1] => “Prepared Statement”,
[2] => “For Performance”,
[3] => “About Missable Vulnerability”
);
3
ARGOS / DaeChoongCon@CNU
SQL_Injection =
• SQL 쿼리에 공격을 위한 SQL을 Injection 하는 공격
• DB를 자유자재로 조작할 수 있어 파괴력이 강함
(임의 실행, 데이터 탈취, 인증 우회 등…)
4
ARGOS / DaeChoongCon@CNU
$sample --sql_injection
// vulnerable_signin.php
$id = $_POST[“user_id”];
$pw = $_POST[“user_pw”];
$query = mysqli_query($conn, “SELECT * FROM users WHERE id=‘$id’ AND pw=‘$pw’”);
if ($query->num_rows === 0) {
// do something when signing fails...
exit;
}
// do something to make status is signed in...
5
ARGOS / DaeChoongCon@CNU
$sample --sql_injection
$id = “admin’;-- ”;
$pw = “1234”;
$query = $conn->query(“SELECT * FROM users WHERE id=‘$id’ AND pw=‘$pw’”);
SELECT * FROM users WHERE id=‘admin’;-- ’ AND pw=‘1234’SELECT * FROM users WHERE id=‘admin’;-- ’ AND pw=‘1234’
6
ARGOS / DaeChoongCon@CNU
Protection =
• 신뢰할 수 없는 데이터를 쿼리에 포함하지 않기
• 입력 데이터를 이스케이핑 하기
• Prepared Statement 사용하기
• 기타등등…
7
ARGOS / DaeChoongCon@CNU
Prepared_Statement =
8
SELECT *
FROM daechoong_con_tbl
WHERE attr_1=? AND attr_2 LIKE CONCAT(‘%’, ?, ‘%’);
Execute with Parameters
Compile
Result
Parameterized Query
ARGOS / DaeChoongCon@CNU
Prepared_Statement =
9
// prepared_signin.php
$id = $_POST[“user_id”];
$pw = $_POST[“user_pw”];
$stmt = $conn->prepare(“SELECT * FROM users WHERE id=? AND pw=?”);
$stmt->bind_param(“ss”, $id, $pw);
$stmt->execute();
if ($query->num_rows === 0) {
// do something when signing fails...
exit;
}
// do something to make status is signed in...
ARGOS / DaeChoongCon@CNU
Better way to use?
ARGOS / DaeChoongCon@CNU
Useless_Prepared_Statement =
ARGOS / DaeChoongCon@CNU
11
• Prepared Statement는 빠르다.
• 쿼리가 Compile & Evaluation 되는 과정이 한번만 일어남
• 이후 백엔드 시스템에서 Parameter만 Binding되어 동작
• 그러나 한번만 쓰고 버려지는 쿼리라면?
Useless_Prepared_Statement =
12
$date = date(“Y”);
// slow_select.php
$stmt = $conn->prepare(“SELECT * FROM notes WHERE year=?”);
$stmt->bind_param(“s”, $date);
$stmt->execute();
// better_select.php
$stmt = $conn->query(“SELECT * FROM notes WHERE year=$date”);
ARGOS / DaeChoongCon@CNU
Useless_Prepared_Statement =
ARGOS / DaeChoongCon@CNU
13
10000 times of iteration 1 2 3 4 5 AVG.
불필요한 Prepared Statement 945 1013 935 909 895 939.4
단순 Concat 쿼리 475 490 469 502 472 481.6
* https://b.patche.me/ups
(miliseconds)
* 로컬 MariaDB, PHP 7.2.18에서 테스트되었음.
Useless_Prepared_Statement =
ARGOS / DaeChoongCon@CNU
14
10000 times of iteration 1 2 3 4 5 AVG.
PS with Loop 359 377 374 371 383 372.8
(miliseconds)
* 로컬 MariaDB, PHP 7.2.18에서 테스트되었음.
* https://b.patche.me/upsp
Useless_Prepared_Statement =
ARGOS / DaeChoongCon@CNU
15
function auto_statement($conn, $query, ...$args) {
// if (args !== null) -> return prepared statement object
// if (args === null) -> return query result object
}
auto_statement($conn, $query, $param1, ...); // mysqli::stmt object
auto_statement($conn, $query); // mysqli::result object
Using_For_Procedures =
16
-- vulnerable_procedure.sql
-- DELIMITER //
CREATE OR REPLACE PROCEDURE create_private_table(
table_name TEXT
) BEGIN
SET @SQL = CONCAT(‘CREATE TABLE ’, table_name, ‘_ptable (...’);
PREPARE stmt FROM @SQL;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END; //
ARGOS / DaeChoongCon@CNU
Using_For_Procedures =
17
// freaking_great.php
$stmt = $conn->prepare(“CALL create_private_table(?)”);
$stmt->bind_param(“s”, $_POST[“id”]);
ARGOS / DaeChoongCon@CNU
$stmt->bind_param(“s”, “pwned(id int)-- &#x20”);
SET @SQL := CONCAT(‘CREATE TABLE ’, table_name, ‘_ptable (...’);SET @SQL := ‘CREATE TABLE pwned(id int)-- &_ptable (...’;CREATE TABLE pwned(id int)-- &_ptable (...’;
Using_For_Procedures =
18
ARGOS / DaeChoongCon@CNU
• https://b.patche.me/ufp
$datetime = date("Ymdhisv");
$query = "pwned_$datetime(id int, c varchar(35)); -- ";
$stmt = mysqli_prepare($conn, "CALL create_private_table(?)");
CREATE PROCEDURE create_private_table (
table_name TEXT
)
BEGIN
SET @query = CONCAT('CREATE TABLE ', table_name ,'_ptable (k int)');
PREPARE stmt FROM @query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END;
Using_For_Procedures =
19
ARGOS / DaeChoongCon@CNU
• https://b.patche.me/ufpp
$datetime = date("Ymdhisv");
$query = "pwned_$datetime(id int, c varchar(35)); -- ";
CREATE PROCEDURE create_private_table_p (
table_name VARCHAR(16)
)
BEGIN
SET @query = CONCAT('CREATE TABLE ', table_name ,'_ptable (k int)');
PREPARE stmt FROM @query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END;
Using_For_Procedures =
20
ARGOS / DaeChoongCon@CNU
member_tbl
member_id
…
…
…
CALL create_private_table(?);
Record Exists
Nah
http_response_code(404);
SELECT member_id
FROM member_tbl
WHERE member_id=?
Conclusion =
21
ARGOS / DaeChoongCon@CNU
Array (
[0] => “성능을 위해 상황에 맞추어” .
“Prepared Statement 사용하기”,
[1] => “놓치기 쉬운 취약점에 대비하기 위해” .
“신뢰할 수 없는 데이터에 항상 주의하기”
);
QnA
ARGOS / DaeChoongCon@CNU
Thank you!_Happy Hacking!
ARGOS / DaeChoongCon@CNU

More Related Content

What's hot

Agile database access with CakePHP 3
Agile database access with CakePHP 3Agile database access with CakePHP 3
Agile database access with CakePHP 3
José Lorenzo Rodríguez Urdaneta
 
15. CodeIgniter editarea inregistrarilor
15. CodeIgniter editarea inregistrarilor15. CodeIgniter editarea inregistrarilor
15. CodeIgniter editarea inregistrarilor
Razvan Raducanu, PhD
 
Quebec pdo
Quebec pdoQuebec pdo
Quebec pdo
Valentine Dianov
 
Xmpp prebind
Xmpp prebindXmpp prebind
Xmpp prebind
Syed Arshad
 
21. CodeIgniter search
21. CodeIgniter search21. CodeIgniter search
21. CodeIgniter search
Razvan Raducanu, PhD
 
Doctrine 2
Doctrine 2Doctrine 2
Doctrine 2
zfconfua
 
CakeFest 2013 keynote
CakeFest 2013 keynoteCakeFest 2013 keynote
CakeFest 2013 keynote
José Lorenzo Rodríguez Urdaneta
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data Objects
Wez Furlong
 
Solr integration in Magento Enterprise
Solr integration in Magento EnterpriseSolr integration in Magento Enterprise
Solr integration in Magento Enterprise
Tobias Zander
 
London XQuery Meetup: Querying the World (Web Scraping)
London XQuery Meetup: Querying the World (Web Scraping)London XQuery Meetup: Querying the World (Web Scraping)
London XQuery Meetup: Querying the World (Web Scraping)
Dennis Knochenwefel
 
New in cakephp3
New in cakephp3New in cakephp3
New in cakephp3
markstory
 
ランダム文字ぽいものをつくる
ランダム文字ぽいものをつくるランダム文字ぽいものをつくる
ランダム文字ぽいものをつくる
Tetsuji Koyama
 
Codeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept ImplementationCodeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept Implementation
Abdul Malik Ikhsan
 
Advanced Querying with CakePHP 3
Advanced Querying with CakePHP 3Advanced Querying with CakePHP 3
Advanced Querying with CakePHP 3
José Lorenzo Rodríguez Urdaneta
 
Php Mysql
Php Mysql Php Mysql
Php Mysql
Mudasir Syed
 
Php unit the-mostunknownparts
Php unit the-mostunknownpartsPhp unit the-mostunknownparts
Php unit the-mostunknownparts
Bastian Feder
 
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Mail.ru Group
 
Coding website
Coding websiteCoding website
Coding website
PutuMahendra Wijaya
 
Codeigniter : Using Third Party Components - Zend Framework Components
Codeigniter : Using Third Party Components - Zend Framework ComponentsCodeigniter : Using Third Party Components - Zend Framework Components
Codeigniter : Using Third Party Components - Zend Framework Components
Abdul Malik Ikhsan
 
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
smueller_sandsmedia
 

What's hot (20)

Agile database access with CakePHP 3
Agile database access with CakePHP 3Agile database access with CakePHP 3
Agile database access with CakePHP 3
 
15. CodeIgniter editarea inregistrarilor
15. CodeIgniter editarea inregistrarilor15. CodeIgniter editarea inregistrarilor
15. CodeIgniter editarea inregistrarilor
 
Quebec pdo
Quebec pdoQuebec pdo
Quebec pdo
 
Xmpp prebind
Xmpp prebindXmpp prebind
Xmpp prebind
 
21. CodeIgniter search
21. CodeIgniter search21. CodeIgniter search
21. CodeIgniter search
 
Doctrine 2
Doctrine 2Doctrine 2
Doctrine 2
 
CakeFest 2013 keynote
CakeFest 2013 keynoteCakeFest 2013 keynote
CakeFest 2013 keynote
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data Objects
 
Solr integration in Magento Enterprise
Solr integration in Magento EnterpriseSolr integration in Magento Enterprise
Solr integration in Magento Enterprise
 
London XQuery Meetup: Querying the World (Web Scraping)
London XQuery Meetup: Querying the World (Web Scraping)London XQuery Meetup: Querying the World (Web Scraping)
London XQuery Meetup: Querying the World (Web Scraping)
 
New in cakephp3
New in cakephp3New in cakephp3
New in cakephp3
 
ランダム文字ぽいものをつくる
ランダム文字ぽいものをつくるランダム文字ぽいものをつくる
ランダム文字ぽいものをつくる
 
Codeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept ImplementationCodeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept Implementation
 
Advanced Querying with CakePHP 3
Advanced Querying with CakePHP 3Advanced Querying with CakePHP 3
Advanced Querying with CakePHP 3
 
Php Mysql
Php Mysql Php Mysql
Php Mysql
 
Php unit the-mostunknownparts
Php unit the-mostunknownpartsPhp unit the-mostunknownparts
Php unit the-mostunknownparts
 
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
 
Coding website
Coding websiteCoding website
Coding website
 
Codeigniter : Using Third Party Components - Zend Framework Components
Codeigniter : Using Third Party Components - Zend Framework ComponentsCodeigniter : Using Third Party Components - Zend Framework Components
Codeigniter : Using Third Party Components - Zend Framework Components
 
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
 

Similar to Prepared Statement 올바르게 사용하기

Creating "Secure" PHP Applications, Part 1, Explicit Code & QA
Creating "Secure" PHP Applications, Part 1, Explicit Code & QACreating "Secure" PHP Applications, Part 1, Explicit Code & QA
Creating "Secure" PHP Applications, Part 1, Explicit Code & QA
archwisp
 
Sydney Oracle Meetup - execution plans
Sydney Oracle Meetup - execution plansSydney Oracle Meetup - execution plans
Sydney Oracle Meetup - execution plans
paulguerin
 
Nko workshop - node js crud & deploy
Nko workshop - node js crud & deployNko workshop - node js crud & deploy
Nko workshop - node js crud & deploy
Simon Su
 
PHP CLI: A Cinderella Story
PHP CLI: A Cinderella StoryPHP CLI: A Cinderella Story
PHP CLI: A Cinderella Story
Mike Lively
 
Javascript Continues Integration in Jenkins with AngularJS
Javascript Continues Integration in Jenkins with AngularJSJavascript Continues Integration in Jenkins with AngularJS
Javascript Continues Integration in Jenkins with AngularJS
Ladislav Prskavec
 
Php Security By Mugdha And Anish
Php Security By Mugdha And AnishPhp Security By Mugdha And Anish
Php Security By Mugdha And Anish
OSSCube
 
DevOps Fest 2019. Сергей Марченко. Terraform: a novel about modules, provider...
DevOps Fest 2019. Сергей Марченко. Terraform: a novel about modules, provider...DevOps Fest 2019. Сергей Марченко. Terraform: a novel about modules, provider...
DevOps Fest 2019. Сергей Марченко. Terraform: a novel about modules, provider...
DevOps_Fest
 
Postman On Steroids
Postman On SteroidsPostman On Steroids
Postman On Steroids
Sara Tornincasa
 
Best Practices in Plugin Development (WordCamp Seattle)
Best Practices in Plugin Development (WordCamp Seattle)Best Practices in Plugin Development (WordCamp Seattle)
Best Practices in Plugin Development (WordCamp Seattle)
andrewnacin
 
Configuring Django projects for multiple environments
Configuring Django projects for multiple environmentsConfiguring Django projects for multiple environments
Configuring Django projects for multiple environments
Apptension
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websites
Lindsay Holmwood
 
SQL Injection: complete walkthrough (not only) for PHP developers
SQL Injection: complete walkthrough (not only) for PHP developersSQL Injection: complete walkthrough (not only) for PHP developers
SQL Injection: complete walkthrough (not only) for PHP developers
Krzysztof Kotowicz
 
Service discovery and configuration provisioning
Service discovery and configuration provisioningService discovery and configuration provisioning
Service discovery and configuration provisioning
Source Ministry
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
Lukas Smith
 
Php Security
Php SecurityPhp Security
Php Security
guest7cf35c
 
Running Django on Docker: a workflow and code
Running Django on Docker: a workflow and codeRunning Django on Docker: a workflow and code
Running Django on Docker: a workflow and code
Danielle Madeley
 
Oracle PL/SQL - Creative Conditional Compilation
Oracle PL/SQL - Creative Conditional CompilationOracle PL/SQL - Creative Conditional Compilation
Oracle PL/SQL - Creative Conditional Compilation
Scott Wesley
 
Future of Web Apps: Google Gears
Future of Web Apps: Google GearsFuture of Web Apps: Google Gears
Future of Web Apps: Google Gears
dion
 
Php frameworks
Php frameworksPhp frameworks
Php frameworks
Anil Kumar Panigrahi
 
Quebec pdo
Quebec pdoQuebec pdo
Quebec pdo
Rengga Aditya
 

Similar to Prepared Statement 올바르게 사용하기 (20)

Creating "Secure" PHP Applications, Part 1, Explicit Code & QA
Creating "Secure" PHP Applications, Part 1, Explicit Code & QACreating "Secure" PHP Applications, Part 1, Explicit Code & QA
Creating "Secure" PHP Applications, Part 1, Explicit Code & QA
 
Sydney Oracle Meetup - execution plans
Sydney Oracle Meetup - execution plansSydney Oracle Meetup - execution plans
Sydney Oracle Meetup - execution plans
 
Nko workshop - node js crud & deploy
Nko workshop - node js crud & deployNko workshop - node js crud & deploy
Nko workshop - node js crud & deploy
 
PHP CLI: A Cinderella Story
PHP CLI: A Cinderella StoryPHP CLI: A Cinderella Story
PHP CLI: A Cinderella Story
 
Javascript Continues Integration in Jenkins with AngularJS
Javascript Continues Integration in Jenkins with AngularJSJavascript Continues Integration in Jenkins with AngularJS
Javascript Continues Integration in Jenkins with AngularJS
 
Php Security By Mugdha And Anish
Php Security By Mugdha And AnishPhp Security By Mugdha And Anish
Php Security By Mugdha And Anish
 
DevOps Fest 2019. Сергей Марченко. Terraform: a novel about modules, provider...
DevOps Fest 2019. Сергей Марченко. Terraform: a novel about modules, provider...DevOps Fest 2019. Сергей Марченко. Terraform: a novel about modules, provider...
DevOps Fest 2019. Сергей Марченко. Terraform: a novel about modules, provider...
 
Postman On Steroids
Postman On SteroidsPostman On Steroids
Postman On Steroids
 
Best Practices in Plugin Development (WordCamp Seattle)
Best Practices in Plugin Development (WordCamp Seattle)Best Practices in Plugin Development (WordCamp Seattle)
Best Practices in Plugin Development (WordCamp Seattle)
 
Configuring Django projects for multiple environments
Configuring Django projects for multiple environmentsConfiguring Django projects for multiple environments
Configuring Django projects for multiple environments
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websites
 
SQL Injection: complete walkthrough (not only) for PHP developers
SQL Injection: complete walkthrough (not only) for PHP developersSQL Injection: complete walkthrough (not only) for PHP developers
SQL Injection: complete walkthrough (not only) for PHP developers
 
Service discovery and configuration provisioning
Service discovery and configuration provisioningService discovery and configuration provisioning
Service discovery and configuration provisioning
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
 
Php Security
Php SecurityPhp Security
Php Security
 
Running Django on Docker: a workflow and code
Running Django on Docker: a workflow and codeRunning Django on Docker: a workflow and code
Running Django on Docker: a workflow and code
 
Oracle PL/SQL - Creative Conditional Compilation
Oracle PL/SQL - Creative Conditional CompilationOracle PL/SQL - Creative Conditional Compilation
Oracle PL/SQL - Creative Conditional Compilation
 
Future of Web Apps: Google Gears
Future of Web Apps: Google GearsFuture of Web Apps: Google Gears
Future of Web Apps: Google Gears
 
Php frameworks
Php frameworksPhp frameworks
Php frameworks
 
Quebec pdo
Quebec pdoQuebec pdo
Quebec pdo
 

Recently uploaded

Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
Nada Hikmah
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
KrishnaveniKrishnara1
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
gray level transformation unit 3(image processing))
gray level transformation unit 3(image processing))gray level transformation unit 3(image processing))
gray level transformation unit 3(image processing))
shivani5543
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
co23btech11018
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
Hematology Analyzer Machine - Complete Blood Count
Hematology Analyzer Machine - Complete Blood CountHematology Analyzer Machine - Complete Blood Count
Hematology Analyzer Machine - Complete Blood Count
shahdabdulbaset
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
gerogepatton
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
sachin chaurasia
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
ecqow
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
Introduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptxIntroduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptx
MiscAnnoy1
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
Mahmoud Morsy
 

Recently uploaded (20)

Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
gray level transformation unit 3(image processing))
gray level transformation unit 3(image processing))gray level transformation unit 3(image processing))
gray level transformation unit 3(image processing))
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
Hematology Analyzer Machine - Complete Blood Count
Hematology Analyzer Machine - Complete Blood CountHematology Analyzer Machine - Complete Blood Count
Hematology Analyzer Machine - Complete Blood Count
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
Introduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptxIntroduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptx
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
 

Prepared Statement 올바르게 사용하기

  • 1. Prepared Statement 올바르게 사용해보기 SELECT name FROM cnu_dept_computer JOIN argos ON cnu_dept_computer.sid=argos.member_sid AND sid=201704150; name='허강준' ARGOS / DaeChoongCon@CNU0x00000FF @0x00000FF 1st_DCCon_0706_2019
  • 2. Recommended_For = DB를 이용한 프로그래밍에 입문하신 분들 어느정도 감을 잡고 좀 더 안전한 코딩을 원하시는 분들 조그만 실수 하나까지 바로잡고 싶으신 분들 // PHP와 SQL을 알고 있거나 막 배웠다면 더욱 잘 이해 가능 2 ARGOS / DaeChoongCon@CNU
  • 3. Contents = Array ( [0] => “SQL Injection”, [1] => “Prepared Statement”, [2] => “For Performance”, [3] => “About Missable Vulnerability” ); 3 ARGOS / DaeChoongCon@CNU
  • 4. SQL_Injection = • SQL 쿼리에 공격을 위한 SQL을 Injection 하는 공격 • DB를 자유자재로 조작할 수 있어 파괴력이 강함 (임의 실행, 데이터 탈취, 인증 우회 등…) 4 ARGOS / DaeChoongCon@CNU
  • 5. $sample --sql_injection // vulnerable_signin.php $id = $_POST[“user_id”]; $pw = $_POST[“user_pw”]; $query = mysqli_query($conn, “SELECT * FROM users WHERE id=‘$id’ AND pw=‘$pw’”); if ($query->num_rows === 0) { // do something when signing fails... exit; } // do something to make status is signed in... 5 ARGOS / DaeChoongCon@CNU
  • 6. $sample --sql_injection $id = “admin’;-- ”; $pw = “1234”; $query = $conn->query(“SELECT * FROM users WHERE id=‘$id’ AND pw=‘$pw’”); SELECT * FROM users WHERE id=‘admin’;-- ’ AND pw=‘1234’SELECT * FROM users WHERE id=‘admin’;-- ’ AND pw=‘1234’ 6 ARGOS / DaeChoongCon@CNU
  • 7. Protection = • 신뢰할 수 없는 데이터를 쿼리에 포함하지 않기 • 입력 데이터를 이스케이핑 하기 • Prepared Statement 사용하기 • 기타등등… 7 ARGOS / DaeChoongCon@CNU
  • 8. Prepared_Statement = 8 SELECT * FROM daechoong_con_tbl WHERE attr_1=? AND attr_2 LIKE CONCAT(‘%’, ?, ‘%’); Execute with Parameters Compile Result Parameterized Query ARGOS / DaeChoongCon@CNU
  • 9. Prepared_Statement = 9 // prepared_signin.php $id = $_POST[“user_id”]; $pw = $_POST[“user_pw”]; $stmt = $conn->prepare(“SELECT * FROM users WHERE id=? AND pw=?”); $stmt->bind_param(“ss”, $id, $pw); $stmt->execute(); if ($query->num_rows === 0) { // do something when signing fails... exit; } // do something to make status is signed in... ARGOS / DaeChoongCon@CNU
  • 10. Better way to use? ARGOS / DaeChoongCon@CNU
  • 11. Useless_Prepared_Statement = ARGOS / DaeChoongCon@CNU 11 • Prepared Statement는 빠르다. • 쿼리가 Compile & Evaluation 되는 과정이 한번만 일어남 • 이후 백엔드 시스템에서 Parameter만 Binding되어 동작 • 그러나 한번만 쓰고 버려지는 쿼리라면?
  • 12. Useless_Prepared_Statement = 12 $date = date(“Y”); // slow_select.php $stmt = $conn->prepare(“SELECT * FROM notes WHERE year=?”); $stmt->bind_param(“s”, $date); $stmt->execute(); // better_select.php $stmt = $conn->query(“SELECT * FROM notes WHERE year=$date”); ARGOS / DaeChoongCon@CNU
  • 13. Useless_Prepared_Statement = ARGOS / DaeChoongCon@CNU 13 10000 times of iteration 1 2 3 4 5 AVG. 불필요한 Prepared Statement 945 1013 935 909 895 939.4 단순 Concat 쿼리 475 490 469 502 472 481.6 * https://b.patche.me/ups (miliseconds) * 로컬 MariaDB, PHP 7.2.18에서 테스트되었음.
  • 14. Useless_Prepared_Statement = ARGOS / DaeChoongCon@CNU 14 10000 times of iteration 1 2 3 4 5 AVG. PS with Loop 359 377 374 371 383 372.8 (miliseconds) * 로컬 MariaDB, PHP 7.2.18에서 테스트되었음. * https://b.patche.me/upsp
  • 15. Useless_Prepared_Statement = ARGOS / DaeChoongCon@CNU 15 function auto_statement($conn, $query, ...$args) { // if (args !== null) -> return prepared statement object // if (args === null) -> return query result object } auto_statement($conn, $query, $param1, ...); // mysqli::stmt object auto_statement($conn, $query); // mysqli::result object
  • 16. Using_For_Procedures = 16 -- vulnerable_procedure.sql -- DELIMITER // CREATE OR REPLACE PROCEDURE create_private_table( table_name TEXT ) BEGIN SET @SQL = CONCAT(‘CREATE TABLE ’, table_name, ‘_ptable (...’); PREPARE stmt FROM @SQL; EXECUTE stmt; DEALLOCATE PREPARE stmt; END; // ARGOS / DaeChoongCon@CNU
  • 17. Using_For_Procedures = 17 // freaking_great.php $stmt = $conn->prepare(“CALL create_private_table(?)”); $stmt->bind_param(“s”, $_POST[“id”]); ARGOS / DaeChoongCon@CNU $stmt->bind_param(“s”, “pwned(id int)-- &#x20”); SET @SQL := CONCAT(‘CREATE TABLE ’, table_name, ‘_ptable (...’);SET @SQL := ‘CREATE TABLE pwned(id int)-- &_ptable (...’;CREATE TABLE pwned(id int)-- &_ptable (...’;
  • 18. Using_For_Procedures = 18 ARGOS / DaeChoongCon@CNU • https://b.patche.me/ufp $datetime = date("Ymdhisv"); $query = "pwned_$datetime(id int, c varchar(35)); -- "; $stmt = mysqli_prepare($conn, "CALL create_private_table(?)"); CREATE PROCEDURE create_private_table ( table_name TEXT ) BEGIN SET @query = CONCAT('CREATE TABLE ', table_name ,'_ptable (k int)'); PREPARE stmt FROM @query; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
  • 19. Using_For_Procedures = 19 ARGOS / DaeChoongCon@CNU • https://b.patche.me/ufpp $datetime = date("Ymdhisv"); $query = "pwned_$datetime(id int, c varchar(35)); -- "; CREATE PROCEDURE create_private_table_p ( table_name VARCHAR(16) ) BEGIN SET @query = CONCAT('CREATE TABLE ', table_name ,'_ptable (k int)'); PREPARE stmt FROM @query; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
  • 20. Using_For_Procedures = 20 ARGOS / DaeChoongCon@CNU member_tbl member_id … … … CALL create_private_table(?); Record Exists Nah http_response_code(404); SELECT member_id FROM member_tbl WHERE member_id=?
  • 21. Conclusion = 21 ARGOS / DaeChoongCon@CNU Array ( [0] => “성능을 위해 상황에 맞추어” . “Prepared Statement 사용하기”, [1] => “놓치기 쉬운 취약점에 대비하기 위해” . “신뢰할 수 없는 데이터에 항상 주의하기” );
  • 23. Thank you!_Happy Hacking! ARGOS / DaeChoongCon@CNU