Problem 2: Is this code good for security, or does it leave obvious security holes?
Every string a user enters will be tested by this script before being used in any way.
Yes, I know it would have been more efficient to use a switch, but this is the third evolution of this script, and the previous versions used lots of If statements.
I have tested it, and it does stop the execution of the script and display the message when one attempts to use a prohibited character.
Problem 1 Solved by ncwdavid.
There are no additional problems to be solved.
To mods: I'll reuse this thread later when I have another stupid question, and change the title to ...thread [[NEW]], so you needn't bother locking it.
mjunhybgtvfrcde <-- a random sequence of letters I can search for later so as to easily find this thread again.
Last edited by ocalhoun on Mon Mar 19, 2007 7:32 pm; edited 3 times in total
Every string a user enters will be tested by this script before being used in any way.
| Code: |
|
function security_validate($string) { //Makes sure a given string does not contain any control charachters which could be used for hacking in any concievable way. // forbidden charachters: /<>()='",;[]{}.? $forbidden="OK"; //As of now, no forbidden charachters have been detected If(strstr($string,"/")!=false) { $forbidden="/"; } If(strstr($string,"<")!=false) { $forbidden="<"; } If(strstr($string,">")!=false) { $forbidden=">"; } If(strstr($string,"(")!=false) { $forbidden="("; } If(strstr($string,")")!=false) { $forbidden=")"; } If(strstr($string,"=")!=false) { $forbidden="="; } If(strstr($string,"'")!=false) { $forbidden="'"; } If(strstr($string,'"')!=false) { $forbidden='"'; } If(strstr($string,",")!=false) { $forbidden=","; } If(strstr($string,";")!=false) { $forbidden=";"; } If(strstr($string,"[")!=false) { $forbidden="["; } If(strstr($string,"]")!=false) { $forbidden="]"; } If(strstr($string,"{")!=false) { $forbidden="{"; } If(strstr($string,"}")!=false) { $forbidden="}"; } If(strstr($string,".")!=false) { $forbidden="."; } If(strstr($string,"?")!=false) { $forbidden="?"; } If($forbidden!="OK") //If any forbidden charachters were detected { mail("___________@hotmail.com","________Hacking Attempt!","There has been a hacking attempt at the archive. A user entered the forbidden charachter, " . $forbidden . " into a text field."); DIE("You have used illigal charachters in an entered string. If you have done so with honest intentions, notify the administration of this site immidiately. Otherwise it will be assumed that you are attempting to hack into this site. The forbidden charachter you used is: ---> " . $forbidden . " <--- The Administrator of the site has been notified of this possible hacking attempt by E-mail."); } //return "validated"; } |
Yes, I know it would have been more efficient to use a switch, but this is the third evolution of this script, and the previous versions used lots of If statements.
I have tested it, and it does stop the execution of the script and display the message when one attempts to use a prohibited character.
Problem 1 Solved by ncwdavid.
There are no additional problems to be solved.
To mods: I'll reuse this thread later when I have another stupid question, and change the title to ...thread [[NEW]], so you needn't bother locking it.
mjunhybgtvfrcde <-- a random sequence of letters I can search for later so as to easily find this thread again.
Last edited by ocalhoun on Mon Mar 19, 2007 7:32 pm; edited 3 times in total
