# Bash scripting

"" everything in between is considered except $ \`\
'' every enclosed characters literally

command substitution user=$(whoami) echo $user

\` backtick discouraged for substitution

arguments (ls -l /var/log) after ls is the arguments $1 $2

echo $? - shows the exist status of last run

Reading user input read answer echo $answer

read -p 'Username: ' username (helps us specify a prompt) read -sp 'Password:' password (-s user input silent)

If, else, Elif statements read -p "what's your age to enter:" value if \[ $value -lt 18> ] then echo "your not allowed to enter" elif \[$value -gt 60 ] then echo "great work!" else echo "Welcome to the club!" fi

Boolean Logical operations \[ AND OR] Pipe | output becomes input in next command user2=kali grep $user2 /etc/passd && echo "$user2 found!" || echo "$user2 not found!"

Loops - For for for-name in do done

example for ip in $(seq 1 10); do echo 10.11.1.$ip done for i {1..10} do echo 10.11.1.$i; done

while \[ ] do done

function function\_name { commands... }

grep "href=" index.html | grep ".domain" | grep -v "[www.\domainname.com](http://www.\domainname.com) | awk -F "http\://" ]{print 2}' | cut -d "/" -f 1

better solution with Regex (regular expression) grep -o '\[^/]\*..domainname.com' index.html | sort -u > output.txt

## convert all domains to ips

for url in $(cat list.txt); do host $url; done | grep "has address" | cut -d " " -f 4 | sort -u

searchsploit afd windows -w -t | grep http | cut -f 2 -d "|"

## download all exploits

for e in $(searchsploit afd windows -w -t | grep http | cut -f 2 -d "|") do exp\_name=$(echo $e | cut -d "/" -f 5) url=$(echo $e | sed 's/exploits/raw/') wget -q --no-check-certificate $url -O $exp\_name done

sudo nmap -A -p80 --open 10.0.0.0/24 -oG nmap-scan\_10.0.0.0-254 cat nmap-scan\_10.0.0.0-254 | grep 80 | grep -v "Nmap" | awk '{print $2}' for ip in $(cat nmap-scan\_10.0.0.0-254 | grep 80 | grep -v "Nmap" | awk '{print $2}': do cutycapt --url=$ip --out=$ip.png; done

cat pngtothml.sh

## simple script to show all png files in a html page

echo "\
" > web.html ls -la \*.png | awk -F : '{ print $1":\
\<IMG SRC=""$1""$2"" width=600>\
"}' >>web.html echo "" >> web.html firefox web.html
