def get_config(): logging.basicConfig(level=logging.INFO, format='%(levelname)-s: %(message)s') shortopts = "vc:" longopts = ["version", "config="] config_path = "config.json" opts, args = getopt.getopt(sys.argv[1:], shortopts, longopts) for key, value in opts: if key == '-c' or key == '--config': config_path = value config = {} with open(config_path, 'rb') as f: try: config = json.loads(f.read().decode('utf8')) except: # No config? Too bad! logging.error('Cannot load config') sys.exit(1) config['interface'] = config.get('interface', 'tun0').encode('utf-8') config['virtual_ip'] = config.get('virtual_ip', '10.0.0.1') config['server'] = config.get('server', '0.0.0.0') config['port'] = int(config.get('port', '2333')) config['output'] = config.get('output', 'eth0') config['timeout'] = int(config.get('timeout', '600')) config['password'] = crypto.md5(config.get('password', 'password')) return config
def handle(self): global key global public_key global private_key address, pid = self.client_address print('%s connected!' % address) while True: data = self.request.recv(BUF_SIZE) if len(data) > 0: print('receive=', data.decode('utf-8')) cur_thread = threading.current_thread() hdata = crypto.md5(data) print(hdata) response = RSA.encrypt(hdata, private_key) + '/' + public_key self.request.sendall(response)
def headerPacker(): """ Create the header of the JSON with some useful information """ reportTime = (time.ctime()) machineInfo = platform.uname() reportID = crypto.md5(str(time.time())) infoDict = dict() infoDict["id"] = reportID infoDict["info"] = machineInfo infoDict["time"] = reportTime mainPack = dict() mainPack["category"] = "attributes" mainPack["objects"] = infoDict return json.dumps(mainPack, sort_keys=True, indent=4)
def init(reportPathUser): """ Initialize report """ # report name and path reportName = crypto.md5(str(time.time())) if os.path.isdir(reportPathUser): reportPath = os.path.join(reportPathUser, reportName) elif reportPathUser is None: reportPath = os.path.join(config.START_PATH, reportName) else: logger.log("Path " + reportPathUser + " is not a valid path") sys.exit(1) # create directory used for report files os.mkdir(reportPath) logger.log("Report name: " + reportName) logger.log("Path: " + reportPath) return (reportName, reportPath)
print >>sys.stderr, '\nwaiting for the next event' readable, writable, exceptional = select.select(inputs, outputs, inputs) # Handle inputs for s in readable: data = s.recv(1024) if data: # A readable client socket has data data=data.split("]") data= data[0].lstrip('[') global peer_public if data.split('/')[0] == 'cEr': peer_certificate1=data.split('/')[1]+'/'+data.split('/')[2]+'/'+data.split('/')[3] peer_public = data.split('/')[1]+'/'+data.split('/')[2] hcertificate=RSA.decrypt(data.split('/')[4],ca_public_key) if crypto.md5(peer_certificate1)==hcertificate: self.DisplayText.AppendText('\ncertificate receiveded\n') else: self.DisplayText.AppendText('exchange certificate failed\n') else: Text=crypto.decryptData(data,private_key,peer_public) #print data print >>sys.stderr, 'received "%s" from %s' % (data, s.getpeername()) global cipherMark if cipherMark==1: self.DisplayText.AppendText('\nreceived cipher: "%s"\n' % data) self.DisplayText.AppendText('\nreceived text:"%s"\n' % Text) #if data=='esc': self.client.close() #self.DisplayText.AppendText('esc\n' ) else: