1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
#!/bin/bash
# Copyright (C) 2012-2018 Marc Ferland
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
ZIP=$(which zip)
ARCHIVE="archive.zip"
YAZC="../yazc/yazc"
CMD="libtool --mode=execute $YAZC"
if [ ! -f "${ZIP}" ]; then
echo >&2 "error: zip not found!"
exit 1
fi
create_dummy_files() {
for i in $(seq 0 2)
do
dd if=/dev/urandom of=file_${i} bs=${RANDOM} count=1
done
for i in $(seq 3 6)
do
dd if=/dev/zero of=file_${i} bs=${RANDOM} count=1
done
}
cleanup() {
rm -f file_[0-9]
rm -f archive.zip
}
generate_random_string() {
echo $(cat /dev/urandom | tr -dc "${1}" | fold -w ${2} | head -n 1)
}
test_zip_1() {
# zip files with passwords [a-z]
for pw in {a..z}
do
FILES=""
for filen in file_{0..6}
do
FILES="${FILES} ${filen}"
zip -e -P ${pw} ${ARCHIVE} ${FILES}
for threads in $(seq 1 8)
do
for cset in -a -aA -aAn -aAns
do
if ! ${CMD} bruteforce -t${threads} ${cset} -l1 ${ARCHIVE}; then
echo >&2 "yazc failed to find the password (options: -t${threads} ${cset} ${ARCHIVE})"
exit 1
fi
done
done
rm ${ARCHIVE}
done
done
}
test_zip_2() {
# zip files with passwords [a-z][a-z]
for pw in {a..z}{a..z}
do
FILES=""
for filen in file_{0..6}
do
FILES="${FILES} ${filen}"
zip -e -P ${pw} ${ARCHIVE} ${FILES}
for threads in $(seq 1 8)
do
for cset in -a -aA -aAn -aAns
do
if ! ${CMD} bruteforce -t${threads} ${cset} -l2 ${ARCHIVE}; then
echo >&2 "yazc failed to find the password (options: -t${threads} ${cset} ${ARCHIVE})"
exit 1
fi
done
done
rm ${ARCHIVE}
done
done
}
test_zip_6() {
# zip files with passwords [a-z]
count=0
while [ $count -lt 10 ]; do
pw="$(generate_random_string a-z 6)"
FILES="file_0 file_1 file_2 file_3"
zip -e -P ${pw} ${ARCHIVE} ${FILES} >/dev/null
echo "Testing password: ${pw}"
if ! ${CMD} bruteforce -t8 -a ${ARCHIVE}; then
echo >&2 "yazc failed to find the password (options: -t8 -a ${ARCHIVE}, password: ${pw})"
exit 1
fi
rm ${ARCHIVE}
count=$((count+1))
done
}
cleanup
create_dummy_files
test_zip_1
test_zip_2
test_zip_6
cleanup
exit 0
|