Possible cookie problem / access to chart2.php from Powershell v7 in Zabbix v6 LTS

137 views Asked by At

we are using Zabbix version 5 LTS and have reporting through Powershell which, among others, retrieve graphs as PNG files. Basically, we are authenticating on Zabbix server like this (we used this, but customized, script: https://gist.github.com/r-plus/0a2a4abd6c24eb647846)

$authJSON = $baseJSON.clone();
$authJSON.method = "user.login";`
$authJSON.params = @{ "user" = $zabbixServerUsernameInput; "password"=$zabbixServerPasswordInput };`
$login = Invoke-RestMethod -Uri $zabbixServerApiUrl -Body ($authJSON | ConvertTo-Json) -method POST -ContentType "application/json";``

and then use $login.result as cookie in session

$zabbixDomain = $zabbixServerUrl;`
$session = New-Object -TypeName Microsoft.PowerShell.Commands.WebRequestSession;`
$cookie = New-Object -TypeName System.Net.Cookie;`
$cookie.Name = "zbx_sessionid";`
$cookie.Value = $login.result;`
$session.Cookies.Add($zabbixDomain, $cookie);`

This session works OK when accessing graph URL, for example

Invoke-WebRequest -Uri http://IP-ADDRESS/zabbix/chart2.php?...ight=100&legen d=0&from=now-30d&to=now&profileIdx=web.graphs.filter -WebSession $session -Outfile $graphCurrentFile;`

When accessing graph URL with this session parameter, it is visible that new cookie is created (PHPSESSID) and everything works OK. This works fine in Zabbix 5 LTS. This does not work in Zabbix 6 LTS. In v6 we are getting "You are not logged in" response when accessing graph URL.

When looking at cookies in v5, we have this (this works):

$session.Cookies.GetCookies("http://IP-ADDRESS/zabbix")`

Comment :
CommentUri :
HttpOnly : True
Discard : False
Domain : IP-ADDRESS
Expired : False
Expires : 1.1.0001. 0:00:00
Name : zbx_sessionid
Path : /zabbix
Port :
Secure : False
TimeStamp : 12.7.2023. 11:18:24
Value : 5522f93476ba60eed3263ffb67eb22e
Version : 0

Comment :
CommentUri :
HttpOnly : True
Discard : False
Domain : IP-ADDRESS
Expired : False
Expires : 1.1.0001. 0:00:00
Name : PHPSESSID
Path : /zabbix
Port :
Secure : False
TimeStamp : 12.7.2023. 9:51:14
Value : sh5h52fgthz7qf5iiq03vp3f8f
Version : 0

When looking at cookies in v6, we have this (this does not work):

$session.Cookies.GetCookies("http://IP-ADDRESS/zabbix")`


Comment :
CommentUri :
HttpOnly : False
Discard : False
Domain : IP-ADDRESS
Expired : False
Expires : 1.1.0001. 0:00:00
Name : zbx_sessionid
Path : /zabbix
Port :
Secure : False
TimeStamp : 12.7.2023. 12:38:42
Value : 39dafb464rft76299b7947ef9960497e
Version : 0

Comment :
CommentUri :
HttpOnly : True
Discard : False
Domain : IP-ADDRESS
Expired : False
Expires : 1.1.0001. 0:00:00
Name : zbx_session
Path : /zabbix
Port :
Secure : False
TimeStamp : 12.7.2023. 12:38:54
Value : eyJzZXNzaW9uaWQiOiI5YTMzftgrhZmZjA0OWVkNWZiMzMyMT ZjZTllYmE5ZiIsInNpZ24iOiIzYThhOGdrtbmkmI0ODczYmJl NjBkMmM5NjNkOGE1ODM1MzI4NGU5Y2EzY412OWRmYWRlNDQxMz FmYjc1NWY5In0%3D
Version : 0

Tried everything. At the end it looks to me that problem is with cookie format in versions 5 and 6, I am not sure. Documentation says that v6 uses cookie "stored as JSON encoded by base64", and v5 "a 32 character string". I did not succeed to convert this long cookie value from base64 in cookie Powershell (v7) can use in Invoke-WebRequest, and I am not even sure is that problem.

So, my question at the end

does anyone have solution to access zabbix 6 graph URL (eg http://IP-ADDRESS/zabbix/chart2.php?graphid=3004) from Powershell and authenticate any way (if not possible with cookie, then with user/password ...) and retrieve PNG. any suggestions are welcome

Thank you Goran​

Tried: generate cookie for graph session only change cookie for API session for graph URL update Powershell on 7.3.5

0

There are 0 answers