Module: PWN::Bounty::LifecycleAuthzReplay

Defined in:
lib/pwn/bounty/lifecycle_authz_replay.rb

Overview

YAML-driven helper for capturing lifecycle authz evidence across pre/post state transitions (e.g., collaborator removal, role change, project visibility flips) with report-ready artifacts.

Constant Summary collapse

DEFAULT_CHECKPOINTS =
%w[pre_change post_change_t0 post_change_tn].freeze
STATUS_VALUES =
%w[missing accessible denied error unknown].freeze

Class Method Summary collapse

Class Method Details

.authorsObject

Author(s)

0day Inc. <support@0dayinc.com>



242
243
244
245
246
# File 'lib/pwn/bounty/lifecycle_authz_replay.rb', line 242

public_class_method def self.authors
  "AUTHOR(S):
    0day Inc. <support@0dayinc.com>
  "
end

.finalize_run(opts = {}) ⇒ Object

Supported Method Parameters

summary = PWN::Bounty::LifecycleAuthzReplay.finalize_run(

run_obj: run_obj

)



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/pwn/bounty/lifecycle_authz_replay.rb', line 152

public_class_method def self.finalize_run(opts = {})
  run_obj = opts[:run_obj]
  raise 'run_obj is required' unless run_obj.is_a?(Hash)

  coverage_cells = run_obj[:coverage_matrix][:cells]
  missing_cells = coverage_cells.select { |cell| cell[:status] == 'missing' }
  stale_access_findings = find_stale_access_findings(run_obj: run_obj)

  summary = {
    run_id: run_obj[:run_id],
    completed_at: Time.now.utc.iso8601,
    campaign: run_obj[:plan][:campaign],
    totals: {
      checkpoints: run_obj[:plan][:checkpoints].length,
      actors: run_obj[:plan][:actors].length,
      surfaces: run_obj[:plan][:surfaces].length,
      cells: coverage_cells.length,
      captured_cells: coverage_cells.count { |cell| cell[:status] != 'missing' },
      missing_cells: missing_cells.length,
      stale_access_findings: stale_access_findings.length
    },
    stale_access_findings: stale_access_findings,
    missing_cells: missing_cells
  }

  write_json(path: File.join(run_obj[:run_root], 'SUMMARY.json'), obj: summary)
  write_report(run_obj: run_obj, summary: summary)

  summary
rescue StandardError => e
  raise e
end

.helpObject

Display Usage Information



250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/pwn/bounty/lifecycle_authz_replay.rb', line 250

public_class_method def self.help
  <<~HELP
    Usage:
      plan = PWN::Bounty::LifecycleAuthzReplay.load_plan(
        yaml_path: '/path/to/lifecycle_authz_replay.yaml'
      )

      run_obj = PWN::Bounty::LifecycleAuthzReplay.start_run(
        plan: plan,
        output_dir: '/tmp/evidence-bundles'
      )

      PWN::Bounty::LifecycleAuthzReplay.record_observation(
        run_obj: run_obj,
        checkpoint: 'post_change_t0',
        actor: 'revoked_user',
        surface: 'repo_settings_page',
        status: :accessible,
        request: { method: 'GET', path: '/org/repo/settings' },
        response: { http_status: 200 },
        notes: 'Still reachable after remove action',
        artifact_paths: ['/tmp/screenshot.png']
      )

      summary = PWN::Bounty::LifecycleAuthzReplay.finalize_run(
        run_obj: run_obj
      )
  HELP
end

.load_plan(opts = {}) ⇒ Object

Supported Method Parameters

plan = PWN::Bounty::LifecycleAuthzReplay.load_plan(

yaml_path: '/path/to/lifecycle_authz_replay.yaml'

)



21
22
23
24
25
26
27
28
29
30
# File 'lib/pwn/bounty/lifecycle_authz_replay.rb', line 21

public_class_method def self.load_plan(opts = {})
  yaml_path = opts[:yaml_path]
  raise 'yaml_path is required' if yaml_path.to_s.strip.empty?
  raise "YAML plan does not exist: #{yaml_path}" unless File.exist?(yaml_path)

  raw_plan = YAML.safe_load_file(yaml_path, aliases: true) || {}
  normalize_plan(plan: symbolize_obj(raw_plan), plan_id_hint: File.basename(yaml_path, File.extname(yaml_path)))
rescue StandardError => e
  raise e
end

.normalize_plan(opts = {}) ⇒ Object

Supported Method Parameters

plan = PWN::Bounty::LifecycleAuthzReplay.normalize_plan(

plan: {
  campaign: { id: 'acme-revoke' },
  actors: ['owner', 'revoked_user'],
  surfaces: ['repo_settings'],
  checkpoints: ['pre_change', 'post_change_t0']
}

)



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/pwn/bounty/lifecycle_authz_replay.rb', line 194

