本文整理汇总了Python中ztag.transform.ZMapTransformOutput类的典型用法代码示例。如果您正苦于以下问题:Python ZMapTransformOutput类的具体用法?Python ZMapTransformOutput怎么用?Python ZMapTransformOutput使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ZMapTransformOutput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: encode
def encode(self, obj):
pb_out = super(RecordEncoder, self).encode(obj)
out = ZMapTransformOutput()
out.transformed = pb_out.transformed.SerializeToString()
out.certificates = [c.SerializeToString() for c in pb_out.certificates]
out.public_keys = [pk.SerializeToString() for pk in pb_out.public_keys]
return out
示例2: _transform_object
def _transform_object(self, obj):
wrapped = Transformable(obj['data'])
ciphers = wrapped['sslv2']['server_hello']['ciphers'].resolve()
certificate = wrapped['sslv2']['server_hello']['certificate'].resolve()
sslv2_support = bool(wrapped['sslv2']['server_verify'].resolve())
sslv2_export = bool(wrapped['sslv2_export']['server_verify'].resolve())
sslv2_extra_clear = bool(wrapped['sslv2_extra_clear']['server_verify']
['extra_clear'].resolve())
out = {
'support': sslv2_support,
'export': sslv2_export,
'extra_clear': sslv2_extra_clear,
}
if ciphers is not None:
out['ciphers'] = ciphers
if certificate is not None:
out['certificate'] = {
'parsed': certificate['parsed']
}
certificates = [certificate]
else:
certificates = list()
zout = ZMapTransformOutput()
zout.transformed = out
zout.certificates = certificates
return zout
示例3: _transform_object
def _transform_object(self, obj):
zout = ZMapTransformOutput()
wrapped = Transformable(obj)
modbus = wrapped["data"]["modbus"]
if not modbus["raw_response"].resolve():
raise errors.IgnoreObject()
out = dict()
function_code = modbus["function_code"].resolve()
mei_response = modbus["mei_response"]
if function_code:
out["function_code"] = function_code
if mei_response:
conformity_level = mei_response["conformity_level"].resolve()
objects = mei_response["objects"]
vendor = objects["vendor"].resolve()
product_code = objects["product_code"].resolve()
revision = objects["revision"].resolve()
vendor_url = objects["vendor_url"].resolve()
product_name = objects["product_name"].resolve()
model_name = objects["model_name"].resolve()
user_application_name = objects["user_application_name"].resolve()
if (
conformity_level
or vendor
or product_code
or revision
or vendor_url
or product_name
or model_name
or user_application_name
):
out["mei_response"] = dict()
if vendor or product_code or revision or vendor_url or product_name or model_name or user_application_name:
out["mei_response"]["objects"] = dict()
if conformity_level:
out["mei_response"]["conformity_level"] = conformity_level
if vendor:
out["mei_response"]["objects"]["vendor"] = vendor
if product_code:
out["mei_response"]["objects"]["product_code"] = product_code
if revision:
out["mei_response"]["objects"]["revision"] = revision
if vendor_url:
out["mei_response"]["objects"]["vendor_url"] = vendor_url
if product_name:
out["mei_response"]["objects"]["product_name"] = product_name
if model_name:
out["mei_response"]["objects"]["model_name"] = model_name
if user_application_name:
out["mei_response"]["objects"]["user_application_name"] = user_application_name
if len(out) == 0:
raise errors.IgnoreObject("Empty output dict")
zout.transformed = out
return zout
示例4: _transform_object
def _transform_object(self, obj):
tls = obj['data']['tls']
out, certificates = HTTPSTransform.make_tls_obj(tls)
zout = ZMapTransformOutput()
zout.transformed = out
zout.certificates = certificates
return zout
示例5: _transform_object
def _transform_object(self, obj):
wrapped = Transformable(obj)
error_component = wrapped['error_component'].resolve()
if error_component is not None and error_component == 'connect':
raise errors.IgnoreObject("Error connecting")
banner = wrapped['data']['banner'].resolve()
zout = ZMapTransformOutput()
try:
tls_handshake = obj['data']['tls']
out, certificates = https.HTTPSTransform.make_tls_obj(tls_handshake)
zout.transformed['tls'] = out
zout.certificates = certificates
except (TypeError, KeyError, IndexError):
pass
if banner is not None:
zout.transformed['banner'] = self.clean_banner(banner)
if len(zout.transformed) == 0:
raise errors.IgnoreObject("Empty output dict")
return zout
示例6: _transform_object
def _transform_object(self, obj):
http = Transformable(obj)
http_response = http['data']['http']['response']
zout = ZMapTransformOutput()
out = dict()
error_component = http['error_component'].resolve()
if error_component is not None and error_component == 'connect':
raise errors.IgnoreObject("connection error")
if http_response is not None:
status_line = http_response['status_line'].resolve()
status_code = http_response['status_code'].resolve()
body = http_response['body'].resolve()
headers = http_response['headers'].resolve()
if status_line is not None:
out['status_line'] = status_line
if status_code is not None:
out['status_code'] = status_code
if body is not None:
out['body'] = body
if headers is not None:
out['headers'] = headers
if len(out) == 0:
raise errors.IgnoreObject("Empty output dict")
zout.transformed = out
return zout
示例7: _transform_object
def _transform_object(self, obj):
if 'tls' not in obj['data']:
raise errors.IgnoreObject("Not a TLS response")
tls = obj['data']['tls']
out, certificates = HTTPSTransform.make_tls_obj(tls)
zout = ZMapTransformOutput()
zout.transformed = out
zout.certificates = certificates
return zout
示例8: _transform_object
def _transform_object(self, obj):
http = Transformable(obj)
connect_response = http['data']['http']['connect_response']
get_response = http['data']['http']['response']
zout = ZMapTransformOutput()
out = dict()
error_component = http['error_component'].resolve()
if error_component is not None and error_component == 'connect':
raise errors.IgnoreObject("connection error")
if connect_response is not None:
status_line = connect_response['status_line'].resolve()
status_code = connect_response['status_code'].resolve()
body = connect_response['body'].resolve()
headers = connect_response['headers'].resolve()
if status_line or status_code or body or headers is not None:
out['connect'] = dict()
if status_line is not None:
out['connect']['status_line'] = status_line
if status_code is not None:
out['connect']['status_code'] = status_code
if body is not None:
out['connect']['body'] = body
if headers is not None:
out['connect']['headers'] = headers
if get_response is not None:
status_line = get_response['status_line'].resolve()
status_code = get_response['status_code'].resolve()
body = get_response['body'].resolve()
headers = get_response['headers'].resolve()
body_sha256 = get_response['body_sha256'].resolve()
out['get'] = dict()
if body:
random_present = "Uh2Qn8Y7NPRm6h3xqEXUq4EhtW7Po4gy" in body
else:
random_present = False
out['get']['random_present'] = random_present
if status_line is not None:
out['get']['status_line'] = status_line
if status_code is not None:
out['get']['status_code'] = status_code
if body is not None:
out['get']['body'] = body
if headers is not None:
out['get']['headers'] = headers
if body_sha256:
out['get']['body_sha256'] = body_sha256
if len(out) == 0:
raise errors.IgnoreObject("Empty output dict")
zout.transformed = out
return zout
示例9: _transform_object
def _transform_object(self, obj):
zout = ZMapTransformOutput()
wrapped = Transformable(obj)
modbus = wrapped['data']['modbus']
if not modbus['raw_response'].resolve():
raise errors.IgnoreObject()
out = dict()
out["support"] = True
function_code = modbus['function_code'].resolve()
if function_code:
out['function_code'] = function_code
mei_response = modbus['mei_response']
if mei_response:
conformity_level = mei_response['conformity_level'].resolve()
objects = mei_response['objects']
vendor = objects['vendor'].resolve()
product_code = objects['product_code'].resolve()
revision = objects['revision'].resolve()
vendor_url = objects['vendor_url'].resolve()
product_name = objects['product_name'].resolve()
model_name = objects['model_name'].resolve()
user_application_name = objects['user_application_name'].resolve()
if conformity_level or vendor or product_code or revision or \
vendor_url or product_name or model_name or user_application_name:
out['mei_response'] = dict()
if vendor or product_code or revision or vendor_url or product_name \
or model_name or user_application_name:
out['mei_response']['objects'] = dict()
if conformity_level:
out['mei_response']['conformity_level'] = conformity_level
if vendor:
out['mei_response']['objects']['vendor'] = vendor
if product_code:
out['mei_response']['objects']['product_code'] = product_code
if revision:
out['mei_response']['objects']['revision'] = revision
if vendor_url:
out['mei_response']['objects']['vendor_url'] = vendor_url
if product_name:
out['mei_response']['objects']['product_name'] = product_name
if model_name:
out['mei_response']['objects']['model_name'] = model_name
if user_application_name:
out['mei_response']['objects']['user_application_name'] = \
user_application_name
zout.transformed = out
return zout
示例10: _transform_object
def _transform_object(self, obj):
http = Transformable(obj)
http_response = http['data']['http']['response']
zout = ZMapTransformOutput()
out = dict()
zout.transformed = out
error_component = http['error_component'].resolve()
if error_component is not None and error_component == 'connect':
raise errors.IgnoreObject("connection error")
if http_response is not None:
status_line = http_response['status_line'].resolve()
status_code = http_response['status_code'].resolve()
body = http_response['body'].resolve()
body_sha256 = http_response['body_sha256'].resolve()
headers = http_response['headers'].resolve()
if status_line is not None:
out['status_line'] = status_line
if status_code is not None:
out['status_code'] = status_code
if body is not None:
out['body'] = body
m = title_regex.search(body)
if m:
title = m.group(1)
if len(title) > 1024:
title = title[0:1024]
out['title'] = title.strip()
if headers:
# FIXME: This modifies the input?
if "set_cookie" in headers:
del headers["set_cookie"]
if "date" in headers:
del headers["date"]
for k, v, in headers.iteritems():
if k == "unknown":
for d in v:
if len(d["value"]) < 1:
continue
d["value"] = d["value"][0]
elif v:
headers[k] = v[0]
else:
del headers[k]
out['headers'] = headers
if body_sha256:
out['body_sha256'] = body_sha256
if len(out) == 0:
raise errors.IgnoreObject("Empty output dict")
return zout
示例11: _transform_object
def _transform_object(self, obj):
classification = obj['classification']
if classification != "upnp":
raise errors.IgnoreObject(classification)
success = int(obj['success'])
if success != 1:
raise errors.IgnoreObject("unsuccessful zmap")
wrapped = Transformable(obj)
transformed = {}
for key in self.KEYS:
transformed[key] = wrapped[key].resolve()
out = ZMapTransformOutput()
out.transformed = transformed
return out
示例12: encode
def encode(self, zout):
out = ZMapTransformOutput()
obj = zout.transformed
ip = obj['ip_address']
ts = obj['timestamp']
domain = obj.get('domain', None)
if zout.metadata.local_metadata is not None:
obj['metadata'] = zout.metadata.local_metadata.to_dict()
m = zout.metadata.global_metadata.to_dict()
tags = list(zout.metadata.tags)
data = {x: obj[x] for x in obj if x not in self.DROP_KEYS}
m = {k: simple_strip(v) for k, v in m.iteritems()}
metadata = self.Metadatum.from_dict(m)
atom = self.ProtocolAtom(tags=tags, metadata=metadata, data=data)
record = self.Record(ip, self.port, self.protocol.value, self.subprotocol.value,
protocol_atom=atom, domain=domain,
timestamp=ts, scan_id=self.scan_id)
out.transformed = record.protobuf
out.certificates = []
for cert_dict in zout.certificates:
ar = self.zsearch_definitions.anonstore_pb2.AnonymousRecord()
c = ar.certificate
c.parsed = json.dumps(cert_dict["parsed"], sort_keys=True)
c.raw = base64.b64decode(cert_dict["raw"])
c.sha1fp = cert_dict["parsed"]["fingerprint_sha1"].decode("hex")
c.sha256fp = cert_dict["parsed"]["fingerprint_sha256"].decode("hex")
valid_nss = cert_dict.get("nss_trusted", None)
if valid_nss is not None:
c.valid_nss = valid_nss
c.validation_timestamp = record.timestamp
parents_sha256 = cert_dict.get("parents", None)
if parents_sha256 is not None:
c.parents.extend([
sha_value.decode("hex") for sha_value in parents_sha256
])
ar.sha256fp = c.sha256fp
ar.scan_id = self.scan_id
out.certificates.append(ar)
return out
示例13: _transform_object
def _transform_object(self, obj):
classification = obj['classification']
if classification != "dns":
raise errors.IgnoreObject(classification)
if int(obj['success']) != 1:
raise errors.IgnoreObject("Not a DNS resposne")
zout = ZMapTransformOutput()
out = dict()
out["support"] = True
errors_present = False
if obj["dns_parse_err"] == True:
errors_present = True
out["questions"] = []
for question in obj["dns_questions"]:
q = dict()
q["name"] = question["name"]
q["type"] = question["qtype_str"]
out["questions"].append(q)
response_types = (("answers", "dns_answers"), ("authorities", "dns_authorities"),\
("additionals", "dns_additionals"))
for out_field, obj_field in response_types:
(response_errors, responses) = self._transform_responses(obj[obj_field])
if response_errors:
errors_present = True
out[out_field] = responses
out["errors"] = errors_present
out["open_resolver"] = bool(len(out["answers"]) + len(out["additionals"]) + \
len(out["authorities"]))
out["resolves_correctly"] = False
for answer in out["answers"]:
if answer["type"] == "A" and answer["response"] == self.CORRECT_RESPONSE:
out["resolves_correctly"] = True
break
zout.transformed = out
return zout
示例14: _transform_object
def _transform_object(self, obj):
ftp_banner = obj
ftp = Transformable(obj)
zout = ZMapTransformOutput()
error = ftp['error'].resolve()
if error is not None:
raise errors.IgnoreObject("Error")
out = dict()
banner = ftp['data']['banner'].resolve()
if banner is not None:
out['banner'] = self.clean_banner(banner)
if len(out) == 0:
raise errors.IgnoreObject("Empty output dict")
out['ip_address'] = obj['ip']
out['timestamp'] = obj['timestamp']
zout.transformed = out
return zout
示例15: _transform_object
def _transform_object(self, obj):
zout = ZMapTransformOutput()
wrapped = Transformable(obj)
bacnet = wrapped['data']['bacnet']
if not bacnet['is_bacnet'].resolve():
raise errors.IgnoreObject()
instance_number = bacnet['instance_number'].resolve()
vendor_id = bacnet['vendor_id'].resolve()
vendor_name = bacnet['vendor_name'].resolve()
firmware_revision = bacnet['firmware_revision'].resolve()
app_software_rev = bacnet['application_software_revision'].resolve()
object_name = bacnet['object_name'].resolve()
model_name = bacnet['model_name'].resolve()
description = bacnet['description'].resolve()
out = dict()
if instance_number:
out['instance_number'] = instance_number
if vendor_id or vendor_name:
vendor = dict()
if vendor_id:
vendor['id'] = vendor_id
vendor['official_name'] = _vendors.get(vendor_id, 'unknown')
if vendor_name:
vendor['reported_name'] = vendor_name
out['vendor'] = vendor
if firmware_revision:
out['firmware_revision'] = firmware_revision.strip()
if app_software_rev:
out['application_software_revision'] = app_software_rev.strip()
if object_name:
out['object_name'] = object_name.strip()
if model_name:
out['model_name'] = model_name.strip()
if description:
out['description'] = description
if not bool(out):
raise errors.IgnoreObject("Empty output dict")
zout.transformed = out
return zout