Video - Creating a BASH Script for Scanning Vulnerable Ports

16 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
ā‚¬93.70
List Price:  ā‚¬131.19
You save:  ā‚¬37.48
Ā£80.17
List Price:  Ā£112.24
You save:  Ā£32.07
CA$137.56
List Price:  CA$192.60
You save:  CA$55.03
A$155.17
List Price:  A$217.25
You save:  A$62.07
S$135.98
List Price:  S$190.37
You save:  S$54.39
HK$783.01
List Price:  HK$1,096.25
You save:  HK$313.23
CHF 90.89
List Price:  CHF 127.26
You save:  CHF 36.36
NOK kr1,101.16
List Price:  NOK kr1,541.68
You save:  NOK kr440.51
DKK kr699.21
List Price:  DKK kr978.92
You save:  DKK kr279.71
NZ$168.70
List Price:  NZ$236.19
You save:  NZ$67.48
ŲÆ.Ų„367.21
List Price:  ŲÆ.Ų„514.11
You save:  ŲÆ.Ų„146.90
ą§³10,942.52
List Price:  ą§³15,319.96
You save:  ą§³4,377.44
ā‚¹8,353.31
List Price:  ā‚¹11,694.97
You save:  ā‚¹3,341.66
RM478.30
List Price:  RM669.64
You save:  RM191.34
ā‚¦129,687.03
List Price:  ā‚¦181,567.03
You save:  ā‚¦51,880
ā‚Ø27,754.24
List Price:  ā‚Ø38,857.05
You save:  ā‚Ø11,102.81
ąøæ3,676.55
List Price:  ąøæ5,147.32
You save:  ąøæ1,470.77
ā‚ŗ3,250.48
List Price:  ā‚ŗ4,550.80
You save:  ā‚ŗ1,300.32
B$523.28
List Price:  B$732.62
You save:  B$209.33
R1,903.66
List Price:  R2,665.20
You save:  R761.54
Š›Š²183.15
List Price:  Š›Š²256.41
You save:  Š›Š²73.26
ā‚©137,464.20
List Price:  ā‚©192,455.38
You save:  ā‚©54,991.18
ā‚Ŗ378.95
List Price:  ā‚Ŗ530.55
You save:  ā‚Ŗ151.59
ā‚±5,720.89
List Price:  ā‚±8,009.48
You save:  ā‚±2,288.58
Ā„15,440.72
List Price:  Ā„21,617.62
You save:  Ā„6,176.90
MX$1,696.11
List Price:  MX$2,374.63
You save:  MX$678.51
QR363.78
List Price:  QR509.31
You save:  QR145.52
P1,378.02
List Price:  P1,929.29
You save:  P551.26
KSh13,298.67
List Price:  KSh18,618.67
You save:  KSh5,320
EĀ£4,850.08
List Price:  EĀ£6,790.31
You save:  EĀ£1,940.22
į‰„įˆ­5,673.01
List Price:  į‰„įˆ­7,942.45
You save:  į‰„įˆ­2,269.43
Kz83,741.62
List Price:  Kz117,241.62
You save:  Kz33,500
CLP$97,883.21
List Price:  CLP$137,040.41
You save:  CLP$39,157.20
CNĀ„723.83
List Price:  CNĀ„1,013.40
You save:  CNĀ„289.56
RD$5,893.56
List Price:  RD$8,251.22
You save:  RD$2,357.66
DA13,447.21
List Price:  DA18,826.63
You save:  DA5,379.42
FJ$227.04
List Price:  FJ$317.87
You save:  FJ$90.82
Q775.43
List Price:  Q1,085.64
You save:  Q310.20
GY$20,874.74
List Price:  GY$29,225.48
You save:  GY$8,350.73
ISK kr14,084.59
List Price:  ISK kr19,718.99
You save:  ISK kr5,634.40
DH1,011.98
List Price:  DH1,416.82
You save:  DH404.83
L1,789.85
List Price:  L2,505.87
You save:  L716.01
Š“ŠµŠ½5,767.34
List Price:  Š“ŠµŠ½8,074.51
You save:  Š“ŠµŠ½2,307.16
MOP$804.17
List Price:  MOP$1,125.87
You save:  MOP$321.70
N$1,897.84
List Price:  N$2,657.05
You save:  N$759.21
C$3,669.73
List Price:  C$5,137.77
You save:  C$1,468.04
ą¤°ą„13,346.58
List Price:  ą¤°ą„18,685.75
You save:  ą¤°ą„5,339.16
S/375.13
List Price:  S/525.19
You save:  S/150.06
K378.96
List Price:  K530.57
You save:  K151.60
SAR375.09
List Price:  SAR525.14
You save:  SAR150.05
ZK2,519.95
List Price:  ZK3,528.03
You save:  ZK1,008.08
L466.17
List Price:  L652.66
You save:  L186.48
Kč2,369.01
List Price:  Kč3,316.71
You save:  Kč947.70
Ft36,915.02
List Price:  Ft51,682.51
You save:  Ft14,767.48
SEK kr1,089.22
List Price:  SEK kr1,524.96
You save:  SEK kr435.73
ARS$86,913.85
List Price:  ARS$121,682.87
You save:  ARS$34,769.02
Bs690.45
List Price:  Bs966.66
You save:  Bs276.20
COP$391,130.80
List Price:  COP$547,598.77
You save:  COP$156,467.96
ā‚”49,957.95
List Price:  ā‚”69,943.14
You save:  ā‚”19,985.18
L2,461.44
List Price:  L3,446.12
You save:  L984.67
ā‚²737,867.79
List Price:  ā‚²1,033,044.43
You save:  ā‚²295,176.63
$U3,889.78
List Price:  $U5,445.86
You save:  $U1,556.07
zł405.87
List Price:  zł568.23
You save:  zł162.36
Already have an account? Log In

