數(shù)據(jù)庫(kù)防腳本注入
來(lái)源:易賢網(wǎng) 閱讀:1123 次 日期:2015-09-24 15:23:36
溫馨提示:易賢網(wǎng)小編為您整理了“數(shù)據(jù)庫(kù)防腳本注入”,方便廣大網(wǎng)友查閱!

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

using System;

using System.Collections.Generic;

using System.Text;

namespace NZS.Common

{

public class Filter

{

///

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

///

/// 預(yù)檢測(cè)的內(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ù)庫(kù)里面關(guān)鍵字和一些特殊字符,如單引號(hào)

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

ReturnValue = Rx.IsMatch(LowerStr, 0);

}

return ReturnValue;

}

///

/// 過(guò)濾 Sql 語(yǔ)句字符串中的注入腳本

///

/// 傳入的字符串

/// 過(guò)濾后的字符串

public static string SqlFilter(string str)

{

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

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

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

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

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

//半角括號(hào)替換為全角括號(hào)

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

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

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

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

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

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

//去除系統(tǒng)存儲(chǔ)過(guò)程或擴(kuò)展存儲(chǔ)過(guò)程關(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;

}

}

}

更多信息請(qǐng)查看IT技術(shù)專(zhuān)欄

更多信息請(qǐng)查看數(shù)據(jù)庫(kù)

扫描二维码关注易贤网公众号

易賢網(wǎng)手機(jī)網(wǎng)站地址:數(shù)據(jù)庫(kù)防腳本注入
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢(xún)回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門(mén)公布的正式信息和咨詢(xún)?yōu)闇?zhǔn)!

2025國(guó)考·省考課程試聽(tīng)報(bào)名

  • 報(bào)班類(lèi)型
  • 姓名
  • 手機(jī)號(hào)
  • 驗(yàn)證碼

【备考推荐】2025年事业单位联考系统精讲课,免费试看,配套资料包邮到家

關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢(xún) | 簡(jiǎn)要咨詢(xún)須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專(zhuān)用圖標(biāo)
聯(lián)系電話(huà):0871-65099533/13759567129 獲取招聘考試信息及咨詢(xún)關(guān)注公眾號(hào):hfpxwx
咨詢(xún)QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專(zhuān)用圖標(biāo)