Python Network Hacking with Kali Linux and Scapy = attack one! πŸ˜€

David Bombal
28 Jul 202114:05

Summary

TLDRThis video demonstrates the power of Python and network knowledge to manipulate network traffic using Scapy. The host shows how to forge and inject packets to disrupt a network's Spanning Tree Protocol, a common method to prevent loops in corporate environments. The video serves as a cautionary tutorial, urging viewers to use such skills ethically for network protection rather than malicious intent. It also emphasizes the importance of proper network configuration to prevent such attacks.

Takeaways

  • 🐍 Coding in Python combined with network knowledge can be powerful for both ethical hacking and network protection.
  • πŸ” The script uses Scapy, a packet manipulation tool, to demonstrate how to capture and manipulate network packets.
  • πŸš€ The video aims to educate on how to use Python and network understanding for good, like protecting companies, rather than causing harm.
  • πŸ”’ It emphasizes the importance of securing networks by configuring them properly, such as enabling features like Root Guard.
  • πŸ“š The presenter suggests obtaining certifications like Network+ or CCNA for a deeper understanding of networking.
  • πŸ’‘ The script captures Spanning Tree Protocol (STP) frames, which are crucial for understanding and manipulating network traffic.
  • πŸ› οΈ By manipulating STP frames, it's possible to disrupt network operations, as demonstrated by the script that can DOS a network.
  • πŸ“‘ The video includes a practical demonstration of how a simple script can change the root port of a switch, causing a denial of service.
  • 🚨 A warning is given against using such scripts for malicious purposes and an encouragement to use knowledge for ethical hacking and network security.
  • 🌐 The video concludes with a call to action for viewers to subscribe to the channel for more content on hacking and network security.

Q & A

  • What is the main purpose of the video script?

    -The main purpose of the video script is to demonstrate how knowledge of Python coding and networking can be used to manipulate network traffic, specifically by forging and injecting packets into a network. The script emphasizes the potential power and danger of such skills and urges the use of these abilities for good, such as protecting networks, rather than for malicious purposes.

  • What is the significance of using Python in network manipulation as described in the script?

    -Python is significant in network manipulation because it allows for the creation of scripts that can capture, manipulate, and send packets back into the network. Its simplicity and the powerful libraries available, such as Scapy, make it an ideal tool for network testing and security auditing.

  • What is Scapy and how is it used in the context of the video?

    -Scapy is a powerful interactive packet manipulation program that allows the forging or decoding of packets of a wide range of protocols. In the video, it is used to capture, manipulate, and re-inject packets into the network to demonstrate how easily a network can be compromised if not properly secured.

  • Why is it important to have a good understanding of networking before attempting to manipulate network traffic?

    -A good understanding of networking is crucial because it provides the necessary knowledge to identify vulnerabilities and configure networks securely. Without this understanding, one might inadvertently cause damage or fail to recognize the potential impact of their actions on network stability and security.

  • What is the Spanning Tree Protocol (STP) and why is it targeted in the script?

    -The Spanning Tree Protocol (STP) is a network protocol that ensures a loop-free topology for any bridged Ethernet local area network. It is targeted in the script because manipulating STP can cause a denial of service by creating network loops or blocking legitimate paths, effectively disrupting network communication.

  • How does the script demonstrate the potential to disrupt a network using STP?

    -The script demonstrates network disruption by capturing STP frames, manipulating them to change the path cost and bridge MAC address, and then re-injecting these manipulated frames into the network. This causes the network switches to re-evaluate their root paths, potentially blocking legitimate connections and creating a denial of service.

  • What is the ethical stance taken by the script's author regarding the use of network manipulation techniques?

    -The script's author takes an ethical stance, advocating for the use of network manipulation techniques for good purposes, such as network security and protection, rather than for malicious intent. The author emphasizes the responsibility of using such powerful knowledge to protect rather than to harm.

  • What is the role of permissions in capturing network packets as mentioned in the script?

    -Permissions play a critical role in capturing network packets. The script mentions a 'permission error' when attempting to capture packets without administrative privileges. Using 'sudo' provides the necessary permissions to capture and manipulate network traffic, which is essential for network testing and security auditing.

  • How does the script use packet manipulation to create a denial of service (DoS) attack?

    -The script creates a DoS attack by manipulating STP packets to make a switch believe that the best path to the root bridge is through the machine running the script, rather than the actual root port. This causes the switch to block the legitimate root port, redirecting all traffic to the script's machine, effectively cutting off network communication between devices.

  • What is the significance of the script's simplicity in terms of line count?

    -The script's simplicity, with less than 10 lines of code, underscores the ease with which someone with knowledge of Python and networking can potentially disrupt a network. This highlights the importance of network security measures and the potential risks posed by even basic scripting knowledge.

