이 글은 기계 번역의 미러 문서이며, 원본 기사로 바로 이동하려면 여기를 클릭해 주세요.

보기: 23797|회답: 2

[인터페이스] c#과 asp.net 는 SQL 주입 필터링 방법을 방지합니다

[링크 복사]
게시됨 2015. 4. 19. 오후 11:54:16 | | | |


저는 발표할 때 asp.net 를 사용해요, 하하

프런트 데스크 코드:
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="sqltest.aspx.cs" Inherits="TestWeb.sqltest" %>

  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5.     <title></title>
  6. </head>
  7. <body>
  8.     <form id="form1" runat="server">
  9.     <div>
  10.         <asp:TextBox ID="txtsql" runat="server"></asp:TextBox>
  11.         <asp:Button ID="btnsql" runat="server" Text="注入" onclick="btnsql_Click" />
  12.     </div>
  13.     </form>
  14. </body>
  15. </html>
코드 복사
배경 코드:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;

  7. namespace TestWeb
  8. {
  9.     public partial class sqltest : System.Web.UI.Page
  10.     {
  11.         protected void Page_Load(object sender, EventArgs e)
  12.         {

  13.         }

  14.         protected void btnsql_Click(object sender, EventArgs e)
  15.         {
  16.             
  17.             if (zhuru.ProcessSqlStr(txtsql.Text))
  18.             {
  19.                 Response.Write("安全");
  20.             }
  21.             else {
  22.                 Response.Write("危险");
  23.             }
  24.         }
  25.     }
  26. }
코드 복사
zhuru.cs 학급 코드:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Text.RegularExpressions;

  6. namespace TestWeb
  7. {
  8.     public class zhuru
  9.     {
  10.         
  11.         public static bool ProcessSqlStr(string inputString)
  12.         {
  13.             string SqlStr = @"and|or|exec|execute|insert|select|delete|update|alter|create|drop|count|\*|chr|char|asc|mid|substring|master|truncate|declare|xp_cmdshell|restore|backup|net +user|net +localgroup +administrators";
  14.             try
  15.             {
  16.                 if ((inputString != null) && (inputString != String.Empty))
  17.                 {
  18.                     string str_Regex = @"\b(" + SqlStr + @")\b";

  19.                     Regex Regex = new Regex(str_Regex, RegexOptions.IgnoreCase);
  20.                     //string s = Regex.Match(inputString).Value;
  21.                     if (true == Regex.IsMatch(inputString))
  22.                         return false;

  23.                 }
  24.             }
  25.             catch
  26.             {
  27.                 return false;
  28.             }
  29.             return true;
  30.         }

  31.     }
  32. }
코드 복사






이전의:C#. .NET 사용법: SQL 인젝션 공격 방지
다음:알려진 LAN IP 주소의 호스트명을 확인하는 방법
 집주인| 게시됨 2022. 2. 7. 오후 7:33:01 |
자바의 동적 스플라이싱 SQL 문은 데이터베이스 주입을 방지합니다
https://www.itsvse.com/thread-10249-1-1.html
게시됨 2022. 3. 6. 오전 10:40:43 |
배우기               
면책 조항:
Code Farmer Network에서 발행하는 모든 소프트웨어, 프로그래밍 자료 또는 기사는 학습 및 연구 목적으로만 사용됩니다; 위 내용은 상업적 또는 불법적인 목적으로 사용되지 않으며, 그렇지 않으면 모든 책임이 사용자에게 부담됩니다. 이 사이트의 정보는 인터넷에서 가져온 것이며, 저작권 분쟁은 이 사이트와는 관련이 없습니다. 위 내용은 다운로드 후 24시간 이내에 컴퓨터에서 완전히 삭제해야 합니다. 프로그램이 마음에 드신다면, 진짜 소프트웨어를 지원하고, 등록을 구매하며, 더 나은 진짜 서비스를 받아주세요. 침해가 있을 경우 이메일로 연락해 주시기 바랍니다.

Mail To:help@itsvse.com