In Typecho v1.3.0 there is a Client IP Spoofing vulnerability, which allows malicious actors to falsify their IP addresses by specifying an arbitrary IP as value of “X-Forwarded-For” or “Client-Ip” headers while performing HTTP requests.
Proof of Concept
The vulnerability originates from the “var/Typecho/Request.php” file of the source code, in which the “getIp()” function is defined. This function returns the client IP address, which is retrieved via request headers such as “X-Forwarded-For” or “Client-Ip”, as shown in the following snippet.
var/Typecho/Request.php
This allows an attacker to bypass the IP-based comment spam protection, since it uses the aforementioned “getIp()” function to retrieve the client IP address, as shown in the following snippet of the “var/Widget/Feedback.php” file.
var/Widget/Feedback.php
Consequently, an attacker can leverage the vulnerability to perform massive comment spamming to a post’s comment section of the application.
The following example shows a spam attack performed by executing the exploit on a test environment for 60 seconds.
Exploit output
The following screenshot illustrates the result of the attack, in which it is possible to notice that the attacker was able to post 5145 comments in 60 seconds.
Result of the spam attack: 5145 comments posted in 60 seconds
In Typecho v1.3.0 there is a Race Condition vulnerability in the post commenting functionality, which allows an attacker to post several comments before the spam protection checks if the comments are posted too frequently.
Proof of Concept
The vulnerability originates from the “var/Widget/Feedback.php” file of the source code, in which the comment spam protection is implemented. Specifically, the application rejects all new comments of a user that commented within a specified time frame, as shown in the following snippet.
var/Widget/Feedback.php
However, it is still possible to post multiple comments within the time range that is not included in the time frame, as demonstrated in the following example.
Multiple comments posted in the excluded time range
In particular, the spam protection mechanism stops the comment spam attack for 60 seconds, but allows continuing it within the second from a time range to another, as shown below.
Time frames not covered by the protection
The following example shows a spam attack performed by executing the exploit on a test environment for 60 seconds.
Exploit output
The following screenshot illustrates the result of the attack, in which it is possible to notice that the attacker was able to post 2000 comments in 60 seconds.
Result of the spam attack: 2000 comments posted in 60 seconds
In Typecho v1.3.0 there is a Stored Cross-Site Scripting vulnerability in the post writing functionality, which allows an attacker with post writing privileges to inject arbitrary JavaScript code inside the preview of a post.
Proof of Concept
In the following attack scenario, an authenticated attacker with “contributor” role will weaponize the vulnerability to perform a privilege escalation. Specifically, an attacker with “contributor” role stores a malicious payload inside the preview page and deceives an administrator user to visit such page, in order to edit the PHP code of the application to backdoor the system in which the application is running.
The following JavaScript code is used to weaponize the XSS vulnerability to edit the PHP code of the application.
Javascript
The aforementioned code then, is converted into Base64 and inserted into the following payload, which will be stored in the body of a post through the “text” HTTP POST parameter of the request fired to the endpoint “/index.php/action/contents-post-edit” for writing a post.
Payload
Upon a visit from the administrator user to the preview page of the malicious post, the aforementioned JavaScript code will be reflected and executed, resulting in editing the PHP code of the application on the administrator’s behalf, allowing an attacker to remotely execute arbitrary shell commands on the system hosting the webapp.
The following example shows this attack scenario performed by executing the exploit on a test environment.
Exploit output
The following screenshot illustrates the preview page of the malicious post, visited by the administrator to trigger the payload.
Preview page of the malicious post visited by the administrator user
As a result, the PHP code of the application has been backdoored, as demonstrated in the following screenshot.
PHP code of the application successfully backdoored