More Related Content
Similar to Webセキュリティ勉強会SQLインジェクション
Similar to Webセキュリティ勉強会SQLインジェクション (14)
Webセキュリティ勉強会SQLインジェクション
- 9. 4.4.1 SQLインジェクション
2015/11/6 WEBセキュリティ勉強会 第2回 9
user_id passwd
chibat admin
fumo hoge
cynthia piyo
rose fuga
SELECT * FROM user_master WHERE user_id = '{$userId}' AND passwd = '{$passwd}'
通常ログイン時
user_master
- 10. 4.4.1 SQLインジェクション
2015/11/6 WEBセキュリティ勉強会 第2回 10
user_id passwd
chibat admin
fumo hoge
cynthia piyo
rose fuga
SELECT * FROM user_master WHERE user_id = 'fumo' AND passwd = '' OR 'A' = 'A'
SQLインジェクション(認証回避)
user_master
$userId 「fumo」
$passwd 「' OR 'A' = 'A」
悪意ある入力
- 11. 4.4.1 SQLインジェクション
2015/11/6 WEBセキュリティ勉強会 第2回 11
user_id passwd
chibat admin
fumo hoge
cynthia piyo
rose fuga
SELECT * FROM user_master WHERE user_id = 'fumo' AND passwd = '' OR 'A' = 'A'
SQLインジェクション(認証回避)
user_master
$userId 「fumo」
$passwd 「' OR 'A' = 'A」
悪意ある入力
パスワードを入力せずにログインが可能に…
- 12. 4.4.1 SQLインジェクション
2015/11/6 WEBセキュリティ勉強会 第2回 12
user_id passwd
chibat admin
fumo hoge
cynthia piyo
rose fuga
SELECT * FROM user_master WHERE user_id = 'fumo' AND passwd = '';
DELETE FROM user_master WHERE 'A' = 'A
SQLインジェクション(セミコロンで分割)
user_master
$userId「 (何も入力しない) 」
$passwd
「'; DELETE FROM user_master WHERE 'A' = 'A」
悪意ある入力
- 13. 4.4.1 SQLインジェクション
2015/11/6 WEBセキュリティ勉強会 第2回 13
user_id passwd
chibat admin
fumo hoge
cynthia piyo
rose fuga
SELECT * FROM user_master WHERE user_id = 'fumo' AND passwd = '';
DELETE FROM user_master WHERE 'A' = 'A
SQLインジェクション(セミコロンで分割)
user_master
$userId「 (何も入力しない) 」
$passwd
「'; DELETE FROM user_master WHERE 'A' = 'A」
悪意ある入力
DBのデータを改ざんされてしまう
- 14. 4.4.1 SQLインジェクション
2015/11/6 WEBセキュリティ勉強会 第2回 14
user_id passwd
chibat admin
fumo hoge
cynthia piyo
rose fuga
SELECT * FROM user_master WHERE user_id = ''; DELETE FROM user_master WHERE 'A' = 'A’
--'fumo' AND passwd =‘’;
SQLインジェクション(コメントアウトで無効化)
user_master
$userId
「 '; DELETE FROM user_master WHERE 'A' = 'A’ -- 」
$passwd
「 (何も入力しない) 」
悪意ある入力
- 15. 4.4.1 SQLインジェクション
2015/11/6 WEBセキュリティ勉強会 第2回 15
user_id passwd
chibat admin
fumo hoge
cynthia piyo
rose fuga
SELECT * FROM user_master WHERE user_id = ''; DELETE FROM user_master WHERE 'A' = 'A’
--'fumo' AND passwd =‘’;
SQLインジェクション(コメントアウトで無効化)
user_master
$userId
「 '; DELETE FROM user_master WHERE 'A' = 'A’ -- 」
$passwd
「 (何も入力しない) 」
悪意ある入力
コメントアウトで条件文を無効化してしまう
- 16. 4.4.1 SQLインジェクション
2015/11/6 WEBセキュリティ勉強会 第2回 16
user_id passwd
admin admin
fumo hoge
cynthia piyo
rose fuga
UPDATE user_master SET passwd = '{$newPasswd}'
WHERE user_id = '{$userId}' AND passwd = '{$oldPasswd}'
通常データ更新時
user_master
- 17. 4.4.1 SQLインジェクション
2015/11/6 WEBセキュリティ勉強会 第2回 17
user_id passwd
admin admin
fumo hoge
cynthia piyo
rose fuga
UPDATE user_master SET passwd = 'malice'
WHERE user_id = 'rose' AND passwd = 'fuga' OR user_id = 'admin'
SQLインジェクション(シングルクォート挿入)
user_master
$userId 「rose」
$oldPasswd「fuga' OR user_id = 'admin」
$newPasswd「malice」
悪意ある入力
- 18. 4.4.1 SQLインジェクション
2015/11/6 WEBセキュリティ勉強会 第2回 18
user_id passwd
admin
fumo hoge
cynthia piyo
rose
UPDATE user_master SET passwd = 'malice'
WHERE user_id = 'rose' AND passwd = 'fuga' OR user_id = 'admin'
SQLインジェクション(シングルクォート挿入)
user_master
$userId 「rose」
$oldPasswd「fuga' OR user_id = 'admin」
$newPasswd「malice」
悪意ある入力
- 19. 4.4.1 SQLインジェクション
2015/11/6 WEBセキュリティ勉強会 第2回 19
user_id passwd
admin
fumo hoge
cynthia piyo
rose
UPDATE user_master SET passwd = 'malice'
WHERE user_id = 'rose' AND passwd = 'fuga' OR user_id = 'admin'
SQLインジェクション(シングルクォート挿入)
user_master
$userId 「rose」
$oldPasswd「fuga' OR user_id = 'admin」
$newPasswd「malice」
悪意ある入力
管理者のパスワードを変更されてしまう
- 20. 4.4.1 SQLインジェクション
2015/11/6 WEBセキュリティ勉強会 第2回 20
user_id passwd
admin admin
fumo hoge
cynthia piyo
rose fuga
UPDATE user_master SET passwd = 'malice'
WHERE user_id = '' OR 'A' = 'A' --' AND パスワード = ''
SQLインジェクション(コメントアウトで無効化)
user_master
$userId 「' OR 'A' = 'A' --」
$oldPasswd「 (何も入力しない)」
$newPasswd「malice」
悪意ある入力
- 21. 4.4.1 SQLインジェクション
2015/11/6 WEBセキュリティ勉強会 第2回 21
user_id passwd
admin
fumo
cynthia
rose
UPDATE user_master SET passwd = 'malice'
WHERE user_id = '' OR 'A' = 'A' --' AND パスワード = ''
SQLインジェクション(コメントアウトで無効化)
user_master
$userId 「' OR 'A' = 'A' --」
$oldPasswd「 (何も入力しない)」
$newPasswd「malice」
悪意ある入力
- 22. 4.4.1 SQLインジェクション
2015/11/6 WEBセキュリティ勉強会 第2回 22
user_id passwd
admin
fumo
cynthia
rose
UPDATE user_master SET passwd = 'malice'
WHERE user_id = '' OR 'A' = 'A' --' AND パスワード = ''
SQLインジェクション(コメントアウトで無効化)
user_master
$userId 「' OR 'A' = 'A' --」
$oldPasswd「 (何も入力しない)」
$newPasswd「malice」
悪意ある入力
ユーザー全員のパスワードを変更されてしまう
- 25. 4.4.1 SQLインジェクション
2015/11/6 WEBセキュリティ勉強会 第2回 25
対策1 :プレースホルダ1(ログイン時)
$sth = $mdb2->prepare(
'SELECT userid, username, profile FROM users WHERE username LIKE :username',
array('username' => 'text'),
array('integer', 'text', 'text')
);
$res = $sth->execute(
array('username' => '%' . $mdb2->escapePattern($_REQUEST['username']) . '%')
);
$all = $res->fetchAll();
$sth->free();
- 26. 4.4.1 SQLインジェクション
2015/11/6 WEBセキュリティ勉強会 第2回 26
対策1 :プレースホルダ1(ログイン時)
$sth = $mdb2->prepare(
'SELECT userid, username, profile FROM users WHERE username LIKE :username',
array('username' => 'text'),
array('integer', 'text', 'text')
);
$res = $sth->execute(
array('username' => '%' . $mdb2->escapePattern($_REQUEST['username']) . '%')
);
$all = $res->fetchAll();
$sth->free();
プレースホルダ
バインド
- 27. 4.4.1 SQLインジェクション
2015/11/6 WEBセキュリティ勉強会 第2回 27
対策1 :プレースホルダ2(ログイン時)
$sth = $mdb2->prepare(
'SELECT userid, username, profile FROM users WHERE username LIKE ?',
array('text'),
MDB2_PREPARE_RESULT
);
$res = $sth->execute('%' . $mdb2->escapePattern($_REQUEST['username']) . '%');
$all = $res->fetchAll();
$sth->free();
- 28. 4.4.1 SQLインジェクション
2015/11/6 WEBセキュリティ勉強会 第2回 28
対策1 :プレースホルダ2(ログイン時)
$sth = $mdb2->prepare(
'SELECT userid, username, profile FROM users WHERE username LIKE ?',
array('text'),
MDB2_PREPARE_RESULT
);
$res = $sth->execute('%' . $mdb2->escapePattern($_REQUEST['username']) . '%');
$all = $res->fetchAll();
$sth->free();
プレースホルダ
バインド