달력

3

« 2024/3 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

'Study/Java'에 해당되는 글 41

  1. 2010.06.26 SQL Injection 용으로 기억을 더듬어 만든 replace 메소드

public static String replace(String str, String oldstr, String newstr)
 {
  if (str == null)
   return null;

  String ans = "";
  int len = oldstr.length();
  int strlen = str.length();
  int pos = 0;
  int oldpos = 0;

  while ((pos = str.indexOf(oldstr, oldpos)) >= 0)
  {
   ans += str.substring(oldpos, pos) + newstr;
   oldpos = pos + len;
  }
  ans += str.substring(oldpos, strlen);

  return ans;
 }

이걸 만들고..
파라미터값으로 받아와서 이런식으로 처리해줬었다.

String value1 = Util.replace(paramter, "<", "&lt;");
String value2 = Util.replace(value1, ">", "&gt;");

근데 SQL INJECTION은 우회가 너무 쉬워서 짜증난다.. 완벽한 방어법은 없겠지.

:
Posted by 유쾌한순례자