-
Notifications
You must be signed in to change notification settings - Fork 0
/
extractpaswd.sh
executable file
·103 lines (87 loc) · 3.18 KB
/
extractpaswd.sh
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
#!/bin/bash -e
export LC_ALL="C"
if [[ "$2" == "-debug" ]] || [[ "$3" == "-debug" ]]; then
DEBUGMODE=1
if [[ "$2" == "-debug" ]]; then
# dirty hack to fix assigning TARGETDIR
# TODO: add proper params handling
params=( "$@" );
unset "params[1]";
set -- "${params[@]}";
fi
echo "DEBUGMODE ON"
fi
if [[ -z "$1" ]]
then
echo "Dumpfile password extractor v.1.3"
echo "Usage: extractpaswd source_file
extractpaswd source_file <target_directory>";
exit 1;
fi
if [[ ! -f "$1" ]]
then
echo "Given input is not a regular file"
exit 1;
fi
if [[ "$2" ]] && [[ $DEBUGMODE == 0 ]] && [[ ! -d "$2" ]]
then
echo "Given path is not a valid directory"
exit 1;
fi
INFILE="$1"
INFILENAME=$(basename "$INFILE")
INFILEDIRNAME=$(dirname "$INFILE")
TARGETDIR=${2:-"$INFILEDIRNAME"}
TARGETDIR=${TARGETDIR%%\/}"/" #normalise TARGETDIR
OUTFILE="$TARGETDIR${INFILENAME%%.*}-out.txt"
REMAINSFILE="$TARGETDIR${INFILENAME%%.*}-out-remains.txt"
WEAKFILE="$TARGETDIR${INFILENAME%%.*}-out-weak-"
SEPARATORS=( "\|" ":" "\;" )
PATTERN="[[:print:]]+@+[[:print:]]+";
DEBUGMODE=${DEBUGMODE:-0}
if hash pv 2>/dev/null; then
COMMAND="pv";
else
echo "Without 'pv' you will not be able to see the progress.
You can install it with homebrew - 'brew install pv' if you are on macOS,
or 'sudo apt-get install pv' on Debian/Ubuntu.
For now we're gonna use 'cat' instead.";
COMMAND="cat";
fi
if [[ $DEBUGMODE == 1 ]]; then
echo "###########";
locale
echo "INFILE: $INFILE";
echo "OUTFILE: $OUTFILE";
echo "INFILENAME: $INFILENAME";
echo "INFILEDIRNAME: $INFILEDIRNAME";
echo "TARGETDIR: $TARGETDIR";
echo "REMAINSFILE: $REMAINSFILE";
echo "WEAKFILE: $WEAKFILE";
echo "${SEPARATORS[*]}";
echo "$COMMAND";
echo "###########";
fi
echo "[$(date '+%H:%M:%S')] Starting parsing file '$INFILE'"
echo "[$(date '+%H:%M:%S')] Parsing lines with '${SEPARATORS[*]}' separators"
"$COMMAND" "$INFILE" | perl -ne "print if s/(${PATTERN}[:])|(${PATTERN}[;])|(${PATTERN}[|])//g" > "$OUTFILE";
#extract remaining lines for further proccessing
echo "[$(date '+%H:%M:%S')] Extracting remaining lines for further proccessing"
"$COMMAND" "$INFILE" | perl -ne "print if not s/(${PATTERN}[:])|(${PATTERN}[;])|(${PATTERN}[|])//g" > "$REMAINSFILE"
#following secions extract flaky, weak patterns, possible crap
#
## reversed pattern "pass:email"
echo "[$(date '+%H:%M:%S')] Extracting reversed pattern 'pass:email'"
"$COMMAND" "$REMAINSFILE" | perl -ne "print if s/([:]${PATTERN})//" > "$WEAKFILE""reversed-patt.txt"
cp "$WEAKFILE""reversed-patt.txt" "$TARGETDIR""tmp.txt"
#
## email-ish pattern, allows illegal characters, missing parts
echo "[$(date '+%H:%M:%S')] Extracting weak candidates"
"$COMMAND" "$REMAINSFILE" | perl -ne 'print if s/([[:print:]]+@+([:]))//' > "$WEAKFILE""weak-cand.txt"
cat "$WEAKFILE""weak-cand.txt" >> "$TARGETDIR""tmp.txt"
echo "[$(date '+%H:%M:%S')] Preparing file with rejected candidates (for manual check)"
"$COMMAND" "$REMAINSFILE" | grep -vFf "$TARGETDIR""tmp.txt" > "$REMAINSFILE"".manual-check"
echo "[$(date '+%H:%M:%S')] Cleaning up temporary files"
echo "[$(date '+%H:%M:%S')] ""$TARGETDIR""tmp.txt"
rm "$TARGETDIR""tmp.txt"
echo "[$(date '+%H:%M:%S')] Finished extracting"