Python Ethical Hacking - Intercepting and Modifying Packets
INTERCEPTING & MODIFYING PACKETS
Scapy can be used to:
- Create packets.
- Analyze packets.
- Send/receive packets.
But it can't be used to intercept packets/flows.
CLASSIC MITM SCENARIO

MITM - SNIFFING DATA

MITM - MODIFYING DATA




1. Execute the command - iptables to capture the packets into a queue.
iptables -I INPUT -d 10.0.0.0/ -j NFQUEUE --queue-num

2. Access the Packets queue.
Install the module netfilterqueue first.
pip3 install -U git+https://github.com/kti/python-netfilterqueue

3. Write the Python script to intercept and process the packets.
#!/usr/bin/env python
from netfilterqueue import NetfilterQueue def process_packet(packet):
print(packet)
packet.accept() queue = NetfilterQueue()
queue.bind(1, process_packet)
try:
queue.run()
except KeyboardInterrupt:
print('')

We can also drop the packets through function packet.drop().
4. Use the following command to stop the packet capturing.
iptables --flush
Converting Packets to Scapy Packets
1. Execute the iptables command to capture the OUTPUT and INPUT packets.
iptables -I OUTPUT -j NFQUEUE --queue-num iptables -I INPUT -j NFQUEUE --queue-num

2. Execute the following Python script to process the captured packets.
#!/usr/bin/env python
from netfilterqueue import NetfilterQueue def process_packet(packet):
print(packet)
packet.accept() queue = NetfilterQueue()
queue.bind(0, process_packet)
try:
queue.run()
except KeyboardInterrupt:
print('')

3. Convert the packet to scapy packet and show on the screen.
#!/usr/bin/env python from netfilterqueue import NetfilterQueue
from scapy.layers.inet import IP def process_packet(packet):
scapy_packet = IP(packet.get_payload())
print(scapy_packet.show())
packet.accept() queue = NetfilterQueue()
queue.bind(0, process_packet)
try:
queue.run()
except KeyboardInterrupt:
print('')

4. Stop the capture of the packet by the command.
iptables --flush
Python Ethical Hacking - Intercepting and Modifying Packets的更多相关文章
- Python Ethical Hacking - Packet Sniffer(1)
PACKET_SNIFFER Capture data flowing through an interface. Filter this data. Display Interesting info ...
- Python Ethical Hacking - MODIFYING DATA IN HTTP LAYER(2)
MODIFYING DATA IN HTTP LAYER Edit requests/responses. Replace download requests. Inject code(html/Ja ...
- Python Ethical Hacking - MODIFYING DATA IN HTTP LAYER(1)
MODIFYING DATA IN HTTP LAYER Edit requests/responses. Replace download requests. Inject code(html/Ja ...
- Python Ethical Hacking - MODIFYING DATA IN HTTP LAYER(3)
Recalculating Content-Length: #!/usr/bin/env python import re from netfilterqueue import NetfilterQu ...
- Python Ethical Hacking - ARP Spoofing
Typical Network ARP Spoofing Why ARP Spoofing is possible: 1. Clients accept responses even if they ...
- Python Ethical Hacking - Bypass HTTPS(1)
HTTPS: Problem: Data in HTTP is sent as plain text. A MITM can read and edit requests and responses. ...
- Python Ethical Hacking - Packet Sniffer(2)
Capturing passwords from any computer connected to the same network. ARP_SPOOF + PACKET_SNIFFER Ta ...
- Python Ethical Hacking - BACKDOORS(8)
Cross-platform hacking All programs we wrote are pure python programs They do not rely on OS-specifi ...
- Python Ethical Hacking - NETWORK_SCANNER(2)
DICTIONARIES Similar to lists but use key instead of an index. LISTS List of values/elements, all ca ...
随机推荐
- leetcode27之移除元素
题目描述: 给你一个数组 nums 和一个值 val,你需要 原地 移除所有数值等于 val 的元素,并返回移除后数组的新长度. 不要使用额外的数组空间,你必须仅使用 O(1) 额外空间并 原地 修改 ...
- 一、Adobe Premiere Pro CC概述
一.Adobe Premiere Pro CC概述 使用建议 一.开始 二.在Adobe Premiere Pro CC执行非线性编辑 1.标准的视频剪辑工作流 2.使用Premiere增强工作流 p ...
- layui动态添加的元素click等事件触发不了的解决办法
在页面加载完成时候 '.add_project' 元素是可以触发click时间的,当动态添加 '.add_project' 时候,新添加的元素却触发不了click事件,类似下面的写法: $(" ...
- linux环境搭建单机kafka
准备工作: jdk-8u191-linux-x64.rpm | zookeeper-3.4.6.tar.gz | kafka_2.11-2.2.0.tgz 对应的地址 zookeeper: ...
- vueX基础知识笔记
接着昨天的知识点 mutations提交时,有时候达不到想要的响应式,我们必须要将数据提前放到state中,否则不会达到响应式的效果.比如 state.info['address'] = value ...
- c++数字转化为字符串、字符串转换为数字
char ch[20]; int i =1; int j = 2; char *p = "34567"; 数字装换为字符串 sprintf(ch , "%d,%d&quo ...
- Elasticsearch从入门到放弃:分词器初印象
Elasticsearch 系列回来了,先给因为这个系列关注我的同学说声抱歉,拖了这么久才回来,这个系列虽然叫「Elasticsearch 从入门到放弃」,但只有三篇就放弃还是有点过分的,所以还是回来 ...
- IOC和DI的概念,以及Spring框架的介绍
对于Java开发者来说,Spring肯定是一个避不开的技术.所以准备系统的学下Spring框架. 我给自己设计的学习路线是这样的:首先阅读下Spring的官方文档(注意Spring官网上有很多项目,S ...
- sql:主键(primary key)和唯一索引(unique index)区别
主键一定是唯一性索引,唯一性索引并不一定就是主键. 所谓主键就是能够唯一标识表中某一行的属性或属性组,一个表只能有一个主键,但可以有多个候选索引. 因为主键可以唯一标识某一行记录,所以可以确保执行数据 ...
- linux下 解释 终端命令 ls -al或者ls -li 输出的信息
$ ls -al drwxr-xr-x. wjshan0808 wjshan0808 Sep : .cache $ ls -li ...