Michael Howard
01-30-2001, 08:08 PM
There's a booboo in the wording of the most current Defense In Depth article
about user input. 100% my mistake!!
change the SQL text example to:
if (isPasswordOK(Request.form("name"),Request.form("pwd"))) {
Response.write("Authenticated!");
// Do stuff
} else {
Response.write("Access Denied");
}
function isPasswordOK(strName, strPwd) {
var fAllowLogon = false;
var oConn = new ActiveXObject("ADODB.Connection");
var strConnection="Data Source=c:\\auth\\auth.mdb;"
oConn.Open(strConnection);
var strSQL = "SELECT count(*) FROM client WHERE " +
"name='" + strName + "' " +
" and pwd='" + strPwd + "'";
var oRS = new ActiveXObject("ADODB.RecordSet");
oRS.Open(strSQL,oConn);
fAllowLogon = (oRS(0).Value > 0) ? true : false;
oRS.Close();
delete oRS;
oConn.Close();
delete oConn;
return fAllowLogon;
}
vulnerable input includes:
name == b' or '1' = '1
pwd == b' or '1' = '1
which yields:
SELECT count(*)
FROM client
WHERE name='b' or '1'='1' and pwd='b' or '1'='1'
apologies for the inconvenience...
about user input. 100% my mistake!!
change the SQL text example to:
if (isPasswordOK(Request.form("name"),Request.form("pwd"))) {
Response.write("Authenticated!");
// Do stuff
} else {
Response.write("Access Denied");
}
function isPasswordOK(strName, strPwd) {
var fAllowLogon = false;
var oConn = new ActiveXObject("ADODB.Connection");
var strConnection="Data Source=c:\\auth\\auth.mdb;"
oConn.Open(strConnection);
var strSQL = "SELECT count(*) FROM client WHERE " +
"name='" + strName + "' " +
" and pwd='" + strPwd + "'";
var oRS = new ActiveXObject("ADODB.RecordSet");
oRS.Open(strSQL,oConn);
fAllowLogon = (oRS(0).Value > 0) ? true : false;
oRS.Close();
delete oRS;
oConn.Close();
delete oConn;
return fAllowLogon;
}
vulnerable input includes:
name == b' or '1' = '1
pwd == b' or '1' = '1
which yields:
SELECT count(*)
FROM client
WHERE name='b' or '1'='1' and pwd='b' or '1'='1'
apologies for the inconvenience...