달력

4

« 2025/4 »

  • 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
2024. 3. 6. 11:14

귀차니즘 sql injection PHP2024. 3. 6. 11:14

$string_404 ="<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL ".$_SERVER['PHP_SELF']." was not found on this server..</p>
</body></html>
";

 

탭이 왜이래? 수정하기 귀찮...

 

//검색등 $params값으로 들어오는 $_REQUEST값에 이상한게 있으면 로그로 기록한다.

//$_POST, $_GET 도 $_REQUEST 검사가능

// 로그인이나 검색 등 파라메터로 받는것들 체크용. 글쓰기 댓글쓰기등 체크에는 절대 사용금지.
//미리 체크하고 싶은 항목의 이름을 입력해준다. 예) check_request_attack('cate|page|search|scan');

function check_request_attack($params){
global $WEB_ROOTPATH, $string_404, $usercode;
if(!$params) return '';
$ck_param = explode('|', $params); $cntp = COUNT($ck_param);

 

// 차단할것들지금까지 확인된 애들.. '|' 로 구분
$noparam = 'nslookup|foreach|waitfor|\'||"|=|))|]]|}}|--|..|./|()|etc/|#$| or | and |passwd|set(|sleep(|assert(|md5(|chr(|hex(|decode(|xss.|concat(|_schema|union|script|cast(';


$ck_words = explode('|', $noparam);$cnt = COUNT($ck_words);


for($i=0; $i<$cntp; $i++){
$rqname = $ck_param[$i];
if(isset($_REQUEST[$rqname])){
$string=implode("", explode("\\", trim($_REQUEST[$rqname])));    

$rqval = stripslashes(trim($string)); //슬래시지우고


for($j=0; $j<$cnt; $j++){
if(stripos($rqval, $ck_words[$j]) !== false){ //로그기록한다.
$ss_time = date("Y-m-d_H:i", time()); $ss_ip = $_SERVER['REMOTE_ADDR']; $ss_proxy=$ENV['HTTP_X_FORWARDED_FOR']; $ss_browser = $_SERVER['HTTP_USER_AGENT'];
$svline = $ss_time.'|'.$_SERVER['PHP_SELF'].'| '.$rqname.' ** '.$ck_words[$j].' |'.$usercode.'|'.$ss_ip.'|'.$ss_proxy.'|'.$ss_browser."|\r\n";

 

if(!$WEB_ROOTPATH){ $WEB_ROOTPATH = '/home/daehan/www.daehan'; }
$svfile = $WEB_ROOTPATH.'/1_server_attack.cgi';

$fp = fopen($svfile, "a+"); flock($fp, LOCK_EX); fwrite($fp, $svline); flock($fp, LOCK_UN); fclose($fp);


//unset($_REQUEST[$rqname]); break; //에러로 중지하는것 없이 해당변수를 지우고 계속 진행
echo $string_404; exit; //페이지 없다고 표시하고 짤없이 멈춘다.
} //제한된게 있다면


}  //of $j
} //of isset
} //of for $i
} //of function

:
Posted by 비개인오후