Skip to content

Commit e6246d3

Browse files
committed
Some more bugfixes when parsing binary blobs.
Colored output is supported now
1 parent 8dbce83 commit e6246d3

File tree

1 file changed

+59
-33
lines changed

1 file changed

+59
-33
lines changed

Dumper/gitdumper.sh

+59-33
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,43 @@
11
#!/bin/bash
22
#$1 : URL to download .git from (http://target.com/.git/)
33
#$2 : Folder where the .git-directory will be created
4+
5+
function init_header() {
6+
cat <<EOF
7+
###########
8+
# GitDumper is part of https://github.com/internetwache/GitTools
9+
#
10+
# Developed and maintained by @gehaxelt from @internetwache
11+
#
12+
# Use at your own risk. Usage might be illegal in certain circumstances.
13+
# Only for educational purposes!
14+
###########
15+
EOF
16+
}
17+
18+
init_header
19+
20+
421
QUEUE=();
522
DOWNLOADED=();
623
BASEURL="$1";
724
BASEDIR="$2";
825
BASEGITDIR="$BASEDIR/.git/";
926

1027
if [ $# -ne 2 ]; then
11-
echo "USAGE: http://target.tld/.git/ dest-dir";
28+
echo -e "\e[33m[*] USAGE: http://target.tld/.git/ dest-dir\e[0m";
1229
exit 1;
1330
fi
1431

1532

1633
if [[ ! "$BASEURL" =~ /.git/$ ]]; then
17-
echo "/.git/ missing in url";
34+
echo -e "\e[31m[-] /.git/ missing in url\e[0m";
1835
exit 0;
1936
fi
2037

2138
if [ ! -d "$BASEGITDIR" ]; then
22-
echo "Destination folder does not exist";
23-
echo "Creating $BASEGITDIR";
39+
echo -e "\e[33m[*] Destination folder does not exist\e[0m";
40+
echo -e "\e[32m[+] Creating $BASEGITDIR\e[0m";
2441
mkdir -p "$BASEGITDIR";
2542
fi
2643

@@ -72,50 +89,59 @@ function download_item() {
7289
fi
7390

7491
#Download file
75-
curl -k -s "$url" > "$target"
92+
curl -f -k -s "$url" -o "$target"
7693

7794
#Mark as downloaded and remove it from the queue
7895
DOWNLOADED+=("$objname")
79-
echo "Downloaded: $objname"
80-
81-
#Check if we have an object hash
82-
if [[ "$objname" =~ /[a-f0-9]{2}/[a-f0-9]{38} ]]; then
83-
#Switch into $BASEDIR and save current working directory
84-
cwd=$(pwd)
85-
cd "$BASEDIR"
86-
87-
#Restore hash from $objectname
88-
hash=$(echo "$objname" | sed -e 's~objects~~g' | sed -e 's~/~~g')
89-
90-
#Check if it's valid git object
91-
git cat-file -t "$hash" &> /dev/null
92-
if [ $? -ne 0 ]; then
93-
#Delete invalid file
94-
cd "$cwd"
95-
rm "$target"
96-
return
97-
fi
98-
99-
#Parse output of git cat-file -p $hash
100-
hashes+=($(git cat-file -p "$hash" | grep -oE "([a-f0-9]{40})"))
101-
102-
cd "$cwd"
103-
fi
104-
96+
if [ ! -f "$target" ]; then
97+
echo -e "\e[31m[-] Downloaded: $objname\e[0m"
98+
return
99+
fi
100+
echo -e "\e[32m[+] Downloaded: $objname\e[0m"
101+
102+
#Check if we have an object hash
103+
if [[ "$objname" =~ /[a-f0-9]{2}/[a-f0-9]{38} ]]; then
104+
#Switch into $BASEDIR and save current working directory
105+
cwd=$(pwd)
106+
cd "$BASEDIR"
107+
108+
#Restore hash from $objectname
109+
hash=$(echo "$objname" | sed -e 's~objects~~g' | sed -e 's~/~~g')
110+
111+
#Check if it's valid git object
112+
type=$(git cat-file -t "$hash" 2> /dev/null)
113+
if [ $? -ne 0 ]; then
114+
#Delete invalid file
115+
cd "$cwd"
116+
rm "$target"
117+
return
118+
fi
119+
120+
#Parse output of git cat-file -p $hash. Use strings for blobs
121+
if [[ "$type" != "blob" ]]; then
122+
hashes+=($(git cat-file -p "$hash" | grep -oE "([a-f0-9]{40})"))
123+
else
124+
hashes+=($(git cat-file -p "$hash" | strings -a | grep -oE "([a-f0-9]{40})"))
125+
fi
126+
127+
cd "$cwd"
128+
fi
129+
105130
#Parse file for other objects
106-
hashes+=($(cat "$target" | grep -oE "([a-f0-9]{40})"))
131+
hashes+=($(cat "$target" | strings -a | grep -oE "([a-f0-9]{40})"))
107132
for hash in ${hashes[*]}
108133
do
109134
QUEUE+=("objects/${hash:0:2}/${hash:2}")
110135
done
111136

112137
#Parse file for packs
113-
packs+=($(cat "$target" | grep -oE "(pack\-[a-f0-9]{40})"))
138+
packs+=($(cat "$target" | strings -a | grep -oE "(pack\-[a-f0-9]{40})"))
114139
for pack in ${packs[*]}
115140
do
116141
QUEUE+=("objects/pack/$pack.pack")
117142
QUEUE+=("objects/pack/$pack.idx")
118143
done
119144
}
120145

146+
121147
start_download

0 commit comments

Comments
 (0)