彻底毁掉了我的 gcc 编译器。需要帮助使其达到正确的状态

0 gcc kali-linux

首先,我试图编译这个 c 代码

\n

我正在使用开发人员推荐的命令,例如

\n
gcc 40049.c -m32 -O2 -o decr\n
Run Code Online (Sandbox Code Playgroud)\n

并收到此错误

\n
/usr/include/features.h:323:26: fatal error: bits/predefs.h: No such file or directory\n
Run Code Online (Sandbox Code Playgroud)\n

执行此命令后

\n
sudo apt-get install gcc-multilib\n
Run Code Online (Sandbox Code Playgroud)\n

我以为代码可以编译,但我错了。

\n

运行相同的命令后,我在 Kali Linux 机器的终端中收到了错误的全文,如图所示。

\n
/bin/bash: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2\n
Run Code Online (Sandbox Code Playgroud)\n

这是我收到的错误的一个片段。

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

我对此很陌生,所以感谢大家的帮助。

\n

D4R*_*RIO 5

我还没有测试过它,但该代码旨在分为两个不同的文件:decr.cpwn.c. 您将其全部保存为40049.c.

\n

看:

\n
40049.c:214:1: error: expected identifier or \xe2\x80\x98(\xe2\x80\x99 before \xe2\x80\x98--\xe2\x80\x99 token\n  214 | --------------------------------------------------- pwn.c ---------------------------------------------------\n      | ^~\n
Run Code Online (Sandbox Code Playgroud)\n

第 214 行是一个标记,告诉您这是文件的开头pwn.c。此行无效 C.

\n

另外,你还有这个:

\n
40049.c:243:5: error: redefinition of \xe2\x80\x98main\xe2\x80\x99\n  243 | int main() {\n      |     ^~~~\n40049.c:178:5: note: previous definition of \xe2\x80\x98main\xe2\x80\x99 was here\n  178 | int main(void) {\n      |     ^~~~\n
Run Code Online (Sandbox Code Playgroud)\n

这两个主电源是两个不同可执行文件的一部分。

\n