Ejemplo aplicación vulnerable, para mayor información:
Last active
May 26, 2017 11:12
-
-
Save fitorec/9b8312d83a2b4aa902b38aee4a067962 to your computer and use it in GitHub Desktop.
Ejemplo aplicación vulnerable SQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE `usuarios` ( | |
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, | |
`username` VARCHAR(15) NOT NULL UNIQUE KEY, | |
`password` CHAR(32) NOT NULL , | |
`fecha_nacimiento` DATE NOT NULL | |
) ENGINE = InnoDB; | |
-- Agregando dos usuarios | |
INSERT INTO `usuarios` | |
(`id`, `username`, `password`, `fecha_nacimiento`) VALUES | |
(NULL, 'fitorec', 'ABC123456...', NOW()), | |
(NULL, 'pepe_grillo', 'ABC123456...', NOW()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package inyeccionsql; | |
import java.sql.Connection; | |
import java.sql.DriverManager; | |
public class BD { | |
private static Connection conexion = null; | |
private static String host = "localhost"; | |
private static String port = "3306"; | |
private static String bd = "test"; | |
private static String user = "root"; | |
private static String password = ""; | |
// El constructor privado no permite que se generen clases | |
private BD() {} | |
public static Connection getConexion() { | |
if (BD.conexion == null) { | |
BD.conectar(); | |
} | |
return BD.conexion; | |
} | |
private static void conectar() { | |
try { | |
DriverManager.registerDriver(new com.mysql.jdbc.Driver()); | |
BD.conexion = DriverManager.getConnection ("jdbc:mysql://" + BD.host + ":" + BD.port + "/" + BD.bd, | |
BD.user, | |
BD.password | |
); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Licencia MIT | |
* | |
* Copyright (c) 2017 @Fitorec <chanerec at gmail.com>. | |
* | |
* Se concede permiso, de forma gratuita, a cualquier persona que obtenga una | |
* copia de este software y de los archivos de documentación asociados | |
* (el "Software"), para utilizar el Software sin restricción, incluyendo sin | |
* limitación los derechos a usar, copiar, modificar, fusionar, publicar, | |
* distribuir, sublicenciar, y/o vender copias del Software, y a permitir a las | |
* personas a las que se les proporcione el Software a hacer lo mismo, sujeto a | |
* las siguientes condiciones: | |
* | |
* El aviso de copyright anterior y este aviso de permiso se incluirán en todas | |
* las copias o partes sustanciales del Software. | |
* | |
* EL SOFTWARE SE PROPORCIONA "TAL CUAL", SIN GARANTÍA DE NINGÚN TIPO, EXPRESA O | |
* IMPLÍCITA, INCLUYENDO PERO NO LIMITADO A GARANTÍAS DE COMERCIALIZACIÓN, | |
* IDONEIDAD PARA UN PROPÓSITO PARTICULAR Y NO INFRACCIÓN. EN NINGÚN CASO LOS | |
* AUTORES O TITULARES DEL COPYRIGHT SERÁN RESPONSABLES DE NINGUNA RECLAMACIÓN, | |
* DAÑOS U OTRAS RESPONSABILIDADES, YA SEA EN UNA ACCIÓN DE CONTRATO, AGRAVIO O | |
* CUALQUIER OTRO MOTIVO, QUE SURJA DE O EN CONEXIÓN CON EL SOFTWARE O EL USO U | |
* OTRO TIPO DE ACCIONES EN EL SOFTWARE. | |
* | |
*/ | |
package inyeccionsql; | |
import javafx.application.Application; | |
import javafx.fxml.FXMLLoader; | |
import javafx.scene.Parent; | |
import javafx.scene.Scene; | |
import javafx.stage.Stage; | |
/** | |
* | |
* @author @Fitorec <chanerec at gmail.com> | |
*/ | |
public class InyeccionSQL extends Application { | |
@Override | |
public void start(Stage stage) throws Exception { | |
Parent root = FXMLLoader.load(getClass().getResource("LoginVista.fxml")); | |
Scene scene = new Scene(root); | |
stage.setScene(scene); | |
stage.show(); | |
} | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) { | |
launch(args); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<?import javafx.scene.text.*?> | |
<?import java.lang.*?> | |
<?import java.util.*?> | |
<?import javafx.scene.*?> | |
<?import javafx.scene.control.*?> | |
<?import javafx.scene.layout.*?> | |
<AnchorPane id="AnchorPane" prefHeight="299.0" prefWidth="320" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" stylesheets="@./style.css" fx:controller="inyeccionsql.LoginVistaController"> | |
<children> | |
<Button fx:id="button" layoutX="116.0" layoutY="260.0" onAction="#accionLogin" text="Login" /> | |
<Label fx:id="label" layoutX="73.0" layoutY="233.0" minHeight="16" minWidth="69" prefHeight="17.0" prefWidth="133.0" /> | |
<TextField fx:id="username" layoutX="74.0" layoutY="68.0" /> | |
<PasswordField fx:id="password" layoutX="74.0" layoutY="125.0" /> | |
<Text layoutX="74.0" layoutY="56.0" strokeType="OUTSIDE" strokeWidth="0.0" text="username" wrappingWidth="97.837890625" /> | |
<Text layoutX="74.0" layoutY="121.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Password" /> | |
</children> | |
</AnchorPane> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Licencia MIT | |
* | |
* Copyright (c) 2017 @Fitorec <chanerec at gmail.com>. | |
* | |
* Se concede permiso, de forma gratuita, a cualquier persona que obtenga una | |
* copia de este software y de los archivos de documentación asociados | |
* (el "Software"), para utilizar el Software sin restricción, incluyendo sin | |
* limitación los derechos a usar, copiar, modificar, fusionar, publicar, | |
* distribuir, sublicenciar, y/o vender copias del Software, y a permitir a las | |
* personas a las que se les proporcione el Software a hacer lo mismo, sujeto a | |
* las siguientes condiciones: | |
* | |
* El aviso de copyright anterior y este aviso de permiso se incluirán en todas | |
* las copias o partes sustanciales del Software. | |
* | |
* EL SOFTWARE SE PROPORCIONA "TAL CUAL", SIN GARANTÍA DE NINGÚN TIPO, EXPRESA O | |
* IMPLÍCITA, INCLUYENDO PERO NO LIMITADO A GARANTÍAS DE COMERCIALIZACIÓN, | |
* IDONEIDAD PARA UN PROPÓSITO PARTICULAR Y NO INFRACCIÓN. EN NINGÚN CASO LOS | |
* AUTORES O TITULARES DEL COPYRIGHT SERÁN RESPONSABLES DE NINGUNA RECLAMACIÓN, | |
* DAÑOS U OTRAS RESPONSABILIDADES, YA SEA EN UNA ACCIÓN DE CONTRATO, AGRAVIO O | |
* CUALQUIER OTRO MOTIVO, QUE SURJA DE O EN CONEXIÓN CON EL SOFTWARE O EL USO U | |
* OTRO TIPO DE ACCIONES EN EL SOFTWARE. | |
* | |
*/ | |
package inyeccionsql; | |
import java.net.URL; | |
import java.sql.PreparedStatement; | |
import java.sql.ResultSet; | |
import java.util.ResourceBundle; | |
import javafx.event.ActionEvent; | |
import javafx.fxml.FXML; | |
import javafx.fxml.Initializable; | |
import javafx.scene.control.Label; | |
import javafx.scene.control.PasswordField; | |
import javafx.scene.control.TextField; | |
/** | |
* | |
* @author @Fitorec <chanerec at gmail.com> | |
*/ | |
public class LoginVistaController implements Initializable { | |
@FXML | |
private Label label; | |
@FXML | |
private TextField username; | |
@FXML | |
private PasswordField password; | |
@FXML | |
private void accionLogin(ActionEvent event) { | |
try { | |
String sql = "SELECT * FROM usuarios " | |
+ "WHERE username='"+username.getText() + "'" | |
+ " AND password='"+password.getText()+"'"; | |
PreparedStatement ps = BD.getConexion().prepareStatement(sql); | |
ResultSet r = ps.executeQuery(); | |
if (r.next()) { | |
username.setText(r.getString("username")); | |
label.setText("Bienvenido: " + username.getText()); | |
} else { | |
label.setText("Login invalido"); | |
} | |
} catch(Exception e){ | |
label.setText("Error SQL"); | |
} | |
} | |
@Override | |
public void initialize(URL url, ResourceBundle rb) { | |
// TODO | |
username.setOnAction(e -> password.requestFocus()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Licencia MIT | |
Copyright (c) 2017 @Fitorec <chanerec at gmail.com>. | |
Se concede permiso, de forma gratuita, a cualquier persona que obtenga una | |
copia de este software y de los archivos de documentación asociados | |
(el "Software"), para utilizar el Software sin restricción, incluyendo sin | |
limitación los derechos a usar, copiar, modificar, fusionar, publicar, | |
distribuir, sublicenciar, y/o vender copias del Software, y a permitir a las | |
personas a las que se les proporcione el Software a hacer lo mismo, sujeto a | |
las siguientes condiciones: | |
El aviso de copyright anterior y este aviso de permiso se incluirán en todas | |
las copias o partes sustanciales del Software. | |
EL SOFTWARE SE PROPORCIONA "TAL CUAL", SIN GARANTÍA DE NINGÚN TIPO, EXPRESA O | |
IMPLÍCITA, INCLUYENDO PERO NO LIMITADO A GARANTÍAS DE COMERCIALIZACIÓN, | |
IDONEIDAD PARA UN PROPÓSITO PARTICULAR Y NO INFRACCIÓN. EN NINGÚN CASO LOS | |
AUTORES O TITULARES DEL COPYRIGHT SERÁN RESPONSABLES DE NINGUNA RECLAMACIÓN, | |
DAÑOS U OTRAS RESPONSABILIDADES, YA SEA EN UNA ACCIÓN DE CONTRATO, AGRAVIO O | |
CUALQUIER OTRO MOTIVO, QUE SURJA DE O EN CONEXIÓN CON EL SOFTWARE O EL USO U | |
OTRO TIPO DE ACCIONES EN EL SOFTWARE. | |
*/ | |
/* | |
Created on : 13/05/2017, 02:27:18 PM | |
Author : @Fitorec <chanerec at gmail.com> | |
*/ | |
/** Contenedor principal **/ | |
AnchorPane { | |
-fx-background-color: linear-gradient(#B1B1AF, #A5A5A5); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment