Jump to content
TheCount.

EXPLOITING THE EXPLOITABLE

Recommended Posts

HI!

 

Let's setup a quick test environment for this exercise. We will use docker compose in order to quickly spin it up. Create a docker-compose.yml file with the following contents:

 

 

version: '2'

services:
  wordpress:
    image: wordpress:4.7.0
    ports:
      - 8080:80
    environment:
      WORDPRESS_DB_PASSWORD: example
    entrypoint:
      - /bin/sh
      - -c
      - (sleep 5; echo "define('WP_AUTO_UPDATE_CORE', false);" >> /var/www/html/wp-config.php) & docker-entrypoint.sh apache2-foreground
  mysql:
    image: mariadb
    environment:
      MYSQL_ROOT_PASSWORD: example

 

 

This is pretty standard. The only thing that sort of stands out is that instead of running the default Dockerfile ENTRYPOINT we use our own which injects the wp-config.php file with a constant to prevent WordPress from auto-updating itself mid-testing. The exploit will not work in 4.7.2 so we need this to get the environment in the right state.

Once you are happy with everything just run the following command to bootstrap the database and WordPress.

 

$ docker-compose up --force-recreate; docker-compose down -v

 

 

Before we move on you will also have to configure WordPress with some credentials. Visit the application url which is most likely available on localhost:8080 or in case you are using Mac OS X it will be $(docker-machine ip):8080. Go through the setup process. If you want you can even create a couple of blog posts. There is a default blog post with id of

1 which we will override with the following exploit.

 

 

 

817cde42-b5db-4c8c-8c1c-3dea4933ddfa-00.

 

The exploit is relatively straightforward but I will take you step by step how to set it up on Rest  

 First, let's open Rest and setup some variables which we will use to control the base URL and the number of the blog post we want to change. This is done like this.

 

 

817cde42-b5db-4c8c-8c1c-3dea4933ddfa-01.

 

Now we need to configure the URL. According to the exploit details we need to encode the post id in the URL. In fact, this step is not necessery and we can supply an arbitrary value but I am going to do it anyway to show how powerful the variable substituation feature really is. Notice how we use both variables to build dynamically the URL.

 

 

817cde42-b5db-4c8c-8c1c-3dea4933ddfa-02.

The next step is to actually override the post id using the trick which actually bypasses the authorisation controls in the WordPress REST API. We need to define a query parameter which takes the post id and pads it with the value abc.

 

 

817cde42-b5db-4c8c-8c1c-3dea4933ddfa-03.

The next step is to build the payload. We need to change the method from GET to POST and setup the content type of the request to JSON. This is straightforward as shown in the screenshot bellow.

 

 

 

817cde42-b5db-4c8c-8c1c-3dea4933ddfa-04.

We are almost there. The last step is to build the actual JSON payload. Switch to the Body tab and select the text/plain body type. We need to create a simple JSON payload that should look like this:

 

 

{
  "content": "The content that you want to appear instead of the original post."
}

 

 

This is enough for the test but we will make it slightly more interesting by building the payload dynamically which will allow us greater control over the exploitation process in case we change our mind and we want to do something more advance. Let's setup another variable which we will call post_content, which will hold the new content.

 

 

 

817cde42-b5db-4c8c-8c1c-3dea4933ddfa-05.

 

Now let's build everything dynamically inside the body. We will use the JSON encoding gadget to make it perfect.

 

 

817cde42-b5db-4c8c-8c1c-3dea4933ddfa-06.

 

Notice how cool this setup is! The exploit is ready so let's test it.

 

 

 

817cde42-b5db-4c8c-8c1c-3dea4933ddfa-07.

 

Mission accomplished. Because our setup is fully dynamic we now have full flexibility to do whatever we want without the need to worry how the final request is generated. Remember - everything is dynamic. So let's now properly deface the blog by making a nice ASCII art defacement page and upload it.

 

 

817cde42-b5db-4c8c-8c1c-3dea4933ddfa-08.

 

And the final result looks like this.

 

 

817cde42-b5db-4c8c-8c1c-3dea4933ddfa-09.

 

 

  • Upvote 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...