Shell Scripting Overview

2 minute read

Description:

Shell scripting is the equivalent of using batch scripts in Windows, but for Linux. To begin, you should get familiar with Linux commands.

Try visiting here, here, andΒ here then moving on to further readings. Try reading this for more actual scripting after learning the basics. My last couple jobs have been primarily Windows networks so I haven’t gotten too far into Linux beyond simple bash scripts.

Most scripts follow these rules

Step 1: Always start with #!/bin/bash

Step 2: Script code

Step 3: End with β€œdone”

Step 4: chmod 755 (script filename)

Step 5: ./(script filename)

Step 6: If the script references any files like somefilename.txt, make sure they are in the same directory

6a. To create a text file:
vi (filename.extension)
Type text
Keyboard shortcut: Ctrl + O
Keyboard key: Enter
Keyboard shortcut: Ctrl + X

6b: To create a file using vi:
vi (filename.extension)
Keyboard shortcut: i #this is insert mode, type your text in here.
Keyboard shortcut: ESC #tap this once to enter command mode.
Keyboard shortcut: 😑 #this saves and exits. use :q to quit without saving changes. Use :x! to force changes.

————————————————————————————————————————–
**
** DNS enum

#!/bin/bash
for url in $(cat cisco.txt) ;do
host $url | grep "has address" | cut -d" " -f4
done

Cisco.txt:
www.cisco.com

Ping sweeper

#!/bin/bash
for ip in $(seq 200 210) ; do
echo 192.168.31.$ip |grep "bytes from" | cut -d":" -f1 & #adding the ampersand allows the pings to run in parrallel. Much faster response time
done

Forward zone lookup

#!/bin/bash
for name in $(cat list.txt) ;do
host $name.megacorpone.com|grep "has address" | cut -d" " -f1,4
done

list.txt:
www
ftp
mail
owa
proxy
router
admin
www2
firewall
mx
pop3

Reverse zone lookup

#!/bin/bash
for ip in $(seq 72 91) ;do
host 38.100.193.$ip |grep "megacorp" | cut -d" " -f1,5
done

Zone transfer script

#You run by ./zonetransfer.sh megacorpone.com or any other domain name.

#!/bin/bash

if [ -z "$1" ]; then
echo "[*] Simple Zone Transfer Script"
echo "[*] Usage : $0 "
exit 0
fi

for server in $(host -t ns $1 |cut -d" " -f4) ;do
host -l $1 $server |grep "has address"
done

Verify email addresses against a SMTP server using Bash

Script:

Β 

#!/bin/bash
for user in $(cat list.txt) ;do
echo VRFY $user | nc -nv -w 192.168.15.215 25 2>/dev/null | grep ^"250";

list.txt: Usually from theharvester or info gathering stage.
root
backup
bob
dick
david
harry
apache
igor
ron
mike
joseph