http://exploit-exercises.com/nebula/level04
This level requires you to read the token file, but the code restricts the files that can be read. Find a way to bypass it :)
To do this level, log in as the level04 account with the password level04 . Files for this level can be found in /home/flag04.
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <stdio.h>
#include <fcntl.h>
int main(int argc, char **argv, char **envp)
{
char buf[1024];
int fd, rc;
if(argc == 1) {
printf("%s [file to read]\n", argv[0]);
exit(EXIT_FAILURE);
}
if(strstr(argv[1], "token") != NULL) {
printf("You may not access '%s'\n", argv[1]);
exit(EXIT_FAILURE);
}
fd = open(argv[1], O_RDONLY);
if(fd == -1) {
err(EXIT_FAILURE, "Unable to open %s", argv[1]);
}
rc = read(fd, buf, sizeof(buf));
if(rc == -1) {
err(EXIT_FAILURE, "Unable to read fd %d", fd);
}
write(1, buf, rc);
}
首先先去/home/flag04目录下运行cat token 发现没有文件的读取权限。
只能使用上面源代码提供的flag04 程序来读取token文件, 但是flag04 文件从源代码中可以看出, 已经对token关键字的读取做了过滤, 所以直接运行./flag04 token会直接退出。
但是由于我们对/tmp目录有权限, 所以我们可以创建一个符号链接, 而且由于没有权限,只能创建软符号链接。
ln -s /home/flag04/token /tmp/exploit_04
然后运行./flag04 /tmp/exploit_04
发现可以读取出来!
tmp这个目录对于漏洞挖掘者来说真是不错的目录, 因为这个目录中你可以为所欲为!