在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1.什么是SQL注入 所谓SQL注入式攻击,就是攻击者把SQL命令插入到Web表单的输入域或页面请求的查询字符串,欺骗服务器执行恶意的SQL命令。在某些表单中,用户输入的内容直接用来构造(或者影响)动态SQL命令,或作为存储过程的输入参数,这类表单特别容易受到SQL注入式攻击。 2.怎么进行SQL注入 关于怎么进行SQL注入,网上已经有很多文章详细介绍过了,可以参考博友滴答的雨的博文 《SQL注入攻防入门详解》,亲测有效。当执行完文中的5、6、7三步的时候,你会发现服务器上的安全保护措施都已是浮云,服务器也因此变成了名副其实的“肉机”。下面附上一张我在本机执行完文中描述的脚本后的效果截图(Win8 x64 操作系统):
1: /// <summary> 2: ///SqlInject 的摘要说明 3: /// </summary> 4: public class SqlInject : System.Web.UI.Page 5: { 6: //检测到注入后的处理方式: 0:仅警告;1:警告+记录;2:警告+自定义错误页面;3:警告+记录+自定义错误页面 7: private const int _type = 0; 8: private const string errRedirectPage = "/err.aspx"; 9: 10: //如果记录注入信息,那么请设置:errMDBpath:数据库路径 11: private const string errMDBpath = "/SqlInject.mdb"; 12: 13: 14: //过滤特征字符 15: //过滤特征字符 16: private static string StrKeyWord = ConfigurationManager.AppSettings["SqlKeyWord"]; //@"select|insert|delete|from|count(|drop table|update|truncate|asc(|mid(|char(|xp_cmdshell|exec|master|net local group administrators|net user|or|and"; 17: private static string StrRegex = ConfigurationManager.AppSettings["SqlRegex"]; //@";|/|(|)|[|]|{|}|%|@|*|'|!"; // 原始过滤条件:【-|;|,|/|(|)|[|]|{|}|%|@|*|'|!】 18: 19: private HttpRequest request; 20: public SqlInject(System.Web.HttpRequest _request) 21: { 22: this.request = _request; 23: } 24: ///<summary> 25: ///检测SQL注入及记录、显示出错信息 26: ///</summary> 27: public void CheckSqlInject() 28: { 29: bool isInject = false; 30: if (CheckRequestQuery() || CheckRequestForm()) 31: { 32: isInject = true; 33: } 34: else 35: { 36: return; 37: } 38: 39: switch (_type) 40: { 41: case 0: 42: ShowErr(); 43: break; 44: case 1: 45: ShowErr(); 46: SaveToMdb(); 47: break; 48: case 2: 49: ShowErr(); 50: string temp; 51: System.Web.HttpContext.Current.Response.Write("<script>setTimeout(\"" + "location.href='" + errRedirectPage + "'" + "\",5000)</script>"); 52: break; 53: case 3: 54: ShowErr(); 55: SaveToMdb(); 56: System.Web.HttpContext.Current.Response.Write("<script>setTimeout(\"" + "location.href='" + errRedirectPage + "'" + "\",5000)</script>"); 57: break; 58: default: 59: break; 60: } 61: System.Web.HttpContext.Current.Response.End(); 62: 63: } 64: private void SaveToMdb() 65: { 66: OleDbConnection conn = new OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0;Data Source=" + Server.MapPath(errMDBpath)); 67: conn.Open(); 68: OleDbCommand cmd = conn.CreateCommand(); 69: 70: cmd.CommandText = "insert into [Record] (sIP,sDate,sPath) values ('" + 71: request.ServerVariables["REMOTE_ADDR"].ToString() + "','" + 72: DateTime.Now + "','" + request.ServerVariables["URL"].ToLower() + RelaceSingleQuotes(request.QueryString.ToString()) + "')"; 73: int code = cmd.ExecuteNonQuery(); 74: if (code == 1) 75: System.Web.HttpContext.Current.Response.Write("<br>****以上信息已记录至日志数据库****"); 76: else 77: System.Web.HttpContext.Current.Response.Write("<br>日志数据库出错"); 78: conn.Close(); 79: 80: } 81: private string RelaceSingleQuotes(string _url) 82: { 83: string URL = _url.Replace("'", "单引号"); 84: return URL; 85: } 86: private void ShowErr() 87: { 88: //string msg = @"<font color=red>请不要尝试未授权之入侵检测!</font>" + @"<br><br>"; 89: //msg += @"操作IP:" + request.ServerVariables["REMOTE_ADDR"] + @"<br>"; 90: //msg += @"操作时间:" + DateTime.Now + @"<br>"; 91: //msg += @"页面:" + request.ServerVariables["URL"].ToLower() + request.QueryString.ToString() + @"<br>"; 92: //msg += @"<a href='#' onclick='javascript:window.close()'>关闭</a>"; 93: //System.Web.HttpContext.Current.Response.Clear(); 94: //System.Web.HttpContext.Current.Response.Write(msg); 95: System.Web.HttpContext.Current.Response.Write("<script>alert('请不要尝试未授权之入侵检测!');javascript:history.go(-1);</script>"); 96: } 97: ///<summary> 98: /// 特征字符 99: ///</summary> 100: public static string KeyWord 101: { 102: get 103: { 104: return StrKeyWord; 105: } 106: } 107: ///<summary> 108: /// 特征符号 109: ///</summary> 110: public static string RegexString 111: { 112: get 113: { 114: return StrRegex; 115: } 116: }
全部评论
专题导读
上一篇:MySQL远程连接不上的解决方法发布时间:2022-02-08下一篇:使用Mysql5.x以上版本出现报错#1929 Incorrect datetime value: '''' ...发布时间:2022-02-08热门推荐
热门话题
阅读排行榜
|
请发表评论