diff --git a/usr/bin/unzip_bruteforce b/usr/bin/unzip_bruteforce index 050c09c..8e33f57 100755 --- a/usr/bin/unzip_bruteforce +++ b/usr/bin/unzip_bruteforce @@ -1,27 +1,32 @@ -#!/usr/bin/bash +#!/usr/bin/env bash -if [ "$#" -lt 1 ] || [ "$#" -gt 3 ]; then - echo "Usage: $0 list file.zip" +set -euo pipefail + +LIST=${1:-list} +FILE=${2:-} + +usage() { + echo "usage: $0 [wordlist] " + echo "default wordlist: ./list" exit 1 -fi +} -LIST=$1 -FILE=$2 -COUNT=$(mktemp) -echo 0 > "$COUNT" -export FILE COUNT +[[ -z "$FILE" ]] && usage +[[ ! -f "$LIST" ]] && { echo "missing wordlist: $LIST"; exit 1; } +[[ ! -f "$FILE" ]] && { echo "missing zip: $FILE"; exit 1; } -xargs -a "$LIST" -P4 -I{} bash -c ' - line="$1" +i=0 - # atomic-ish counter - n=$(($(<"$COUNT")+1)) - echo "$n" > "$COUNT" +while IFS= read -r line; do + ((i++)) - ((n % 1000 == 0)) && echo "$n tries..." + (( i % 1000 == 0 )) && echo "$i tried..." if unzip -P "$line" -t "$FILE" >/dev/null 2>&1; then echo "FOUND: $line" - killall xargs 2>/dev/null + exit 0 fi -' _ {} +done < "$LIST" + +echo "not found" +exit 1