在看到这个提示之前我也如此,呵呵,但是肯定还是有很多朋友都知道这个,但是忽略这个问题的人我想一定不会在少数!具体看下面,按照我的老规矩,做成一个Demo,前后台页代码都在,只是数据库,我是用的SQL,数据哭结构只有两个字段,一个用户名,一个密码,所以自己都可以建一个就是,呵呵!!

 后台C#代码
后台C#代码
1 using System;
using System;
2 using System.Collections;
using System.Collections;
3 using System.ComponentModel;
using System.ComponentModel;
4 using System.Data;
using System.Data;
5 using System.Drawing;
using System.Drawing;
6 using System.Web;
using System.Web;
7 using System.Web.SessionState;
using System.Web.SessionState;
8 using System.Web.UI;
using System.Web.UI;
9 using System.Web.UI.WebControls;
using System.Web.UI.WebControls;
10 using System.Web.UI.HtmlControls;
using System.Web.UI.HtmlControls;
11 using System.Data.SqlClient;
using System.Data.SqlClient;
12 namespace Ado.net
namespace Ado.net
13

 {
{
14
 /**//// <summary>
    /**//// <summary>
15 /// WebForm1 的摘要说明。
    /// WebForm1 的摘要说明。
16 /// </summary>
    /// </summary>
17 public class WebForm1 : System.Web.UI.Page
    public class WebForm1 : System.Web.UI.Page
18
 
     {
{
19 protected System.Web.UI.WebControls.TextBox TextBox1;
        protected System.Web.UI.WebControls.TextBox TextBox1;
20 protected System.Web.UI.WebControls.TextBox TextBox2;
        protected System.Web.UI.WebControls.TextBox TextBox2;
21 protected System.Web.UI.WebControls.Button Button1;
        protected System.Web.UI.WebControls.Button Button1;
22 protected System.Web.UI.WebControls.Button Button2;
        protected System.Web.UI.WebControls.Button Button2;
23 
    
24 private void Page_Load(object sender, System.EventArgs e)
        private void Page_Load(object sender, System.EventArgs e)
25
 
         {
{
26 // 在此处放置用户代码以初始化页面
            // 在此处放置用户代码以初始化页面
27 }
        }
28
29
 Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
        Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
30 override protected void OnInit(EventArgs e)
        override protected void OnInit(EventArgs e)
31
 
         {
{
32 //
            //
33 // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
34 //
            //
35 InitializeComponent();
            InitializeComponent();
36 base.OnInit(e);
            base.OnInit(e);
37 }
        }
38 
        
39
 /**//// <summary>
        /**//// <summary>
40 /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
41 /// 此方法的内容。
        /// 此方法的内容。
42 /// </summary>
        /// </summary>
43 private void InitializeComponent()
        private void InitializeComponent()
44
 
         {
{    
45 this.Button1.Click += new System.EventHandler(this.Button1_Click);
            this.Button1.Click += new System.EventHandler(this.Button1_Click);
46 this.Button2.Click += new System.EventHandler(this.Button2_Click);
            this.Button2.Click += new System.EventHandler(this.Button2_Click);
47 this.Load += new System.EventHandler(this.Page_Load);
            this.Load += new System.EventHandler(this.Page_Load);
48
49 }
        }
50 #endregion
        #endregion
51
52 private SqlConnection con()
        private SqlConnection con()
53
 
         {//下面有调用几次这个,所以就做个方法,呵呵,没有意见吧
{//下面有调用几次这个,所以就做个方法,呵呵,没有意见吧
54 SqlConnection con=new SqlConnection("server=.;database=voteone;uid=sa;pwd=980123;");
            SqlConnection con=new SqlConnection("server=.;database=voteone;uid=sa;pwd=980123;");
55 return con;
            return con;
56 }
        }
57 private void Button1_Click(object sender, System.EventArgs e)
        private void Button1_Click(object sender, System.EventArgs e)
58
 
         {
{
59 SqlConnection con=this.con();
            SqlConnection con=this.con();
60 con.Open();
            con.Open();
61 SqlCommand cmd=new SqlCommand("select * from admin where name='"+TextBox1.Text+"' and pwd='"+TextBox2.Text+"'",con);
            SqlCommand cmd=new SqlCommand("select * from admin where name='"+TextBox1.Text+"' and pwd='"+TextBox2.Text+"'",con);
62 SqlDataReader sdr=cmd.ExecuteReader();
            SqlDataReader sdr=cmd.ExecuteReader();
63 if(sdr.Read())
            if(sdr.Read())
64
 
             {//这个成功不需要输入密码或者连用户名都不用输入就可以得到
{//这个成功不需要输入密码或者连用户名都不用输入就可以得到
65 //例如你在第第一个文本框里输入 thc '-- (这个是假设我们知道用户名是thc)或者 ' or 1=1--  (这个更厉害了,更本就不需要知道什么,重要知道 1=1就可以了)
             //例如你在第第一个文本框里输入 thc '-- (这个是假设我们知道用户名是thc)或者 ' or 1=1--  (这个更厉害了,更本就不需要知道什么,重要知道 1=1就可以了)
66 Response.Write("登陆成功");
                Response.Write("登陆成功");
67 }
            }
68 else
            else
69
 
             {
{
70 Response.Write("失败");
                Response.Write("失败");
71 }
            }
72 }
        }
73
74 private void Button2_Click(object sender, System.EventArgs e)
        private void Button2_Click(object sender, System.EventArgs e)
75
 
         {//下面方法主要是使用了Replace关键字把传近来的字符中的 单引号给替换了('),其他没有什么,呵呵
{//下面方法主要是使用了Replace关键字把传近来的字符中的 单引号给替换了('),其他没有什么,呵呵
76 SqlConnection con=this.con();
            SqlConnection con=this.con();
77 con.Open();
            con.Open();
78 SqlCommand cmd=new SqlCommand("select * from admin where name='"+TextBox1.Text.Replace("'","''")+"' and pwd='"+TextBox2.Text.Replace("'","''")+"'",con);
            SqlCommand cmd=new SqlCommand("select * from admin where name='"+TextBox1.Text.Replace("'","''")+"' and pwd='"+TextBox2.Text.Replace("'","''")+"'",con);
79 SqlDataReader sdr=cmd.ExecuteReader();
            SqlDataReader sdr=cmd.ExecuteReader();
80 if(sdr.Read())
            if(sdr.Read())
81
 
             {
{
82 Response.Write("登陆成功");
                Response.Write("登陆成功");
83 }
            }
84 else
            else
85
 
             {
{
86 Response.Write("失败");
                Response.Write("失败");
87 }
            }
88 }
        }
89 }
    }
90 }
}
91 

 前台HTML代码
