program/asp.net

sql injection 처리 함수

yoursyun 2009. 2. 24. 15:58

받아온 파라미터를 '|'를 통한 형태의 문자열 체크 표본을 만들고 검사 한다.

public string chk_Injection(string strParam)
  {
    string pattern = "script|iframe|frameset|onmouse"
      + "|select|declare|delete|create|drop|union|exec|sp_oacreate"
      + "|xp_cmdshell|shutdown|kill|truncate|execmaster|netlocalgroupadministratthens"
      + "|--|@variable|@@variable|sysobject";
    string rtnString = strParam;

    Regex rx = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);

    if (rtnString != null)
    {
      rtnString = rtnString.Replace("'", "'");
      rtnString = rtnString.Replace("\"", """);
      rtnString = rx.Replace(rtnString, "");
    }

    return rtnString;
  }

반응형