Skip to content

Instantly share code, notes, and snippets.

@SalatielSauer
Last active March 24, 2022 17:28
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SalatielSauer/a0d9df2cd3b16bb90acf9d06e357a4bf to your computer and use it in GitHub Desktop.
Save SalatielSauer/a0d9df2cd3b16bb90acf9d06e357a4bf to your computer and use it in GitHub Desktop.
NodeJS for mining Discord Gift keys.
//by @SalatielSauer
//Version: 21/12/2018
var request = require("request");
var counter = 0;
var letras = [
"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"
];
var fs = require("fs");
fs.writeFile('genkeys.txt', "//Start \n", function(err, result) {
if(err) console.log('error', err);
});
var stream = fs.createWriteStream("genkeys.txt", {flags:'a'});
genkey();
var delaytime = 0;
var valids = 0;
function verify(key) {
var keyl = link + key;
setTimeout(function() {
request({
url: keyl,
json: true
}, function (error, response, body) {
var message = JSON.stringify(body);
// Connection issues
if (message == null){
console.log("Unverified: https://discord.gift/" + key);
console.log("could not verify the key, trying again... \n (maybe you're offline) \n ----------")
verify(key);
} else {
delaytime = 2300;
// Rate Limit
if (message.match("limited")){
console.log("Unverified: https://discord.gift/" + key);
console.log(body);
console.log("\n too fast, waiting...");
counter--
verify(key);
};
// Invalid key
if (message.match("Unknown Gift Code")){
console.log("https://discord.gift/" + key);
console.log(body);
genkey();
}
// Valid key
if (message.match("application_id")){
console.log("--------VALID KEY!--------: \n https://discord.gift/" + key + "\n--------------------------");
stream.write("https://discord.gift/" + key + "\n");
valids++
genkey();
};
counter++;
var data = new Date();
var dia = data.getDate();
var mes = data.getMonth()+1;
var ano = data.getFullYear();
var horas = data.getHours();
var minutos = data.getMinutes();
var segundos = data.getSeconds();
console.log(counter + "| " + dia + "/" + mes + "/" + ano + " | " + horas + ":" + minutos + ":" + segundos + " | Valids: " + valids + "\n -------");
};
});
}, delaytime);
};
function genkey(){
link = "https://discordapp.com/api/v6/entitlements/gift-codes/";
var finalkey = "";
for (var i = 0; i <= 15; i++) {
var rnd = letras[Math.floor(Math.random() * letras.length)];
finalkey = finalkey + rnd;
if (i == 15){
verify(finalkey);
finalkey = "";
};
};
};

Some Important Informations

  • This kind of mining is not illegal.
  • This is far from a "hacking script".
  • Keys are valid for a few minutes after a user action, so the chances of getting a valid one are minimal.
  • A key is generated every 2.5 seconds, it can not be less than this to avoid a "block" coming from discord api.
    • Even with this delay, sometimes the block will happen ("You are being rate limited."), but it will only last a few seconds.
  • Although not illegal, if you are lucky enough to get a valid key, be aware that someone else will have this key stolen if you claim it (and this is not cool xD).
  • Everything was done for study proposals, use at your own risk!!1

How it works

  • Generates a 16-letter combination
  • Uses discord's api to check if the url is valid
  • If the api url page contains the text "Unknown" that combination is considered invalid, and the code runs again
  • If it does not contain "Unknown" it means that that combination is somehow valid, so it is saved to a text file in the same folder as the script was run (and you will see a message on the screen).

To work you will need to have the request installed (more info: https://www.npmjs.com/package/request). And npm: https://www.npmjs.com/get-npm.

After installing npm, you can install request with the command: npm install request

To run the script is simple, just run 'node dgkminer.js' at the terminal.

Everything has been tested with Linux and Windows, using NodeJS v11.4.0 and NPM v6.4.1.

@SalatielSauer
Copy link
Author

20/12/2018:

  • Counter and Timestamp were added
  • Connection problems will no longer cause an error and stop the process.

21/12/2018:

  • Codes generated while Rate Limit will not be lost any more.
  • Now the counter will only count invalid and valid attempts

@zefir-git
Copy link

zefir-git commented Oct 19, 2020

-1 for using var (consider let and const, where applicable for the latter)
-1 for not naming variables in English
-1 for lack of configuration
-1 for no code optimisation
-1 for poor iteration performance, bad practices and code formatting
-1 for not using the number of ms that the API provides (the script instead continues to attempt validation, despite the 429 providing the exact time the limit will reset)

I'm planning to develop a fork with the issues above resolved, plus the following additional features:

  • configurable webhook notification
  • proxies for increasing the performance against the API rate limit
  • management of local devices (same network) running the script
  • statistics on locally hosted nodejs page
  • option to minimise to tray

@SalatielSauer
Copy link
Author

@williamd5 Thank you for your time in pointing out these flaws, but this is a gist from almost 3 years ago, initially intended only for a group of friends. It is obviously out of date (request doesn't even exist anymore) and, as I said at the end of the text, this was done just for learning.

Feel free to fork it, even though I don't recommend (for the reasons mentioned above). I honestly think the best choice would be to redo it from scratch.

@zefir-git
Copy link

Yeah, ultimately decided to code a new one from scratch as I was planning to introduce a completely different approach for querying.

Of course this remains for educational purposes only; the chance of getting a valid gift is less than 1/62^(19).

@scopped123
Copy link

Hello, maybe it could be very good if you get like a notification, by a webhook or something. How could i do that btw

@zefir-git
Copy link

zefir-git commented Dec 6, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment