Loading raw code from C program

后端 未结 4 1270
醉梦人生
醉梦人生 2020-12-06 06:09

I\'m writing a program that loads and executes code from file. But i got a problem: \"write\" syscall does not work. Code successfully loads and executes, but does not displ

相关标签:
4条回答
  • 2020-12-06 06:31

    One thing: you should open the file as binary.

    FILE* fp = fopen(argv[1],"rb"); 
    
    0 讨论(0)
  • 2020-12-06 06:38

    Why are you not using .so files to dynamically load your code? Are you testing a security scenario or really trying to dynamically load and run code?

    Read here on how to compile code as a .so, load it dynamically within a program, and execute exported functions out of it.

    http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html

    0 讨论(0)
  • 2020-12-06 06:45

    Your approach can't work: shellcode must be position-independant, but your code refers to the absolute address str. The unconditional jump can also be either relative or absolute: make sure you get the relative verison (opcodes EB and E9 on x86).

    See The Technique of Writing Portable Shell Code for more information.

    0 讨论(0)
  • 2020-12-06 06:50

    You don't specify the details of your CPU, but you might be running afoul of the NX bit. I would expect your code to SEGFAULT though rather than run to completion.

    This is precisely what happens on my box (Linux 2.6.32-28-generic #55-Ubuntu SMP Mon Jan 10 23:42:43 UTC 2011 x86_64 GNU/Linux) running on Intel Xeon E5410.

    0 讨论(0)
提交回复
热议问题