Esempio n. 1
0
    def get(self, session_id):
        args = SnifferSessionData.parser.parse_args()
        _all = args['all']
        evil = args['evil']
        elements = args['elements']

        session_info = g.messenger.send_recieve('sessioninfo',
                                                'sniffer-commands',
                                                {'session_id': session_id})

        if not session_info:
            abort(404)

        if _all:
            return session_info

        result = Model.find(
            {'_id': {
                '$in': [ObjectId(i) for i in session_info['node_list']]
            }})

        if elements:
            return {"node_list": list(result)}

        if evil:
            return {
                'evil_node_list': [r for r in result if len(r['evil']) > 0]
            }

        if not (_all or elements or evil):
            return abort(400)
Esempio n. 2
0
File: api.py Progetto: CYJ/malcom
def query_data():

	query = {}

	page = int(request.args.get('page', 0))
	per_page = int(request.args.get('per_page', 50))
	if per_page > 500: per_page = 500
	fuzzy = True if request.args.get('fuzzy', False) == 'true' else False
	for key in request.args:
		if key not in ['page', 'fuzzy', 'per_page']:
				if request.args[key].find(',') != -1: # split request arguments
						if fuzzy:
								#query['$and'] = [{ key: re.compile(split, re.IGNORECASE)} for split in request.args[key].split(',')]
								query['$and'] = [{ key: re.compile(split)} for split in request.args[key].split(',')]
						else:
								query['$and'] = [{ key: split} for split in request.args[key].split(',')]
				else:
						if fuzzy:
								#query[key] = re.compile(request.args[key], re.IGNORECASE) # {"$regex": request.args[key]}
								query[key] = re.compile(request.args[key]) # {"$regex": request.args[key]}
						else:
								query[key] = request.args[key]

	data = {}
	chrono_query = datetime.datetime.utcnow()

	print "Query: ", query
	if fuzzy:
		elts = list(Model.elements.find(query, skip=page*per_page, limit=per_page, sort=[('date_created', pymongo.DESCENDING)]).hint([('date_created', -1), ('value', 1)]))
	else:
		elts = list(Model.elements.find(query, skip=page*per_page, limit=per_page, sort=[('date_created', pymongo.DESCENDING)]))
	
	chrono_query = datetime.datetime.utcnow() - chrono_query	

	data['page'] = page
	data['per_page'] = per_page
	
	
	
	for elt in elts:
		elt['link_value'] = url_for('nodes', field='value', value=elt['value'])
		elt['link_type'] = url_for('nodes', field='type', value=elt['type'])
	if len(elts) > 0:
		data['fields'] = elts[0].display_fields
		data['elements'] = elts
	else:
		data['fields'] = [('value', 'Value'), ('type', 'Type'), ('tags', 'Tags')]
		data['elements'] = []
	chrono_count = datetime.datetime.utcnow()
	if not fuzzy:
		data['total_results'] = Model.find(query).count()
	else:
		data['total_results'] = "many"
	chrono_count = datetime.datetime.utcnow() - chrono_count

	data['chrono_query'] = str(chrono_query)
	data['chrono_count'] = str(chrono_count)

	return (dumps(data), 200, {'Content-Type': 'application/json'})
Esempio n. 3
0
    def get(self, session_id):
        args = SnifferSessionData.parser.parse_args()
        _all = args['all']
        evil = args['evil']
        elements = args['elements']

        session_info = g.messenger.send_recieve('sessioninfo', 'sniffer-commands', {'session_id': session_id})

        if not session_info:
            abort(404)

        if _all:
            return session_info

        result = Model.find({'_id': {'$in': [ObjectId(i) for i in session_info['node_list']]}})

        if elements:
            return {"node_list" : list(result)}

        if evil:
            return {'evil_node_list': [r for r in result if len(r['evil']) > 0]}

        if not (_all or elements or evil):
            return abort(400)
Esempio n. 4
0
    def get(self):
        query = {}

        page = int(request.args.get('page', 0))
        per_page = int(request.args.get('per_page', 50))
        if per_page > 500: per_page = 500
        regex = True if request.args.get('regex', False) != False else False

        for key in request.args:
            if key not in ['page', 'regex', 'per_page']:
                if request.args[key].find(
                        ',') != -1:  # split request arguments
                    if regex:
                        #query['$and'] = [{ key: re.compile(split, re.IGNORECASE)} for split in request.args[key].split(',')]
                        query['$and'] = [{
                            key: re.compile(split)
                        } for split in request.args[key].split(',')]
                    else:
                        query['$and'] = [{
                            key: split
                        } for split in request.args[key].split(',')]
                else:
                    if regex:
                        #query[key] = re.compile(request.args[key], re.IGNORECASE) # {"$regex": request.args[key]}
                        query[key] = re.compile(
                            request.args[key])  # {"$regex": request.args[key]}
                    else:
                        query[key] = request.args[key]
        if query:
            hist = query.get('value')
            if hasattr(
                    hist,
                    'pattern'):  # do not attempt to store a regex in history.
                Model.add_to_history(hist.pattern)
            else:
                Model.add_to_history(hist)

        data = {}
        chrono_query = datetime.datetime.utcnow()

        print "Query: ", query
        print "Regex:", regex
        if regex:
            elts = list(
                Model.elements.find(query,
                                    skip=page * per_page,
                                    limit=per_page,
                                    sort=[('date_created', pymongo.DESCENDING)
                                          ]).hint([('date_created', -1),
                                                   ('value', 1)]))
        else:
            elts = list(
                Model.elements.find(query,
                                    skip=page * per_page,
                                    limit=per_page,
                                    sort=[('date_created', pymongo.DESCENDING)
                                          ]))

        chrono_query = datetime.datetime.utcnow() - chrono_query

        data['page'] = page
        data['per_page'] = per_page

        for elt in elts:
            elt['link_value'] = url_for('nodes',
                                        field='value',
                                        value=elt['value'])
            elt['link_type'] = url_for('nodes',
                                       field='type',
                                       value=elt['type'])

        if len(elts) > 0:
            data['fields'] = elts[0].display_fields
            data['elements'] = elts
        else:
            data['fields'] = [('value', 'Value'), ('type', 'Type'),
                              ('tags', 'Tags')]
            data['elements'] = []

        chrono_count = datetime.datetime.utcnow()
        if not regex:
            data['total_results'] = Model.find(query).count()
        else:
            data['total_results'] = "many"
        chrono_count = datetime.datetime.utcnow() - chrono_count

        data['chrono_query'] = str(chrono_query)
        data['chrono_count'] = str(chrono_count)

        return data
