Activar Application & API Protection para .NET

Este producto no es compatible con el sitio Datadog seleccionado. ().

Puedes monitorizar la seguridad de las aplicaciones .NET que se ejecutan en Docker, Kubernetes, Amazon ECS y AWS Fargate.

Prerequisites

Activar Application & API Protection

Para empezar

  1. Actualiza la biblioteca .NET de Datadog al menos a la versión 2.2.0 (o a la versión 2.16.0 para las funciones de detección del análisis de composición de software) para la arquitectura del sistema operativo de destino.

    Para comprobar que las versiones del lenguaje y del marco de trabajo de tu servicio son compatibles con las funciones de Application & API Protection, consulta Compatibilidad.

  2. Habilita Application & API Protection configurando las variables de entorno. Para un uso exclusivo de seguridad sin rastreo de APM, configura DD_APPSEC_ENABLED=true y DD_APM_TRACING_ENABLED=false. Por ejemplo, en Windows autoalojado, ejecuta el siguiente fragmento de PowerShell como parte del script de inicio de tu aplicación:

    $target=[System.EnvironmentVariableTarget]::Process
    [System.Environment]::SetEnvironmentVariable("DD_APPSEC_ENABLED","true",$target)
    [System.Environment]::SetEnvironmentVariable("DD_APM_TRACING_ENABLED","false",$target)
    

    O uno de los siguientes métodos, dependiendo de dónde se ejecute la aplicación:

    En una consola de Windows:

    rem Set environment variables
    SET CORECLR_ENABLE_PROFILING=1
    SET CORECLR_PROFILER={846F5F1C-F9AE-4B07-969E-05C26BC060D8}
    SET DD_APPSEC_ENABLED=true
    SET DD_APM_TRACING_ENABLED=false
    
    rem Start application
    dotnet.exe example.dll
    

    Ejecuta el siguiente comando de PowerShell como administrador para configurar las variables de entorno necesarias en el registro HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment y reinicia IIS.

    $target=[System.EnvironmentVariableTarget]::Machine
    [System.Environment]::SetEnvironmentVariable("DD_APPSEC_ENABLED","true",$target)
    [System.Environment]::SetEnvironmentVariable("DD_APM_TRACING_ENABLED","false",$target)
    net stop was /y
    net start w3svc
    

    O, para servicios de IIS exclusivamente, en WAS y W3SVC con PowerShell como administrador, ejecuta:

    $appsecPart = "DD_APPSEC_ENABLED=true DD_APM_TRACING_ENABLED=false"
    [string[]] $defaultvariable = @("CORECLR_ENABLE_PROFILING=1", "CORECLR_PROFILER={846F5F1C-F9AE-4B07-969E-05C26BC060D8}", $appsecPart)
    
    function Add-AppSec {
    
        param (
            $path
        )
        $v = (Get-ItemProperty -Path $path).Environment
        If ($v -eq $null) {
            Set-ItemProperty -Path $path -Name "Environment" -Value $defaultvariable
        }
        ElseIf (-not ($v -match $appsecPart)) {
            $v += " " + $appsecPart;
            Set-ItemProperty -Path $path -Name "Environment" -Value $v
        }
    }
    Add-AppSec -path "HKLM:SYSTEM\CurrentControlSet\Services\WAS\"
    Add-AppSec -path "HKLM:SYSTEM\CurrentControlSet\Services\W3SVC\"
    
    net stop was /y
    net start w3svc
    

    Or, to avoid editing registry keys, edit the application settings in the web.config file of your application:

    <configuration>
      <appSettings>
            <add key="DD_APPSEC_ENABLED" value="true"/>
            <add key="DD_APM_TRACING_ENABLED" value="false"/>
      </appSettings>
    </configuration>
    

    Esto también puede hacerse a nivel de grupo de aplicaciones de IIS en el archivo applicationHost.config, normalmente en C:\Windows\System32\inetsrv\config\:

    <system.applicationHost>
    
        <applicationPools>
            <add name="DefaultAppPool">
                <environmentVariables>
                    <add name="DD_APPSEC_ENABLED" value="true" />
                    <add name="DD_APM_TRACING_ENABLED" value="false" />
                </environmentVariables>
                (...)
    

    Añade lo siguiente a la configuración de tu aplicación:

    DD_APPSEC_ENABLED=true
    DD_APM_TRACING_ENABLED=false
    

    Actualiza tu contenedor de configuración para APM añadiendo los siguientes argumentos en tu comando docker run:

    docker run [...] -e DD_APPSEC_ENABLED=true -e DD_APM_TRACING_ENABLED=false [...]
    

    Añade los siguientes valores de variable de entorno a tu archivo de contenedor de Docker:

    ENV DD_APPSEC_ENABLED=true
    ENV DD_APM_TRACING_ENABLED=false
    

    Actualiza tu archivo de configuración de despliegue para APM y añade las variables de entorno de Application & API Protection:

    spec:
      template:
        spec:
          containers:
            - name: <CONTAINER_NAME>
              image: <CONTAINER_IMAGE>/<TAG>
              env:
                - name: DD_APPSEC_ENABLED
                  value: "true"
                - name: DD_APM_TRACING_ENABLED
                  value: "false"
    

    Actualiza tu archivo JSON de definición de tareas de ECS, añadiendo esto en la sección de entorno:

    "environment": [
      ...,
      {
        "name": "DD_APPSEC_ENABLED",
        "value": "true"
      },
      {
        "name": "DD_APM_TRACING_ENABLED",
        "value": "false"
      }
    ]
    

    Añade las siguientes líneas a tu archivo de contenedor de Docker:

    ENV DD_APPSEC_ENABLED=true
    ENV DD_APM_TRACING_ENABLED=false
    
  3. Reinicia la aplicación deteniéndola por completo y volviéndola a iniciar.

    After this configuration is complete, the library collects security data from your application and sends it to the Agent. The Agent sends the data to Datadog, where out-of-the-box detection rules flag attacker techniques and potential misconfigurations so you can take steps to remediate.

  4. To see App and API Protection threat detection in action, send known attack patterns to your application. For example, trigger the Security Scanner Detected rule by running a file that contains the following curl script:

    for ((i=1;i<=250;i++)); 
    do
    # Target existing service's routes
    curl https://your-application-url/existing-route -A dd-test-scanner-log;
    # Target non existing service's routes
    curl https://your-application-url/non-existing-route -A dd-test-scanner-log;
    done

    Note: The dd-test-scanner-log value is supported in the most recent releases.

    A few minutes after you enable your application and send known attack patterns to it, threat information appears in the Application Signals Explorer and vulnerability information appears in the Vulnerabilities explorer.

Referencias adicionales