{"id":88035,"date":"2019-08-30T18:44:28","date_gmt":"2019-08-30T13:14:28","guid":{"rendered":"https:\/\/blogs_admin.quickheal.com\/?p=88035"},"modified":"2019-09-09T16:07:51","modified_gmt":"2019-09-09T10:37:51","slug":"powershell-living-off-land","status":"publish","type":"post","link":"https:\/\/www.quickheal.com\/blogs\/powershell-living-off-land\/","title":{"rendered":"PowerShell: Living off the land!"},"content":{"rendered":"<p>Trend of PowerShell based malware is increasing. General trend observed shows that malware authors use new techniques for infection and propagation of malwares along with open source tools. PowerShell gets executed with high privileges and that&#8217;s why it easily performs its activity and propagates through network.<\/p>\n<p>Quick Heal Security Lab has observed that some malwares are using file-less techniques. A file-less malware is sometimes considered synonymous with in-memory malware, as both perform their core functionalities without writing data to disk during the lifetime of their operation. File-less malware attacks are typically very difficult to prevent and detect by any AV, as file-less malware are not present on disk.<\/p>\n<p>In many cases we found that, infection vector is through RDP. If password is weak, by using brute force method, attacker can easily get access to machine. Attacker sends a PowerShell script and after execution, it downloads second stage of PowerShell payload which is obfuscated, and it checks whether system is already infected or not. If not, it enters a persistence entry and downloads third stage of payload, which contains different modules embedded in it.<\/p>\n<p>At each stage, obfuscation level and its techniques get more complex.<\/p>\n<p>Following is the image of entry\/first level PowerShell script which executes with parameter \u201c-nop\u201d (Does not load the Windows PowerShell profile), \u201c\u2013ep\u201d (Sets the execution policy) and \u201c-e\u201d (Accepts a base-64-encoded string) with Base64 parameter.<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-88072 aligncenter\" src=\"https:\/\/blogs.quickheal.com\/wp-content\/uploads\/2019\/08\/first-level-script-1-300x45.png\" alt=\"\" width=\"601\" height=\"90\" srcset=\"https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/first-level-script-1-300x45.png 300w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/first-level-script-1-768x115.png 768w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/first-level-script-1-650x98.png 650w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/first-level-script-1-789x118.png 789w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/first-level-script-1.png 1306w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/><em>Fig.1: First level PowerShell script<\/em><\/p>\n<p style=\"text-align: left;\">After decoding script, it shows information which requests on URL to download and executes script present on that website.\u00a0Following is image of second level PowerShell script containing Base64 encoding with Deflate Stream compression.<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-88079 aligncenter\" src=\"https:\/\/blogs.quickheal.com\/wp-content\/uploads\/2019\/08\/second-level-script-1-300x41.jpg\" alt=\"\" width=\"570\" height=\"78\" srcset=\"https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/second-level-script-1-300x41.jpg 300w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/second-level-script-1-768x105.jpg 768w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/second-level-script-1-650x89.jpg 650w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/second-level-script-1-789x108.jpg 789w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/second-level-script-1.jpg 1307w\" sizes=\"(max-width: 570px) 100vw, 570px\" \/><em>Fig. 2: Second level PowerShell script<\/em><\/p>\n<p style=\"text-align: left;\">This script has multiple purpose. Basically, it is used to create global mutex, to check whether system is already infected or not and it also creates persistence entry.<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-88081 aligncenter\" src=\"https:\/\/blogs.quickheal.com\/wp-content\/uploads\/2019\/08\/de-obfuscated-1-300x98.jpg\" alt=\"\" width=\"627\" height=\"205\" srcset=\"https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/de-obfuscated-1-300x98.jpg 300w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/de-obfuscated-1-768x250.jpg 768w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/de-obfuscated-1-650x212.jpg 650w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/de-obfuscated-1-789x257.jpg 789w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/de-obfuscated-1.jpg 1287w\" sizes=\"(max-width: 627px) 100vw, 627px\" \/><em>Fig. 3: De-obfuscated Second level PowerShell script<\/em><\/p>\n<p style=\"text-align: left;\">This script creates a Global mutex of name \u201cGlobal\\PSEXEC\u201d. After that, it creates two log files and checks whether those log files are already created or not. If files are already created, then further execution of script gets stopped. If files are not there, it creates two files at \u201c%temp%\u201d location having name \u201cccc.log\u201d and \u201ckkkk.log\u201d.<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-88083 aligncenter\" src=\"https:\/\/blogs.quickheal.com\/wp-content\/uploads\/2019\/08\/log-files-1-300x92.jpg\" alt=\"\" width=\"498\" height=\"153\" srcset=\"https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/log-files-1-300x92.jpg 300w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/log-files-1-768x235.jpg 768w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/log-files-1-650x199.jpg 650w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/log-files-1-789x241.jpg 789w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/log-files-1.jpg 814w\" sizes=\"(max-width: 498px) 100vw, 498px\" \/><em>Fig. 4: Log files created at %temp% location<\/em><\/p>\n<p style=\"text-align: left;\">This script also creates a persistence entry in <em>Task Scheduler.<\/em><\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-88087 aligncenter\" src=\"https:\/\/blogs.quickheal.com\/wp-content\/uploads\/2019\/08\/task-sche-entry-300x84.png\" alt=\"\" width=\"518\" height=\"145\" srcset=\"https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/task-sche-entry-300x84.png 300w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/task-sche-entry-768x214.png 768w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/task-sche-entry-650x181.png 650w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/task-sche-entry-789x220.png 789w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/task-sche-entry-304x84.png 304w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/task-sche-entry.png 1049w\" sizes=\"(max-width: 518px) 100vw, 518px\" \/><em>Fig. 5: Task Scheduler entry<\/em><\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-88088 aligncenter\" src=\"https:\/\/blogs.quickheal.com\/wp-content\/uploads\/2019\/08\/task-scheduler-entry-1-300x140.jpg\" alt=\"\" width=\"463\" height=\"216\" srcset=\"https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/task-scheduler-entry-1-300x140.jpg 300w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/task-scheduler-entry-1-768x358.jpg 768w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/task-scheduler-entry-1-650x303.jpg 650w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/task-scheduler-entry-1-789x368.jpg 789w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/task-scheduler-entry-1.jpg 937w\" sizes=\"(max-width: 463px) 100vw, 463px\" \/><em>Fig. 6: Task Scheduler entry<\/em><\/p>\n<p style=\"text-align: left;\">This entry contains same code which is entered at first level and this will execute after every 45 minutes.<\/p>\n<p style=\"text-align: left;\">After that, the script will collect system information and send to CnC server:<\/p>\n<p style=\"text-align: left;\">hxxp[:]\/\/134[.]209[.]103[.]152\/updatev1?&lt;<em>system_info<\/em>&gt;<\/p>\n<p style=\"text-align: left;\">from which it downloads third stage PowerShell script.<\/p>\n<p>&nbsp;<\/p>\n<p>The third level PowerShell script is heavily obfuscated, having size more than 3 MB.<\/p>\n<p>After 3 levels of de-obfuscation, we found that this script uses many open source tools to perform its malicious activity.<\/p>\n<p>In first step, it checks for privilege of running script and according to privilege of PowerShell script, it downloads a PowerShell script and adds its persistence entry into schedule task which triggers after every 45 minutes.<\/p>\n<p>In next step, it executes <a href=\"https:\/\/github.com\/EmpireProject\/Empire\/blob\/master\/data\/module_source\/credentials\/Invoke-PowerDump.ps1\">PowerDump<\/a> tool which is used to dump the hashes from local system. Using these hashes, PowerShell performs lateral movement.<\/p>\n<p>This script is responsible for dumping credentials using <a href=\"https:\/\/github.com\/gentilkiwi\/mimikatz\">Mimikatz<\/a> utility. This script embeds two <a href=\"https:\/\/github.com\/gentilkiwi\/mimikatz\">Mimikatz<\/a> dlls (32 bit and 64 bit) and it loads according to system configuration. The dll is loaded by PowerShell script using reflective dll loading. By getting these hashes, PowerShell will append these hashes to predefined commonly used username and password list.<\/p>\n<p>Following is list of some NTLM hashes.<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-88089 aligncenter\" src=\"https:\/\/blogs.quickheal.com\/wp-content\/uploads\/2019\/08\/users-hash-1-300x51.jpg\" alt=\"\" width=\"624\" height=\"106\" srcset=\"https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/users-hash-1-300x51.jpg 300w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/users-hash-1-768x131.jpg 768w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/users-hash-1-650x111.jpg 650w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/users-hash-1-789x135.jpg 789w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/users-hash-1.jpg 1269w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><em>Fig. 7: Users Hash<\/em><\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-88090 aligncenter\" src=\"https:\/\/blogs.quickheal.com\/wp-content\/uploads\/2019\/08\/common-password-1-300x30.jpg\" alt=\"\" width=\"610\" height=\"61\" srcset=\"https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/common-password-1-300x30.jpg 300w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/common-password-1-768x76.jpg 768w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/common-password-1-650x64.jpg 650w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/common-password-1-789x78.jpg 789w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/common-password-1.jpg 1272w\" sizes=\"(max-width: 610px) 100vw, 610px\" \/><em>Fig. 8: Commonly used password list<\/em><\/p>\n<p style=\"text-align: left;\">Till now, PowerShell script had hashes and using\u00a0 passthehash technique, it tried to get access of another system within network. And hence, to discover network, it uses <a href=\"https:\/\/github.com\/vletoux\/pingcastle\"><em>PingCastle<\/em><\/a> utility. This is basically used to assess quickly Active Directory security level.<\/p>\n<p>After getting network information, using passthehash attack, it tries to create an authentic session within a network. If it gets system access successfully, then using <a href=\"https:\/\/github.com\/Kevin-Robertson\/Invoke-TheHash\/blob\/master\/Invoke-SMBExec.ps1\"><em>SMBEXEC<\/em><\/a> tools, it creates a task scheduler entry in remote system having name \u201c<em>Sync<\/em>\u201d which is different from previous file and it also adds new rule in firewall and open port on tcp having port number <strong>65353<\/strong> in listening state. Task scheduler entry triggers after every 40 minutes.<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-88091 aligncenter\" src=\"https:\/\/blogs.quickheal.com\/wp-content\/uploads\/2019\/08\/sync-1-300x14.jpg\" alt=\"\" width=\"621\" height=\"29\" srcset=\"https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/sync-1-300x14.jpg 300w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/sync-1-768x35.jpg 768w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/sync-1-650x30.jpg 650w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/sync-1-789x36.jpg 789w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/sync-1.jpg 1260w\" sizes=\"(max-width: 621px) 100vw, 621px\" \/><em>Fig. 9: \u201cSync\u201d Task Scheduler entry<\/em><\/p>\n<p style=\"text-align: left;\">The task scheduler service creates entry in <em>TaskCache<\/em> which can also be triggered for this scheduler task.<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-88096 aligncenter\" src=\"https:\/\/blogs.quickheal.com\/wp-content\/uploads\/2019\/08\/sync-registry-1-300x43.jpg\" alt=\"\" width=\"502\" height=\"72\" srcset=\"https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/sync-registry-1-300x43.jpg 300w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/sync-registry-1-768x111.jpg 768w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/sync-registry-1-650x94.jpg 650w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/sync-registry-1-789x114.jpg 789w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/sync-registry-1.jpg 926w\" sizes=\"(max-width: 502px) 100vw, 502px\" \/><em>Fig. 10: \u201cSync\u201d entry in Registry<\/em><\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-88098 aligncenter\" src=\"https:\/\/blogs.quickheal.com\/wp-content\/uploads\/2019\/08\/powershell-entry-1-300x139.jpg\" alt=\"\" width=\"461\" height=\"214\" srcset=\"https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/powershell-entry-1-300x139.jpg 300w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/powershell-entry-1-768x355.jpg 768w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/powershell-entry-1-650x300.jpg 650w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/powershell-entry-1-789x364.jpg 789w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/powershell-entry-1.jpg 959w\" sizes=\"(max-width: 461px) 100vw, 461px\" \/><em>Fig. 11: PowerShell entry in Sync task<\/em><\/p>\n<p style=\"text-align: left;\">If passthehash attack gets failed, this script also has SMB exploits in it. It starts to check the SMB version (SMBv1, SMBv2) of system in network and for SMBv1 PowerShell tries to enter in another system using SMB exploit.<\/p>\n<p style=\"text-align: left;\">After lateral movement, PowerShell goes in infinite loop in which it checks if any Anti-Virus product is installed on system. If found, then that information will be sent to its CnC server.<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-88099 aligncenter\" src=\"https:\/\/blogs.quickheal.com\/wp-content\/uploads\/2019\/08\/AV-products-1-300x76.jpg\" alt=\"\" width=\"466\" height=\"118\" srcset=\"https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/AV-products-1-300x76.jpg 300w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/AV-products-1-768x195.jpg 768w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/AV-products-1-650x165.jpg 650w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/AV-products-1-789x200.jpg 789w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/AV-products-1.jpg 1276w\" sizes=\"(max-width: 466px) 100vw, 466px\" \/><em>Fig. 12: Check for AV products<\/em><\/p>\n<p style=\"text-align: left;\">As per activity done by PowerShell, by opening a tcp port on 65353, we suspect that it can be used to perform bot activity in future.<\/p>\n<p>Quick Heal has successfully detected the PowerShell malware by our Behavior based detection.<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-88100 aligncenter\" src=\"https:\/\/blogs.quickheal.com\/wp-content\/uploads\/2019\/08\/behaviour-detection-1-300x110.jpg\" alt=\"\" width=\"445\" height=\"163\" srcset=\"https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/behaviour-detection-1-300x110.jpg 300w, https:\/\/www.quickheal.com\/blogs\/wp-content\/uploads\/2019\/08\/behaviour-detection-1.jpg 395w\" sizes=\"(max-width: 445px) 100vw, 445px\" \/><em>Fig. 13: Behavior Detection<\/em><\/p>\n<p><strong>Conclusion<\/strong><\/p>\n<p>Quick Heal security labs analyze new trends of malware containing number of open source tools with fileless activity. From our analysis only we found that PowerShell is performing all malicious activities and executes payload in memory, spread in network using exploits and along with it opens a listening port on tcp having port number <strong>65353<\/strong> like a backdoor malware. The malware are still active, so we recommend updating systems and anti-virus product with available patches.<\/p>\n<p><strong>IOCs:<\/strong><\/p>\n<p>C6C4220DA03351645FADC33F6F985CFC<\/p>\n<p>500A3B178AF4D066A88A27EDF1A278C0<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Subject Matter Expert:<\/strong><\/p>\n<p>Aniruddha Dolas, Nagesh Lathkar<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Trend of PowerShell based malware is increasing. General trend observed shows that malware authors use new techniques for infection and propagation of malwares along with open source tools. PowerShell gets executed with high privileges and that&#8217;s why it easily performs its activity and propagates through network. Quick Heal Security Lab has observed that some malwares [&hellip;]<\/p>\n","protected":false},"author":38,"featured_media":88059,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[],"class_list":["post-88035","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-malware"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.quickheal.com\/blogs\/wp-json\/wp\/v2\/posts\/88035"}],"collection":[{"href":"https:\/\/www.quickheal.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.quickheal.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.quickheal.com\/blogs\/wp-json\/wp\/v2\/users\/38"}],"replies":[{"embeddable":true,"href":"https:\/\/www.quickheal.com\/blogs\/wp-json\/wp\/v2\/comments?post=88035"}],"version-history":[{"count":8,"href":"https:\/\/www.quickheal.com\/blogs\/wp-json\/wp\/v2\/posts\/88035\/revisions"}],"predecessor-version":[{"id":88106,"href":"https:\/\/www.quickheal.com\/blogs\/wp-json\/wp\/v2\/posts\/88035\/revisions\/88106"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.quickheal.com\/blogs\/wp-json\/wp\/v2\/media\/88059"}],"wp:attachment":[{"href":"https:\/\/www.quickheal.com\/blogs\/wp-json\/wp\/v2\/media?parent=88035"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.quickheal.com\/blogs\/wp-json\/wp\/v2\/categories?post=88035"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.quickheal.com\/blogs\/wp-json\/wp\/v2\/tags?post=88035"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}