Un simple script en PHP para banear una IP en una pagina.

Una imagen :

Imagen


Los codigos :

index.php
<?php

// Ban System 0.3
// (C) Doddy Hackman 2015

// Login

$username = "admin"; // Edit
$password = "21232f297a57a5a743894a0e4a801fc3"; // Edit

//

$index = "admin.php"; // Edit

if (isset($_GET['poraca'])) {
    
    echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>Login</title>
      <link rel="shortcut icon" href="images/icono.png">
      <link href="style.css" rel="stylesheet" type="text/css" />
   </head>
   <body>
      <center><br>
         <div class="post">
            <h3>Login</h3>
            <div class="post_body">
               <img src="images/login.jpg" width="562" height="440" />
               <br />
               <form action="" method=POST>
                  Username : <input type=text size=30 name=username /><br 

/><br />
                  Password : <input type=password size=30 name=password 

/><br /><br />
                  <input type=submit name=login style="width: 100px;" 

value=Login /><br /><br />
               </form>
            </div>
         </div>
      </center>
   </body>
</html>';
    
    if (isset($_POST['login'])) {
        
        $test_username = $_POST['username'];
        $test_password = md5($_POST['password']);
        
        if ($test_username == $username && $test_password == $password) {
            setcookie("login", base64_encode($test_username . "@" . $test_password));
            echo "<script>alert('Welcome idiot');</script>";
            $ruta = "http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/" . $index;
            echo '<meta http-equiv="refresh" content="0; url=' . htmlentities($ruta) . '" 

/>';
        } else {
            echo "<script>alert('Fuck You');</script>";
        }
    }
    
} else {
    echo '<meta http-equiv="refresh" content="0; 

url=http://www.petardas.com" />';
}

// The End ?

?>
admin.php
<?php

// Ban System 0.3
// (C) Doddy Hackman 2015

error_reporting(0);

// Login

$username = "admin"; // Edit
$password = "21232f297a57a5a743894a0e4a801fc3"; // Edit

// DB

$host  = "localhost"; // Edit
$userw = "root"; // Edit
$passw = ""; // Edit
$db    = "ban"; // Edit

if (isset($_COOKIE['login'])) {
    
    $st = base64_decode($_COOKIE['login']);
    
    $plit = explode("@", $st);
    $user = $plit[0];
    $pass = $plit[1];
    
    if ($user == $username and $pass == $password) {
        
        mysql_connect($host, $userw, $passw);
        mysql_select_db($db);
        
        echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>Ban System 0.3</title>
      <link href="style.css" rel="stylesheet" type="text/css" />
      <link rel="shortcut icon" href="images/icono.png">
   </head>
   <body>
   <center>';
        
        mysql_connect($host, $userw, $passw);
        mysql_select_db($db);
        
        echo '         <br><img src="images/ban.png" /><br><br>';
        
        if (isset($_POST['instalar'])) {
            
            $todo = "create table ban_system (
id int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
ip TEXT NOT NULL,
PRIMARY KEY(id));
";
            
            if (mysql_query($todo)) {
                echo "<script>alert('Installed');</script>";
                echo '<meta http-equiv="refresh" content=0;URL=>';
            } else {
                echo "<script>alert('Error');</script>";
            }
        }
        
        if (mysql_num_rows(mysql_query("show tables like 'ban_system'"))) {
            
            echo "<title>Ban System 0.3 Administracion</title>";
            
            if (isset($_POST['ipadd'])) {
                
                $ipfinal = ip2long($_POST['ipadd']);
                $ipaz    = $_POST['ipadd'];
                
                if ($ipfinal == -1 || $ipfinal === FALSE) {
                    echo "<script>alert('IP invalid');</script>";
                    
                } else {
                    
                    if (mysql_query("INSERT INTO ban_system (id,ip) values (NULL,'$ipaz')")) {
                        echo "<script>alert('IP added');</script>";
                    } else {
                        echo "<script>alert('Error');</script>";
                    }
                    
                    
                }
            }
            
            if (isset($_GET['del'])) {
                $id = $_GET['del'];
                if (@mysql_query("DELETE FROM ban_system where id ='$id'")) {
                    echo "<script>alert('IP Deleted');</script>";
                } else {
                    echo "<script>alert('Error');</script>";
                }
            }
            
            echo '
            <div class="post">
                <h3>Add IP</h3>
                   <div class="post_body">';
            
            echo "<br>
<form action='' method=POST>
<b>IP : </b><input type=text name=ipadd value=127.0.0.1> <input type=submit style='width: 100px;' value=Add>
</form><br>";
            
            echo '                </div>
            </div>';
            
            
            $sql       = "select id from ban_system";
            $resultado = mysql_query($sql);
            $cantidad  = mysql_num_rows($resultado);
            
            echo '
            <div class="post">
                <h3>Banned : ' . htmlentities($cantidad) . '</h3>
                   <div class="post_body"><br>';
            
            if ($cantidad <= 0) {
                echo '<b>No entries found</b><br>';
            } else {
                
                echo '<table>
<td><b>ID</b></td><td><b>IP</b></td><td><b>Option</b></td><tr>';
                
                $sen = @mysql_query("select * from ban_system order by id ASC");
                
                while ($ab = @mysql_fetch_array($sen)) {
                    
                    echo "<td>" . htmlentities($ab[0]) . "</td><td>" . htmlentities($ab[1]) . "</td><td><a href=?del=" . htmlentities($ab[0]) . ">Delete</a></td><tr>";
                }
                
                echo '</table>';
                
            }
            
            echo '                <br></div>
            </div>';
            
            echo "</table>
</center>
";
            //
        } else {
            
            echo '
            <div class="post">
                <h3>Installer</h3>
                   <div class="post_body">';
            
            echo "
<form action='' method=POST>
<h2>Do you want install Ban System ?</h2><br>
<input type=submit style='width: 100px;' name=instalar value=Install><br><br>
</form>";
            
            echo '                </div>
            </div>';
            
        }
        
        echo '
   <br><h3>(C) Doddy Hackman 2015</h3><br>
   </center>
   </body>
</html>';
        
        mysql_close();
        exit(1);
        
    } else {
        echo "<script>alert('Fuck You');</script>";
    }
} else {
    echo '<meta http-equiv="refresh" content="0; url=http://www.petardas.com" />';
}

