assembly - How do I link this execlp program using ld in Windows? -
i'm using gas mingw (gcc, as, , ld specific) compile following to-be shellcode in windows...
.text .globl _main .def _main; .scl 2; .type 32; .endef #.extern _execlp .def _execlp; .scl 2; .type 32; .endef _main: push %ebp movl %esp, %ebp pushl $0 pushl $0x00657865 pushl $0x2e646d63 call _execlp movl %ebp, %esp pop %ebp
that compiles fine using...
as -o ex.o ex.s
where ex.s assembly source file.
but during linking...
ld -o ex.exe ex.o
it gives error...
ex.o:fake:(.text+0x10): undefined reference 'execlp'
so tried make extern putting...
.extern _execlp
...above definition (the comment).
meanwhile had .c file code (which generated ex.s file (using gcc -s -m32 -o ex.s ex.c))...
#include <process.h> int main(int argc, char *argv[]) { execlp("cmd.exe", 0); return 0; }
when compiled with...
gcc -o exc.exe exc.c
where exc.c c file. compiles , runs desired functionality... used dependency walker find dll's used exc.exe , found kernel32.dll, ntdll.dll, , msvcrt.dll being used. msvcrt important because c runtime library (which contains execlp). tried link ex.o so...
ld -lkernel32 -lndtll -lmsvcrt -o ex.exe ex.o
...with
.extern _execlp
...defined within source file (ex.s) comment is.
it generated same linking error above...
what doing wrong?
you need use 2 underscores , list libraries after object file. also, pass arguments wrong. works me:
.globl _main _main: push %ebp movl %esp, %ebp pushl $0x00657865 pushl $0x2e646d63 pushl $0 lea 4(%esp), %eax pushl %eax call __execlp
assembled with: as -o ex.o ex.s
linked with: ld -o ex.exe ex.o -lkernel32 -lmsvcrt