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

Packet Sniffing

Preetam Jinka
September 20, 2014

Packet Sniffing

Preetam Jinka

September 20, 2014
Tweet

More Decks by Preetam Jinka

Other Decks in Programming

Transcript

  1. Background What’s a socket? They’re basically channels for packets to

    travel across. What’s a packet? The fundamental unit of data in networking. A chunk of bytes, perhaps.
  2. • Datagram (e.g. UDP) • Stream (e.g. TCP) • Raw

    ◦ “It’s RAW!” Types of sockets
  3. The socket() syscall “ socket() creates an endpoint for communication

    and returns a descriptor. int socket(int domain, int type, int protocol); ”
  4. TCP and UDP are complicated, right? • TCP ◦ Stateful

    ◦ Connections ◦ Ports • UDP ◦ Stateless ◦ Ports
  5. Abstractions make sockets simpler. Your programming environment takes care of

    setting up sockets. You just have to send data. The packets are constructed for you (by the OS).
  6. TCP sockets in Node.js var net = require('net'); var server

    = net.createServer(function (socket) { socket.write('Echo server\r\n'); socket.pipe(socket); }); server.listen(1337, '127.0.0.1');
  7. When a socket is bound to an address:port, it only

    receives data sent to that address:port. The kernel manages that for you.
  8. What else can we do? Look at TCP flags. SYN

    but not ACK => connection opened FIN and ACK => connection closed
  9. Caveats We’re not considering connection states. SSL/TLS? Resource utilization (how

    fast can we sniff?) If you’re not reading from the socket fast enough, the kernel buffer fills up and it will drop packets.
  10. Technique: sampling If you only want a representative sample, pick

    1 in N packets. Ignore the rest. Upside: monitor lots of network traffic Downside: not accurate (See me if you want to learn about sFlow)
  11. More fun ideas You can read from raw sockets, but

    you can also write to raw sockets. Construct your own Ethernet, IP, and TCP/UDP packets! Write your own protocol on top of IPv4/IPv6!