C:\xampp\htdocs\landing\wp-content\plugins\malcare-security\protect\wp\lp\lp.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<?php

if (!defined('ABSPATH')) exit;
if (!
class_exists('BVWPLP')) :
    

class 
BVWPLP {
    public 
$db;
    public 
$settings;
    private 
$ip;
    private 
$time;
    private 
$category;
    private 
$username;
    private 
$message;
    public 
$config;
    public 
$logger;
    public 
$ipstore;
    public static 
$requests_table 'lp_requests';
    public static 
$unblock_ip_transient 'bvlp_unblock_ip';

    
#status
    
const LOGINFAILURE 1;
    const 
LOGINSUCCESS 2;
    const 
LOGINBLOCKED 3;

    
#categories
    
const CAPTCHABLOCK 1;
    const 
TEMPBLOCK    2;
    const 
ALLBLOCKED   3;
    const 
UNBLOCKED    4;
    const 
BLACKLISTED  5;
    const 
BYPASSED     6;
    const 
ALLOWED      7;
    
    public function 
__construct($db$settings$ip$ipstore$confHash) {
        
$this->db $db;
        
$this->settings $settings;
        
$this->ip $ip;
        
$this->config = new BVWPLPConfig($confHash);
        
$this->ipstore $ipstore;
        
$this->logger = new BVLogger($dbBVWPLPConfig::$requests_table);
        
$this->time strtotime(date("Y-m-d H:i:s"));
    }

    public function 
init() {
        
add_filter('authenticate', array($this'loginInit'), 303);
        
add_action('wp_login', array($this'loginSuccess'));
        
add_action('wp_login_failed', array($this'loginFailed'));
    }

    public function 
setMessage($message) {
        
$this->message $message;
    }

    public function 
setUserName($username) {
        
$this->username $username;
    }

    public function 
setCategory($category) {
        
$this->category $category;
    }

    public function 
getCaptchaLink() {
        
$account MCAccount::apiPublicAccount($this->settings);
        
$url $account->authenticatedUrl('/captcha/solve');
        
$url .= "&adminurl=".base64_encode(get_admin_url());
        return 
$url;
    }

    public function 
getUserName() {
        return 
$this->username $this->username '';
    }

    public function 
getMessage() {
        return 
$this->message $this->message '';
    }

    public function 
getCategory() {
        return 
$this->category $this->category BVWPLP::ALLOWED;
    }

    public function 
getCaptchaLimit() {
        return 
$this->config->captchaLimit;
    }

    public function 
getTempBlockLimit() {
        return 
$this->config->tempBlockLimit;
    }

    public function 
getBlockAllLimit() {
        return 
$this->config->blockAllLimit;
    }

    public function 
getAllowLoginsTransient() {
        return 
$this->settings->getTransient('bvlp_allow_logins');
    }

    public function 
getBlockLoginsTransient() {
        return 
$this->settings->getTransient('bvlp_block_logins');
    }

    public function 
terminateTemplate() {
        
$info = new MCInfo($this->settings);
        
$brandname $info->getBrandName().' Firewall';
        
$templates = array (
            
=> "<p>Too many failed attempts, You are barred from logging into this site.</p><a href=".$this->getCaptchaLink().
                    class='btn btn-default'>Click here</a> to unblock yourself."
,
            
=> "You cannot login to this site for 30 minutes because of too many failed login attempts.",
            
=> "<p>Logins to this site are currently blocked.</p><a href=".$this->getCaptchaLink().
                    class='btn btn-default'>Click here</a> to unblock yourself."
,
            
=> "Your IP is blacklisted."
        
);
            return 
"
            <div style='height: 98vh;'>
                <div style='text-align: center; padding: 10% 0; font-family: Arial, Helvetica, sans-serif;'>
                    <div><p><img src="
.plugins_url('/../../../img/icon.png'__FILE__)."><h2>Login Protection</h2><h3>powered by</h3><h2>"
                            
.$brandname."</h2></p><div>
                    <p>" 
$templates[$this->getCategory()]. "</p>
                    <p>Reference ID: " 
MCInfo::getRequestID() . "</p>
                </div>
            </div>"
;
    }

    public function 
isProtecting() {
        return (
$this->config->mode === BVWPLPConfig::PROTECT);
    }

    public function 
isActive() {
        return (
$this->config->mode !== BVWPLPConfig::DISABLED);
    }

    public function 
isBlacklistedIP() {
        return 
$this->ipstore->isLPIPBlacklisted($this->ip);
    }

    public function 
isWhitelistedIP() {
        return 
$this->ipstore->isLPIPWhitelisted($this->ip);
    }

    public function 
isUnBlockedIP() {
        
$transient_name BVWPLP::$unblock_ip_transient.$this->ip;
        
$attempts $this->settings->getTransient($transient_name);
        if (
$attempts && $attempts 0) {
            
$this->settings->setTransient($transient_name$attempts 1600 $attempts);
            return 
true;
        }
        return 
false;
    }

    public function 
isLoginBlocked() {
        if (
$this->getAllowLoginsTransient() ||
                (
$this->getLoginCount(BVWPLP::LOGINFAILURE) < $this->getBlockAllLimit())) {
            return 
false;
        }
        return 
true;
    }

    public function 
log($status) {
        
$data = array (
            
"ip" => $this->ip,
            
"status" => $status,
            
"time" => $this->time,
            
"category" => $this->getCategory(),
            
"username" => $this->getUserName(),
            
"request_id" => MCInfo::getRequestID(),
            
"message" => $this->getMessage());
        
$this->logger->log($data);
    }

    public function 
terminateLogin() {
        
$this->setMessage('Login Blocked');
        
$this->log(BVWPLP::LOGINBLOCKED);
        if (
$this->isProtecting()) {
            
header("Cache-Control: no-cache, no-store, must-revalidate");
            
header("Pragma: no-cache");
            
header("Expires: 0");
            
header('HTTP/1.0 403 Forbidden');
            die(
$this->terminateTemplate());
            exit;
        }
    }

    public function 
loginInit($user$username ''$password '') {
        if (
$this->isUnBlockedIP()) {
            
$this->setCategory(BVWPLP::UNBLOCKED);
        } else {
            
$failed_attempts $this->getLoginCount(BVWPLP::LOGINFAILURE$this->ip);
            if (
$this->isWhitelistedIP()) {
                
$this->setCategory(BVWPLP::BYPASSED);
            } else if (
$this->isBlacklistedIP()) {
                
$this->setCategory(BVWPLP::BLACKLISTED);
                
$this->terminateLogin();
            } else if (
$this->isKnownLogin()) {
                
$this->setCategory(BVWPLP::BYPASSED);
            } else if (
$this->isLoginBlocked()) {
                
$this->setCategory(BVWPLP::ALLBLOCKED);
                
$this->terminateLogin();
            } else if (
$failed_attempts >= $this->getTempBlockLimit()) {
                
$this->setCategory(BVWPLP::TEMPBLOCK);
                
$this->terminateLogin();
            } else if (
$failed_attempts >= $this->getCaptchaLimit()) {
                
$this->setCategory(BVWPLP::CAPTCHABLOCK);
                
$this->terminateLogin();
            }
        }
        if (!empty(
$user) && !empty($password) && is_wp_error($user)) {
            
$this->setMessage($user->get_error_code());
        }
        return 
$user;
    }

    public function 
loginFailed($username) {
        
$this->setUserName($username);
        
$this->log(BVWPLP::LOGINFAILURE);
    }

    public function 
loginSuccess($username) {
        
$this->setUserName($username);
        
$this->setMessage('Login Success');
        
$this->log(BVWPLP::LOGINSUCCESS);
    }

    public function 
isKnownLogin() {
        return 
$this->getLoginCount(BVWPLP::LOGINSUCCESS$this->ip3600) > 0;
    }

    public function 
getLoginCount($status$ip null$gap 1800) {
        
$db $this->db;
        
$table $db->getBVTable(BVWPLP::$requests_table);
        
$query $db->prepare("SELECT COUNT(*) as count from `$table` WHERE status=%d && time > %d", array($status, ($this->time $gap)));
        if (
$ip) {
            
$query .= $db->prepare(" && ip=%s"$ip);
        }
        
$rows $db->getResult($query);
        if (!
$rows)
            return 
0;
        return 
intval($rows[0]['count']);
    }
}
endif;
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586