Outlines

00:00

🐍 Python and Network Power

The speaker emphasizes the potential power and danger of combining Python coding skills with a deep understanding of networking. They caution against using these skills for malicious purposes and instead advocate for ethical hacking to protect networks. The video aims to demonstrate the simplicity of breaking a network using Python, specifically by manipulating packets with Scapy, a tool for packet manipulation. The speaker sets up a network environment with Cisco switches and MacBooks to illustrate the process and encourages viewers to subscribe for more content on hacking networks ethically.

05:01

πŸ” Capturing and Manipulating Network Packets

The speaker demonstrates how to capture a packet from the network, specifically a Spanning Tree Protocol (STP) frame, using Scapy. They explain the importance of understanding the content of the captured packet and how to view it in a readable format. The video then transitions into showing how to manipulate the captured packet by altering its path cost and bridge MAC address, with the intention of disrupting the network's normal functioning. The speaker uses this example to highlight the ease with which a network can be compromised if not configured with security in mind.

10:02

πŸ’₯ Disrupting Network with a Simple Script

The speaker executes a script that sends manipulated STP frames into the network, effectively creating a denial of service (DoS) attack by changing the root port of a switch. This action blocks legitimate traffic and causes ping requests between two MacBooks to time out. The video shows the switch's console changing its root port from the intended port to the one manipulated by the script. The speaker reiterates the importance of using such knowledge for good, understanding networks, and securing them against simple attacks. The video concludes with a call to action for viewers to subscribe and support the channel for more educational content.

Mindmap

Keywords

πŸ’‘Packets

Packets are units of data transmitted across a network. In the script, the speaker discusses capturing packets off the network and manipulating them, which is a fundamental concept in network hacking and security. The script demonstrates how packets can be used to disrupt network operations, such as by forging or spoofing them to interfere with the Spanning Tree Protocol (STP).

πŸ’‘Python

Python is a high-level programming language known for its readability and versatility. The video emphasizes the power of Python in network manipulation, suggesting that with knowledge of Python and networking, one can perform powerful actions, either for good (like securing networks) or for malicious purposes. The script provided uses Python to demonstrate how to capture and manipulate network packets.

πŸ’‘Scapy

Scapy is a Python-based interactive packet manipulation program. It allows for the forging and decoding of packets of various protocols. In the script, Scapy is used to craft and inject manipulated packets into a network, showcasing its potential for both educational and potentially harmful activities, depending on the intent of the user.

πŸ’‘Spanning Tree Protocol (STP)

STP is a network protocol that prevents loops in a network by creating a logical loop-free topology. The script describes how an attacker might manipulate STP to disrupt network operations, such as by sending forged BPDUs (Bridge Protocol Data Units) to change the root bridge's perception and cause a denial of service.

πŸ’‘Manipulated or Forged Packets

In the context of the script, manipulated or forged packets refer to the intentional alteration of data packets to deceive network protocols or systems. The video demonstrates how such packets can be crafted using Python and Scapy to disrupt network operations, such as by causing a switch to change its root port, leading to a denial of service.

πŸ’‘Network Topology

Network topology refers to the arrangement of the network components and how they are interconnected. The script describes a specific network topology with Cisco switches and MacBooks, which is used to illustrate how network attacks can be executed and how understanding topology is crucial for both attackers and defenders.

πŸ’‘Kali Linux

Kali Linux is a Linux distribution designed for digital forensics and penetration testing. In the script, Kali is used as the operating system within a virtual machine to perform network attacks. It is noted for its pre-installed security tools, such as Scapy, which are used in the demonstration to capture and manipulate packets.

πŸ’‘Denial of Service (DoS)

