Bash
execute command for each line in file
cat IntrudersXSS.txt | while read in; do echo "$in" > $i.txt $((i=i+1)) ; done
for ip in $(cat ips.txt); do nmap $ip; done
grep IPs from file grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' ips_input.txt | sort | uniq > ips_output.txt
sed – replace echo "I am Mr.Cat" | sed 's/Cat/Robot/'
cut echo "root,lorem,password123,ipsum,/root" | cut -d"," -f1,3,5
awk cat /etc/passwd | awk -F: '{printf "USER--> %s\t HOME--> %s\n", $1, $6}'
piping cat /etc/passwd | grep '/bin/false' | cut -d":" -f 1,6 | awk -F: '{printf "user: %s home:%s\n", $1, $2}'
cat /etc/passwd | grep '/bin/false' | awk -F: '{printf "user: %s home:%s\n", $1, $6}'
filter out some stuff cat feroxbuster_80.txt | grep -v -E '.js|.css|.gif|.svg|.png|.jpg|.ttf|.eot|.woff|.md'
split by space, take 6 columns, sort, unit, filter cat feroxbuster_80.txt | awk '{print $6}' | sort | uniq | grep -v -E '.js|.css|.gif|.svg|.png|.jpg|.ttf|.eot|.woff|.md'
wipe all whitespace including newlines from file cat file.txt | tr -d " \t\n\r"
Restricted bash
export PATH=/usr/bin:$PATH
export PATH=/bin:$PATH
basic
alias
alias ..='cd ..'
alias ll='ls -la'
shebang #! make script executable chmod +x hack.sh
./hack.sh
print variable TARGET=10.10.99.99
echo $TARGET
arguments #!/bin/bash
echo "Arg-1 $1 arg-2 $2"
arguments #!/bin/bash
echo "What is your anme ?";
read name;
echo "Your name is $name";
assign output #!/bin/bash
user=$(whoami)
echo $user kali
If (string) #!/bin/bash
echo "Select scan XSS/SQLi";
read -p "Attack name:" action
if [ $action == 'XSS' ]; then
echo "XSS attack...";
fi
If (number) #!/bin/bash
echo "Number of request";
read -p "Nr:" action
if [ $action -lt 10 ]; then
echo "< 10";
fi
if [ $action -eq 10 ]; then
echo "== 10";
fi
if [ $action -gt 10 ]; then
echo "> 10";
fi
If-Else #!/bin/bash
echo "Number of request";
read -p "Nr:" action
if [ $action -eq 10 ]; then
echo "OK";
else
echo "No OK"
fi
If-ElseIf-Else #!/bin/bash
echo "Number of request";
read -p "Nr:" action
if [ $action -eq 10 ]; then
echo "OK.1";
elif [ $action -eq 20 ]; then
echo "OK.2";
else
echo "No OK"
fi
Logical Operations grep 'kali' /etc/passwd && echo "User exist"
grep 'john' /etc/passwd || echo "User NOT exist"
[ $(whoami) == 'kali' ] && echo "Not root user"
[ $(whoami) == 'root' ] && echo "Root user"
[ $(whoami) != 'root' ] || echo "Ah NOT ROOT"
For #!/bin/bash
for ip in $(seq 1 10); do
echo 10.11.1.$ip;
done
#!/bin/bash
for ip in {1..10}; do
echo 10.11.1.$ip;
done
While #!/bin/bash
index=1
while [ $index -le 5 ]
do
echo "10.10.10$index"
index=$(( $index + 1 ))
done
Function #!/bin/bash
banner(){
echo "Super HaCkEr Engine";
}
banner;
banner;
compare download