Skip to content
This repository has been archived by the owner on Aug 17, 2018. It is now read-only.

Commit

Permalink
style: run yapf on all files
Browse files Browse the repository at this point in the history
Run yapf on all files to ensure formatting is done for all the files.
  • Loading branch information
blackHatMonkey committed Nov 17, 2017
1 parent 4fca1e7 commit e217707
Show file tree
Hide file tree
Showing 17 changed files with 360 additions and 519 deletions.
52 changes: 26 additions & 26 deletions robophisher/common/accesspoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,39 +105,37 @@ def start_dhcp_dns(self):
:rtype: None
"""

config = (
'no-resolv\n'
'interface=%s\n'
'dhcp-range=%s\n'
)
config = ('no-resolv\n' 'interface=%s\n' 'dhcp-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,))
dhcpconf.write("server=%s" % (constants.PUBLIC_DNS, ))
else:
dhcpconf.write("address=/#/%s" % (constants.NETWORK_GW_IP,))
dhcpconf.write("address=/#/%s" % (constants.NETWORK_GW_IP, ))
# catch the exception if dnsmasq is not installed
try:
subprocess.Popen(['dnsmasq', '-C', '/tmp/dhcpd.conf'],
stdout=subprocess.PIPE, stderr=constants.DN)
subprocess.Popen(
['dnsmasq', '-C', '/tmp/dhcpd.conf'], stdout=subprocess.PIPE, stderr=constants.DN)
except OSError:
print ("[" + constants.R + "!" + constants.W + "] " +
"dnsmasq is not installed!")
print("[" + constants.R + "!" + constants.W + "] " + "dnsmasq is not installed!")
raise Exception

subprocess.Popen(['ifconfig', str(self.interface), 'mtu', '1400'],
stdout=constants.DN, 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
[
'ifconfig',
str(self.interface), 'up', constants.NETWORK_GW_IP, 'netmask',
constants.NETWORK_MASK
],
stdout=constants.DN,
stderr=constants.DN
)
stderr=constants.DN)
# Give it some time to avoid "SIOCADDRT: Network is unreachable"
time.sleep(1)
# Make sure that we have set the network properly.
Expand All @@ -159,14 +157,17 @@ def start(self):
"ssid": self.essid,
"interface": self.interface,
"channel": self.channel,
"karma_enable": 1}
"karma_enable": 1
}
if self.psk:
hostapd_config['wpa_passphrase'] = self.psk

# create the option dictionary
hostapd_options = {'debug_level': hostapd_constants.HOSTAPD_DEBUG_OFF,
'mute': True,
"eloop_term_disable": True}
hostapd_options = {
'debug_level': hostapd_constants.HOSTAPD_DEBUG_OFF,
'mute': True,
"eloop_term_disable": True
}

try:
self.hostapd_object = hostapd_controller.Hostapd()
Expand All @@ -185,17 +186,16 @@ def start(self):
try:
self.hostapd_object = subprocess.Popen(
['hostapd', hostapd_constants.HOSTAPD_CONF_PATH],
stdout=constants.DN, stderr=constants.DN)
stdout=constants.DN,
stderr=constants.DN)
except OSError:
print ("[" + constants.R + "!" + constants.W + "] " +
"hostapd is not installed!")
print("[" + constants.R + "!" + constants.W + "] " + "hostapd is not installed!")
# just raise exception when hostapd is not installed
raise Exception

time.sleep(2)
if self.hostapd_object.poll() is not None:
print ("[" + constants.R + "!" + constants.W + "] " +
"hostapd failed to lunch!")
print("[" + constants.R + "!" + constants.W + "] " + "hostapd failed to lunch!")
raise Exception

def on_exit(self):
Expand Down
40 changes: 21 additions & 19 deletions robophisher/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import os

dir_of_executable = os.path.dirname(__file__)
path_to_project_root = os.path.abspath(
os.path.join(dir_of_executable, '../../robophisher'))
path_to_project_root = os.path.abspath(os.path.join(dir_of_executable, '../../robophisher'))
dir_of_data = path_to_project_root + '/data/'

# Basic configuration
Expand Down Expand Up @@ -35,15 +34,17 @@
WIFI_IPV6MCAST2 = "33:33:ff:"
WIFI_SPANNINGTREE = "01:80:c2:00:00:00"
WIFI_MULTICAST = "01:00:5e:"
NON_CLIENT_ADDRESSES = set([WIFI_BROADCAST, WIFI_INVALID, WIFI_MULTICAST, WIFI_IPV6MCAST1,
WIFI_IPV6MCAST2, WIFI_SPANNINGTREE, None])
NON_CLIENT_ADDRESSES = set([
WIFI_BROADCAST, WIFI_INVALID, WIFI_MULTICAST, WIFI_IPV6MCAST1, WIFI_IPV6MCAST2,
WIFI_SPANNINGTREE, None
])
DEFAULT_OUI = '00:00:00'
LINES_OUTPUT = 3
DN = open(os.devnull, 'w')
INTERFERING_PROCS = ["wpa_action", "wpa_supplicant", "wpa_cli", "dhclient",
"ifplugd", "dhcdbd", "dhcpcd", "udhcpc",
"avahi-autoipd", "avahi-daemon", "wlassistant",
"wifibox", "NetworkManager", "knetworkmanager"]
INTERFERING_PROCS = [
"wpa_action", "wpa_supplicant", "wpa_cli", "dhclient", "ifplugd", "dhcdbd", "dhcpcd", "udhcpc",
"avahi-autoipd", "avahi-daemon", "wlassistant", "wifibox", "NetworkManager", "knetworkmanager"
]

# Modes of operation
# Advanced
Expand Down Expand Up @@ -74,15 +75,15 @@
AP_RATES = "\x0c\x12\x18\x24\x30\x48\x60\x6c"

# Console colors
W = '\033[0m' # white (normal)
R = '\033[31m' # red
G = '\033[32m' # green
O = '\033[33m' # orange
B = '\033[34m' # blue
P = '\033[35m' # purple
C = '\033[36m' # cyan
W = '\033[0m' # white (normal)
R = '\033[31m' # red
G = '\033[32m' # green
O = '\033[33m' # orange
B = '\033[34m' # blue
P = '\033[35m' # purple
C = '\033[36m' # cyan
GR = '\033[37m' # gray
T = '\033[93m' # tan
T = '\033[93m' # tan

# Logging configurations
# possible values for debug levels are:
Expand All @@ -109,10 +110,11 @@
},
'root': {
'level': 'DEBUG',
'handlers': ['file', ],
},
"loggers": {
'handlers': [
'file',
],
},
"loggers": {},
'disable_existing_loggers': False
}

Expand Down
26 changes: 10 additions & 16 deletions robophisher/common/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import scapy.arch.linux as linux
import robophisher.common.constants as constants


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -140,8 +139,7 @@ def _channel_hop(self):
"""

