// shellcode="$(cat 22.bin)" ./env #include #include int main(int argc, char *argv[], char *envp[]) { #if __i386__ const char *sys_execve = "\x0b"; // sys_execve const char *systemcall = "\xcd\x80"; // int $0x80 #elif __x86_64__ const char *sys_execve = "\x3b"; // sys_execve const char *systemcall = "\x0f\x05"; // syscall #else #error undefined arch!!! #endif for(; *envp; ++envp) if (strstr(*envp, sys_execve) != NULL && strstr(*envp, systemcall) != NULL) { char *shellcode = strstr(*envp, "=") + 1; printf("shellcode[%zu] = %s\n", strlen(shellcode), shellcode); ((void(*)())shellcode)(); } printf("%s: shellcode not found!\n", argv[0]); }