SlideShare a Scribd company logo
1 of 2
Download to read offline
COVER STORY                       Bash vs. Vista PowerShell




Comparing Bash with the Windows Vista shell


SHELL GAMES


                                                                                                                                          es.war.einmal.., photocase.com
Microsoft’s new PowerShell relies on .NET framework libraries and

thus has access to a treasure trove of functions and objects. How does

PowerShell measure up to traditional shells like Bash?
                                                                                              means that you trust the author. Power-
BY MARCUS NASAREK                                                                             Shell will not run “unknown” scripts at
                                                                                              all. To run a script without a signature,
                                                                                              you need to change the execution policy



B
         oth Bash and the Windows Vista       Listing 1 compares outputting a counter         to RemoteSigned at the command line
         PowerShell include commands          with for in PowerShell and Bash.                like so:
         for navigating directories, man-        Bash and PowerShell are similar with
aging files, and launching other pro-         respect to case-based program flow con-          PS:> Set-ExecutionPolicy U
grams. System administration is an im-        trol with if or switch. The definition of        RemoteSigned
portant duty for the shell, and Bash and      functions, the use of environmental vari-
PowerShell are equipped to help manage        ables, scoping (restricted validity of vari-             Listing 1: Loops
systems from the command prompt.              ables), the use of regular expressions,
                                                                                               A for loop in the Windows Vista
   Whereas Bash typically relies on a         and the evaluation of program return
                                                                                               PowerShell:
combination of newer tools and classic        values are all similar in both shells.
                                                                                               PS:> for ($i=1;$i -le 3;$i++) {
Unix utilities, the PowerShell has its own
                                              Restricted Launch                                Write-Host $i }
set of command-line programs. Win-
dows refers to PowerShell commands as         Permission                                       1

cmdlets. The PowerShell cmdlet called         An initial difference between PowerShell         2
Get-Process is a counterpart to ps, and       and Bash occurs when a script is exe-            3
the cmdlet Get-Content corresponds to         cuted. PowerShell will not launch script         PS:>
less. PowerShell differs significantly from   files by default and thus only supports          The same loop in Bash:
previous Windows command shells. In           interactive use. However, PowerShell             bash[~]$ for ((i=1;i<=3;i++); do
this article, I look at how Windows Vista     will run scripts if they are digitally           echo $i; done
PowerShell compares with Bash.                signed. The digital signature identifies         1
   To support program control, a shell        the script’s author because the author is        2
needs elements for conditional execu-         the only person capable of creating the          3
tion. for or while evaluate a variable to     signature by cryptographic means. Ac-
                                                                                               bash[~]$
support a defined number of iterations.       cepting the author’s signature certificate




38        ISSUE 78 MAY 2007                      W W W. L I N U X - M A G A Z I N E . C O M
Bash vs. Vista PowerShell                    COVER STORY




                                                                                              input and output files. Bash trusts that
                      Listing 2: Get-Member Output                                            the next command in the chain can do
 01 PS:> Get-Content Textdatei.txt | Get-Member                                               something meaningful with the output.
 02                                                                                              In PowerShell, all cmdlets create de-
 03     TypeName: System.String                                                               fined objects as their output data instead
 04                                                                                           of text-only output. Even if it appears
                                                                                              that only strings are passed in text out-
 05 Name                MemberType               Definition
                                                                                              put, what happens is that the complete
 06 ----                ----------               ----------
                                                                                              output is converted to an object.
 07 Clone               Method                   System.Object Clone()                           Objects can be queried with the
 08 CompareTo       Method               System.Int32 CompareTo(Object                        Get-Member command, which outputs
    value), System.Int32 CompareTo(String strB)                                               the elements and functions of the object.
 09 Contains             Method                  System.Boolean Contains(String               See Listing 2. For example, the command
    value)
 10 CopyTo          Method               System.Void CopyTo(Int32                              PS:> Get-Content Textdatei.txt |
    sourceIndex, Char[] destination, Int32 destinationIn...                                     Sort { $_.Length }
 11 ...
 12 Length              Property                                                              lets you sort the lines in a text file by
                                                                                              length with the object's Length property.
 13
                                                                                                 Although passing data objects is
 14 PS:>
                                                                                              slightly more complex, this object orien-
                                                                                              tation helps standardize operations and
This command tells PowerShell to accept       gards everything as a filesystem and not        supports handling of complex data struc-
all local scripts. If you downloaded the      only navigates the filesystem and drives,       tures. Bash cannot compete here; in-
data, or if the data is attached to an        but the Registry, the certificate store, and    stead, it relies on the abilities of external
email, the shell will continue to insist on   environmental variables. You can copy,          programs to handle data structures.
a signature. The ability to prevent com-      rename, and move Registry values just              For example, Bash needs an external
mands from external sources from exe-         as you would files on a drive. The Pow-         XML parser (like Saxon or Xalan-J) to
cuting is a whole new league security-        erShell refers to these virtual filesystems     parse XML files. Listing 3 is a short Pow-
wise, and scripted viruses such as “Love      as Providers, thus implementing a phi-          erShell script that loads an RSS feed off
Letter” [1] lose their threat.                losophy that Linux has always offered to        the Internet in the form of an XML file.
   In contrast to this, Bash does not rely    Bash: “Everything is a file.”                   The script defines a Show-SpiegelRSS
on digital signatures to evaluate a                                                           function that gets the current RSS Feeds.
script’s execution permissions. Instead,      Forwarding
filesystem permissions determine              PowerShell’s most powerful tool is the          Conclusions
whether the script is permitted to run.       pipe, which supports ordered passing of         In one respect, PowerShell relies on the
   Both shells share some surprising          values, allowing the use of output from         Unix concept that many small utilities
common ground in the way they handle          one command as input to the next com-           are preferable to one large, custom-made
system configuration. New to the world        mand. Bash supports pipes too, but it           utility. At the same time, it adopts an ob-
of Windows is the way PowerShell re-          does not make particular demands on             ject-oriented approach that makes larger
                                                                                              scale projects simpler at the cost of a
                    Listing 3: Show-SpiegelRSS.ps1                                            steeper learning curve. The major prob-
                                                                                              lem with objects is that you need to in-
 01 # Show-RSS.ps1
                                                                                              vest significant time in discovering
 02 # Declaration of variables for URL                                                        which function or object you need. The
 03       $feed="http://rss.news.yahoo.com/rss/linux")                                        Get-Member cmdlet is likely to see much
 04       Write-Host -ForegroundColor "green" "RSS-Feed: " $feed                              use in PowerShell.
 05 # Download RSS feed                                                                         Bash is useful as a plain but straight-
 06       $wco = New-Object System.Net.WebClient
                                                                                              forward tool for most daily tasks. If it
                                                                                              comes to the need for advanced uses
 07       $rss = [xml]$wco.DownloadString($feed)
                                                                                              and complex data structures, you can
 08 # Show title
                                                                                              branch out into object-oriented Python
 09       Write-Host -ForegroundColor "red" $rss.rss.channel.title                            or the graphical capabilities of Tcl/Tk. ■
 10 # Display short form
 11       $rss.rss.item | Select-Object title,description | format-table                                        INFO
 12 # Display title and description of entries                                                 [1] CERT-Advisory CA-2000-04 “Love
 13       $rss.rss.channel.item | Select-Object title,pubDate,description                          Letter Worm”: http://www.cert.org/
      | format-list                                                                                advisories/CA-2000-04.html




                                                 W W W. L I N U X - M A G A Z I N E . C O M              ISSUE 78 MAY 2007            39

More Related Content

What's hot

What's hot (20)

EPM Planning &amp; Budget Red Paper
EPM Planning &amp; Budget Red PaperEPM Planning &amp; Budget Red Paper
EPM Planning &amp; Budget Red Paper
 
Riding the Overflow - Then and Now
Riding the Overflow - Then and NowRiding the Overflow - Then and Now
Riding the Overflow - Then and Now
 
Curl
CurlCurl
Curl
 
Linux class 8 tar
Linux class 8   tar  Linux class 8   tar
Linux class 8 tar
 
MCLS 45 Lab Manual
MCLS 45 Lab ManualMCLS 45 Lab Manual
MCLS 45 Lab Manual
 
VTU 3RD SEM UNIX AND SHELL PROGRAMMING SOLVED PAPERS
VTU 3RD SEM UNIX AND SHELL PROGRAMMING SOLVED PAPERSVTU 3RD SEM UNIX AND SHELL PROGRAMMING SOLVED PAPERS
VTU 3RD SEM UNIX AND SHELL PROGRAMMING SOLVED PAPERS
 
Linux
LinuxLinux
Linux
 
Lession1 Linux Preview
Lession1 Linux PreviewLession1 Linux Preview
Lession1 Linux Preview
 
Unix commands in etl testing
Unix commands in etl testingUnix commands in etl testing
Unix commands in etl testing
 
20141111 파이썬으로 Hadoop MR프로그래밍
20141111 파이썬으로 Hadoop MR프로그래밍20141111 파이썬으로 Hadoop MR프로그래밍
20141111 파이썬으로 Hadoop MR프로그래밍
 
SQL Server Select Topics
SQL Server Select TopicsSQL Server Select Topics
SQL Server Select Topics
 
Os lab manual
Os lab manualOs lab manual
Os lab manual
 
Advanced SQL injection to operating system full control (short version)
Advanced SQL injection to operating system full control (short version)Advanced SQL injection to operating system full control (short version)
Advanced SQL injection to operating system full control (short version)
 
Got database access? Own the network!
Got database access? Own the network!Got database access? Own the network!
Got database access? Own the network!
 
Linux com
Linux comLinux com
Linux com
 
Operating System Assignment Help
Operating System Assignment HelpOperating System Assignment Help
Operating System Assignment Help
 
Applecmdlista zs
Applecmdlista zsApplecmdlista zs
Applecmdlista zs
 
Linux
LinuxLinux
Linux
 
Linux
LinuxLinux
Linux
 
Windows command prompt a to z
Windows command prompt a to zWindows command prompt a to z
Windows command prompt a to z
 

Similar to Bash vs. vista_power_shell

Post exploitation using powershell
Post exploitation using powershellPost exploitation using powershell
Post exploitation using powershellMihir Shah
 
Shell Scripting and Programming.pptx
Shell Scripting and Programming.pptxShell Scripting and Programming.pptx
Shell Scripting and Programming.pptxHarsha Patel
 
Shell Scripting and Programming.pptx
Shell Scripting and Programming.pptxShell Scripting and Programming.pptx
Shell Scripting and Programming.pptxHarsha Patel
 
BACKGROUND A shell provides a command-line interface for users. I.docx
BACKGROUND A shell provides a command-line interface for users. I.docxBACKGROUND A shell provides a command-line interface for users. I.docx
BACKGROUND A shell provides a command-line interface for users. I.docxwilcockiris
 
intro unix/linux 08
intro unix/linux 08intro unix/linux 08
intro unix/linux 08duquoi
 
Lab 7 - Bash Script.pptx
Lab 7 - Bash Script.pptxLab 7 - Bash Script.pptx
Lab 7 - Bash Script.pptxNourhanTarek23
 
Pwning with powershell
Pwning with powershellPwning with powershell
Pwning with powershelljaredhaight
 
2023comp90024_linux.pdf
2023comp90024_linux.pdf2023comp90024_linux.pdf
2023comp90024_linux.pdfLevLafayette1
 
Let's Take A Look At The Boost Libraries
Let's Take A Look At The Boost LibrariesLet's Take A Look At The Boost Libraries
Let's Take A Look At The Boost LibrariesThomas Pollak
 
Tiny Linux Kernel Project: Section Garbage Collection Patchset
Tiny Linux Kernel Project: Section Garbage Collection Patchset Tiny Linux Kernel Project: Section Garbage Collection Patchset
Tiny Linux Kernel Project: Section Garbage Collection Patchset libfetion
 
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdf
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdfLearn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdf
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdfClapperboardCinemaPV
 
CSCI  132  Practical  Unix  and  Programming   .docx
CSCI  132  Practical  Unix  and  Programming   .docxCSCI  132  Practical  Unix  and  Programming   .docx
CSCI  132  Practical  Unix  and  Programming   .docxmydrynan
 
1 of 9 CSCE 3600 Systems Programming Major Assignm.docx
  1 of 9 CSCE 3600 Systems Programming  Major Assignm.docx  1 of 9 CSCE 3600 Systems Programming  Major Assignm.docx
1 of 9 CSCE 3600 Systems Programming Major Assignm.docxShiraPrater50
 

Similar to Bash vs. vista_power_shell (20)

Post exploitation using powershell
Post exploitation using powershellPost exploitation using powershell
Post exploitation using powershell
 
Shell Scripting and Programming.pptx
Shell Scripting and Programming.pptxShell Scripting and Programming.pptx
Shell Scripting and Programming.pptx
 
Shell Scripting and Programming.pptx
Shell Scripting and Programming.pptxShell Scripting and Programming.pptx
Shell Scripting and Programming.pptx
 
BACKGROUND A shell provides a command-line interface for users. I.docx
BACKGROUND A shell provides a command-line interface for users. I.docxBACKGROUND A shell provides a command-line interface for users. I.docx
BACKGROUND A shell provides a command-line interface for users. I.docx
 
intro unix/linux 08
intro unix/linux 08intro unix/linux 08
intro unix/linux 08
 
Lab 7 - Bash Script.pptx
Lab 7 - Bash Script.pptxLab 7 - Bash Script.pptx
Lab 7 - Bash Script.pptx
 
Power Shell For Testers
Power Shell For TestersPower Shell For Testers
Power Shell For Testers
 
Pwning with powershell
Pwning with powershellPwning with powershell
Pwning with powershell
 
Windows PowerShell
Windows PowerShellWindows PowerShell
Windows PowerShell
 
Pydbapi
PydbapiPydbapi
Pydbapi
 
2023comp90024_linux.pdf
2023comp90024_linux.pdf2023comp90024_linux.pdf
2023comp90024_linux.pdf
 
Let's Take A Look At The Boost Libraries
Let's Take A Look At The Boost LibrariesLet's Take A Look At The Boost Libraries
Let's Take A Look At The Boost Libraries
 
Tiny Linux Kernel Project: Section Garbage Collection Patchset
Tiny Linux Kernel Project: Section Garbage Collection Patchset Tiny Linux Kernel Project: Section Garbage Collection Patchset
Tiny Linux Kernel Project: Section Garbage Collection Patchset
 
Mach-O Internals
Mach-O InternalsMach-O Internals
Mach-O Internals
 
One Click Ownage
One Click OwnageOne Click Ownage
One Click Ownage
 
One Click Ownage
One Click OwnageOne Click Ownage
One Click Ownage
 
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdf
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdfLearn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdf
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdf
 
Powershell notes
Powershell notesPowershell notes
Powershell notes
 
CSCI  132  Practical  Unix  and  Programming   .docx
CSCI  132  Practical  Unix  and  Programming   .docxCSCI  132  Practical  Unix  and  Programming   .docx
CSCI  132  Practical  Unix  and  Programming   .docx
 
1 of 9 CSCE 3600 Systems Programming Major Assignm.docx
  1 of 9 CSCE 3600 Systems Programming  Major Assignm.docx  1 of 9 CSCE 3600 Systems Programming  Major Assignm.docx
1 of 9 CSCE 3600 Systems Programming Major Assignm.docx
 

Bash vs. vista_power_shell

  • 1. COVER STORY Bash vs. Vista PowerShell Comparing Bash with the Windows Vista shell SHELL GAMES es.war.einmal.., photocase.com Microsoft’s new PowerShell relies on .NET framework libraries and thus has access to a treasure trove of functions and objects. How does PowerShell measure up to traditional shells like Bash? means that you trust the author. Power- BY MARCUS NASAREK Shell will not run “unknown” scripts at all. To run a script without a signature, you need to change the execution policy B oth Bash and the Windows Vista Listing 1 compares outputting a counter to RemoteSigned at the command line PowerShell include commands with for in PowerShell and Bash. like so: for navigating directories, man- Bash and PowerShell are similar with aging files, and launching other pro- respect to case-based program flow con- PS:> Set-ExecutionPolicy U grams. System administration is an im- trol with if or switch. The definition of RemoteSigned portant duty for the shell, and Bash and functions, the use of environmental vari- PowerShell are equipped to help manage ables, scoping (restricted validity of vari- Listing 1: Loops systems from the command prompt. ables), the use of regular expressions, A for loop in the Windows Vista Whereas Bash typically relies on a and the evaluation of program return PowerShell: combination of newer tools and classic values are all similar in both shells. PS:> for ($i=1;$i -le 3;$i++) { Unix utilities, the PowerShell has its own Restricted Launch Write-Host $i } set of command-line programs. Win- dows refers to PowerShell commands as Permission 1 cmdlets. The PowerShell cmdlet called An initial difference between PowerShell 2 Get-Process is a counterpart to ps, and and Bash occurs when a script is exe- 3 the cmdlet Get-Content corresponds to cuted. PowerShell will not launch script PS:> less. PowerShell differs significantly from files by default and thus only supports The same loop in Bash: previous Windows command shells. In interactive use. However, PowerShell bash[~]$ for ((i=1;i<=3;i++); do this article, I look at how Windows Vista will run scripts if they are digitally echo $i; done PowerShell compares with Bash. signed. The digital signature identifies 1 To support program control, a shell the script’s author because the author is 2 needs elements for conditional execu- the only person capable of creating the 3 tion. for or while evaluate a variable to signature by cryptographic means. Ac- bash[~]$ support a defined number of iterations. cepting the author’s signature certificate 38 ISSUE 78 MAY 2007 W W W. L I N U X - M A G A Z I N E . C O M
  • 2. Bash vs. Vista PowerShell COVER STORY input and output files. Bash trusts that Listing 2: Get-Member Output the next command in the chain can do 01 PS:> Get-Content Textdatei.txt | Get-Member something meaningful with the output. 02 In PowerShell, all cmdlets create de- 03 TypeName: System.String fined objects as their output data instead 04 of text-only output. Even if it appears that only strings are passed in text out- 05 Name MemberType Definition put, what happens is that the complete 06 ---- ---------- ---------- output is converted to an object. 07 Clone Method System.Object Clone() Objects can be queried with the 08 CompareTo Method System.Int32 CompareTo(Object Get-Member command, which outputs value), System.Int32 CompareTo(String strB) the elements and functions of the object. 09 Contains Method System.Boolean Contains(String See Listing 2. For example, the command value) 10 CopyTo Method System.Void CopyTo(Int32 PS:> Get-Content Textdatei.txt | sourceIndex, Char[] destination, Int32 destinationIn... Sort { $_.Length } 11 ... 12 Length Property lets you sort the lines in a text file by length with the object's Length property. 13 Although passing data objects is 14 PS:> slightly more complex, this object orien- tation helps standardize operations and This command tells PowerShell to accept gards everything as a filesystem and not supports handling of complex data struc- all local scripts. If you downloaded the only navigates the filesystem and drives, tures. Bash cannot compete here; in- data, or if the data is attached to an but the Registry, the certificate store, and stead, it relies on the abilities of external email, the shell will continue to insist on environmental variables. You can copy, programs to handle data structures. a signature. The ability to prevent com- rename, and move Registry values just For example, Bash needs an external mands from external sources from exe- as you would files on a drive. The Pow- XML parser (like Saxon or Xalan-J) to cuting is a whole new league security- erShell refers to these virtual filesystems parse XML files. Listing 3 is a short Pow- wise, and scripted viruses such as “Love as Providers, thus implementing a phi- erShell script that loads an RSS feed off Letter” [1] lose their threat. losophy that Linux has always offered to the Internet in the form of an XML file. In contrast to this, Bash does not rely Bash: “Everything is a file.” The script defines a Show-SpiegelRSS on digital signatures to evaluate a function that gets the current RSS Feeds. script’s execution permissions. Instead, Forwarding filesystem permissions determine PowerShell’s most powerful tool is the Conclusions whether the script is permitted to run. pipe, which supports ordered passing of In one respect, PowerShell relies on the Both shells share some surprising values, allowing the use of output from Unix concept that many small utilities common ground in the way they handle one command as input to the next com- are preferable to one large, custom-made system configuration. New to the world mand. Bash supports pipes too, but it utility. At the same time, it adopts an ob- of Windows is the way PowerShell re- does not make particular demands on ject-oriented approach that makes larger scale projects simpler at the cost of a Listing 3: Show-SpiegelRSS.ps1 steeper learning curve. The major prob- lem with objects is that you need to in- 01 # Show-RSS.ps1 vest significant time in discovering 02 # Declaration of variables for URL which function or object you need. The 03 $feed="http://rss.news.yahoo.com/rss/linux") Get-Member cmdlet is likely to see much 04 Write-Host -ForegroundColor "green" "RSS-Feed: " $feed use in PowerShell. 05 # Download RSS feed Bash is useful as a plain but straight- 06 $wco = New-Object System.Net.WebClient forward tool for most daily tasks. If it comes to the need for advanced uses 07 $rss = [xml]$wco.DownloadString($feed) and complex data structures, you can 08 # Show title branch out into object-oriented Python 09 Write-Host -ForegroundColor "red" $rss.rss.channel.title or the graphical capabilities of Tcl/Tk. ■ 10 # Display short form 11 $rss.rss.item | Select-Object title,description | format-table INFO 12 # Display title and description of entries [1] CERT-Advisory CA-2000-04 “Love 13 $rss.rss.channel.item | Select-Object title,pubDate,description Letter Worm”: http://www.cert.org/ | format-list advisories/CA-2000-04.html W W W. L I N U X - M A G A Z I N E . C O M ISSUE 78 MAY 2007 39