invoke-webrequest with js that sets custom header
I'm hoping for some ideas to move forward on a script I am writing involving invoke-webrequest. Hopefully this isn't too far out of scope for r/powershell.
https://admin.zscalerone.net/ is setting a custom header 'ZS_CUSTOM_CODE'
before logging in that header gets attached to the login POST.
This 'ZS_CUSTOM_CODE' header is set before logging in somehow and it is some sort of obfuscation.
I can see references to 'ZS_CUSTOM_CODE' in main_224965.js once browsing to https://admin.zscalerone.net/
Their API does not include the method I am looking to use but the web does have it I just can't figure out how to get that header.
I have been POSTing to https://admin.zscalerone.net/zsapi/v1/authenticatedSession which succeeds but the POST that follows (watching chrome dev tools) includes this 'ZS_CUSTOM_CODE' header that I have figured out how to generate in powershell yet.
example code I have used to login, pulled from chrome dev tools and altered
$loginuri = "https://admin.zscalerone.net/zsapi/v1/authenticatedSession
$login = invoke-webrequest -uri $loginuri -method post -headers $headers -body $body -websession $session1
The following request to pull the data I want returns this:
{"message":"Unauthorized resource Access"}
Which I believe is because of that missing 'ZS_CUSTOM_CODE' header.
For reference they detail their API usage and their authentication does a basic obfuscation here https://help.zscaler.com/zia/api-getting-started#CreateSession which I have used to access their official API.
This may be too much to ask of someone and too much of a javascript question so I can remove and try posting somewhere else if needed. More simply I could ask how to run a js script with powershell and get a set header value returned from it I guess.
Posted Apr 29, 2020, 8:22 PM UTC
Those API docs make it look like you just need to make a PowerShell version of that
obfuscateApiKey()they have examples of in various languages. You send that plus credentials and a timestamp in the body of your authenticatedSession POST and get back a standard session cookie that you can save and use for subsequent calls.Thanks for the input. I have made a powershell version of the obfuscation and that works for the official API. I'm trying to use the web, an unsupported api call that is not in the docs and thought the js that loads on the page listed is doing another undocumented obfuscation to create ZS_CUSTOM_CODE