This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Shared library add-on to iptables to add wcs2 target support. | |
* | |
* Copyright (C) 2010 Mike Chen | |
* | |
* This program is free software; you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License version 2 as | |
* published by the Free Software Foundation. | |
* | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from netfilterqueue import NetfilterQueue | |
import subprocess | |
import signal | |
def observe_dns_hijacking(nfqueue_element): | |
print('packet past through me') | |
nfqueue_element.accept() | |
nfqueue = NetfilterQueue() | |
nfqueue.bind(0, observe_dns_hijacking) | |
def clean_up(*args): | |
subprocess.call('iptables -D OUTPUT -p udp --dst 8.8.8.8 -j QUEUE', shell=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from netfilterqueue import NetfilterQueue | |
import subprocess | |
import signal | |
import dpkt | |
import traceback | |
import socket | |
def observe_dns_hijacking(nfqueue_element): | |
try: | |
ip_packet = dpkt.ip.IP(nfqueue_element.get_payload()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from netfilterqueue import NetfilterQueue | |
import subprocess | |
import signal | |
import dpkt | |
import traceback | |
import socket | |
import sys | |
DNS_IP = '8.8.8.8' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import subprocess | |
# source http://zh.wikipedia.org/wiki/%E5%9F%9F%E5%90%8D%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%BC%93%E5%AD%98%E6%B1%A1%E6%9F%93 | |
WRONG_ANSWERS = { | |
'4.36.66.178', | |
'8.7.198.45', | |
'37.61.54.158', | |
'46.82.174.68', | |
'59.24.3.173', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import dpkt.ip | |
def main_loop(server_socket, raw_socket): | |
while True: | |
packet_bytes, from_ip = server_socket.recvfrom(4096) | |
packet = dpkt.ip.IP(packet_bytes) | |
dst = socket.inet_ntoa(packet.dst) | |
print('%s:%s => %s:%s' % (socket.inet_ntoa(packet.src), packet.data.sport, dst, packet.data.dport)) | |
raw_socket.sendto(packet_bytes, (dst, 0)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from netfilterqueue import NetfilterQueue | |
import traceback | |
import subprocess | |
import signal | |
import dpkt | |
import socket | |
raw_socket = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(3)) | |
raw_socket.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 2**30) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from netfilterqueue import NetfilterQueue | |
import traceback | |
import subprocess | |
import signal | |
import dpkt | |
import socket | |
import time | |
raw_socket = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(3)) | |
raw_socket.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 2**30) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from netfilterqueue import NetfilterQueue | |
import traceback | |
import subprocess | |
import signal | |
import dpkt | |
import socket | |
import time | |
raw_socket = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(3)) | |
raw_socket.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 2**30) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from netfilterqueue import NetfilterQueue | |
import traceback | |
import subprocess | |
import signal | |
import dpkt | |
import socket | |
raw_socket = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(3)) | |
raw_socket.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 2**30) |