-
Notifications
You must be signed in to change notification settings - Fork 0
/
weird-file.php
38 lines (32 loc) · 836 Bytes
/
weird-file.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
<?php
//error_reporting(E_ALL);
$key = '# **access-flag - End script';
$newfile = 'filetemp.txt';
$date = date('Y-m-d H:i:s');
if (($handle = fopen('.htaccess', "r")) !== FALSE) {
while (!feof ($handle)) {
$buffer = fgets($handle, 4096);
$lines[] = $buffer;
}
$f = fopen($newfile, "w") or die();
foreach($lines as $line) {
if (strpos($line, $key) !== false){
$ip = getRealIpAddr();
fwrite($f, "deny from ".$ip." # added ".$date."\n");
}
fwrite($f, $line);
}
fclose($f);
copy($newfile, '.htaccess') or die();
}
function getRealIpAddr() {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip=$_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
?>