![]() |
|
|
#1 |
|
Архивный участник
Join Date: Nov 2006
Posts: 204
|
hi,
i dont really like the PHP registration forms that are out there (l2cp mainly ) so i started writing my own ( np there ) now i was just wondering on how to defend myself against SQL-injection i had 2 ideas and just wondering what i would do best. 1) the hard way: parse the variables one by one and filter out ',", ,-,;,,, and all the other stuff or just 2) make some regex's that only allow [:alpha:],[:num:] and mayb[:space:] i personally think that if you only allow the alphanum and the numeric chars then all other chars used for sql-injection are basicly out of the picture.. just cut off at 16chars but i'm not sure if i'm looking at it too easy.. any help on this would be nice |
|
|
|
|
#2 |
|
Архивный участник
Join Date: Jun 2005
Posts: 285
|
find any article about sql injections - u'll see what you need to do
normal way: 1. audit, audit and .....ughm.... audit. make stored procedures from all of your queries, make separate user with only rights to execute those procedures (and no other permissions). 2. check any data, that goes directly into query - length, symbols, reserved words. 3. don't forget about php injections. |
|
|
|
|
#3 |
|
Архивный участник
Join Date: Nov 2006
Posts: 204
|
1) no idea how it works really
2) yeah tahts what i ment really.. would that be better to do by actually filtering out all the bad stuff or just blocking it when bad chars are in the value 3) i'll look into that imho 2 would be sufficient to get most of the sql-injections out , if they cant screw up the input they cant do it thru the input fields and cause its server side checking even tampering with the actuall packets wont matter.. |
|
|
|
|
#4 |
|
Архивный участник
Join Date: Jun 2005
Posts: 285
|
1. msdn.com
2. imho better to block it reporting warning to user |
|
|
|
|
#5 |
|
Архивный участник
Join Date: Nov 2006
Posts: 204
|
yeah that was my idea too.. just if any "illegal" char is in there.. report to user and let them do it again regex would be perfect for that imo
cause if i would replace it myself god know what i would end up with comming from the data that the user has put in lets start on my regex's then ^^ //edit: oh btw does case matter with lineage? do i have to write it all as lowercase or does it not matter? |
|
|
|
|
#6 |
|
Архивный участник
Join Date: Mar 2006
Posts: 241
|
It might be stupid... I made it on fast so... rotfl xD
Code:
$inject = 0;
$check_in[0] = '\'';
$check_in[1] = ',';
$check_in[2] = ';';
$check_in[3] = '--';
$check_in[4] = '"';
$check_in[5] = '\\';
$ch = 0;
while($ch < 5){
if (eregi($check_in[$ch], $account)) {$inject++;}
if (eregi($check_in[$ch], $password)) {$inject++;}
if (eregi($check_in[$ch], $password2)) {$inject++;}
if (eregi($check_in[$ch], $email)) {$inject++;}
if (eregi($check_in[$ch], $email2)) {$inject++;}
$ch++;
}
if($inject>0){
#OH MY GOD KILL THAT BASTARD!
}else{
#Horay! Let him play!
}
|
|
|
|
|
#7 |
|
Архивный участник
Join Date: Jan 2006
Posts: 281
|
u can't find an example of char validating in the php code of the L2CP
so either u use msdn.com or code ur own (last shouldn't take much time) |
|
|
|
|
#8 |
|
Архивный участник
Join Date: Nov 2006
Posts: 204
|
i tried playing arround with some regex but if i make em too flexible they dont filter enough..
guess i'll have to write my own func for it ![]() thinking about just going char by char and checking it for bad chars my first idea was [a-z0-9]{4,14} , works fine until you put anywhere in your string a char that is minimum 4 with no spaces or illegal chars gonna see if i can anchor it down if that helps ..otherwise i'll get going on a custom function.. @drag: that looks fine but i had the idea of -why check for bad chars where you could be missing some- and rather go for the -check if the chars are valid- approach so instead of looking for " ' \ etc.. just check if its 0-9 and A-Z edit : not sure but think the anchoring fixed it allready .. ^[a-z0-9]{4,14}$ should do the trick.. |
|
|
|
|
#9 |
|
Архивный участник
Join Date: Aug 2005
Posts: 394
|
PHP Code:
just use it like this: PHP Code:
I'm pretty good with PHP. I'll re-do L2CP and post it soon(if someone else doesn't do it before me) |
|
|
|
|
#10 | |
|
Архивный участник
Join Date: Dec 2005
Posts: 242
|
Quote:
|
|
|
|
|
|
#11 |
|
Архивный участник
Join Date: Nov 2006
Posts: 204
|
well the thing for me was .. i looked thru the code of l2cp .and imho its so unorganized and badcoded.. i can get taht you want flexibility but when it comes of the price of code readability and overall performance.. no thnx
therefore i just wanted a clean page ( or pages - reg/change pw/recover pw ) no hassle.. just clean/efficient code @Phantom: you say your function will replace non-alphanumeric chars.. looking at it it just matches it.. replacing would be ereg_replace() not just ereg() which just matches the regex i'll keep going on my little custom l2cp and if you think i can help you on your l2CP revamp lemme know ^^ |
|
|
|
|
#12 |
|
Архивный участник
Join Date: Mar 2006
Posts: 241
|
|
|
|
|
|
#13 |
|
Архивный участник
Join Date: Nov 2006
Posts: 204
|
not bad.. still working on my own version with the regex..seems to be working nice
i'll post it when i'm done so i can get flamed "you noob it sucks "
|
|
|
| Thread Tools | Search this Thread |
| Display Modes | |
|
|