DoS refers to an attack that overwhelms a system, making it unavailable to its intended users. The script demonstrates a DoS attack by manipulating STP to block legitimate traffic, causing a network failure. This is a critical concept in network security, as it illustrates the potential impact of even simple scripts on network reliability.

πŸ’‘Ethical Hacking

Ethical hacking involves assessing computer systems, networks, and applications to find vulnerabilities that a malicious hacker could exploit. The video script promotes the use of hacking skills for ethical purposes, such as strengthening network security, rather than causing harm. It encourages viewers to use their knowledge to protect systems rather than to attack them.

πŸ’‘Root Guard

Root Guard is a security feature used in STP to prevent unauthorized devices from becoming the root bridge. The script mentions the importance of configuring Root Guard to prevent attacks like the one demonstrated, where an attacker could manipulate the network to change the root bridge, causing a DoS.

πŸ’‘BPDUs (Bridge Protocol Data Units)

BPDUs are messages used by STP to manage and maintain the network topology. In the script, the speaker captures and manipulates BPDUs to disrupt the network. Understanding BPDUs is crucial for network engineers to secure networks against attacks that exploit STP vulnerabilities.

Highlights

Demonstrates how to manipulate network packets to disrupt a network using Python and Scapy.

Emphasizes the importance of using such knowledge for ethical purposes, like network protection, rather than malicious intent.

Introduces Scapy as a tool for packet manipulation and its capabilities in various protocols.

Shows how to set up a virtual machine with Kali Linux for network testing purposes.

Explains the concept of Spanning Tree Protocol (STP) and its role in preventing network loops.

Advocates for proper network configuration to prevent security vulnerabilities.

Provides a basic script example to capture and manipulate STP frames using Scapy.

Details the process of capturing packets and how to view them using Scapy's functionalities.

Illustrates how to forge packets to disrupt network communication by manipulating path cost and bridge MAC address.

Discusses the impact of a Denial of Service (DoS) attack on network functionality.

Demonstrates the effectiveness of a simple script in causing a DoS attack on a network.

Shows how to use Scapy to capture and manipulate STP BPDUs to disrupt network traffic.

Explains the concept of root guard in network security and its importance.

Provides a step-by-step guide on how to use Scapy to forge and inject packets into a network.

Warns against the misuse of network knowledge and tools for unethical hacking.

Encourages viewers to subscribe and support the channel for more educational content.

Ends with a reminder to use the demonstrated skills responsibly and for the betterment of network security.

Transcripts

play00:00

now just like that i've been able to dos

play00:02

a network

play00:03

by using packets captured off the

play00:05

network and

play00:06

sending manipulated or forged packets

play00:09

back into the network

play00:10

it's amazing what you'll be able to do

play00:12

if you know how to code in python

play00:14

if you understand how networks work

play00:16

combining knowledge of those two areas

play00:18

will make you

play00:19

very very powerful or very very scary

play00:21

depending on what you do

play00:23

don't use this for malicious purposes

play00:26

use your power for good

play00:28

don't go out there and break networks

play00:30

and get into trouble

play00:31

use what i'm showing you here the power

play00:33

of python power of understanding of

play00:35

networks

play00:35

to do good to protect companies rather

play00:38

than destroy them

play00:39

but i want to show you in this video how

play00:40

a very simple script

play00:42

can break a network

play00:45

[Music]

play00:55

now before we continue if you enjoy

play00:56

these types of hacking videos

play00:58

please consider subscribing to my

play00:59

youtube channel please like this video

play01:01

and click on the bell to get

play01:02

notifications

play01:03

that really does help me with the

play01:04

youtube robots allows me to create more

play01:06

content like this

play01:07

i'm starting a series of videos where

play01:09

i'm going to show you how easy it is to

play01:12

hack

play01:12

networks using python to help us do that

play01:15

we're going to use

play01:16

scapy or scappy if you prefer but i'm

play01:18

going to call this scapy

play01:20

on the scapy website they say that scapy

play01:22

is a powerful

play01:23

interactive packet manipulation program

play01:27

it allows you to forge or decode packets

play01:29

of a wide range of protocols

play01:31

there's a whole bunch of stuff that you

play01:33

can do with scapy i want to make this as

play01:35

interesting as i can

play01:36

and to help demonstrate that i've got

play01:39

the following network

play01:40

i have three cisco switches

play01:43

i've also got two macbooks first macbook

play01:47

is the macbook in front of me

play01:48

macbook is connected to the 3560 cx

play01:52

switch which is the switch on the bottom

play01:54

in this topology

play01:55

i'm running kali within a virtual

play01:58

machine

play01:58

on my windows computer and it's also

play02:00

connected to a 3560

play02:02

so this windows computer over here is

play02:04

running kelly within a virtual machine

play02:06

if you want to see how to set that up

play02:07

have a look at this video where i show

play02:08

you how to download kali

play02:10

and install it within vmware workstation

play02:12

player on windows

play02:14

i typically use a virtual machine on

play02:16

windows just to make it more accessible

play02:18

to more people if you want to run kelly

play02:20

natively you could do that i've also got

play02:22

another windows

play02:23

computer which is behind me so windows

play02:25

laptop behind me

play02:27

so what i'm going to be doing is using

play02:29

kali

play02:30

to sniff traffic from the network and to

play02:32

inject

play02:33

packets and frames into the network so

play02:35

we basically going to inject

play02:37

stuff into the network we're going to

play02:39

forge packets forge frames

play02:41

and send them into the network to break

play02:43

the network

play02:44

in this first example i'll show you how

play02:46

i can break spanning tree protocol

play02:48

or stp which is used in a lot of

play02:49

corporate environments to stop

play02:51

loops if you want to be a good ethical

play02:53

hacker it helps to have an understanding

play02:55

of networking

play02:56

so go and get your network plus

play02:58

certification or ccna

play03:00

do something that gives you a good

play03:02

understanding of networking because if

play03:03

you understand networking

play03:05

you'll see that it's very very easy to

play03:07

break networks if they're not configured

play03:09

properly

play03:10

if you're a network engineer i'm

play03:12

hopefully going to demonstrate to you

play03:14

why you should enable or configure your

play03:16

networks properly

play03:18

why you should run root guard as an

play03:20

example why you don't want to accept

play03:21

bpdus

play03:22

from any device on the network you need

play03:24

to configure your network with security

play03:26

in mind

play03:27

okay so i'm going to demonstrate a

play03:29

little bit about scapy and then i'll

play03:31

show you how you can capture packets off

play03:33

the wire

play03:34

manipulate them and send them into the

play03:36

network to break the network

play03:38

so on my kali or kali linux vm

play03:41

i'm going to open up a terminal

play03:46

i'm going to start python 3. scapy is

play03:49

installed by default

play03:51

on kali that makes life a lot easier

play03:54

here's a very basic script i'm going to

play03:57

import scapy into python

play04:01

and then what i can do is sniff for a

play04:03

packet off the wire

play04:05

now i've put links to all these scripts

play04:07

on github so use the link below

play04:09

if you want to download these scripts or

play04:11

get access to them they're on my github

play04:13

page

play04:14

so i'll paste that command in sniff and

play04:18

we are sniffing

play04:19

the well-known mac address for spanning

play04:21

tree and notice i get permission

play04:23

error operation not permitted and that's

play04:26

because i should have used

play04:28

sudo python3 so sudo

play04:31

python3 put in my password

play04:35

okay so try that again import scapy

play04:42

and then we want to capture

play04:47

traffic to this well-known mac address

play04:50

and store that in a variable

play04:54

okay so that's now been done so now we

play04:56

can view

play04:57

the captured packet by simply using the

play05:01

command packet

play05:02

zero now i only captured one packet or

play05:05

one frame in this example

play05:07

if i captured two i could use one here

play05:10

rather than zero to see the second

play05:12

packet or second frame if you want to be

play05:14

specific

play05:16

okay so that's what it looks like not

play05:18

very easy to read

play05:20

so what we can do is use the show

play05:22

command to

play05:23

show the information nicely so packet

play05:26

zero show and there you go

play05:29

i can see that the frame that was

play05:32

captured

play05:33

it's an 802.3 frame in other words it's

play05:36

ethernet

play05:37

destination mac addresses this source

play05:40

mac addresses this

play05:42

we can see link layer control

play05:44

information

play05:45

but what's important is the spanning

play05:47

tree part that's what we're interested

play05:49

in

play05:50

you can see the root id is this the root

play05:53

has this mac address

play05:55

the switch that sent the message was

play05:57

this switch

play05:59

you can see information such as the port

play06:00

id and other information

play06:03

so basically what we've done now is we

play06:05

have captured

play06:06

a packet off the wire and we can view

play06:08

the output now you could as an example

play06:11

go through the different layers by using

play06:15

packet to zero

play06:16

first packet that was captured and first

play06:19

layer that shows us exactly the same

play06:22

information

play06:23

if i want to see layer 1 that shows me

play06:26

that

play06:27

or if i want to see layer 2 in the

play06:29

output i see that

play06:30

so i only see spanning tree information

play06:32

or rather than doing it that way i could

play06:34

simply specify stp

play06:36

so only show me the stp information so

play06:39

just by using two lines of code

play06:42

importing escaping to python

play06:43

and specifying what i want to view i've

play06:46

been able to capture spanning tree

play06:47

frames off the wire

play06:48

and i can interrogate that i can see

play06:50

what's going on

play06:52

but now let me show you how i can

play06:53

leverage that to break the network

play06:56

so what i'm going to do is capture the

play06:58

frame off the wire

play07:00

but then i'm going to manipulate things

play07:02

so i'm going to change the packet

play07:04

path cost to this the bridge mac

play07:08

i'm going to change to the root mac

play07:11

so it's as if the spanning tree root is

play07:13

sending messages

play07:14

to the switch the switch that advertised

play07:18

this frame is not the root switch it's

play07:21

the 3560 switch in my topology who's not

play07:24

the root

play07:24

the root is one of the other switches

play07:26

but what i could do is block the

play07:28

connection to the root

play07:29

so on the 3560 show spanning tree

play07:33

i can see that its root port

play07:36

is gigabit 0 2 which is the connection

play07:40

to the 2960 switch

play07:41

so the 2960 switch is the root in this

play07:43

topology not

play07:45

the switch i'm connected to now what

play07:47

we're going to do with this first

play07:48

script is capture spanning tree frames

play07:51

and then what i'm going to do is block

play07:53

the port to the root switch by setting

play07:55

the cost to the root to zero

play07:58

so basically this switch here

play08:01

is going to think that it's got a better

play08:04

path to the root switch

play08:05

via the kali virtual machine rather than

play08:08

its actual

play08:09

root port so the root port on this

play08:11

switch is this port

play08:13

this switch is the route bridge but

play08:15

we're going to tell

play08:16

this switch that the best way to get to

play08:18

the route is via us

play08:20

and we can do that by manipulating the

play08:23

cost

play08:24

this switch sees the cost to the root

play08:26

switch as

play08:27

full but we're going to change the cost

play08:31

to zero we're going to change the

play08:33

advertising bridge

play08:34

mac address to the root switch so

play08:37

basically

play08:38

this switch is going to think that this

play08:40

is the best port to use to get to the

play08:42

root switch

play08:43

rather than this port once again show

play08:46

spanning tree on the switch

play08:47

its root port is gigabit 0 2

play08:51

which is the port to the 2960 we're

play08:53

gonna change that

play08:55

to gigabit zero five which is currently

play08:58

a designated port

play08:59

but we're gonna make that the root port

play09:00

and that will basically do a denial of

play09:02

service attack against the macbooks so

play09:04

rather than this macbook being able to

play09:06

ping this macbook

play09:08

traffic is going to be sent to us rather

play09:10

than

play09:11

to this macbook so we could for instance

play09:14

capture that traffic and do something

play09:15

with it

play09:15

but for this basic demonstration i'm

play09:17

just going to show you how to destroy

play09:18

the network

play09:19

okay macbook 1 has this ip address 10

play09:22

110

play09:23

can it ping macbook 2 which

play09:27

has this ip address 10 1 1.

play09:30

i know that already but just to show it

play09:32

here

play09:33

macbook 2 has this ip address 10 1 1

play09:36

1. let's see if we can break the network

play09:40

so pings are currently succeeding

play09:42

macbook 1 can ping macbook 2.

play09:45

okay so on our kelly machine we're

play09:46

importing scapy we're going to capture

play09:48

a spanning tree bpdu we're going to set

play09:51

the path cost to zero we're going to set

play09:53

the bridge mac address to the root mac

play09:56

address

play09:56

we're going to set the port id to one

play09:59

we're going to send multiple bpdus into

play10:01

the network

play10:02

so we'll send a bpdu that's manipulated

play10:05

we'll wait a second

play10:06

and what i'll do actually is put the

play10:09

timer here

play10:11

so we'll send a packet into the network

play10:14

we'll wait a second and then we'll loop

play10:16

around

play10:18

so i'll copy that simple script now

play10:21

notice the script is very small

play10:23

it's less than 10 lines of code most of

play10:25

it is comments but very basic script

play10:27

what i'll do is quit python here so i'm

play10:30

in

play10:31

the cali shell and i'll type nano

play10:35

http hack root port dot py

play10:40

and i'll paste that script in control x

play10:43

save that so now if i run python 3 and i

play10:46

need to use sudo

play10:48

so sudo python 3 sdp

play10:51

hack root port currently this mac can

play10:54

ping the other mac

play10:56

but if i run that

play10:59

we've captured a frame packet has been

play11:02

sent into the network

play11:03

notice pings are timing out i've dosed

play11:06

this network

play11:07

or i've created a denial of service

play11:10

attack against this network

play11:12

pings are timing out if i look at the

play11:14

console

play11:15

of the switch previously its root port

play11:17

was gigabit zero two

play11:19

now it's gigabit zero

play11:22

five in other words this port

play11:26

we have made the root port of the switch

play11:28

us we've become the root port

play11:31

the port to the root bridge has been

play11:32

blocked you can see here it says

play11:34

alternate blocking

play11:36

we've essentially used spanning tree

play11:38

against itself

play11:39

captured a packet of the wire changed a

play11:41

few values

play11:42

sent it back into the network and dosed

play11:45

the network basically

play11:47

spanning tree is blocking the right port

play11:49

and we are getting all traffic

play11:51

to come to us now that timed out

play11:54

notice the root port is back to gigabit

play11:57

zero two

play11:59

so pings are succeeding once again let

play12:01

me run that script again i was a bit

play12:02

slow there

play12:04

so pings has started to time out again

play12:06

and on

play12:07

the kali virtual machine if i ran

play12:10

wireshark

play12:17

and search for icmp you'll notice that i

play12:20

see

play12:21

icmp echo messages from 10

play12:24

110 to 10 111

play12:28

i'm capturing packets from the macbook

play12:31

it can't send traffic to the other

play12:32

device

play12:33

because i'm blocking the port so again

play12:37

that's what it looked like previously

play12:40

now the root port is us

play12:45

i'll make that longer because it times

play12:46

out as i'm speaking to you

play12:49

so running that again root port

play12:52

was gigabit zero two you can see it's

play12:55

listening at this point it was

play12:57

forwarding as it's trying to learn where

play12:59

the root bridge is

play13:00

but now it's blocking so i've basically

play13:04

used spanning tree against itself to dos

play13:07

the network

play13:08

and this script is less than 10 lines of

play13:10

code if you know python

play13:12

if you know how networks work it's

play13:14

amazing what you can accomplish

play13:16

simplescript with an understanding of

play13:18

networking makes you very dangerous or

play13:20

very powerful

play13:22

please only use this for good do not

play13:25

use these scripts for malicious purposes

play13:28

i own this network i'm testing this on

play13:31

my own network

play13:32

make sure that you understand how

play13:34

networks work make sure that you

play13:35

understand how to protect them

play13:37

because a simple script like this can

play13:39

break an entire network

play13:40

now once again if you enjoyed this video

play13:42

please consider subscribing to my

play13:43

youtube channel please like this video

play13:45

and click on the bell to get

play13:46

notifications i'm david bomble

play13:48

and i want to wish you all the very best

play13:50

only use this for good

play13:52

not for bad

play14:04

oh

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
Python ScriptingNetwork SecurityEthical HackingPacket ManipulationScapy TutorialSTP BypassDoS AttackNetwork ProtocolsCyber DefenseCisco Switches