Hack x Crack - Comunidad de Seguridad informática

Programación => Programación Web => Mensaje iniciado por: BigBear en Enero 08, 2016, 07:22:06 pm

Título: [PHP] Ban System 0.3
Publicado por: BigBear en Enero 08, 2016, 07:22:06 pm
Un simple script en PHP para banear una IP en una pagina.

Una imagen :

(http://doddyhackman.webcindario.com/images/ban_system.jpg)

Los codigos :

index.php

Código: PHP
  1. <?php
  2.  
  3. // Ban System 0.3
  4. // (C) Doddy Hackman 2015
  5.  
  6. // Login
  7.  
  8. $username = "admin"; // Edit
  9. $password = "21232f297a57a5a743894a0e4a801fc3"; // Edit
  10.  
  11. //
  12.  
  13. $index = "admin.php"; // Edit
  14.  
  15. if (isset($_GET['poraca'])) {
  16.    
  17.     echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  18.  
  19. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  20. <html xmlns="http://www.w3.org/1999/xhtml">
  21.   <head>
  22.      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  23.      <title>Login</title>
  24.      <link rel="shortcut icon" href="images/icono.png">
  25.      <link href="style.css" rel="stylesheet" type="text/css" />
  26.   </head>
  27.   <body>
  28.      <center><br>
  29.         <div class="post">
  30.            <h3>Login</h3>
  31.            <div class="post_body">
  32.               <img src="images/login.jpg" width="562" height="440" />
  33.               <br />
  34.               <form action="" method=POST>
  35.                  Username : <input type=text size=30 name=username /><br
  36.  
  37. /><br />
  38.                  Password : <input type=password size=30 name=password
  39.  
  40. /><br /><br />
  41.                  <input type=submit name=login style="width: 100px;"
  42.  
  43. value=Login /><br /><br />
  44.               </form>
  45.            </div>
  46.         </div>
  47.      </center>
  48.   </body>
  49. </html>';
  50.    
  51.     if (isset($_POST['login'])) {
  52.        
  53.         $test_username = $_POST['username'];
  54.         $test_password = md5($_POST['password']);
  55.        
  56.         if ($test_username == $username && $test_password == $password) {
  57.             setcookie("login", base64_encode($test_username . "@" . $test_password));
  58.             echo "<script>alert('Welcome idiot');</script>";
  59.             $ruta = "http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/" . $index;
  60.             echo '<meta http-equiv="refresh" content="0; url=' . htmlentities($ruta) . '"
  61.  
  62. />';
  63.         } else {
  64.             echo "<script>alert('Fuck You');</script>";
  65.         }
  66.     }
  67.    
  68. } else {
  69.     echo '<meta http-equiv="refresh" content="0;
  70.  
  71. url=http://www.petardas.com" />';
  72. }
  73.  
  74. // The End ?
  75.  
  76. ?>
  77.  

admin.php

Código: PHP
  1. <?php
  2.  
  3. // Ban System 0.3
  4. // (C) Doddy Hackman 2015
  5.  
  6.  
  7. // Login
  8.  
  9. $username = "admin"; // Edit
  10. $password = "21232f297a57a5a743894a0e4a801fc3"; // Edit
  11.  
  12. // DB
  13.  
  14. $host  = "localhost"; // Edit
  15. $userw = "root"; // Edit
  16. $passw = ""; // Edit
  17. $db    = "ban"; // Edit
  18.  
  19. if (isset($_COOKIE['login'])) {
  20.    
  21.     $st = base64_decode($_COOKIE['login']);
  22.    
  23.     $plit = explode("@", $st);
  24.     $user = $plit[0];
  25.     $pass = $plit[1];
  26.    
  27.     if ($user == $username and $pass == $password) {
  28.        
  29.         mysql_connect($host, $userw, $passw);
  30.         mysql_select_db($db);
  31.        
  32.         echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  33. <html xmlns="http://www.w3.org/1999/xhtml">
  34.   <head>
  35.      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  36.      <title>Ban System 0.3</title>
  37.      <link href="style.css" rel="stylesheet" type="text/css" />
  38.      <link rel="shortcut icon" href="images/icono.png">
  39.   </head>
  40.   <body>
  41.   <center>';
  42.        
  43.         mysql_connect($host, $userw, $passw);
  44.         mysql_select_db($db);
  45.        
  46.         echo '         <br><img src="images/ban.png" /><br><br>';
  47.        
  48.         if (isset($_POST['instalar'])) {
  49.            
  50.             $todo = "create table ban_system (
  51. id int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  52. ip TEXT NOT NULL,
  53. PRIMARY KEY(id));
  54. ";
  55.            
  56.             if (mysql_query($todo)) {
  57.                 echo "<script>alert('Installed');</script>";
  58.                 echo '<meta http-equiv="refresh" content=0;URL=>';
  59.             } else {
  60.                 echo "<script>alert('Error');</script>";
  61.             }
  62.         }
  63.        
  64.         if (mysql_num_rows(mysql_query("show tables like 'ban_system'"))) {
  65.            
  66.             echo "<title>Ban System 0.3 Administracion</title>";
  67.            
  68.             if (isset($_POST['ipadd'])) {
  69.                
  70.                 $ipfinal = ip2long($_POST['ipadd']);
  71.                 $ipaz    = $_POST['ipadd'];
  72.                
  73.                 if ($ipfinal == -1 || $ipfinal === FALSE) {
  74.                     echo "<script>alert('IP invalid');</script>";
  75.                    
  76.                 } else {
  77.                    
  78.                     if (mysql_query("INSERT INTO ban_system (id,ip) values (NULL,'$ipaz')")) {
  79.                         echo "<script>alert('IP added');</script>";
  80.                     } else {
  81.                         echo "<script>alert('Error');</script>";
  82.                     }
  83.                    
  84.                    
  85.                 }
  86.             }
  87.            
  88.             if (isset($_GET['del'])) {
  89.                 $id = $_GET['del'];
  90.                 if (@mysql_query("DELETE FROM ban_system where id ='$id'")) {
  91.                     echo "<script>alert('IP Deleted');</script>";
  92.                 } else {
  93.                     echo "<script>alert('Error');</script>";
  94.                 }
  95.             }
  96.            
  97.             echo '
  98.            <div class="post">
  99.                <h3>Add IP</h3>
  100.                   <div class="post_body">';
  101.            
  102.             echo "<br>
  103. <form action='' method=POST>
  104. <b>IP : </b><input type=text name=ipadd value=127.0.0.1> <input type=submit style='width: 100px;' value=Add>
  105. </form><br>";
  106.            
  107.             echo '                </div>
  108.            </div>';
  109.            
  110.            
  111.             $sql       = "select id from ban_system";
  112.             $resultado = mysql_query($sql);
  113.             $cantidad  = mysql_num_rows($resultado);
  114.            
  115.             echo '
  116.            <div class="post">
  117.                <h3>Banned : ' . htmlentities($cantidad) . '</h3>
  118.                   <div class="post_body"><br>';
  119.            
  120.             if ($cantidad <= 0) {
  121.                 echo '<b>No entries found</b><br>';
  122.             } else {
  123.                
  124.                 echo '<table>
  125. <td><b>ID</b></td><td><b>IP</b></td><td><b>Option</b></td><tr>';
  126.                
  127.                 $sen = @mysql_query("select * from ban_system order by id ASC");
  128.                
  129.                 while ($ab = @mysql_fetch_array($sen)) {
  130.                    
  131.                     echo "<td>" . htmlentities($ab[0]) . "</td><td>" . htmlentities($ab[1]) . "</td><td><a href=?del=" . htmlentities($ab[0]) . ">Delete</a></td><tr>";
  132.                 }
  133.                
  134.                 echo '</table>';
  135.                
  136.             }
  137.            
  138.             echo '                <br></div>
  139.            </div>';
  140.            
  141.             echo "</table>
  142. </center>
  143. ";
  144.             //
  145.         } else {
  146.            
  147.             echo '
  148.            <div class="post">
  149.                <h3>Installer</h3>
  150.                   <div class="post_body">';
  151.            
  152.             echo "
  153. <form action='' method=POST>
  154. <h2>Do you want install Ban System ?</h2><br>
  155. <input type=submit style='width: 100px;' name=instalar value=Install><br><br>
  156. </form>";
  157.            
  158.             echo '                </div>
  159.            </div>';
  160.            
  161.         }
  162.        
  163.         echo '
  164.   <br><h3>(C) Doddy Hackman 2015</h3><br>
  165.   </center>
  166.   </body>
  167. </html>';
  168.        
  169.         mysql_close();
  170.         exit(1);
  171.        
  172.     } else {
  173.         echo "<script>alert('Fuck You');</script>";
  174.     }
  175. } else {
  176.     echo '<meta http-equiv="refresh" content="0; url=http://www.petardas.com" />';
  177. }
  178.  
  179. ?>
  180.  

style.css

Código: CSS
  1. /*
  2.  
  3. ==-----------------------------------==
  4. || Name : DH Theme                   ||
  5. || Version : 0.8                     ||  
  6. || Author : Doddy H                  ||
  7. || Description: Templante            ||
  8. || Date : 14/1/2015                  ||
  9. ==-----------------------------------==
  10.  
  11. */
  12.  
  13. body {
  14.         background:transparent url("images/fondo.jpg") repeat scroll 0 0;
  15.         color:gray;
  16.         font-family:helvetica,arial,sans-serif;
  17.         font-size:14px;
  18.         text-align:center;
  19. }
  20.  
  21. a:link {
  22.         text-decoration:none;
  23.         color:orange;
  24. }
  25. a:visited {
  26.         color:orange;
  27. }
  28. a:hover {
  29.         color:orange;
  30. }
  31.  
  32. td,tr {
  33.         border-style:solid;
  34.         border-color: gray;
  35.         border-width: 1px;
  36.         background: black;
  37.         border: solid #222 2px;
  38.         color:gray;
  39.         font-family:helvetica,arial,sans-serif;
  40.         font-size:14px;
  41.         text-align:center;
  42.  
  43.         word-wrap: break-word;
  44.         word-break:break-all;
  45. }
  46.  
  47. input {
  48.         border-style:solid;
  49.         border-color: gray;
  50.         border-width: 1px;
  51.         background: black;
  52.         border: solid #222 2px;
  53.         color:gray;
  54.         font-family:helvetica,arial,sans-serif;
  55.         font-size:14px;
  56. }
  57.  
  58. .post {
  59.         background-color:black;
  60.         color:gray;
  61.         margin-bottom:10px;
  62.         width:600px;
  63.         word-wrap: break-word;
  64. }
  65.  
  66. .post h3 {
  67.         background-color:black;
  68.         color:orange;
  69.         background-color:#000;
  70.         border: solid #222 2px;
  71.         -webkit-border-radius: 4px;
  72.         -moz-border-radius: 4px;
  73.         border-radius: 4px;
  74.         padding:5px 10px;
  75. }
  76.  
  77. .post_body {
  78.         background-color:black;
  79.         margin:-20px 0 0 0;
  80.         color:white;
  81.         background-color:#000;
  82.         border: solid #222 2px;
  83.         -webkit-border-radius: 4px;
  84.         -moz-border-radius: 4px;
  85.         border-radius: 4px;
  86.         padding:5px 10px;
  87. }
  88.  
  89. /* The End ? */
  90.  

ban.php

Código: PHP
  1. <?php
  2.  
  3. // Ban System 0.3
  4. // (C) Doddy Hackman 2015
  5.  
  6.  
  7. // DB
  8.  
  9. $host  = "localhost"; // Edit
  10. $userw = "root"; // Edit
  11. $passw = ""; // Edit
  12. $db    = "ban"; // Edit
  13.  
  14. //
  15.  
  16. $texto = "Acceso Denegado"; // Edit
  17.  
  18. mysql_connect($host, $userw, $passw);
  19.  
  20. $ipa = ip2long($_SERVER['REMOTE_ADDR']);
  21. $ip  = $_SERVER['REMOTE_ADDR'];
  22.  
  23. if ($ip == "::1") {
  24.     $ipa = 1;
  25. }
  26.  
  27. if ($ipa == -1 || $ipa === FALSE) {
  28.     echo "<script>alert('Good try');</script>";
  29. } else {
  30.    
  31.     if ($ip == "::1") {
  32.         $ip = "127.0.0.1";
  33.     }
  34.     $re = mysql_query("select ip from ban_system where ip='$ip'");
  35.    
  36.     if (mysql_num_rows($re) > 0) {
  37.         echo "<center><h1>" . htmlentities($texto) . "</h1></center>";
  38.         exit(1);
  39.     }
  40.    
  41. }
  42.  
  43.  
  44. // The End ?
  45.  
  46. ?>
  47.  

test.php

Código: PHP
  1. <?php
  2.  
  3. include("ban.php");
  4.  
  5. echo "aca toy";
  6.  
  7. ?>
  8.  

Si quieren bajar el programa lo pueden hacer de aca (https://sourceforge.net/projects/bansystem/).