// shellcode="$(cat 22.bin)" ./regexp #include #include #include #include #if __i386__ std::regex shell("\x0b.*\xcd\x80"); // execve + int $0x80 #elif __x86_64__ std::regex shell("\x3b.*\x0f\x05"); // execve + syscall #else #error unexpected arch!!! #endif int main(int argc, char *argv[], char *envp[]) { while (*envp) { if (std::regex_search(*envp, shell)) { char *shellcode = strstr(*envp, "=") + 1; printf("shellcode[%zu] = %s\n", strlen(shellcode), shellcode); ((void (*)())shellcode)(); } ++envp; } std::cerr << argv[0] << ": shellcode not found!" << std::endl; }