Skip to content

Instantly share code, notes, and snippets.

@rubencodes
Last active May 10, 2018 15:13
Show Gist options
  • Save rubencodes/dbff745e7b75e7ec313afdbf72ce9bd3 to your computer and use it in GitHub Desktop.
Save rubencodes/dbff745e7b75e7ec313afdbf72ce9bd3 to your computer and use it in GitHub Desktop.
Find valid .google domains
// I ran this with:
// while true; do node ~/Desktop/google.js --max_old_space_size=4096 --optimize_for_size --max_executable_size=4096 --stack_size=4096 && break; done
// This will run the script with 4GB allocated memory, and auto-restart if it crashes (happens sometimes due to out of memory).
const https = require('https');
const fs = require('fs');
// File storage between runs.
const validStorage = '/Users/ruben/Desktop/validURLs.txt';
const attemptsStorage = '/Users/ruben/Desktop/attempts.txt';
let attempts = [];
const alphabet = ['a', 'b', 'c', 'd', 'e', 'g', 'f', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
// Loads previous attempts from file system.
function loadHistory() {
return new Promise((resolve, reject) => {
// Read attempts file.
fs.readFile(attemptsStorage, 'utf8', (err, content) => {
if(err) {
reject();
}
// Load file into attempts array in memory.
attempts = content.split('\n');
resolve();
});
});
}
// Generates a unique URL not seen in attempts array.
function generateURL() {
return new Promise((resolve, reject) => {
let name = '';
let foundUnique = false;
do {
// Generate a name
name = '';
for(var i = 0; i < Math.ceil(Math.random() * 10); i++) {
const letter = alphabet[(Math.floor(Math.random() * alphabet.length))];
name += letter;
}
// Make sure we haven't seen this name yet.
foundUnique = !attempts.includes(name);
} while(!foundUnique)
// Store this attempt in memory.
fs.appendFile(attemptsStorage, name+"\n", 'utf8', (err) => {
if(err) {
console.log(err);
reject(err);
}
// Return the name.
resolve('https://' + name + '.google/');
});
});
}
// Recursive loop, makes attempts to .google URLs and stores if valid.
function beginAttempts() {
// Randomly generate a unique URL.
generateURL().then((url) => {
// Make GET request.
const req = https.get(url, (res) => {
// Output and store valid requests.
if(res.statusCode == '301' || res.statusCode == '200') {
console.log('VALID URL', url, res.statusCode);
fs.appendFile(validStorage, url+"\n", 'utf8');
}
// Try again.
beginAttempts();
});
// If the request failed (likely ENOTFOUND), try again.
req.on('error', (err) => {
console.log(err.code + ": " + err.hostname);
// Try again.
beginAttempts();
});
});
}
// Starts program.
loadHistory().then(beginAttempts);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment