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
0x5c
encodes\
and0x27
encodes'
. The bytes0xbf27
represent the two characters¿'
and the bytes0xbf5c
are 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?