Kali-Linux

完全破壞了我的 gcc 編譯器。需要幫助使其處於正確狀態

  • October 4, 2021

首先,我試圖編譯這個 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’

我是新手,所以感謝大家的幫助。

我尚未對其進行測試,但該程式碼旨在分為兩個不同的文件:decr.cpwn.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) {
     |     ^~~~

這兩個主要是兩個不同的執行檔的一部分。

引用自:https://unix.stackexchange.com/questions/671728