sql注入


六.暴力破解密码

 

目前的登陆和修改密码,没有错误次数的限制。

 

Solution: 是否可以加入新的逻辑:单位时间内输入错误次数大于一个数值时,改账号会被冻结。可以由改company的admin 解冻 或者发送申请到 sunnet后由sunnet公司解冻。


1.web.config里加链接字段:

[html]  view plain  copy
  1. <configuration>  
  2.   <connectionStrings >  
  3.     <add name="myConnectionString"  
  4.          connectionString="Server=10.231.248.177;Database=testdb;User ID=sa;Password=pa$$word;Trusted_Connection=False;"  
  5.          providerName="System.Data.SqlClient"/>  
  6.   </connectionStrings>  


2.拖几个控件在form里:

[html]  view plain  copy
  1. <form id="form1" runat="server">  
  2.         <asp:Label ID="LU" runat="server" Text="User Name:"></asp:Label>  
  3.         <asp:TextBox ID="TBU" runat="server"></asp:TextBox>  
  4.         <br/>  
  5.         <asp:Label ID="LP" runat="server" Text="Password:"></asp:Label>  
  6.         <asp:TextBox ID="TBP" runat="server"></asp:TextBox>  
  7.         <br/>  
  8.         <asp:Button ID="Login" runat="server" Text="Login" OnClick="Login_Click" />  
  9.     <div>  


3.写登录事件:

[csharp]  view plain  copy
  1. protected void Login_Click(object sender, EventArgs e)  
  2.     {  
  3.         using(SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString))  
  4.         {  
  5.             con.Open();  
  6.             SqlCommand cmd = new SqlCommand();  
  7.             cmd.CommandText = "SELECT Count(1) FROM [User] where UserName='" + TBU.Text.Trim() + "' and Password='" + TBP.Text.Trim() + "'";  
  8.             cmd.CommandType = CommandType.Text;  
  9.             cmd.Connection = con;  
  10.             int count =(int) cmd.ExecuteScalar();  
  11.             Response.Write(cmd.CommandText);  
  12.             if (count > 0)  
  13.             {  
  14.                 Response.Write("<script>alert('Login pass!');</script>");  
  15.             }  
  16.             else  
  17.             {  
  18.                 Response.Write("<script>alert('Login fail!');</script>");  
  19.             }  
  20.   
  21.         }  
  22.     }  


4.构造SQL注入登录:

用户名输入:test' or ''='

密码输入:' or ''='

或者

用户名输入:test

密码输入:' or ''='

如图:




其他ASP.net SQL注入的例子,如果有兴趣可以参考下:

http://www.aspsnippets.com/Articles/SQL-Injection-Attack-its-examples-and-Prevention-mechanisms-and-Techniques-in-ASPNet.aspx

http://www.codeproject.com/Articles/459324/Understading-SQL-Injection-and-Creating-SQL-Inject

http://blogs.iis.net/nazim/sql-injection-demo

其他的SQL注入:http://www.unixwiz.net/techtips/sql-injection.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值