desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Sets interface for EM. :param self: An ExtensionManager object :type self: ExtensionManager :param interface: Interface name :type interface: String :return: None :rtype: None'
def set_interface(self, interface):
self._interface = interface self._socket = linux.L2Socket(iface=self._interface)
'Sets extensions for EM. :param self: An ExtensionManager object :type self: ExtensionManager :param extensions: List of str extension names :type extensions: List :return: None :rtype: None'
def set_extensions(self, extensions):
self._extensions_str = extensions
'Init EM extensions. Should be run when all shared data has been gathered. :param self: An ExtensionManager object :type self: ExtensionManager :param shared_data: Dictionary object :type shared_data: Dictionary :return: None :rtype: None'
def init_extensions(self, shared_data):
shared_data = collections.namedtuple('GenericDict', shared_data.keys())(**shared_data) for extension in self._extensions_str: mod = importlib.import_module((constants.EXTENSIONS_LOADPATH + extension)) extension_class = getattr(mod, extension.title()) obj = extension_class(shared_data) ...
'Starts the two main daemons of EM: 1) Daemon that listens to every packet and forwards it to each extension for further processing. 2) Daemon that receives special-crafted packets from extensions and broadcasts them in the air. :param self: An ExtensionManager object :type self: ExtensionManager :return: None :rtype: ...
def start_extensions(self):
self._listen_thread.start() self._send_thread.start() self.get_channels() self._channelhop_thread.start()
'Stops both daemons of EM on exit. :param self: An ExtensionManager object :type self: ExtensionManager :return: None :rtype: None'
def on_exit(self):
self._should_continue = False if self._listen_thread.is_alive(): self._listen_thread.join(3) if self._send_thread.is_alive(): self._send_thread.join(3) if self._channelhop_thread.is_alive(): self._send_thread.join(3) try: self._socket.close() except AttributeError...
'Gets the channels from each extension. Merges them to create a list of channels to hop. :param self: An ExtensionManager object :type self: ExtensionManager :return: None :rtype: None'
def get_channels(self):
for extension in self._extensions: channels_interested = extension.send_channels() number_of_channels = len(channels_interested) if (channels_interested and (number_of_channels > 0)): self._channels_to_hop += list((set(channels_interested) - set(self._channels_to_hop)))
'Gets the output of each extensions. Merges them in a list and returns it. :param self: An ExtensionManager object :type self: ExtensionManager :return: None :rtype: None'
def get_output(self):
output = [] for extension in self._extensions: m_output = extension.send_output() num_of_lines = len(m_output) if (m_output and (num_of_lines > 0)): output += m_output return output
'Pass each captured packet to each module. Gets the packets to send. :param self: An ExtensionManager object :type self: ExtensionManager :param pkt: A Scapy packet object :type pkt: Scapy Packet :return: None :rtype: None'
def _process_packet(self, pkt):
for extension in self._extensions: (channel_nums, received_packets) = extension.get_packet(pkt) num_of_packets = len(received_packets) if (received_packets and (num_of_packets > 0)): for c_num in channel_nums: self._packets_to_send[c_num] += received_packets
'A scapy filter to determine if we need to stop. :param self: An ExtensionManager object :type self: ExtensionManager :param self: A Scapy packet object :type self: Scapy Packet :return: True or False :rtype: Boolean'
def _stopfilter(self, pkt):
return (not self._should_continue)
'Listening thread. Listens for packets and forwards them to _process_packet. :param self: An ExtensionManager object :type self: ExtensionManager :return: None :rtype: None'
def _listen(self):
while self._should_continue: dot11.sniff(iface=self._interface, prn=self._process_packet, count=1, store=0, stop_filter=self._stopfilter)
'Sending thread. Continously broadcasting packets crafted by extensions. :param self: An ExtensionManager object :type self: ExtensionManager :return: None :rtype: None'
def _send(self):
while self._should_continue: for pkt in (self._packets_to_send[self._current_channel] + self._packets_to_send['*']): try: self._socket.send(pkt) except BaseException: continue time.sleep(1)
'Construct the class :param self: A TuiTemplateSelection object :type self: TuiTemplateSelection :return None :rtype None'
def __init__(self):
self.green_text = None self.heightlight_text = None self.heightlight_number = 0 self.page_number = 0 self.sections = list() self.sec_page_map = {} self.dimension = [0, 0]
'Get all the phishing scenario contents and store them in a list :param self: A TuiTemplateSelection object :param template_names: A list of string :param templates: A dictionary :type self: TuiTemplateSelection :type template_names: list :type templates: dict :return None :rtype: None'
def get_sections(self, template_names, templates):
for name in template_names: phishing_contents = (' - ' + str(templates[name])) lines = phishing_contents.splitlines() short_lines = [] for line in lines: for short_line in line_splitter(15, line): short_lines.append(short_line) self.sections....
'Update the page number for each section :param self: A TuiTemplateSelection object :param last_row: The last row of the window :type self: TuiTemplateSelection :type last_row: int :return: None :rtype: None'
def update_sec_page_map(self, last_row):
page_number = 0 row_number = 0 self.sec_page_map = {} for (number, section) in enumerate(self.sections): row_number += len(section) if (row_number > last_row): row_number = 0 page_number += 1 self.sec_page_map[number] = page_number
'Select a template based on whether the template argument is set or not. If the template argument is not set, it will interfactively ask user for a template :param self: A TuiTemplateSelection object :type self: TuiTemplateSelection :param template_argument: The template argument which might have been entered by the us...
def gather_info(self, template_argument, template_manager):
templates = template_manager.get_templates() template_names = list(templates.keys()) self.get_sections(template_names, templates) if (template_argument and (template_argument in templates)): return templates[template_argument] elif (template_argument and (template_argument not in templates))...
'Check for key movement and hightlight the corresponding phishing scenario :param self: A TuiTemplateSelection object :param number_of_sections: Number of templates :param key: The char user keying :type self: TuiTemplateSelection :type number_of_sections: int :type key: str :return: None :rtype: None'
def key_movement(self, screen, number_of_sections, key):
if (key == curses.KEY_DOWN): if (self.heightlight_number < (number_of_sections - 1)): page_number = self.sec_page_map[(self.heightlight_number + 1)] if (page_number > self.page_number): self.page_number += 1 screen.erase() self.heightlight_...
'Display the phishing scenarios :param self: A TuiTemplateSelection object :type self: TuiTemplateSelection :param screen: A curses window object :type screen: _curses.curses.window :return total row numbers used to display the phishing scenarios :rtype: int'
def display_phishing_scenarios(self, screen):
try: (max_window_height, max_window_len) = screen.getmaxyx() if ((self.dimension[0] != max_window_height) or (self.dimension[1] != max_window_len)): screen.erase() self.dimension[0] = max_window_height self.dimension[1] = max_window_len self.update_sec_page_map((m...
'Display the template information to users :param self: A TuiTemplateSelection object :type self: TuiTemplateSelection :param screen: A curses window object :type screen: _curses.curses.window :param templates: A dictionay map page to PhishingTemplate :type templates: dict :param template_names: list of template names ...
def display_info(self, screen, templates, template_names):
curses.curs_set(0) screen.nodelay(True) curses.init_pair(1, curses.COLOR_GREEN, screen.getbkgd()) curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_CYAN) self.green_text = (curses.color_pair(1) | curses.A_BOLD) self.heightlight_text = (curses.color_pair(2) | curses.A_BOLD) number_of_secti...
'Construct the class :param self: ApDisplayInfo :param pos: position of the line in the ap selection page :param page_number: page number of the ap selection :param box: the curses.newwin.box object containing ap information :param key: the key user have keyed in :param box_info: list of window height, window len, and ...
def __init__(self, pos, page_number, box, box_info):
self.pos = pos self.page_number = page_number self.box = box self._box_info = box_info
'The height of the terminal screen :param self: ApDisplayInfo :type self: ApDisplayInfo :return: the height of terminal screen :rtype: int'
@property def max_h(self):
return self._box_info[0]
'Set the height of the terminal screen :param self: ApDisplayInfo :type self: ApDisplayInfo :return: None :rtype: None'
@max_h.setter def max_h(self, val):
self._box_info[0] = val
'The width of the terminal screen :param self: ApDisplayInfo :type self: ApDisplayInfo :return: the width of terminal screen :rtype: int'
@property def max_l(self):
return self._box_info[1]
'Set the width of the terminal screen :param self: ApDisplayInfo :type self: ApDisplayInfo :return: None :rtype: None'
@max_l.setter def max_l(self, val):
self._box_info[1] = val
'Maximum row numbers used to contain the ap information :param self: ApDisplayInfo :type self: ApDisplayInfo :return: The row numbers of the box that contains the ap info :rtype: int'
@property def max_row(self):
return self._box_info[2]
'Set maximum row numbers used to contain the ap information :param self: ApDisplayInfo :type self: ApDisplayInfo :return: None :rtype: None'
@max_row.setter def max_row(self, val):
self._box_info[2] = val
'Get the key the users have keyed :param self: ApDisplayInfo :type self: ApDisplayInfo :return: The key :rtype: int'
@property def key(self):
return self._box_info[3]
'Set the key the users have keyed :param self: ApDisplayInfo :type self: ApDisplayInfo :return: None :rtype: None'
@key.setter def key(self, val):
self._box_info[3] = val
'Construct the class :param self: A TuiApSel object :type self: TuiApSel :return: None :rtype: None'
def __init__(self):
self.total_ap_number = 0 self.access_points = list() self.access_point_finder = None self.highlight_text = None self.normal_text = None self.mac_matcher = None self.renew_box = False
'Initialization of the ApDisplyInfo object :param self: A TuiApSel object :type self: TuiApSel :param screen: A curses window object :type screen: _curses.curses.window :param info: A namedtuple of information from pywifiphisher :type info: namedtuple :return ApDisplayInfo object :rtype: ApDisplayInfo'
def init_display_info(self, screen, info):
position = 1 page_number = 1 (max_window_height, max_window_length) = screen.getmaxyx() if ((max_window_height < 14) or (max_window_length < 9)): box = curses.newwin(max_window_height, max_window_length, 0, 0) self.renew_box = True else: box = curses.newwin((max_window_height...
'Get the information from pywifiphisher and print them out :param self: A TuiApSel object :type self: TuiApSel :param screen: A curses window object :type screen: _curses.curses.window :param info: A namedtuple of information from pywifiphisher :type info: namedtuple :return AccessPoint object if users type enter :rtyp...
def gather_info(self, screen, info):
curses.curs_set(0) screen.nodelay(True) curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_CYAN) self.highlight_text = curses.color_pair(1) self.normal_text = curses.A_NORMAL ap_info = self.init_display_info(screen, info) while (ap_info.key != 27): is_done = self.display_info(scree...
'Resize the window if the dimensions have been changed :param self: A TuiApSel object :type self: TuiApSel :param screen: A curses window object :type screen: _curses.curses.window :param ap_info: An ApDisplayInfo object :type ap_info: ApDisplayInfo'
def resize_window(self, screen, ap_info):
if (screen.getmaxyx() != (ap_info.max_h, ap_info.max_l)): (ap_info.max_h, ap_info.max_l) = screen.getmaxyx() if ((ap_info.max_h < (10 + 4)) or (ap_info.max_l < (6 + 3))): box = curses.newwin(ap_info.max_h, ap_info.max_l, 0, 0) box.box() ap_info.box = box ...
'Check for any key movement and update it\'s result :param self: A TuiApSel object :type self: TuiApSel :param ap_info: ApDisplayInfo object :type: ApDisplayInfo :return: None :rtype: None'
def key_movement(self, ap_info):
key = ap_info.key pos = ap_info.pos max_row = ap_info.max_row page_number = ap_info.page_number if (key == curses.KEY_DOWN): try: self.access_points[pos] except IndexError: ap_info.key = 0 ap_info.pos = pos ap_info.max_row = max_row ...
'Display the AP informations on the screen :param self: A TuiApSel object :type self: TuiApSel :param screen: A curses window object :type screen: _curses.curses.window :param ap_info: An ApDisplayInfo object :type ap_info: ApDisplayInfo :return True if ap selection is done :rtype: bool'
def display_info(self, screen, ap_info):
is_apsel_end = False self.resize_window(screen, ap_info) new_total_ap_number = len(self.access_point_finder.get_all_access_points()) if (new_total_ap_number != self.total_ap_number): self.access_points = self.access_point_finder.get_sorted_access_points() self.total_ap_number = len(self....
'Display information in the box window :param self: A TuiApSel object :type self: TuiApSel :param screen: A curses window object :type screen: _curses.curses.window :param ap_info: An ApDisplayInfo object :type ap_info: ApDisplayInfo :return: None :rtype: None .. note: The display system is setup like the following: - ...
def display_access_points(self, screen, ap_info):
page_boundary = range((1 + (ap_info.max_row * (ap_info.page_number - 1))), ((ap_info.max_row + 1) + (ap_info.max_row * (ap_info.page_number - 1)))) ap_info.box.erase() ap_info.box.border(0) header_fmt = '{0:30} {1:16} {2:3} {3:4} {4:5} {5:5} {6:20}' header = header_fmt.format('ESSI...
'Construct the class :param self: A TuiMain object :type self: TuiMain :return: None :rtype: None'
def __init__(self):
self.blue_text = None self.orange_text = None self.yellow_text = None
'Get the information from pywifiphisher and print them out :param self: A TuiMain object :param screen: A curses window object :param info: A namedtuple of printing information :type self: TuiMain :type screen: _curses.curses.window :type info: namedtuple :return: None :rtype: None'
def gather_info(self, screen, info):
curses.curs_set(0) screen.nodelay(True) curses.init_pair(1, curses.COLOR_BLUE, screen.getbkgd()) curses.init_pair(2, curses.COLOR_YELLOW, screen.getbkgd()) self.blue_text = (curses.color_pair(1) | curses.A_BOLD) self.yellow_text = (curses.color_pair(2) | curses.A_BOLD) while True: is...
'Print the http request on the main terminal :param self: A TuiMain object :type self: TuiMain :param start_row_num: start line to print the http request type start_row_num: int :param http_output: string of the http requests :type http_output: str'
def print_http_requests(self, screen, start_row_num, http_output):
requests = http_output.splitlines() match_str = '(.*\\s)(request from\\s)(.*)(\\sfor|with\\s)(.*)' for request in requests: match = re.match(match_str, request) if (match is None): continue request_type = match.group(1) request_from = match.group(2) ip_...
'Print the information of Victims on the terminal :param self: A TuiMain object :param screen: A curses window object :param info: A nameduple of printing information :type self: TuiMain :type screen: _curses.curses.window :type info: namedtuple :return True if users have pressed the Esc key :rtype: bool'
def display_info(self, screen, info):
is_done = False screen.erase() (_, max_window_length) = screen.getmaxyx() try: screen.addstr(0, (max_window_length - 30), '|') screen.addstr(1, (max_window_length - 30), '|') screen.addstr(1, (max_window_length - 29), (' Wifiphisher ' + info.version), self.blue_text) ...
'Setup the class with all the given arguments :param self: A MACMatcher object :param mac_vendor_file: The path of the vendor file :type self: MACMatcher :type mac_vendor_file: string :return: None :rtype: None'
def __init__(self, mac_vendor_file):
self._mac_to_vendor = {} self._vendor_file = mac_vendor_file self._get_vendor_information()
'Read and process all the data in the vendor file :param self: A MACMatcher object :type self: MACMatcher :return: None :rtype: None'
def _get_vendor_information(self):
with open(self._vendor_file, 'r') as _file: for line in _file: if (not line.startswith('#')): separated_line = line.rstrip('\n').split('|') mac_identifier = separated_line[0] vendor = separated_line[1] logo = separated_line[2] ...
'Return the matched vendor name for the given MAC address or Unknown if no match is found :param self: A MACMatcher object :param mac_address: MAC address of device :type self: MACMatcher :type mac_address: string :return: The vendor name of the device if MAC address is found and Unknown otherwise :rtype: string'
def get_vendor_name(self, mac_address):
if (mac_address is None): return None mac_identifier = mac_address.replace(':', '').upper()[0:6] try: vendor = self._mac_to_vendor[mac_identifier][0] return vendor except KeyError: return 'Unknown'
'Return the the full path of the logo in the filesystem for the given MAC address or None if no match is found :param self: A MACMatcher object :param mac_address: MAC address of the device :type self: MACMatcher :type mac_address: string :return: The full path of the logo if MAC address if found and None otherwise :rt...
def get_vendor_logo_path(self, mac_address):
if (mac_address is None): return None mac_identifier = mac_address.replace(':', '').upper()[0:6] if (mac_identifier in self._mac_to_vendor): logo = self._mac_to_vendor[mac_identifier][1] logo_path = (constants.LOGOS_DIR + logo) if logo: return logo_path el...
'Unloads mac to vendor mapping from memory and therefore you can not use MACMatcher instance once this method is called :param self: A MACMatcher object :type self: MACMatcher :return: None :rtype: None'
def unbind(self):
del self._mac_to_vendor
'Construct the class :param self: A InvalidInterfaceError object :param interface_name: Name of an interface :type self: InvalidInterfaceError :type interface_name: str :return: None :rtype: None'
def __init__(self, interface_name, mode=None):
message = 'The provided interface "{0}" is invalid!'.format(interface_name) if mode: message += "Interface {0} doesn't support {1} mode".format(interface_name, mode) Exception.__init__(self, message)
'Construct the class :param self: A InvalidMacAddressError object :param mac_address: A MAC address :type self: InvalidMacAddressError :type mac_address: str :return: None :rtype: None'
def __init__(self, mac_address):
message = 'The provided MAC address {0} is invalid'.format(mac_address) Exception.__init__(self, message)
'Construct the class :param self: A InvalidValueError object :param value_type: The value supplied :param correct_value_type: The correct value type :type self: InvalidValueError :type value_type: any :type correct_value_type: any :return: None :rtype: None'
def __init__(self, value, correct_value_type):
value_type = type(value) message = 'Expected value type to be {0} while got {1}.'.format(correct_value_type, value_type) Exception.__init__(self, message)
'Construct the class :param self: A InterfaceCantBeFoundError object :param interface_modes: Modes of interface required :type self: InterfaceCantBeFoundError :type interface_modes: tuple :return: None :rtype: None .. note: For interface_modes the tuple should contain monitor mode as first argument followed by AP mode'...
def __init__(self, interface_modes):
monitor_mode = interface_modes[0] ap_mode = interface_modes[1] message = 'Failed to find an interface with ' if monitor_mode: message += 'monitor' elif ap_mode: message += 'AP' message += ' mode' Exception.__init__(self, message)
'Construct the class. :param self: An InterfaceManagedByNetworkManagerError object :param interface_name: Name of interface :type self: InterfaceManagedByNetworkManagerError :type interface_name: str :return: None :rtype: None'
def __init__(self, interface_name):
message = 'Interface "{0}" is controlled by NetworkManager.You need to manually set the devices that should be ignored by NetworkManager using the keyfile plugin (unmanaged-directive). For example, \'[keyfile] unmanaged-devices=interface-...
'Setup the class with all the given arguments :param self: A NetworkAdapter object :param name: Name of the interface :param card_obj: A pyric.pyw.Card object :param mac_address: The MAC address of interface :type self: NetworkAdapter :type name: str :type card_obj: pyric.pyw.Card :type mac_address: str :return: None :...
def __init__(self, name, card_obj, mac_address):
self._name = name self._has_ap_mode = False self._has_monitor_mode = False self._is_managed_by_nm = False self._card = card_obj self._original_mac_address = mac_address self._current_mac_address = mac_address
'Return the name of the interface :param self: A NetworkAdapter object :type self: NetworkAdapter :return: The name of the interface :rtype: str'
@property def name(self):
return self._name
'Return whether the interface controlled by NetworkManager :param self: A NetworkAdapter object :type self: NetworkAdapter :return: True if interface is controlled by NetworkManager :rtype: bool'
@property def is_managed_by_nm(self):
return self._is_managed_by_nm
'Set whether the interface is controlled by NetworkManager :param self: A NetworkAdapter object :param value: A value representing interface controlled by NetworkManager :type self: NetworkAdapter :type value: bool :return: None :rtype: None :raises InvalidValueError: When the given value is not bool'
@is_managed_by_nm.setter def is_managed_by_nm(self, value):
if isinstance(value, bool): self._is_managed_by_nm = value else: raise InvalidValueError(value, bool)
'Return whether the interface supports AP mode :param self: A NetworkAdapter object :type self: NetworkAdapter :return: True if interface supports AP mode and False otherwise :rtype: bool'
@property def has_ap_mode(self):
return self._has_ap_mode
'Set whether the interface supports AP mode :param self: A NetworkAdapter object :param value: A value representing AP mode support :type self: NetworkAdapter :type value: bool :return: None :rtype: None :raises InvalidValueError: When the given value is not bool'
@has_ap_mode.setter def has_ap_mode(self, value):
if isinstance(value, bool): self._has_ap_mode = value else: raise InvalidValueError(value, bool)
'Return whether the interface supports monitor mode :param self: A NetworkAdapter object :type self: NetworkAdapter :return: True if interface supports monitor mode and False otherwise :rtype: bool'
@property def has_monitor_mode(self):
return self._has_monitor_mode
'Set whether the interface supports monitor mode :param self: A NetworkAdapter object :param value: A value representing monitor mode support :type self: NetworkAdapter :type value: bool :return: None :rtype: None :raises InvalidValueError: When the given value is not bool'
@has_monitor_mode.setter def has_monitor_mode(self, value):
if isinstance(value, bool): self._has_monitor_mode = value else: raise InvalidValueError(value, bool)
'Return the card object associated with the interface :param self: A NetworkAdapter object :type self: NetworkAdapter :return: The card object :rtype: pyric.pyw.Card'
@property def card(self):
return self._card
'Return the current MAC address of the interface :param self: A NetworkAdapter object :type self: NetworkAdapter :return: The MAC of the interface :rtype: str'
@property def mac_address(self):
return self._current_mac_address
'Set the MAC address of the interface :param self: A NetworkAdapter object :param value: A value representing monitor mode support :type self: NetworkAdapter :type value: str :return: None :rtype: None'
@mac_address.setter def mac_address(self, value):
self._current_mac_address = value
'Return the original MAC address of the interface :param self: A NetworkAdapter object :type self: NetworkAdapter :return: The original MAC of the interface :rtype: str'
@property def original_mac_address(self):
return self._original_mac_address
'Setup the class with all the given arguments. :param self: A NetworkManager object :type self: NetworkManager :return: None :rtype: None'
def __init__(self):
self._name_to_object = dict() self._active = set() self._exclude_shutdown = set()
'Check if interface is valid :param self: A NetworkManager object :param interface_name: Name of an interface :param mode: The mode of the interface to be checked :type self: NetworkManager :type interface_name: str :type mode: str :return: True if interface is valid :rtype: bool :raises InvalidInterfaceError: If the i...
def is_interface_valid(self, interface_name, mode=None):
try: interface_adapter = self._name_to_object[interface_name] except KeyError: if (mode == 'internet'): return True else: raise InvalidInterfaceError(interface_name) if (mode == 'internet'): self._exclude_shutdown.add(interface_name) if ((mode != '...
'Set the specified MAC address for the interface :param self: A NetworkManager object :param interface_name: Name of an interface :param mac_address: A MAC address :type self: NetworkManager :type interface_name: str :type mac_address: str :return: None :rtype: None .. note: This method will set the interface to manage...
def set_interface_mac(self, interface_name, mac_address):
card = self._name_to_object[interface_name].card self.set_interface_mode(interface_name, 'managed') try: pyw.down(card) pyw.macset(card, mac_address) pyw.up(card) except pyric.error as error: if (error[0] == 22): raise InvalidMacAddressError(mac_address) ...
'Return the MAC address of the interface :param self: A NetworkManager object :param interface_name: Name of an interface :type self: NetworkManager :type interface_name: str :return: Interface MAC address :rtype: str'
def get_interface_mac(self, interface_name):
return self._name_to_object[interface_name].mac_address
'Set random MAC address for the interface :param self: A NetworkManager object :param interface_name: Name of an interface :type self: NetworkManager :type interface_name: str :return: None :rtype: None .. note: This method will set the interface to managed mode. Also the first 3 octets are always 00:00:00 by default'
def set_interface_mac_random(self, interface_name):
new_mac_address = generate_random_address() self._name_to_object[interface_name].mac_address = new_mac_address self.set_interface_mac(interface_name, new_mac_address)
'Set the specified mode for the interface :param self: A NetworkManager object :param interface_name: Name of an interface :param mode: Mode of an interface :type self: NetworkManager :type interface_name: str :type mode: str :return: None :rtype: None .. note: Available modes are unspecified, ibss, managed, AP AP VLAN...
def set_interface_mode(self, interface_name, mode):
card = self._name_to_object[interface_name].card pyw.down(card) pyw.modeset(card, mode) pyw.up(card)
'Return the name of a valid interface with modes supplied :param self: A NetworkManager object :param has_ap_mode: AP mode support :param has_monitor_mode: Monitor mode support :type self: NetworkManager :type has_ap_mode: bool :type has_monitor_mode: bool :return: Name of valid interface :rtype: str .. raises Interfac...
def get_interface(self, has_ap_mode=False, has_monitor_mode=False):
possible_adapters = list() for (interface, adapter) in self._name_to_object.iteritems(): if ((interface not in self._active) and (adapter not in possible_adapters)): if ((adapter.has_ap_mode == has_ap_mode) and (adapter.has_monitor_mode == has_monitor_mode)): possible_adapter...
'Return a name of two interfaces :param self: A NetworkManager object :param self: NetworkManager :return: Name of monitor interface followed by AP interface :rtype: tuple'
def get_interface_automatically(self):
monitor_interface = self.get_interface(has_monitor_mode=True) ap_interface = self.get_interface(has_ap_mode=True) return (monitor_interface, ap_interface)
'Unblock interface if it is blocked :param self: A NetworkManager object :param interface_name: Name of an interface :type self: NetworkManager :type interface_name: str :return: None :rtype: None'
def unblock_interface(self, interface_name):
card = self._name_to_object[interface_name].card if pyw.isblocked(card): pyw.unblock(card)
'Set the channel for the interface :param self: A NetworkManager object :param interface_name: Name of an interface :param channel: A channel number :type self: NetworkManager :type interface_name: str :type channel: int :return: None :rtype: None'
def set_interface_channel(self, interface_name, channel):
card = self._name_to_object[interface_name].card pyw.chset(card, channel)
'Start the network manager :param self: A NetworkManager object :type self: NetworkManager :return: None :rtype: None'
def start(self):
for interface in pyw.interfaces(): try: card = pyw.getcard(interface) mac_address = pyw.macget(card) adapter = NetworkAdapter(interface, card, mac_address) self._name_to_object[interface] = adapter interface_property_detector(adapter) excep...
'Perform a clean up for the class :param self: A NetworkManager object :type self: NetworkManager :return: None :rtype: None ..note: The cards in _exclude_shutdown will not set to the original mac address since these cards are not changed the mac addresses by the program.'
def on_exit(self):
for interface in self._active: if (interface not in self._exclude_shutdown): adapter = self._name_to_object[interface] mac_address = adapter.original_mac_address self.set_interface_mac(interface, mac_address) if (hasattr(toggle_networking, 'has_disable_nm') and toggle...
'Setup the class with all the given arguments :param self: An AccessPoint object :type self: AccessPoint :return: None :rtype: None'
def __init__(self):
self.interface = None self.internet_interface = None self.channel = None self.essid = None self.psk = None self.hostapd_object = None
'Set the interface for the softAP :param self: An AccessPoint object :param interface: interface name :type self: AccessPoint :type interface: str :return: None :rtype: None'
def set_interface(self, interface):
self.interface = interface
'Set the internet interface :param self: An AccessPoint object :param interface: interface name :type self: AccessPoint :type interface: str :return: None :rtype: None'
def set_internet_interface(self, interface):
self.internet_interface = interface
'Set the channel for the softAP :param self: An AccessPoint object :param channel: channel number :type self: AccessPoint :type channel: str :return: None :rtype: None'
def set_channel(self, channel):
self.channel = channel
'Set the ssid for the softAP :param self: An AccessPoint object :param essid: SSID for the softAP :type self: AccessPoint :type essid: str :return: None :rtype: None'
def set_essid(self, essid):
self.essid = essid
'Set the psk for the softAP :param self: An AccessPoint object :param psk: passphrase for the softAP :type self: AccessPoint :type psk: str :return: None :rtype: None'
def set_psk(self, psk):
self.psk = psk
'Start the dhcp server :param self: An AccessPoint object :type self: AccessPoint :return: None :rtype: None'
def start_dhcp_dns(self):
config = 'no-resolv\ninterface=%s\ndhcp-range=%s\n' with open('/tmp/dhcpd.conf', 'w') as dhcpconf: dhcpconf.write((config % (self.interface, constants.DHCP_LEASE))) with open('/tmp/dhcpd.conf', 'a+') as dhcpconf: if self.internet_interface: dhcpconf.write(('server=%s' % (constant...
'Start the softAP :param self: An AccessPoint object :type self: AccessPoint :return: None :rtype: None'
def start(self):
hostapd_config = {'ssid': self.essid, 'interface': self.interface, 'channel': self.channel, 'karma_enable': 1} if self.psk: hostapd_config['wpa_passphrase'] = self.psk hostapd_options = {'debug_level': hostapd_constants.HOSTAPD_DEBUG_OFF, 'mute': True, 'eloop_term_disable': True} try: se...
'Clean up the resoures when exits :param self: An AccessPoint object :type self: AccessPoint :return: None :rtype: None'
def on_exit(self):
subprocess.call('pkill dnsmasq', shell=True) try: self.hostapd_object.stop() except BaseException: subprocess.call('pkill hostapd', shell=True) if os.path.isfile(hostapd_constants.HOSTAPD_CONF_PATH): os.remove(hostapd_constants.HOSTAPD_CONF_PATH) if os.path.isfi...
':param self: A tornado.web.RequestHandler object :param em: An extension manager object :type self: tornado.web.RequestHandler :type em: ExtensionManager :return: None :rtype: None'
def initialize(self, em):
self.em = em
':param self: A tornado.web.RequestHandler object :type self: tornado.web.RequestHandler :return: None :rtype: None ..note: overide the post method to do the verification'
def post(self):
json_obj = json_decode(self.request.body) response_to_send = {} backend_methods = self.em.get_backend_funcs() for func_name in list(json_obj.keys()): if (func_name in backend_methods): callback = getattr(backend_methods[func_name], func_name) response_to_send[func_name] =...
'Override the get method :param self: A tornado.web.RequestHandler object :type self: tornado.web.RequestHandler :return: None :rtype: None'
def get(self):
requested_file = self.request.path[1:] template_directory = template.get_path() if os.path.isfile((template_directory + requested_file)): render_file = requested_file else: render_file = 'index.html' file_path = (template_directory + render_file) self.render(file_path, **template...
'Override the post method :param self: A tornado.web.RequestHandler object :type self: tornado.web.RequestHandler :return: None :rtype: None ..note: we only serve the Content-Type which starts with "application/x-www-form-urlencoded" as a valid post request'
def post(self):
global terminate try: content_type = self.request.headers['Content-Type'] except KeyError: return if content_type.startswith(VALID_POST_CONTENT_TYPE): post_data = tornado.escape.url_unescape(self.request.body) log_file_path = '/tmp/wifiphisher-webserver.tmp' with ...
'Construct object. :param self: A PhishingTemplate object :type self: PhishingScenario :return: None :rtype: None .. todo:: Maybe add a category field'
def __init__(self, name):
config_path = os.path.join(PHISHING_PAGES_DIR, name, 'config.ini') info = config_section_map(config_path, 'info') self._name = name self._display_name = info['name'] self._description = info['description'] self._payload = False if ('payloadpath' in info): self._payload = info['payloa...
'Merge dict context with current one In case of confict always keep current values'
def merge_context(self, context):
context.update(self._context) self._context = context
'Return the context of the template. :param self: A PhishingTemplate object :type self: PhishingTemplate :return: the context of the template :rtype: dict'
def get_context(self):
return self._context
'Return the display name of the template. :param self: A PhishingTemplate object :type self: PhishingTemplate :return: the display name of the template :rtype: str'
def get_display_name(self):
return self._display_name
'Return the payload path of the template. :param self: A PhishingTemplate object :type self: PhishingTemplate :return: The path of the template :rtype: bool'
def get_payload_path(self):
return self._payload
'Return whether the template has a payload. :param self: A PhishingTemplate object :type self: PhishingTemplate :return: boolean if it needs payload :rtype: bool'
def has_payload(self):
if self._payload: return True return False
'Return the description of the template. :param self: A PhishingTemplate object :type self: PhishingTemplate :return: the description of the template :rtype: str'
def get_description(self):
return self._description
'Return the path of the template files. :param self: A PhishingTemplate object :type self: PhishingTemplate :return: the path of template files :rtype: str'
def get_path(self):
return self._path
'Return the path of the static template files. JS, CSS, Image files lie there. :param self: A PhishingTemplate object :type self: PhishingTemplate :return: the path of static template files :rtype: str'
def get_path_static(self):
return self._path_static
'Copies a file in the filesystem to the path of the template files. :param self: A PhishingTemplate object :type self: PhishingTemplate :param path: path of the file that is to be copied :type self: str :return: the path of the file under the template files :rtype: str'
def use_file(self, path):
if ((path is not None) and os.path.isfile(path)): filename = os.path.basename(path) copyfile(path, (self.get_path_static() + filename)) self._extra_files.append((self.get_path_static() + filename)) return filename
'Removes extra used files (if any) :param self: A PhishingTemplate object :type self: PhishingTemplate :return: None :rtype: None'
def remove_extra_files(self):
for f in self._extra_files: if os.path.isfile(f): os.remove(f)
'Return a string representation of the template. :param self: A PhishingTemplate object :type self: PhishingTemplate :return: the name followed by the description of the template :rtype: str'
def __str__(self):
return (((self._display_name + '\n DCTB ') + self._description) + '\n')
'Construct object. :param self: A TemplateManager object :type self: TemplateManager :return: None :rtype: None'
def __init__(self):
self._template_directory = PHISHING_PAGES_DIR page_dirs = os.listdir(PHISHING_PAGES_DIR) self._templates = {} for page in page_dirs: if os.path.isdir(page): self._templates[page] = PhishingTemplate(page) self.add_user_templates()
'Return all the available templates. :param self: A TemplateManager object :type self: TemplateManager :return: all the available templates :rtype: dict'
def get_templates(self):
return self._templates
'Return all the user\'s templates available. :param self: A TemplateManager object :type self: TemplateManager :return: all the local templates available :rtype: list .. todo:: check to make sure directory contains HTML files'
def find_user_templates(self):
local_templates = [] for name in os.listdir(self._template_directory): if (os.path.isdir(os.path.join(self._template_directory, name)) and (name not in self._templates)): local_templates.append(name) return local_templates