I reacord a ZEST script as below for ZAP authentication, I want to modify the script, save the "ts" value to a variable, and use it in "csrfToken"Ā field.
But from Windows ZAP GUI, Add Zest Assignment, I can't find a way to do this.
{
Ā "about": "This is a Zest script. For more details about Zest visit
https://github.com/zaproxy/zest/",
Ā "zestVersion": "0.8",
Ā "title": "chtlogin4",
Ā "description": "",
Ā "prefix": "",
Ā "type": "StandAlone",
Ā "parameters": {
Ā Ā "tokenStart": "{{",
Ā Ā "tokenEnd": "}}",
Ā Ā "tokens": {},
Ā Ā "elementType": "ZestVariables"
Ā },
Ā "statements": [
Ā Ā {
Ā Ā Ā "url": "
https://192.168.1.136/api/token",
Ā Ā Ā "data": "{\"method\":\"login\"}",
Ā Ā Ā "method": "POST",
Ā Ā Ā "headers": "Content-Type: application/x-www-form-urlencoded; charset\u003dUTF-8\r\nContent-Length: 18\r\nOrigin:
https://192.168.1.136\r\nSec-Fetch-Dest: empty\r\nSec-Fetch-Mode: cors\r\nSec-Fetch-Site: same-origin\r\n",
Ā Ā Ā "response": {
Ā Ā Ā Ā "url": "
https://192.168.1.136/api/token",
Ā Ā Ā Ā "headers": "HTTP/1.1 200 OK\r\nStrict-Transport-Security: max-age\u003d60\r\nCache-Control: no-cache,no-store\r\nPragma: no-cache\r\nExpires: 0\r\nX-Content-Type-Options: nosniff\r\nX-Content-Type-Options: nosniff\r\nX-Frame-Options: SAMEORIGIN\r\nX-XSS-Protection: 1; mode\u003dblock\r\nX-XSS-Protection: 1; mode\u003dblock\r\nContent-Type: application/json; charset\u003d\"UTF-8\"\r\nConnection: close\r\nContent-Security-Policy: frame-ancestors \u0027self\u0027\r\nContent-Length: 78\r\nDate: Thu, 10 Feb 2022 11:13:35 GMT\r\nServer: lighttpd/1.4.56\r\n\r\n",
Ā Ā Ā Ā "body": "{ \"code\": 0, \"wait\": 0, \"timestamp\": \"3838\", \"data\":
{ \"ts\": \"73463067427\" } }",Ā Ā Ā Ā "statusCode": 200,
Ā Ā Ā Ā "responseTimeInMs": 21,
Ā Ā Ā Ā "elementType": "ZestResponse"
Ā Ā Ā },
Ā Ā Ā "assertions": [
Ā Ā Ā Ā {
Ā Ā Ā Ā Ā "rootExpression": {
Ā Ā Ā Ā Ā Ā "code": 200,
Ā Ā Ā Ā Ā Ā "not": false,
Ā Ā Ā Ā Ā Ā "elementType": "ZestExpressionStatusCode"
Ā Ā Ā Ā Ā },
Ā Ā Ā Ā Ā "elementType": "ZestAssertion"
Ā Ā Ā Ā },
Ā Ā Ā Ā {
Ā Ā Ā Ā Ā "rootExpression": {
Ā Ā Ā Ā Ā Ā "length": 78,
Ā Ā Ā Ā Ā Ā "approx": 2,
Ā Ā Ā Ā Ā Ā "variableName": "response.body",
Ā Ā Ā Ā Ā Ā "not": false,
Ā Ā Ā Ā Ā Ā "elementType": "ZestExpressionLength"
Ā Ā Ā Ā Ā },
Ā Ā Ā Ā Ā "elementType": "ZestAssertion"
Ā Ā Ā Ā }
Ā Ā Ā ],
Ā Ā Ā "followRedirects": false,
Ā Ā Ā "timestamp": 1644491615854,
Ā Ā Ā "cookies": [],
Ā Ā Ā "index": 1,
Ā Ā Ā "enabled": true,
Ā Ā Ā "elementType": "ZestRequest"
Ā Ā },
Ā Ā {
Ā Ā Ā "url": "
https://192.168.1.136/api/login",
Ā Ā Ā "data": "u\u003dPVlXUnRhVzQ9MQ%3D%3D\u0026p\u003dYmNHRnpjM2R2Y21RPXc%3D",
Ā Ā Ā "method": "POST",
Ā Ā Ā "headers": "Content-Type: application/x-www-form-urlencoded; charset\u003dUTF-8\r\n
csrfToken: 73463067427\r\nContent-Length: 47\r\nOrigin:
https://192.168.1.136\r\nSec-Fetch-Dest: empty\r\nSec-Fetch-Mode: cors\r\nSec-Fetch-Site: same-origin\r\n",
Ā Ā Ā "response": {
Ā Ā Ā Ā "url": "
https://192.168.1.136/api/login",
Ā Ā Ā Ā "headers": "HTTP/1.1 200 OK\r\nStrict-Transport-Security: max-age\u003d60\r\nCache-Control: no-cache,no-store\r\nPragma: no-cache\r\nExpires: 0\r\nX-Content-Type-Options: nosniff\r\nX-Content-Type-Options: nosniff\r\nX-Frame-Options: SAMEORIGIN\r\nX-XSS-Protection: 1; mode\u003dblock\r\nX-XSS-Protection: 1; mode\u003dblock\r\nSet-Cookie: auth_tokens\u003daNV594IcHLwPSkKg; Path\u003d/; HttpOnly; SameSite\u003dStrict; Secure;\r\nContent-Type: application/json; charset\u003d\"UTF-8\"\r\nConnection: close\r\nContent-Security-Policy: frame-ancestors \u0027self\u0027\r\nContent-Length: 264\r\nDate: Thu, 10 Feb 2022 11:13:35 GMT\r\nServer: lighttpd/1.4.56\r\n\r\n",
Ā Ā Ā Ā "body": "{ \"code\": 0, \"wait\": 0, \"timestamp\": \"3838\", \"data\": { \"mac\": \"00:11:22:33:44:50\", \"version\": \"V1.0.0.26-Cloud_1229\", \"model_name\": \"CHT\", \"role\": \"Master\", \"lan_iface_num\": 2, \"triband_enable\": \"1\", \"username\": \"admin\", \"right\": 1, \"token\": \"aNV594IcHLwPSkKg\" } }",
Ā Ā Ā Ā "statusCode": 200,
Ā Ā Ā Ā "responseTimeInMs": 68,
Ā Ā Ā Ā "elementType": "ZestResponse"
Ā Ā Ā },
Ā Ā Ā "assertions": [
Ā Ā Ā Ā {
Ā Ā Ā Ā Ā "rootExpression": {
Ā Ā Ā Ā Ā Ā "code": 200,
Ā Ā Ā Ā Ā Ā "not": false,
Ā Ā Ā Ā Ā Ā "elementType": "ZestExpressionStatusCode"
Ā Ā Ā Ā Ā },
Ā Ā Ā Ā Ā "elementType": "ZestAssertion"
Ā Ā Ā Ā },
Ā Ā Ā Ā {
Ā Ā Ā Ā Ā "rootExpression": {
Ā Ā Ā Ā Ā Ā "length": 264,
Ā Ā Ā Ā Ā Ā "approx": 2,
Ā Ā Ā Ā Ā Ā "variableName": "response.body",
Ā Ā Ā Ā Ā Ā "not": false,
Ā Ā Ā Ā Ā Ā "elementType": "ZestExpressionLength"
Ā Ā Ā Ā Ā },
Ā Ā Ā Ā Ā "elementType": "ZestAssertion"
Ā Ā Ā Ā }
Ā Ā Ā ],
Ā Ā Ā "followRedirects": false,
Ā Ā Ā "timestamp": 1644491615896,
Ā Ā Ā "cookies": [],
Ā Ā Ā "index": 2,
Ā Ā Ā "enabled": true,
Ā Ā Ā "elementType": "ZestRequest"
Ā Ā },
Ā Ā {
Ā Ā Ā "url": "
https://192.168.1.136/api/info",
Ā Ā Ā "data": "",
Ā Ā Ā "method": "GET",
Ā Ā Ā "headers": "
csrfToken: 73463067427\r\nAuthorization: Bearer aNV594IcHLwPSkKg\r\nContent-Type: application/x-www-form-urlencoded; charset\u003dUTF-8\r\nSec-Fetch-Dest: empty\r\nSec-Fetch-Mode: cors\r\nSec-Fetch-Site: same-origin\r\n",
Ā Ā Ā "response": {
Ā Ā Ā Ā "url": "
https://192.168.1.136/api/info",
Ā Ā Ā Ā "headers": "HTTP/1.1 200 OK\r\nStrict-Transport-Security: max-age\u003d60\r\nCache-Control: no-cache,no-store\r\nPragma: no-cache\r\nExpires: 0\r\nX-Content-Type-Options: nosniff\r\nX-Content-Type-Options: nosniff\r\nX-Frame-Options: SAMEORIGIN\r\nX-XSS-Protection: 1; mode\u003dblock\r\nX-XSS-Protection: 1; mode\u003dblock\r\nContent-Type: application/json; charset\u003d\"UTF-8\"\r\nConnection: close\r\nContent-Security-Policy: frame-ancestors \u0027self\u0027\r\nContent-Length: 235\r\nDate: Thu, 10 Feb 2022 11:13:36 GMT\r\nServer: lighttpd/1.4.56\r\n\r\n",
Ā Ā Ā Ā "body": "{ \"code\": 0, \"wait\": 0, \"timestamp\": \"3838\", \"data\": { \"mac\": \"00:11:22:33:44:50\", \"version\": \"V1.0.0.26-Cloud_1229\", \"model_name\": \"CHT\", \"role\": \"Master\", \"lan_iface_num\": 2, \"triband_enable\": \"1\", \"username\": \"admin\", \"right\": 1 } }",
Ā Ā Ā Ā "statusCode": 200,
Ā Ā Ā Ā "responseTimeInMs": 33,
Ā Ā Ā Ā "elementType": "ZestResponse"
Ā Ā Ā },
Ā Ā Ā "assertions": [
Ā Ā Ā Ā {
Ā Ā Ā Ā Ā "rootExpression": {
Ā Ā Ā Ā Ā Ā "code": 200,
Ā Ā Ā Ā Ā Ā "not": false,
Ā Ā Ā Ā Ā Ā "elementType": "ZestExpressionStatusCode"
Ā Ā Ā Ā Ā },
Ā Ā Ā Ā Ā "elementType": "ZestAssertion"
Ā Ā Ā Ā },
Ā Ā Ā Ā {
Ā Ā Ā Ā Ā "rootExpression": {
Ā Ā Ā Ā Ā Ā "length": 235,
Ā Ā Ā Ā Ā Ā "approx": 2,
Ā Ā Ā Ā Ā Ā "variableName": "response.body",
Ā Ā Ā Ā Ā Ā "not": false,
Ā Ā Ā Ā Ā Ā "elementType": "ZestExpressionLength"
Ā Ā Ā Ā Ā },
Ā Ā Ā Ā Ā "elementType": "ZestAssertion"
Ā Ā Ā Ā }
Ā Ā Ā ],
Ā Ā Ā "followRedirects": false,
Ā Ā Ā "timestamp": 1644491615983,
Ā Ā Ā "cookies": [],
Ā Ā Ā "index": 3,
Ā Ā Ā "enabled": true,
Ā Ā Ā "elementType": "ZestRequest"
Ā Ā }
Ā ],
Ā "authentication": [],
Ā "index": 0,
Ā "enabled": true,
Ā "elementType": "ZestScript"
}