欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

是否可以使用扩展名file.php.jpg执行PHP?(Is it possible to execute PHP with extension file.php.jpg?) jpg png 当作php来执行 有大用

是否可以使用扩展名file.php.jpg执行PHP?(Is it possible to execute PHP with extension file.php.jpg?)

 692   IT屋

Site legit file image_upload.php was used to upload file 89471928047.php.jpg Which was simple file upload form that copy tmp file to same images folder. How they managed to execute it and upload other files trough it. Someone know how this is possible? PHP version was 5.1.6 that being updated exactly hour ago or after by schedule with host to 5.3.8... what a, coincidence?

解决方案

Check your .htaccess file

Using AddType in your .htaccess file, you can add many other extensions from which PHP can be ran. This is generally how .html extensions can be used while still using PHP within themselves. So, yes, it's possible:

AddType application/x-httpd-php .jpg

You can test this if you like.

  1. Create a directory with two files: .htaccess and test.php.jpg

  2. Set content of .htaccess to AddType application-x-httpd-php .jpg

  3. Set content of test.php.jpg to <?php echo 'foo'; ?>

  4. Access test.php.jpg through localhost

If all goes as planned, "foo" will be output to your screen. You could expand upon this to move /tmp files around if you like.

Definitely something you want to be very careful with.

Check exposed calls to include/require

Another way this could have been done is through a call to require() or include() (or any of the _once() methods) where by the hacker was able to load in his badfile.php.jpg file that had been uploaded under the guise of an innocent image:

<?php

  include $_GET["file"];

?>

In the above case (simplified example), the hacker could pass in a path to his .php.jpg file and have its contents loaded in and processed as PHP code.

Other (frightening) ideas

Require, Include, and their related methods aren't the only ways you can process external scripts - unfortunately you can use eval() as well. I would hope that you have none of this going on though. If you did have any scripts on your server that were using any one of the file functions to read the contents of another script, and then eval() to evaluate that content as PHP, this could also provide a gaping security hole in your website.

站点合法文件image_upload.php用于上传文件89471928047.php.jpg,这是将tmp文件复制到同一图像文件夹的简单文件上传形式. 他们如何设法执行它并通过它上传其他文件.有人知道这怎么可能吗? PHP version was 5.1.6正好在一个小时之前或之后按计划与主机进行了更新,5.3.8 ...这是什么巧合?

解决方案

检查您的.htaccess文件

在.htaccess文件中使用 AddType ,您可以添加许多其他可以运行PHP的扩展.通常,这是在仍在内部使用PHP的同时可以使用.html扩展的方式.所以,是的,有可能:

AddType application/x-httpd-php .jpg

如果愿意,您可以测试一下.

  1. 创建一个包含两个文件的目录:.htaccess和test.php.jpg

  2. 将.htaccess的内容设置为AddType application-x-httpd-php .jpg

  3. 将test.php.jpg的内容设置为<?php echo 'foo'; ?>

  4. 通过本地主机访问test.php.jpg

如果一切按计划进行,"foo"将输出到您的屏幕.如果愿意,可以扩展此范围以移动/tmp个文件.

绝对要特别小心.

检查公开的呼叫是否包含/要求

另一种可能的方法是通过调用require()或include()(或任何_once()方法),黑客可以在其中加载已上传的badfile.php.jpg文件以无辜的形象为掩饰:

<?php

  include $_GET["file"];

?>

在上述情况下(简化示例),黑客可以传递到其.php.jpg文件的路径,并将其内容加载并作为PHP代码进行处理.

其他(令人恐惧的)想法

Require,Include及其相关方法不是处理外部脚本的唯一方法-不幸的是,您也可以使用eval().我希望您没有任何这种情况.如果服务器上确实有任何脚本正在使用文件功能中的任何一个来读取另一个脚本的内容,然后使用eval()将该内容评估为PHP,则这也可能在您的网站中提供巨大的安全漏洞.

本文地址:IT屋 » 是否可以使用扩展名file.php.jpg执行PHP?

来自 https://www.it1352.com/1742230.html


