This repository has been archived by the owner on Sep 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 105
/
unpack.sh
121 lines (114 loc) · 1.95 KB
/
unpack.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
# Unpack Archive Beta
delete=0
cur=`dirname $0`
dst="$2"
trypassds(){
dir=`dirname "$1"`
name=`basename "$1"`
if [ "$dst" ]; then
dir="$dir/$dst"
fi
a=`eval echo "$2" | tr -d '\r'`
echo "Try Passwd:$a"
files=`7za l "$1" -p"$a"|grep -w "\.\.\.\.\."|awk -F" " '{print $6}'`
7za x "$1" -o"${dir}" -y -p"$a"
if [ $? = 0 ] ;then
echo "Unpack $name Success"
return 0
else
cd $dir
for line in $files
do
rm -rf ./$line
done
return 1
fi
}
unpackonefile(){
dir=`dirname "$1"`
name=`basename "$1"`
echo "Unpack:$name Dir:$dir"
trypassds "$1"
if [ $? = 0 ];then
echo "Unpack $name Success"
if [ $delete = 1 ];then
rm "$1"
echo "Delete $1"
fi
return 0
else
for line in `cat /app/passwds.txt`
do
trypassds "$1" "$line"
if [ $? = 0 ];then
echo "Unpack $name Success by Brute Force!"
if [ $delete = 1 ];then
rm "$1"
echo "Delete $1"
fi
return 0
fi
done
echo "Unpack $name Failed"
dir=`dirname "$1"`
if [ "$dst" ]; then
dir="$dir"/"$dst"
if [ ! -d "$dst" ];then
mkdir "$dir"
fi
mv "$1" "$dir"
fi
return 1
fi
}
unpackfile(){
name=`basename "$1"`
extision="${name##*.}"
if [ "$extision" == "rar" ] || [ "$extision" == "zip" ] || [ "$extision" == "7z" ]|| [ "$extision" == "gz" ]|| [ "$extision" == "tar" ];then
echo "extsion $extision"
unpackonefile "$1"
return 1
else
dir=`dirname "$1"`
if [ "$dst" ]; then
dir="$dir"/"$dst"
if [ ! -d "$dst" ];then
mkdir "$dir"
fi
mv "$1" "$dir"
fi
return -1
fi
}
unpackfolder(){
for file in $1/*
do
if [ -d "$file" ]
then
echo "folder :$file"
unpackfolder "$file"
elif [ -f "$file" ]
then
echo "file:$file"
unpackfile "$file"
else
echo "Error File"
fi
done
}
unpackall(){
if [ -d "$1" ]
then
echo "diectory"
unpackfolder "$1"
elif [ -f "$1" ]
then
echo "file"
unpackfile "$1"
else
echo "No Such File Or Dir"
fi
}
echo "Starting Unpack"
unpackall "$1"