SQL Injection Attack
Friday, 28 May 2010 18:46
SQL Injection ဆိုတာ ဘာလဲ မေျပာခင္ ဒီ youtube movie ေလးကို အရင္ၾကည့္လိုက္ၾကရေအာင္။ ကြၽန္ေတာ္
တစ္ခုၾကိဳေျပာခ်င္တာက သူခိုးလမ္းျပလုပ္တာ မဟုတ္ပါဘူး။ ကြၽန္ေတာ္တို႔ ဒီလိုမ်ိဳး attack ကို awareness ရွိျပီး
ၾကိဳတင္ကာကြယ္ႏိုင္ေစဖို႔ ရည္ရြယ္ျပီး ေရးလိုက္ ပါတယ္။
ကြၽန္ေတာ္တို႔ database application ေရးတဲ့ အခါ မပါမျဖစ္ ေရးရတဲ့ SQL Query ေတြကို အနည္းငယ္ ေျပာင္းလဲလိုက္ျပီး attack လုပ္တာ
ျဖစ္ပါတယ္။ SQL injection attack လုပ္ဖို႔ အတြက္ DBA တစ္ေယာက္လိုမ်ိဳး database သေဘာ တရားေတြ နားလည္ေနစရာ မလိုပဲ query
မွာ ရွိေနတဲ့ condition ေတြကို ေျပာင္းသြားဖို႔ ေလာက္ကို ေရးႏိုင္ရင္ အလုပ္ျဖစ္ပါတယ္။ အထက္မွာ ျပခဲ့တဲ့ movie ေလးအတိုင္းေပါ့။ SELECT fieldlist
ဥပမာ ေလးနဲ႔ ၾကည့္ရေအာင္
FROM table
WHERE field = 'zack@gmail.com';
ဒါက ကြၽန္ေတာ္တို႔ စစ္ေနၾက where clause ပုံစံပါ zack@gmail.com နဲ႔ တူမွ အလုပ္လုပ္မွာပါ။ အဲဒါကို ဒါမ်ိဳးေလး ေျပာင္းၾကည့္လိုက္ ၾကရေအာင္
SELECT fieldlist
FROM table
WHERE field = 'anything' OR 'x'='x';
သေဘာက ေနာက္ကေန OR ကိုထည့္ လိုက္ျပီး အျမဲမွန္ ေနတဲ့ condition တခုကို ထည့္ေပးလိုက္တာ ျဖစ္ပါတယ္။ အဲဒီလိုလုပ္လိုက္ေတာ့
ေရွ႕က condition က ျဖစ္ခ်င္တာ ျဖစ္ေပမယ့္ ေနာက္က OR ေၾကာင့္ အလုပ္လုပ္ပါမယ္။ SELECT * FROM user WHERE user_name = 'zack'
SELECT * FROM user WHERE user_name = 'anything' OR '1'='1';
ဒုတိယ query မွာ OR ေၾကာင့္ result ေတြထြက္ လာပါလိမ့္မယ္။
ဒီထက္ပိုျပီး ရက္စက္ခ်င္ တယ္ဆိုရင္ ေနာက္ကေန delete, drop စတဲ့ query ေတြကို ထည့္ေပးလိုက္လို႕ ရပါတယ္။ ဒီ example ကို
ၾကည့္လိုက္ရေအာင္။ SELECT email, passwd, login_id, full_name FROM members
WHERE email = 'x';
DELETE from members;
အဲလို႕ေရးလိုက္ရင္ ေရွ႕က query ကျဖစ္ခ်င္တာ ျဖစ္ေနလဲ ေနာက္က delete query run သြားပါမယ္။ အဲဒါဆိုရင္ေတာ့ data ေတြ ကုန္ျပီသာ
မွတ္ေပေတာ့။ကြၽန္ေတာ္ ကိုယ္တိုင္ အဲလိုမ်ိဳး SQL Injection Attack လုပ္တာကို ခံခဲ့ရဘူးပါတယ္။ ရုံးက application အေဟာင္းေတြက
SQL Injection ေတြကို ေပါက္ေနပါတယ္။ လုပ္တဲ့ ေကာင္ကလဲ delete ကိုခ်သြားတာ ကုန္ေရာပဲဗ်ာ။ကဲ ဒီေတာ့ အနာသိရင္ ေဆးရွိပါတယ္။
How to prevent SQL Injection?
PHP မွာ SQL Injection ကိုကာဖို႔ mysql_real_escape_string ဆိုတဲ့ function ေလးရွိတယ္။ အဲဒီ function ကေန \ ေလးေတြ auto ေပါင္းထည့္ ေပးသြားပါမယ္။ ဒီလိုေလးေတြ ေျပာင္းသြားပါမယ္။ SELECT * FROM customers WHERE username = '\' OR 1\''
SELECT * FROM customers WHERE username = '\'; DELETE FROM customers WHERE 1 or username = \''
mysql_real_escape_string ကိုသုံးျပီး SQL Injection Attack ကိုကာကြယ္ႏိုင္ဖို႔ ဒီ Post ေလးကို ေရးလိုက္ပါတယ္။ အသုံးမ်ားေသာ SQL Injection character မ်ား
| Input character | Meaning in Transact-SQL |
|---|---|
| ; | Query delimiter. |
|
' |
Character data string delimiter. |
| -- | Comment delimiter. |
| /* ... */ | Comment delimiters. Text between /* and */ is not evaluated by the server. |
-
2010-06-01 11:16:44 |SAdministrator| admin - Re: everlearner
ဟုတ္.. ၾကိဳတင္ကာကြယ္ျခင္းက ကုသျခင္းထက္ ပိုထိေရာက္တယ္ဆိုတဲ့ စကား အတိုင္းေပါ့။ ... အကိုေပးတဲ့ Link နဲ႔ power point slide ကေတာ္ေတာ္ေကာင္း တယ္ဗ်။ power point ကေတာ့ တဝက္ၾကည့္ျပီးျပီ။ XSS အေၾကာင္းေလး ဆက္ေရးမယ္ အကို
-
For XSS, there are some articles I wrote in http://sharingtofrds.blogspot.com/search/label/XSS. At that time, I wrote from user point of view. (I kept that blog for my first blogging day memories). I believe you can write from web application developer point of view. Thanks.
-
2010-06-01 13:24:09 |SAdministrator| admin - Re: everlearner
အကိုေရးထားတာ ေတာ္ေတာ္စုံလင္တာပဲ ကြၽန္ေတာ္ reference လုပ္ျပီး ျပန္ေရးမယ္။ ေက်းဇူး အကို
-
2010-09-12 22:30:27 |203.81.72.xxx| nickname
Database Password ကိုအရင္ေဖာက္ၿပီးမွ အဲ့လို Attack လုပ္လို႕ရတာလား ဒါမွမဟုတ္ ဘယ္လိုမ်ိဳးလဲဆိုတာ တစ္ခ်က္ေလာက္ ရွင္းျပေပးပါ
-
2010-09-12 22:48:19 |SAdministrator| admin - Re: nickname
Database Password ကိုသိစရာ မလိုဘူး။ operator ေတြေၾကာင့္ Query ေတြက condition ေတြေျပာင္း သြားတာပါ။
-
2010-09-20 13:03:03 |Registered| fish - critical sql injection
အဲ .. ကို zack ေရ ..
ကၽြန္ေတာ့္ Site လည္း အခု ျဖစ္ေနတယ္ .. ဒီ မနက္မွ သိရတာ ... http://www.planetcreator.net/2010/09/critical-sql-injection-in-stamps- myanmar/ ..
ကၽြန္ေတာ္လည္း အကို Blog နဲ႔ myanmar tutorial မွာ သြားေတြ႔လို႔ ..ပါ ... sql injection ဆိုတာ ဘာလဲ အခုမွ သိရေတာ့တယ္ ..
အဲ .. အဲဒါ ဘာဆက္လုပ္ရမလဲ .. ေျပာျပပါဦးေနာ္ ... mysql_real_escape_string .. ဒီ function ကိုလည္း ထည့္သုံးပါတယ္ .. !_!
-
2010-09-20 14:37:28 |SAdministrator| admin - Re: fish
Fish ေရ အဲဒါကေတာ့ user ကို data entry ေပးတဲ့ page ေတြအားလုံးမွာ trace လိုက္ၾကည့္သင့္တယ္။ FYI:
http://www.learnphponline.com/security/sql-injection-preve ntion-mysql-php
| < Prev | Next > |
|---|
Login Form
Latest Post
Categories Table View
- Reader's Conner (133)
- PHP (48)
- Joomla CMS (46)
- Codeigniter (18)
- jQuery (12)
- iDhamma (11)
- Mobile Development (10)
- PHP & AJAX (4)
- Apache (3)
- For Mac (3)
- mySQL (2)
- DhammaDroid (1)
Thanks for this interesting and useful article bro. Most of us not too much aware on web application security, though it is very important for us and the clients. I also want to share an interesting web site regarding to Web Security, http://www.owasp.org/ "Open Web Application Security Project (OWASP)". And this one (http://bit.ly/bsYwMu) is a nice presentation about "Advanced SQL Injection Protection" from there.
Please write this kind of Web Application Security related articles much more, bro.