{"id":8306,"date":"2017-07-11T08:10:08","date_gmt":"2017-07-11T16:10:08","guid":{"rendered":"http:\/\/www.palada.net\/index.php\/2017\/07\/11\/news-2080\/"},"modified":"2017-07-11T08:10:08","modified_gmt":"2017-07-11T16:10:08","slug":"news-2080","status":"publish","type":"post","link":"https:\/\/www.palada.net\/index.php\/2017\/07\/11\/news-2080\/","title":{"rendered":"Learning PowerShell: The basics"},"content":{"rendered":"<p><strong>Credit to Author: Pieter Arntz| Date: Tue, 11 Jul 2017 15:00:15 +0000<\/strong><\/p>\n<p>I bet I went about learning PowerShell the wrong way, so I may need your help, readers of this blog. If only to organize my knowledge and use it for the fight against malware and not just to figure out how it was used in malware.<\/p>\n<p>The <a href=\"https:\/\/blog.malwarebytes.com\/cybercrime\/2016\/01\/trojan-dnschanger-circumvents-powershell-restrictions\/\" target=\"_blank\" rel=\"noopener noreferrer\">first serious look I had at PowerShell<\/a> was when I was trying to figure out what some piece of malware was doing. But the most important lessons I learned back then was that PowerShell is very versatile and that its execution policy is hardly stopping anyone from performing malicious acts on an infected computer.<\/p>\n<p>Both of these properties make it a powerful weapon in the hands of hackers, pen testers, and malware authors. Given the current tendency to use legitimate tools and programs in an attack, I want to learn more about it and see how we can use it to our advantage. Sort of as white hat hackers would.<\/p>\n<h3>Bypassing the execution policy<\/h3>\n<p>The PowerShell execution policy is what controls how much PowerShell can do on the system at hand. The possible settings can be found in this Technet article about <a href=\"https:\/\/technet.microsoft.com\/en-us\/library\/ee176961.aspx\" target=\"_blank\" rel=\"noopener noreferrer\">Using the Set-ExecutionPolicy Cmdlet<\/a>, where \u201cRestricted\u201d is the default setting.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-18766 size-full\" src=\"https:\/\/blog.malwarebytes.com\/wp-content\/uploads\/2017\/07\/Restricted.png\" alt=\"Restricted?\" width=\"549\" height=\"143\" srcset=\"https:\/\/blog.malwarebytes.com\/wp-content\/uploads\/2017\/07\/Restricted.png 549w, https:\/\/blog.malwarebytes.com\/wp-content\/uploads\/2017\/07\/Restricted-300x78.png 300w\" sizes=\"auto, (max-width: 549px) 100vw, 549px\" \/><\/p>\n<p>But one of the first things I noticed was how trivial it is to bypass this restriction. The easiest way to run your PowerShell program is to \u201cpipe\u201d it and add a <strong>-executionpolicy bypass<\/strong> switch. This will ensure the command will run without taking the current execution policy into consideration. If the script is too complex to pipe, you can encode the entire script (base64) and use the switch &#8211;<strong>EncodedCommand<\/strong>. For malware authors, this has the added benefit that it will take the average user a lot longer to figure out what was done.<\/p>\n<h3><strong>Basics<\/strong><\/h3>\n<h4>Cmdlets<\/h4>\n<p>But let\u2019s start with the basics first. PowerShell uses so-called <em>cmdlets<\/em>. These <em>cmdlets<\/em> typically perform a task and return a .NET object that can be piped to the next command. They are NOT standalone executables like some of the commands that we used in the command prompt, but rather .NET framework classes.<\/p>\n<h4>Naming convention<\/h4>\n<p>Windows PowerShell uses a verb-noun pair for the names of <em>cmdlets<\/em> and their derived classes. This makes it easy to understand what to expect. For example, if we look at the <em>cmdlet<\/em>\u00a0<strong>ConvertTo-Xml <\/strong>it<strong>\u00a0<\/strong>should be clear enough to figure out what will happen when you use it. And for <em>cmdlets<\/em> that aren\u2019t so clear, or when\u00a0you\u2019d like to know more about the <em>cmdlet<\/em> or its syntax you can use the <strong>Get-Help <\/strong>cmdlet.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-18765\" src=\"https:\/\/blog.malwarebytes.com\/wp-content\/uploads\/2017\/07\/GetHelp.png\" alt=\"Get-Help\" width=\"997\" height=\"486\" srcset=\"https:\/\/blog.malwarebytes.com\/wp-content\/uploads\/2017\/07\/GetHelp.png 997w, https:\/\/blog.malwarebytes.com\/wp-content\/uploads\/2017\/07\/GetHelp-300x146.png 300w, https:\/\/blog.malwarebytes.com\/wp-content\/uploads\/2017\/07\/GetHelp-600x292.png 600w\" sizes=\"auto, (max-width: 997px) 100vw, 997px\" \/><\/p>\n<h4>Aliases<\/h4>\n<p>Another important thing to know about in this context, however, especially when reverse engineering a script, are aliases. A lot of <em>cmdlets<\/em> have an alias that triggers the <em>cmdlet<\/em>, but that doesn\u2019t use the naming convention for them. For example, the alias <strong>del<\/strong> is in use for the <em>cmdlet<\/em> <strong>Remove-Item<\/strong>. An overview of the basic <em>cmdlets<\/em>, aliases, and functions can be obtained by running <strong>Get-Command <\/strong>which will show you an extensive list.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-18764\" src=\"https:\/\/blog.malwarebytes.com\/wp-content\/uploads\/2017\/07\/GetCommand.png\" alt=\"Get-Command\" width=\"997\" height=\"309\" srcset=\"https:\/\/blog.malwarebytes.com\/wp-content\/uploads\/2017\/07\/GetCommand.png 997w, https:\/\/blog.malwarebytes.com\/wp-content\/uploads\/2017\/07\/GetCommand-300x93.png 300w, https:\/\/blog.malwarebytes.com\/wp-content\/uploads\/2017\/07\/GetCommand-600x186.png 600w\" sizes=\"auto, (max-width: 997px) 100vw, 997px\" \/><\/p>\n<p>This was a quick summary of the working knowledge I have together with some de-obfuscation techniques and a lot of \u201clooking stuff up\u201d, it has been enough to serve my purpose of being able to figure out what others were doing. But I feel it\u2019s time to learn some more, and since I learn best using the hands-on method, in the next post we will be doing some basic programming.<\/p>\n<p>See you then!<\/p>\n<p>The post <a rel=\"nofollow\" href=\"https:\/\/blog.malwarebytes.com\/101\/how-tos\/2017\/07\/learning-powershell-the-basics\/\">Learning PowerShell: The basics<\/a> appeared first on <a rel=\"nofollow\" href=\"https:\/\/blog.malwarebytes.com\">Malwarebytes Labs<\/a>.<\/p>\n<p><a href=\"https:\/\/blog.malwarebytes.com\/101\/how-tos\/2017\/07\/learning-powershell-the-basics\/\" target=\"bwo\" >https:\/\/blog.malwarebytes.com\/feed\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p><strong>Credit to Author: Pieter Arntz| Date: Tue, 11 Jul 2017 15:00:15 +0000<\/strong><\/p>\n<table cellpadding='10'>\n<tr>\n<td valign='top' align='center'><a href='https:\/\/blog.malwarebytes.com\/101\/how-tos\/2017\/07\/learning-powershell-the-basics\/' title='Learning PowerShell: The basics'><img src='https:\/\/blog.malwarebytes.com\/wp-content\/uploads\/2017\/07\/Powershellhero.jpg' border='0'  width='300px'  \/><\/a><\/td>\n<\/tr>\n<tr>\n<td valign='top' align='left'>Get acquainted with some of the basic principles of Powershell and get prepared for some basic usage of this versatile tool that is available on all modern Windows systems.<\/p>\n<p>Categories: <\/p>\n<ul class=\"post-categories\">\n<li><a href=\"https:\/\/blog.malwarebytes.com\/category\/101\/\" rel=\"category tag\">101<\/a><\/li>\n<li><a href=\"https:\/\/blog.malwarebytes.com\/category\/101\/how-tos\/\" rel=\"category tag\">How-tos<\/a><\/li>\n<\/ul>\n<p>Tags: <a href=\"https:\/\/blog.malwarebytes.com\/tag\/basic\/\" rel=\"tag\">basic<\/a><a href=\"https:\/\/blog.malwarebytes.com\/tag\/cmdlet\/\" rel=\"tag\">cmdlet<\/a><a href=\"https:\/\/blog.malwarebytes.com\/tag\/malware\/\" rel=\"tag\">malware<\/a><a href=\"https:\/\/blog.malwarebytes.com\/tag\/pieter-arntz\/\" rel=\"tag\">Pieter Arntz<\/a><a href=\"https:\/\/blog.malwarebytes.com\/tag\/powershell\/\" rel=\"tag\">powershell<\/a><a href=\"https:\/\/blog.malwarebytes.com\/tag\/restrictions\/\" rel=\"tag\">restrictions<\/a><\/p>\n<table width='100%'>\n<tr>\n<td align=right>\n<p><b>(<a href='https:\/\/blog.malwarebytes.com\/101\/how-tos\/2017\/07\/learning-powershell-the-basics\/' title='Learning PowerShell: The basics'>Read more&#8230;<\/a>)<\/b><\/p>\n<\/td>\n<\/tr>\n<\/table>\n<\/td>\n<\/tr>\n<\/table>\n<p>The post <a rel=\"nofollow\" href=\"https:\/\/blog.malwarebytes.com\/101\/how-tos\/2017\/07\/learning-powershell-the-basics\/\">Learning PowerShell: The basics<\/a> appeared first on <a rel=\"nofollow\" href=\"https:\/\/blog.malwarebytes.com\">Malwarebytes Labs<\/a>.<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[10488,10378],"tags":[10519,12985,12986,11171,3764,10523,11191,12987],"class_list":["post-8306","post","type-post","status-publish","format-standard","hentry","category-malwarebytes","category-security","tag-10519","tag-basic","tag-cmdlet","tag-how-tos","tag-malware","tag-pieter-arntz","tag-powershell","tag-restrictions"],"_links":{"self":[{"href":"https:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/posts\/8306","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/comments?post=8306"}],"version-history":[{"count":0,"href":"https:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/posts\/8306\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/media?parent=8306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/categories?post=8306"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/tags?post=8306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}