Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file.name Field Missing From Root File Using Oneshot #294

Closed
ryanohoro opened this issue Jan 23, 2023 · 0 comments · Fixed by #295
Closed

file.name Field Missing From Root File Using Oneshot #294

ryanohoro opened this issue Jan 23, 2023 · 0 comments · Fixed by #295

Comments

@ryanohoro
Copy link
Collaborator

ryanohoro commented Jan 23, 2023

Describe the bug

When using oneshot, the filename of the provided file is not emitted in the returned Strelka event as part of the file object.

The proto for the various Go binaries and the main.go for oneshot show that the filename is being sent as part of the request. Strelka work() should be using this metadata to supply the name attribute of the File() object.

	req := structs.ScanFileRequest{
		Request: request,
		Attributes: &strelka.Attributes{
			Filename: *scanFile,
		},
		Chunk:  32768,
		Delay:  time.Second * 0,
		Delete: false,
	}

Steps to reproduce

 ./strelka-oneshot -l - -f src/python/strelka/tests/fixtures/test.html | jq
{
  "file": {
    "depth": 0,
    "flavors": {
      "mime": [
        "text/html"
      ],
      "yara": [
        "html_file"
      ]
    },
    "scanners": [
      "ScanEntropy",
      "ScanFooter",
      "ScanHash",
      "ScanHeader",
      "ScanHtml",
      "ScanYara"
    ],
    "size": 5875,
    "tree": {
      "node": "0d729ee4-9b2e-4a98-a2fa-84c1b2320961",
      "root": "0d729ee4-9b2e-4a98-a2fa-84c1b2320961"
    }
  },

Expected behavior

 ./strelka-oneshot -l - -f src/python/strelka/tests/fixtures/test.html | jq
{
  "file": {
    "depth": 0,
    "flavors": {
      "mime": [
        "text/html"
      ],
      "yara": [
        "html_file"
      ]
    },
    "scanners": [
      "ScanEntropy",
      "ScanFooter",
      "ScanHash",
      "ScanHeader",
      "ScanHtml",
      "ScanYara"
    ],
    name: "src/python/strelka/tests/fixtures/test.html",
    "size": 5875,
    "tree": {
      "node": "0d729ee4-9b2e-4a98-a2fa-84c1b2320961",
      "root": "0d729ee4-9b2e-4a98-a2fa-84c1b2320961"
    }
  },

Screenshots

Release

  • Release: 0.22.12.08

Additional context

Each Go client sends requests to Redis. When Requests reach Redis, frontend takes the requests and adds them as tasks inside Redis for the backend to handle.

frontend should be modifying the tasks to include a json encoded attributes object with all of the request metadata, and work() should be attempting to deserialize the json metadata.

main.go

+	requestInfo, err := json.Marshal(em["request"])
+	if err != nil {
+		return err
+	}

	if err := s.coordinator.cli.ZAdd(
		stream.Context(),
		"tasks",
		&redis.Z{
			Score:  float64(deadline.Unix()),
-			Member: id,
+			Member: requestInfo,
		},
	).Err(); err != nil {
		return err

strelka.py

            # Get request metadata and Redis context deadline UNIX timestamp
            (task_item, expire_at) = task[0]
            try:
                task_info = json.loads(task_item)
            except json.JSONDecodeError:
                root_id = task_item.decode()
                # Create new file object for task, use the request root_id as the pointer
                file = File(pointer=root_id)
            else:
                root_id = task_info["id"]
                try:
                    file = File(pointer=root_id, name=task_info["attributes"]["filename"])
                except KeyError as ex:
                    logging.debug(f"No filename attached (error: {ex}) to request: {task_item}")
                    file = File(pointer=root_id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant