Foro de elhacker.net

Seguridad Informática => Criptografía => Mensaje iniciado por: deurus en 5 Septiembre 2011, 18:44 pm



Título: Reto: descifrar archivo
Publicado por: deurus en 5 Septiembre 2011, 18:44 pm
Haber si alguien me puede ayudar con esto. Tengo un fichero cifrado y ya que no estoy muy familiarizado con Java me gustaría que alguien me echara una mano.

Si alguien se anima le mando lo que tengo por email ya que supongo que teniendo los datos de cifrado, contruir un desencriptador será facilillo. Si quieres los archivos ponte en contacto conmigo.

Un saludo y gracias

Esto es un resumen de lo que tengo:

cifrado
------------
Tipo: PBEWithMD5AndDES
iterationCount = 19;
byte salt[] = {-87, -101, -56, 50, 86, 53, -29, 3 };
decryptPassword = "ESI";

-----------------
Cargar demos.java
-----------------
               try
                {
stream = Application1.crypto.decrypt((java.lang.Object.class).getResourceAsStream("/project/modulo" + demos.substring(6, demos.length() - 4) + ".xml"));
                    if(stream != null)
                    {
                        demosAMostrar = demosAMostrar + demos.substring(6, demos.length() - 4) + ";";
                        stream.close();
                    }
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                }
            }

-----------------------------
Crypto.java (solo el decrypt)
----------- -----------------

    public InputStream decrypt(InputStream in)
    {
        if(AccederADatos.leer("h.desencriptarModulos").compareToIgnoreCase("S\355") == 0) //a omitir
            try
            {
                in = new CipherInputStream(in, dcipher);
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
        return in;
    }

-----------------
Application1.java
-----------------
    static
    {
        crypto = new Crypto(AccederADatos.decryptPassword);
    }

------------
Applet1.java
------------

AccederADatos.decryptPassword = "ESI";





















Título: Re: Reto: descifrar archivo
Publicado por: deurus en 6 Septiembre 2011, 22:40 pm
Me he construido un desencriptador pero todavía falla algo, alguien ve por que falla el código???

import java.io.*;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.util.*;

public class FileDecryptor_custom
{
   private static String filename;
   private static String password;
   private static FileInputStream inFile;
   private static FileOutputStream outFile;
   //-----
   //bufi = new byte[1024];
   //m_buffer = new byte[10240];

   /**
    * Note: All kinds of exceptions can be thrown in main.
    * See the API documentation for each method used.
    */

   public static void main(String[] args) throws Exception
   {

      // File to decrypt.

      filename = "modulo1.xml";

      String password = "ESI";

      inFile = new FileInputStream(filename);
      outFile = new FileOutputStream(filename + "_decrypted");

      PBEKeySpec keySpec = new PBEKeySpec(password.toCharArray());
      SecretKeyFactory keyFactory =  SecretKeyFactory.getInstance("PBEWithMD5AndDES");
      SecretKey passwordKey = keyFactory.generateSecret(keySpec);

      // Read in the previouly stored salt and set the iteration count.

     // 8-byte Salt
         byte[] salt = {
         (byte)0xA9, (byte)0x9B, (byte)0xC8, (byte)0x32,
         (byte)0x56, (byte)0x35, (byte)0xE3, (byte)0x03
    };
      inFile.read(salt);
      int iterations = 19;

      PBEParameterSpec parameterSpec = new PBEParameterSpec(salt, iterations);
      // Create the cipher and initialize it for decryption.
      Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES");
      cipher.init(Cipher.DECRYPT_MODE, passwordKey, parameterSpec);

      //byte[] input = new byte[64];
      byte[] input = new byte[10240];
      int bytesRead;
      while ((bytesRead = inFile.read(input)) != -1)
      //while ((bytesRead = inFile.read(input)) > -1)
      {
         byte[] output = cipher.update(input, 0, bytesRead);
         //byte[] output = cipher.update(input, 0, bytesRead);
         if (output != null)
            outFile.write(output);
      }

      byte[] output = cipher.doFinal();
      if (output != null)
         outFile.write(output);

      inFile.close();
      outFile.flush();
      outFile.close();
  }
}


Título: Re: Reto: descifrar archivo
Publicado por: deurus en 8 Septiembre 2011, 11:57 am
Para el que le interese, los archivos se encuentran aquí (http://www.megaupload.com/?d=W1TT6BX5):



Título: Re: Reto: descifrar archivo
Publicado por: deurus en 7 Noviembre 2012, 15:03 pm
Reto superado. Para el que le interese aquí tiene el enlace del como se hizo con todos los archivos.

http://ul.to/94hfrf0c