zoukankan      html  css  js  c++  java
  • .net防止数据注入

    把以下代码放入global.asax
            protected void Application_BeginRequest(Object sender, EventArgs e)
            
    {
                StartProcessRequest();
            }
            private void StartProcessRequest()
            
    {
                
    try
                
    {
                    
    string sqlErrorPage = "Error.aspx";//转向的错误提示页面 
                    if (System.Web.HttpContext.Current.Request.QueryString != null)
                    
    {

                        
    string url = Request.Url.ToString();
                        
    if (!ProcessSqlStr(url))
                        
    {
                            Response.Redirect(sqlErrorPage);
                        }


                    }

                    
    if (System.Web.HttpContext.Current.Request.Form != null)
                    
    {
                            System.Collections.Specialized.NameObjectCollectionBase.KeysCollection getkeys 
    = System.Web.HttpContext.Current.Request.Form.Keys;
                        
                            
    for (int j = 0; j < getkeys.Count; j++)
                            
    {
                                
                                
    if (getkeys[j] == "__VIEWSTATE"continue;
                                
    if (!ProcessSqlStr(System.Web.HttpContext.Current.Request.Form[getkeys[j]]))
                                
    {
                                    System.Web.HttpContext.Current.Response.Redirect(sqlErrorPage);
                                    System.Web.HttpContext.Current.Response.End();
                                }


                            }

                    }

                }

                
    catch
                
    {
                    
    // 错误处理: 处理用户提交信息! 
                }

            }

            
    private bool ProcessSqlStr(string Str)
            
    {
                
    bool ReturnValue = true;
                
    try
                
    {
                    
    if (Str.Trim() != "")
                    
    {
                        
    string SqlStr = "and¦exec¦insert¦select¦delete¦update¦count¦*¦chr¦mid¦master¦truncate¦char¦declare";

                        
    string[] anySqlStr = SqlStr.Split('¦');
                        
    foreach (string ss in anySqlStr)
                        
    {
                            
    if (Str.ToLower().IndexOf(ss) >= 0)
                            
    {
                                ReturnValue 
    = false;
                                
    break;
                            }

                        }

                    }

                }

                
    catch
                
    {
                    ReturnValue 
    = false;
                }

                
    return ReturnValue;
            }
  • 相关阅读:
    DedeCMS Xss+Csrf Getshell dedefile_manage_control.php
    dedeCMS /plus/ad_js.php、/plus/mytag_js.php Vul Via Injecting PHP Code By /plus/download.php Into DB && /include/dedesql.class.php
    phpMyadmin /scripts/setup.php Execute Arbitrary PHP Code Via A Crafted POST Request CVE-2010-3055
    Linux inode && Fast Directory Travel Method(undone)
    Linux进程自保护攻防对抗技术研究(Process Kill Technology && Process Protection Against In Linux)
    PHP Web System Optimization(undone)
    PHP Simulation HTTP Request(undone)
    Server Data Synchronization Via Linux rsync、rsync+inotify Between Load Balance Server
    Ecshop /admin/get_password.php Password Recovery Secrect Code Which Can Predict Vulnerability
    Dedecms includedialogselect_soft_post.php Upload Any Files To The Specified Directory Via Variable Not Initial Flaw Bypass Extension Defence
  • 原文地址:https://www.cnblogs.com/weichuo/p/1205891.html
Copyright © 2011-2022 走看看