在看到这个提示之前我也如此,呵呵,但是肯定还是有很多朋友都知道这个,但是忽略这个问题的人我想一定不会在少数!具体看下面,按照我的老规矩,做成一个Demo,前后台页代码都在,只是数据库,我是用的SQL,数据哭结构只有两个字段,一个用户名,一个密码,所以自己都可以建一个就是,呵呵!!
后台C#代码
1
using System;
2
using System.Collections;
3
using System.ComponentModel;
4
using System.Data;
5
using System.Drawing;
6
using System.Web;
7
using System.Web.SessionState;
8
using System.Web.UI;
9
using System.Web.UI.WebControls;
10
using System.Web.UI.HtmlControls;
11
using System.Data.SqlClient;
12
namespace Ado.net
13

{
14
/**//// <summary>
15
/// WebForm1 的摘要说明。
16
/// </summary>
17
public class WebForm1 : System.Web.UI.Page
18
{
19
protected System.Web.UI.WebControls.TextBox TextBox1;
20
protected System.Web.UI.WebControls.TextBox TextBox2;
21
protected System.Web.UI.WebControls.Button Button1;
22
protected System.Web.UI.WebControls.Button Button2;
23
24
private void Page_Load(object sender, System.EventArgs e)
25
{
26
// 在此处放置用户代码以初始化页面
27
}
28
29
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
30
override protected void OnInit(EventArgs e)
31
{
32
//
33
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
34
//
35
InitializeComponent();
36
base.OnInit(e);
37
}
38
39
/**//// <summary>
40
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
41
/// 此方法的内容。
42
/// </summary>
43
private void InitializeComponent()
44
{
45
this.Button1.Click += new System.EventHandler(this.Button1_Click);
46
this.Button2.Click += new System.EventHandler(this.Button2_Click);
47
this.Load += new System.EventHandler(this.Page_Load);
48
49
}
50
#endregion
51
52
private SqlConnection con()
53
{//下面有调用几次这个,所以就做个方法,呵呵,没有意见吧
54
SqlConnection con=new SqlConnection("server=.;database=voteone;uid=sa;pwd=980123;");
55
return con;
56
}
57
private void Button1_Click(object sender, System.EventArgs e)
58
{
59
SqlConnection con=this.con();
60
con.Open();
61
SqlCommand cmd=new SqlCommand("select * from admin where name='"+TextBox1.Text+"' and pwd='"+TextBox2.Text+"'",con);
62
SqlDataReader sdr=cmd.ExecuteReader();
63
if(sdr.Read())
64
{//这个成功不需要输入密码或者连用户名都不用输入就可以得到
65
//例如你在第第一个文本框里输入 thc '-- (这个是假设我们知道用户名是thc)或者 ' or 1=1-- (这个更厉害了,更本就不需要知道什么,重要知道 1=1就可以了)
66
Response.Write("登陆成功");
67
}
68
else
69
{
70
Response.Write("失败");
71
}
72
}
73
74
private void Button2_Click(object sender, System.EventArgs e)
75
{//下面方法主要是使用了Replace关键字把传近来的字符中的 单引号给替换了('),其他没有什么,呵呵
76
SqlConnection con=this.con();
77
con.Open();
78
SqlCommand cmd=new SqlCommand("select * from admin where name='"+TextBox1.Text.Replace("'","''")+"' and pwd='"+TextBox2.Text.Replace("'","''")+"'",con);
79
SqlDataReader sdr=cmd.ExecuteReader();
80
if(sdr.Read())
81
{
82
Response.Write("登陆成功");
83
}
84
else
85
{
86
Response.Write("失败");
87
}
88
}
89
}
90
}
91
前台HTML代码
1
<%
@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="Ado.net.WebForm1" %>
2
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
3
<HTML>
4
<HEAD>
5
<title>WebForm1</title>
6
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
7
<meta name="CODE_LANGUAGE" Content="C#">
8
<meta name="vs_defaultClientScript" content="JavaScript">
9
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
10
</HEAD>
11
<body MS_POSITIONING="GridLayout">
12
<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>
14
<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"
16
Text="有漏洞"></asp:Button>
17
<asp:Button id="Button2" style="Z-INDEX: 104; LEFT: 120px; POSITION: absolute; TOP: 160px" runat="server"
18
Text="修改后"></asp:Button>
19
</form>
20
</body>
21
</HTML>
22


1

2

3

4

5

6

7

8

9

10

11

12

13



14


15

16

17

18



19

20

21

22

23

24

25



26

27

28

29


30

31



32

33

34

35

36

37

38

39


40

41

42

43

44



45

46

47

48

49

50

51

52

53



54

55

56

57

58



59

60

61

62

63

64



65

66

67

68

69



70

71

72

73

74

75



76

77

78

79

80

81



82

83

84

85



86

87

88

89

90

91



1



2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22
