Skip to content

Instantly share code, notes, and snippets.

@rgee0
Last active July 25, 2018 18:35
Show Gist options
  • Save rgee0/b21a756aa737d7b8b82a2e926b83f229 to your computer and use it in GitHub Desktop.
Save rgee0/b21a756aa737d7b8b82a2e926b83f229 to your computer and use it in GitHub Desktop.
Quick example of trapping amazon dash button presses on the network using python

This is an adaptation of something I found over 12 months ago. If it looks familiar, please say as I'm more than happy to credit.

#!/usr/bin/env python

from scapy.all import *
import datetime
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)

def button_pressed_dash():
  print 'Dash button pressed at %s' % datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S')

def udp_filter(pkt):
  options = pkt[DHCP].options
  for option in options:
    if isinstance(option, tuple) and 'requested_addr' in option:
      mac_to_action[pkt.src]()
      break

mac_to_action = {'xx:xx:xx:xx:xx:xx' : button_pressed_dash}
mac_id_list = list(mac_to_action.keys())

print "Waiting for a button press..."
sniff(prn=udp_filter, store=0, filter="udp", lfilter=lambda d: d.src in mac_id_list)

if __name__ == "__main__":
  main()

To run:

$ sudo ./pydash.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment