Slide 1

Slide 1 text

Introduction to Network Programming with Python Rafael Santos @Tucif Hacking.mx meetup

Slide 2

Slide 2 text

● Why? ● Network Packets ● Packets and Python ● Demo Network Programming with Python

Slide 3

Slide 3 text

Why? With most tools you won't build someting the author did not imagine. To stop being an script kiddie. It's fun!

Slide 4

Slide 4 text

Let's talk a bit about networking How/Why does the internet work? How does my machine talk to others?

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

IP

Slide 7

Slide 7 text

But what if the packet is.. manipulated? captured? sent to other place? ...

Slide 8

Slide 8 text

Wait a minute.. Who creates the packets? Can I create my own packets?

Slide 9

Slide 9 text

Scapy ● Written in Python ● Command-line interactive ● TCP,IP,ICMP,ARP,... ● Easy encapsulation ● Decodes but doesn't interpret

Slide 10

Slide 10 text

Scapy Creating an IP packet: >>> ip = IP() >>> ip.dst = "127.0.0.1" >>> ip

Slide 11

Slide 11 text

Sending packets send(IP(dst="10.1.99.2")/ICMP()/"HelloWorld") I can do that with a simple ping!

Slide 12

Slide 12 text

Sending evil packets send(IP(src="10.1.99.100", dst=" 10.1.99.2")/ICMP()/"HelloWorld")

Slide 13

Slide 13 text

Demo time! Let's build a Port Scanner!

Slide 14

Slide 14 text

scanPacket = IP(dst='192.168.1.177')/TCP (dport=8080,sport=459) #sendReceive sr(scanPacket) Scanning Ports

Slide 15

Slide 15 text

Interpreting results IP / TCP 192.168.1.185:(sport) > 192.168.1.177:(dport) S ==> IP / TCP 192.168.1.177:(dport) > 192.168.1.185:(sport) SA

Slide 16

Slide 16 text

References Warriors of the Net (warriorsofthe.net) The TCP/IP Guide (TCPIPGuide.com) The Very Unofficial Dummies Guide to Scapy (scapy-guide.googlecode.com) Scapy Official docs (http://www.secdev. org/projects/scapy/doc/)

Slide 17

Slide 17 text

Q & A @Tucif