Merge pull request #444 from rad4day/captive_portal_fix

Captive portal fix
This commit is contained in:
deltax 2018-04-05 15:29:13 +02:00 committed by GitHub
commit ab1681d5eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 43 additions and 44 deletions

View File

@ -711,8 +711,12 @@ index-file.names = (
# Create a DNS service with python, forwarding all traffic to gateway. # Create a DNS service with python, forwarding all traffic to gateway.
echo "\ echo "\
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import socket import socket
class DNSQuery: class DNSQuery:
def __init__(self, data): def __init__(self, data):
self.data=data self.data=data
@ -730,7 +734,7 @@ class DNSQuery:
def respuesta(self, ip): def respuesta(self, ip):
packet='' packet=''
if self.dominio: if self.dominio:
packet+=self.data[:2] + \"\x81\x80\" packet+=self.data[:2] + '\x81\x80'
packet+=self.data[4:6] + self.data[4:6] + '\x00\x00\x00\x00' packet+=self.data[4:6] + self.data[4:6] + '\x00\x00\x00\x00'
packet+=self.data[12:] packet+=self.data[12:]
packet+='\xc0\x0c' packet+='\xc0\x0c'
@ -738,15 +742,16 @@ class DNSQuery:
packet+=str.join('', map(lambda x: chr(int(x)), ip.split('.'))) packet+=str.join('', map(lambda x: chr(int(x)), ip.split('.')))
return packet return packet
if __name__ == '__main__': if __name__ == '__main__':
ip='$CaptivePortalGatewayAddress' ip='$CaptivePortalGatewayAddress'
print 'pyminifakeDwebconfNS:: dom.query. 60 IN A %s' % ip print 'pyminifakeDwebconfNS:: dom.query. 60 IN A %s' % ip
udps = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) udps = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udps.bind(('',53)) udps.bind((ip, 53))
try: try:
while 1: while True:
data, addr = udps.recvfrom(1024) data, addr = udps.recvfrom(1024)
p=DNSQuery(data) p=DNSQuery(data)
udps.sendto(p.respuesta(ip), addr) udps.sendto(p.respuesta(ip), addr)
@ -1090,8 +1095,7 @@ captive_portal_unset_routes() {
ip addr del $CaptivePortalGatewayAddress/24 dev $CaptivePortalAccessInterface 2>/dev/null ip addr del $CaptivePortalGatewayAddress/24 dev $CaptivePortalAccessInterface 2>/dev/null
} }
# Set up DHCP / WEB server # Set up DHCP / WEB server / DNS Firewall
# Set up DHCP / WEB server
captive_portal_set_routes() { captive_portal_set_routes() {
# Give an address to the gateway interface in the rogue network. # Give an address to the gateway interface in the rogue network.
# This makes the interface accessible from the rogue network. # This makes the interface accessible from the rogue network.
@ -1107,15 +1111,10 @@ captive_portal_set_routes() {
iptables --table nat --flush iptables --table nat --flush
iptables --delete-chain iptables --delete-chain
iptables --table nat --delete-chain iptables --table nat --delete-chain
iptables -P FORWARD ACCEPT iptables -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT \ iptables -A INPUT -p udp --dport 53 -j ACCEPT
--to-destination $CaptivePortalGatewayAddress:80 iptables -A INPUT -p udp --dport 67 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT \
--to-destination $CaptivePortalGatewayAddress:443
iptables -A INPUT -p tcp --sport 443 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 443 -j ACCEPT
iptables -t nat -A POSTROUTING -j MASQUERADE
} }
captive_portal_stop_interface() { captive_portal_stop_interface() {