Bonjour,

J’essaie d'afficher les données d'un XML (Résultat d'un sslscan) pour par la suite placer ce résultat en base de donner.

Mon problème est que je n'arrive pas à récupérer mes données proprement.
Voilà mon fichier XML :
Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?xml version="1.0" encoding="UTF-8"?>
<document title="SSLScan Results" version="1.11.8-static" web="http://github.com/rbsec/sslscan">
    <ssltest host="googleapis.com" port="443">
        <renegotiation supported="1" secure="1" />
        <compression supported="0" />
        <heartbleed sslversion="TLSv1.2" vulnerable="0" />
        <heartbleed sslversion="TLSv1.1" vulnerable="0" />
        <heartbleed sslversion="TLSv1.0" vulnerable="0" />
        <cipher status="preferred" sslversion="TLSv1.2" bits="128" cipher="ECDHE-RSA-AES128-GCM-SHA256" id="0xC02F" curve="P-256" ecdhebits="256" />
        <cipher status="accepted" sslversion="TLSv1.2" bits="128" cipher="ECDHE-RSA-AES128-SHA" id="0xC013" curve="P-256" ecdhebits="256" />
        <cipher status="accepted" sslversion="TLSv1.2" bits="128" cipher="AES128-GCM-SHA256" id="0x9C" />
        <cipher status="accepted" sslversion="TLSv1.2" bits="128" cipher="AES128-SHA" id="0x2F" />
        <cipher status="accepted" sslversion="TLSv1.2" bits="112" cipher="DES-CBC3-SHA" id="0xA" />
        <cipher status="accepted" sslversion="TLSv1.2" bits="256" cipher="ECDHE-RSA-AES256-GCM-SHA384" id="0xC030" curve="P-256" ecdhebits="256" />
        <cipher status="accepted" sslversion="TLSv1.2" bits="256" cipher="ECDHE-RSA-AES256-SHA" id="0xC014" curve="P-256" ecdhebits="256" />
        <cipher status="accepted" sslversion="TLSv1.2" bits="256" cipher="AES256-GCM-SHA384" id="0x9D" />
        <cipher status="accepted" sslversion="TLSv1.2" bits="256" cipher="AES256-SHA" id="0x35" />
        <cipher status="accepted" sslversion="TLSv1.2" bits="128" cipher="ECDHE-RSA-AES128-SHA256" id="0xC027" curve="P-256" ecdhebits="256" />
        <cipher status="accepted" sslversion="TLSv1.2" bits="256" cipher="ECDHE-RSA-AES256-SHA384" id="0xC028" curve="P-256" ecdhebits="256" />
        <cipher status="accepted" sslversion="TLSv1.2" bits="128" cipher="AES128-SHA256" id="0x3C" />
        <cipher status="accepted" sslversion="TLSv1.2" bits="256" cipher="AES256-SHA256" id="0x3D" />
        <cipher status="preferred" sslversion="TLSv1.1" bits="128" cipher="ECDHE-RSA-AES128-SHA" id="0xC013" curve="P-256" ecdhebits="256" />
        <cipher status="accepted" sslversion="TLSv1.1" bits="128" cipher="AES128-SHA" id="0x2F" />
        <cipher status="accepted" sslversion="TLSv1.1" bits="112" cipher="DES-CBC3-SHA" id="0xA" />
        <cipher status="accepted" sslversion="TLSv1.1" bits="256" cipher="ECDHE-RSA-AES256-SHA" id="0xC014" curve="P-256" ecdhebits="256" />
        <cipher status="accepted" sslversion="TLSv1.1" bits="256" cipher="AES256-SHA" id="0x35" />
        <cipher status="preferred" sslversion="TLSv1.0" bits="128" cipher="ECDHE-RSA-AES128-SHA" id="0xC013" curve="P-256" ecdhebits="256" />
        <cipher status="accepted" sslversion="TLSv1.0" bits="128" cipher="AES128-SHA" id="0x2F" />
        <cipher status="accepted" sslversion="TLSv1.0" bits="112" cipher="DES-CBC3-SHA" id="0xA" />
        <cipher status="accepted" sslversion="TLSv1.0" bits="256" cipher="ECDHE-RSA-AES256-SHA" id="0xC014" curve="P-256" ecdhebits="256" />
        <cipher status="accepted" sslversion="TLSv1.0" bits="256" cipher="AES256-SHA" id="0x35" />
            <certificate>
                <signature-algorithm>sha256WithRSAEncryption</signature-algorithm>
                <pk error="false" type="RSA" bits="2048" />
                <subject><![CDATA[*.googleapis.com]]></subject>
                <altnames><![CDATA[DNS:*.googleapis.com, DNS:*.clients6.google.com, DNS:*.cloudendpointsapis.com, DNS:cloudendpointsapis.com, DNS:googleapis.com]]></altnames>
                <issuer><![CDATA[Google Internet Authority G2]]></issuer>
                <self-signed>false</self-signed>
                <not-valid-before>Dec 15 13:50:52 2016 GMT</not-valid-before>
                <not-valid-after>Mar  9 13:35:00 2017 GMT</not-valid-after>
                <expired>false</expired>
            </certificate>
    </ssltest>
</document>

Voilà mon code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
 
#!/usr/bin/env perl
use strict;
use utf8;
use warnings qw(all);
use Data::Dumper;
use XML::Twig;
 
my $FichierXML = 'test.xml';
 
my $twig = XML::Twig->new();
$twig->parsefile($FichierXML);
 
my $root = $twig->root;
my $ssltest = $root->first_child('ssltest');
 
$ssltest->print;
print "\n\n\n";
 
print "ssltest-compression-supported = $ssltest->first_child('compression')->att('supported')\n";
print "ssltest-renegotiation-secure = $ssltest->first_child('renegotiation')->att('secure')\n";
print "ssltest-renegotiation-supported = $ssltest->first_child('renegotiation')->att('supported')\n";
print "ssltest-certificate-self-signed = $ssltest->first_child('certificate')->field('self-signed')\n";
print "ssltest-certificate-not-valid-after = $ssltest->first_child('certificate')->field('not-valid-after')\n";
print "ssltest-certificate-pk-error = $ssltest->first_child('certificate')->first_child('pk')->att('error')\n";
print "ssltest-certificate-pk-bits = $ssltest->first_child('certificate')->first_child('pk')->att('bits')\n";
print "ssltest-certificate-pk-type = $ssltest->first_child('certificate')->first_child('pk')->att('type')\n";
print "ssltest-certificate-subject = $ssltest->first_child('certificate')->field('subject')\n";
print "ssltest-certificate-signature-algorithm = $ssltest->first_child('certificate')->field('signature-algorithm')\n";
print "ssltest-certificate-not-valid-before = $ssltest->first_child('certificate')->field('not-valid-before')\n";
print "ssltest-certificate-issuer = $ssltest->first_child('certificate')->field('issuer');\n";
print "ssltest-certificate-altnames = $ssltest->first_child('certificate')->field('altnames')\n";
print "ssltest-certificate-expired = $ssltest->first_child('certificate')->field('expired')\n";
foreach my $heartbleed ($ssltest->child('heartbleed')) {
    print "ssltest-heartbleed-version = $heartbleed->att('sslversion')\n";
    print "ssltest-heartbleed-vulnerable = $heartbleed->att('vulnerable')\n";
}
foreach my $cipher ($ssltest->child('cipher')) {
    print "ssltest-cipher-status = $cipher->att('status')\n";
    print "ssltest-cipher-sslversion = $cipher->att('sslversion')\n";
    print "ssltest-cipher-bits = $cipher->att('bits')\n";
    print "ssltest-cipher-cipher = $cipher->att('cipher')\n";
    print "ssltest-cipher-id = $cipher->att('id')\n";
    print "ssltest-cipher-curve = $cipher->att('curve')\n";
    print "ssltest-cipher-ecdhebits = $cipher->att('ecdhebits')\n";
}
Le résultat :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
<ssltest host="googleapis.com" port="443"><renegotiation secure="1" supported="1"/><compression supported="0"/><heartbleed sslversion="TLSv1.2" vulnerable="0"/><heartbleed sslversion="TLSv1.1" vulnerable="0"/><heartbleed sslversion="TLSv1.0" vulnerable="0"/><cipher bits="128" cipher="ECDHE-RSA-AES128-GCM-SHA256" curve="P-256" ecdhebits="256" id="0xC02F" sslversion="TLSv1.2" status="preferred"/><cipher bits="128" cipher="ECDHE-RSA-AES128-SHA" curve="P-256" ecdhebits="256" id="0xC013" sslversion="TLSv1.2" status="accepted"/><cipher bits="128" cipher="AES128-GCM-SHA256" id="0x9C" sslversion="TLSv1.2" status="accepted"/><cipher bits="128" cipher="AES128-SHA" id="0x2F" sslversion="TLSv1.2" status="accepted"/><cipher bits="112" cipher="DES-CBC3-SHA" id="0xA" sslversion="TLSv1.2" status="accepted"/><cipher bits="256" cipher="ECDHE-RSA-AES256-GCM-SHA384" curve="P-256" ecdhebits="256" id="0xC030" sslversion="TLSv1.2" status="accepted"/><cipher bits="256" cipher="ECDHE-RSA-AES256-SHA" curve="P-256" ecdhebits="256" id="0xC014" sslversion="TLSv1.2" status="accepted"/><cipher bits="256" cipher="AES256-GCM-SHA384" id="0x9D" sslversion="TLSv1.2" status="accepted"/><cipher bits="256" cipher="AES256-SHA" id="0x35" sslversion="TLSv1.2" status="accepted"/><cipher bits="128" cipher="ECDHE-RSA-AES128-SHA256" curve="P-256" ecdhebits="256" id="0xC027" sslversion="TLSv1.2" status="accepted"/><cipher bits="256" cipher="ECDHE-RSA-AES256-SHA384" curve="P-256" ecdhebits="256" id="0xC028" sslversion="TLSv1.2" status="accepted"/><cipher bits="128" cipher="AES128-SHA256" id="0x3C" sslversion="TLSv1.2" status="accepted"/><cipher bits="256" cipher="AES256-SHA256" id="0x3D" sslversion="TLSv1.2" status="accepted"/><cipher bits="128" cipher="ECDHE-RSA-AES128-SHA" curve="P-256" ecdhebits="256" id="0xC013" sslversion="TLSv1.1" status="preferred"/><cipher bits="128" cipher="AES128-SHA" id="0x2F" sslversion="TLSv1.1" status="accepted"/><cipher bits="112" cipher="DES-CBC3-SHA" id="0xA" sslversion="TLSv1.1" status="accepted"/><cipher bits="256" cipher="ECDHE-RSA-AES256-SHA" curve="P-256" ecdhebits="256" id="0xC014" sslversion="TLSv1.1" status="accepted"/><cipher bits="256" cipher="AES256-SHA" id="0x35" sslversion="TLSv1.1" status="accepted"/><cipher bits="128" cipher="ECDHE-RSA-AES128-SHA" curve="P-256" ecdhebits="256" id="0xC013" sslversion="TLSv1.0" status="preferred"/><cipher bits="128" cipher="AES128-SHA" id="0x2F" sslversion="TLSv1.0" status="accepted"/><cipher bits="112" cipher="DES-CBC3-SHA" id="0xA" sslversion="TLSv1.0" status="accepted"/><cipher bits="256" cipher="ECDHE-RSA-AES256-SHA" curve="P-256" ecdhebits="256" id="0xC014" sslversion="TLSv1.0" status="accepted"/><cipher bits="256" cipher="AES256-SHA" id="0x35" sslversion="TLSv1.0" status="accepted"/><certificate><signature-algorithm>sha256WithRSAEncryption</signature-algorithm><pk bits="2048" error="false" type="RSA"/><subject><![CDATA[*.googleapis.com]]></subject><altnames><![CDATA[DNS:*.googleapis.com, DNS:*.clients6.google.com, DNS:*.cloudendpointsapis.com, DNS:cloudendpointsapis.com, DNS:googleapis.com]]></altnames><issuer><![CDATA[Google Internet Authority G2]]></issuer><self-signed>false</self-signed><not-valid-before>Dec 15 13:50:52 2016 GMT</not-valid-before><not-valid-after>Mar  9 13:35:00 2017 GMT</not-valid-after><expired>false</expired></certificate></ssltest>
 
 
ssltest-compression-supported = XML::Twig::Elt=HASH(0x2916bc8)->first_child('compression')->att('supported')
ssltest-renegotiation-secure = XML::Twig::Elt=HASH(0x2916bc8)->first_child('renegotiation')->att('secure')
ssltest-renegotiation-supported = XML::Twig::Elt=HASH(0x2916bc8)->first_child('renegotiation')->att('supported')
ssltest-certificate-self-signed = XML::Twig::Elt=HASH(0x2916bc8)->first_child('certificate')->field('self-signed')
ssltest-certificate-not-valid-after = XML::Twig::Elt=HASH(0x2916bc8)->first_child('certificate')->field('not-valid-after')
ssltest-certificate-pk-error = XML::Twig::Elt=HASH(0x2916bc8)->first_child('certificate')->first_child('pk')->att('error')
ssltest-certificate-pk-bits = XML::Twig::Elt=HASH(0x2916bc8)->first_child('certificate')->first_child('pk')->att('bits')
ssltest-certificate-pk-type = XML::Twig::Elt=HASH(0x2916bc8)->first_child('certificate')->first_child('pk')->att('type')
ssltest-certificate-subject = XML::Twig::Elt=HASH(0x2916bc8)->first_child('certificate')->field('subject')
ssltest-certificate-signature-algorithm = XML::Twig::Elt=HASH(0x2916bc8)->first_child('certificate')->field('signature-algorithm')
ssltest-certificate-not-valid-before = XML::Twig::Elt=HASH(0x2916bc8)->first_child('certificate')->field('not-valid-before')
ssltest-certificate-issuer = XML::Twig::Elt=HASH(0x2916bc8)->first_child('certificate')->field('issuer');
ssltest-certificate-altnames = XML::Twig::Elt=HASH(0x2916bc8)->first_child('certificate')->field('altnames')
ssltest-certificate-expired = XML::Twig::Elt=HASH(0x2916bc8)->first_child('certificate')->field('expired')
Argument "heartbleed" isn't numeric in numeric ge (>=) at /usr/local/share/perl5/XML/Twig.pm line 6914.
ssltest-heartbleed-version = XML::Twig::Elt=HASH(0x2916d60)->att('sslversion')
ssltest-heartbleed-vulnerable = XML::Twig::Elt=HASH(0x2916d60)->att('vulnerable')
Argument "cipher" isn't numeric in numeric ge (>=) at /usr/local/share/perl5/XML/Twig.pm line 6914.
ssltest-cipher-status = XML::Twig::Elt=HASH(0x2916d60)->att('status')
ssltest-cipher-sslversion = XML::Twig::Elt=HASH(0x2916d60)->att('sslversion')
ssltest-cipher-bits = XML::Twig::Elt=HASH(0x2916d60)->att('bits')
ssltest-cipher-cipher = XML::Twig::Elt=HASH(0x2916d60)->att('cipher')
ssltest-cipher-id = XML::Twig::Elt=HASH(0x2916d60)->att('id')
ssltest-cipher-curve = XML::Twig::Elt=HASH(0x2916d60)->att('curve')
ssltest-cipher-ecdhebits = XML::Twig::Elt=HASH(0x2916d60)->att('ecdhebits')
Qu'ai je mal fait ? Si quelqu'un peux m'aider SVP

Cordialement
Franpom