1

If the following array contained shell code in a C program on a LINUX machine

char buf [100]

then how does the following execute this shell code :

((void(*)())buf)()
1
  • @Joachim Why do you conclude that this makes it impossible? Most JIT compilers will do something just like that. Also, I don't think that root rights are required. Commented Sep 18, 2014 at 5:23

1 Answer 1

3

Simple. It casts buf to a pointer-to-function taking no arguments and returning void, and then invokes that function.

However, that probably won't work since the page containing buf is highly unlikely to be marked as executable.

Sign up to request clarification or add additional context in comments.

1 Comment

You'll want to use mprotect() to give the memory location PROD_READ|PROD_EXEC rights. This works on page boundaries, so I'd recommend allocating buf with mmap().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.