我想利用一個SUID程序。gdb退出而不是產生一個shell
的程序是:
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#define e(); if(((unsigned int)ptr & 0xff000000)==0xca000000) { setresuid(geteuid(), geteuid(), geteuid()); execlp("/bin/sh", "sh", "-i", NULL); }
void print(unsigned char *buf, int len)
{
int i;
printf("[ ");
for(i=0; i < len; i++) printf("%x ", buf[i]);
printf(" ]\n");
}
int main()
{
unsigned char buf[512];
unsigned char *ptr = buf + (sizeof(buf)/2);
unsigned int x;
while((x = getchar()) != EOF) {
switch(x) {
case '\n': print(buf, sizeof(buf)); continue; break;
case '\\': ptr--; break;
default: e(); if(ptr > buf + sizeof(buf)) continue; ptr++[0] = x; break;
}
}
printf("All done\n");
}
我們可以很容易地看到,如果我們以某種方式改變PTR的內容與CA開頭,則某些地址的新外殼將催生我們。而且由於ptr通常擁有一些以FF開頭的地址,減少它的方式(ptr)是輸入\字符。所以,我就與0x35000000文件「\」字符,最後3「」在文件
perl -e "print '\\\'x889192448" > file # decimal equivalent of 0x35000000
echo aaa > file # So that e() is called which actually spawns the shell
最後在gdb年底,
run < file
然而,而不是產卵殼GDB在說
process <some number> is executing new program /bin/dash
inferior 1 exited normally
然後回到gdb提示符而不是獲得一個shell。 我已經通過在合適的位置設置斷點來確認ptr確實是在setresuid()被調用之前以CA開始的。
此外,如果我管這gdb之外,沒有任何反應。
./vulnProg < file
Bash提示返回。
請告訴我我在哪裏犯錯。
如果去掉所有的冗餘代碼,只是做'會發生什麼INT的main(){setresuid(geteuid(),geteuid(),geteuid()); execlp(「/ bin/sh」,「sh」,「-i」,NULL); }'?這實際上是否符合你的期望? –
對不起,但我不能這樣做,因爲程序在遠程CTF服務器上,而且我的權限有限。 –