[Fix] Error compiling 32-bit C language shellcode on 64-bit Linux machine

If your Linux is 64-bit and you wanna compile a .c file into a 32-bit .o file by gcc compiler, but get an error as the following while compiling, means that the compiler cannot find the libc-header-start.h file/library.

This image has an empty alt attribute; its file name is image.png
Pic 1. The command: gcc -fno-stack-protector -m32 -z execstack getshell.c -o getshell

fatal error: bits/libc-header-start.h: No such file or directory”

Now you try checking whether any file named libc-header-start.h exists in your OS.
On my machine, the result as below, the file was in x86_64-linux-gnu folder but still get the error:

Pic 2. The command: sudo find /usr/ -name libc-header-start.h

In the picture 1, the -m32 tells gcc to compile for a 32-bit platform. On a 64-bit machine, gcc normally runs with 64-bit libraries. To solve, you need to install 32-bit headers and libraries.

Run below command to install libraries which pulled in the libc6-dev-i386 package:

sudo apt-get install gcc-multilib

If your OS can find the repositories/packages of gcc-multilib, it will download without any error:

Pic 3

After downloading, the packages will be unpacked and set up, means the installation is successful.

Pic 4

Now, run the command on picture 1 again to check if gcc compiler can successfully run .c shellcode:

Pic 5

It’s okay, a new file named getshell was created on the desktop.

Thanks for visiting my blog! Hope you will return next time…

Leave a comment

Design a site like this with WordPress.com
Get started