public_class_method def self.normalize_plan(opts = {})
  plan = symbolize_obj(opts[:plan] || {})
  plan_id_hint = normalize_token(opts[:plan_id_hint])

  campaign = symbolize_obj(plan[:campaign] || {})
  campaign_id = normalize_token(campaign[:id])
  campaign_id = normalize_token(campaign[:name]) if campaign_id.empty?
  campaign_id = plan_id_hint if campaign_id.empty?
  campaign_id = 'lifecycle-authz-replay' if campaign_id.empty?

  actors = normalize_named_records(
    list: Array(plan[:actors]),
    fallback: [{ id: 'primary_actor', label: 'Primary Actor' }],
    default_prefix: 'actor'
  )

  surfaces = normalize_named_records(
    list: Array(plan[:surfaces]),
    fallback: [{ id: 'primary_surface', label: 'Primary Surface' }],
    default_prefix: 'surface'
  )

  checkpoints = Array(plan[:checkpoints]).map { |checkpoint| normalize_token(checkpoint) }.reject(&:empty?)
  checkpoints = DEFAULT_CHECKPOINTS if checkpoints.empty?

  expected_denied_after = Array(plan[:expected_denied_after]).map { |checkpoint| normalize_token(checkpoint) }.reject(&:empty?)
  expected_denied_after = checkpoints.select { |checkpoint| checkpoint.start_with?('post_change') } if expected_denied_after.empty?

  {
    campaign: {
      id: campaign_id,
      label: campaign[:label].to_s.strip,
      target: campaign[:target].to_s.strip,
      change_event: campaign[:change_event].to_s.strip,
      notes: campaign[:notes].to_s.strip
    },
    actors: actors,
    surfaces: surfaces,
    checkpoints: checkpoints,
    expected_denied_after: expected_denied_after,
    metadata: symbolize_obj(plan[:metadata] || {})
  }
rescue StandardError => e
  raise e
end

.record_observation(opts = {}) ⇒ Object

Supported Method Parameters

PWN::Bounty::LifecycleAuthzReplay.record_observation(

run_obj: run_obj,
checkpoint: 'post_change_t0',
actor: 'revoked_user',
surface: 'repo_settings_page',
status: :accessible,
request: { method: 'GET', path: '/org/repo/settings' },
response: { http_status: 200 },
notes: 'Still reachable after collaborator removal',
artifact_paths: ['/tmp/screen.png']

)



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/pwn/bounty/lifecycle_authz_replay.rb', line 89

public_class_method def self.record_observation(opts = {})
  run_obj = opts[:run_obj]
  raise 'run_obj is required' unless run_obj.is_a?(Hash)

  checkpoint = normalize_token(opts[:checkpoint])
  actor = normalize_token(opts[:actor])
  surface = normalize_token(opts[:surface])
  status = normalize_token(opts[:status])

  raise 'checkpoint is required' if checkpoint.empty?
  raise 'actor is required' if actor.empty?
  raise 'surface is required' if surface.empty?

  status = 'unknown' if status.empty?
  raise "unsupported status: #{status} (supported: #{STATUS_VALUES.join(', ')})" unless STATUS_VALUES.include?(status)

  coverage_cell = find_coverage_cell(
    coverage_matrix: run_obj[:coverage_matrix],
    checkpoint: checkpoint,
    actor: actor,
    surface: surface
  )

  raise "unknown coverage cell checkpoint=#{checkpoint} actor=#{actor} surface=#{surface}" if coverage_cell.nil?

  evidence = {
    observed_at: Time.now.utc.iso8601,
    checkpoint: checkpoint,
    actor: actor,
    surface: surface,
    status: status,
    request: symbolize_obj(opts[:request] || {}),
    response: symbolize_obj(opts[:response] || {}),
    notes: opts[:notes].to_s,
    artifact_paths: Array(opts[:artifact_paths]).map(&:to_s)
  }

  evidence_path = File.join(
    run_obj[:artifacts_dir],
    checkpoint,
    actor,
    "#{surface}.json"
  )
  write_json(path: evidence_path, obj: evidence)

  coverage_cell[:status] = status
  coverage_cell[:observed_at] = evidence[:observed_at]
  coverage_cell[:evidence_path] = evidence_path

  run_obj[:observations] << evidence.merge(evidence_path: evidence_path)

  write_json(path: File.join(run_obj[:run_root], 'coverage_matrix.json'), obj: run_obj[:coverage_matrix])
  write_coverage_markdown(run_obj: run_obj)

  evidence
rescue StandardError => e
  raise e
end

.start_run(opts = {}) ⇒ Object

Supported Method Parameters

run_obj = PWN::Bounty::LifecycleAuthzReplay.start_run(

yaml_path: '/path/to/lifecycle_authz_replay.yaml',
output_dir: '/tmp/evidence_bundle'

)

OR run_obj = PWN::Bounty::LifecycleAuthzReplay.start_run(

plan: normalized_plan_hash,
output_dir: '/tmp/evidence_bundle'

)



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/pwn/bounty/lifecycle_authz_replay.rb', line 43

public_class_method def self.start_run(opts = {})
  output_dir = opts[:output_dir].to_s.strip
  output_dir = Dir.pwd if output_dir.empty?

  plan = opts[:plan]
  plan = load_plan(yaml_path: opts[:yaml_path]) if plan.nil?
  plan = normalize_plan(plan: plan) if plan.is_a?(Hash)

  run_id = opts[:run_id].to_s.strip
  run_id = "#{Time.now.utc.strftime('%Y%m%dT%H%M%SZ')}-#{plan[:campaign][:id]}" if run_id.empty?

  run_root = File.expand_path(File.join(output_dir, run_id))
  artifacts_dir = File.join(run_root, 'artifacts')
  FileUtils.mkdir_p(artifacts_dir)

  run_obj = {
    run_id: run_id,
    run_root: run_root,
    artifacts_dir: artifacts_dir,
    started_at: Time.now.utc.iso8601,
    plan: plan,
    coverage_matrix: build_coverage_matrix(plan: plan),
    observations: []
  }

  write_json(path: File.join(run_root, 'coverage_matrix.json'), obj: run_obj[:coverage_matrix])
  write_yaml(path: File.join(run_root, 'plan.normalized.yaml'), obj: plan)
  write_runbook(run_obj: run_obj)

  run_obj
rescue StandardError => e
  raise e
end