

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

# Usa Network Firewall per acquisire i nomi di dominio DNS dall'Indicazione del nome del server per il traffico in uscita
<a name="use-network-firewall-to-capture-the-dns-domain-names-from-the-server-name-indication-sni-for-outbound-traffic"></a>

*Kirankumar Chandrashekar, Amazon Web Services*

## Riepilogo
<a name="use-network-firewall-to-capture-the-dns-domain-names-from-the-server-name-indication-sni-for-outbound-traffic-summary"></a>

Questo modello mostra come utilizzare AWS Network Firewall per raccogliere i nomi di dominio DNS forniti dalla Server Name Indication (SNI) nell'intestazione HTTPS del traffico di rete in uscita. Network Firewall è un servizio gestito che semplifica l'implementazione di protezioni di rete critiche per Amazon Virtual Private Cloud (Amazon VPC), inclusa la possibilità di proteggere il traffico in uscita con un firewall che blocca i pacchetti che non soddisfano determinati requisiti di sicurezza. La protezione del traffico in uscita verso nomi di dominio DNS specifici si chiama filtro in uscita, che consiste nel monitorare e potenzialmente limitare il flusso di informazioni in uscita da una rete all'altra.

Dopo aver acquisito i dati SNI che passano attraverso Network Firewall, puoi utilizzare Amazon CloudWatch Logs e AWS Lambda per pubblicare i dati su un argomento Amazon Simple Notification Service (Amazon SNS) che genera notifiche e-mail. Le notifiche e-mail includono il nome del server e altre informazioni SNI pertinenti. Inoltre, è possibile utilizzare l'output di questo pattern per consentire o limitare il traffico in uscita in base al nome di dominio nell'SNI utilizzando le regole del firewall. Per ulteriori informazioni, consulta [Lavorare con gruppi di regole stateful in AWS Network Firewall nella documentazione](https://docs.aws.amazon.com/network-firewall/latest/developerguide/stateful-rule-groups-ips.html) di Network Firewall.

## Prerequisiti e limitazioni
<a name="use-network-firewall-to-capture-the-dns-domain-names-from-the-server-name-indication-sni-for-outbound-traffic-prereqs"></a>

**Prerequisiti**
+ Un account AWS attivo.
+ [AWS Command Line Interface (AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html)) versione 2, installata e configurata su Linux, macOS o Windows.
+ [Network Firewall](https://docs.aws.amazon.com/network-firewall/latest/developerguide/getting-started.html), configurato e configurato in Amazon VPC e utilizzato per ispezionare il traffico in uscita. È possibile configurare Network Firewall per utilizzare una delle seguenti configurazioni VPC:
  + [Architettura semplice a zona singola con un gateway Internet](https://docs.aws.amazon.com/network-firewall/latest/developerguide/arch-single-zone-igw.html)
  + [Architettura multizona con un gateway Internet](https://docs.aws.amazon.com/network-firewall/latest/developerguide/arch-two-zone-igw.html)
  + [Architettura con un gateway Internet e un gateway NAT](https://docs.aws.amazon.com/network-firewall/latest/developerguide/arch-igw-ngw.html)

## Architecture
<a name="use-network-firewall-to-capture-the-dns-domain-names-from-the-server-name-indication-sni-for-outbound-traffic-architecture"></a>

Il diagramma seguente mostra come utilizzare Network Firewall per raccogliere dati SNI dal traffico di rete in uscita e quindi pubblicare tali dati su un argomento SNS utilizzando CloudWatch Logs e Lambda.

![\[Flusso di lavoro tra Network Firewall, CloudWatch Logs, Lambda e Amazon SNS.\]](http://docs.aws.amazon.com/it_it/prescriptive-guidance/latest/patterns/images/pattern-img/9eb1e9e3-f459-4ea3-8e6d-60fec6b7ea98/images/1094b5f6-33e3-42bc-8fb8-7409b5b826b0.png)


Il diagramma mostra il flusso di lavoro seguente:

1. Network Firewall raccoglie i nomi di dominio dai dati SNI nell'intestazione HTTPS del traffico di rete in uscita.

1. CloudWatch Logs monitora i dati SNI e richiama una funzione Lambda ogni volta che il traffico di rete in uscita passa attraverso Network Firewall.

1. La funzione Lambda legge i dati SNI acquisiti da CloudWatch Logs e quindi li pubblica su un argomento SNS.

1. L'argomento SNS ti invia una notifica e-mail che include i dati SNI.

**Automazione e scalabilità**
+ Puoi usare [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html) per creare questo modello utilizzando l'[infrastruttura come codice](https://docs.aws.amazon.com/whitepapers/latest/introduction-devops-aws/infrastructure-as-code.html).

**Stack tecnologico**
+  CloudWatch Registri Amazon
+ Amazon SNS
+ Amazon VPC
+ AWS Lambda 
+ AWS Network Firewall

## Tools (Strumenti)
<a name="use-network-firewall-to-capture-the-dns-domain-names-from-the-server-name-indication-sni-for-outbound-traffic-tools"></a>

**Servizi AWS**
+ [Amazon CloudWatch Logs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html): puoi utilizzare Amazon CloudWatch Logs per monitorare, archiviare e accedere ai tuoi file di log da istanze Amazon Elastic Compute Cloud (Amazon EC2), CloudTrail AWS, Amazon Route 53 e altre fonti.
+ [Amazon SNS — Amazon Simple](https://docs.aws.amazon.com/sns/latest/dg/welcome.html) Notification Service (Amazon SNS) è un servizio gestito che fornisce il recapito dei messaggi dagli editori agli abbonati (noti anche come produttori e consumatori).
+ [Amazon VPC](https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html): Amazon Virtual Private Cloud (Amazon VPC) fornisce una sezione logicamente isolata del cloud AWS in cui è possibile avviare le risorse AWS in una rete virtuale definita dall'utente. Questa rete virtuale è simile a una comune rete da gestire all'interno del proprio data center, ma con i vantaggi dell'infrastruttura scalabile di AWS.
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html): AWS Lambda è un servizio di elaborazione che consente di eseguire codice senza effettuare il provisioning o la gestione di server.
+ [AWS Network Firewall](https://docs.aws.amazon.com/network-firewall/latest/developerguide/what-is-aws-network-firewall.html): AWS Network Firewall è un servizio gestito che semplifica l'implementazione delle protezioni di rete essenziali per tutto il tuo Amazon. VPCs

## Epiche
<a name="use-network-firewall-to-capture-the-dns-domain-names-from-the-server-name-indication-sni-for-outbound-traffic-epics"></a>

### Creare un gruppo di CloudWatch log per Network Firewall
<a name="create-a-cloudwatch-log-group-for-network-firewall"></a>


| Operazione | Description | Competenze richieste | 
| --- | --- | --- | 
| Crea un gruppo di CloudWatch log. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/it_it/prescriptive-guidance/latest/patterns/use-network-firewall-to-capture-the-dns-domain-names-from-the-server-name-indication-sni-for-outbound-traffic.html)Per ulteriori informazioni, consulta [Lavorare con gruppi di log e flussi](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/Working-with-log-groups-and-streams.html) di log nella CloudWatch documentazione. | Amministratore cloud | 

### Crea un argomento e un abbonamento SNS
<a name="create-an-sns-topic-and-subscription"></a>


| Operazione | Description | Competenze richieste | 
| --- | --- | --- | 
| Creare un argomento SNS. | Per creare un argomento SNS, segui le istruzioni nella documentazione di [Amazon SNS](https://docs.aws.amazon.com/sns/latest/dg/sns-create-topic.html#create-topic-aws-console). | Amministratore cloud | 
| Sottoscrivi un endpoint all'argomento SNS. | Per iscrivere un indirizzo e-mail come endpoint all'argomento SNS che hai creato, segui le istruzioni nella documentazione di [Amazon SNS](https://docs.aws.amazon.com/sns/latest/dg/sns-create-subscribe-endpoint-to-topic.html). [Per **Protocollo**, scegli Email/email-JSON.](https://docs.aws.amazon.com/sns/latest/dg/sns-email-notifications.html) Puoi anche scegliere un endpoint diverso in base alle tue esigenze. | Amministratore cloud | 

### Configurare la registrazione in Network Firewall
<a name="set-up-logging-in-network-firewall"></a>


| Operazione | Description | Competenze richieste | 
| --- | --- | --- | 
| Abilita la registrazione del firewall. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/it_it/prescriptive-guidance/latest/patterns/use-network-firewall-to-capture-the-dns-domain-names-from-the-server-name-indication-sni-for-outbound-traffic.html)Per ulteriori informazioni sull'utilizzo di CloudWatch Logs come destinazione di log per Network Firewall, consulta [Amazon CloudWatch Logs nella documentazione](https://docs.aws.amazon.com/network-firewall/latest/developerguide/logging-cw-logs.html) di Network Firewall.  | Amministratore cloud | 

### Imposta una regola statica in Network Firewall
<a name="set-up-a-stateful-rule-in-network-firewall"></a>


| Operazione | Description | Competenze richieste | 
| --- | --- | --- | 
| Crea una regola statica. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/it_it/prescriptive-guidance/latest/patterns/use-network-firewall-to-capture-the-dns-domain-names-from-the-server-name-indication-sni-for-outbound-traffic.html) | Amministratore cloud | 
| Associa la regola stateful a Network Firewall. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/it_it/prescriptive-guidance/latest/patterns/use-network-firewall-to-capture-the-dns-domain-names-from-the-server-name-indication-sni-for-outbound-traffic.html) | Amministratore cloud | 

### Crea una funzione Lambda per leggere i log
<a name="create-a-lambda-function-to-read-the-logs"></a>


| Operazione | Description | Competenze richieste | 
| --- | --- | --- | 
| Crea il codice per la funzione Lambda. | In un ambiente di sviluppo integrato (IDE) in grado di leggere l'evento CloudWatch Logs di Network Firewall per il traffico in uscita, incolla il seguente codice Python 3 e `<SNS-topic-ARN>` sostituiscilo con il tuo valore:<pre>import json<br />import gzip<br />import base64<br />import boto3<br />sns_client = boto3.client('sns')<br />def lambda_handler(event, context):<br />    decoded_event = json.loads(gzip.decompress(base64.b64decode(event['awslogs']['data'])))<br />    body = '''<br />    {filtermatch}<br />    '''.format(<br />        loggroup=decoded_event['logGroup'],<br />        logstream=decoded_event['logStream'],<br />        filtermatch=decoded_event['logEvents'][0]['message'],<br />    )<br />    print(body)<br />    filterMatch = json.loads(body)<br />    data = []<br />    if 'http' in filterMatch['event']:<br />        data.append(filterMatch['event']['http']['hostname'])<br />    elif 'tls' in filterMatch['event']:<br />        data.append(filterMatch['event']['tls']['sni'])<br />    result = 'Domain accessed ' + 1*' ' + (data[0]) + 1*' ' 'via AWS Network Firewall ' + 1*' '  + (filterMatch['firewall_name'])<br />    print(result)<br />    message = {'ServerName': result}<br />    send_to_sns = sns_client.publish(<br />        TargetArn=<SNS-topic-ARN>,          #Replace with the SNS topic ARN<br />        Message=json.dumps({'default': json.dumps(message),<br />                        'sms': json.dumps(message),<br />                        'email': json.dumps(message)}),<br />        Subject='Server Name passed through the Network Firewall',<br />        MessageStructure='json'<br />    )</pre>Questo esempio di codice analizza il contenuto dei CloudWatch Logs e acquisisce il nome del server fornito da SNI nell'intestazione HTTPS. | Sviluppatore di app | 
| Creazione della funzione Lambda | ****Per creare la funzione Lambda, segui le istruzioni nella documentazione di [Lambda e](https://docs.aws.amazon.com/lambda/latest/dg/getting-started.html#getting-started-create-function) scegli Python 3.9 for Runtime.**** | Amministratore cloud | 
| Aggiungi il codice alla funzione Lambda. | [Per aggiungere il codice Python alla funzione Lambda creata in precedenza, segui le istruzioni nella documentazione di Lambda.](https://docs.aws.amazon.com/lambda/latest/dg/configuration-function-zip.html#configuration-function-update) | Amministratore cloud | 
| Aggiungi CloudWatch i log come trigger alla funzione Lambda. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/it_it/prescriptive-guidance/latest/patterns/use-network-firewall-to-capture-the-dns-domain-names-from-the-server-name-indication-sni-for-outbound-traffic.html)Per ulteriori informazioni, consulta [Using Lambda with CloudWatch Logs](https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchlogs.html) nella documentazione di Lambda. | Amministratore cloud | 
| Aggiungi le autorizzazioni di pubblicazione SNS. | Aggiungi l'autorizzazione **SNS:Publish** al ruolo di esecuzione Lambda, in modo che Lambda possa effettuare chiamate API per pubblicare messaggi su SNS.  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/it_it/prescriptive-guidance/latest/patterns/use-network-firewall-to-capture-the-dns-domain-names-from-the-server-name-indication-sni-for-outbound-traffic.html)<pre>{<br />    "Version": "2012-10-17",		 	 	 <br />    "Statement": [<br />        {<br />            "Sid": "AllowSNSPublish",<br />            "Effect": "Allow",<br />            "Action": [<br />                "sns:GetTopicAttributes",<br />                "sns:Subscribe",<br />                "sns:Unsubscribe",<br />                "sns:Publish"<br />            ],<br />            "Resource": "*"<br />        }<br />    ]<br />}</pre> | Amministratore del cloud | 

### Verifica la funzionalità della tua notifica SNS
<a name="test-the-functionality-of-your-sns-notification"></a>


| Operazione | Description | Competenze richieste | 
| --- | --- | --- | 
| Invia traffico tramite Network Firewall. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/it_it/prescriptive-guidance/latest/patterns/use-network-firewall-to-capture-the-dns-domain-names-from-the-server-name-indication-sni-for-outbound-traffic.html)<pre>{<br />    "Type": "Notification",<br />    "MessageId": "<messageID>",<br />    "TopicArn": "arn:aws:sns:us-west-2:123456789:testSNSTopic",<br />    "Subject": "Server Name passed through the Network Firewall",<br />    "Message": "{\"ServerName\": \"Domain 'aws.amazon.com' accessed via AWS Network Firewall 'AWS-Network-Firewall-Multi-AZ-firewall\"}",<br />    "Timestamp": "2022-03-22T04:10:04.217Z",<br />    "SignatureVersion": "1",<br />    "Signature": "<Signature>",<br />    "SigningCertURL": "<SigningCertUrl>",<br />    "UnsubscribeURL": "<UnsubscribeURL>"<br />}</pre>Quindi, controlla il registro degli avvisi di Network Firewall in Amazon CloudWatch seguendo le istruzioni nella [ CloudWatch documentazione di Amazon](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/SearchDataFilterPattern.html). Il registro degli avvisi mostra il seguente output:<pre>{<br />    "firewall_name": "AWS-Network-Firewall-Multi-AZ-firewall",<br />    "availability_zone": "us-east-2b",<br />    "event_timestamp": "<event timestamp>",<br />    "event": {<br />        "timestamp": "2021-03-22T04:10:04.214222+0000",<br />        "flow_id": <flow ID>,<br />        "event_type": "alert",<br />        "src_ip": "10.1.3.76",<br />        "src_port": 22761,<br />        "dest_ip": "99.86.59.73",<br />        "dest_port": 443,<br />        "proto": "TCP",<br />        "alert": {<br />            "action": "allowed",<br />            "signature_id": 2,<br />            "rev": 0,<br />            "signature": "",<br />            "category": "",<br />            "severity": 3<br />        },<br />        "tls": {<br />            "subject": "CN=aws.amazon.com",<br />            "issuerdn": "C=US, O=Amazon, OU=Server CA 1B, CN=Amazon",<br />            "serial": "<serial number>",<br />            "fingerprint": "<fingerprint ID>",<br />            "sni": "aws.amazon.com",<br />            "version": "TLS 1.2",<br />            "notbefore": "2020-09-30T00:00:00",<br />            "notafter": "2021-09-23T12:00:00",<br />            "ja3": {},<br />            "ja3s": {}<br />        },<br />        "app_proto": "tls"<br />    }<br />}</pre> | Tecnico collaudatore | 