Access web service behind Citrix NetScaler

241 Views Asked by At

I'm having an internal .NET web service which I try to access from the public network.

If using a browser, a user may enter login and passwd in a form on the Citrix NetScaler custom page and after the form is submitted, the browsing continues and the web service endpoint is working with no issues.

I don't know anything about Citrix NetScaler, but by checking the network calls in the browser's dev tools, I was able to get to the web service by using PowerShell and the a Microsoft.PowerShell.Commands.WebRequestSession object:

$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession

$cookie = New-Object System.Net.Cookie 
$cookie.Name = "NSC_TASS"
$cookie.Value = "https://REST_SERVICE_DOMAIN/api/"
$cookie.Domain = "CITRIX_NETSCALER_DOMAIN.com"
$session.Cookies.Add($cookie);

$response = Invoke-WebRequest -Uri "https://CITRIX_NETSCALER_DOMAIN/cgi/login" `
    -Method "POST" `
    -Headers @{"Content-Type"="application/x-www-form-urlencoded"} `
    -Body "login=URL_ENCODED_EMAIL&passwd=URLENCODED_PASSWORD" `
    -WebSession $session

Is there a way to login by not using PowerShell's Microsoft.PowerShell.Commands.WebRequestSession object? Do I use the right endpoint?

EDIT: I'm looking for a solution which doesn't involve PowerShell, but it only relies on HTTP headers and cookies

1

There are 1 best solutions below

2
apollosoftware.org On

I think you may be able to do -SessionVariable with Invoke-WebRequest, and then append the cookies a similar way.

Invoke-WebRequest https://CITRIX_NETSCALER_DOMAIN/cgi/login -SessionVariable session
...
$session.Cookies.Add($cookie);