So I wanted to convert a compiled C program into Hex format so that I can inject it inside the memory. The problem I am currently facing is that I have no idea how to convert a compiled C file to hex. Can someone show me how it's done?
My C Code (temp.c):
#include <stdio.h>
void main(){
printf("Working!");
}
Compiled it using gcc: gcc -g temp.c -o temp -m32
You can write in assembly using write();
syscall and exit();
syscall.
Here code I wrote, file w.asm
:
global _start
section .text
_start:
push byte 0x0a
push dword "ing!"
push dword "Work"
inc ebx
mov ecx, esp
mov dl, 9
mov al, 4
int 0x80
xor ebx, ebx
mov al, 1
int 0x80
Assembling and linking using nasm
and ld
:
nasm -f elf w.asm && ld -o w w.o
Dump binary file into hex (shellcode style) using objdump one-liner like this:
objdump -d ./w | grep '[0-9a-f]:'|grep -v 'file'|cut -f2 -d:|cut -f1-6 -d' '|tr -s ' '|tr '\t' ' '|sed 's/ $//g'|sed 's/ /\\x/g'|paste -d '' -s |sed 's/^/"/'|sed 's/$/"/g'
You will get the result like this:
"\x6a\x0a\x68\x69\x6e\x67\x21\x68\x57\x6f\x72\x6b\x43\x89\xe1\xb2\x09\xb0\x04\xcd\x80\x31\xdb\xb0\x01\xcd\x80"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.