2017-05-08 393 views
0

我剛剛注意到WordPress的發現新的漏洞,我想用下面的代碼修復它(但任何成功PHP stream_socket_client():無法連接到https

<?php 

$url = 'https://mywebip/wp-login.php?action=lostpassword'; 
$data = 'user_login=admin&redirect_to=&wp-submit=Get+New+Password'; 

// use key 'http' even if you send the request to https://... 
$options = array(
    'http' => array(
     'header' => "Host: mailserver\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: ". strlen($data) ."\r\n", 
     'method' => 'POST', 
     'content' => $data, 
     'ssl'=>array('verify_peer'=>true, 'capath'=>'/etc/ssl/certs') 
    ) 
); 
$context = stream_context_create($options); 
//$result = file_get_contents($url, false, $context); 

$fp = stream_socket_client($url, $errno, $errstr, 30); 
//stream_socket_enable_crypto($fp, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); 

$fp = fopen($url, 'r', false, $context); 

if ($fp === FALSE) { /* Handle error */ } 

var_dump($result); 
?> 

錯誤登錄我就是這樣的:

PHP Warning: stream_socket_client(): unable to connect to https://mywebip/wp-login.php?action=lostpassword (Unable to find the socket transport "https" - did you forget to enable it when you configured PHP?) in /home/jorge/Escritorio/joomla.php on line 18 

PHP Warning: fopen(): Peer certificate CN=`website` did not match expected CN=`mywebip' in /home/jorge/Escritorio/joomla.php on line 21 

PHP Warning: fopen(): Failed to enable crypto in /home/jorge/Escritorio/joomla.php on line 21 

PHP Warning: fopen(https://mywebip/wp-login.php?action=lostpassword): failed to open stream: operation failed in /home/jorge/Escritorio/joomla.php on line 21 

其中mywebip代表承載我的網站和websitemailserver服務的DNS方向的實際IP

謝謝。

回答

0

通過套接字你不指定協議。

http://php.net/stream_socket_client

第一個參數:

remote_socket

地址來連接到插座。

地址僅爲mywebip

您應該改用CURL。

http://php.net/manual/en/curl.examples.php

的另一個問題(與fopen(),它可以處理與協議流!)是您的網絡服務器發出一個畸形/錯誤的證書。

使用此服務來調試問題,您的Web服務器證書:

https://www.ssllabs.com/ssltest/

+0

可否請你扔一些輕關於這一主題?因爲我在這方面很新手。我正在嘗試使用CURL,但我不知道如何與我已有的代碼進行關聯。無論如何感謝您的合作;) – giorgioW