Example #1
0
    def do_tunnel(self, option):
        '''tunnel [OPTION]
		calls program to manage tunnels
		option: simple advanced'''
        self.logger.debug('user ran tunnel')

        if self.sfile['survey'] == False:
            self.logger.error(
                'survey had not been completed, please run survey')
            return

        if 'packetToolkit' in self.sfile['uploaded_mod_list']:
            pass
        else:
            self.logger.error('your tunnel module is not uploaded')
            return

        self.logger.info('Starting tunnel in ' + str(option) + ' mode')
        if option == '':
            option = 'simple'
        elif option == 'simple':
            option = 'simple'
        else:
            option = 'advanced'

        self.sfile['mode'] = option

        tunnel_mod = tunnel.Tunnel(self.sfile, self.logger)
        tunnel_mod.cmdloop()
Example #2
0
 def reset(self):
     self.sfx = music.Music()
     self.sfx.play_sfx()
     self.speed = 1
     self.tunnel = tunnel.Tunnel()
     self.score = 0
     self.is_paused = False
     self.plane = plane.Plane()
     self.jump_velo = -1
     self.is_game_over = False
Example #3
0
 def listen(self):
     self.socket.listen()
     log.log('Server is listening at %s:%d' %
             (self.config['addr'], self.config['port']))
     while True:
         clientSocket, _ = self.socket.accept()
         if self.isTLS:
             try:
                 clientSocket = self.context.wrap_socket(clientSocket,
                                                         server_side=True)
             except:
                 clientSocket.close()
                 continue
         tunnel.Tunnel(clientSocket).start()
Example #4
0
def main():
    options, server, remote = parse_options()

    if options.keyfile:
        my_key = open(options.keyfile, 'r')

    t = tunnel.Tunnel(server[0],
                      server[1],
                      username=options.user,
                      client_key=my_key)

    print("Adding defaults ...")
    t1 = t.add_endpoint('127.0.0.1', 25)
    t2 = t.add_endpoint('127.0.0.1', 80)

    print("Adding command line destination")
    t3 = t.add_endpoint(remote[0], remote[1])

    print("Removing defaults ...")
    t.remove_endpoint(t1)
    t.remove_endpoint(t2)

    t.disconnect()
