-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwaf-lib.php
86 lines (74 loc) · 2.48 KB
/
waf-lib.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/*
* Project: Update API
* Author: Vontainment
* URL: https://vontainment.com
* File: waf-lib.php
* Description: WordPress Update API
*/
// Sanitize and validate input data
function sanitize_input($data)
{
// Trim whitespace and remove HTML tags
$data = trim(strip_tags($data));
// Filter the input using appropriate filters
$data = filter_var($data, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
// Add additional security measures
$data = str_replace(array("<?", "?>", "<%", "%>"), "", $data);
$data = str_replace(array("<script", "</script"), "", $data);
$data = str_replace(array("/bin/sh", "exec(", "system(", "passthru(", "shell_exec(", "phpinfo("), "", $data);
return $data;
}
// Function to check if a string contains a disallowed character
function contains_disallowed_chars($str)
{
global $disallowed_chars;
foreach ($disallowed_chars as $char) {
if (strpos($str, $char) !== false) {
return true;
}
}
return false;
}
// Function to check if a string contains a disallowed pattern
function contains_disallowed_patterns($str)
{
global $disallowed_patterns;
foreach ($disallowed_patterns as $pattern) {
if (strpos($str, $pattern) !== false) {
return true;
}
}
return false;
}
function update_failed_attempts($ip)
{
$blacklist_file = BLACKLIST_DIR . "/BLACKLIST.json";
$content = json_decode(file_get_contents($blacklist_file), true);
if (isset($content[$ip])) {
$content[$ip]['login_attempts'] += 1;
if ($content[$ip]['login_attempts'] >= 3) {
$content[$ip]['blacklisted'] = true;
$content[$ip]['timestamp'] = time();
}
} else {
$content[$ip] = ['login_attempts' => 1, 'blacklisted' => false, 'timestamp' => time()];
}
file_put_contents($blacklist_file, json_encode($content));
}
function is_blacklisted($ip)
{
$blacklist_file = BLACKLIST_DIR . "/BLACKLIST.json";
$blacklist = json_decode(file_get_contents($blacklist_file), true);
if (isset($blacklist[$ip]) && $blacklist[$ip]['blacklisted']) {
// Check if the timestamp is older than three days
if (time() - $blacklist[$ip]['timestamp'] > (3 * 24 * 60 * 60)) {
// Remove the IP address from the blacklist
$blacklist[$ip]['blacklisted'] = false;
file_put_contents($blacklist_file, json_encode($blacklist));
} else {
return true;
}
}
return false;
}