Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steven-p-walsh/9b7c0ffd2fe4817d6745951766f5a0f0 to your computer and use it in GitHub Desktop.
Save steven-p-walsh/9b7c0ffd2fe4817d6745951766f5a0f0 to your computer and use it in GitHub Desktop.
Social Media Shock Collar
#! /usr/bin/python
from scapy.all import *
import sys, ifaddr, os
bad_sites = [
'reddit.com',
'youtube.com',
'news.ycombinator.com',
'wsj.com',
'theintercept.com',
'facebook.com',
'twitter.com'
]
def check_match(dns_name):
# just so it's eaiser to add domains
if dns_name.startswith('www.'):
dns_name = dns_name[4:]
# if it's a bad domain, let's shock the user
if dns_name in bad_sites:
print '%s is a bad domain' % dns_name
os.system('play -n synth .5 sin 1500')
def get_adapter_name():
# get the first available adapter
adapters = ifaddr.get_adapters()
for adapter in adapters:
if len(adapter.ips) > 0 and adapter.ips[0].ip != '127.0.0.1':
return adapter.name
# listen for dns requests
def querysniff(pkt):
if IP in pkt:
ip_src = pkt[IP].src
ip_dst = pkt[IP].dst
if pkt.haslayer(DNS) and pkt.getlayer(DNS).qr == 0:
check_match(pkt.getlayer(DNS).qd.qname[:-1])
interface = get_adapter_name()
print 'using interface: %s' % interface
sniff(iface = interface,filter = "port 53", prn = querysniff, store = 0)
Copy link

ghost commented Aug 13, 2019

Very cool script, here's a quick python3 translation for others:

from scapy.all import IP, DNS, sniff
import ifaddr
import subprocess

bad_sites = [
    "reddit.com",
    "youtube.com",
    "news.ycombinator.com",
    "wsj.com",
    "theintercept.com",
    "facebook.com",
    "twitter.com",
]


def check_match(dns_name):
    # just so it's eaiser to add domains
    if dns_name.startswith(b"www."):
        dns_name = dns_name[4:]

    # if it's a bad domain, let's shock the user
    if dns_name in bad_sites:
        print("%s is a bad domain" % dns_name)
        subprocess.run("play -n synth .5 sin 1500".split())


def get_adapter_name():
    # get the first available adapter
    adapters = ifaddr.get_adapters()
    for adapter in adapters:
        if len(adapter.ips) > 0 and adapter.ips[0].ip != "127.0.0.1":
            return adapter.name


# listen for dns requests
def querysniff(pkt):
    if IP in pkt:
        if pkt.haslayer(DNS) and pkt.getlayer(DNS).qr == 0:
            check_match(pkt.getlayer(DNS).qd.qname[:-1])


interface = get_adapter_name()
print("using interface: %s" % interface)
sniff(iface=interface, filter="port 53", prn=querysniff, store=0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment