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
ā‚¬95.97
List Price:  ā‚¬134.37
You save:  ā‚¬38.39
Ā£79.80
List Price:  Ā£111.73
You save:  Ā£31.92
CA$139.82
List Price:  CA$195.75
You save:  CA$55.93
A$153.75
List Price:  A$215.26
You save:  A$61.51
S$134.64
List Price:  S$188.51
You save:  S$53.86
HK$778.36
List Price:  HK$1,089.74
You save:  HK$311.37
CHF 89.34
List Price:  CHF 125.09
You save:  CHF 35.74
NOK kr1,107.14
List Price:  NOK kr1,550.05
You save:  NOK kr442.90
DKK kr715.75
List Price:  DKK kr1,002.09
You save:  DKK kr286.33
NZ$171.37
List Price:  NZ$239.93
You save:  NZ$68.55
ŲÆ.Ų„367.26
List Price:  ŲÆ.Ų„514.18
You save:  ŲÆ.Ų„146.92
ą§³11,945.63
List Price:  ą§³16,724.36
You save:  ą§³4,778.73
ā‚¹8,442.99
List Price:  ā‚¹11,820.52
You save:  ā‚¹3,377.53
RM446.75
List Price:  RM625.47
You save:  RM178.72
ā‚¦169,271.38
List Price:  ā‚¦236,986.70
You save:  ā‚¦67,715.32
ā‚Ø27,777.22
List Price:  ā‚Ø38,889.22
You save:  ā‚Ø11,112
ąøæ3,446.26
List Price:  ąøæ4,824.91
You save:  ąøæ1,378.64
ā‚ŗ3,454.90
List Price:  ā‚ŗ4,837
You save:  ā‚ŗ1,382.10
B$580.04
List Price:  B$812.08
You save:  B$232.04
R1,811.35
List Price:  R2,535.96
You save:  R724.61
Š›Š²187.69
List Price:  Š›Š²262.77
You save:  Š›Š²75.08
ā‚©140,436.95
List Price:  ā‚©196,617.35
You save:  ā‚©56,180.40
ā‚Ŗ370.16
List Price:  ā‚Ŗ518.24
You save:  ā‚Ŗ148.08
ā‚±5,893.31
List Price:  ā‚±8,250.87
You save:  ā‚±2,357.56
Ā„15,475.45
List Price:  Ā„21,666.25
You save:  Ā„6,190.80
MX$2,042.64
List Price:  MX$2,859.78
You save:  MX$817.14
QR364.56
List Price:  QR510.41
You save:  QR145.84
P1,367.06
List Price:  P1,913.94
You save:  P546.88
KSh12,945.58
List Price:  KSh18,124.33
You save:  KSh5,178.75
EĀ£4,964.52
List Price:  EĀ£6,950.52
You save:  EĀ£1,986
į‰„įˆ­12,237.67
List Price:  į‰„įˆ­17,133.23
You save:  į‰„įˆ­4,895.55
Kz91,290.87
List Price:  Kz127,810.87
You save:  Kz36,520
CLP$98,658.13
List Price:  CLP$138,125.33
You save:  CLP$39,467.20
CNĀ„724.22
List Price:  CNĀ„1,013.94
You save:  CNĀ„289.72
RD$6,024.63
List Price:  RD$8,434.73
You save:  RD$2,410.09
DA13,426.15
List Price:  DA18,797.15
You save:  DA5,371
FJ$227.57
List Price:  FJ$318.61
You save:  FJ$91.03
Q771.64
List Price:  Q1,080.33
You save:  Q308.69
GY$20,913.50
List Price:  GY$29,279.73
You save:  GY$8,366.23
ISK kr13,966.60
List Price:  ISK kr19,553.80
You save:  ISK kr5,587.20
DH1,005.63
List Price:  DH1,407.93
You save:  DH402.29
L1,821.98
List Price:  L2,550.85
You save:  L728.86
Š“ŠµŠ½5,904.20
List Price:  Š“ŠµŠ½8,266.12
You save:  Š“ŠµŠ½2,361.91
MOP$801.48
List Price:  MOP$1,122.11
You save:  MOP$320.62
N$1,812.81
List Price:  N$2,538.01
You save:  N$725.20
C$3,678.31
List Price:  C$5,149.78
You save:  C$1,471.47
ą¤°ą„13,500.25
List Price:  ą¤°ą„18,900.90
You save:  ą¤°ą„5,400.64
S/379.05
List Price:  S/530.69
You save:  S/151.63
K402.47
List Price:  K563.48
You save:  K161
SAR375.40
List Price:  SAR525.58
You save:  SAR150.17
ZK2,764.29
List Price:  ZK3,870.12
You save:  ZK1,105.82
L477.77
List Price:  L668.90
You save:  L191.12
Kč2,432.37
List Price:  Kč3,405.42
You save:  Kč973.04
Ft39,496.05
List Price:  Ft55,296.05
You save:  Ft15,800
SEK kr1,103.50
List Price:  SEK kr1,544.95
You save:  SEK kr441.44
ARS$100,374.93
List Price:  ARS$140,528.92
You save:  ARS$40,153.99
Bs690.75
List Price:  Bs967.07
You save:  Bs276.32
COP$438,931.09
List Price:  COP$614,521.09
You save:  COP$175,589.99
ā‚”50,918.63
List Price:  ā‚”71,288.12
You save:  ā‚”20,369.49
L2,526.16
List Price:  L3,536.73
You save:  L1,010.56
ā‚²780,388.98
List Price:  ā‚²1,092,575.79
You save:  ā‚²312,186.81
$U4,261.82
List Price:  $U5,966.72
You save:  $U1,704.90
zł416.31
List Price:  zł582.85
You save:  zł166.54
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.