前台HTML代码
1
 <%
<% @ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="Ado.net.WebForm1" %>
@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="Ado.net.WebForm1" %>
2 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
3 <HTML>
<HTML>
4 <HEAD>
    <HEAD>
5 <title>WebForm1</title>
        <title>WebForm1</title>
6 <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
        <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
7 <meta name="CODE_LANGUAGE" Content="C#">
        <meta name="CODE_LANGUAGE" Content="C#">
8 <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_defaultClientScript" content="JavaScript">
9 <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
10 </HEAD>
    </HEAD>
11 <body MS_POSITIONING="GridLayout">
    <body MS_POSITIONING="GridLayout">
12 <form id="Form1" method="post" runat="server">
        <form id="Form1" method="post" runat="server">
13 <asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 32px; POSITION: absolute; TOP: 80px" runat="server"></asp:TextBox>
            <asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 32px; POSITION: absolute; TOP: 80px" runat="server"></asp:TextBox>
14 <asp:TextBox id="TextBox2" style="Z-INDEX: 102; LEFT: 32px; POSITION: absolute; TOP: 120px" runat="server"></asp:TextBox>
            <asp:TextBox id="TextBox2" style="Z-INDEX: 102; LEFT: 32px; POSITION: absolute; TOP: 120px" runat="server"></asp:TextBox>
15 <asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 32px; POSITION: absolute; TOP: 160px" runat="server"
            <asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 32px; POSITION: absolute; TOP: 160px" runat="server"
16 Text="有漏洞"></asp:Button>
                Text="有漏洞"></asp:Button>
17 <asp:Button id="Button2" style="Z-INDEX: 104; LEFT: 120px; POSITION: absolute; TOP: 160px" runat="server"
            <asp:Button id="Button2" style="Z-INDEX: 104; LEFT: 120px; POSITION: absolute; TOP: 160px" runat="server"
