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
ā‚¬96.05
List Price:  ā‚¬134.47
You save:  ā‚¬38.42
Ā£78.28
List Price:  Ā£109.60
You save:  Ā£31.31
CA$143.28
List Price:  CA$200.59
You save:  CA$57.31
A$160.13
List Price:  A$224.20
You save:  A$64.06
S$135.03
List Price:  S$189.05
You save:  S$54.02
HK$777
List Price:  HK$1,087.84
You save:  HK$310.83
CHF 88.49
List Price:  CHF 123.89
You save:  CHF 35.40
NOK kr1,126.80
List Price:  NOK kr1,577.57
You save:  NOK kr450.76
DKK kr717.22
List Price:  DKK kr1,004.14
You save:  DKK kr286.92
NZ$176.87
List Price:  NZ$247.63
You save:  NZ$70.75
ŲÆ.Ų„367.26
List Price:  ŲÆ.Ų„514.17
You save:  ŲÆ.Ų„146.91
ą§³11,929.84
List Price:  ą§³16,702.26
You save:  ą§³4,772.41
ā‚¹8,538.94
List Price:  ā‚¹11,954.85
You save:  ā‚¹3,415.91
RM448.65
List Price:  RM628.13
You save:  RM179.48
ā‚¦154,544.52
List Price:  ā‚¦216,368.52
You save:  ā‚¦61,823.99
ā‚Ø27,792.76
List Price:  ā‚Ø38,910.97
You save:  ā‚Ø11,118.21
ąøæ3,416.65
List Price:  ąøæ4,783.45
You save:  ąøæ1,366.80
ā‚ŗ3,519.17
List Price:  ā‚ŗ4,926.99
You save:  ā‚ŗ1,407.81
B$637.56
List Price:  B$892.61
You save:  B$255.05
R1,874.85
List Price:  R2,624.87
You save:  R750.01
Š›Š²188
List Price:  Š›Š²263.20
You save:  Š›Š²75.20
ā‚©145,711.39
List Price:  ā‚©204,001.77
You save:  ā‚©58,290.38
ā‚Ŗ364.90
List Price:  ā‚Ŗ510.87
You save:  ā‚Ŗ145.97
ā‚±5,865.41
List Price:  ā‚±8,211.81
You save:  ā‚±2,346.40
Ā„15,715.92
List Price:  Ā„22,002.92
You save:  Ā„6,286.99
MX$2,016.21
List Price:  MX$2,822.78
You save:  MX$806.56
QR363.08
List Price:  QR508.32
You save:  QR145.24
P1,386.50
List Price:  P1,941.15
You save:  P554.65
KSh12,902.70
List Price:  KSh18,064.30
You save:  KSh5,161.60
EĀ£5,082.90
List Price:  EĀ£7,116.27
You save:  EĀ£2,033.36
į‰„įˆ­12,710.92
List Price:  į‰„įˆ­17,795.80
You save:  į‰„įˆ­5,084.87
Kz91,190.88
List Price:  Kz127,670.88
You save:  Kz36,480
CLP$98,919.10
List Price:  CLP$138,490.70
You save:  CLP$39,571.60
CNĀ„729.82
List Price:  CNĀ„1,021.78
You save:  CNĀ„291.96
RD$6,081.12
List Price:  RD$8,513.82
You save:  RD$2,432.69
DA13,508.78
List Price:  DA18,912.83
You save:  DA5,404.05
FJ$231.84
List Price:  FJ$324.58
You save:  FJ$92.74
Q768.97
List Price:  Q1,076.59
You save:  Q307.62
GY$20,886.35
List Price:  GY$29,241.72
You save:  GY$8,355.37
ISK kr13,953.60
List Price:  ISK kr19,535.60
You save:  ISK kr5,582
DH1,006.73
List Price:  DH1,409.47
You save:  DH402.73
L1,841.91
List Price:  L2,578.75
You save:  L736.83
Š“ŠµŠ½5,908.74
List Price:  Š“ŠµŠ½8,272.47
You save:  Š“ŠµŠ½2,363.73
MOP$798.63
List Price:  MOP$1,118.11
You save:  MOP$319.48
N$1,856.28
List Price:  N$2,598.86
You save:  N$742.58
C$3,673.45
List Price:  C$5,142.98
You save:  C$1,469.52
ą¤°ą„13,596.38
List Price:  ą¤°ą„19,035.48
You save:  ą¤°ą„5,439.09
S/371.74
List Price:  S/520.45
You save:  S/148.71
K405.18
List Price:  K567.27
You save:  K162.09
SAR375.47
List Price:  SAR525.68
You save:  SAR150.20
ZK2,762.82
List Price:  ZK3,868.06
You save:  ZK1,105.23
L478.38
List Price:  L669.75
You save:  L191.37
Kč2,417.95
List Price:  Kč3,385.23
You save:  Kč967.27
Ft39,478.73
List Price:  Ft55,271.81
You save:  Ft15,793.07
SEK kr1,088.11
List Price:  SEK kr1,523.40
You save:  SEK kr435.29
ARS$102,698.50
List Price:  ARS$143,782.01
You save:  ARS$41,083.50
Bs689.84
List Price:  Bs965.80
You save:  Bs275.96
COP$441,236.66
List Price:  COP$617,748.98
You save:  COP$176,512.31
ā‚”50,688.88
List Price:  ā‚”70,966.47
You save:  ā‚”20,277.58
L2,536.46
List Price:  L3,551.14
You save:  L1,014.68
ā‚²778,577.57
List Price:  ā‚²1,090,039.75
You save:  ā‚²311,462.17
$U4,443.67
List Price:  $U6,221.32
You save:  $U1,777.64
zł409.39
List Price:  zł573.17
You save:  zł163.77
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.