[No audio]
The next scripting environment we're going to explore
is called PowerShell. It used to be
Windows PowerShell, and up until 2016, it was
actually a Windows only product. But as of 2016,
Microsoft re-released it as open source cross
platform. So now it's just PowerShell, and you can
actually get it in MacOS and Linux. You'll likely
see it most of the time still just in Windows,
but it is available for any environment. We're
going to focus on the Windows implementation of
PowerShell. There's just a very few things that
you need to be aware of to set it up and to run
PowerShell scripts, but the rest of the contents
and the concepts are really the same as any other
scripting environment. So let's take a look at how
to launch PowerShell and how to edit a PowerShell
script. So the first thing you'll do on a new
installation of Windows is allow PowerShell
scripts to execute. By default, they're not
allowed, they're actually restricted. So let's
search for PowerShell. There it is. I need to go
in as administrator this once, and from there, I'm going to Set
[No audio]
ExecutionPolicy
[No audio]
Unrestricted. Says, 'Are you sure you want to do this?' Yes, I'm sure.
And that allows me to run PowerShell scripts on
this entire machine. All right. So now let's go
find our favorite PowerShell script. This is a
port scanner, and I'm going to Edit it. So if I
right mouse click and Edit, it takes me into the
Windows PowerShell ISE. It's a really nice
environment where I do get more than just a simple
text editor. But the cool thing about it is all I
have to do is click Run, and it runs the script.
So it tells me that I have some assignments here,
port is 80, subnet is 10.10.1, and the range is
1..254. So my loop says foreach r in range. So
basically r is 1, then 2, then 3, and so
on so forth. We build an IP using concatenation
within PowerShell of 0.1, which basically means
I'm going to replace the subnet and the r, so it'd
be 10.1, I'm sorry, 10.10.1.1, then 10.10.1.2,
and so on and so forth, and notice
we're getting an error here because he's unable to
make a connection with a specific target, because
my machine 12, my Kali Linux machine is
actively refusing port 80. This particular script
doesn't handle errors very well, it's very simple.
So it gives me a little error, and then once I go
into my loop, I set up my socket, I just try to
create a new socket based on the IP address and
the port. If it's connected, I say it's open.
Otherwise, I move on. Simple, very simple script.
But this is how it operates, and we can see the
port 80 is open on 10.10.1.1, 10, 11, and then
the machine number 12 actively refused it and so
it errored out. So that's what a simple, very
simple Windows PowerShell script looks like.
So this script is the same functionality somewhat.
It's what we just saw in bash. It's a port
scanner. Yes, it hard coded some values, we can
bring those in from the outside, but it
effectively grabs an IP and a port range and then
loops through trying to determine if the port is
open or closed. So it looks totally different
because it's a different scripting language, but
it's doing the same thing. Now we're going to look
at some other languages and come back and then
compare all the different languages, so you can be
able to recognize the aspect or the particular
commands of any of the languages you'll have to
recognize for the exam.
[No audio]