18 Text="修改后"></asp:Button>
                Text="修改后"></asp:Button>
19 </form>
        </form>
20 </body>
    </body>
21 </HTML>
</HTML>
22 

 后台C#代码
后台C#代码1
 using System;
using System;2
 using System.Collections;
using System.Collections;3
 using System.ComponentModel;
using System.ComponentModel;4
 using System.Data;
using System.Data;5
 using System.Drawing;
using System.Drawing;6
 using System.Web;
using System.Web;7
 using System.Web.SessionState;
using System.Web.SessionState;8
 using System.Web.UI;
using System.Web.UI;9
 using System.Web.UI.WebControls;
using System.Web.UI.WebControls;10
 using System.Web.UI.HtmlControls;
using System.Web.UI.HtmlControls;11
 using System.Data.SqlClient;
using System.Data.SqlClient;12
 namespace Ado.net
namespace Ado.net13


 {
{14

 /**//// <summary>
    /**//// <summary>15
 /// WebForm1 的摘要说明。
    /// WebForm1 的摘要说明。16
 /// </summary>
    /// </summary>17
 public class WebForm1 : System.Web.UI.Page
    public class WebForm1 : System.Web.UI.Page18

 
     {
{19
 protected System.Web.UI.WebControls.TextBox TextBox1;
        protected System.Web.UI.WebControls.TextBox TextBox1;20
 protected System.Web.UI.WebControls.TextBox TextBox2;
        protected System.Web.UI.WebControls.TextBox TextBox2;21
 protected System.Web.UI.WebControls.Button Button1;
        protected System.Web.UI.WebControls.Button Button1;22
 protected System.Web.UI.WebControls.Button Button2;
        protected System.Web.UI.WebControls.Button Button2;23
 
    24
 private void Page_Load(object sender, System.EventArgs e)
        private void Page_Load(object sender, System.EventArgs e)25

 
         {
{26
 // 在此处放置用户代码以初始化页面
            // 在此处放置用户代码以初始化页面27
 }
        }28

29

 Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
        Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码30
 override protected void OnInit(EventArgs e)
        override protected void OnInit(EventArgs e)31

 
         {
{32
 //
            //33
 // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。34
 //
            //35
 InitializeComponent();
            InitializeComponent();36
 base.OnInit(e);
            base.OnInit(e);37
 }
        }38
 
        39

 /**//// <summary>
        /**//// <summary>40
 /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改41
 /// 此方法的内容。
        /// 此方法的内容。42
 /// </summary>
        /// </summary>43
 private void InitializeComponent()
        private void InitializeComponent()44

 
         {
{    45
 this.Button1.Click += new System.EventHandler(this.Button1_Click);
            this.Button1.Click += new System.EventHandler(this.Button1_Click);46
 this.Button2.Click += new System.EventHandler(this.Button2_Click);
            this.Button2.Click += new System.EventHandler(this.Button2_Click);47
 this.Load += new System.EventHandler(this.Page_Load);
            this.Load += new System.EventHandler(this.Page_Load);48

49
 }
        }50
 #endregion
        #endregion51

52
 private SqlConnection con()
        private SqlConnection con()53

 
         {//下面有调用几次这个,所以就做个方法,呵呵,没有意见吧
{//下面有调用几次这个,所以就做个方法,呵呵,没有意见吧54
 SqlConnection con=new SqlConnection("server=.;database=voteone;uid=sa;pwd=980123;");
            SqlConnection con=new SqlConnection("server=.;database=voteone;uid=sa;pwd=980123;");55
 return con;
            return con;56
 }
        }57
 private void Button1_Click(object sender, System.EventArgs e)
        private void Button1_Click(object sender, System.EventArgs e)58

 
         {
{59
 SqlConnection con=this.con();
            SqlConnection con=this.con();60
 con.Open();
            con.Open();61
 SqlCommand cmd=new SqlCommand("select * from admin where name='"+TextBox1.Text+"' and pwd='"+TextBox2.Text+"'",con);
            SqlCommand cmd=new SqlCommand("select * from admin where name='"+TextBox1.Text+"' and pwd='"+TextBox2.Text+"'",con);62
 SqlDataReader sdr=cmd.ExecuteReader();
            SqlDataReader sdr=cmd.ExecuteReader();63
 if(sdr.Read())
            if(sdr.Read())64

 
             {//这个成功不需要输入密码或者连用户名都不用输入就可以得到
{//这个成功不需要输入密码或者连用户名都不用输入就可以得到65
 //例如你在第第一个文本框里输入 thc '-- (这个是假设我们知道用户名是thc)或者 ' or 1=1--  (这个更厉害了,更本就不需要知道什么,重要知道 1=1就可以了)
             //例如你在第第一个文本框里输入 thc '-- (这个是假设我们知道用户名是thc)或者 ' or 1=1--  (这个更厉害了,更本就不需要知道什么,重要知道 1=1就可以了)66
 Response.Write("登陆成功");
                Response.Write("登陆成功");67
 }
            }68
 else
            else69

 
             {
{70
 Response.Write("失败");
                Response.Write("失败");71
 }
            }72
 }
        }73

74
 private void Button2_Click(object sender, System.EventArgs e)
        private void Button2_Click(object sender, System.EventArgs e)75

 
         {//下面方法主要是使用了Replace关键字把传近来的字符中的 单引号给替换了('),其他没有什么,呵呵
{//下面方法主要是使用了Replace关键字把传近来的字符中的 单引号给替换了('),其他没有什么,呵呵76
 SqlConnection con=this.con();
            SqlConnection con=this.con();77
 con.Open();
            con.Open();78
 SqlCommand cmd=new SqlCommand("select * from admin where name='"+TextBox1.Text.Replace("'","''")+"' and pwd='"+TextBox2.Text.Replace("'","''")+"'",con);
            SqlCommand cmd=new SqlCommand("select * from admin where name='"+TextBox1.Text.Replace("'","''")+"' and pwd='"+TextBox2.Text.Replace("'","''")+"'",con);79
 SqlDataReader sdr=cmd.ExecuteReader();
            SqlDataReader sdr=cmd.ExecuteReader();80
 if(sdr.Read())
            if(sdr.Read())81

 
             {
{82
 Response.Write("登陆成功");
                Response.Write("登陆成功");83
 }
            }84
 else
            else85

 
             {
{86
 Response.Write("失败");
                Response.Write("失败");87
 }
            }88
 }
        }89
 }
    }90
 }
}91


 前台HTML代码
