Esempio n. 1
0
	def __create_hotspot(self):
		"""Finds associated MAC addresses. Creates a hotspot."""
		connections = subprocess.Popen(["nmcli", "connection"], stdout=subprocess.PIPE)
		conn_grep = subprocess.Popen(["grep", self.ssid], stdin=connections.stdout, stdout=subprocess.PIPE)
			
		connections.stdout.close()
		if not re.search("\w+", conn_grep.communicate()[0].decode("utf-8")) is None:
			logger.log(":: Connection already exists. Starting..")
			try:
				subprocess.check_output(["nmcli", "connection", "up", self.ssid])
			except subprocess.CalledProcessError:
				logger.log(":: Failed to start hotspot, remaking " + self.ssid)
				subprocess.check_output(["nmcli", "connection", "delete", self.ssid])
				#self.__create_ap_config()
		else:
			self.__create_ap_config()

		try:
			subprocess.check_output(["nmcli", "connection", "up", self.ssid])
			config = subprocess.Popen(["nmcli", "connection"], stdout=subprocess.PIPE).communicate()[0].decode("utf-8")
			if re.search(self.ssid, config) is None:
				logger.log("Failed to connect")
			else:
				self.driver.set_status(2)
				logger.log("Connection successful")
		except subprocess.CalledProcessError:
			logger.log(":: Failed to start hotspot " + self.ssid)
			self.driver.set_status(0)
Esempio n. 2
0
 def run(self, ssid=None, passwd=None):
     """OH SNAP HERE COME DATBOI"""
     logger.log("Starting DATBOI..")
     if (ssid == "" or ssid is None) and (passwd == "" or passwd is None):
         return self.VALIDATION_ERRORS["ERR_EMPTY"]
     else:
         self.ssid = ssid
         self.set_status(1)
         self.socket = Socket(ssid, passwd, self)
Esempio n. 3
0
    def order_66(self):
        """Toggle the WiFi radio"""

        logger.log("It will be done my lord.")
        if self.killswitch_engage:
            subprocess.check_output(["nmcli", "connection", "down", self.ssid])
            self.set_status(0)
        else:
            subprocess.check_output(["nmcli", "connection", "up", self.ssid])
            self.set_status(2)

        self.killswitch_engage != self.killswitch_engage
Esempio n. 4
0
    def __init__(self):
        """Initialize DATBOI"""

        self.killswitch_engage = True
        self.VALIDATION_ERRORS = {
            "ERR_EMPTY": -1,
            "ERR_LENGTH": -2,
            "ERR_INSECURE": -3
        }

        logger.log("Here come DATBOI")
        self.ssid = None
        self.status = 0
        self.socket = None
Esempio n. 5
0
    def set_error(self, field, valid_err=0):
        error_string = None
        if valid_err == -1:
            error_string = "Field required"
        elif valid_err == -2:
            error_string = "Length must be at least 14 characters"
        elif valid_err == -3:
            error_string = "Insecure passphrase"

        if not error_string is None:
            logger.log(error_string)
            field.error(error_string)
            return False
        field.clear_error()
        return True
Esempio n. 6
0
	def __create_ap_config(self):
		bssid_proccess = subprocess.Popen(["iw", self.dev, "scan"], stdout=subprocess.PIPE)
		egrep_bssid = subprocess.Popen(["egrep", "^BSS|SSID:"], stdin=bssid_proccess.stdout, stdout=subprocess.PIPE)
		egrep_associated = subprocess.Popen(["egrep", "associated"], stdin=egrep_bssid.stdout, stdout=subprocess.PIPE)

		bssid_proccess.stdout.close()
		egrep_bssid.stdout.close()
		bssid = re.search("(([a-f0-9]{2}:){5}([a-f0-9]{2}))", egrep_associated.communicate()[0].decode("utf-8")).group(0).upper()

		logger.log(":: Acess Point BSSID: " + bssid)

		ether_egrep = subprocess.Popen(["ifconfig", self.ssid], stdout=subprocess.PIPE)
		self.mac_addr = re.search("(([a-f0-9]{2}:){5}([a-f0-9]{2}))", ether_egrep.communicate()[0].decode("utf-8")).group(0).upper()

		logger.log(":: Cloned MAC Address: " + self.mac_addr)

		logger.log(":: Creating connection..")

		try:	
			logger.log(":: Connection added.")
			subprocess.check_output(["nmcli", "connection", "add", "con-name", self.ssid, "type", "wifi", "ifname", self.ssid, "ssid", self.ssid])
			subprocess.check_output(["nmcli", "connection", "modify", self.ssid, "802-11-wireless.ssid", self.ssid, "802-11-wireless.mode", "ap", "802-11-wireless.bssid", bssid, "802-11-wireless.cloned-mac-address", self.mac_addr, "802-11-wireless-security.key-mgmt", "wpa-psk", "802-11-wireless-security.wep-key0", self.passwd, "802-11-wireless-security.psk", self.passwd, "802-11-wireless-security.wep-key-type", "2", "ipv4.method", "shared"])
		except (subprocess.CalledProcessError, OSError):
			logger.log(":: Connection already exists!")
Esempio n. 7
0
	def __add_iw(self):
		"""Creates a virtual interface bound to wlan0"""

		logger.log("Getting WiFi Information")

		iw_dev = subprocess.Popen(["iw", "dev"], stdout=subprocess.PIPE)
		self.dev = re.search("(wlp.+|wlan.+)", iw_dev.communicate()[0].decode("utf-8")).group(0)
		
		logger.log(":: WiFi Device: " + self.dev)

		try:
			logger.log(":: Adding virtual network: " + self.ssid)
			subprocess.check_output(["iw", "dev", self.dev, "interface", "add", self.ssid, "type", "__ap"])
		except (subprocess.CalledProcessError, OSError):
			logger.log(":: Couldn't add virtual network: already exists.")
			
		self.__create_hotspot()