|
1 | 1 | # wp-cli/secure-command
|
| 2 | +Official website: [Hackthewp.com](https://hackthewp.com/) |
| 3 | + |
2 | 4 | Manages common security aspects of WordPress. Supports nginx and Apache.
|
3 | 5 |
|
4 | 6 | ## Basic Usage
|
5 | 7 | This package implements the following commands:
|
6 | 8 |
|
7 |
| -**wp secure block_access_to_htaccess** |
| 9 | +### Deploy All Security rules |
8 | 10 |
|
9 |
| -Blocks access to `.htaccess` and `nginx.conf` files. |
| 11 | +Deploys all above-mentioned rules at once. |
10 | 12 |
|
11 |
| -``` |
12 |
| -wp secure block_access_to_htaccess [--remove] [--file-path=/alternative/path] [--output] [--server=apache|nginx] |
| 13 | +```bash |
| 14 | +wp secure all |
13 | 15 | ```
|
14 | 16 |
|
15 |
| -**wp secure block_access_to_sensitive_directories** |
| 17 | +### Remove All Security Rules |
16 | 18 |
|
17 |
| -Blocks direct access to sensitive directories - `.git`, `svn`, `cache` and `vendors` |
| 19 | +Removes all security rules. |
18 | 20 |
|
| 21 | +```bash |
| 22 | +wp secure flush |
19 | 23 | ```
|
20 |
| -wp secure block_access_to_sensitive_directories [--remove] [--file-path=/alternative/path] [--output] [--server=apache|nginx] |
| 24 | + |
| 25 | +### Block the access to sensitive files and directories |
| 26 | +```bash |
| 27 | +wp secure block-access <what-to-block> |
21 | 28 | ```
|
22 | 29 |
|
23 |
| -**wp secure block_access_to_sensitive_files** |
| 30 | +By default, this command blocks the direct access to sensitive files and directories: |
| 31 | +`readme.txt`, `readme.html`, `xmlrpc.php`, `wp-config.php`, `wp-admin/install.php`, `wp-admin/upgrade.php`, `.git`, `svn`, `cache` and `vendors` |
24 | 32 |
|
25 |
| -Blocks direct access to sensitive files - `readme.txt`, `readme.html`, `wp-config.php`, `wp-admin/install.php` and `wp-admin/upgrade.php` |
| 33 | +Possible options are: |
| 34 | +- sensitive-files |
| 35 | +- sensitive-directories |
| 36 | +- xmlrpc |
| 37 | +- htaccess |
| 38 | +- custom |
| 39 | +- all (does all the above) |
26 | 40 |
|
27 |
| -``` |
28 |
| -wp secure block_access_to_sensitive_files [--remove] [--file-path=/alternative/path] [--output] [--server=apache|nginx] |
| 41 | +Examples: |
| 42 | + |
| 43 | +```bash |
| 44 | +wp secure block-access sensitive-files |
| 45 | +wp secure block-access sensitive-directories |
| 46 | +wp secure block-access xmlrpc |
| 47 | +wp secure block-access htaccess |
| 48 | +wp secure block-access all |
29 | 49 | ```
|
30 | 50 |
|
31 |
| -**wp secure block_access_to_xmlrpc** |
| 51 | +However, you can also block custom files and/or folders of your choice. To do that you should use `custom` argument |
| 52 | +and pass one of two additional options `--files` and/or `--directories`. |
32 | 53 |
|
33 |
| -Blocks direct access XML-RPC |
| 54 | +If you want to block custom files, make sure that you pass only file names, not a full file paths. |
34 | 55 |
|
35 |
| -``` |
36 |
| -wp secure block_access_to_xmlrpc [--remove] [--file-path=/alternative/path] [--output] [--server=apache|nginx] |
37 |
| -``` |
| 56 | +Examples: |
38 | 57 |
|
39 |
| -### wp secure block_author_scanning |
| 58 | +````bash |
| 59 | +wp secure block-access custom --files=dump.sql,phpinfo.php,adminer.php |
| 60 | +wp secure block-access custom --directories=wp-content/mu-plugins |
| 61 | +```` |
40 | 62 |
|
41 |
| -Blocks author scanning. Author scanning is a common technique of brute force attacks on WordPress. It is used to crack passwords for the known usernames and to gather additional information about the WordPress itself. |
| 63 | +### Block Author Scanning |
42 | 64 |
|
43 |
| -``` |
44 |
| -wp secure block_author_scanning [--remove] [--file-path=/alternative/path] [--output] [--server=apache|nginx] |
| 65 | +```bash |
| 66 | +wp secure block-author-scanning |
45 | 67 | ```
|
46 | 68 |
|
47 |
| -### wp secure block_php_execution_in_plugins |
| 69 | +Blocks author scanning. Author scanning is a common technique of brute force attacks on WordPress. It is used to crack passwords for the known usernames and to gather additional information about the WordPress itself. |
48 | 70 |
|
49 |
| -Blocks direct access and execution of PHP files in `wp-content/plugins` directory. |
| 71 | +Examples: |
50 | 72 |
|
| 73 | +```bash |
| 74 | +wp secure block-author-scanning |
51 | 75 | ```
|
52 |
| -wp secure block_php_execution_in_plugins [--remove] [--file-path=/alternative/path] [--output] [--server=apache|nginx] |
| 76 | + |
| 77 | +### Block Direct Access and Execution in certain directories |
| 78 | + |
| 79 | +```bash |
| 80 | +wp secure block-php-execution <where> |
53 | 81 | ```
|
54 | 82 |
|
55 |
| -### wp secure block_php_execution_in_uploads |
| 83 | +Blocks direct access and execution of PHP files in `wp-content/plugins`, `wp-content/uploads`, `wp-content/themes` and `wp-includes` directories. |
56 | 84 |
|
57 |
| -Blocks direct access and execution of PHP files in `wp-content/uploads` directory. |
| 85 | +You need to specify where you want to prevent direct access to PHP files. Possible options are: |
| 86 | +- all |
| 87 | +- plugins |
| 88 | +- uploads |
| 89 | +- themes |
| 90 | +- wp-includes |
58 | 91 |
|
| 92 | +Examples: |
| 93 | + |
| 94 | +```bash |
| 95 | +wp secure block-php-execution all |
| 96 | +wp secure block-php-execution plugins |
| 97 | +wp secure block-php-execution uploads |
| 98 | +wp secure block-php-execution themes |
| 99 | +wp secure block-php-execution wp-includes |
59 | 100 | ```
|
60 |
| -wp secure block_php_execution_in_uploads [--remove] [--file-path=/alternative/path] [--output] [--server=apache|nginx] |
| 101 | + |
| 102 | +### Disable Directory Browsing |
| 103 | +```bash |
| 104 | +wp secure disable-directory-browsing |
61 | 105 | ```
|
62 | 106 |
|
63 |
| -### wp secure block_php_execution_in_themes |
| 107 | +Disables directory browsing. |
| 108 | + |
| 109 | +By default, when your web server does not find an index file (i.e. a file like index.php or index.html), it |
| 110 | +automatically displays an index page showing the contents of the directory. |
| 111 | +This could make your site vulnerable to hack attacks by revealing important information needed to exploit a vulnerability in a WordPress plugin, theme, or your server in general. |
64 | 112 |
|
65 |
| -Blocks direct access and execution of PHP files in `wp-content/themes` directory. |
| 113 | +Examples: |
66 | 114 |
|
67 |
| -``` |
68 |
| -wp secure block_php_execution_in_themes [--remove] [--file-path=/alternative/path] [--output] [--server=apache|nginx] |
| 115 | +```bash |
| 116 | +wp secure disable-directory-browsing |
69 | 117 | ```
|
70 | 118 |
|
71 |
| -### wp secure block_php_execution_in_wp_includes |
72 |
| -Blocks direct access and execution of PHP files in include directories - `wp-admin/includes`, `wp-includes/*.php`, `wp-includes/js/tinymce/langs/*.php`, `wp-includes/theme-compat` |
| 119 | +### Disable WordPress File Editor |
73 | 120 |
|
| 121 | +Disables the WordPress file editor. It could be used to edit arbitrary files using the web interface. |
| 122 | +This makes it easier for attackers to change files on the server using a web browser. |
| 123 | + |
| 124 | +```bash |
| 125 | +wp secure disable-file-editor |
74 | 126 | ```
|
75 |
| -wp secure block_php_execution_in_wp_includes [--remove] [--file-path=/alternative/path] [--output] [--server=apache|nginx] |
| 127 | + |
| 128 | +### Fix file and directory permissions |
| 129 | + |
| 130 | +```bash |
| 131 | +wp secure fix-permissions |
76 | 132 | ```
|
77 | 133 |
|
78 |
| -### wp secure disable_directory_browsing |
| 134 | +Use this command to verify that the permissions of all files and directories are set according the WordPress recommendations. |
| 135 | +This command will set **0666** to all files and **0755** to all folders inside WordPress installation. |
79 | 136 |
|
80 |
| -Disables directory browsing. |
| 137 | +**IMPORTANT: Don't use this command if you don't know what you are doing here!** |
81 | 138 |
|
82 |
| -By default when your web server does not find an index file (i.e. a file like index.php or index.html), it |
83 |
| -automatically displays an index page showing the contents of the directory. |
84 |
| -This could make your site vulnerable to hack attacks by revealing important information needed to exploit a vulnerability in a WordPress plugin, theme, or your server in general. |
| 139 | +### Check the integrity of WordPress files |
85 | 140 |
|
86 |
| -``` |
87 |
| -wp secure disable_directory_browsing [--remove] [--file-path=/alternative/path] [--output] [--server=apache|nginx] |
88 |
| -``` |
| 141 | +Downloads MD5 checksums for the current version from WordPress.org, and compares those checksums against the currently |
| 142 | +installed files. |
89 | 143 |
|
90 |
| -### wp secure flush |
| 144 | +It also returns a list of files that shouldn't be part of default WordPress installation, which can be very useful when you are |
| 145 | +looking for a possible injected files. |
91 | 146 |
|
92 |
| -Removes all security rules. |
| 147 | +Examples: |
93 | 148 |
|
94 |
| -``` |
95 |
| -wp secure flush |
| 149 | +```bash |
| 150 | +wp secure integrity-scan |
96 | 151 | ```
|
97 | 152 |
|
98 | 153 | ## Global options
|
99 | 154 |
|
100 | 155 | ### Remove single security rule
|
101 | 156 | Using `--remove` with any rule command, you can remove it from configuration.
|
102 | 157 |
|
103 |
| -``` |
104 |
| -wp secure block_php_execution_in_wp_includes --remove |
| 158 | +```bash |
| 159 | +wp secure block-access xmlrpc --remove |
105 | 160 | ```
|
106 | 161 |
|
107 | 162 | ### Get the output instead of writing in configuration files
|
108 | 163 | Using `--output` option with any rule command, you can see actual rule code which you can inspect or manually copy to any file of your choice.
|
109 | 164 |
|
110 |
| -``` |
111 |
| -wp secure block_php_execution_in_wp_includes --output |
112 |
| -wp secure block_php_execution_in_wp_includes --output --server=nginx |
| 165 | +```bash |
| 166 | +wp secure block-access htaccess --output |
| 167 | +wp secure block-access htaccess --output --server=nginx |
113 | 168 | ```
|
114 | 169 |
|
115 | 170 | ### Specify server type
|
116 | 171 | By default, all rules are generated for Apache or LiteSpeed web servers that utilize `.htaccess` file. However, you can use `--server` to specify nginx if you want.
|
117 | 172 |
|
118 |
| -``` |
119 |
| -wp secure block_php_execution_in_wp_includes --server=nginx |
120 |
| -wp secure block_php_execution_in_wp_includes --server=--file-path=/home/user/mysite.com/nginx.conf |
| 173 | +```bash |
| 174 | +wp secure block-access htaccess --server=nginx |
121 | 175 | ```
|
122 | 176 |
|
123 | 177 | ### Specify custom file path
|
124 | 178 | By default, all commands assume that rules should be written in the root of WordPress installation in `.htaccess` and `nginx.conf`, depending on which server you choose.
|
125 | 179 | However, you can specify a custom file path that is going to be used for storing security rules.
|
126 | 180 |
|
127 | 181 | ```
|
128 |
| -wp secure block_php_execution_in_plugins --file-path=/home/user/mysite.com/.htaccess |
| 182 | +wp secure block-access htaccess --file-path=/home/user/mysite.com/.htaccess |
129 | 183 | ```
|
130 | 184 |
|
131 | 185 | ## Important Note for nginx users
|
132 |
| -nginx rules are stored in the `nginx.conf` file. However, for rules to actually work, you need to manually include this file in your vhost configuration and then restart nginx server: |
| 186 | +The nginx rules are stored in the `nginx.conf` file. However, for rules to actually work, you need to manually include this file in your vhost configuration and then restart nginx server: |
133 | 187 | ```
|
134 | 188 | systemctl restart nginx
|
135 | 189 | ```
|
@@ -160,4 +214,3 @@ These paths and URLs are going to be used during tests, so make sure that they a
|
160 | 214 | We appreciate you taking the initiative to contribute to this project.
|
161 | 215 |
|
162 | 216 | Contributing isn’t limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.
|
163 |
| - |
|
0 commit comments