前台HTML代码1

 <%
<% @ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="Ado.net.WebForm1" %>
@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="Ado.net.WebForm1" %>2
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >3
 <HTML>
<HTML>4
 <HEAD>
    <HEAD>5
 <title>WebForm1</title>
        <title>WebForm1</title>6
 <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
        <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">7
 <meta name="CODE_LANGUAGE" Content="C#">
        <meta name="CODE_LANGUAGE" Content="C#">8
 <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_defaultClientScript" content="JavaScript">9
 <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">10
 </HEAD>
    </HEAD>11
 <body MS_POSITIONING="GridLayout">
    <body MS_POSITIONING="GridLayout">12
 <form id="Form1" method="post" runat="server">
        <form id="Form1" method="post" runat="server">13
 <asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 32px; POSITION: absolute; TOP: 80px" runat="server"></asp:TextBox>
            <asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 32px; POSITION: absolute; TOP: 80px" runat="server"></asp:TextBox>14
 <asp:TextBox id="TextBox2" style="Z-INDEX: 102; LEFT: 32px; POSITION: absolute; TOP: 120px" runat="server"></asp:TextBox>
            <asp:TextBox id="TextBox2" style="Z-INDEX: 102; LEFT: 32px; POSITION: absolute; TOP: 120px" runat="server"></asp:TextBox>15
 <asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 32px; POSITION: absolute; TOP: 160px" runat="server"
            <asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 32px; POSITION: absolute; TOP: 160px" runat="server"16
 Text="有漏洞"></asp:Button>
                Text="有漏洞"></asp:Button>17
 <asp:Button id="Button2" style="Z-INDEX: 104; LEFT: 120px; POSITION: absolute; TOP: 160px" runat="server"
            <asp:Button id="Button2" style="Z-INDEX: 104; LEFT: 120px; POSITION: absolute; TOP: 160px" runat="server"18
 Text="修改后"></asp:Button>
                Text="修改后"></asp:Button>19
 </form>
        </form>20
 </body>
    </body>21
 </HTML>
</HTML>22

 
                     
                    
                 
                    
                 
 
         
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号