一个被大多数初级程序员忽略的安全问题 [严重]

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

 1using System;
 2using System.Collections;
 3using System.ComponentModel;
 4using System.Data;
 5using System.Drawing;
 6using System.Web;
 7using System.Web.SessionState;
 8using System.Web.UI;
 9using System.Web.UI.WebControls;
10using System.Web.UI.HtmlControls;
11using System.Data.SqlClient;
12namespace 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 窗体设计器生成的代码
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


 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
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值