我如何阅读xml? [英] How do i read an xml?
问题描述
我有一个来自sslyze_cli.py的xml输出文件,内容如下。
I have an xml output file from sslyze_cli.py with following content.
<?xml version="1.0" encoding="utf-8"?>
<document SSLyzeVersion="0.13.4" SSLyzeWeb="https://github.com/nabla-c0d3/sslyze" title="SSLyze Scan Results">
<invalidTargets/>
<results networkMaxRetries="4" networkTimeout="5" totalScanTime="14.9100000858">
<target host="www.loremipsum.com" ip="10.10.10.10" port="443" tlsWrappedProtocol="https">
<sslv3 isProtocolSupported="True" title="SSLV3 Cipher Suites">
<preferredCipherSuite>
<cipherSuite anonymous="False" keySize="128" name="TLS_RSA_WITH_RC4_128_SHA"/>
</preferredCipherSuite>
<acceptedCipherSuites>
<cipherSuite anonymous="False" keySize="256" name="TLS_RSA_WITH_AES_256_CBC_SHA"/>
<cipherSuite anonymous="False" keySize="128" name="TLS_RSA_WITH_AES_128_CBC_SHA"/>
<cipherSuite anonymous="False" keySize="128" name="TLS_RSA_WITH_RC4_128_SHA"/>
<cipherSuite anonymous="False" keySize="128" name="TLS_RSA_WITH_RC4_128_MD5"/>
<cipherSuite anonymous="False" keySize="112" name="TLS_RSA_WITH_3DES_EDE_CBC_SHA"/>
</acceptedCipherSuites>
</sslv3>
当我们继续使用xml文件时,SSLv2也有类似的内容。 />
我想为sslv3和sslv2元素提取已接受的密码名称和密钥大小。
我如何遍历子元素并验证属于sslv2的某些密码组元素以及其他用于接受密码的sslv3父元素的元素?
谢谢。
我尝试了什么:
我尝试使用lxml模块,但我没有成功。当我导入它时,我的文档中没有提到太多选项。
我现在正在使用xml模块。我已经能够遍历root并获取sslv3元素并检查它是否受支持。
There is similar content for SSLv2 as well when we go ahead in xml file.
I want to extract accepted cipher name and keysize for sslv3 and sslv2 elements.
How do I iterate through child elements and validate certain ciphersuite elements belong to sslv2 and others belowng to sslv3 parent element for accepted ciphers?
Thanks.
What I have tried:
I tried using lxml module but I am not successful with it. when I import it, I don't get much options which are mentioned in its documentation.
I am using xml module now. I have been able to iterate through root and get sslv3 element and check if it is supported or not.
for _sslv3 in _root.iter('sslv3'):
_sslv3 = _sslv3.attrib
_result = str(_sslv3['isProtocolSupported'])
不确定,怎么办进一步。非常感谢任何帮助。
Not sure, how to proceed further. Any help is much appreciated.
推荐答案
好的,通过实现下面的代码找到解决方案。
alright, found solution by implementing below code.
for _ver3 in _root.iter('sslv3'):
for _accepted in _ver3.findall('acceptedCipherSuites'):
for _ciphers in _accepted.findall('cipherSuite'):
_ciphers = _ciphers.attrib
if int(_ciphers['keySize']) <= 128:
print 'Weak cipher found'
这篇关于我如何阅读xml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!