Exploring the goal of common WordPress and PHP attack paths.

After checking the access logs for any suspicious activity on the server, I noticed some common paths that seemed to come up a lot.
Checking about them through Gemini AI and online searches provided the following information:


Here’s a breakdown of the listed paths and why some are likely attacks:

Likely Attacks:

  • /wp-content/uploads/wp-casper.php: This file is not a standard WordPress file and likely a malicious script for uploading malware or exploiting vulnerabilities.
  • /wp-content/uploads/uploads.php: Uploading functionality is typically handled by WordPress core, not a separate script in the uploads folder. This suggests a potential attempt to bypass security measures.
  • /wp-content/uploads/wso112233.php: This filename format (wsoXXXX) is commonly associated with webshell tools used for gaining unauthorized access.
  • /wp-content/uploads/2023/wp-signup.php: While a legitimate signup script could exist in this location for some plugins, it’s uncommon. The presence of a year in the path makes it more suspicious.
  • /wp-includes/css/wp-config.php: This is a highly critical configuration file storing database credentials. Accessing it via a HTTP request is a clear attack attempt.

Suspicious but require further investigation:

  • /vendor/phpunit: PHPUnit is a legitimate testing framework used by developers. However, if you are not actively running tests or expecting PHPUnit usage, unknown access to this folder could be suspicious.
  • /vendor/bin/test.php: Similar to the above, this could be a legitimate testing script but requires verification of its purpose.
  • /wp-content/uploads/2022/themes.php”: Themes are usually stored in the /wp-content/themes folder. Having a themes.php script in the uploads folder is suspicious, especially with a year in the path.
  • /wp-content/uploads/2020/09/themes.php: Similar to the above, the presence of a themes.php script in the uploads folder with a date path is suspicious.

After searching online further, I found a long list of paths that shows common paths that are attacked:

https://www.luszcz.de/widwsisw/i/i0004en.php

WordPress paths and .env paths come up a lot!

Also, the reasoning for searching for phpunit, might be answered by the following article: https://thephp.cc/articles/phpunit-a-security-risk

It seems there has been a file included in it that can be exploited.
As usual, it is best to be careful to not include development code in production and also not expose dependency areas such as vendor publicly.

The CSP(Content Security Policy) of a page is blocking a request. How do I find out the CSP of the page using JavaScript?

When dealing with external requests, CORS errors can often occur.
CORS settings have generally become standardized to use CSP (Content Security Policy) settings.
These CSP settings can be set in multiple places, so it can be a little confusing what the final CSP is.
I asked AI (Bard), and got a useful (Bard has sometimes responded with incorrect responses) response.


The CSP(Content Security Policy) of a page is blocking a request. How do I find out the CSP of the page using JavaScript?


There are two ways to find out the CSP of a page using JavaScript:

  1. Check the HTTP response headers. This is the most reliable way to find the CSP, as it is the source of truth. To do this, you can use the document.documentURI property to get the URL of the page, and then use the XMLHttpRequest object to make a request to the URL. Once you have the response, you can check the Content-Security-Policy header to get the CSP.
  2. Check the <meta> tags. CSPs can also be specified using <meta> tags in the HTML head section. To check for a CSP in a <meta> tag, you can use the document.querySelector() method to find the <meta> tag with the http-equiv attribute set to Content-Security-Policy. If the <meta> tag is found, you can get the CSP from the content attribute.

Here is an example of how to find the CSP of a page using JavaScript:

JavaScript
function getCSP() {
  // Check the HTTP response headers.
  const xhr = new XMLHttpRequest();
  xhr.open('GET', document.documentURI);
  xhr.send();
  xhr.onload = function() {
    if (xhr.status === 200) {
      const csp = xhr.getResponseHeader('Content-Security-Policy');
      if (csp) {
        return csp;
      }
    }
  };

  // Check the <meta> tags.
  const metaTag = document.querySelector('meta[http-equiv="Content-Security-Policy"]');
  if (metaTag) {
    return metaTag.content;
  }

  // If no CSP is found, return null.
  return null;
}

// Get the CSP of the page.
const csp = getCSP();

// Do something with the CSP, such as logging it to the console.
console.log(csp);
Use code with caution.

If the CSP of the page is blocking a request, you can try the following:

  • Whitelisting the request in the CSP. This is the most secure option, as it allows you to explicitly specify which requests are allowed. To do this, you need to add the source of the request to the CSP. For example, if the CSP is blocking a request to https://example.com/script.js, you would need to add the following to the CSP:
script-src https://example.com/
  • Using a report-only CSP. This option allows you to test changes to your CSP without blocking any requests. To do this, you need to add the report-only directive to the CSP header. For example:
Content-Security-Policy-Report-Only: script-src https://example.com/

This will cause the browser to report any violations of the CSP to the specified URI, but the requests will not be blocked.

  • Disabling the CSP. This is the least secure option, as it disables all CSP protections. To do this, you need to remove the Content-Security-Policy header from the HTTP response.

Important: Be very careful when disabling or changing a CSP, as this can make your website vulnerable to attack.


If a page has CSP both in the response headers and in one or more meta tags, how are they merged?


If a page has CSP both in the response headers and in one or more meta tags, the CSP in the response headers is used. The meta tags are ignored.

This is because the CSP in the response headers is the most authoritative source of the CSP for the page. The meta tags are only used if there is no CSP in the response headers.

This behavior is specified in the CSP specification:

If multiple policies are received for the same resource, the HTTP response header value takes precedence over the HTML meta element value.

If you need to specify a CSP for a page, it is best to do so in the response headers. This will ensure that the CSP is applied consistently, regardless of whether the page is loaded from the server or from a cache.

If you are using a meta tag to specify a CSP, be aware that it will be ignored if there is a CSP in the response headers. You should also be aware that meta tags are not supported in all browsers.


What about if multiple CSP meta tags exist?


If a page has multiple CSP meta tags, they are merged into a single CSP. The order in which the meta tags are merged is not specified in the CSP specification, so it is best to avoid using multiple meta tags to specify a CSP.

If you need to specify a CSP for a page, it is best to do so in the response headers. This will ensure that the CSP is applied consistently, regardless of whether the page is loaded from the server or from a cache.

If you are using meta tags to specify a CSP, be aware that they may be merged in an unexpected order. You should also be aware that meta tags are not supported in all browsers.

Here is an example of how multiple CSP meta tags may be merged:

HTML
<head>
  <meta http-equiv="Content-Security-Policy" content="script-src 'self'">
  <meta http-equiv="Content-Security-Policy" content="style-src 'self'">
</head>
Use code with caution.

This would be merged into the following CSP:

script-src 'self'; style-src 'self'

The order of the directives in the merged CSP is not guaranteed. It is possible that the style-src directive could come before the script-src directive.

It is best to avoid using multiple CSP meta tags to specify a CSP. If you need to specify a CSP for a page, it is best to do so in the response headers.


From these responses it can be concluded that:

  • CSP headers ('Content-Security-Policy') are prioritized and should be used where possible.
  • Multiple meta tags with CSP are possible. However, this is not recommended.
  • When both CSP headers and meta tags are used, the CSP headers only are applied.
  • When multiple meta tags are used, depending on the browser implementation, they may be merged.