Skip to content

Commit

Permalink
CPE: query backend, cgi and help
Browse files Browse the repository at this point in the history
  • Loading branch information
fmonjalet committed May 3, 2015
1 parent a261f73 commit bbc9b0d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/WEBUI.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ single or double quotes.
- `netdev`, `networkdevice` look for network devices (firewalls,
routers, ...).
- `phonedev` look for telephony devices.
- `cpe:` look for a given cpe.
- `[!]hop:` look for a particular IP address in the traceroute
results.
- `[!]hopname:` look for a matching hostname in the traceroute
Expand Down
26 changes: 26 additions & 0 deletions ivre/db/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,32 @@ def searchscreenshot(port=None, protocol='tcp', service=None, neg=False):
'screenshot': {'$exists': not neg}}
}}

@staticmethod
def searchcpe(value=None, type=None, vendor=None, product=None,
components=None):
"""Look for a CPE by value (original cpe string), type (a, o or h),
vendor, product or components (the part after the column following
the product). No argument will just check for cpe existence.
"""
if all(arg is None
for arg in [value, type, vendor, product, components]):
return {"cpes": {"$exists": True}}

flt = {}
fields = [
("value", value),
("type", type),
("vendor", vendor),
("product", product),
("components", components),
]

for (field_name, field_val) in fields:
if field_val is not None:
flt["cpes." + field_name] = field_val
return flt

def topvalues(self, field, flt=None, topnbr=10, sortby=None,
limit=None, skip=None, least=False, archive=False,
aggrflt=None, specialproj=None, specialflt=None,
Expand Down
16 changes: 16 additions & 0 deletions web/cgi-bin/scanjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,22 @@ def check_referer():
else:
flt = db.nmap.flt_and(flt, db.nmap.searchscreenshot(
service=q[1], neg=neg))
elif nq == "cpe":
cpe_kwargs = {}
allowed_fields = set(["value", "type", "vendor", "product",
"components"])
if q[1]:
cpe_args = q[1].split(',')
for cpe_arg in cpe_args:
if '=' not in cpe_arg:
# only value
cpe_kwargs["value"] = ivre.utils.str2regexp(cpe_arg)
else:
field, value = cpe_arg.split("=", 1)
if field not in allowed_fields:
continue
cpe_kwargs[field] = ivre.utils.str2regexp(value)
flt = db.nmap.flt_and(flt, db.nmap.searchcpe(**cpe_kwargs))
elif nq == 'display':
# ignore this parameter
pass
Expand Down
1 change: 1 addition & 0 deletions web/dokuwiki/doc/webui.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ If your command includes spaces, you need to protect it by using single or doubl
* ''%%devtype:%%'', ''%%devicetype:%%'' look for a type of devices.
* ''%%netdev%%'', ''%%networkdevice%%'' look for network devices (firewalls, routers, ...).
* ''%%phonedev%%'' look for telephony devices.
* ''%%cpe%%''` look for a given cpe.
* ''%%[!]hop:%%'' look for a particular IP address in the traceroute results.
* ''%%[!]hopname:%%'' look for a matching hostname in the traceroute results.
* ''%%[!]hopdomain:%%'' look for a hostname within a matching domain name in the traceroute results.
Expand Down
5 changes: 5 additions & 0 deletions web/static/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ var HELP = {
"title": "phonedev",
"content": "Look for phone devices (e.g., PBX, VoIP devices, phones, etc.).",
},
/* CPEs */
"cpe": {
"title": "cpe:<b>([value])</b> or cpe:<b>[field name]=[field value]</b>(, ...)",
"content": "Looks for CPEs matching value (which can be a /regex/). Providing no value will match all the hosts that have CPE information. The 'field name' can be: type (a, o or h), vendor, product or components, and 'field value' can be a /regex/.",
},
/* traceroute */
"hop:": {
"title": "<b>(!)</b>hop:<b>[IP address](:[TTL])</b>",
Expand Down

0 comments on commit bbc9b0d

Please sign in to comment.