?>
style.css
/*

==-----------------------------------==
|| Name : DH Theme                   ||
|| Version : 0.8                     ||  
|| Author : Doddy H                  ||
|| Description: Templante            ||
|| Date : 14/1/2015                  ||
==-----------------------------------==

*/

body {
	background:transparent url("images/fondo.jpg") repeat scroll 0 0;
	color:gray;
	font-family:helvetica,arial,sans-serif;
	font-size:14px;
	text-align:center;
}

a:link {
	text-decoration:none;
	color:orange;
}
a:visited {
	color:orange;
}
a:hover {
	color:orange;
}

td,tr {
	border-style:solid;
	border-color: gray;
	border-width: 1px;
	background: black;
	border: solid #222 2px;
	color:gray;
	font-family:helvetica,arial,sans-serif;
	font-size:14px;
	text-align:center;

	word-wrap: break-word;
	word-break:break-all; 
}

input {
	border-style:solid;
	border-color: gray;
	border-width: 1px;
	background: black;
	border: solid #222 2px;
	color:gray;
	font-family:helvetica,arial,sans-serif;
	font-size:14px;
}

.post {
	background-color:black;
	color:gray;
	margin-bottom:10px;
	width:600px;
	word-wrap: break-word;
}

.post h3 {
	background-color:black;
	color:orange;
	background-color:#000;
	border: solid #222 2px;
	-webkit-border-radius: 4px;
	-moz-border-radius: 4px;
	border-radius: 4px;
	padding:5px 10px;
}

.post_body {
	background-color:black;
	margin:-20px 0 0 0;
	color:white;
	background-color:#000;
	border: solid #222 2px;
	-webkit-border-radius: 4px;
	-moz-border-radius: 4px;
	border-radius: 4px;
	padding:5px 10px;
}

/* The End ? */
ban.php
<?php

// Ban System 0.3
// (C) Doddy Hackman 2015

error_reporting(0);

// DB

$host  = "localhost"; // Edit
$userw = "root"; // Edit
$passw = ""; // Edit
$db    = "ban"; // Edit

//

$texto = "Acceso Denegado"; // Edit

mysql_connect($host, $userw, $passw);
mysql_select_db($db);

$ipa = ip2long($_SERVER['REMOTE_ADDR']);
$ip  = $_SERVER['REMOTE_ADDR'];

if ($ip == "::1") {
    $ipa = 1;
}

if ($ipa == -1 || $ipa === FALSE) {
    echo "<script>alert('Good try');</script>";
} else {
    
    if ($ip == "::1") {
        $ip = "127.0.0.1";
    }
    $re = mysql_query("select ip from ban_system where ip='$ip'");
    
    if (mysql_num_rows($re) > 0) {
        echo "<center><h1>" . htmlentities($texto) . "</h1></center>";
        exit(1);
    }
    
}

mysql_close();

// The End ?

?>
test.php
<?php

include("ban.php");

echo "aca toy";

?>
Si quieren bajar el programa lo pueden hacer de [Enlace externo eliminado para invitados].
Responder

Volver a “PHP”