Adding eviltwin tools, updated args.

This commit is contained in:
derv82
2018-04-21 11:44:01 -04:00
parent 9a12e38dda
commit 94dd02b3ab
7 changed files with 398 additions and 2 deletions

67
wifite/tools/dnsmasq.py Executable file
View File

@@ -0,0 +1,67 @@
#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
import os
from .dependency import Dependency
from ..util.process import Process
from ..config import Configuration
class Dnsmasq(Dependency):
'''Wrapper for dnsmasq program.'''
dependency_required = False
dependency_name = 'dnsmasq'
dependency_url = 'apt-get install dnsmasq'
def __init__(self, interface):
self.interface = interface
self.pid = None
def create_config_file(self):
config_file = os.path.join(Configuration.temp(), 'dnsmasq.conf')
if os.path.exists(config_file):
os.remove(config_file)
with open(config_file, 'w') as config:
config.write('interface={}\n'.format(self.interface))
config.write('dhcp-range=10.0.0.10,10.0.0.100,8h\n')
config.write('dhcp-option=3,10.0.0.1\n')
config.write('dhcp-option=6,10.0.0.1\n')
config.write('server=8.8.8.8\n')
config.write('log-queries\n')
config.write('log-dhcp\n')
return config_file
def start(self):
config_file = self.create_config_file()
# Stop already-running dnsmasq process
self.killall()
# Start new dnsmasq process
self.pid = Process([
'dnsmasq',
'-C', config_file
])
def stop(self):
# Kill dnsmasq process
if self.pid:
self.pid.interrupt()
self.killall()
# TODO: Wait until dnsmasq is completely stopped.
def check(self):
# TODO: Check if dnsmasq is still running, if there's any errors in the logs, etc.
if self.pid.poll() is not None:
# Process stopped
pass
def killall(self):
Process(['killall', 'dnsmasq']).wait()

View File

@@ -0,0 +1,64 @@
#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
class EviltwinServer(HTTPServer):
def __init__(self, success_callback, port=80):
super(EviltwinServer, self).__init__('', port, EviltwinRequestHandler)
def serve_forever(self):
super(EviltwinServer, self).serve_forever()
class EviltwinRequestHandler(BaseHTTPRequestHandler):
def __init__(self, success_callback):
self.success_callback = success_callback
def do_GET(self):
request_path = self.path
# TODO: URL mappings to load specific pages.
print("\n----- Request Start ----->\n")
print(request_path)
print(self.headers)
print("<----- Request End -----\n")
self.send_response(200)
self.send_header("Set-Cookie", "foo=bar")
def do_POST(self):
request_path = self.path
# TODO: If path includes router password, call self.success_callback
# TODO: Verify router passwords via separate interface?
print("\n----- Request Start ----->\n")
print(request_path)
request_headers = self.headers
content_length = request_headers.getheaders('content-length')
length = int(content_length[0]) if content_length else 0
print(request_headers)
print(self.rfile.read(length))
print("<----- Request End -----\n")
self.send_response(200)
do_PUT = do_POST
do_DELETE = do_GET
if __name__ == "__main__":
parser = OptionParser()
parser.usage = ("Creates an http-server that will echo out any GET or POST parameters\n"
"Run:\n\n"
" reflect")
(options, args) = parser.parse_args()
main()

74
wifite/tools/hostapd.py Executable file
View File

@@ -0,0 +1,74 @@
#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
import re
import os
from .dependency import Dependency
from ..config import Configuration
class Hostapd(Dependency):
process_name = 'hostapd'
dependency_required = False
dependency_name = process_name
dependency_url = 'apt-get install hostapd'
@classmethod
def exists(cls):
return Process.exists(cls.process_name)
def __init__(self, target, interface):
self.target = target
self.interface = interface
self.pid = None
# Save hostapd state?
def create_config_file(self):
if not self.target.essid_known:
raise Exception('Cannot start hostapd if target has unknown SSID')
config_file = os.path.abspath(os.path.join(Configuration.temp(), 'hostapd.conf'))
with open(config_file, 'w') as config:
config.write('driver=nl80211\n')
config.write('ssid={}\n'.format(self.target.essid))
config.write('hw_mode=g\n') # TODO: support 5ghz
config.write('channel={}\n'.format(self.target.channel))
config.write('logger_syslog=-1\n')
config.write('logger_syslog_level=2\n')
return config_file
def start(self):
config_file = self.create_config_file()
self.killall()
self.pid = Process([
self.process_name,
'-C', config_file,
'-i', self.interface
])
def stop(self):
if self.pid:
self.pid.interrupt()
self.killall()
# TODO: Wait until hostapd is completely stopped.
def check(self):
# TODO: Check if hostapd is still running, if there's any errors in the logs, etc.
if self.pid.poll() is not None:
# Process stopped
pass
def killall(self):
Process(['killall', self.process_name]).wait()

47
wifite/tools/iptables.py Normal file
View File

@@ -0,0 +1,47 @@
#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
import re
from .dependency import Dependency
class Iptables(Dependency):
process_name = 'iptables'
dependency_required = False
dependency_name = process_name
dependency_url = 'apt-get install iptables'
@classmethod
def exists(cls):
return Process.exists(cls.process_name)
@classmethod
def __exec(cls, args, expect_return_code=0):
if type(args) is str:
args = args.split(' ')
command = [cls.process_name] + args
pid = Process(command)
pid.wait()
if expect_return_code and pid.poll() != 0:
raise Exception('Error executing %s:\n%s\n%s' % (' '.join(command), pid.stdout(), pid.stderr()))
@classmethod
def new_chain(cls, chain_name, table):
command = ['-N', name, '-t', table]
cls.__exec(command)
@classmethod
def append(cls, chain, table=None, rules=[]):
args = []
if table is not None:
args.extend(['-t', table])
args.extend(['-A', chain])
args.extend(rules)
cls.__exec(args)