asp.net sql注入实验(2)

net sql注入实验(2)

跨页传递在asp时代最简单的做法是查询字符串。这种做法在asp.net 2.0已经不是推荐的做法了,但对于简单数据传输还是一种简单的便利的做法。今天我们就通过查询字符串进一步了解sql注入的注入漏洞判断的相关知识。
一.实验准备:page1:传递参数
Page2: 接收并处理参数.
 
         
二.相关代码:
(1)page1传递参数的代码
protected void Button1_Click1(object sender, EventArgs e)
    {
        Response.Redirect(“page2.aspx?name=”+textbox_name.Text.Tostring()+ “&password=”+ textbox_password.Text.Tostring());
}
(2) page2接收并处理
username.Text = Request.QueryString[“name”].ToString();
        tpassword.Text = Request.QueryString[“password”].ToString();
        username = tusername.Text;
        pswd = tpassword.Text;
        cmd.CommandText = “SELECT * FROM [test].[dbo].[user] where [user]='” + username + “‘ and [pswd]='” + pswd + “‘”;
        if (cmd.ExecuteScalar() != null)
            Response.Write(“hao”);
        //Response.Redirect(“Welcom.aspx”);
        else
            TextBox1.Text = “用户名或密码错误”;
运行情况:
用查询字符串,传递的参数会在地址栏显示出来:
http://localhost:1239/WebSite/page2.aspx?name=xuanhun&password=123456,
根据这个形式的地址,我们讨论一个简单的注入漏洞判断的原理。
三.
1.数字型
查询语句类似为:Select * from 表名 where 字段=23。因为数字型没有引号,直接加查询语句测试是否可以执行
①http://localhost:1239/WebSite/page2.aspx?id=23。这是正常网页。查询语句为
Select * from 表名 where 字段=23
②http://localhost:1239/WebSite/page2.aspx?id=23 and 1=1。因为and 1=1为真,所以如果返回的页面和①同,说明我们插入的语句执行了。查询语句为:Select * from 表名 where 字段=23 and 1=1.
③http://localhost:1239/WebSite/page2.aspx?id=23 and 1=2。因为and 1=2为假,查询语句为:Select * from 表名 where 字段=23 and 1=2。
这就是经典的1=1、1=2测试法的原理。可以注入的表现:
① 正常显示(这是必然的,不然就是程序有错误了) ② 正常显示,内容基本与①相同 ③ 提示BOF或EOF(程序没做任何判断时)、或提示找不到记录(判断了rs.eof时)、或显示内容为空(程序加了on error resume next)
   不可以注入就比较容易判断了,①同样正常显示,②和③一般都会有程序定义的错误提示,或提示类型转换时出错。
2.字符型。
查询语句类似为:Select * from 表名 where 字段=’xuanhun’。
测试不过是先屏蔽单引号再用上面的方法来检测漏洞。
比如我们上面的测试页面:http://localhost:1239/WebSite/page2.aspx?name=xuanhun&password=123456,
查询语句为:Select * from [user] where [name]=’xuanhun’and [pswd]=’123456’。
字符型可以直接在单引号看程序的错误信息,如http://localhost:1239/WebSite/page2.aspx?name=xuanhun&password=123456’返回错误信息:
“/WebSite”应用程序中的服务器错误。

 

——————————————————————————–

字符串 ‘123456” 后的引号不完整。 ‘123456” 附近有语法错误。
再屏蔽单引号看结果:http://localhost:1239/WebSite/page2.aspx?name=xuanhun&password=123456’and ‘a’=’a’- –
页面正常。
http://localhost:1239/WebSite/page2.aspx?name=xuanhun&password=123456’and ‘a’=’b’- –
页面错误。
3.搜索型。
查询语句类似为:Select * from 表名 where 字段like ’%关键字%’
要屏蔽单引号和百分号再用上面的方法测试,注入也是一样。
例如:select * from [user] where [username] like ‘%a%’ and 1=1–
原理跟上面讲的相同,就不详细介绍了。



本文固定链接: http://www.ntxz.net/?p=652 | 周忞 | 吉心的记事本



该日志由 吉心 于2010年06月26日发表在 懒得分类, 旧版博客 分类下, 你可以发表评论
在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: asp.net sql注入实验(2) | 周忞 | 吉心的记事本

asp.net sql注入实验(2):等您坐沙发呢!

发表评论

您必须 [ 登录 ] 才能发表留言!