Suppose a web server uses the following PHP code to process login requests:
$username = $_POST[user];
$password = $_POST[pass];
$sql = "SELECT * FROM users WHERE name = '$username' AND password = '$password'";
if(mysql_num_rows($rs) > 0){ //do something
}
- What value for username will always result in a successful login?
I think the value ' OR 1=1 will always result in a successful login, because the query will then be:
"SELECT * FROM users WHERE name = '' OR 1=1 AND password = '$password'"
Is this correct?
- Suppose the data is set to use the GBK Chinese unicode character set. In GBK, the byte 0x5cencodes\and0x27encodes'. The bytes0xbf27represent the two characters¿'and the bytes0xbf5care a single Chinese character. If the username and passwords fields add slashes to',",\, andnull, what username will always result in a successful login, assuming the database interprets the string as GBK but adding slashes processes the string as ASCII?
I'm not sure what the last part of the sentence means (by interpreting as GBK but processing as ASCII). Can someone shed light on how to solve this problem?
 
    