Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Internet by Jessica McKellar

The Internet by Jessica McKellar

PyCon 2013

March 17, 2013
Tweet

More Decks by PyCon 2013

Other Decks in Technology

Transcript

  1. The Internet
    @jessicamckellar
    http://jesstess.com

    View Slide

  2. You type http://python.org
    into your browser bar and
    press Enter. What happens?

    View Slide

  3. View Slide

  4. Questions
    What
    Where
    How
    is python.org?
    is python.org?
    does my computer talk to
    python.org?
    does my computer say to
    python.org?
    What

    View Slide

  5. Protocol
    A format and rules for
    exchanging information

    View Slide

  6. Internet
    protocols
    are layered,
    one protocol
    per task

    View Slide

  7. What is python.org?
    Domain Name Service
    (DNS) translates hostnames to
    addresses
    python.org → 82.94.164.162

    View Slide

  8. View Slide

  9. Where is python.org?
    Internet Protocol (IP)
    handles addressing and routing

    View Slide

  10. Your packets of data hop from router to router
    through the Internet to their destination

    View Slide

  11. scapy demo!

    View Slide

  12. View Slide

  13. >>> res, _ = traceroute("python.org")
    Begin emission:*.*.*.*.*.*.*.*.*.*.*.
    82.94.164.162:tcp80
    1 192.168.1.1
    2 96.120.66.81
    3 68.85.160.37
    4 68.85.106.29
    5 68.86.90.57
    6 68.86.85.22
    7 75.149.228.126
    8 134.222.226.154
    9 134.222.231.148
    10 134.222.231.156
    11 134.222.229.113
    12 134.222.97.18
    13 194.109.5.82
    14 194.109.12.34
    15 82.94.164.162
    >>> res.graph(target="> traceroute.svg")
    openwrt.lan
    96.120.168.1.1
    cambridge.ma.boston.comcast.net
    needham.ma.boston.comcast.net
    newyork.ny.ibone.comcast.net
    111eighthave.ny.ibone.comcast.net
    nyk-s2-rou-1001.us.eurorings.net
    ldn-s2-rou-1101.uk.eurorings.net
    ldn-s1-rou-1021.uk.eurorings.net
    asd2-rou-1022.nl.eurorings.net
    asd2-rou-1044.nl.eurorings.net
    134.222.97.18
    xr4.1d12.xs4all.net
    swcolo2.3d12.xs4all.net
    dinsdale.python.org

    View Slide

  14. Me
    python.org

    View Slide

  15. Me

    View Slide

  16. View Slide

  17. View Slide

  18. python.org

    View Slide

  19. traceroute_ips = """
    96.120.66.81
    68.85.160.37
    68.85.106.29
    68.86.90.57
    68.86.85.22
    75.149.228.126
    134.222.226.154
    134.222.231.148
    134.222.231.156
    134.222.229.113
    134.222.97.18
    194.109.5.82
    194.109.12.34
    82.94.164.162
    """.strip().split("\n")

    View Slide

  20. import pygeoip
    gi = pygeoip.GeoIP("GeoLiteCity.dat")
    for ip in traceroute_ips:
    record = gi.record_by_addr(ip)
    print ip.ljust(15),
    print record["country_name"],
    if record["time_zone"]:
    print record["time_zone"],
    print ""

    View Slide

  21. $ python geolocate.py
    96.120.66.81 United States Boston
    68.85.160.37 United States Boston
    68.85.106.29 United States Boston
    68.86.90.57 United States New_York
    68.86.85.22 United States New_York
    75.149.228.126 United States New_York
    134.222.226.154 United Kingdom London
    134.222.231.148 United Kingdom London
    134.222.231.156 Netherlands Amsterdam
    134.222.229.113 Netherlands Amsterdam
    134.222.97.18 Netherlands Amsterdam
    194.109.5.82 Netherlands Amsterdam
    194.109.12.34 Netherlands Amsterdam
    82.94.164.162 Netherlands Amsterdam

    View Slide

  22. http://submarinecablemap.com

    View Slide

  23. View Slide

  24. Where is python.org?
    Internet Protocol (IP)
    IP handles addressing and
    routing

    View Slide

  25. How does my computer
    talk to python.org?
    Transmission Control
    Protocol (TCP)
    TCP reliably delivers data

    View Slide

  26. View Slide

  27. Application-layer
    protocols that use TCP
    web: HTTP
    chat: IRC, XMPP/Jabber
    email: SMTP, POP3, IMAP
    Each application uses a different “port”
    number, so many different applications can use
    TCP to talk to an IP address at the same time

    View Slide

  28. How does my computer
    talk to python.org?
    Transmission Control
    Protocol (TCP)
    TCP reliably delivers data

    View Slide

  29. What does my computer
    say to python.org?
    HyperText Transfer
    Protocol (HTTP)
    Clients use HTTP to request
    resources from servers

    View Slide

  30. Resources
    • HTML
    • images
    • textual or binary data
    • dynamically-generated query results
    ://python.org
    http

    View Slide

  31. How to be a web
    browser
    telnet demo!

    View Slide

  32. View Slide

  33. $ telnet python.org 80
    Trying 82.94.164.162...
    Connected to python.org.
    Escape character is '^]'.
    GET / HTTP/1.1
    Host: python.org

    View Slide

  34. HTTP/1.1 200 OK
    Date: Mon, 04 Mar 2013 00:22:30 GMT
    Server: Apache/2.2.16 (Debian)
    Last-Modified: Fri, 01 Mar 2013
    22:31:40 GMT
    Content-Type: text/html


    Python Programming Language
    – Official Website


    View Slide

  35. HTTP/1.1 200 OK
    Date: Mon, 04 Mar 2013 00:22:30 GMT
    Server: Apache/2.2.16 (Debian)
    Last-Modified: Fri, 01 Mar 2013
    22:31:40 GMT
    Content-Type: text/html


    Python Programming Language
    – Official Website


    View Slide

  36. HTTP/1.1 200 OK
    Date: Mon, 04 Mar 2013 00:22:30 GMT
    Server: Apache/2.2.16 (Debian)
    Last-Modified: Fri, 01 Mar 2013
    22:31:40 GMT
    Content-Type: text/html


    Python Programming Language
    – Official Website


    View Slide

  37. HTTP/1.1 200 OK
    Date: Mon, 04 Mar 2013 00:22:30 GMT
    Server: Apache/2.2.16 (Debian)
    Last-Modified: Fri, 01 Mar 2013
    22:31:40 GMT
    Content-Type: text/html


    Python Programming Language
    – Official Website


    View Slide

  38. HTTP/1.1 200 OK
    Date: Mon, 04 Mar 2013 00:22:30 GMT
    Server: Apache/2.2.16 (Debian)
    Last-Modified: Fri, 01 Mar 2013
    22:31:40 GMT
    Content-Type: text/html


    Python Programming Language
    – Official Website


    View Slide

  39. import urllib2
    urllib2.urlopen(
    "http://python.org").read()
    HyperText Transfer Protocol
    HyperText Markup Language
    Scrapy: it GETs the Web

    View Slide

  40. How to be a
    web server

    View Slide

  41. class HTTPProtocol(basic.LineReceiver):
    def __init__(self):
    self.lines = []
    def lineReceived(self, line):
    self.lines.append(line)
    if not line:
    self.sendResponse()
    def sendResponse(self):
    self.sendLine("HTTP/1.1 200 OK")
    self.sendLine("")
    for line in self.lines:
    self.sendLine(line)
    self.transport.loseConnection()
    reactor.listenTCP(80, HTTPFactory())
    reactor.run()
    Twisted HTTP
    echo server

    View Slide

  42. class HTTPProtocol(basic.LineReceiver):
    def __init__(self):
    self.lines = []
    def lineReceived(self, line):
    self.lines.append(line)
    if not line:
    self.sendResponse()
    def sendResponse(self):
    self.sendLine("HTTP/1.1 200 OK")
    self.sendLine("")
    for line in self.lines:
    self.sendLine(line)
    self.transport.loseConnection()
    reactor.listenTCP(80, HTTPFactory())
    reactor.run()

    View Slide

  43. GET / HTTP/1.1
    Host: localhost:80
    Connection: keep-alive
    Accept: text/html,application/xhtml
    +xml,application/xml;q=0.9,*/*;q=0.8
    User-Agent: Mozilla/5.0 (Macintosh;
    Intel Mac OS X 10_8_2) AppleWebKit/
    537.17 (KHTML, like Gecko) Chrome/
    24.0.1312.57 Safari/537.17
    Accept-Encoding: gzip,deflate,sdch
    Accept-Language: en-US,en;q=0.8
    Accept-Charset:
    ISO-8859-1,utf-8;q=0.7,*;q=0.3
    What your
    browser sends
    web servers

    View Slide

  44. What does my computer
    say to python.org?
    HyperText Transfer
    Protocol (HTTP)
    Clients use HTTP to request
    resources from servers

    View Slide

  45. You type http://python.org
    into your browser bar and
    press Enter. What happens?

    View Slide

  46. IP IP
    TCP TCP
    HTTP HTTP
    addressing and routing
    reliable delivery
    requesting resources
    DNS DNS
    hostnames → IP addresses

    View Slide


  47. View Slide

  48. View Slide

  49. Surfing the web
    protocol
    source IP
    destination IP protocol data

    View Slide

  50. Lonely printers
    source IP
    destination IP
    protocol
    protocol data

    View Slide

  51. Lonely TiVos

    View Slide

  52. Errors
    TCP protocol,
    retransmitting lost data

    View Slide

  53. Encrypted communication
    source IP
    destination IP
    protocol
    protocol data

    View Slide

  54. IRC

    View Slide

  55. IRC
    IRC server
    prompting
    for a
    password

    View Slide

  56. IRC
    My password, django4life

    View Slide


  57. View Slide

  58. One last demo
    How to propose marriage
    on your local network
    using Scapy and ARP-cache
    poisoning

    View Slide

  59. Lonely printers
    Address Resolution
    Protocol (ARP) maps hardware
    (MAC) addresses to IP addresses

    View Slide

  60. View Slide

  61. What next?
    •Twisted (visit me at the Expo
    Hall!)
    •Scapy
    •wireshark

    View Slide

  62. @jessicamckellar
    http://jesstess.com
    Thank you!

    View Slide

  63. A map of the entire Internet in 1977

    View Slide