79720968

Date: 2025-07-31 08:05:20
Score: 1
Natty:
Report link

# PowerShell Script to Extract SSL Certificate from a Remote Server (LDAPS)

# Define server and port

$server = "fggg"

$port = 636

# Connect and retrieve the certificate

$tcpClient = New-Object System.Net.Sockets.TcpClient

$tcpClient.Connect($server, $port)

$sslStream = New-Object System.Net.Security.SslStream($tcpClient.GetStream(), $false, ({$true}))

$sslStream.AuthenticateAsClient($server)

# Export the certificate

$remoteCert = $sslStream.RemoteCertificate

$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 $remoteCert

$certPath = "$env:USERPROFILE\Desktop\$server.cer"

[System.IO.File]::WriteAllBytes($certPath, $cert.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Cert))

# Clean up

$sslStream.Close()

$tcpClient.Close()

Write-Host "Certificate saved to Desktop: $certPath"

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Vamshikrishna Gaade