Prototipo: Crackeador PDF Java

Posted on 10:52 by Xianur0

Ultimamente he estado algo fuera, por x.25sec, programando, diseñando, etc...
Pero entre ese tiempo tambien estoy diseñando algunos codigos individuales, en este caso un crackeador PDF, aun es un "prototipo", pues se podria mejorar mucho, bueno se los comparto, y se aceptan cualquier sugerencia para mejorar el funcionamiento :)...



package pdfcracker;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.pdfbox.pdmodel.PDDocument;
/**
*
* @author xianur0
*/
class TestTh extends Thread {
private String filename;
private String passs;
private int caractermin = 32;
private int caractermax = 127;
private static PDDocument document = null;
public static int passwd[];
public static int largopass = 1;
public static boolean available = false;
public TestTh(String filename, int caractermina, int caractermaxa, PDDocument documento, int pass[]) {
caractermin = caractermina;
caractermax = caractermaxa;
passwd = pass;
document = documento;
}
public synchronized String aumentar()
{
while(available == true) {
try {
wait();
} catch (InterruptedException e) { }
}
available = true;
int tamarray = passwd.length;
passwd[tamarray-1]++;
for(int posicion = tamarray-1;posicion>=0;posicion--) {
if(passwd[posicion] > caractermax) {
if(posicion == 0) {
largopass++;
System.out.println(new StringBuilder().append("Aumentado a ").append(largopass).append(" caracteres").toString());
int tmp[] = new int[tamarray+1];
for(int ia = tamarray-1;ia>=0;ia--) {
tmp[ia+1] = passwd[ia];
if(ia == 0) tmp[0] = caractermin;
}
passwd = tmp;
passwd[1] = caractermin;
tamarray++;
} else {
passwd[posicion] = caractermin;
passwd[posicion-1]++;
}
}
}
StringBuilder passbuff = new StringBuilder();
for(int posicion = 0;posicion<tamarray;posicion++)
passbuff.append((char) passwd[posicion]);
notifyAll();
return passbuff.toString();
}
public synchronized Boolean comprobar(String filename,String pass) {
while(available == false) {
try {
wait();
} catch (InterruptedException e) { }
}
available = false;
try {
if(!document.isEncrypted()) {
System.out.println("Archivo no encriptado!");
System.exit(1);
} else {
document.decrypt(pass);
}
} catch (Exception ex) {
}
if(!document.isEncrypted()) {
notifyAll();
return true;
} else {
notifyAll();
return false;
}
}
public void run() {
while(true) {
passs = aumentar();
if(comprobar(filename,passs)) {
System.out.println(new StringBuilder().append("Password encontrada: ").append(passs).toString());
System.exit(0);
}
}
}
}


public class Main {
static String filename = "";
static int threadsausar = 1;
static int caractermin = 48;
static int caractermax = 57;
public static void main(String args[] ) {
if(args.length < 4) {
System.out.println("Uso: java -jar crackeador.jar [archivo] [numeros/todo] [N. caracteres] [Threads a usar]");
System.exit(-1);
}
filename = args[0];
if(args[1].equals("numeros")) { caractermin = 48; caractermax = 57;}
else if(args[1].equals("todo")) { caractermin = 32; caractermax = 127;}
else { System.out.println("Rango invalido!\n"); System.exit(-1);}
int nca = 0;
try {
nca = Integer.parseInt(args[2]);
} catch(Exception ex) {
System.out.println("N caracter invalido!\n");
System.exit(-1);
}
int pass[];
if(nca > 0) { pass = new int[nca]; for(int inis = 0; inis < nca; inis++) {pass[inis] = caractermin;} } else { pass = new int[1]; pass[0] = caractermin; }
PDDocument document = null;
try {
document = PDDocument.load(filename);
} catch (IOException ex) {
Logger.getLogger(TestTh.class.getName()).log(Level.SEVERE, null, ex);
}
if(Integer.parseInt(args[3]) > 0) threadsausar = Integer.parseInt(args[3]);
TestTh[] t1 = new TestTh[threadsausar];
System.out.println(new StringBuilder().append("Desplegando ").append(threadsausar).append(" threads").toString());
for(int tr = 0; tr < threadsausar; tr++) {
t1[tr] = new TestTh(filename,caractermin,caractermax,document, pass);
t1[tr].start();
}
System.out.println("Desplegados...\n");
}
}



Bytez Xianur0

1 comentarios:

ricardowiba dijo...

chocherita, y dime, para que sirve este crackeador?