Example #5
0
    def __init__(self, shelve_file, logger):
        '''Intalize variables'''
        cmd.Cmd.__init__(self)

        #shelve file
        self.sfile = shelve_file
        #self.sfile = shelve.open(self.shelve_file)

        #set up logging
        name = 'bananaglee' + self.sfile['version']
        self.logger = logger
        self.prompt = 'BG' + self.sfile['version'] + '>>'

        #log shelve file
        self.logger.debug('sfile contents:')
        for i in self.sfile:
            self.logger.debug(i + ' : ' + str(self.sfile[i]))

        #Parse out tools config which is generated by finder
        self.tools_config = ConfigParser.ConfigParser()
        self.tools_config.read(
            os.path.join(self.sfile['script_dir'], 'tools.cfg'))
        try:
            self.sfile['lp_bin'] = self.tools_config.get(
                str(self.sfile['tool']) + str(self.sfile['version']), 'lp')
        except:
            self.logger.debug('could not get lp from banananaglee' +
                              str(self.sfile['version']))

        self.sfile['timestamp'] = tools.timeStamp()
        self.sfile['lp_dir'], tmp = os.path.split(self.sfile['lp_bin'])
        self.sfile['logs_to_process'] = os.path.join(
            self.sfile['log_dir'],
            self.sfile['hostname'] + '.' + self.sfile['target'])
        self.sfile['logfile'] = os.path.join(
            self.sfile['log_dir'], 'BG_log_' + str(self.sfile['hostname']) +
            '.' + str(self.sfile['target']) + '.log')

        if not os.path.exists(
                self.sfile['logs_to_process']):  # creates log dir
            os.makedirs(self.sfile['logs_to_process'])

        if self.sfile.has_key('lp') == True:
            self.logger.debug('lp ip already exists')
        else:
            self.sfile['lp'] = '127.0.0.1'

        if self.sfile.has_key('implant') == True:
            self.logger.debug('implant ip already exists')
        else:
            self.sfile['implant'] = '127.0.0.1'

        if self.sfile.has_key('idkey') == True:
            self.logger.debug('idkey already exists')
            if os.path.isfile(self.sfile['idkey']) == False:
                self.logger.error('Your keyfile does not exist at: ' +
                                  str(self.sfile['idkey']))
        else:
            self.sfile['idkey'] = 'idkey'

        self.sfile['sport'] = tools.newPort()
        self.sfile['dport'] = tools.newPort()

        #set survey to false
        if tools.timeStamp().split('_')[0] == self.sfile['timestamp'].split(
                '_')[0]:
            pass
        else:
            self.sfile['survey'] = False

        #log starting values
        self.logger.info('starting bananaglee ' + self.sfile['version'])
        self.logger.info('LP IP: ' + self.sfile['lp'])
        self.logger.info('Implant IP: ' + self.sfile['implant'])
        self.logger.info('IDKey : ' + self.sfile['idkey'])
        self.logger.debug('Source Port: ' + str(self.sfile['sport']))
        self.logger.debug('Destination Port: ' + str(self.sfile['dport']))

        os.chdir(self.sfile['lp_dir'])
        if self.sfile.has_key('uploaded_mod_list') == True:
            self.uploaded_mod_list = self.sfile['uploaded_mod_list']
        else:
            self.uploaded_mod_list = []

        if self.sfile.has_key('persistent_modules') == False:
            self.sfile['persistent_modules'] = []

        #auto
        if self.sfile['auto'] == True:
            if self.sfile['auto_start'] == True:
                self.do_survey(' ')
                if 'packetToolkit' in self.sfile['uploaded_mod_list']:
                    self.logger.info('PTK is already here')
                    self.sfile['auto_PTK'] = False
                else:
                    self.logger.info('PTK not present, uploading')
                    self.sfile['auto_PTK'] = True
                    self.do_load('packetToolkit')
                self.sfile['tunnel'] = True
                print self.sfile['tunnel']
                print self.sfile['current_rule']
                tunnel_mod = tunnel.Tunnel(self.sfile, self.logger)
                tunnel_mod.cmdloop()
                self.do_quit(' ')
            elif self.sfile['auto_end'] == True:
                self.do_set_survey(' ')
                if 'packetToolkit' in self.sfile['persistent_modules']:
                    self.logger.info('PTK is a persistent module')
                else:
                    self.logger.info('unloading PTK')
                    self.do_unload('packetToolkit')
                    tools.resetAuto(self.sfile, self.logger)
                    sys.exit()
Example #6
0
import os
import sys
import time
import getpass
import tunnel

my_home = os.path.expanduser("~/.ssh")
my_key_file = "%s/id_rsa" % (my_home)

my_key = open(my_key_file, 'r')
print("Using ssh key: %s" % (my_key))

username = getpass.getuser()

t = tunnel.Tunnel('192.168.1.3', 22, username=username, client_key=my_key)

t1 = t.add_endpoint('127.0.0.1', 25)
t2 = t.add_endpoint('127.0.0.1', 80)
t3 = t.add_endpoint('127.0.0.1', 8080)
t4 = t.add_endpoint('192.168.3.2', 80)

t.remove_endpoint(t3)

print(t.list_endpoints())

t.disconnect()
Example #7
0
import dpkt
import logging
import socket

import tunnel

LOGLEVEL = logging.DEBUG
LOGFORMAT = '%(name)s - %(levelname)s - %(message)s'


def dummyhandler(_):
    pass

if __name__ == '__main__':
    logging.basicConfig(format=LOGFORMAT, level=LOGLEVEL)
    t = tunnel.Tunnel(mode='tun')

    def echohandler(data):
        """Echo the received data back to the sender
        but swap source and dest IPs"""
        # Assume it's L3
        leading_bytes = data[:4]
        data = data[4:]  # Strip off the first 4 bytes
        ip_pkt = dpkt.ip.IP(data)
        src = ip_pkt.src
        dst = ip_pkt.dst
        ip_pkt.src = dst
        ip_pkt.dst = src
        data = leading_bytes + ip_pkt.__bytes__()
        t.send(data)
    t.set_rx_handler(echohandler)
