#1 30-12-2007 04:11:12

Thibow
Administrateur
Lieu: Nord
Date d'inscription: 17-12-2007
Messages: 633
Site web

PHP Proxy

Voici un petit proxy en php alors voici le code php :

(Attention, il n'est pas sécurisé, c'est un nid a Remote file inclusion...)

Je précise que c'est pas moi qui l'es codé mais le code est sympa donc ... voila smile

Code:

<?

        if (isset($_SERVER["PATH_INFO"])) {
                $url = $_SERVER["PATH_INFO"];
        }

        if (isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] != "") {
                $url .= "?" . $_SERVER["QUERY_STRING"];
        }

        $debug = false;

        $ref = array(
                        "host" => "http://" . $_SERVER["HTTP_HOST"],
                        "script" => $_SERVER["SCRIPT_NAME"]
                );

        if (isset($url) && $url != "") {

                $h_url = explode("/", eregi_replace("^/", "", $url));
                $host = $h_url[0];
                unset($h_url[0]);
                $rsc = implode($h_url);

                $request_method = isset($_SERVER["REQUEST_METHOD"]) ? $_SERVER["REQUEST_METHOD"] : "GET";

                $send_headers_name = array(
                                "HTTP_ACCEPT" => "Accept",
                                "HTTP_ACCEPT_CHARSET" => "Accept-Charset",
//                              "HTTP_ACCEPT_ENCODING" => "Accept-Encoding",
                                "HTTP_ACCEPT_LANGUAGE" => "Accept-Language",
//                              "HTTP_HOST" => "Host",
//                              "HTTP_CONNECTION" => "Connection",
                                "HTTP_USER_AGENT" => "User-Agent"
                        );
                $send_headers = array();
                foreach ($send_headers_name as $key => $value) {
                        if (isset($_SERVER[$key])) {
                                $send_headers[] = $value . ": " . $_SERVER[$key];
                        }
                }

                $send_headers[] = "Host: " . $host;

                foreach ($_COOKIE as $key => $value) {
                        $send_headers[] = "Cookie: " . $key . "=" . $value;
                }

                $opts = array(
                                "http" => array(
                                                 "method" => $request_method
                                        )
                        );

                if ($request_method == "POST") {
                        $opts["http"]["content"] = file_get_contents("php://input");
                        $send_headers[] = "Content-Type: application/x-www-form-urlencoded";
                        $send_headers[] = "Content-Length: " . strlen($opts["http"]["content"]);
                }

                if (count($send_headers) > 0) {
                        $opts["http"]["header"] = implode("\r\n", $send_headers) . "\r\n";
                }

                $ctx = stream_context_create($opts);

                $fp = @fopen(eregi_replace("^/", "http://", $url), "r", false, $ctx);
                if ($fp) {
                        $opts = stream_get_meta_data($fp);
                        $is_gzip = true;
                        $headers = array();
                        foreach ($opts["wrapper_data"] as $value) {
                                if (eregi("^HTTP", $value)) {
                                        $headers = array();
                                } else {
                                        $headers[] = $value;
                                }
                        }
                        foreach ($headers as $key => $value) {
                                if (eregi("^(Set-Cookie:)([ ]*[^;]*;)[ ]*Path=([^;]*)(.*)", $value, $reg)) {
                                        $headers[$key] = $value = $reg[1] . $reg[2] . " Path=" . $ref["script"] . "/" . $
host . $reg[3] . $reg[4];
  } else if (eregi("^(Content-Type:)[ ]*([^;]*)(.*)", $value, $reg)) {
                                        $content_type = $reg[2];
                                } else if (eregi("^(Content-Length:)[ ]*([^;]*)(.*)", $value, $reg)) {
                                        $content_length = $reg[2];
                                } else if (eregi("^(Connection:)[ ]*([^;]*)(.*)", $value)) {
                                        $cxHeader = $value;
                                        continue;
                                } else if (eregi("^Content-Encoding:[ ]*gzip", $value)) {
                                        $is_gzip = true;
                                }
                                header($value, true);
                        }

                        if ($content_type == "text/html") {
                                if ($debug) {

?><div style="background-color: #eef; display: block; position: absolute">
        <table border="0" cellpadding="2" cellspacing="1" style="width: 100%">
                <tbody>
 <tr><th colspan="2" style="border: 1px solid #ddd; text-align: left"><?= $request_method ?></th></tr>
                        <tr>
                                <td style="border: 1px solid #ddd; vertical-align: top; width: 50%"><?= implode("<br/>",
$send_headers) ?></td>
                                <td style="border: 1px solid #ddd; vertical-align: top; width: 50%"><?= implode("<br/>",
$headers) ?></td>
                        </tr>
                </tbody>
        </table>
</div>
<?
                                }

                                $content = "";
                                while (!feof($fp)) $content .= fread($fp, 8192);
                                echo preg_replace(
                                                array(
                                                                "/([ ]*(href|HREF|src|SRC|action|ACTION)=\")\/([^\"]*)/",
                                                                "/([ ]*(href|HREF|src|SRC|action|ACTION)=)\/([^ ]*)/",
                                                                "/((url|URL)=)\/([^\";]*)/",
                                                                "/(http|HTTP):\/\//",
                                                                "/(<(base|BASE)[^>]*>)/",
                                                                "/(<(head|HEAD)[^>]*>)/"
                                                        ),
                                                array(
                                                                "\\1" . $ref["script"] . "/" . $host . "/\\3",
                                                                "\\1\"" . $ref["script"] . "/" . $host . "/\\3\"",
                                                                "\\1" . $ref["script"] . "/" . $host . "/\\3",
                                                                $ref["host"] . $ref["script"] . "/",
                                                                "",
 "\\1<base href=\"" . $ref["host"] . $ref["script"] . $url
 . "\">"
                                                        ),
                                                $content
                                        );

                        } else {
                                if (!isset($content_length) || $content_length > (100 * 1024)) {
                                        header("Connection: Keep-Alive", true);
                                } else if (isset($cxHeader)) {
                                        header($cxHeader, true);
                                }
                                fpassthru($fp);
                        }

                        fclose($fp);

//                      exit();
                } else {
                        echo "unable to get content from " . $url . "<br/>";
                }
        } else {
?><html>
<head>
<style type="text/css">
* {
        font-family: Arial;
        font-size: 8pt;
}
</style>
</head>
<body>
no url defined
</body>
</html>
<?
        }

