1. php的網站,怎麼掃描出潛藏的一句話木馬
查找那些高危函數就行了,比如eval
php後門木馬常用的函數大致上可分為四種類型:
1. 執行系統命令: system, passthru, shell_exec, exec, popen,
proc_open
2. 代碼執行與加密: eval, assert, call_user_func,base64_decode, gzinflate,
gzuncompress, gzdecode, str_rot13
3. 文件包含與生成: require, require_once, include, include_once,
file_get_contents, file_put_contents, fputs, fwrite
4. .htaccess: SetHandler, auto_prepend_file, auto_append_file
2. 以下哪些是常見的php 一句話木馬
查找那些高危函數就行了,比如eval
php後門木馬常用的函數大致上可分為四種類型:
1. 執行系統命令: system, passthru, shell_exec, exec, popen,
proc_open
2. 代碼執行與加密: eval, assert, call_user_func,base64_decode, gzinflate,
gzuncompress, gzdecode, str_rot13
3. 文件包含與生成: require, require_once, include, include_once,
file_get_contents, file_put_contents, fputs, fwrite
4. .htaccess: SetHandler, auto_prepend_file, auto_append_file
3. php rpc好用嗎,有什麼優缺點php rpc框架哪個好
什麼是RPC框架? 如果用一句話概括RPC就是:遠程調用框架(Remote Procere Call)那什麼是遠程調用?通常我們調用一個php中的方法,比如這樣一個函數方法: localAdd(10, 20),localAdd方法的具體實現要麼是用戶自己定義的,要麼是php庫函數中自帶的,也就說在localAdd方法的代碼實現在本地,它是一個本地調用!遠程調用意思就是:被調用方法的具體實現不在程序運行本地,而是在別的某個遠程地方。
遠程調用原理
比如 A (client) 調用 B (server) 提供的remoteAdd方法:
首先A與B之間建立一個TCP連接;
然後A把需要調用的方法名(這里是remoteAdd)以及方法參數(10, 20)序列化成位元組流發送出去;
B接受A發送過來的位元組流,然後反序列化得到目標方法名,方法參數,接著執行相應的方法調用(可能是localAdd)並把結果30返回;
A接受遠程調用結果,輸出30。
RPC框架就是把我剛才說的這幾點些細節給封裝起來,給用戶暴露簡單友好的API使用。
遠程調用的好處
解耦:當server需要對方法內實現修改時,client完全感知不到,不用做任何變更;這種方式在跨部門,跨公司合作的時候經常用到,並且方法的提供者我們通常稱為:服務的暴露。
RPC與Socket有什麼區別?
通過上面的簡單闡述,好像RPC與Socket 好像啊。都是調用遠程的方法,都是client/server模式,我之前也寫了一篇文章: 細說socket 那他們有啥區別呢?
RPC(遠程過程調用)採用客戶機/伺服器模式實現兩個進程之間相互通信。socket是RPC經常採用的通信手段之一,RPC是在Socket的基礎上實現的,它比socket需要更多的網路和系統資源。除了Socket,RPC還有其他的通信方法,比如:http、操作系統自帶的管道等技術來實現對於遠程程序的調用。微軟的Windows系統中,RPC就是採用命名管道進行通信。
RPC與REST有什麼區別?
通過了解RPC後,我們知道是RPC是client/server模式的,調用遠程的方法,REST也是我們熟悉的一套API調用協議方法,它也是基於client/server模式的,調用遠程的方法的,那他倆又有啥區別呢?
REST API 和 RPC 都是在 Server端 把一個個函數封裝成介面暴露出去,以供 Client端 調用,不過 REST API 是基於HTTP協議的,REST致力於通過http協議中的POST/GET/PUT/DELETE等方法和一個可讀性強的URL來提供一個http請求。而 RPC 則可以不基於 HTTP協議
因此,如果是後端兩種語言互相調用,用 RPC 可以獲得更好的性能(省去了 HTTP 報頭等一系列東西),應該也更容易配置。如果是前端通過 AJAX 調用後端,那麼用 REST API 的形式比較好(因為無論如何也避不開 HTTP 這道坎)。
php中流行的rpc框架有哪些
既然php是世界上最好的語言,那php中流行的RPC框架有哪些呢?
先列舉下: phprpc,yar, thrift, gRPC, swoole, hprose
因為時間和精力有限,不可能一個一個的去學習和使用,我選幾個世面上用的最多的幾個用下吧。因為RPC原理是一樣的,都是Client/Server模式,只是每個框架的使用方式不一樣而已。
4. jszip如何解壓字元串
其實php對gzip解壓很簡單,用內置的gzdecode函數就可以了,不過很可惜我配置了半天也無法支持gzdecode函數,所以只好變通一下: 復制代碼 代碼如下: if (!function_exists('gzdecode')) { function gzdecode ($data) { $flags = ord(substr($data, 3, 1)); $headerlen = 10; $extralen = 0; $filenamelen = 0; if ($flags & 4) { $extralen = unpack('v' ,substr($data, 10, 2)); $extralen = $extralen[1]; $headerlen += 2 + $extralen; } if ($flags & 8) // Filename $headerlen = strpos($data, chr(0), $headerlen) + 1; if ($flags & 16) // Comment $headerlen = strpos($data, chr(0), $headerlen) + 1; if ($flags & 2) // CRC at end of file $headerlen += 2; $unpacked = @gzinflate(substr($data, $headerlen)); if ($unpacked === FALSE) $unpacked = $data; return $unpacked; } } 調用方法很簡單: 復制代碼 代碼如下: $f=@file_get_contents(""); echo gzdecode($f);
5. 怎麼php發送get請求給java,然後返回想要的具體參數
curl請求java介面,介面返回值後進行相關操作,給你貼一個curl的代碼
functionihttp_request($url,$post='',$extra=array(),$timeout=60){
$urlset=parse_url($url);
if(empty($urlset['path'])){
$urlset['path']='/';
}
if(!empty($urlset['query'])){
$urlset['query']="?{$urlset['query']}";
}
if(empty($urlset['port'])){
$urlset['port']=$urlset['scheme']=='https'?'443':'80';
}
if(strexists($url,'https://')&&!extension_loaded('openssl')){
if(!extension_loaded("openssl")){
message('請開啟您PHP環境的openssl');
}
}
if(function_exists('curl_init')&&function_exists('curl_exec')){
$ch=curl_init();
if(ver_compare(phpversion(),'5.6')>=0){
curl_setopt($ch,CURLOPT_SAFE_UPLOAD,false);
}
if(!empty($extra['ip'])){
$extra['Host']=$urlset['host'];
$urlset['host']=$extra['ip'];
unset($extra['ip']);
}
curl_setopt($ch,CURLOPT_URL,$urlset['scheme'].'://'.$urlset['host'].($urlset['port']=='80'?'':':'.$urlset['port']).$urlset['path'].$urlset['query']);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
@curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_HEADER,1);
@curl_setopt($ch,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_0);
if($post){
if(is_array($post)){
$filepost=false;
foreach($postas$name=>$value){
if((is_string($value)&&substr($value,0,1)=='@')||(class_exists('CURLFile')&&$valueinstanceofCURLFile)){
$filepost=true;
break;
}
}
if(!$filepost){
$post=http_build_query($post);
}
}
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post);
}
if(!empty($GLOBALS['_W']['config']['setting']['proxy'])){
$urls=parse_url($GLOBALS['_W']['config']['setting']['proxy']['host']);
if(!empty($urls['host'])){
curl_setopt($ch,CURLOPT_PROXY,"{$urls['host']}:{$urls['port']}");
$proxytype='CURLPROXY_'.strtoupper($urls['scheme']);
if(!empty($urls['scheme'])&&defined($proxytype)){
curl_setopt($ch,CURLOPT_PROXYTYPE,constant($proxytype));
}else{
curl_setopt($ch,CURLOPT_PROXYTYPE,CURLPROXY_HTTP);
curl_setopt($ch,CURLOPT_HTTPPROXYTUNNEL,1);
}
if(!empty($GLOBALS['_W']['config']['setting']['proxy']['auth'])){
curl_setopt($ch,CURLOPT_PROXYUSERPWD,$GLOBALS['_W']['config']['setting']['proxy']['auth']);
}
}
}
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
curl_setopt($ch,CURLOPT_TIMEOUT,$timeout);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($ch,CURLOPT_SSLVERSION,1);
if(defined('CURL_SSLVERSION_TLSv1')){
curl_setopt($ch,CURLOPT_SSLVERSION,CURL_SSLVERSION_TLSv1);
}
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0(WindowsNT6.1;WOW64;rv:9.0.1)Gecko/20100101Firefox/9.0.1');
if(!empty($extra)&&is_array($extra)){
$headers=array();
foreach($extraas$opt=>$value){
if(strexists($opt,'CURLOPT_')){
curl_setopt($ch,constant($opt),$value);
}elseif(is_numeric($opt)){
curl_setopt($ch,$opt,$value);
}else{
$headers[]="{$opt}:{$value}";
}
}
if(!empty($headers)){
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
}
}
$data=curl_exec($ch);
$status=curl_getinfo($ch);
$errno=curl_errno($ch);
$error=curl_error($ch);
curl_close($ch);
if($errno||empty($data)){
returnerror(1,$error);
}else{
returnihttp_response_parse($data);
}
}
$method=empty($post)?'GET':'POST';
$fdata="{$method}{$urlset['path']}{$urlset['query']}HTTP/1.1 ";
$fdata.="Host:{$urlset['host']} ";
if(function_exists('gzdecode')){
$fdata.="Accept-Encoding:gzip,deflate ";
}
$fdata.="Connection:close ";
if(!empty($extra)&&is_array($extra)){
foreach($extraas$opt=>$value){
if(!strexists($opt,'CURLOPT_')){
$fdata.="{$opt}:{$value} ";
}
}
}
$body='';
if($post){
if(is_array($post)){
$body=http_build_query($post);
}else{
$body=urlencode($post);
}
$fdata.='Content-Length:'.strlen($body)." {$body}";
}else{
$fdata.=" ";
}
if($urlset['scheme']=='https'){
$fp=fsockopen('ssl://'.$urlset['host'],$urlset['port'],$errno,$error);
}else{
$fp=fsockopen($urlset['host'],$urlset['port'],$errno,$error);
}
stream_set_blocking($fp,true);
stream_set_timeout($fp,$timeout);
if(!$fp){
returnerror(1,$error);
}else{
fwrite($fp,$fdata);
$content='';
while(!feof($fp))
$content.=fgets($fp,512);
fclose($fp);
returnihttp_response_parse($content,true);
}
}
6. PHP如何解碼Chunked+gzip獲得的源碼
我粘貼一下我的HTTP下載函數代碼,可以處理chunked編碼,我的程序裡面沒有GZIP編碼,如果你遇到GZIP,你在函數返回後再次進行解壓縮即可。
//執行HTTP請求
function http_request($url,$method='GET',$data='',$cookie='',$refer=''){
$header='';
$body='';
$newcookie='';
if (preg_match('/^http:\/\/(.*?)(\/.*)$/',$url,$reg)){$host=$reg[1]; $path=$reg[2];}
else {outs(1,"URL($url)格式非法!"); return;}
$http_host=$host;
if (preg_match('/^(.*):(\d+)$/', $host, $reg)) {$host=$reg[1]; $port=$reg[2];}
else $port=80;
$fp = fsockopen($host, $port, $errno, $errstr, 30);
if (!$fp) {
outs(1,"$errstr ($errno)\n");
} else {
fputs($fp, "$method $path HTTP/1.1\r\n");
fputs($fp, "Host: $http_host\r\n");
if ($refer!='') fputs($fp, "Referer: $refer\r\n");
if ($cookie!='') fputs($fp, "Cookie: $cookie\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ".strlen($data)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $data . "\r\n\r\n");
$header_body=0;
$chunked_format=0;
$chunked_len=0;
while (!feof($fp)) {
$str=fgets($fp);
if ($header_body==1){
if ($chunked_format){
if ($chunked_len<=0){
$chunked_len=hexdec($str);
if ($chunked_len==0) break;
else continue;
} else {
$chunked_len-=strlen($str);
if ($chunked_len<=0) $str=trim($str);
}
}
$body.=$str;
}
else if ($str=="\r\n") $header_body=1;
else {
$header.=$str;
if ($str=="Transfer-Encoding: chunked\r\n") $chunked_format=1;
if (preg_match('|Set-Cookie: (\S+)=(\S+);|',$str,$reg)) $newcookie.=($newcookie==''?'':'; ').$reg[1].'='.$reg[2];
}
}
fclose($fp);
}
$GLOBALS['TRAFFIC']+=414+strlen($url)+strlen($data)+strlen($header)+strlen($body);
if (preg_match('/^Location: (\S+)\r\n/m',$header,$reg)) {
if (substr($reg[1],0,1)!='/'){
$path=substr($path,0,strrpos($path,'/')+1);
$path.=$reg[1];
} else $path=$reg[1];
if ($newcookie) $cookie=$newcookie;
return http_request('http://'.$http_host.$path,'GET','',$cookie,$url);
}
return array($body, $header, $newcookie);
}