# set the current channel to the ap channel
self._nm.set_interface_channel(
self._interface, int(self._current_channel))
self._nm.set_interface_channel(self._interface, int(self._current_channel))

# if the stop flag not set, change the channel
while self._should_continue:
Expand All @@ -152,10 +150,9 @@ def _channel_hop(self):
if self._should_continue:
try:
self._socket.close()
self._nm.set_interface_channel(
self._interface, int(self._current_channel))
self._socket = linux.L2Socket(
iface=self._interface)
self._nm.set_interface_channel(self._interface,
int(self._current_channel))
self._socket = linux.L2Socket(iface=self._interface)
# extends the channel hopping time to sniff
# more frames
time.sleep(3)
Expand Down Expand Up @@ -207,14 +204,12 @@ def init_extensions(self, shared_data):
"""

# Convert shared_data from dict to named tuple
shared_data = collections.namedtuple('GenericDict',
shared_data.keys())(**shared_data)
shared_data = collections.namedtuple('GenericDict', shared_data.keys())(**shared_data)
self._shared_data = shared_data

# Initialize all extensions with the shared data
for extension in self._extensions_str:
mod = importlib.import_module(
constants.EXTENSIONS_LOADPATH + extension)
mod = importlib.import_module(constants.EXTENSIONS_LOADPATH + extension)
extension_class = getattr(mod, extension.title())
obj = extension_class(shared_data)
self._extensions.append(obj)
Expand Down Expand Up @@ -260,9 +255,8 @@ def on_exit(self):
self._listen_thread.join(3)
if self._send_thread.is_alive():
self._send_thread.join(3)
if (self._shared_data is not None and
self._shared_data.is_freq_hop_allowed and
self._channelhop_thread.is_alive()):
if (self._shared_data is not None and self._shared_data.is_freq_hop_allowed
and self._channelhop_thread.is_alive()):
self._channelhop_thread.join(3)
# Close socket if it's open
try:
Expand All @@ -287,8 +281,8 @@ def get_channels(self):
number_of_channels = len(channels_interested)
if channels_interested and number_of_channels > 0:
# Append only new channels (no duplicates)
self._channels_to_hop += list(set(channels_interested) -
set(self._channels_to_hop))
self._channels_to_hop += list(
set(channels_interested) - set(self._channels_to_hop))

def get_output(self):
"""
Expand Down
25 changes: 12 additions & 13 deletions robophisher/common/firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@
import subprocess
from robophisher.common.constants import *

class Fw():

class Fw():
def __init__(self):
pass

def nat(self, internal_interface, external_interface):
subprocess.call(
('iptables -t nat -A POSTROUTING -o %s -j MASQUERADE'
% (external_interface,)),
('iptables -t nat -A POSTROUTING -o %s -j MASQUERADE' % (external_interface, )),
shell=True)

subprocess.call(
('iptables -A FORWARD -i %s -o %s -j ACCEPT'
% (internal_interface, external_interface)),
('iptables -A FORWARD -i %s -o %s -j ACCEPT' %
(internal_interface, external_interface)),
shell=True)

def clear_rules(self):
Expand All @@ -26,20 +25,20 @@ def clear_rules(self):

def redirect_requests_localhost(self):
subprocess.call(
('iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination %s:%s'
% (NETWORK_GW_IP, PORT)),
('iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination %s:%s' %
(NETWORK_GW_IP, PORT)),
shell=True)
subprocess.call(
('iptables -t nat -A PREROUTING -p udp --dport 53 -j DNAT --to-destination %s:%s'
% (NETWORK_GW_IP, 53)),
('iptables -t nat -A PREROUTING -p udp --dport 53 -j DNAT --to-destination %s:%s' %
(NETWORK_GW_IP, 53)),
shell=True)
subprocess.call(
('iptables -t nat -A PREROUTING -p tcp --dport 53 -j DNAT --to-destination %s:%s'
% (NETWORK_GW_IP, 53)),
('iptables -t nat -A PREROUTING -p tcp --dport 53 -j DNAT --to-destination %s:%s' %
(NETWORK_GW_IP, 53)),
shell=True)
subprocess.call(
('iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination %s:%s'
% (NETWORK_GW_IP, SSL_PORT)),
('iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination %s:%s' %
(NETWORK_GW_IP, SSL_PORT)),
shell=True)

def on_exit(self):
Expand Down
Loading

0 comments on commit e217707

Please sign in to comment.