Created
February 28, 2017 20:24
-
-
Save ivanvza/2ba0377ba20f08c26689cba4e79f65d2 to your computer and use it in GitHub Desktop.
Get Environment Variable Mem Address
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> | |
#include <stdlib.h> | |
#include <string.h> | |
# USAGE: | |
# ~$ export PWN='echo 1' | |
# ~$ ./getenvaddr PWN ./pwnme | |
# PWN will be at 0xbfffff7d | |
int main(int argc, char *argv[]) { | |
char *ptr; | |
if(argc < 3) { | |
printf("Usage: %s <environment variable> <target program name>\n", argv[0]); | |
exit(0); | |
} | |
ptr = getenv(argv[1]); /* get env var location */ | |
ptr += (strlen(argv[0]) - strlen(argv[2]))*2; /* adjust for program name */ | |
printf("%s will be at %p\n", argv[1], ptr); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment