SQL注入漏洞

来源:互联网 发布:淘宝联盟的预估收入 编辑:程序博客网 时间:2024/04/30 03:23

后台代码

protected void Button1_Click(object sender, EventArgs e)        {            string sql = "Data source=hp-pc;initial catalog=ADOzhuru;user=sa;password=admin";            using (SqlConnection con = new SqlConnection(sql))            {                string a = string.Format("select count(*) from Table_1 where username='{0}' and password='{1}'", TextBox1.Text, TextBox2.Text);                using (SqlCommand com = new SqlCommand(a, con))                {                    con.Open();                    int i = (int)com.ExecuteScalar();                    if (i > 0)                    {                        Response.Write("登陆成功后");                    }                    else                    {                        Response.Write("登录失败");                    }                }            }        }

数据库中存有 admin 用户但用随便一个字符串登陆出现

在后台添加断点查看后

此时的where 就变成 username==xx 或者 1==1 恒成立了 并且 password被 -- 注释掉了

解决方案用 Parameters