[패턴문자]
ls |
dir |
type |
cat |
netstat |
set |
ipconfig |
ifconfig |
; |
& |
| |
|
- 패턴 문자 필터링
JSP SQL Injection 시큐어 코딩
page.jsp 파일중에서
String param = request.getParameter('field');
Pattern PreventChar = Pattern.compile("['\"\\-#()@;=*/+]"); String filteredData = PreventChar.matcher(param).replaceAll("");
OR
String[] PreventChars = {"ls","dir"...} //위 표에 있는 데이터 나열함.
for (int i=0; i< PreventChars.length; i++) { if(param.indexOf(PreventChars[i]) != -1){ System.out.println("금지된 키워드 사용입니다."); return false; } }
PHP
SQL Injection 시큐어 코딩
page.php 파일중에서
$param = $_POST['field'] or $_GET['field'];
$filtereddata = htmlspecialchars($param); $filtereddata = strip_tags($filtereddata); $filtereddata = mysql_real_escape_string($filtereddata);
OR
$PreventChars = array("'","\""...); //위 표에 있는 데이터 나열함.
foreach($PreventChars as $keyword){ $param = str_replace($keyword,"",$param); }
db.php 파일중에서
$value =
$filtereddata;
$sth = $dbh->prepare('select field1, field2...from table where
field1 = :field1');
$sth->bindValue(':field1',$value,PDO:PARAM:STR,10);
$sth->execute();
ASP.NET
(C#) 시큐어 코딩(MSDN 참조)
page.aspx 파일중에서
<%@ Page Language="C#" ValidateRequest="false"%>
<script runat="server">
void submitBtn_Click(object sender, EventArgs e)
{
string[] patterns = {"./"...}; 위 표에 나열된 데이터 나열함
// Encode the string input
StringBuilder sb = new StringBuilder(HttpUtility.HtmlEncode(htmlInputTxt.Text));
for(int i=0; i<patterns.length; i++){
if(pattens[i].indexOf(sb.ToString()) > 0){
sb.Replace(pattenrs[i],"");
}
}
Response.Write(sb.ToString());
}
</script>
<html>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="htmlInputTxt" Runat="server"
TextMode="MultiLine" Width="318px"
Height="168px"></asp:TextBox>
<asp:Button ID="submitBtn" Runat="server"
Text="Submit" OnClick="submitBtn_Click" />
</div>
</form>
</body>
</html>
|