如何让非.php后缀名的文件,以php脚本的形式运行?

dream77585212010-04-26 04:23:40
我用php gd库写了一个输出jpg图片的文件

但是我在百度贴吧贴图, 必须要用 jpg后缀名, php后缀无法贴图

我设想把php后缀改成jpg,但是服务器还是将它作为php代码解释,可以写。htaccess规则吗?

网上是
<FilesMatch "\.(jpg)$">
ForceType application/x-httpd-php
</FilesMatch>

可是我没有成功,很头疼
麻烦各位了!

网上资料说要编辑http.conf,本地可以,远程主机我没这个权限, 期望能用。htaccess解决下
587点赞收藏15
 写回复
15 条回复
 切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
cooledit2730 2010-04-28

<FilesMatch "*.jpg">
SetHandler application/x-httpd-php
</FilesMatch>
jlzan1314 2010-04-27
[Quote=引用 12 楼 tabris17 的回复:]

为啥不用url_rewrite功能呢
不用拘泥于以php方式执行jpg
[/Quote]

用 url_rewirete 把某个jpg文件 变成php文件访问. 这个方法也是可以了.
tabris17 2010-04-27
为啥不用url_rewrite功能呢
不用拘泥于以php方式执行jpg
Abin-2008 2010-04-27
用url_rewirete
RewriteEngine on
RewriteRule ([a-zA-Z]{1,})-([0-9]{1,})\.jpg$ index.php?action=$1&id=$2
oophper 2010-04-26
很多木马使这种做法,改后缀名
但是楼主的想法是可以做的,将jpg文件友php来执行。楼上很全了
只是不知道htaccess里是不是什么都可以改,受不受服务器控制,这个我太清楚。帮顶
cooledit2730 2010-04-26
如果你这样改了,你的网站很不安全。。。 .
dream7758521 2010-04-26
现在问题是本地能成功,远程主机不行,但是我写的htaccess防盗链可以实现,说明htaccess远程主机支持.

这是怎么回事>
dream7758521 2010-04-26
[Quote=引用 7 楼 yangball 的回复:]
htaccess 不需要修改服务器里的

只要服务器允许使用 htaccess 就可以,放到网站目录就行了
[/Quote]

服务器容许使用htaccess
但是我将这个脚本<?php echo "aaaa"; ?>
重命名成echo.ooo,后缀名为ooo,
规则这样写
AddType application/x-httpd-php .ooo

好像不当php来解释.
而在本地调试成功,求解
床上等您 2010-04-26
htaccess 不需要修改服务器里的

只要服务器允许使用 htaccess 就可以,放到网站目录就行了
PIGer920 2010-04-26
[Quote=引用 4 楼 dream7758521 的回复:]
引用 1 楼 piger920 的回复:
lz的意思是把执行代码伪装成jpg,然后上传到baidu server上对百度进行攻击?


哥们,你太抬举我了,我只是想做一个动态显示ip的图片! 不过你这样说我,我特有成就感!!
[/Quote]
http://www.jb51.net/article/8967.htm

貌似是做个输出图片的php,放到你自己的server
然后再在论坛签名的地方用引入图片的方式来引入此php
thinkinginAOCP 2010-04-26
汗,这样改也可以...
dream7758521 2010-04-26
[Quote=引用 1 楼 piger920 的回复:]
lz的意思是把执行代码伪装成jpg,然后上传到baidu server上对百度进行攻击?
[/Quote]

哥们,你太抬举我了,我只是想做一个动态显示ip的图片! 不过你这样说我,我特有成就感!!
骄傲青蛙 2010-04-26
改htaccess或php.ini都行, 下面中文文档

http://docs.php.net/manual/zh/security.hiding.php
骄傲青蛙 2010-04-26
是可以的,php手册上有写,以前我也把php改成html来运行。

详细看 http://cn2.php.net/manual/en/security.hiding.php
PIGer920 2010-04-26

lz的意思是把执行代码伪装成jpg,然后上传到baidu server上对百度进行攻击?


来自  https://bbs.csdn.net/topics/330263399


普通分类: