-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrute_W_H_forCRC.sh
executable file
·295 lines (284 loc) · 8.5 KB
/
brute_W_H_forCRC.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/bin/bash
#run brute_W_H_forCRC.sh <option> file.png"
#options :
#-h --min-height : set the min value for height | default value : 1
#-w --min-width : set the min value for width | default value : 1
#-H --max-height : set the max value for height | default value : 666
#-W --max-width : set the max value for width | default value : 666
##work type [default all] :
#-oh --only-height : bruteforce only the height
#-ow --only-width : bruteforce only the width
#-wh --width-height : bruteforce the width and the height. SLOW
#-a --all : bruteforce the width then the height then the width and the height. VERY SLOW
#-d --debug : print all usefull variables
#info utile de l'ente IHDR :
#Width: 4 bytes - 0x00000780 (1920)
#Height: 4 bytes - 0x00000342 (834)
#Bit depth: 1 byte - 0x04
#Color type: 1 byte - 0x03
#Compression method: 1 byte - 0x00
#Filter method: 1 byte - 0x00
#Interlace method: 1 byte - 0x00
#
#${chaine:position:longueur}
if [[ -z "$1" ]] ; then
echo "run brute_W_H_forCRC.sh <option> file.png"
echo "options :"
echo "-h --min-height : set the min value for height | default value : 1"
echo "-w --min-width : set the min value for width | default value : 1"
echo "-H --max-height : set the max value for height | default value : 666"
echo "-W --max-width : set the max value for width | default value : 666"
echo "#work type [default all] :"
echo "-oh --only-height : bruteforce only the height"
echo "-ow --only-width : bruteforce only the width"
echo "-wh --width-height : bruteforce the width and the height. SLOW"
echo "-a --all : bruteforce the width then the height then the width and the height. VERY SLOW"
echo "-d --debug : print all usefull variables"
exit 0
fi
while [[ -n "$1" ]]
do
case $1 in
-h|--min-height)
if [[ "$2" != -* && "$2" != "" ]] ; then
minheight=$2
else
echo "syntax error"
exit 2
fi
shift 2
;;
-w|--min-width)
if [[ "$2" != -* && "$2" != "" ]] ; then
minwidth=$2
else
echo "syntax error"
exit 2
fi
shift 2
;;
-H|--max-height)
if [[ "$2" != -* && "$2" != "" ]] ; then
maxheight=$2
else
echo "syntax error"
exit 2
fi
shift 2
;;
-W|--max-width)
if [[ "$2" != -* && "$2" != "" ]] ; then
maxwidth=$2
else
echo "syntax error"
exit 2
fi
shift 2
;;
-a|--all)
work=all
shift
;;
-ow|--only-width)
work=width
shift 1
;;
-oh|--only-height)
work=height
shift 1
;;
-wh|--width-height)
work=width-height
shift 1
;;
-d|--debug)
work=debug
shift 1
;;
--help)
echo "run brute_W_H_forCRC.sh <option> file.png"
echo "options :"
echo "-h --min-height : set the min value for height | default value : 1"
echo "-w --min-width : set the min value for width | default value : 1"
echo "-H --max-height : set the max value for height | default value : 666"
echo "-W --max-width : set the max value for width | default value : 666"
echo "#work type [default all] :"
echo "-oh --only-height : bruteforce only the height"
echo "-ow --only-width : bruteforce only the width"
echo "-wh --width-height : bruteforce the width and the height. SLOW"
echo "-a --all : bruteforce the width then the height then the width and the height. VERY SLOW"
echo "-d --debug : print all usefull variables"
exit 0
;;
*)
fichier="$1"
if [[ ! -f "$fichier" ]] ; then
echo "Moukrènes à la glaviouse"
exit 2
fi
shift
;;
esac
done
## Controle qualité des arguments
if [[ -z "$maxheight" ]] ; then
maxheight=6666
fi
if [[ -z "$minheight" ]] ; then
minheight=1
fi
if [[ -z "$minwidth" ]] ; then
minwidth=1
fi
if [[ -z "$maxwidth" ]] ; then
maxwidth=6666
fi
if [[ -z "$work" ]] ; then
work=debug
fi
if [[ "$maxheight" != +([[:digit:]]) || "$minheight" != +([[:digit:]]) || "$minwidth" != +([[:digit:]]) || "$maxwidth" != +([[:digit:]]) ]] ; then
echo "Moukrènes à la glaviouse"
echo "##########################################################################"
echo "run brute_W_H_forCRC.sh <option> file.png"
echo "options :"
echo "-h --min-height : set the min value for height | default value : 1"
echo "-w --min-width : set the min value for width | default value : 1"
echo "-H --max-height : set the max value for height | default value : 6666"
echo "-W --max-width : set the max value for width | default value : 6666"
echo "#work type [default all] :"
echo "-oh --only-height : bruteforce only the height"
echo "-ow --only-width : bruteforce only the width"
echo "-wh --width-height : bruteforce the width and the height. SLOW"
echo "-a --all : bruteforce the width then the height then the width and the height. VERY SLOW"
echo "-d --debug : print all usefull variables"
exit 2
fi
if [[ "$maxheight" -lt "$minheight" || "$maxwidth" -lt "$minwidth" ]] ; then
echo "Moukrènes à la glaviouse"
echo "maxheight < minheight or maxwidth < minwidth"
echo "max height : $maxheight"
echo "min height : $minheight"
echo "max width : $maxwidth"
echo "min width : $minwidth"
exit 2
fi
if [[ -z "$fichier" ]] ; then
echo "Moukrènes à la glaviouse"
exit 2
fi
## définition des variables :
fichier_hexa=$(xxd -p ${fichier} | tr -d "\n")
IHDR=$(echo ${fichier_hexa} | head -2 | tr -d "\n" | sed -E 's/89504e470d0a1a0a.{8}(.{42}).*/\1/')
head_IHDR="${IHDR:0:8}"
width_IHDR="${IHDR:8:8}"
height_IHDR="${IHDR:16:8}"
info_IHDR="${IHDR:24:10}"
crc_IHDR="${IHDR:34}"
rm RESULT.png 2> /dev/null
## déclaration des Fonctions
#fonction width only
funk_width() {
for width in $(seq $minwidth $maxwidth) ; do
width=$(printf '%x\n' $width)
for (( i=$((8 - ${#width})); i>=1; i-=1 )) ; do
buff="${buff}0"
done
new_width=$buff$width
new_crc=$(printf "$head_IHDR$buff$width$height_IHDR$info_IHDR" | xxd -r -p | rhash --simple - | awk '{print $1}')
if [[ "$new_crc" = "$crc_IHDR" ]] ; then
echo "$fichier_hexa" | sed -E 's/(.{32}).{8}(.*$)/\1'"$new_width"'\2/' | xxd -r -p > RESULT.png
echo "Width Recover, check RESULT.png file"
exit 0
fi
unset buff
done
}
#fonction height only
funk_height() {
for height in $(seq $minheight $maxheight) ; do
height=$(printf '%x\n' $height)
for (( i=$((8 - ${#height})); i>=1; i-=1 )) ; do
buff="${buff}0"
done
new_height=$buff$height
new_crc=$(printf "$head_IHDR$width_IHDR$buff$height$info_IHDR" | xxd -r -p | rhash --simple - | awk '{print $1}')
if [[ "$new_crc" = "$crc_IHDR" ]] ; then
echo "$fichier_hexa" | sed -E 's/(.{40}).{8}(.*$)/\1'"$new_height"'\2/' | xxd -r -p > RESULT.png
echo "height Recover, check RESULT.png file"
exit 0
fi
unset buff
done
}
#fonction width and height
funk_all() {
for valeurh in $(seq $minheight $maxheight) ; do
height=$(printf '%x\n' $valeurh)
for (( i=$((8 - ${#height})); i>=1; i-=1 )) ; do
buffh="${buffh}0"
done
new_height=$buffh$height
unset buffh
for valeurw in $(seq $minwidth $maxwidth) ; do
width=$(printf '%x\n' $valeurw)
for (( i=$((8 - ${#width})); i>=1; i-=1 )) ; do
buffw="${buffw}0"
done
new_width=$buffw$width
unset buffw
#echo $new_width $new_height
new_crc=$(printf "$head_IHDR$new_width$new_height$info_IHDR" | xxd -r -p | rhash --simple - | awk '{print $1}')
clear
echo " CRC : $crc_IHDR H : $new_height W : $valeurw nW : $new_width New CRC : $new_crc"
#echo $new_crc
if [[ "$new_crc" = "$crc_IHDR" ]] ; then
echo "$fichier_hexa" | sed -E 's/(.{32}).{16}(.*$)/\1'"$new_width$new_height"'\2/' | xxd -r -p > RESULT.png
echo "file recover, check RESULT.png file"
exit 0
fi
done
done
}
##début du script :
case $work in
width)
echo width
funk_width
;;
height)
echo height
funk_height
;;
width-height)
echo width-height
funk_all
;;
all)
echo all
funk_width
funk_height
funk_all
;;
debug)
fichier_hexa=$(xxd -p ${fichier} | tr -d "\n")
IHDR=$(echo ${fichier_hexa} | head -2 | tr -d "\n" | sed -E 's/89504e470d0a1a0a.{8}(.{42}).*/\1/')
head_IHDR="${IHDR:0:8}"
width_IHDR="${IHDR:8:8}"
height_IHDR="${IHDR:16:8}"
info_IHDR="${IHDR:24:10}"
crc_IHDR="${IHDR:34}"
echo "
the maxheight is : $maxheight
the minheight is : $minheight
the minwidth is : $minwidth
the maxwidth is : $maxwidth
the file is : $fichier
the 66th first byte : ${fichier_hexa:0:66}
the IHDR : $IHDR
the head_IHDR : $head_IHDR
the width_IHDR : $width_IHDR
the height_IHDR : $height_IHDR
the info_IHDR : $info_IHDR
the crc_IHDR : $crc_IHDR"
;;
esac