Esempio n. 5
0
    def get(self):
        query = {}

        page = int(request.args.get('page', 0))
        per_page = int(request.args.get('per_page', 50))
        if per_page > 500: per_page = 500
        regex = True if request.args.get('regex', False) != False else False

        for key in request.args:
            if key not in ['page', 'regex', 'per_page']:
                    if request.args[key].find(',') != -1: # split request arguments
                            if regex:
                                    #query['$and'] = [{ key: re.compile(split, re.IGNORECASE)} for split in request.args[key].split(',')]
                                    query['$and'] = [{ key: re.compile(split)} for split in request.args[key].split(',')]
                            else:
                                    query['$and'] = [{ key: split} for split in request.args[key].split(',')]
                    else:
                            if regex:
                                    #query[key] = re.compile(request.args[key], re.IGNORECASE) # {"$regex": request.args[key]}
                                    query[key] = re.compile(request.args[key]) # {"$regex": request.args[key]}
                            else:
                                    query[key] = request.args[key]
        if query:
            hist = query.get('value')
            if hasattr(hist, 'pattern'):  # do not attempt to store a regex in history.
                Model.add_to_history(hist.pattern)
            else:
                Model.add_to_history(hist)

        data = {}
        chrono_query = datetime.datetime.utcnow()

        print "Query: ", query
        print "Regex:", regex
        if regex:
            elts = list(Model.elements.find(query, skip=page*per_page, limit=per_page, sort=[('date_created', pymongo.DESCENDING)]).hint([('date_created', -1), ('value', 1)]))
        else:
            elts = list(Model.elements.find(query, skip=page*per_page, limit=per_page, sort=[('date_created', pymongo.DESCENDING)]))

        chrono_query = datetime.datetime.utcnow() - chrono_query

        data['page'] = page
        data['per_page'] = per_page

        for elt in elts:
            elt['link_value'] = url_for('nodes', field='value', value=elt['value'])
            elt['link_type'] = url_for('nodes', field='type', value=elt['type'])

        if len(elts) > 0:
            data['fields'] = elts[0].display_fields
            data['elements'] = elts
        else:
            data['fields'] = [('value', 'Value'), ('type', 'Type'), ('tags', 'Tags')]
            data['elements'] = []

        chrono_count = datetime.datetime.utcnow()
        if not regex:
            data['total_results'] = Model.find(query).count()
        else:
            data['total_results'] = "many"
        chrono_count = datetime.datetime.utcnow() - chrono_count

        data['chrono_query'] = str(chrono_query)
        data['chrono_count'] = str(chrono_count)

        return data
Esempio n. 6
0
File: api.py Progetto: darron/malcom
def query_data():

    query = {}

    page = int(request.args.get('page', 0))
    per_page = int(request.args.get('per_page', 50))
    if per_page > 500: per_page = 500
    fuzzy = True if request.args.get('fuzzy', False) == 'true' else False
    for key in request.args:
        if key not in ['page', 'fuzzy', 'per_page']:
            if request.args[key].find(',') != -1:  # split request arguments
                if fuzzy:
                    #query['$and'] = [{ key: re.compile(split, re.IGNORECASE)} for split in request.args[key].split(',')]
                    query['$and'] = [{
                        key: re.compile(split)
                    } for split in request.args[key].split(',')]
                else:
                    query['$and'] = [{
                        key: split
                    } for split in request.args[key].split(',')]
            else:
                if fuzzy:
                    #query[key] = re.compile(request.args[key], re.IGNORECASE) # {"$regex": request.args[key]}
                    query[key] = re.compile(
                        request.args[key])  # {"$regex": request.args[key]}
                else:
                    query[key] = request.args[key]

    data = {}
    chrono_query = datetime.datetime.utcnow()

    print "Query: ", query
    if fuzzy:
        elts = list(
            Model.elements.find(query,
                                skip=page * per_page,
                                limit=per_page,
                                sort=[('date_created', pymongo.DESCENDING)
                                      ]).hint([('date_created', -1),
                                               ('value', 1)]))
    else:
        elts = list(
            Model.elements.find(query,
                                skip=page * per_page,
                                limit=per_page,
                                sort=[('date_created', pymongo.DESCENDING)]))

    chrono_query = datetime.datetime.utcnow() - chrono_query

    data['page'] = page
    data['per_page'] = per_page

    for elt in elts:
        elt['link_value'] = url_for('nodes', field='value', value=elt['value'])
        elt['link_type'] = url_for('nodes', field='type', value=elt['type'])
    if len(elts) > 0:
        data['fields'] = elts[0].display_fields
        data['elements'] = elts
    else:
        data['fields'] = [('value', 'Value'), ('type', 'Type'),
                          ('tags', 'Tags')]
        data['elements'] = []
    chrono_count = datetime.datetime.utcnow()
    if not fuzzy:
        data['total_results'] = Model.find(query).count()
    else:
        data['total_results'] = "many"
    chrono_count = datetime.datetime.utcnow() - chrono_count

    data['chrono_query'] = str(chrono_query)
    data['chrono_count'] = str(chrono_count)

    return (dumps(data), 200, {'Content-Type': 'application/json'})