Exemple #1
0
def sniffer():
	if request.method == 'POST':

		filter = request.form['filter']

		session_name = secure_filename(request.form['session_name'])
		if session_name == "":
			flash("Please specify a session name", 'warning')
			return redirect(url_for('sniffer'))

		debug_output("Creating session %s" % session_name)

		# intercept TLS?
		# intercept_tls = True if request.form.get('intercept_tls', False) and g.config.sniffer_engine.tls_proxy != None else False
		intercept_tls = True if request.form.get('intercept_tls', False) == 'on' else False
		print "Intercept TLS: %s" % intercept_tls

		file = request.files.get('pcap-file').read()

		if not file and not g.config['SNIFFER_NETWORK']:
			flash("Please specify a PCAP file", 'warning')
			return redirect(url_for('sniffer'))


		params = {  'session_name': session_name,
					'remote_addr' : str(request.remote_addr),
					'filter': filter,
					'intercept_tls': intercept_tls,
					'public': True if request.form.get('public', False) else False,
					'pcap': True if file else False,
				}

		# REDIS send message to sniffer w/ params
		session_id = str(loads(g.messenger.send_recieve('newsession', 'sniffer-commands', params=params)))
		session_info = g.messenger.send_recieve('sessioninfo', 'sniffer-commands', {'session_id': session_id})
		# this is where the data will be stored persistently
		# if we're dealing with an uploaded PCAP file
		if file:
			# store in /sniffer folder
			with open(g.config['SNIFFER_DIR'] + "/" + session_info['pcap_filename'], 'wb') as f:
				f.write(file)

		# associate sniffer session with current user
		current_user.add_sniffer_session(session_id)
		UserManager.save_user(current_user)
		debug_output("Added session %s for user %s" % (session_id, current_user.username))

		# if requested, start sniffing right away
		if request.form.get('startnow', None):
			# REDIS send message to sniffer to start
			g.messenger.send_recieve('sniffstart', 'sniffer-commands', params= {'session_id': session_id, 'remote_addr': str(request.remote_addr)} )
			#sniffer_session.start(str(request.remote_addr))

		return redirect(url_for('sniffer_session', session_id=session_id))

	return render_template('network_session_new.html')
Exemple #2
0
def sniffer():
	if request.method == 'POST':

		filter = request.form['filter']

		session_name = secure_filename(request.form['session_name'])
		if session_name == "":
			flash("Please specify a session name", 'warning')
			return redirect(url_for('sniffer'))

		debug_output("Creating session %s" % session_name)

		# intercept TLS?
		# intercept_tls = True if request.form.get('intercept_tls', False) and g.config.sniffer_engine.tls_proxy != None else False
		intercept_tls = True if request.form.get('intercept_tls', False) == 'on' else False
		print "Intercept TLS: %s" % intercept_tls

		file = request.files.get('pcap-file').read()

		if not file and not g.config['SNIFFER_NETWORK']:
			flash("Please specify a PCAP file", 'warning')
			return redirect(url_for('sniffer'))


		params = {  'session_name': session_name,
					'remote_addr' : str(request.remote_addr),
					'filter': filter,
					'intercept_tls': intercept_tls,
					'public': True if request.form.get('public', False) else False,
					'pcap': True if file else False,
				}

		# REDIS send message to sniffer w/ params
		session_id = str(loads(g.messenger.send_recieve('newsession', 'sniffer-commands', params=params)))
		session_info = g.messenger.send_recieve('sessioninfo', 'sniffer-commands', {'session_id': session_id})
		# this is where the data will be stored persistently
		# if we're dealing with an uploaded PCAP file
		if file:
			# store in /sniffer folder
			with open(g.config['SNIFFER_DIR'] + "/" + session_info['pcap_filename'], 'wb') as f:
				f.write(file)

		# associate sniffer session with current user
		current_user.add_sniffer_session(session_id)
		UserManager.save_user(current_user)
		debug_output("Added session %s for user %s" % (session_id, current_user.username))

		# if requested, start sniffing right away
		if request.form.get('startnow', None):
			# REDIS send message to sniffer to start
			g.messenger.send_recieve('sniffstart', 'sniffer-commands', params= {'session_id': session_id, 'remote_addr': str(request.remote_addr)} )

		return redirect(url_for('sniffer_session', session_id=session_id))

	return render_template('network_session_new.html')