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

前置介绍

什么是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的开放端口(3008030081

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!
相关推荐
qq_430908573 小时前
网络安全-机遇与挑战
安全
希望奇迹很安静3 小时前
SSRF_XXE_RCE_反序列化学习
学习·web安全·ctf·渗透测试学习
程序员编程指南5 小时前
Qt 网络编程进阶:网络安全与加密
c语言·网络·c++·qt·web安全
Johny_Zhao6 小时前
Centos8搭建hadoop高可用集群
linux·hadoop·python·网络安全·信息安全·云计算·shell·yum源·系统运维·itsm
安 当 加 密9 小时前
守护汽车“空中升级“:基于HSM/KMS的安全OTA固件签名与验证方案
安全·汽车
大咖分享课17 小时前
多租户系统中的安全隔离机制设计
人工智能·安全·安全隔离
荔枝吻17 小时前
软件异常读写威胁硬盘安全:从过往案例到防护之道
安全·硬盘
小马爱打代码17 小时前
Spring Boot 接口安全设计:接口限流、防重放攻击、签名验证
网络·spring boot·安全
北极光SD-WAN组网20 小时前
工业互联网时代,如何通过混合SD-WAN提升煤炭行业智能化网络安全
网络·安全·web安全
深圳安锐科技有限公司21 小时前
基坑渗压数据不准?选对渗压计能实现自动化精准监测吗?
安全·自动化·自动化监测·大坝监测·渗压计