Installing build-essentials in CentOS (make, gcc, gdb)

CentOS IconOnce upon a time I was a very avid desktop user of Ubuntu Linux. As a software developer, I would usually need the standard build tools installed on my machine.

Installing build tools in Debian/Ubuntu

In Debian/Ubuntu, you can install the typical build tools by installing the package build-essentials, which is just a pseudo-package that downloads all the popular development packages:

# apt-get install build-essentials

Installing build tools in CentOS

Since I prefer CentOS as my server platform, I also occasionally need to install packages using yum.

To install the common build tools using yum in CentOS you’ll want to install the group package “Development Tools”, which is similar to build-essentials in Debian/Ubuntu flavors of linux. You’ll probably also want to install kernel-devel and kernel-headers if they’re not already installed:

# yum groupinstall "Development Tools"
# yum install kernel-devel kernel-headers

This should give you a copy of make, gcc, gdb, and all those other tools you were looking for.

Happy hacking!

How to fix Error: suffix or operands invalid for ‘push’ or ‘pop’

TerminalIf you compile a 32-bit assembly program (or a C program that contains assembly instructions) on a 64-bit machine you may see the following error:

# as -o example32bit.o example32bit.s
example32bit.s: Assembler messages:
example32bit.s:10: Error: suffix or operands invalid for `pop'

To fix this problem you need to pass the compiler or assembler a flag telling it you want to compile the software as 32-bit and not 64-bit.

The fix for C: Compiling with the -m32 flag

If you’re using gcc to compile a C program, pass in -m32. There’s a complete example here on my blog.

The fix for assembly: Compiling with the –32 flag

If you’re using as to compile an assembly program, pass in –32. Then when you link with ld pass in -m elf_i386. There’s a complete example here on my blog.

Happy hacking!

How to Compile 32-bit C Programs on a 64-bit PC in Linux

TerminalI’ve been writing a lot of articles recently about compiling C and assembly programs on my 64-bit machine. But eventually I needed to compile a 32-bit program and I thought I would explain how I did that in case anyone else runs into trouble.

Using the -m32 flag

To compile a 32-bit program with gcc you can just use the m32 flag (which you’ll find under i386 and x86-64 Options on the gcc man page). But if you’re on a 64-bit machine, don’t be surprised if you see something like this:

# gcc -m32 -o example32bit example32bit.c
In file included from /usr/include/features.h:378,
                 from /usr/include/stdio.h:28,
                 from example32bit.c:1:
/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory

Installing the 32-bit glibc headers

You see that because you don’t have the 32-bit glibc headers installed. That’s not a problem though, since most package managers should have them available for installation. If you’re on a Debian or Ubuntu machine you can install them like this:

# apt-get install gcc-multilib

Look ma, no compiler errors!

# gcc -m32 -o example32bit example32bit.c
#

Tada!

Testing Shellcode on a Non-Executable Stack or Heap

EditIf you’re learning about buffer overflows and shellcode, chances are you’re exploiting some stack-based vulnerabilities. If you’re like me you might also find that when you compile your programs they have stack execution disabled by default. So instead of getting excited as you see your shellcode blissfully running after smashing the stack, you might just see this instead:

Program received signal SIGSEGV, Segmentation fault.
0x0000000000601018 in shellcode ()
“Noooo! You can’t do this to me! I want to write exploits!”

Ok.. calm down.. we just need to turn on stack execution when compiling.

Continue reading