Post Pacific

Post Pacific (https://postpacific.loc-online.com/index.php)
-   Темы без сохранившегося раздела (https://postpacific.loc-online.com/forumdisplay.php?f=10001)
-   -   [help on idea]L2 Regform ( PHP ) (https://postpacific.loc-online.com/showthread.php?t=6482)

dirkr 23.12.2006 20:16

[help on idea]L2 Regform ( PHP )
 
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

hr 23.12.2006 21:12

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.

dirkr 23.12.2006 21:29

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..

hr 23.12.2006 21:31

1. msdn.com
2. imho better to block it reporting warning to user

dirkr 23.12.2006 21:34

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?

Drag 23.12.2006 23:12

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!
}

I dont know does that all illegal chars...

Met45 23.12.2006 23:23

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)

dirkr 23.12.2006 23:30

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..

Phantom2005 23.12.2006 23:58

PHP Code:

function isAlphaNumeric($str)
{
     return !
ereg("[^A-Za-z0-9]", $str);
} 

That's my fav. It will remove all not-alphanumeric characters.

just use it like this:
PHP Code:

$account = isAlphaNumeric($account);
$password = isAlphaNumeric($password);
$password = isAlphaNumeric($password2);
etc. 

And basically you can just add "@" and "." for email addresses

I'm pretty good with PHP. I'll re-do L2CP and post it soon(if someone else doesn't do it before me)

RipperX 24.12.2006 00:05

Quote:

Originally Posted by Phantom2005 (Post 74830)
PHP Code:

function isAlphaNumeric($str)
{
     return !
ereg("[^A-Za-z0-9]", $str);
} 

That's my fav. It will remove all not-alphanumeric characters.

just use it like this:
PHP Code:

$account = isAlphaNumeric($account);
$password = isAlphaNumeric($password);
$password = isAlphaNumeric($password2);
etc. 

And basically you can just add "@" and "." for email addresses

I'm pretty good with PHP. I'll re-do L2CP and post it soon(if someone else doesn't do it before me)

I like this guy :)

dirkr 24.12.2006 00:09

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 ^^

Drag 24.12.2006 15:18

https://postpacific.loc-online.com/f...6&postcount=24

dirkr 24.12.2006 16:36

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 " :p


All times are GMT. The time now is 15:09.