-
Notifications
You must be signed in to change notification settings - Fork 41
/
CTF_WAF.php
68 lines (66 loc) · 1.64 KB
/
CTF_WAF.php
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
$log_file_path = './log.txt';
$blackIp = ['127.0.0.1'];
/**
* [access 日志记录模块]
* @return [type] [description]
*/
function access(){
global $log_file_path;
if($_FILES!=[]){
$tmp = [];
foreach ($_FILES as $key => $value) {
array_push($tmp,["filename"=>$_FILES[$key]["name"],"contents"=>base64_encode(file_get_contents($_FILES[$key]["tmp_name"]))]);
}
$flow = array(
'Userip'=>$_SERVER['REMOTE_ADDR'],
'Path' =>'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"],
'Post'=>$_POST,
"File"=>$tmp,
'Cookie'=>$_COOKIE,
'Time'=> date('Y-m-s h:i:s',time())
);
}else{
$flow = array(
'Userip'=>$_SERVER['REMOTE_ADDR'],
'Path' =>'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"],
'Post'=>$_POST,
'Cookie'=>$_COOKIE,
'Time'=> date('Y-m-s h:i:s',time())
);
}
$log_path = $log_file_path;
$f = fopen($log_path,'a');
fwrite($f,"\n".json_encode($flow,true));
fclose($f);
}
/**
* [banIP IP封禁模块]
* @return [type] [description]
*/
function banIP(){
global $blackIp;
if(is_file('black.txt')){
$blackIp = array_filter(explode("\n",file_get_contents('black.txt')));
}
$userIP = $_SERVER['REMOTE_ADDR'];
$_not_found = <<<END
<!DOCTYPE html PUBLIC '-//IETF//DTD HTML 2.0//EN'>
<html><head>
<meta http-equiv='content-type' content='text/html; charset=windows-1252'>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL / was not found on this server.</p>
</body>
</html>
END;
if(in_array($userIP,$blackIp)){
$staus_code = "HTTP/1.1 404 Not Found";
header($staus_code);
die($_not_found);
}
}
access();
banIP();
?>