ssh cmd1@pwnable.kr -p2222 (pw:guest)
先看一下c的源码
#include <stdio.h> #include <string.h> int filter(char* cmd){ int r=0; r += strstr(cmd, "flag")!=0; r += strstr(cmd, "sh")!=0; r += strstr(cmd, "tmp")!=0; return r; } int main(int argc, char* argv[], char** envp){ putenv("PATH=/thankyouverymuch"); if(filter(argv[1])) return 0; system( argv[1] ); return 0; }
上面那个filter函数把flag sh tmp都过滤掉了,输入的参数可以用system调用
过滤掉了关键字,怎么办
我们可以用通配符的方式来获得flag
还有一种就是修改环境变量
putenv("PATH=/thankyouverymuch");
在/tmp/thankyouverymuch下面添加一个bash脚本,之后让system调用
新建一个bash脚本
输入/bin/cat /home/cmd1/flag
之后赋予它755的权限
在执行 相当于调用system(‘./gnq’)
mommy now I get what PATH environment is for :)