forked from The-Art-of-Hacking/h4cker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaslr_changer.c
More file actions
29 lines (23 loc) · 788 Bytes
/
aslr_changer.c
File metadata and controls
29 lines (23 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
FILE *fp;
char buff[100];
if(seteuid(0) == -1) {
fprintf(stderr, "Failed to set UID to root - is this binary setuid root?\n");
return -1;
}
if(argc != 2 || (strcmp(argv[1], "0") != 0 && strcmp(argv[1], "2") != 0)) {
fprintf(stderr, "Usage: %s [0 or 2]\nSets randomize_va_space to 0 (ASLR off) or 2 (ASLR on)\n", argv[0]);
return -1;
}
fp = fopen("/proc/sys/kernel/randomize_va_space", "w");
fprintf(fp, "%s\n", argv[1]);
fclose(fp);
fp = fopen("/proc/sys/kernel/randomize_va_space", "r");
fgets(buff, 99, fp);
fclose(fp);
printf("randomize_va_space is now %s", buff);
return 0;
}