Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2009
    Posts
    135
    Thanks
    83
    Thanked 0 Times in 0 Posts

    CURL SOCKS Proxies Going To Incorrect URL???

    I am attempting to get the script below to connect to a URL but when it connects to a file that I setup that simply echos out the URL being requested it is requesting:

    Code:
    http://www.mysite.comhttp://www.mysite.com/test.php
    So it is adding the server address before the request URL for some strange reason, whereas the same script using HTTP proxies is connecting just fine.

    test.php:
    PHP Code:
    <?php
    echo "http://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    ?>
    If I browse directly to the above file it will show me:
    Code:
    http://www.mysite.com/test.php
    CURL Script:
    PHP Code:
    <?php
    function Return_Content_From_URL_Agent($url,$cookies,$proxy,$port,$loginpassw,$userAgent,$proxytype){
        
    $ch curl_init();
        
    curl_setopt($chCURLOPT_USERAGENT$userAgent);
        
    curl_setopt($chCURLOPT_URL,$url);
        
    curl_setopt($chCURLOPT_FAILONERROR1);
        
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);
        
    curl_setopt($chCURLOPT_AUTOREFERER1);
        
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
        
    curl_setopt($chCURLOPT_PROXYPORT$port);
        
    curl_setopt($chCURLOPT_PROXYTYPE$proxytype);
        
    curl_setopt($chCURLOPT_PROXY$proxy);
        if (
    $loginpassw!="0:0"){
            
    curl_setopt($chCURLOPT_PROXYUSERPWD$loginpassw);
            }
        
    curl_setopt($chCURLOPT_VERBOSE0);
        
    curl_setopt($chCURLOPT_COOKIEJARstr_replace('\\','/',dirname(__FILE__)).'/cookies/'.$cookies.'.txt');
        
    curl_setopt($chCURLOPT_COOKIEFILEstr_replace('\\','/',dirname(__FILE__)).'/cookies/'.$cookies.'.txt');
        
    $htmlcurl_exec($ch);
        
    $err 0;
        
    $err curl_errno($ch);
        
    curl_close($ch);
        if (
    $err!=0){
            echo 
    "<b>Error Connecting To Proxy. CURL Error: $err.</b><br />";
            return(
    false);
            }
        
    $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
        
    $content str_replace($newlines""html_entity_decode($html));
        return 
    $content;
        }
    $proxy "xxx";
    $port "xxx";
    $loginpassw "0:0";
    $useragent "Mozilla/5.0 (Windows NT 5.0; U; en-GB; rv:1.8.1) Gecko/20061208 Firefox/2.0.0 Opera 9.61";
    $proxytype "CURLPROXY_SOCKS5";
    $content Return_Content_From_URL_Agent("http://www.mysite.com/test.php","cookies",$proxy,$port,$loginpassw,$useragent,$proxytype);
    echo 
    "<textarea>$content</textarea>";
    ?>
    Yet again, if I change the request URL to:
    Code:
    https://www.mysite.com/test.php
    (Note the https://) it works just fine.

    I cannot work out for the life of me why https:// will work fine and http:// wont when exactly the same script on HTTP proxies works just fine.

    Any ideas?
    Last edited by Sussex_Chris; 06-25-2010 at 02:59 PM.

  • #2
    120
    120 is offline
    Regular Coder
    Join Date
    Nov 2009
    Location
    UK
    Posts
    105
    Thanks
    6
    Thanked 15 Times in 15 Posts
    Chris, that does not read well to me - so can I just clarify and ask a couple of supplementary questions?

    If you call your 'echoback' script that repeats the called URL/I directly from a browser it gives the correct results as in:

    Code:
    http://host/uri
    But if you call it with your Curl script that makes use of a socks5 proxy you get:

    Code:
    http://host/http://host/uri
    What if you call it with your Curl script without specifying a socks5 proxy? What happens then? What is the target server (Apache/IIS/other)?

    I note your comment about it working with https but failing with http. Is your SOCKS5 proxy actually handling the https request as a 'man in the middle' or is it bypassed for https?

    I've played with that code Chris and I can't recreate the doubling of the host. My logical guess is *something* is appending the server name to the URI {$_SERVER["REQUEST_URI"]} directive. I guess a URI could quite legally include the server name but it begs the question 'why not consistently?'
    There is always plenty of idol work for the devils hands to do
    Registered Linux User 475075 : Project Honeypot


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •