自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

數(shù)據(jù)庫防腳本注入

安全 數(shù)據(jù)安全
下面分享一個(gè)使用的防止數(shù)據(jù)庫Sql腳本注入的使用類

 

網(wǎng)站安全非常重要,所以一個(gè)網(wǎng)站必須要有對攻擊的基礎(chǔ)防范措施,比如腳本攻擊,跨域攻擊,數(shù)據(jù)庫注入攻擊等。下面分享一個(gè)使用的防止數(shù)據(jù)庫Sql腳本注入的使用類

using System;

using System.Collections.Generic;

using System.Text;

namespace NZS.Common

{

public class Filter

{

///

/// 檢測是否含有危險(xiǎn)字符(防止Sql注入)

///

/// 預(yù)檢測的內(nèi)容

/// 返回True或false

public static bool HasSqlKeywords(string contents)

{

bool ReturnValue = false;

if (contents.Length > 0)

{

string LowerStr = contents.ToLower();

string RxStr = @”(/sand/s)|(/sand/s)|(/slike/s)|(select/s)|(insert/s)|(delete/s)|(update/s[/s/S].*/sset)|(create/s)|(/stable)|(<[iframe|/iframe|script|/script])|(‘)|(/sexec)|(declare)|(/struncate)|(/smaster)|(/sbackup)|(/smid)|(/scount)|(cast)|(%)|(/sadd/s)|(/salter/s)|(/sdrop/s)|(/sfrom/s)|(/struncate/s)|(/sxp_cmdshell/s)”; //Match 檢查數(shù)據(jù)庫里面關(guān)鍵字和一些特殊字符,如單引號

System.Text.RegularExpressions.Regex Rx = new System.Text.RegularExpressions.Regex(RxStr);

ReturnValue = Rx.IsMatch(LowerStr, 0);

}

return ReturnValue;

}

///

/// 過濾 Sql 語句字符串中的注入腳本

///

/// 傳入的字符串

/// 過濾后的字符串

public static string SqlFilter(string str)

{

str = str.Replace(“””, “‘’”);

//單引號替換成兩個(gè)單引號

str = str.Replace(“‘”, “‘”);

//半角封號替換為全角封號,防止多語句執(zhí)行

str = str.Replace(“;”, “;”);

//半角括號替換為全角括號

str = str.Replace(“(“, “(”);

str = str.Replace(“)”, “)”);

///////////////要用正則表達(dá)式替換,防止字母大小寫得情況////////////////////

//去除執(zhí)行存儲過程的命令關(guān)鍵字

str = str.Replace(“Exec”, “”);

str = str.Replace(“Execute”, “”);

//去除系統(tǒng)存儲過程或擴(kuò)展存儲過程關(guān)鍵字

str = str.Replace(“xp_”, “x p_”);

str = str.Replace(“sp_”, “s p_”);

//防止16進(jìn)制注入

str = str.Replace(“0x”, “0 x”);

return str;

}

}

}

責(zé)任編輯:藍(lán)雨淚 來源: 道人家
相關(guān)推薦

2010-09-30 09:11:01

2010-09-30 08:27:48

2014-01-17 12:35:48

2010-09-14 19:50:55

2025-04-15 08:40:00

數(shù)據(jù)庫悲觀鎖樂觀鎖

2009-03-16 13:30:55

腳本數(shù)據(jù)字典Oracle

2013-07-25 20:36:02

2010-10-22 15:09:39

2011-05-16 09:32:33

mysql數(shù)據(jù)庫備份

2015-07-16 17:00:15

MySQLMariaDBPercona

2010-09-09 14:31:31

SQL函數(shù)數(shù)據(jù)庫

2013-01-11 16:31:27

2017-10-20 13:28:50

2022-11-08 08:11:52

PG數(shù)據(jù)庫防誤

2010-05-20 15:22:37

2009-02-01 10:29:04

Oracle數(shù)據(jù)庫管理

2010-04-12 08:59:00

2018-12-12 19:10:01

Oracle數(shù)據(jù)庫自動備份

2009-07-16 11:04:17

Jython連接數(shù)據(jù)庫

2015-09-15 16:29:25

點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號