Fun Bash (Faith is the evidence of new birth, not the cause of it.)
GNU Bourne Again shell (Author Stephen Bourne) or Bash is a popular Unix shell that provides
us with a very powerful working environment it also provides a scripting engine which
allows us in writing simple scripts and automating procedures using exiting
Linux tools and commands. Quick automation
of any given task is an essential requirement
of any security professional and also it becomes a necessity to survive in such a fast pace life. we can take real-time like scenarios and learn how to use bash to automate
the task. Follow along with me by just typing below command in Linux just replace the
domain name(website) with your interested one.
It’s time to dive in the sea
#Scenerio 1
Finding all the anywebsite subdomain listed on the index page and find there corresponding IP addresses
wget www.anywebsite.com
more index.html
clear
cat index.html |grep "href="
cat index.html |grep "href=" |cut -d"/" -f3 |more
cat index.html |grep "href=" |cut -d"/" -f3 |grep "anywebsite\.com"|more
#remove extra delimiter
cat index.html |grep "href=" |cut -d"/" -f3 |grep "anywebsite\.com"|cut -d'"' -f1 |more
#remove duplicate with unique option
cat index.html |grep "href=" |cut -d"/" -f3 |grep "anywebsite\.com"|cut -d'"' -f1 |sort -u
#grep
sort out with grep
grep -o '[A-Za-z0-9_\.-]*\.*anywebsite.com' index.html |sort -u
grep -o '[A-Za-z0-9_\.-]*\.*anywebsite.com' index.html |sort -u > anywebsite.txt
clear
cat anywebsite.txt
host www.anywebsite.com
#extract ip address
host www.anywebsite.com | grep "has address" |cut -d" " -f4
#write bash file
clear
vm
nano anywebsite.sh
#!/bin/bash
for url in $(cat anywebsite.txt);do
host $url |grep "has address" |cut -d" " -f4
done
#save
chmod 755 anywebsite.sh
./anywebsite.sh
#Same exercise with a single line
for url in $(grep -o '[A-Za-z0-9_\.-]*\.*cisco.com' index.html |sort -u); do host $url|grep "has address"|cut -d" " -f4;done
Party isn't over yet. Try out other commands along.
#check vpn interface
ifconf tap0
clear
ping 192.168.31.220
man ping
clear
nano ping-loop.sh
#!/bin/bash (bash subhang)
for ip in $(seq 200 210); do
echo 192.168.31.$ip
done
chmod 755 ping-loop.sh
./ping-loop.sh
------------------
#!/bin/bash (bash subhang)
for ip in $(seq 200 210); do
ping -c 1 192.168.31.$ip
done
./ping-loop.sh
----------------------
#!/bin/bash (bash subhang)
for ip in $(seq 200 210); do
ping -c 1 192.168.31.$ip |grep "bytes from" |cut -d" " -f 4|cut -d":" -f1
done
./ping-loop.sh
---------------------------
>run each command parallel to increase the speed
#!/bin/bash (bash subhang)
for ip in $(seq 200 210); do
ping -c 1 192.168.31.$ip |grep "bytes from" |cut -d" " -f 4|cut -d":" -f1 &
done
./ping-loop.sh
Finally... Thank you and be proud of yourself for trying out.
Comments
Post a Comment