?>

Hors ligne

 

#2 31-12-2007 14:43:28

Matt
Insideur
Date d'inscription: 26-12-2007
Messages: 16
Site web

Re: PHP Proxy

ca fait quoi au juste ce code ?

Hors ligne

 

#3 31-12-2007 16:07:16

Thibow
Administrateur
Lieu: Nord
Date d'inscription: 17-12-2007
Messages: 633
Site web

Re: PHP Proxy

Tu la met sur un page de ton site par exemple, tu pourras naviguer sur d'autre site, en ayant l'ip du serveur qui heberge ton site ...

Hors ligne

 

#4 21-01-2008 13:33:18

cabusar
Administrateur
Date d'inscription: 18-01-2008
Messages: 430

Re: PHP Proxy

une manière de pas être détecté si je comprend bien ton explication? smile


smile big_smile lol tongue wink

Hors ligne

 

#5 21-01-2008 15:11:29

Thibow
Administrateur
Lieu: Nord
Date d'inscription: 17-12-2007
Messages: 633
Site web

Re: PHP Proxy

Hm pas tout a fait, enfin tout dépend le but final.

Disons que tu peux te cacher derriere l'ip de ton serveur grâce a ce script.

N'oublions pas qu'il est toujours possible de voir dans les logs les ip réél ...

Mais en effet, ça peut être un bon moyen de se cacher smile

Hors ligne

 

Pied de page des forums

Propulsé par PunBB
© Copyright 2002–2005 Rickard Andersson
Traduction par punbb.fr