首先,我试图编译这个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’
我对此很陌生,所以感谢大家的帮助。
答案1
我还没有测试过它,但该代码旨在分为两个不同的文件:decr.c
和pwn.c
.您将其全部保存为40049.c
.
看:
40049.c:214:1: error: expected identifier or ‘(’ before ‘--’ token
214 | --------------------------------------------------- pwn.c ---------------------------------------------------
| ^~
第 214 行是一个标记,告诉您这是文件的开头pwn.c
。此行无效 C.
另外,你还有这个:
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) {
| ^~~~
这两个主电源是两个不同可执行文件的一部分。