본문 바로가기

IT/Java

Xss 컴파일 함수

 

private boolean searchReservedChars(String value, String paramName) {

                           value=value.toLowerCase();

                           Pattern xsspattern = Pattern.compile("[\\w]*((%27)|())\\s*((%6F)|o|(%4F))((%72)|r|(%52))"                      + "|[\\w]*((%27)|())\\s*((%61)|a|(%41))((%6E)|n|(%4E))((%64)|d|(%44))" 

    + "|(((%3E)|>|(%3C)|<))"

    + "|(((%3E)|>|(%3C)|<)+.*[://.=/(/);'\"&#-]+.*)"  

    + "|(.*[://.=/(/);'\"&#-]+.*((%3E)|>|(%3C)|<)+)" 

    + "|(((%3C)|<)((%69)|i|(%49))((%6D)|m|(%4D))((%67)|g|(%47))[^\\n]+((%3E)|>))");

                           Matcher match = xsspattern.matcher(value);

                          

                           if(match.find()) {

                                        String charstr = value.substring(match.start(), match.end());

                                        charstr = charstr.replaceAll(">", "&gt;");

                                        charstr = charstr.replaceAll("<", "&lt;");

                                        charstr = charstr.replaceAll("|", "");

                                        charstr = charstr.replaceAll("&", "");

                                        charstr = charstr.replaceAll(";", "");

                                        return true;

                           }

                           return false;

             }