前置介绍
什么是DVWA?
DVWA(Damn Vulnerable Web Application)是一个专门设计用于测试和提高Web应用程序安全技能的开源PHP/MySQL Web应用程序。它是一个具有多个安全漏洞的故意不安全的应用程序,供安全专业人员、渗透测试人员、学生和开发人员用来练习和提升他们的技能。
DVWA的主要特点:
-
多种漏洞类型:DVWA包含多种常见的Web应用程序漏洞,如SQL注入、XSS(跨站脚本攻击)、CSRF(跨站请求伪造)、文件包含漏洞、命令注入等。这使用户可以在一个环境中练习和理解不同类型的漏洞。
-
不同的安全级别:DVWA提供不同的安全级别(低、中、高和不可能),以帮助用户逐步提高他们的技能和理解。这些级别通过改变应用程序代码和配置的复杂性来增加挑战。
-
教育目的:DVWA的设计初衷是用于教育目的,帮助用户理解和识别Web应用程序中的常见漏洞,以及如何利用这些漏洞。
-
社区支持和扩展:DVWA有一个活跃的社区,用户可以共享他们的经验、工具和技巧。它还可以与其他安全工具集成,以创建更全面的学习和测试环境。
使用DVWA的注意事项:
-
安全环境:由于DVWA是故意不安全的应用程序,它应仅在安全和隔离的环境中使用,例如本地虚拟机或专用实验室环境,以防止对生产系统或不安全网络造成影响。
-
学习和测试目的:DVWA应仅用于合法的学习和测试目的。未经授权的测试或在他人系统上使用可能违反法律法规。
集群环境
|------------|----------------|
| k8s-master | 192.168.58.231 |
| k8s-node1 | 192.168.58.232 |
| k8s-node2 | 192.168.58.233 |
部署测试用服务(端口扫描目标)
bash
[root@k8s-master ~]# kubectl create namespace security-test
namespace/security-test created
[root@k8s-master ~]# cat <<EOF | kubectl apply -f -
> apiVersion: apps/v1
> kind: Deployment
> metadata:
> name: nginx
> namespace: security-test
> spec:
> replicas: 1
> selector:
> matchLabels:
> app: nginx
> template:
> metadata:
> labels:
> app: nginx
> spec:
> containers:
> - name: nginx
> image: nginx:latest
> ports:
> - containerPort: 80
> EOF
deployment.apps/nginx created
暴露Service(NodePort类型,便于外部访问)
bash
[root@k8s-master ~]# cat <<EOF | kubectl apply -f -
> apiVersion: v1
> kind: Service
> metadata:
> name: nginx
> namespace: security-test
> spec:
> type: NodePort
> selector:
> app: nginx
> ports:
> - port: 80
> targetPort: 80
> nodePort: 30080
> EOF
service/nginx created
[root@k8s-master ~]# kubectl get pod -n security-test
NAME READY STATUS RESTARTS AGE
nginx-585449566-n4nxf 1/1 Running 0 57s

部署带漏洞的Web应用(SQL注入测试目标)
bash
#手动先拉取镜像
[root@k8s-master ~]# docker pull vulnerables/web-dvwa:latest
latest: Pulling from vulnerables/web-dvwa
3e17c6eae66c: Pull complete
0c57df616dbf: Pull complete
eb05d18be401: Pull complete
e9968e5981d2: Pull complete
2cd72dba8257: Pull complete
6cff5f35147f: Pull complete
098cffd43466: Pull complete
b3d64a33242d: Pull complete
Digest: sha256:dae203fe11646a86937bf04db0079adef295f426da68a92b40e3b181f337daa7
Status: Downloaded newer image for vulnerables/web-dvwa:latest
docker.io/vulnerables/web-dvwa:latest
[root@k8s-master ~]# cat <<EOF | kubectl apply -f -
> apiVersion: apps/v1
> kind: Deployment
> metadata:
> name: dvwa
> namespace: security-test
> spec:
> replicas: 1
> selector:
> matchLabels:
> app: dvwa
> template:
> metadata:
> labels:
> app: dvwa
> spec:
> containers:
> - name: dvwa
> image: vulnerables/web-dvwa:latest
> ports:
> - containerPort: 80
> EOF
deployment.apps/dvwa unchanged
[root@k8s-master ~]# kubectl get pod -n security-test -w
NAME READY STATUS RESTARTS AGE
dvwa-5666759b95-bp8zt 1/1 Running 0 72s
nginx-585449566-n4nxf 1/1 Running 0 8m41s
暴露Service(NodePort类型)
bash
[root@k8s-master ~]# cat <<EOF | kubectl apply -f -
> apiVersion: v1
> kind: Service
> metadata:
> name: dvwa
> namespace: security-test
> spec:
> type: NodePort
> selector:
> app: dvwa
> ports:
> - port: 80
> targetPort: 80
> nodePort: 30081
> EOF
service/dvwa created

开发Python安全测试脚本
端口扫描
已成功检测到Kubernetes节点192.168.58.232
的开放端口(30080
和30081
)
bash
[root@k8s-master ~]# python3 port_scanner.py --target 192.168.58.232 --start-port 30000 --end-port 30100 --output k8s_ports.txt
[+] 30080/TCP Open
[+] 30081/TCP Open
Scan completed in 0:00:00.229895
Open ports saved to k8s_ports.txt
[root@k8s-master ~]# ll
total 436
-rw-------. 1 root root 1244 Dec 25 07:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 238376 Dec 25 08:22 calico.yaml
-rw-r--r--. 1 root root 189916 Dec 25 08:04 calico.yaml.0
-rw-r--r--. 1 root root 12 Mar 9 05:04 k8s_ports.txt
-rw-r--r--. 1 root root 1660 Mar 9 05:03 port_scanner.py
[root@k8s-master ~]# cat k8s_ports.txt
30080
30081
SQL注入
bash
[root@k8s-master ~]# python3 sql_detector.py --url http://192.168.58.232:30081/login.php --method POST --param username
[*] Testing URL: http://192.168.58.232:30081/login.php
[+] Payload成功: ' OR '1'='1
[!] SQL Injection vulnerability detected!
