首先,我试图编译这个 c 代码。
我正在使用开发人员推荐的命令,例如
gcc 40049.c -m32 -O2 -o decr
并收到此错误
/usr/include/features.h:323:26: fatal error: bits/predefs.h: No such file or directory
执行此命令后
sudo apt-get install gcc-multilib
我以为代码可以编译,但我错了。
运行相同的命令后,我在 Kali Linux 机器上的终端中得到了完整的错误文本,如图所示。
/bin/bash: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2
这是我收到的错误片段。
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’
我是新手,所以感谢大家的帮助。