I want to cross compile a Metasploit template (in assembly language) for 64 bit Windows on Kali Linux.
I am trying to compile from assembly to exe.
Here is the code -
; Author: Stephen Fewer (stephen_fewer[at]harmonysecurity[dot]com)
; Architecture: x64
;
; Assemble and link with the following command:
; "C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\x86_amd64\ml64" template_x64_windows.asm /link /subsystem:windows /defaultlib:"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib\x64\kernel32.lib" /entry:main
extrn ExitProcess : proc
extrn VirtualAlloc : proc
.code
main proc
sub rsp, 40 ;
mov r9, 40h ;
mov r8, 3000h ;
mov rdx, 4096 ;
xor rcx, rcx ;
call VirtualAlloc ; lpPayload = VirtualAlloc( NULL, 4096, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE );
mov rcx, 4096 ;
mov rsi, payload ;
mov rdi, rax ;
rep movsb ; memcpy( lpPayload, payload, 4096 );
call rax ; lpPayload();
xor rcx, rcx ;
call ExitProcess ; ExitProcess( 0 );
main endp
payload proc
A byte 'PAYLOAD:'
B db 4096-8 dup ( 0 )
payload endp
end
I am using w64-mingw32, and I can compile 32 bit c files with the command i686-mingw32msvc-gcc xxx, but I am having trouble with compiling 64 bit assembly.
There are so many different options for w64-mingw32, I have tried numerous, all with error messages. To be honest, I haven't done assembly since I had a Commodore 64.
I tried:
x86_64-w64-mingw32-gcc -c template_x64_windows.asm -o file.o
And the error message is -
template_x64_windows.asm: linker input file unused because linking not done
I don't even know which option will compile assembly, I have checked online for howt-o's, nothing.
w64-mingw32should take the same command line options as 32-bit MinGW. Are you trying to compile to assembly, or compile a.Sasm source file to machine code?gcc -c foo.sjust works, if your asm is written in GAS syntax. If not, you can't assemble it with gcc. We can't do any more than guess without seeing the source you're trying to build, or any error messages, or any of the command line options you tried. This isn't a minimal reproducible example of the problem you're having. - Peter Cordes.intel_syntax noprefix. Or port it to NASM directives. - Peter Cordes