Transcript

If your script will air out, this next line of the script is saying, whatever you input for the starting IP address treated as the first IP, that becomes a variable that the end map is going to use to begin its scan, and know what range of IP addresses to scan for. So we have an echo for the starting IP address. So we're going to need an echo to tell us or to prompt us to type in the last IP address of the range. And again, we want this to be treated as a variable then n map can use and it's going to be called last IP. Next we create a variable called last IP packet, which is equal to the value after the third period in the last IP address. When a user enters the IP address into the last IP, last IP octet is equal to two five We'd then follow that up with an echo command that's going to be commented out.

But it's just as important as any of the other echo commands. So make sure that you get the syntax correct. We next need to be prompted for the port that we want to scan for. To do this, we're going to type in another echo command and echo face, and it's going to be enclosed enter the port to scan for. And again, we want the script to read this information as a variable called port. And now you can see with this end map command that we have added to the script, exactly how those variables are going to be read.

So anything that we input as a first IP, a last IP, or the last IP octet and or the port number is going to be looked at as a variable and end map is then going to input that information regardless of what the numbers are into its script. So that can run the scan. On a side note, when n map is done performing this scan, we want it to go ahead and output the results to a web file or a txt file called web. And we're going to go ahead and do some more cat stuff here now. So if I type in cat, space web, I'm telling it that I want you to output the contents of the web file. But first, I want you to use the grep command to filter it.

And I only want to see the contents of IP addresses that are have the port open that we scan for, and I want that input or that output sent over to another text file called web one. Now, just as we do with our previous script, we can go ahead and get cat to format that output so that it's much more readable and that's what we're doing here. And we're telling cat, I want you to format the contents that you were given for web one. And I want that information, sent over to another file called web two, and sent to the screen. And now that input, or that information that was formatted and put into the web two file can now be read when we type in cat, web two. So we're now ready to run this script.

