{"id":4432,"date":"2017-11-10T01:12:22","date_gmt":"2017-11-10T01:12:22","guid":{"rendered":"http:\/\/www.hexacorn.com\/blog\/?p=4432"},"modified":"2017-11-10T01:22:03","modified_gmt":"2017-11-10T01:22:03","slug":"reusigned-binaries-living-off-the-signed-land","status":"publish","type":"post","link":"https:\/\/www.hexacorn.com\/blog\/2017\/11\/10\/reusigned-binaries-living-off-the-signed-land\/","title":{"rendered":"Reusigned Binaries &#8211; Living off the signed land"},"content":{"rendered":"<p>Lots of research that concentrates on living off the land techniques focuses on finding legitimate OS binaries (both EXE and DLLs) that allow to:<\/p>\n<ul>\n<li>load unsigned DLLs by the signed EXE files,<\/li>\n<li>load code in an unexpected, unconventional way using phantom DLLs, sideloaded DLLs,<\/li>\n<li>use native OS tools and abuse their functionality to download and upload files, maintain persistence, convert data, etc.,<\/li>\n<li>break the process tree, and<\/li>\n<li>many more.<\/li>\n<\/ul>\n<p>Here, I propose to take it to a possible next, or at least parallel level.<\/p>\n<p>If you are familiar with the ROP gadgets you know that it relies on re-using pieces of code belonging to loaded libraries already present in memory. These are used to chain together code blocks that may execute code of attackers&#8217; choice. By its sole nature ROP is a complex beast and while it can be, and is now fully automated, it most of the time relies on the fact that the final piece of code is just a regular payload that the ROP chain transfer the control to&#8230;<\/p>\n<p>I was wondering if it would be possible to re-use the ROP idea on a file-system level and build a library of high-level gadget-like signed executables and DLLs that could deliver the payload-like functionality, or at least its core building blocks. That would not only reduce the need to write the actual payload code &#8211; it would basically transfer the responsibility for the core functionality required by the attackers to signed libraries!<\/p>\n<p>If it sounds weird, or complicated, let&#8217;s think for a second about existing installers. They implement and provide functionality that every single piece of malware needs: spawn processes, read file, write files, copying, downloading, uploading, same with the Registry operations, and more.<\/p>\n<p>The installers have been abused by malware for a very long time, so it&#8217;s just a trivial example. I was thinking of something a little bit more refined and stealthy. Consider an example like this: a malicious document executes a macro; the macro drops a clean, signed executable produced by a well-known company &#8211; a file that not a single security solution can detect as malicious. It then instruments that signed executable to do all the dirty work. The chances are high that it would possibly bypass antivirus solutions, EDR, sandboxes and who knows, maybe even the Holy Grail &#8211; the whitelisting solutions.<\/p>\n<p>Now that I formulated the idea in my head it was time to do some legwork&#8230;<\/p>\n<p>I kicked off a number of searches within my files repository. After some poking around, eyeballing some code, a number of failed attempts I finally got lucky and hit the jackpot. To my surprise, I found a number of really interesting potentials!<\/p>\n<p>The first interesting reusigned binary I came across is described below.<\/p>\n<p>The nvuhda.exe and nvuhda6.exe are NVIDIA Uninstallers for 32- and 64-bit. When you execute them from a command line you will see the following screen:<\/p>\n<p><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2017\/11\/nvuhda2.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-4437\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2017\/11\/nvuhda2.png\" alt=\"\" width=\"483\" height=\"563\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2017\/11\/nvuhda2.png 483w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2017\/11\/nvuhda2-257x300.png 257w\" sizes=\"(max-width: 483px) 100vw, 483px\" \/><\/a>The list of commands is shown below:<\/p>\n<ul>\n<li>AddUninstall, Call, CheckPath, CheckRAID, ClassSweep, Copy, CopyV, CreateDevice, CreateShortcut, Del, DelBoot, DelBootQuiet, DelIniIfMatched, DelOemInfs, DelReg, DelRegE, DirAndApply, Echo, EnumDevices, EnumRegCmd, EnumRegNamesCmd, Eval, FindOEMInf, GetDrivePort, GetFolderPath, GetInfGUID, GetReg, Help, If, InstallDriver, InstallDriverEx, KillApp, RemoveDevice, Run, RunOnce, SendMessage, Set, SetEnv, SetReg, Sleep, Splash, StartLogging, StopLogging, SysCallAndWait, System, UnifyUninst, Uninstall, UnInstallEx, UninstallGUI, UninstallService, WaitOnRegDel<\/li>\n<\/ul>\n<p>Hmm some of them look really interesting.<\/p>\n<p>Using the &#8216;Help&#8217; command we can retrieve more information about the commands:<\/p>\n<p><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2017\/11\/nvuhda3.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-4438\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2017\/11\/nvuhda3.png\" alt=\"\" width=\"427\" height=\"173\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2017\/11\/nvuhda3.png 427w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2017\/11\/nvuhda3-300x122.png 300w\" sizes=\"(max-width: 427px) 100vw, 427px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>We can run a few tests:<\/p>\n<ul>\n<li>\n<pre>nvuhda6.exe System calc.exe<\/pre>\n<ul>\n<li>spawns the Calculator<\/li>\n<\/ul>\n<\/li>\n<li>\n<pre>nvuhda6.exe Copy test.txt,test-2.txt<\/pre>\n<ul>\n<li>copies &#8216;test.txt&#8217; to &#8216;test-2.txt&#8217;<\/li>\n<\/ul>\n<\/li>\n<li>\n<pre>nvuhda6.exe SetReg HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\\malware=malware.exe<\/pre>\n<ul>\n<li>adds a persistence key<\/li>\n<\/ul>\n<\/li>\n<li>\n<pre>nvuhda6.exe CreateShortcut test.lnk,\"Test\",\"c:\\windows\\system32\\calc.exe\",\"\",\"c:\\windows\\system32\"<\/pre>\n<ul>\n<li>creates a shortcut file &#8216;test.lnk&#8217; pointing to calculator<\/li>\n<\/ul>\n<\/li>\n<li>\n<pre>nvuhda6.exe KillApp calculator.exe<\/pre>\n<ul>\n<li>kills the instances of &#8216;calculator.exe&#8217; process<\/li>\n<\/ul>\n<\/li>\n<li>and so on and and so forth, and finally<\/li>\n<li>\n<pre>nvuhda6.exe Run foo<\/pre>\n<ul>\n<li>will run commands from the file &#8216;foo&#8217; (where commands are from the list above; it&#8217;s basically an install script)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>It&#8217;s pretty much a Swiss-Army tool for doing a lot of legitimate operations on the system, but it could be certainly abused. The only issue is the UAC, because the file required Admin privileges in its manifest.<\/p>\n<p>And&#8230; last, but not least &#8211; here&#8217;s the full list of commands:<\/p>\n<ul>\n<li><strong>Help<\/strong><br \/>\nCommand Name<br \/>\nIf &lt;Command Name&gt; is provided displayes syntax and description of that command otherwise displays all the avilable commands<\/li>\n<li><strong>System<\/strong><br \/>\nCommand<br \/>\nExecutes the given system command (returns immidiately)<\/li>\n<li><strong>SysCallAndWait<\/strong><br \/>\nExact path to App + arguments<br \/>\ncall and wait untill app is done.<\/li>\n<li><strong>Set<\/strong><br \/>\nName[=Value]<br \/>\nDefines the variable if not defined and Sets the its value to the given value.<\/li>\n<li><strong>Call<\/strong><br \/>\nSection Name<br \/>\nruns all the commands in that section and returnd and continues executing commands after that line<\/li>\n<li><strong>Run<\/strong><br \/>\nPath to an NVU File<br \/>\nExecutes all the commands in that file and returns<\/li>\n<li><strong>RunOnce<\/strong><br \/>\nPath to an NVU File<br \/>\nRun all the commands in this file and delete the file<\/li>\n<li><strong>DirAndApply<\/strong><br \/>\nDirPath,Command<br \/>\nA dir will be applied to the given path and for each file found it sets variable {current file} to that file and calls the given command.<\/li>\n<li><strong>If<\/strong><br \/>\n[!]Exp1}[=%]{Exp2} then {Command}<br \/>\nExecutes command if Exp1 is the same as Exp2 for = or Exp1 has Exp2 for % if ! is added to the beging of Exp1 it will negate the result<\/li>\n<li><strong>Eval<\/strong><br \/>\nCommand<br \/>\nreEvaluates the given command and executes it<\/li>\n<li><strong>StartLogging<\/strong><br \/>\nFilename<br \/>\nOpens the given log files ad Logs all the commands in the given file<\/li>\n<li><strong>StopLogging<\/strong><br \/>\nN\/A<br \/>\nStops logging close the file<\/li>\n<li><strong>Sleep<\/strong><br \/>\nmilisconds<br \/>\nWaits for a number of miliseconds passed before executing the next command<\/li>\n<li><strong>Splash<\/strong><br \/>\n{milisconds}, {BitmapPath}<br \/>\nShows the given bitmap for the given time number on the screen<\/li>\n<li><strong>WaitOnRegDel<\/strong><br \/>\n{Key,Value,LoopDelay,MaxLoopCount,TimeoutCommand}<br \/>\nAllows waiting for a specific registry key or value to be deleted<\/li>\n<li><strong>FindOEMInf<\/strong><br \/>\n{Variable} , INF name<br \/>\nLooks under the windows INF directory for additional NVIDIA display driver infs (oem*.inf). Returns TRUE if found.<\/li>\n<li><strong>CheckPath<\/strong><br \/>\n{Variable} = Local Path<br \/>\nReturns TRUE if path exists.<\/li>\n<li><strong>Uninstall<\/strong><br \/>\n{NVU File}, {Uninstall Reg key}<br \/>\nRuns the given file and deletes it. It also removes the given key from Add\/Remove Program list<\/li>\n<li><strong>UnInstallEx<\/strong><br \/>\nUninstall Display Reg key<br \/>\nUninstalls the given product from add remove programs. If it detects uninstall as its nvu it uses internal uninstall command otherwise calls the appropriate uninstall command.<\/li>\n<li><strong>AddUninstall<\/strong><br \/>\n{Uninstall File} , {Display Name}<br \/>\nAdds Display name as the title to in Add\/Remove programs list and copies uninstall binary and script file to windows system directory<\/li>\n<li><strong>DelBoot<\/strong><br \/>\nPath to files to be deleted on reboot<br \/>\nPut the given file for delete in the next reboot. If the file exists it will ask user for the reboot when program ends.<\/li>\n<li><strong>Del<\/strong><br \/>\nPath to file to be deleted<br \/>\nDeletes the given file if it exists, It also deletes a directory if it is empty. If the file is locked it will set the system to delete the file upon reboot<\/li>\n<li><strong>DelBootQuiet<\/strong><br \/>\nPath to files to be deleted on reboot without reboot request<br \/>\nPut the given file for delete in the next reboot. If the file exists it will ask user for the reboot when program ends.<\/li>\n<li><strong>Copy<\/strong><br \/>\nSrcfile,DstFile<br \/>\nCopies a file from the given source to given dest<\/li>\n<li><strong>CopyV<\/strong><br \/>\nSrcfile,DstFile<br \/>\nCopies a file from the given source to given dest only if source is a higher version.<\/li>\n<li><strong>DelReg<\/strong><br \/>\nRegistry pattern matching string<br \/>\nDeletes regkey(s) matching the given registry key<\/li>\n<li><strong>DelRegE<\/strong><br \/>\nRegistry pattern matching string<br \/>\nOnly deletes regkey(s) matching the given registry key if they have no subkeys or values<\/li>\n<li><strong>SetReg<\/strong><br \/>\nRegistry pattern matching string\\ame[=value]<br \/>\nFor all the matching registry paths, sets values if [=value] is present, creates subkeys otherwise<\/li>\n<li><strong>GetReg<\/strong><br \/>\n{Variable} = {regkeypath\\name}<br \/>\nIf it finds name under regkeypath copies its value to the given variable, othewise does nothing.<\/li>\n<li><strong>UninstallService<\/strong><br \/>\nService Name<br \/>\nuninstalls the given service name<\/li>\n<li><strong>RemoveDevice<\/strong><br \/>\n{Enum Type} , {Hardware ID}, {Device type}<br \/>\nRemove any device matched with the given description from the system using setupdi calls.<br \/>\nEnum can be (PCI, EISA, etc), HWID usually is VEN_10DE and device type can be DISPLAY,HDC,MEDIA,NET,SYSTEM<\/li>\n<li><strong>InstallDriverEx<\/strong><br \/>\n{Hardware ID}, {InfFullPath}<br \/>\nInstalls the given driver for any device matched with the given device ID from the system using setupdi calls.<\/li>\n<li><strong>InstallDriver<\/strong><br \/>\n{Hardware ID}, {InfFullPath}<br \/>\nInstalls the given driver for any device matched using UpdateDriverForPlugAndPlayDevices for Win200 and above and InstallDriverEx for Win95 and Win98<\/li>\n<li><strong>CreateDevice<\/strong><br \/>\n{Hardware ID}, {InfFullPath}<br \/>\nThis function first creates a device Installs the driver for this device using given inf. This function should work for all versions of Windows<\/li>\n<li><strong>GetInfGUID<\/strong><br \/>\nVariable Name = Full Path to Inf<br \/>\nSets the given variable to a string representing the inf&#8217;s GUID<\/li>\n<li><strong>DelOemInfs<\/strong><br \/>\n{WildCard} , {Section} , {Name} , {Value} , {[&#8230;]<br \/>\nit searches in all inf files under sysdir\\\\inf\\\\[Wildcard and OEM*.inf] and if it finds a match with given parameters it deletes it on reboot<\/li>\n<li><strong>DelIniIfMatched<\/strong><br \/>\nInffile} , {Section} , {Name} , {Value} , {[,&#8230;]<br \/>\nit searches in all inf files under sysdir\\\\inf\\\\OEM*.inf and if it finds a match with given parameters it deletes it on reboot<\/li>\n<li><strong>ClassSweep<\/strong><br \/>\nGUID,{StrPattern1};{StrPattern2};&#8230;.<br \/>\nPass in the GUID of the inf and the string patterns of the reg names to be deleted. It will remove all the reg names corresponding to the str pattern under the GUID 0001&#8230;.. except in Properties)<\/li>\n<li><strong>EnumRegNamesCmd<\/strong><br \/>\nRegPathToEnumatrate} , {Command<br \/>\nEnumerates all keys matching the given regpath and when matched enumarates all names under that key then calls the given command {Current Reg name} and {Current Reg value} are set when the given command is executed<\/li>\n<li><strong>EnumRegCmd<\/strong><br \/>\n{RegPathToEnumatrate} , {Command}<br \/>\nEnumerates all keys matching the given regpath and when matched calls the given command {Current Reg Key} is set then the given command is executed<\/li>\n<li><strong>UnifyUninst<\/strong><br \/>\nN\/A<br \/>\nThis is a legacy command to maintain backward compatibility.<\/li>\n<li><strong>SetEnv<\/strong><br \/>\nName=Value<br \/>\nAdds the given name to environment variables and sets its value<\/li>\n<li><strong>UninstallGUI<\/strong><br \/>\nWindowName<br \/>\nDisplays the GUI to uninstall whatever user chooses<\/li>\n<li><strong>KillApp<\/strong><br \/>\nAppName<br \/>\nGiven an appname enumerates all the running app and kills its process if it is running<\/li>\n<li>SendMessage<br \/>\n{AppName}, {Message}<br \/>\nGiven an appname, sends its window a message<\/li>\n<li><strong>CreateShortcut<\/strong><br \/>\nLnkFile,Title,ProgFile,ProgArgs,ProgWorkingDir<br \/>\nCreates a shell link (shortcut)<\/li>\n<li><strong>GetDrivePort<\/strong><br \/>\n{Variable} = {path}<br \/>\nIt uses the first char of the path as drive letter and assigns the port number of that to the given variable name.<\/li>\n<li><strong>EnumDevices<\/strong><br \/>\n{DeviceId},{Class},{Cmd}<br \/>\nIt enumerats all the devices present on the system if any device has {DeviceID} and is from the given {Class} then variable {Current Device} is set to that device ID and the given command gets executed.<\/li>\n<li><strong>GetFolderPath<\/strong><br \/>\nVariable Name = FolderCode<br \/>\nSets the given variable to the path of a special folder, identified by its CSIDL (check MSDN SHGetSpecialFolderPath Function)<\/li>\n<li><strong>CheckRAID<\/strong><br \/>\nN\/A<br \/>\nReturns TRUE if RAID exists.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Lots of research that concentrates on living off the land techniques focuses on finding legitimate OS binaries (both EXE and DLLs) that allow to: load unsigned DLLs by the signed EXE files, load code in an unexpected, unconventional way using &hellip; <a href=\"https:\/\/www.hexacorn.com\/blog\/2017\/11\/10\/reusigned-binaries-living-off-the-signed-land\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[43,13,15,19,46,56,59],"tags":[],"_links":{"self":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/4432"}],"collection":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/comments?post=4432"}],"version-history":[{"count":8,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/4432\/revisions"}],"predecessor-version":[{"id":4442,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/4432\/revisions\/4442"}],"wp:attachment":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/media?parent=4432"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/categories?post=4432"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/tags?post=4432"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}