Skip to content

Instantly share code, notes, and snippets.

@lukas2511
Created July 13, 2017 12:08
Show Gist options
  • Save lukas2511/dd3ea9f5e98c0c4145c894a05916f8e4 to your computer and use it in GitHub Desktop.
Save lukas2511/dd3ea9f5e98c0c4145c894a05916f8e4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from scapy import all as scapy
#import subprocess
INTERFACE = "eth0"
SECRET = b"thecakeisalie"
def do_reply(incoming_pkt_ether):
# get request
incoming_pkt = incoming_pkt_ether.payload
echo_request = incoming_pkt.payload
# create reply
echo_reply = scapy.ICMPv6EchoReply(data=echo_request.data, id=echo_request.id, seq=echo_request.seq)
# wrap reply in ipv6 and ethernet frame
outgoing_pkt = scapy.IPv6(src=incoming_pkt.dst, dst=incoming_pkt.src)
outgoing_pkt.payload = echo_reply
outgoing_pkt_ether = scapy.Ether(dst=incoming_pkt_ether.src)
outgoing_pkt_ether.payload = outgoing_pkt
# modify reply
outgoing_pkt_ether.payload.payload.data += b'\nDas Geheimnis lautet "%s".' % SECRET
# send reply
scapy.sendp(outgoing_pkt_ether, iface=INTERFACE, verbose=False)
def main():
#output = subprocess.check_output(["/sbin/ip6tables", "-S"]).splitlines()
#if not b'-A INPUT -p ipv6-icmp -m icmp6 --icmpv6-type 128 -j DROP' in output:
# subprocess.call(["/sbin/ip6tables", "-A", "INPUT", "-p", "ipv6-icmp", "-m", "icmp6", "--icmpv6-type", "128", "-j", "DROP"])
scapy.sniff(iface=INTERFACE, filter="icmp6 and ip6[40] == 128", prn=do_reply)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment