Guest User

Untitled

a guest
Aug 20th, 2025
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4.  
  5. struct node {
  6. struct node *prev;
  7. struct node *next;
  8. char const *data;
  9. };
  10.  
  11. [[noreturn]] void die(char const *s) {
  12. fputs(s, stderr);
  13. exit(EXIT_FAILURE);
  14. }
  15.  
  16. struct node *list_new(char const *data) {
  17. struct node *node = malloc(sizeof(struct node));
  18. if (node == NULL) {
  19. die("malloc failed in list_new\n");
  20. }
  21. node->prev = NULL;
  22. node->next = NULL;
  23. node->data = data;
  24. return node;
  25. }
  26.  
  27. void list_insert_after(struct node *insertion_point, char const *data) {
  28. struct node *node = malloc(sizeof(struct node));
  29. if (node == NULL) {
  30. die("malloc failed in list_insert_after\n");
  31. }
  32.  
  33. node->prev = insertion_point;
  34. node->data = data;
  35.  
  36. if (insertion_point->next) {
  37. insertion_point->next->prev = node;
  38. }
  39. node->next = insertion_point->next;
  40. insertion_point->next = node;
  41. }
  42.  
  43. void list_remove(struct node *node) {
  44. if (node->prev) {
  45. node->prev->next = node->next;
  46. }
  47. if (node->next) {
  48. node->next->prev = node->prev;
  49. }
  50. free(node);
  51. }
  52.  
  53. void list_remove_safe(struct node *node);
  54.  
  55. static char authenticated = 0;
  56.  
  57. int main(void) {
  58. struct node *first_node = list_new("first node");
  59. list_insert_after(first_node, "second node");
  60. struct node *second_node = first_node->next;
  61. list_insert_after(second_node, "third node");
  62.  
  63. // Begin "vulnerability"
  64. printf("LEAK: &authenticated is %p\n", &authenticated);
  65. char buf[2 + 0x10 + 1] = {};
  66. read(STDIN_FILENO, buf, sizeof(buf) - 1);
  67. second_node->prev = (void *)strtoull(buf, NULL, 16);
  68.  
  69. read(STDIN_FILENO, buf, sizeof(buf) - 1);
  70. second_node->next = (void *)strtoull(buf, NULL, 16);
  71. // End "vulnerability"
  72.  
  73. list_remove_safe(second_node);
  74.  
  75. if (authenticated) {
  76. puts("You win!");
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment