Read random memory out of the address space.
authorMatt Mullins <mmullins@mmlx.us>
Sat, 21 Sep 2013 04:37:50 +0000 (21:37 -0700)
committerMatt Mullins <mmullins@mmlx.us>
Sat, 21 Sep 2013 04:37:50 +0000 (21:37 -0700)
mmap_everything.c

index 2e9c7c3..8cd4646 100644 (file)
@@ -1,7 +1,10 @@
 #include <limits.h>
 #include <sys/mman.h>
 #include <sys/types.h>
+#include <stdint.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
 #include <unistd.h>
 
 #define MAX_BITS (sizeof(size_t) * CHAR_BIT - 1)
@@ -41,5 +44,18 @@ int main() {
                }
        }
 
-       getchar();
+       srand48(time(NULL));
+       while (1) {
+               printf("Press enter to read a random byte of memory. (pid %d) >", pid);
+               while (getchar() != '\n');
+               uint32_t lower = lrand48();
+               uint32_t upper = lrand48();
+
+               long pvalue = ((long)lower << 32) | ((long)upper);
+               // align to integer, keep in "userspace" address space
+               pvalue &= 0x00007FFFFFFFFFF0;
+
+               int *pi = (void*)(pvalue);
+               printf("*%p = %x\n", (void*)pi, *pi);
+       }
 }