Basics Of Powershell For Hackers: The beginning Part 1

Recently I started learning PowerShell Because If you try to hack services on windows environment in an efficient way the more powershell you know the better you and it is really great to automate tasks as well.

quickmeme.com

Why POwerShell?

Powershell is everywhere it can be used to automate task, manipulate files, registries in windows machine and what not.

It is now even available in Linux and Mac Os Itself. It is Great for gathering all kinds of data and building reports.

Powershell is the Windows Scripting Language and shell environment that is built using the .NET framework.

The most powerful commands are called cmdlets and they are written in .NET, the output of these cmdlets are objects making poweshell somewhat object oriented.

The normal format of a cmdlet is represented using verb-Noun.

example - cmdlet list commands is Get-Command

Some Common Verbs:

  • Get
  • start
  • stop
  • Read
  • Write
  • New
  • Out
  • Connect/Disconnect

More verbs Microsoft Documentation.

Using Get-Help

Get-Help as name suggest displays information about a cmdlet. To get help about a particular cmdlet run,

P.s > Get-Help Command-Name 

We can also understand how exactly to use the commands by passing the -Examples flag.

p.s > Get-Help Get-command -Examples

Using Get-Command

Get-command gets all the cmdlets installed on the current system. The great thing about this cmdlet is that it allows for pattern matching.

p.s > Get-Command verb-*
p.s > Get-Command *-Noun

Lets run for the Backup to match any cmdlet is present on the system. But it return a function means there is no cmdlet for Backup.

Get-Command Backup-*
Get-Command *-Debug*

Using Get-ChildItem and ls


PS > Get-ChildItem //Listing of all the files in current directory
PS > ls //listing all the files
Listing files.
Same as Get-ChildItem

Using Get-Child and ls with a path

with path variable

Add-Content and Aliases

Add-Content adds a file in the system or add existing data to a file.

PS > Add-Content -path C:\ a.txt

Most of the command we use in Linux and windows can be used in powershell but then the question arises why we are even learning if we can use Linux command like cat and windows command type.

Example to show how powerful is PowerShell for the sake of simplicity we will use the Ping command vs the Test-Connection Command.

Just look at the output of both the commands you can see the difference how gibberish result ping gives and how clean Test-Connection command.

Get-Alias

A word about Microsoft team is that these guys are really making powershell easy by giving you many inbuilt aliases from windows and Linux environment to adapt Powershell.

Photo by Yulia Matvienko on Unsplash

I think I should end this post here Because many a people just Don’t like too long post.

Some Words about Powershell that it is really a fun, as well as powerful language And the auto-completion feature, make it really a better choice.

I assume the next part is going to be fun.

Author-Harsh Dushyant Singh

I am a student, Bug Bounty Hunter, CTF player and a geek for sure. Who is currently sharpening the axe.