Last active
August 29, 2015 14:13
-
-
Save codebucketdev/64000ea10445d10f65a9 to your computer and use it in GitHub Desktop.
With this snippet you can decrypt the password of a zipfile in Java using Zip4j (http://www.lingala.net/zip4j/).
This file contains hidden or 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 org.anonymous; | |
| import java.io.BufferedReader; | |
| import java.io.File; | |
| import java.io.IOException; | |
| import java.io.InputStreamReader; | |
| import net.lingala.zip4j.core.ZipFile; | |
| import net.lingala.zip4j.exception.ZipException; | |
| public class ZipDecrypter | |
| { | |
| public static void main(String[] args) | |
| { | |
| System.out.println("ZipDecrypter for Java VM"); | |
| System.out.println("Version 1.0, compiled on 10.January 2015 at 19:57."); | |
| System.out.println("(c) Copyright Codebucket 2015\n"); | |
| System.out.println("Decrypting password using brute-force..."); | |
| Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() | |
| { | |
| @Override | |
| public void run() | |
| { | |
| System.out.print("\n"); | |
| } | |
| })); | |
| ZipFile zipfile = null; | |
| if(args.length > 0 && args[0] != null) | |
| { | |
| File file = new File(args[0]); | |
| if(!file.exists()) | |
| { | |
| System.out.println("Cannot open file: File not exists!"); | |
| return; | |
| } | |
| try | |
| { | |
| zipfile = new ZipFile(file); | |
| } | |
| catch(Exception ex) | |
| { | |
| System.out.println("Cannot open file: Invalid or broken file!"); | |
| return; | |
| } | |
| } | |
| else | |
| { | |
| System.out.println("Cannot start application: Not enough arguments!"); | |
| return; | |
| } | |
| File tmpdir = null; | |
| try | |
| { | |
| File file = File.createTempFile("zip", "_tmp"); | |
| file.delete(); | |
| if(!file.exists()) | |
| { | |
| file.mkdirs(); | |
| } | |
| tmpdir = file; | |
| } | |
| catch(IOException ex) {} | |
| try | |
| { | |
| Thread.sleep((long) 2.5 * 1000L); | |
| } | |
| catch(InterruptedException ex) { /* Who cares the interrupted exception?! */ } | |
| Stringer pwd = new Stringer("all"); | |
| while(1 > 0) | |
| { | |
| String password = pwd.nextString(); | |
| if(checkPassword(zipfile, tmpdir, password)) | |
| { | |
| System.out.println("Zipfile sucessfully decrypted! The password is: " + password); | |
| break; | |
| } | |
| } | |
| } | |
| // public static final String CMD_SYNTAX = "{0}7za.exe t {1} -p{2}"; | |
| public static boolean checkPassword(ZipFile zip, File dir, String password) | |
| { | |
| try | |
| { | |
| zip.setPassword(password); | |
| zip.extractAll(dir.getAbsolutePath()); | |
| zip.setComment("Decrypted using ZipDecryptor for Java v1.0!"); | |
| } | |
| catch(ZipException ex) | |
| { | |
| return false; | |
| } | |
| return true; | |
| } | |
| public static class ConsoleUtils | |
| { | |
| /** | |
| * @Author Codebucket | |
| * a small collection of useful methods for the console output | |
| */ | |
| public static void clear() | |
| { | |
| String os = System.getProperty("os.name"); | |
| if(!(os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0 || os.indexOf("aix") > 0 )) | |
| { | |
| return; | |
| } | |
| System.out.print("\033[H\033[2J"); | |
| System.out.flush(); | |
| } | |
| public static void pause(String message) | |
| { | |
| BufferedReader console = new BufferedReader(new InputStreamReader(System.in)); | |
| System.out.print(message); | |
| try | |
| { | |
| console.readLine(); | |
| } | |
| catch (IOException ex) {} | |
| System.out.println(""); | |
| } | |
| public static void printException(Throwable ex) | |
| { | |
| System.err.println("\n" + ex); | |
| } | |
| public static boolean showConfirmInput(String question) | |
| { | |
| return showConfirmInput(question, "Y", "n"); | |
| } | |
| public static boolean showConfirmInput(String question, String yes, String no) | |
| { | |
| BufferedReader console = new BufferedReader(new InputStreamReader(System.in)); | |
| System.out.print(question + " [" + yes + "/" + no + "] ? "); | |
| try | |
| { | |
| String input = console.readLine(); | |
| if(input != null && input.toLowerCase().startsWith(no)) | |
| { | |
| return false; | |
| } | |
| } | |
| catch (IOException ex) {} | |
| return true; | |
| } | |
| public static String showInputDialog(String input) | |
| { | |
| BufferedReader console = new BufferedReader(new InputStreamReader(System.in)); | |
| System.out.print(input + " "); | |
| try | |
| { | |
| String value = console.readLine(); | |
| if(value.length() > 0 && !value.startsWith(" ")) | |
| { | |
| return value; | |
| } | |
| } | |
| catch (IOException ex) {} | |
| return null; | |
| } | |
| public static void showLoadingDialog(String input, final ProgressTask task) | |
| { | |
| System.out.print(input + ".."); | |
| new Thread("load") | |
| { | |
| public void run() | |
| { | |
| while(task.isRunning()) | |
| { | |
| try | |
| { | |
| Thread.sleep(1*1000L); | |
| } | |
| catch (InterruptedException ex) {} | |
| System.out.print("."); | |
| } | |
| try | |
| { | |
| Thread.sleep(500L); | |
| } | |
| catch (InterruptedException ex) {} | |
| System.out.print(" " + task.getMessage() + "\n"); | |
| } | |
| }.start(); | |
| task.start(); | |
| } | |
| public static void showProcessInput(Process process) | |
| { | |
| String line = "$"; | |
| BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream())); | |
| try | |
| { | |
| while ((line = input.readLine()) != null) | |
| { | |
| System.out.println(line); | |
| } | |
| } | |
| catch (IOException ex) {} | |
| } | |
| public static abstract class ProgressTask | |
| { | |
| private String message; | |
| public ProgressTask(String message) | |
| { | |
| this.message = message; | |
| } | |
| private boolean running = true; | |
| public void start() | |
| { | |
| this.run(); | |
| try | |
| { | |
| Thread.sleep(300L); | |
| } | |
| catch (InterruptedException ex) {} | |
| } | |
| public abstract void run() throws RuntimeException; | |
| public void finish(String error) | |
| { | |
| this.message = error; | |
| this.finish(); | |
| } | |
| public void finish() | |
| { | |
| try | |
| { | |
| Thread.sleep(300L); | |
| } | |
| catch (InterruptedException ex) {} | |
| this.running = false; | |
| try | |
| { | |
| Thread.sleep(1*1000L); | |
| } | |
| catch (InterruptedException ex) {} | |
| } | |
| public boolean isRunning() | |
| { | |
| return running; | |
| } | |
| public String getMessage() | |
| { | |
| return message; | |
| } | |
| } | |
| } | |
| public static class Stringer | |
| { | |
| /** | |
| * @Author iToobi | |
| * used to generate brute-force strings | |
| */ | |
| public static final char[] CHARSET_CHARONLYLOWER = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; | |
| public static final char[] CHARSET_CHARONLY = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; | |
| public static final char[] CHARSET_LETTERANDNUMBERS = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','0'}; | |
| public static final char[] CHARSET_GERLETTERANDNUMBERS = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','Ä','Ö','Ü','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','ö','ä','ü','ß','1','2','3','4','5','6','7','8','9','0'}; | |
| public static final char[] CHARSET_ALL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','Ä','Ö','Ü','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','ö','ä','ü','ß','1','2','3','4','5','6','7','8','9','0','!','"','§','$','%','&','/','(',')','=','?'}; | |
| private boolean first = true; | |
| private char[] charset; | |
| private String string; | |
| private int maxid; | |
| public long generated = 0; | |
| public Stringer(String arg) | |
| { | |
| if(arg.equalsIgnoreCase("all")) | |
| { | |
| this.charset = CHARSET_ALL; | |
| } | |
| else if(arg.equalsIgnoreCase("charlower")) | |
| { | |
| this.charset = CHARSET_CHARONLYLOWER; | |
| } | |
| else if(arg.equalsIgnoreCase("ger")) | |
| { | |
| this.charset = CHARSET_GERLETTERANDNUMBERS; | |
| } | |
| else if(arg.equalsIgnoreCase("charonly")) | |
| { | |
| this.charset = CHARSET_CHARONLY; | |
| } | |
| else | |
| { | |
| this.charset = CHARSET_LETTERANDNUMBERS; | |
| } | |
| this.string = String.valueOf(charset[0]); | |
| this.maxid = (charset.length - 1); | |
| } | |
| public String nextString() | |
| { | |
| generated++; | |
| if(!first) | |
| { | |
| this.string = addNewString(string); | |
| return this.string; | |
| } | |
| else | |
| { | |
| first = false; | |
| return string; | |
| } | |
| } | |
| public int getCharsetCount() | |
| { | |
| return charset.length; | |
| } | |
| public String getCurrent() | |
| { | |
| return this.string; | |
| } | |
| private String addNewString(String s) | |
| { | |
| char[] old = s.toCharArray(); | |
| int cid = getID(old[old.length-1]); | |
| if(cid < maxid) | |
| { | |
| //normal case | |
| StringBuilder b = new StringBuilder(); | |
| for(int i = 0; i < old.length -1; i++) | |
| { | |
| b.append(old[i]); | |
| } | |
| b.append(getById(cid+1)); | |
| return b.toString(); | |
| } | |
| else | |
| { | |
| //increase case | |
| boolean total = true; | |
| int cs = 1; | |
| p: | |
| for(; cs < old.length; cs++) | |
| { | |
| cid = getID(old[old.length-(cs+1)]); | |
| if(cid < maxid){ | |
| total = false; | |
| break p; | |
| } | |
| } | |
| if(total) | |
| { | |
| int nl = old.length+1; | |
| StringBuilder b = new StringBuilder(); | |
| for(int i = 0; i < nl; i++) | |
| { | |
| b.append(getById(0)); | |
| } | |
| return b.toString(); | |
| } | |
| else | |
| { | |
| StringBuilder b = new StringBuilder(); | |
| int needed = old.length; int caseid = old.length-cs; | |
| for(int i = 0; i < caseid -1; i++) | |
| { | |
| b.append(old[i]); | |
| needed--; | |
| } | |
| b.append(getById(getID(old[caseid-1])+1)); | |
| needed--; | |
| for(int i = 0; i < needed; i++) | |
| { | |
| b.append(getById(0)); | |
| } | |
| return b.toString(); | |
| } | |
| } | |
| } | |
| private char getById(int id) | |
| { | |
| return charset[id]; | |
| } | |
| private int getID(char c) | |
| { | |
| for(int i = 0; i < charset.length; i++) | |
| { | |
| if((int)charset[i] == (int)c) | |
| { | |
| return i; | |
| } | |
| } | |
| return -1; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment