├── .github └── FUNDING.yml ├── Dumper ├── README.md └── gitdumper.sh ├── Extractor ├── README.md └── extractor.sh ├── Finder ├── README.md ├── gitfinder.py └── requirements.txt ├── LICENSE.md └── README.md /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | github: gehaxelt 3 | -------------------------------------------------------------------------------- /Dumper/README.md: -------------------------------------------------------------------------------- 1 | GitDumper 2 | ================= 3 | This is a tool for downloading .git repositories from webservers which do not have directory listing enabled. 4 | 5 | # Requirements 6 | - git 7 | - curl 8 | - bash 9 | - sed 10 | 11 | # Usage 12 | 13 | ``` 14 | bash gitdumper.sh http://target.tld/.git/ dest-dir 15 | ``` 16 | 17 | Note: This tool has no 100% guaranty to completely recover the .git repository. Especially if the repository has been compressed into ```pack```-files, it may fail. 18 | -------------------------------------------------------------------------------- /Dumper/gitdumper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #$1 : URL to download .git from (http://target.com/.git/) 3 | #$2 : Folder where the .git-directory will be created 4 | 5 | function init_header() { 6 | cat < /dev/null); then 135 | #Delete invalid file 136 | cd "$cwd" 137 | rm "$target" 138 | return 139 | fi 140 | 141 | #Parse output of git cat-file -p $hash. Use strings for blobs 142 | if [[ "$type" != "blob" ]]; then 143 | hashes+=($(git cat-file -p "$hash" | grep -oE "([a-f0-9]{40})")) 144 | else 145 | hashes+=($(git cat-file -p "$hash" | strings -a | grep -oE "([a-f0-9]{40})")) 146 | fi 147 | 148 | cd "$cwd" 149 | fi 150 | 151 | #Parse file for other objects 152 | hashes+=($(cat "$target" | strings -a | grep -oE "([a-f0-9]{40})")) 153 | for hash in ${hashes[*]} 154 | do 155 | QUEUE+=("objects/${hash:0:2}/${hash:2}") 156 | done 157 | 158 | #Parse file for packs 159 | packs+=($(cat "$target" | strings -a | grep -oE "(pack\-[a-f0-9]{40})")) 160 | for pack in ${packs[*]} 161 | do 162 | QUEUE+=("objects/pack/$pack.pack") 163 | QUEUE+=("objects/pack/$pack.idx") 164 | done 165 | } 166 | 167 | 168 | start_download 169 | -------------------------------------------------------------------------------- /Extractor/README.md: -------------------------------------------------------------------------------- 1 | Git Extractor 2 | ============================== 3 | 4 | This is a script which tries to recover incomplete git repositories: 5 | 6 | - Iterate through all commit-objects of a repository 7 | - Try to restore the contents of the commit 8 | - Commits are *not* sorted by date 9 | 10 | # Usage 11 | 12 | ``` 13 | bash extractor.sh /tmp/mygitrepo /tmp/mygitrepodump 14 | ``` 15 | where 16 | - ```/tmp/mygitrepo``` contains a ```.git``` directory 17 | - ```/tmp/mygitrepodump``` is the destination directory 18 | 19 | This can be used in combination with the ```Git Dumper``` in case the downloaded repository is incomplete. 20 | 21 | -------------------------------------------------------------------------------- /Extractor/extractor.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #$1 : Folder containing .git directory to scan 3 | #$2 : Folder to put files to 4 | function init_header() { 5 | cat < "$path/$name" 55 | else 56 | echo -e "\e[32m[+] Found folder: $path/$name\e[0m" 57 | mkdir -p "$path/$name"; 58 | #Recursively traverse sub trees 59 | traverse_tree $hash "$path/$name"; 60 | fi 61 | 62 | done; 63 | } 64 | 65 | function traverse_commit() { 66 | local base=$1 67 | local commit=$2 68 | local count=$3 69 | 70 | #Create folder for commit data 71 | echo -e "\e[32m[+] Found commit: $commit\e[0m"; 72 | path="$base/$count-$commit" 73 | mkdir -p $path; 74 | #Add meta information 75 | git cat-file -p "$commit" > "$path/commit-meta.txt" 76 | #Try to extract contents of root tree 77 | traverse_tree $commit $path 78 | } 79 | 80 | #Current directory as we'll switch into others and need to restore it. 81 | OLDDIR=$(pwd) 82 | TARGETDIR=$2 83 | COMMITCOUNT=0; 84 | 85 | #If we don't have an absolute path, add the prepend the CWD 86 | if [ "${TARGETDIR:0:1}" != "/" ]; then 87 | TARGETDIR="$OLDDIR/$2" 88 | fi 89 | 90 | cd $1 91 | 92 | #Extract all object hashes 93 | find ".git/objects" -type f | 94 | sed -e "s/\///g" | 95 | sed -e "s/\.gitobjects//g" | 96 | while read object; do 97 | 98 | type=$(git cat-file -t $object) 99 | 100 | # Only analyse commit objects 101 | if [ "$type" = "commit" ]; then 102 | CURDIR=$(pwd) 103 | traverse_commit "$TARGETDIR" $object $COMMITCOUNT 104 | cd $CURDIR 105 | 106 | COMMITCOUNT=$((COMMITCOUNT+1)) 107 | fi 108 | 109 | done; 110 | 111 | cd $OLDDIR; 112 | -------------------------------------------------------------------------------- /Finder/README.md: -------------------------------------------------------------------------------- 1 | # GitFinder 2 | 3 | This python script identifies websites with publicly accessible `.git` repositories. 4 | It checks if the `.git/HEAD` file contains `refs/heads`. 5 | 6 | # Setup 7 | 8 | ``` 9 | > pip3 install -r requirements.txt 10 | ``` 11 | 12 | # Usage 13 | 14 | ``` 15 | > python3 gitfinder.py -h 16 | usage: gitfinder.py [-h] [-i INPUTFILE] [-o OUTPUTFILE] [-t THREADS] 17 | 18 | optional arguments: 19 | -h, --help show this help message and exit 20 | -i INPUTFILE, --inputfile INPUTFILE 21 | input file 22 | -o OUTPUTFILE, --outputfile OUTPUTFILE 23 | output file 24 | -t THREADS, --threads THREADS 25 | threads 26 | ``` 27 | 28 | The input file should contain the targets one per line. 29 | The script will output discovered domains in the form of `[*] Found: DOMAIN` to stdout. 30 | -------------------------------------------------------------------------------- /Finder/gitfinder.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | ''' 4 | Finder is part of https://github.com/internetwache/GitTools 5 | 6 | Developed and maintained by @gehaxelt from @internetwache 7 | 8 | Use at your own risk. Usage might be illegal in certain circumstances. 9 | Only for educational purposes! 10 | ''' 11 | 12 | import argparse 13 | from functools import partial 14 | from multiprocessing import Pool 15 | from urllib.request import urlopen 16 | from urllib.error import HTTPError, URLError 17 | import sys 18 | import ssl 19 | import encodings.idna 20 | 21 | def findgitrepo(output_file, domains): 22 | domain = ".".join(encodings.idna.ToASCII(label).decode("ascii") for label in domains.strip().split(".")) 23 | 24 | try: 25 | # Try to download http://target.tld/.git/HEAD 26 | with urlopen(''.join(['http://', domain, '/.git/HEAD']), context=ssl._create_unverified_context(), timeout=5) as response: 27 | answer = response.read(200).decode('utf-8', 'ignore') 28 | 29 | except HTTPError: 30 | return 31 | except URLError: 32 | return 33 | except OSError: 34 | return 35 | except ConnectionResetError: 36 | return 37 | except ValueError: 38 | return 39 | except (KeyboardInterrupt, SystemExit): 40 | raise 41 | 42 | # Check if refs/heads is in the file 43 | if 'refs/heads' not in answer: 44 | return 45 | 46 | # Write match to output_file 47 | with open(output_file, 'a') as file_handle: 48 | file_handle.write(''.join([domain, '\n'])) 49 | 50 | print(''.join(['[*] Found: ', domain])) 51 | 52 | 53 | def read_file(filename): 54 | with open(filename) as file: 55 | return file.readlines() 56 | 57 | def main(): 58 | print(""" 59 | ########### 60 | # Finder is part of https://github.com/internetwache/GitTools 61 | # 62 | # Developed and maintained by @gehaxelt from @internetwache 63 | # 64 | # Use at your own risk. Usage might be illegal in certain circumstances. 65 | # Only for educational purposes! 66 | ########### 67 | """) 68 | 69 | # Parse arguments 70 | parser = argparse.ArgumentParser() 71 | parser.add_argument('-i', '--inputfile', default='input.txt', help='input file') 72 | parser.add_argument('-o', '--outputfile', default='output.txt', help='output file') 73 | parser.add_argument('-t', '--threads', default=200, help='threads') 74 | args = parser.parse_args() 75 | 76 | domain_file = args.inputfile 77 | output_file = args.outputfile 78 | try: 79 | max_processes = int(args.threads) 80 | except ValueError as err: 81 | sys.exit(err) 82 | 83 | try: 84 | domains = read_file(domain_file) 85 | except FileNotFoundError as err: 86 | sys.exit(err) 87 | 88 | fun = partial(findgitrepo, output_file) 89 | print("Scanning...") 90 | with Pool(processes=max_processes) as pool: 91 | pool.map(fun, domains) 92 | print("Finished") 93 | 94 | if __name__ == '__main__': 95 | main() 96 | -------------------------------------------------------------------------------- /Finder/requirements.txt: -------------------------------------------------------------------------------- 1 | requests 2 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright >=2015 Sebastian Neef 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![GitHub stars](https://img.shields.io/github/stars/internetwache/GitTools.svg)](https://github.com/internetwache/GitTools/stargazers) 2 | [![GitHub license](https://img.shields.io/github/license/internetwache/GitTools.svg)](https://github.com/internetwache/GitTools/blob/master/LICENSE.md) 3 | 4 | 5 | # GitTools 6 | 7 | This repository contains three small python/bash scripts used for the Git research. [Read about it here](https://en.internetwache.org/dont-publicly-expose-git-or-how-we-downloaded-your-websites-sourcecode-an-analysis-of-alexas-1m-28-07-2015/) 8 | 9 | ## Finder 10 | 11 | You can use this tool to find websites with their .git repository available to the public 12 | 13 | ### Usage 14 | 15 | This python script identifies websites with publicly accessible ```.git``` repositories. 16 | It checks if the ```.git/HEAD``` file contains ```refs/heads```. 17 | 18 | ``` 19 | $ ./gitfinder.py -h 20 | 21 | ########### 22 | # Finder is part of https://github.com/internetwache/GitTools 23 | # 24 | # Developed and maintained by @gehaxelt from @internetwache 25 | # 26 | # Use at your own risk. Usage might be illegal in certain circumstances. 27 | # Only for educational purposes! 28 | ########### 29 | 30 | usage: gitfinder.py [-h] [-i INPUTFILE] [-o OUTPUTFILE] [-t THREADS] 31 | 32 | optional arguments: 33 | -h, --help show this help message and exit 34 | -i INPUTFILE, --inputfile INPUTFILE 35 | input file 36 | -o OUTPUTFILE, --outputfile OUTPUTFILE 37 | output file 38 | -t THREADS, --threads THREADS 39 | threads 40 | ``` 41 | 42 | The input file should contain the targets one per line. 43 | The script will output discovered domains in the form of ```[*] Found: DOMAIN``` to stdout. 44 | 45 | #### Scanning Alexa’s Top 1M 46 | 47 | ``` 48 | wget http://s3.amazonaws.com/alexa-static/top-1m.csv.zip 49 | unzip top-1m.csv.zip 50 | sed -i.bak 's/.*,//' top-1m.csv 51 | ./gitfinder.py -i top-1m.csv 52 | ``` 53 | 54 | ## Dumper 55 | 56 | This tool can be used to download as much as possible from the found .git repository from webservers which do not have directory listing enabled. 57 | 58 | ### Usage 59 | 60 | ``` 61 | $ ./gitdumper.sh -h 62 | 63 | [*] USAGE: http://target.tld/.git/ dest-dir [--git-dir=otherdir] 64 | --git-dir=otherdir Change the git folder name. Default: .git 65 | 66 | ``` 67 | 68 | Note: This tool has no 100% guaranty to completely recover the .git repository. Especially if the repository has been compressed into ```pack```-files, it may fail. 69 | 70 | 71 | ## Extractor 72 | 73 | A small bash script to extract commits and their content from a broken repository. 74 | 75 | This script tries to recover incomplete git repositories: 76 | 77 | - Iterate through all commit-objects of a repository 78 | - Try to restore the contents of the commit 79 | - Commits are *not* sorted by date 80 | 81 | ### Usage 82 | 83 | ``` 84 | $ ./extractor.sh /tmp/mygitrepo /tmp/mygitrepodump 85 | ``` 86 | where 87 | - ```/tmp/mygitrepo``` contains a ```.git``` directory 88 | - ```/tmp/mygitrepodump``` is the destination directory 89 | 90 | This can be used in combination with the ```Git Dumper``` in case the downloaded repository is incomplete. 91 | 92 | 93 | ## Demo 94 | 95 | Here's a small demo of the **Dumper** tool: 96 | 97 | [![asciicast](https://asciinema.org/a/24072.png)](https://asciinema.org/a/24072) 98 | 99 | ## Proxy support 100 | 101 | The `urllib` and `curl` should support proxy configuration through environment variables: 102 | 103 | In bash, set: 104 | 105 | ``` 106 | export HTTP_PROXY=http://proxy_url:proxy_port 107 | export HTTPS_PROXY=http://proxy_url:proxy_port 108 | ``` 109 | 110 | In Window's CMD, use: 111 | 112 | ``` 113 | set HTTP_PROXY=http://proxy_url:proxy_port 114 | set HTTPS_PROXY=http://proxy_url:proxy_port 115 | ``` 116 | 117 | Basic auth should be supported with: 118 | 119 | ``` 120 | http://username:password@proxy_url:proxy_port 121 | ``` 122 | 123 | ## Requirements 124 | * git 125 | * Python 3+ 126 | * curl 127 | * bash 128 | * sed 129 | * binutils (strings) 130 | 131 | # License 132 | 133 | All tools are licensed using the MIT license. See [LICENSE.md](LICENSE.md) 134 | --------------------------------------------------------------------------------