Example #8
0
	def __init__(self, hostname, target, auto):
		cmd.Cmd.__init__(self)
		self.config = ConfigParser.ConfigParser()
                self.config.read('fw_wrapper.cfg')

		#set up logging
		name = 'fw_wrapper'
		self.logger = fw_logging.getLogger(logging.DEBUG,name,hostname,target)

		self.logger.info('welcome to ' + str(name) + ' please select your tool')
		
		#check to make sure running as root
		if getpass.getuser() != 'root':
			self.logger.critical('not running as root, bailing')
			sys.exit()	
		self.prompt = 'FW>>'
		self.hostname = hostname
		self.target = target
		self.logger.info('hostname: ' + str(self.hostname))
		self.logger.info('target: ' + str(self.target))
		self.logger.debug('calling finder')
		finder.finder(hostname,target)
		self.tool_versions = {}
		try:
			self.tools = self.config.get('main','tools')
		except:
			self.logger.exception('could not read the tools in main section of the config')
			sys.exit()
		
		try:
			self.log_dir = self.config.get('main','log_dir')
		except:
			self.logger.exception('could not read the log_dir in the main section of the config')
			sys.exit()
	
		try:
			self.root_path = self.config.get('main','root_path')
		except:
			self.logger.exception('could not read the root_path in the main section of the config')
			sys.exit()

		try:
			self.script_dir = self.config.get('main','script_dir')
		except:
			self.logger.exception('could not read script_dir in the main section of the config')
			sys.exit()

		try:
			self.fg_dir = self.config.get('main','fg_dir')
		except:
			self.logger.exception('could not read fg_dir in the main section of the config')

		try:
			self.bg_versions = self.config.get('bananaglee','versions').split(',')
		except:
			self.logger.exception('could not get the bananaglee versions')

		self.shelve_file = os.path.join(self.log_dir,'firewall_' + str(hostname) + '.' + str(target) + '.shelve')

		if os.path.isfile(self.shelve_file) == True:
			pass
		else:
			self.logger.error('Could not find your shelve file')
		
		try:
			self.sfile = shelve.open(self.shelve_file)	
		except:
			self.logger.exception('could not open the shelve file: ' + str(self.shelve_file))
			sys.exit()

		self.sfile['hostname'] = self.hostname
		self.sfile['target'] = self.target
		self.sfile['root_path'] = self.root_path
                self.sfile['script_dir'] = self.script_dir
                self.sfile['log_dir'] = self.log_dir
                self.sfile['fg_dir'] = self.fg_dir

		self.sfile['do_tunnel'] = True

		self.sfile['echo'] = self.config.get('main','echo')
		self.sfile['nc'] = self.config.get('main','nc')

		#check fg for files
		for root, subFolders, files in os.walk(self.fg_dir):
			for file in files:
				if '.zip' in file:
					if 'firewall' in file:
						self.logger.info('found ' + str(os.path.join(root,file)) + ' unzipping')
						tools.unzip(self.logger,os.path.join(root,file),root)

                for root, subFolders, files in os.walk(self.fg_dir):
                        for file in files:
				if '.key' in file:
					self.logger.info('found ' + str(os.path.join(root,file)) + ' moving to ' + str(os.path.join(self.root_path,'OPS')))
					shutil.copy(os.path.join(root,file),os.path.join(self.root_path,'OPS'))
				if '.shelve' in file:
					self.logger.info('found ' + str(os.path.join(root,file)) + ' moving to ' + str(self.log_dir))
					shutil.copy(os.path.join(root,file),self.log_dir)
				

                if auto[0] == True:
                        self.sfile['auto'] = True
			#auto has been set to true
                        if auto[1] == True and auto[2] == True:
                                self.logger.error('you specified auto with start and end')
                        elif auto[1] == True:
                                self.logger.info('going into auto mode for the start of the op')
				self.sfile['auto_start'] = True
				if self.sfile['tool'] == 'bananaglee':
					bananaglee_mod = bananaglee.BananaGlee(self.sfile, self.logger)
		                        bananaglee_mod.cmdloop()
	                elif auto[2] == True:
                                self.logger.info('going into auto mode for the end of the op')
				self.sfile['auto_end'] = True
				if self.sfile['tool'] == 'bananaglee':
	                                tunnel_mod = tunnel.Tunnel(self.sfile,self.logger)
        	                        tunnel_mod.cmdloop()
                        else:
                                self.logger.error('you specifed auto but did not tell me if it was the start or end of the op')
		else:
			self.sfile['auto'] = False