Created
September 24, 2012 14:22
-
-
Save YukiSakamoto/3776193 to your computer and use it in GitHub Desktop.
Disable ASLR on MacOSX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
/* | |
This source is testing for address layout randomization. | |
If ASLR is enabled, output of this program will be variable. | |
*/ | |
int main(void) | |
{ | |
printf("%p\n", main); | |
here: | |
printf("%p\n", &&here); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <spawn.h> | |
#include <stdio.h> | |
int main(void) | |
{ | |
int ret; | |
short ps_flags = 0; | |
pid_t pid; | |
posix_spawn_file_actions_t actions; | |
posix_spawnattr_t attrs; | |
/* | |
char *args[] = {"/bin/ls", "-l", NULL}; | |
*/ | |
char *args[] = {"./random", NULL}; | |
posix_spawn_file_actions_init(&actions); | |
posix_spawnattr_init(&attrs); | |
#ifndef _POSIX_SPAWN_DISABLE_ASLR | |
# define _POSIX_SPAWN_DISABLE_ASLR 0x0100 | |
#endif | |
ps_flags |= POSIX_SPAWN_SETEXEC; | |
ps_flags |= _POSIX_SPAWN_DISABLE_ASLR; | |
ret = posix_spawnattr_setflags(&attrs, ps_flags); | |
if (ret != 0) { | |
printf("cannot set posix_spawn flags\n"); | |
} | |
posix_spawn(&pid, args[0], &actions, &attrs, args, NULL); | |
printf("pid: %d\n", pid); | |
printf("========================\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's an improved version of spawn.c which passes along the command name and arguments, and environment variables.