Can someone explain me this code ?
Posted
by VaioIsBorn
on Stack Overflow
See other posts from Stack Overflow
or by VaioIsBorn
Published on 2010-04-03T12:53:10Z
Indexed on
2010/04/03
13:03 UTC
Read the original article
Hit count: 288
#include <stdio.h>
#include <unistd.h>
#include <string.h>
int good(int addr) {
printf("Address of hmm: %p\n", addr);
}
int hmm() {
printf("Win.\n");
execl("/bin/sh", "sh", NULL);
}
extern char **environ;
int main(int argc, char **argv) {
int i, limit;
for(i = 0; environ[i] != NULL; i++)
memset(environ[i], 0x00, strlen(environ[i]));
int (*fptr)(int) = good;
char buf[32];
if(strlen(argv[1]) <= 40) limit = strlen(argv[1]);
for(i = 0; i <= limit; i++) {
buf[i] = argv[1][i];
if(i < 36) buf[i] = 0x41;
}
int (*hmmptr)(int) = hmm;
(*fptr)((int)hmmptr);
return 0;
}
I don't really understand the code above, i have it from an online game - i should supply something in the arguments so it would give me shell, but i don't get it how it works so i don't know what to do. So i need someone that would explain it what it does, how it's working and the stuff. Thanks.
© Stack Overflow or respective owner