Skip to content

Commit ed15272

Browse files
committed
readme fix 2
1 parent d3ad9dd commit ed15272

4 files changed

Lines changed: 74 additions & 2 deletions

File tree

wordpress-fail2ban/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Trigger banning on malicious requests by the fail2ban daemon running on a server.
44
Shared hosting has no server-wide banning (because of security reasons)
5-
but you can use it without fail2ban to stop attack temporarily by setting trigger count to 1.
5+
but you can use it without fail2ban to stop attacks temporarily by setting trigger count to 1.
66

77
### block-bad-requests
88

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
/*
4+
*Apache
5+
*NGINX
6+
*other environments
7+
*/
8+
9+
function htaccess_rules() {
10+
11+
-> better-wp-security/core/class-itsec-files.php
12+
13+
define() custom HTTP header to get IP default:'X-CLUSTER-CLIENT-IP'
14+
preg_quote $host_ip
15+
"SetEnvIF " . array( 'REMOTE_ADDR', 'X-FORWARDED-FOR' ) $deny_env;
16+
# Apache < 2.3, # Apache ≥ 2.3
17+
<IfModule !mod_authz_core.c>
18+
Order allow,deny
19+
Deny from env=$deny_env
20+
# Deny from $host_ip
21+
Allow from all
22+
Satisfy All
23+
</IfModule>
24+
<IfModule mod_authz_core.c>
25+
Require not env $deny_env
26+
# Require not ip $host_ip
27+
</IfModule>
28+
29+
}
30+
31+
function singleton_put_contents( $path, $marker, $content, $timeout ) {
32+
33+
// wp-admin/includes/misc.php
34+
save_mod_rewrite_rules()
35+
clone: insert_with_markers()
36+
- gethome(htaccess) normal/subdir install
37+
38+
//1. exists, writeable ...
39+
! fstat()/mod -> then @chmod( $htaccess, 0664 );
40+
41+
//2. lock || wait and loop
42+
"If the file has been locked with LOCK_EX in another process, the CALL WILL BLOCK UNTIL ALL OTHER LOCKS have been released."
43+
// must use "@"
44+
$fp = @fopen( $path, 'w' )
45+
check $fp
46+
47+
$give_up = time() + 30;
48+
while ( ! flock( $file_handle, LOCK_EX | LOCK_NB ) ) {
49+
//Lock not acquired, try again in:
50+
usleep( round( rand( 0, 100 ) * 1000 ) );
51+
if ( $give_up >= time() )
52+
}
53+
54+
//3. read rules
55+
$file_stat = fstat( $handle );
56+
$contents = fread( $handle, $file_stat['size'] );
57+
// line ends
58+
$contents = preg_replace( '/\n|\r\n?/', PHP_EOL, $contents );
59+
//already contains?
60+
preg_match multiline "# BEGIN " . $marker . PHP_EOL -> "# END " . $marker . PHP_EOL;
61+
62+
//4. ftruncate($fp, 0); write new rules in one go
63+
64+
// 5. release lock
65+
fflush
66+
flock( $handle, LOCK_UN );
67+
fclose
68+
}

wordpress-fail2ban/block-bad-requests/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ define( 'O1_BAD_REQUEST_CDN_HEADERS', 'HTTP_X_AMZ_CF_ID:HTTP_VIA:HTTP_X_FORWARDE
5656
```
5757

5858
- (integer) `O1_BAD_REQUEST_COUNT` fail2ban trigger limit, `maxretry`
59-
- (string) `O1_BAD_REQUEST_CDN_HEADERS` a colon separated list of HTTP headers your CDN is recognized by **can be faked**
59+
- (string) `O1_BAD_REQUEST_CDN_HEADERS` a colon separated list of HTTP headers your CDN is recognized by
6060
- (boolean) `O1_BAD_REQUEST_ALLOW_REG` allow WP registration, disabled referer and test cookie checks
6161
- (boolean) `O1_BAD_REQUEST_ALLOW_IE8` allow login with IE8 too (IE8 is not a `Mozilla/5.0` browser)
6262
- (boolean) `O1_BAD_REQUEST_ALLOW_OLD_PROXIES` allow `HTTP/1.0` login requests

wordpress-fail2ban/mu-plugin/wp-fail2ban-mu.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,4 +355,8 @@ private function exit_with_instructions() {
355355
error_log( 'em:' . $em );
356356
return $em;
357357
}, 0 );
358+
- general
359+
- bad queries https://github.com/wp-plugins/block-bad-queries/
360+
- bad UAs
361+
- strlen( $_SERVER['REQUEST_URI'] ) > 255
358362
*/

0 commit comments

Comments
 (0)