Asp.net SQL注入实例分享

简介: Asp.net SQL注入实例分享1.web.config里加链接字段: 2.拖几个控件在form里: 3.


Asp.net SQL注入实例分享


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

<configuration>
  <connectionStrings >
    <add name="myConnectionString"
         connectionString="Server=10.231.248.177;Database=testdb;User ID=sa;Password=pa$$word;Trusted_Connection=False;"
         providerName="System.Data.SqlClient"/>
  </connectionStrings>


2.拖几个控件在form里:

<form id="form1" runat="server">
        <asp:Label ID="LU" runat="server" Text="User Name:"></asp:Label>
        <asp:TextBox ID="TBU" runat="server"></asp:TextBox>
        <br/>
        <asp:Label ID="LP" runat="server" Text="Password:"></asp:Label>
        <asp:TextBox ID="TBP" runat="server"></asp:TextBox>
        <br/>
        <asp:Button ID="Login" runat="server" Text="Login" OnClick="Login_Click" />
    <div>


3.写登录事件:

protected void Login_Click(object sender, EventArgs e)
    {
        using(SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString))
        {
            con.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "SELECT Count(1) FROM [User] where UserName='" + TBU.Text.Trim() + "' and Password='" + TBP.Text.Trim() + "'";
            cmd.CommandType = CommandType.Text;
            cmd.Connection = con;
            int count =(int) cmd.ExecuteScalar();
            Response.Write(cmd.CommandText);
            if (count > 0)
            {
                Response.Write("<script>alert('Login pass!');</script>");
            }
            else
            {
                Response.Write("<script>alert('Login fail!');</script>");
            }

        }
    }


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


目录
相关文章
|
7天前
|
SQL 存储 Java
如何避免SQL注入?
【4月更文挑战第30天】如何避免SQL注入?
18 0
|
7天前
|
SQL 分布式计算 DataWorks
DataWorks操作报错合集之在DataWorks中使用ODPS SQL时遇到"该文件对应引擎实例已失效,请重新选择可用的引擎实例"的错误提示”,是什么导致的
DataWorks是阿里云提供的一站式大数据开发与治理平台,支持数据集成、数据开发、数据服务、数据质量管理、数据安全管理等全流程数据处理。在使用DataWorks过程中,可能会遇到各种操作报错。以下是一些常见的报错情况及其可能的原因和解决方法。
31 0
|
7天前
|
SQL 安全 PHP
【PHP 开发专栏】PHP 防止 SQL 注入的方
【4月更文挑战第30天】本文介绍了PHP防止SQL注入的策略,包括理解SQL注入的原理和危害,如数据泄露和系统控制。推荐使用参数化查询(如PDO扩展)、过滤和验证用户输入,以及选择安全的框架和库(如Laravel)。此外,强调了保持警惕、定期更新维护和开发人员安全培训的重要性,以确保应用安全。
|
7天前
|
SQL 存储 安全
|
7天前
|
SQL Oracle 关系型数据库
常见 SQL 注入绕过方法
常见 SQL 注入绕过方法
|
7天前
|
SQL Oracle 关系型数据库
利用 SQL 注入提取数据方法总结
利用 SQL 注入提取数据方法总结
|
7天前
|
SQL 关系型数据库 MySQL
利用 SQL 注入识别数据库方法总结
利用 SQL 注入识别数据库方法总结
|
7天前
|
SQL Oracle Java
SQL 注入神器:jSQL Injection 保姆级教程
SQL 注入神器:jSQL Injection 保姆级教程
|
7天前
|
SQL 数据库
常见寻找 SQL 注入方法总结
常见寻找 SQL 注入方法总结
|
10天前
|
SQL 安全 Java
【Mybatis】Mybatis如何防止sql注入
【Mybatis】Mybatis如何防止sql注入