shellbags: make the registry traversal injectable so the malformed-record recovery path is testable

未关闭
#9,359 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
48/100
Issue 类型
重构
描述清晰度
基本清楚
活跃度
活跃
技术栈
cpp

调研方向

Start in the shellbags traversal: parseShellbags() and parseRegistry() call queryKey() directly, and parseShellData() is where the malformed-record exception is thrown. Thread a QueryKeyFunc through both, with genShellbags() passing the real queryKey and an empty function falling back to it. Done when a test with an injected layout (valid parent, malformed child, valid sibling) shows the sibling row present, the child and its descendants absent, and the sibling path correct.

由索引模型根据 Issue 内容生成。

描述

test virtual tables Windows
Context

During the #9286 review, @mike-myers-aapl approved with a note inviting a follow-up: the malformed-record recovery added in that PR (the try/catch around parseShellData with build_shellbag.resize(depth) + continue) is untested, because parseShellbags()/parseRegistry() call queryKey() against the live registry — a regression test that actually fails without the recovery would first need the traversal to take an injectable key source.

Why the recovery path matters

parseShellbags() recurses over registry keys; for each key it calls parseShellData() on attacker-controlled record bytes and then recurses into the child path. The recovery added in #9286 means a malformed record must (a) not abort the whole shellbags query, (b) not leave a partial path behind for its descendants, and (c) let siblings keep the correct path (build_shellbag.resize(depth) runs before continue, and the recursion is inside the try). None of that is currently exercised by a test.

Proposed design

Thread a key-source function through the traversal:

using QueryKeyFunc = std::function<void(const std::string& path, QueryData& results)>;

void parseShellbags(const std::string& path,
                    std::vector<std::string>& build_shellbag,
                    QueryData& results,
                    const std::string& sid,
                    const std::string& source,
                    const QueryKeyFunc& query_key_func);

void parseRegistry(const std::string& full_path,
                   const std::string& sid,
                   QueryData& results,
                   const std::string& source,
                   const QueryKeyFunc& query_key_func);

genShellbags() passes the real queryKey; an empty QueryKeyFunc falls back to it, so existing callers are unchanged. guidLookup() keeps hitting the live registry — in a test its misses fall back to the GUID string via guidNameOrSentinel(), which is harmless for traversal assertions.

The regression test this unlocks

An injected key source returns a controlled layout: a valid parent (a real shellbag record, e.g. the network-share record the existing shellitem tests use), a malformed child whose parseShellData() throws (a nonempty record shorter than four characters, per the review discussion), and a valid sibling. Assertions:

  1. traversal continues past the malformed child (the sibling's row exists);
  2. the malformed child contributes no row and its descendants are skipped;
  3. the sibling's path contains exactly the expected parent and sibling components (the depth restoration held).

Without the #9286 recovery the thrown exception escapes the traversal and the assertions cannot pass, so the test genuinely fails on the pre-fix code.

Happy to take this up as a follow-up PR if the shape works for maintainers — or to adapt to a different injection style (template parameter, keyed interface class) if that fits the codebase better.

主要语言
C++
星标
23.8k
派生
2.7k
平均合并
6 天 11 小时
30 天内合并 PR
69

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

osquery/osquery 的其他 Issue

查看 osquery/osquery 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。