0

To start off, I was trying to compile this c code.

I was using the command the developer recommended such as

gcc 40049.c -m32 -O2 -o decr

and was getting this error

/usr/include/features.h:323:26: fatal error: bits/predefs.h: No such file or directory

After doing this command

sudo apt-get install gcc-multilib

I thought the code could be compiled but I was wrong.

After running the same commands, I get a full text of errors in my terminal in Kali Linux machine which is shown.

/bin/bash: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2

This is a snippet of the errors I am receiving.

40049.c: In function ‘main’:
40049.c:200:19: warning: incompatible implicit declaration of built-in function ‘malloc’
  200 |  stack = (void *) malloc(65536);
      |                   ^~~~~~
40049.c:200:19: note: include ‘<stdlib.h>’ or provide a declaration of ‘malloc’
40049.c: At top level:
40049.c:214:1: error: expected identifier or ‘(’ before ‘--’ token
  214 | --------------------------------------------------- pwn.c ---------------------------------------------------
      | ^~
40049.c: In function ‘privesc’:
40049.c:240:42: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  240 |         commit_creds(prepare_kernel_cred((uint64_t)NULL));
      |                                          ^
40049.c: At top level:
40049.c:243:5: error: redefinition of ‘main’
  243 | int main() {
      |     ^~~~
40049.c:178:5: note: previous definition of ‘main’ was here
  178 | int main(void) {
      |     ^~~~
40049.c: In function ‘main’:
40049.c:249:2: warning: incompatible implicit declaration of built-in function ‘memset’
  249 |  memset(shellcode, 0, 0x300000);
      |  ^~~~~~
40049.c:249:2: note: include ‘<string.h>’ or provide a declaration of ‘memset’
40049.c:251:14: warning: implicit declaration of function ‘memcpy’ [-Wimplicit-function-declaration]
  251 |  void *ret = memcpy(shellcode, &privesc, 0x300);
      |              ^~~~~~
40049.c:251:14: warning: incompatible implicit declaration of built-in function ‘memcpy’
40049.c:251:14: note: include ‘<string.h>’ or provide a declaration of ‘memcpy’

I am new to this so thank you for the help everyone.

1
  • That code is intended to be split into two different files: decr.c and pwn.c. You are saving it all as 40049.c.
    – D4RIO
    Oct 4, 2021 at 5:06

1 Answer 1

5

I haven't tested it, but that code is intended to be split into two different files: decr.c and pwn.c. You are saving it all as 40049.c.

See:

40049.c:214:1: error: expected identifier or ‘(’ before ‘--’ token
  214 | --------------------------------------------------- pwn.c ---------------------------------------------------
      | ^~

Line 214 is a marker to tell you that this is the start of the file pwn.c. This line isn't valid C.

Also, you have this:

40049.c:243:5: error: redefinition of ‘main’
  243 | int main() {
      |     ^~~~
40049.c:178:5: note: previous definition of ‘main’ was here
  178 | int main(void) {
      |     ^~~~

The two mains are meant to be part of two different executables.

1
  • You are right! Laziness by me, lessons learned Oct 4, 2021 at 5:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.