So make sure your syntax is correct. You got no errors, everybody's got double quotes. Everything's good to go. And now you can hit Ctrl x, you can type in Y for yes, and hit enter. You can use your up arrow to find the command that will run the Port scan.sh and hit Enter. And now it asks you for the starting IP address.

You can do an IF config and you can find out what your network IP is and then you Get the correct IP information for your script. This is the IP address from my network, or the network IP of it for my network. So I'm typing in 192 dot 168 dot 145 dot one, which is the starting it. And when I hit Enter, it's going to ask me for the last IP address. So I've typed in 192 dot 168 dot 145254. Because I don't really care about the broadcast for this network, that's which is two pi five.

I'm gonna go ahead and hit enter. Now it wants to know what port I want to scan for. And you can scan for any port. For instance, if you want to know if FTP is running on your network, well, then you can scan for Port 21. If you want to know if someone's got a web server running on your network, well then you can scan for Port 80. I'll go ahead and just scan for Port 80 just for grins and giggles and we'll see what happens and now starts to scan in just a few moments.

It comes back up and it tells me that it found four holes That is scanned the entire range of the IP addresses in 2.46 seconds. And it tells me that Port 80 is closed just about everywhere. So I don't see a problem with Port 80 running on my network. So the takeaway for this lab is to appreciate how useful bash scripting can be for pen testing and for hacking. We can use these scripts to help reduce our administrative burden of having to scan a large number of IP addresses, and then filter them for specific outputs such as what ports are open on what IP address, so we know that our script, our port scan.sh, generated some txt file, let's go find them. So if I go up here to my files folder, and I go in to the contents of my home directory, you'll see that I have those three files that were generated by the cat and the crap.

Now, this first file is going to have some output. This has got some information about the status of ports and all that good stuff. And I can go ahead and close it out. Now remember, we told it to output any of these IP addresses that had Port 80 running on that. If you didn't have Port 80 running, then there's pretty much nothing to send over to the next text file, which was web one and web two. So when you open these up, yes, they're going to be an empty because there was no IP addresses that were running Port 80.

So just for grins and giggles, let's go back into the script. And this time, we'll run it again. And this time, I'm going to run it across meta splittable to which saw my network. Now, I don't know that many splittable tools on the network, I'm going to scan that same range of IP addresses and we're going to scan for Port 80 and we'll see what happens. So to make sure that I get a clean input, I'm going to go up in here inside of my home directory. I'm going to delete these three output files and just delete those And send it over to the trash.

And now we're going to go back over here to my terminal. Let's go ahead and clear it. And now he's my up arrow. And let's go ahead and run this script one more time. So again, it wants to start an IP address. I'll type that in, I'll hit enter.

Now it wants the last IP address. I'm going to go ahead and hit enter to that. And it wants to port so I can type in Port 80. I'll hit enter, unless you would end map comes up with this time. So this time we got a port 80 that is actually open up on the machine, one dot 30, which is my portable just for grins and giggles. And let's go see what those results look like now.

So again, here's the first output file. We got that done. Then we're going to have that sent over to web one. And there's that information. Now we're going to have it filtered. One more time sent over to web two.

And there you go. So I know that the machine with the IP address of 130 has a port 80 running on it. So imagine that I had 10s of thousands of IP addresses to scan through and look for that last txt file that we created, the web two would have just the IP addresses of the machines that were running party. And I could do the same thing for Port 21. Now, let's say that I've heard that there is a new piece of malware that is exploiting a certain port. I want to know if my network is vulnerable.

Well, what I'm going to do is I'm going to use this script, and I'm going to scan all my IP addresses for that Pacific port that that malware is looking for. That concludes this short video presentation on how we go about using bash scripting to help reduce the administrative burden of having to pen test a large number of IP ranges. If you have any questions or concerns about the video or its content or the lab, please do not hesitate to reach out and contact your instructor. Thank you and I will see you in my next video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.