网络安全之端口扫描(一)

前置介绍

什么是DVWA?

DVWA(Damn Vulnerable Web Application)是一个专门设计用于测试和提高Web应用程序安全技能的开源PHP/MySQL Web应用程序。它是一个具有多个安全漏洞的故意不安全的应用程序,供安全专业人员、渗透测试人员、学生和开发人员用来练习和提升他们的技能。

DVWA的主要特点:

  1. 多种漏洞类型:DVWA包含多种常见的Web应用程序漏洞,如SQL注入、XSS(跨站脚本攻击)、CSRF(跨站请求伪造)、文件包含漏洞、命令注入等。这使用户可以在一个环境中练习和理解不同类型的漏洞。

  2. 不同的安全级别:DVWA提供不同的安全级别(低、中、高和不可能),以帮助用户逐步提高他们的技能和理解。这些级别通过改变应用程序代码和配置的复杂性来增加挑战。

  3. 教育目的:DVWA的设计初衷是用于教育目的,帮助用户理解和识别Web应用程序中的常见漏洞,以及如何利用这些漏洞。

  4. 社区支持和扩展: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!
相关推荐
山东科恩光电1 小时前
安全地毯压敏传感防护在工业机器人与流水线区域的耐腐蚀材质及快速停机应用
安全
奈落246 小时前
AI辅助的另一面:从2026年国际AI安全报告的“故障”清单到国内专家的可靠性短板,自主行动的Agent为什么更难及时干预
人工智能·安全·agent·本地部署·ai 办公
赛博守夜人11 小时前
AI安全攻防与治理之十六:对抗样本、恶意文件与多模态攻击,AI 内容安全检测的真实盲区
人工智能·安全
ZEB110613 小时前
首届安全应急救援机器人大赛在广州举办 深圳璇玑动力斩获多项冠军
安全·机器人·消防
未来之窗软件服务15 小时前
WAF负载均衡+蜜罐混淆安全体系-东方仙盟
运维·安全·负载均衡·仙盟创梦ide·东方仙盟·阿雪技术观·网关开发
高德开放平台16 小时前
构建“车-云-端”安全闭环:新大洲本田通过高德开放平台接入“鹰眼守护预警系统”
安全
dora17 小时前
接口被疯狂调用怎么办?聊聊接口限流
后端·安全
国科安芯17 小时前
长期在轨的计算底座:商业空间站与在轨服务飞行器健康管理中的抗辐射MCU—— 面向可维护空间平台的分层容错与安全通信综述
人工智能·单片机·嵌入式硬件·安全·低轨卫星·抗辐射
kingx318 小时前
Bugku WEB 题解总集:文件包含 / SQLi / 反序列化 / SSTI / 反爬 / 组件漏洞
web安全·网络安全·ctf·bugku
衡石科技18 小时前
让多轮问数保持口径一致:Data Agent 的上下文、偏好与学习开关
人工智能·学习·安全