Skip to content

Instantly share code, notes, and snippets.

@aplneto
Last active October 24, 2024 15:02
Show Gist options
  • Save aplneto/433d265c70a160373c52ae2362a52136 to your computer and use it in GitHub Desktop.
Save aplneto/433d265c70a160373c52ae2362a52136 to your computer and use it in GitHub Desktop.

Revisions

  1. aplneto renamed this gist Oct 24, 2024. 1 changed file with 7 additions and 19 deletions.
    26 changes: 7 additions & 19 deletions reflect-request.php → index.php
    Original file line number Diff line number Diff line change
    @@ -1,29 +1,17 @@
    <?php
    // Returns the content of HTTP Requests received

    // put output into file
    function file_callback($buffer)
    {
    $fh = fopen("/var/www/html/logs/" . $_SERVER['REMOTE_ADDR']. "_" . time() . ".txt", "w");
    fwrite($fh, $buffer);
    fclose($fh);

    return $buffer;
    }

    ob_start("file_callback");

    // Retorna o conteúdo da requisição em formato HTTP

    // Define o tipo de conteúdo como texto simples
    // Set content-type to plaintext to avoid XSS problems
    header("Content-Type: text/plain");

    // Imprime as informações da requisição
    // Request Method, URL and Protocol
    echo "{$_SERVER['REQUEST_METHOD']} {$_SERVER['REQUEST_URI']} {$_SERVER['SERVER_PROTOCOL']}\n";
    // Request Headers
    foreach (apache_request_headers() as $header => $value) {
    echo "$header: $value\n";
    }

    // Se houver dados de POST, imprime também
    // x-www-form-urlencoded post data
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $post_data_array = [];
    foreach ($_POST as $key => $value) {
    @@ -32,10 +20,10 @@ function file_callback($buffer)
    echo "\n\n" . join("&", $post_data_array);
    }

    // Se houver dados de JSON, imprime também
    // other post data
    $json = file_get_contents('php://input');
    if ($json) {
    echo $json;
    }

    ob_end_flush();
    // TODO add multipart/form-data support
  2. aplneto revised this gist Oct 24, 2024. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion .htaccess
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    RewriteEngine On
    RewriteRule ^grpc grpc.php [L]
    RewriteRule ^ index.php [L]
    RewriteRule ^\.htaccess$ - [F]
    RewriteRule ^config\.php$ - [F]
  3. aplneto revised this gist Oct 24, 2024. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions .htaccess
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    RewriteEngine On
    RewriteRule ^grpc grpc.php [L]
    RewriteRule ^ index.php [L]
    RewriteRule ^\.htaccess$ - [F]
    RewriteRule ^config\.php$ - [F]
    RewriteRule .* - [e=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
  4. aplneto renamed this gist Oct 24, 2024. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. aplneto created this gist Oct 24, 2024.
    41 changes: 41 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    <?php

    // put output into file
    function file_callback($buffer)
    {
    $fh = fopen("/var/www/html/logs/" . $_SERVER['REMOTE_ADDR']. "_" . time() . ".txt", "w");
    fwrite($fh, $buffer);
    fclose($fh);

    return $buffer;
    }

    ob_start("file_callback");

    // Retorna o conteúdo da requisição em formato HTTP

    // Define o tipo de conteúdo como texto simples
    header("Content-Type: text/plain");

    // Imprime as informações da requisição
    echo "{$_SERVER['REQUEST_METHOD']} {$_SERVER['REQUEST_URI']} {$_SERVER['SERVER_PROTOCOL']}\n";
    foreach (apache_request_headers() as $header => $value) {
    echo "$header: $value\n";
    }

    // Se houver dados de POST, imprime também
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $post_data_array = [];
    foreach ($_POST as $key => $value) {
    array_push($post_data_array, "$key=$value");
    }
    echo "\n\n" . join("&", $post_data_array);
    }

    // Se houver dados de JSON, imprime também
    $json = file_get_contents('php://input');
    if ($json) {
    echo $json;
    }

    ob_end_flush();