Created
February 14, 2022 16:14
-
-
Save cicorias/662e4f0773a3ce4241bd632fdb8b8b57 to your computer and use it in GitHub Desktop.
bash to execute series of comands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
shopt -s nocasematch | |
getFileExtension () { | |
case "$1" in | |
"zip" ) | |
echo "zip" | |
;; | |
"bzip2" ) | |
echo "bz2" | |
;; | |
"xz" ) | |
echo "xz" | |
;; | |
"gzip" ) | |
echo "gz" | |
;; | |
"ascii" ) | |
echo "txt" | |
;; | |
esac | |
} | |
processFile () { | |
filename="if" | |
case "$1" in | |
InterestingFile*zip ) | |
fileType=`unzip -p -P Xy2jKjm92Bbp InterestingFile.zip | file -b - | cut -d ' ' -f 1` | |
fileExtension=`getFileExtension ${fileType}` | |
unzip -P Xy2jKjm92Bbp -p InterestingFile.zip > "${filename}.${fileExtension}" | |
echo "${filename}.${fileExtension}" | |
;; | |
if*zip ) | |
fileType=`unzip -p "${filename}.zip" | file -b - | cut -d ' ' -f 1` | |
fileExtension=`getFileExtension ${fileType}` | |
unzip -p "${filename}.zip" > "${filename}.${fileExtension}" | |
echo "${filename}.${fileExtension}" | |
;; | |
if*bz2 ) | |
fileType=`bzip2 -dc "${filename}.bz2" | file -b - | cut -d ' ' -f 1` | |
fileExtension=`getFileExtension ${fileType}` | |
bzip2 -cd "${filename}.bz2" > "${filename}.${fileExtension}" | |
echo "${filename}.${fileExtension}" | |
;; | |
if*gz ) | |
fileType=`gunzip -dc "${filename}.gz" | file -b - | cut -d ' ' -f 1` | |
fileExtension=`getFileExtension ${fileType}` | |
gunzip -cd "${filename}.gz" > "${filename}.${fileExtension}" | |
echo "${filename}.${fileExtension}" | |
;; | |
if*xz ) | |
fileType=`xz -dc "${filename}.xz" | file -b - | cut -d ' ' -f 1` | |
fileExtension=`getFileExtension ${fileType}` | |
xz -cd "${filename}.xz" > "${filename}.${fileExtension}" | |
echo "${filename}.${fileExtension}" | |
;; | |
if*txt ) | |
password=`grep -P level1password.+ "${filename}.txt" | sed -E 's/.+\{(.+)\}/\1/'` | |
echo "Password is ${password}" | |
;; | |
esac | |
} | |
file="InterestingFile.zip" | |
while [[ "$file" != *"password"* ]] | |
do | |
echo "Processing ${file}" | |
file=`processFile $file` | |
# echo $file | |
done | |
echo $file | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment