In this series, we will discuss about some bash script examples that can be used on penetration testing, in real life or kali linux lab environments. We will proceed from easy to hard, therefore those examples will help you to improve yourself step by step. Let’s start with a simple bash script.
First of all, in the bash script, we will create a host ip finder script that is used to find the ip address of multiple domains in the same time. Before start to writing the script, lets see how we can find the ip address of a domain. We can use “host” command for this.
root@kali:~# host www.cyberrsec.com
www.cyberrsec.com is an alias for cyberrsec.com.
cyberrsec.com has address 220.127.116.11
As you see the output above, we have found public ip address of my website by using the “host” command. However we need to ip address of website only. We have to cut off those unnecessary fields by using command that I wrote below.
root@kali:~# host www.cyberrsec.com | grep “has address” | cut -d ” ” -f4
Yes, this output seems good for us. We have use “grep” and “cut” command for clear to output. We will use these commands in the script.
Before we start, we need a host list that includes domains. As I mentioned before, when the script run, it will list ip addresses of domains. We are going to use nano text editor to tell our script which domains would be resolved.
Now, we can write the script. We will use “nano” text editor again.
root@kali:~# nano host-ip-finder.sh
The script is ready. We have to change access permissions now.
root@kali:~# chmod 755 host-ip-finder.sh
We have finished, let’s try to run script.
Yes, we succeed. We have found ip addresses of domains. If you would like to use the script with different host files, you should define a dynamic object in the script such as below.
Let’s try again
Nice. Now we have got the script that we can use to find ip address of multiple domains in same time.
See you on next script.