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) self._extensions.append(obj)
'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: None'
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: pass
'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.append(short_lines)
'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 user :type template_argument: str :param template_manager: A TemplateManager object :type template_manager: TemplateManager :return A PhishingTemplate object :rtype: PhishingTemplagte :raises InvalidTemplate in case the template argument entered by the user is not available.'
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)): raise phishingpage.InvalidTemplate else: template = curses.wrapper(self.display_info, templates, template_names) return template
'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_number += 1 elif (key == curses.KEY_UP): if (self.heightlight_number > 0): page_number = self.sec_page_map[(self.heightlight_number - 1)] if (page_number < self.page_number): self.page_number -= 1 screen.erase() self.heightlight_number -= 1
'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((max_window_height - 20)) display_str = 'Options: [Up Arrow] Move Up [Down Arrow] Move Down' screen.addstr(0, 0, display_string(max_window_len, display_str)) display_str = 'Avaliable Phishing Scenarios:' screen.addstr(3, 0, display_string(max_window_len, display_str), curses.A_BOLD) except curses.error: return 0 row_num = 5 first = False for (number, short_lines) in enumerate(self.sections): try: if ((self.sec_page_map[self.heightlight_number] != self.page_number) and (not first)): screen.addstr(row_num, 2, short_lines[0], self.heightlight_text) self.heightlight_number = 0 self.page_number = 0 first = True if (self.sec_page_map[number] != self.page_number): continue screen.addstr(row_num, 0, str((number + 1)), self.green_text) if (number == self.heightlight_number): screen.addstr(row_num, 2, short_lines[0], self.heightlight_text) else: screen.addstr(row_num, 2, short_lines[0], curses.A_BOLD) row_num += 1 screen.addstr(row_num, 8, short_lines[1]) row_num += 1 if (len(short_lines) > 1): for short_line in short_lines[2:]: screen.addstr(row_num, 0, short_line) row_num += 1 row_num += 1 except curses.error: return row_num return row_num
'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 :type template_names: list'
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_sections = len(templates) screen.erase() while True: row_number = self.display_phishing_scenarios(screen) key = screen.getch() self.key_movement(screen, number_of_sections, key) row_number += 2 if (key == ord('\n')): try: screen.addstr(row_number, 3, ('YOU HAVE SELECTED ' + template_names[self.heightlight_number]), curses.A_BOLD) except curses.error: pass screen.refresh() time.sleep(1) template_name = template_names[self.heightlight_number] template = templates[template_name] return template screen.refresh()
'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 max row number :type self: ApDisplayInfo :type pos: int :type page_number: int :type box: curse.newwin.box :type key: str :return: None :rtype: None'
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 - 9), (max_window_length - 5), 4, 3) box.box() box_height = box.getmaxyx()[0] max_row = (box_height - 2) key = 0 box_info = [max_window_height, max_window_length, max_row, key] ap_info = ApDisplayInfo(position, page_number, box, box_info) self.mac_matcher = info.mac_matcher self.access_point_finder = recon.AccessPointFinder(info.interface, info.network_manager) if info.args.lure10_capture: self.access_point_finder.capture_aps() self.access_point_finder.find_all_access_points() return ap_info
'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 :rtype AccessPoint if users type enter else None'
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(screen, ap_info) if is_done: self.access_point_finder.stop_finding_access_points() return self.access_points[(ap_info.pos - 1)] self.access_point_finder.stop_finding_access_points()
'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 self.renew_box = True return elif self.renew_box: screen.erase() box = curses.newwin((ap_info.max_h - 9), (ap_info.max_l - 5), 4, 3) box.box() ap_info.box = box self.renew_box = False ap_info.box.resize((ap_info.max_h - 9), (ap_info.max_l - 5)) box_height = ap_info.box.getmaxyx()[0] ap_info.max_row = (box_height - 2) ap_info.pos = 1 ap_info.page_number = 1
'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 return if ((pos % max_row) == 0): pos += 1 page_number += 1 else: pos += 1 elif (key == curses.KEY_UP): if ((pos - 1) > 0): if (((pos - 1) % max_row) == 0): pos -= 1 page_number -= 1 else: pos -= 1 ap_info.key = key ap_info.pos = pos ap_info.page_number = page_number
'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.access_points) self.display_access_points(screen, ap_info) self.key_movement(ap_info) ap_info.key = screen.getch() if ((ap_info.key == ord('\n')) and (self.total_ap_number != 0)): screen.addstr((ap_info.max_h - 2), 3, ('YOU HAVE SELECTED ' + self.access_points[(ap_info.pos - 1)].get_name())) screen.refresh() time.sleep(1) is_apsel_end = True return is_apsel_end
'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: - (1,3)Options - - (3,5)Header - - (4,3)**************************** - - v * | v * - - v * | v * - - v * | v * - - v * v v * - - v ************v*************** - - v v v - -----v-------------v------v------------- v v v v v > max_window_length-5 v v max_window_height-9 v V v--> box_height-2'
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('ESSID', 'BSSID', 'CH', 'PWR', 'ENCR', 'CLIENTS', 'VENDOR') opt_str = 'Options: [Esc] Quit [Up Arrow] Move Up [Down Arrow] Move Down' try: window_l = screen.getmaxyx()[1] screen.addstr(1, 3, display_string((window_l - 3), opt_str)) screen.addstr(3, 5, display_string((window_l - 5), header)) except curses.error: return for item_position in page_boundary: if (self.total_ap_number == 0): display_str = 'No access point has been discovered yet!' try: ap_info.box.addstr(1, 1, display_string((ap_info.max_l - 1), display_str), self.highlight_text) except curses.error: return else: access_point = self.access_points[(item_position - 1)] vendor = self.mac_matcher.get_vendor_name(access_point.get_mac_address()) display_text = '{0:30} {1:17} {2:2} {3:3}% {4:^7} {5:^5} {6:20}'.format(access_point.get_name(), access_point.get_mac_address(), access_point.get_channel(), access_point.get_signal_strength(), access_point.get_encryption(), access_point.get_number_connected_clients(), vendor) print_row_number = (item_position - (ap_info.max_row * (ap_info.page_number - 1))) try: if (item_position == ap_info.pos): ap_info.box.addstr(print_row_number, 2, display_string((ap_info.max_l - 2), display_text), self.highlight_text) else: ap_info.box.addstr(print_row_number, 2, display_string((ap_info.max_l - 2), display_text), self.normal_text) except curses.error: return if (item_position == self.total_ap_number): break screen.refresh() ap_info.box.refresh()
'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_done = self.display_info(screen, info) if is_done: return
'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_address = match.group(3) for_or_with = match.group(4) resource = match.group(5) start_col = 0 screen.addstr(start_row_num, start_col, '[') start_col += 1 screen.addstr(start_row_num, start_col, '*', self.yellow_text) start_col += 1 screen.addstr(start_row_num, start_col, '] ') start_col += 2 screen.addstr(start_row_num, start_col, request_type, self.yellow_text) start_col += len(request_type) screen.addstr(start_row_num, start_col, request_from) start_col += len(request_from) screen.addstr(start_row_num, start_col, ip_address, self.yellow_text) start_col += len(ip_address) screen.addstr(start_row_num, start_col, for_or_with) start_col += len(for_or_with) screen.addstr(start_row_num, start_col, resource, self.yellow_text) start_row_num += 1
'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) screen.addstr(2, (max_window_length - 30), (('|' + ' ESSID: ') + info.essid)) screen.addstr(3, (max_window_length - 30), (('|' + ' Channel: ') + info.channel)) screen.addstr(4, (max_window_length - 30), (('|' + ' AP interface: ') + info.ap_iface)) screen.addstr(5, (max_window_length - 30), ('|' + ' Options: [Esc] Quit')) screen.addstr(6, (max_window_length - 30), ('|' + ('_' * 29))) screen.addstr(1, 0, 'Deauthenticating clients: ', self.blue_text) except curses.error: pass if info.em: raw_num = 2 for client in info.em.get_output()[(-5):]: screen.addstr(raw_num, 0, client) raw_num += 1 try: screen.addstr(7, 0, 'DHCP Leases', self.blue_text) if os.path.isfile('/var/lib/misc/dnsmasq.leases'): dnsmasq_output = check_output(['tail', '-5', '/var/lib/misc/dnsmasq.leases']) screen.addstr(8, 0, dnsmasq_output) screen.addstr(13, 0, 'HTTP requests: ', self.blue_text) if os.path.isfile('/tmp/wifiphisher-webserver.tmp'): http_output = check_output(['tail', '-5', '/tmp/wifiphisher-webserver.tmp']) self.print_http_requests(screen, 14, http_output) except curses.error: pass if (screen.getch() == 27): is_done = True if (info.phishinghttp.terminate and info.args.quitonsuccess): is_done = True screen.refresh() return is_done
'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] self._mac_to_vendor[mac_identifier] = (vendor, logo)
'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 :rtype: string or None'
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 else: return None
'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-name:"{0}"\' needs to be added in your NetworkManager configuration file.'.format(interface_name) Exception.__init__(self, message)
'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 :rtype: 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 interface is invalid or the interface has been chosen in the set _active :raises InterfaceManagedByNetworkManagerError: If the card is managed and is being used as deauth/ap mode .. note: The available modes are monitor, AP and internet The internet adapter should be put in the _exclude_shutdown set so that it will not be shutdown after the program exits.'
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 != 'internet') and interface_adapter.is_managed_by_nm): raise InterfaceManagedByNetworkManagerError(interface_name) if ((mode == 'monitor') and (not interface_adapter.has_monitor_mode)): raise InvalidInterfaceError(interface_name, mode) elif ((mode == 'AP') and (not interface_adapter.has_ap_mode)): raise InvalidInterfaceError(interface_name, mode) if (interface_name in self._active): raise InvalidInterfaceError(interface_name) self._active.add(interface_name) return True
'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 managed mode'
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) else: raise
'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, wds, monitor, mesh, p2p'
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 InterfaceCantBeFoundError: When an interface with supplied modes can\'t be found .. raises InterfaceManagedByNetworkManagerError: When the chosen interface is managed by NetworkManager .. note: This method guarantees that an interface with perfect match will be returned if available'
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_adapters.insert(0, adapter) elif (has_ap_mode and adapter.has_ap_mode): possible_adapters.append(adapter) elif (has_monitor_mode and adapter.has_monitor_mode): possible_adapters.append(adapter) for adapter in possible_adapters: if (not adapter.is_managed_by_nm): chosen_interface = adapter.name self._active.add(chosen_interface) return chosen_interface if possible_adapters: raise InterfaceManagedByNetworkManagerError('ALL') else: raise InterfaceCantBeFoundError((has_monitor_mode, has_ap_mode))
'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) except pyric.error as error: if ((error[0] == 93) or (error[0] == 19)): pass else: raise error
'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_networking.has_disable_nm): toggle_networking(True)
'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' % (constants.PUBLIC_DNS,))) else: dhcpconf.write(('address=/#/%s' % (constants.NETWORK_GW_IP,))) subprocess.Popen(['dnsmasq', '-C', '/tmp/dhcpd.conf'], stdout=subprocess.PIPE, stderr=constants.DN) subprocess.Popen(['ifconfig', str(self.interface), 'mtu', '1400'], stdout=constants.DN, stderr=constants.DN) subprocess.Popen(['ifconfig', str(self.interface), 'up', constants.NETWORK_GW_IP, 'netmask', constants.NETWORK_MASK], stdout=constants.DN, stderr=constants.DN) time.sleep(0.5) proc = subprocess.check_output(['ifconfig', str(self.interface)]) if (constants.NETWORK_GW_IP not in proc): return False subprocess.call(('route add -net %s netmask %s gw %s' % (constants.NETWORK_IP, constants.NETWORK_MASK, constants.NETWORK_GW_IP)), shell=True)
'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: self.hostapd_object = hostapd_controller.Hostapd() self.hostapd_object.start(hostapd_config, hostapd_options) except KeyboardInterrupt: raise Exception except BaseException: hostapd_config.pop('karma_enable', None) hostapd_options = {} hostapd_config_obj = hostapd_controller.HostapdConfig() hostapd_config_obj.write_configs(hostapd_config, hostapd_options) self.hostapd_object = subprocess.Popen(['hostapd', hostapd_constants.HOSTAPD_CONF_PATH], stdout=constants.DN, stderr=constants.DN) time.sleep(2) if (self.hostapd_object.poll() is not None): raise Exception
'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.isfile('/var/lib/misc/dnsmasq.leases'): os.remove('/var/lib/misc/dnsmasq.leases') if os.path.isfile('/tmp/dhcpd.conf'): os.remove('/tmp/dhcpd.conf')
':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] = callback(json_obj[func_name]) else: response_to_send[func_name] = 'NotFound' self.write(json.dumps(response_to_send))
'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.get_context()) log_file_path = '/tmp/wifiphisher-webserver.tmp' with open(log_file_path, 'a+') as log_file: log_file.write('GET request from {0} for {1}\n'.format(self.request.remote_ip, self.request.full_url()))
'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 open(log_file_path, 'a+') as log_file: log_file.write('POST request from {0} with {1}\n'.format(self.request.remote_ip, post_data)) creds.append(post_data) terminate = True
'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['payloadpath'] self._path = ((PHISHING_PAGES_DIR + self._name.lower()) + '/') self._path_static = ((PHISHING_PAGES_DIR + self._name.lower()) + '/static/') self._context = config_section_map(config_path, 'context') self._extra_files = []
'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