Module: PWN::Config
- Defined in:
- lib/pwn/config.rb
Overview
Used to manage PWN configuration settings within PWN drivers.
Class Method Summary collapse
-
.authors ⇒ Object
- Author(s)
-
0day Inc.
-
.default_env(opts = {}) ⇒ Object
- Supported Method Parameters
-
env = PWN::Config.default_env( pwn_env_path: ‘optional - Path to pwn.yaml file. Defaults to ~/.pwn/pwn.yaml’ ).
-
.help ⇒ Object
Display Usage for this Module.
-
.init_driver_options ⇒ Object
- Supported Method Parameters
-
env = PWN::Config.init_driver_options.
-
.load_memory ⇒ Object
- Supported Method Parameters
-
PWN::Config.load_memory.
-
.load_skills(opts = {}) ⇒ Object
- Supported Method Parameters
-
skills = PWN::Config.load_skills( pwn_skills_path: ‘optional - Path to skills folder. Defaults to ~/.pwn/skills’ ).
-
.pwn_cron_path ⇒ Object
- Supported Method Parameters
-
path = PWN::Config.pwn_cron_path.
-
.pwn_memory_path ⇒ Object
- Supported Method Parameters
-
path = PWN::Config.pwn_memory_path.
-
.pwn_sessions_path ⇒ Object
- Supported Method Parameters
-
path = PWN::Config.pwn_sessions_path.
-
.pwn_skills_path(opts = {}) ⇒ Object
- Supported Method Parameters
-
pwn_skills_path = PWN::Config.pwn_skills_path( pwn_env_path: ‘optional - Path to pwn.yaml file. Defaults to ~/.pwn/pwn.yaml’ ).
-
.redact_sensitive_artifacts(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Config.redact_sensitive_artifacts( config: ‘optional - Hash to redact sensitive artifacts from. Defaults to PWN::Env’ ).
-
.refresh_env(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Config.refresh_env( pwn_env_path: ‘optional - Path to pwn.yaml file. Defaults to ~/.pwn/pwn.yaml’, pwn_dec_path: ‘optional - Path to pwn.yaml.decryptor file. Defaults to ~/.pwn/pwn.yaml.decryptor’ ).
Class Method Details
.authors ⇒ Object
- Author(s)
-
0day Inc. <support@0dayinc.com>
441 442 443 444 445 |
# File 'lib/pwn/config.rb', line 441 public_class_method def self. "AUTHOR(S): 0day Inc. <support@0dayinc.com> " end |
.default_env(opts = {}) ⇒ Object
- Supported Method Parameters
-
env = PWN::Config.default_env(
pwn_env_path: 'optional - Path to pwn.yaml file. Defaults to ~/.pwn/pwn.yaml')
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 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 76 77 78 79 80 81 82 83 84 85 86 87 88 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 147 148 149 150 151 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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/pwn/config.rb', line 13 public_class_method def self.default_env(opts = {}) pwn_env_path = opts[:pwn_env_path] pwn_dec_path = "#{pwn_env_path}.decryptor" puts " [*] NOTICE: 1. Writing minimal PWN::Env to: #{pwn_env_path} 2. Your decryptor file will be written to: #{pwn_dec_path} 3. Use the pwn-vault command in the pwn prototyping driver to update: #{pwn_env_path} 4. For optimal security, it's recommended to move: #{pwn_dec_path} to a secure location and use the --pwn-dec parameter for PWN drivers. " env = { ai: { active: 'grok', introspection: false, grok: { base_uri: 'optional - Base URI for Grok - Use private base OR defaults to https://api.x.ai/v1', key: 'required - xAI Grok API Key', model: 'optional - Grok model to use', system_role_content: 'You are an ethically hacking xAI Grok agent.', temp: 'optional - Grok temperature', max_prompt_length: 256_000, # OAuth support for xAI SuperGrok subscriptions (in addition to API key) # Populate via pwn-vault command (values stored encrypted in ~/.pwn/pwn.yaml) oauth: { client_id: 'optional - xAI SuperGrok OAuth Client ID (for subscriptions without API key)', client_secret: 'optional - xAI SuperGrok OAuth Client Secret', bearer_token: 'optional - xAI SuperGrok OAuth Access Token (preferred for SuperGrok subs; used as Bearer)', refresh_token: 'optional - xAI SuperGrok OAuth Refresh Token', token_uri: 'optional - OAuth token endpoint (defaults handled in PWN::AI::Grok if needed)' } }, openai: { base_uri: 'optional - Base URI for OpenAI - Use private base OR defaults to https://api.openai.com/v1', key: 'required - OpenAI API Key', model: 'optional - OpenAI model to use', system_role_content: 'You are an ethically hacking OpenAI agent.', temp: 'optional - OpenAI temperature', max_prompt_length: 128_000 }, ollama: { base_uri: 'required - Base URI for Open WebUI - e.g. https://ollama.local', key: 'required - Open WebUI API Key Under Settings >> Account >> JWT Token', model: 'required - Ollama model to use', system_role_content: 'You are an ethically hacking Ollama agent.', temp: 'optional - Ollama temperature', max_prompt_length: 32_000 }, anthropic: { base_uri: 'optional - Base URI for Anthropic - Use private base OR defaults to https://api.anthropic.com/v1', key: 'required - Anthropic API Key', model: 'optional - Anthropic model to use (e.g. claude-3-5-sonnet-20240620)', system_role_content: 'You are an ethically hacking Anthropic agent.', temp: 'optional - Anthropic temperature', max_prompt_length: 200_000 }, gemini: { base_uri: 'optional - Base URI for Gemini - Use private base OR defaults to https://generativelanguage.googleapis.com/v1beta', key: 'required - Google Gemini API Key', model: 'optional - Gemini model to use (e.g. gemini-2.5-pro, gemini-2.5-flash)', system_role_content: 'You are an ethically hacking Gemini agent.', temp: 'optional - Gemini temperature', max_prompt_length: 1_000_000 }, agent: { native_tools: true, max_iters: 25, toolsets: nil } }, plugins: { asm: { arch: PWN::Plugins::DetectOS.arch, endian: PWN::Plugins::DetectOS.endian.to_s }, blockchain: { bitcoin: { rpc_host: 'localhost', rpc_port: 8332, rpc_user: 'bitcoin RPC Username', rpc_pass: 'bitcoin RPC Password' } }, irc: { ui_nick: '_human_', shared_chan: '#pwn', ai_agent_nicks: { browser: { pwn_rb: '/opt/pwn/lib/pwn/plugins/transparent_browser.rb', system_role_content: 'You are a browser. You are a web browser that can be controlled by a human or AI agent' }, nimjeh: { pwn_rb: '', system_role_content: 'You are a sarcastic hacker. You find software zero day vulnerabilities. This involves analyzing source code, race conditions, application binaries, and network protocols from an offensive security perspective.' }, nmap: { pwn_rb: '/opt/pwn/lib/pwn/plugins/nmap_it.rb', system_role_content: 'You are a network scanner. You are a network scanner that can be controlled by a human or AI agent' }, shodan: { pwn_rb: '/opt/pwn/lib/pwn/plugins/shodan.rb', system_role_content: 'You are a passive reconnaissance agent. You are a passive reconnaissance agent that can be controlled by a human or AI agent' } } }, hunter: { api_key: 'hunter.how API Key' }, jira_data_center: { base_uri: 'Jira Server Base API URI (e.g. https://jira.company.com/rest/api/latest)', token: 'Jira Server API Token' }, meshtastic: { admin_key: 'Public key authorized to send admin messages to nodes', serial: { port: '/dev/ttyUSB0', baud: 115_200, bits: 8, stop: 1, parity: :none }, mqtt: { host: 'mqtt.meshtastic.org', port: 1883, tls: false, user: 'meshdev', pass: 'large4cats' }, channel: { active: 'LongFast', LongFast: { psk: 'AQ==', region: 'US/<STATE>', topic: '2/e/#', channel_num: 8 }, PWN: { psk: 'required - PSK for pwn channel', region: 'US/<STATE>', topic: '2/e/PWN/#', channel_num: 99 } } }, shodan: { api_key: 'SHODAN API Key' } }, memory: { enabled: true, provider: 'file' # file | sqlite (future) }, sessions: { enabled: true, provider: 'jsonl' }, cron: { enabled: true, provider: 'yaml' } } # Remove beginning colon from key names yaml_env = YAML.dump(env).gsub(/^(\s*):/, '\1') File.write(pwn_env_path, yaml_env) # Change file permission to 600 File.chmod(0o600, pwn_env_path) # Ensure skills dir for pwn-ai agent (in parent of pwn_env_path) pwn_env_root = File.dirname(pwn_env_path) pwn_skills_path = File.join(pwn_env_root, 'skills') FileUtils.mkdir_p(pwn_skills_path) env[:driver_opts] = { pwn_env_path: pwn_env_path, pwn_dec_path: pwn_dec_path } PWN::Plugins::Vault.create( file: pwn_env_path, decryptor_file: pwn_dec_path ) Pry.config.refresh_pwn_env = false if defined?(Pry) env[:pwn_skills_path] = pwn_skills_path PWN::Config.load_skills(pwn_skills_path: pwn_skills_path) # pwn-ai agent: memory/sessions/cron paths env[:pwn_memory_path] = PWN::Memory::MEMORY_FILE if defined?(PWN::Memory) env[:pwn_sessions_path] = PWN::Sessions.sessions_dir if defined?(PWN::Sessions) env[:pwn_cron_path] = PWN::Cron.cron_dir if defined?(PWN::Cron) PWN.send(:remove_const, :Env) if PWN.const_defined?(:Env) PWN.const_set(:Env, env.freeze) rescue StandardError => e raise e end |
.help ⇒ Object
Display Usage for this Module
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 |
# File 'lib/pwn/config.rb', line 449 public_class_method def self.help puts "USAGE: #{self}.default_env( pwn_env_path: 'optional - Path to pwn.yaml file. Defaults to ~/.pwn/pwn.yaml' ) #{self}.redact_sensitive_artifacts( config: 'optional - Hash to redact sensitive artifacts from. Defaults to PWN::Env' ) #{self}.refresh_env( pwn_env_path: 'optional - Path to pwn.yaml file. Defaults to ~/.pwn/pwn.yaml', pwn_dec_path: 'optional - Path to pwn.yaml.decryptor file. Defaults to ~/.pwn/pwn.yaml.decryrptor' ) #{self}.authors " end |
.init_driver_options ⇒ Object
- Supported Method Parameters
-
env = PWN::Config.init_driver_options
247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/pwn/config.rb', line 247 public_class_method def self. env = { driver_opts: { pwn_env_path: nil, pwn_dec_path: nil } } PWN.const_set(:Env, env) # puts '[*] Loaded driver options.' rescue StandardError => e raise e end |
.load_memory ⇒ Object
- Supported Method Parameters
-
PWN::Config.load_memory
423 424 425 |
# File 'lib/pwn/config.rb', line 423 public_class_method def self.load_memory defined?(PWN::Memory) ? PWN::Memory.load : {} end |
.load_skills(opts = {}) ⇒ Object
- Supported Method Parameters
-
skills = PWN::Config.load_skills(
pwn_skills_path: 'optional - Path to skills folder. Defaults to ~/.pwn/skills')
Loads instruction-based skills (.md, .txt, .skill, .yaml) and executable Ruby skills (.rb) into PWN::Skills constant (hash of basename => path, content, loaded?). The pwn-ai command (REPL driver) loads and is aware of this folder to expand autonomous agent capabilities (skill documents loaded for task execution).
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
# File 'lib/pwn/config.rb', line 384 public_class_method def self.load_skills(opts = {}) pwn_skills_path = opts[:pwn_skills_path] || PWN::Env[:pwn_skills_path] || pwn_skills_path FileUtils.mkdir_p(pwn_skills_path) if pwn_skills_path && !Dir.exist?(pwn_skills_path.to_s) skills = {} return skills unless pwn_skills_path && Dir.exist?(pwn_skills_path.to_s) Dir.glob(File.join(pwn_skills_path, '*.{rb,md,txt,skill,yml,yaml}')).each do |skill_file| basename = File.basename(skill_file, '.*').to_sym content = File.read(skill_file) ext = File.extname(skill_file).downcase if ext == '.rb' begin require skill_file skills[basename] = { type: :ruby, path: skill_file, content: content, loaded: true } rescue StandardError => e skills[basename] = { type: :ruby, path: skill_file, content: content, loaded: false, error: e. } end else skills[basename] = { type: :instruction, path: skill_file, content: content } end end PWN.send(:remove_const, :Skills) if PWN.const_defined?(:Skills) PWN.const_set(:Skills, skills.freeze) skills rescue StandardError => e raise e end |
.pwn_cron_path ⇒ Object
- Supported Method Parameters
-
path = PWN::Config.pwn_cron_path
435 436 437 |
# File 'lib/pwn/config.rb', line 435 public_class_method def self.pwn_cron_path defined?(PWN::Cron) ? PWN::Cron.cron_dir : File.join(Dir.home, '.pwn', 'cron') end |
.pwn_memory_path ⇒ Object
- Supported Method Parameters
-
path = PWN::Config.pwn_memory_path
417 418 419 |
# File 'lib/pwn/config.rb', line 417 public_class_method def self.pwn_memory_path defined?(PWN::Memory) ? PWN::Memory::MEMORY_FILE : File.join(Dir.home, '.pwn', 'memory.json') end |
.pwn_sessions_path ⇒ Object
- Supported Method Parameters
-
path = PWN::Config.pwn_sessions_path
429 430 431 |
# File 'lib/pwn/config.rb', line 429 public_class_method def self.pwn_sessions_path defined?(PWN::Sessions) ? PWN::Sessions.sessions_dir : File.join(Dir.home, '.pwn', 'sessions') end |
.pwn_skills_path(opts = {}) ⇒ Object
- Supported Method Parameters
-
pwn_skills_path = PWN::Config.pwn_skills_path(
pwn_env_path: 'optional - Path to pwn.yaml file. Defaults to ~/.pwn/pwn.yaml')
370 371 372 373 |
# File 'lib/pwn/config.rb', line 370 public_class_method def self.pwn_skills_path(opts = {}) pwn_env_path = opts[:pwn_env_path] ||= "#{Dir.home}/.pwn/pwn.yaml" File.join(File.dirname(pwn_env_path), 'skills') end |
.redact_sensitive_artifacts(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Config.redact_sensitive_artifacts(
config: 'optional - Hash to redact sensitive artifacts from. Defaults to PWN::Env')
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/pwn/config.rb', line 215 public_class_method def self.redact_sensitive_artifacts(opts = {}) config = opts[:config] ||= PWN::Env sensitive_keys = %i[ admin_key api_key auth_client_secret bearer_token client_secret consumer_key key pass password psk secret_key token ] # Transform values at the current level: redact sensitive keys config.transform_values.with_index do |v, k| if sensitive_keys.include?(config.keys[k]) '>>> REDACTED >>> USE `pwn-vault` FOR ADMINISTRATION <<< REDACTED <<<' else v.is_a?(Hash) ? redact_sensitive_artifacts(config: v) : v end end rescue StandardError => e raise e end |
.refresh_env(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Config.refresh_env(
pwn_env_path: 'optional - Path to pwn.yaml file. Defaults to ~/.pwn/pwn.yaml', pwn_dec_path: 'optional - Path to pwn.yaml.decryptor file. Defaults to ~/.pwn/pwn.yaml.decryptor')
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
# File 'lib/pwn/config.rb', line 266 public_class_method def self.refresh_env(opts = {}) pwn_env_root = "#{Dir.home}/.pwn" pwn_env_path = opts[:pwn_env_path] ||= "#{pwn_env_root}/pwn.yaml" pwn_env_root = File.dirname(pwn_env_path) FileUtils.mkdir_p(pwn_env_root) pwn_skills_path = File.join(pwn_env_root, 'skills') FileUtils.mkdir_p(pwn_skills_path) return default_env(pwn_env_path: pwn_env_path) unless File.exist?(pwn_env_path) is_encrypted = PWN::Plugins::Vault.file_encrypted?(file: pwn_env_path) raise "PWN Environment (#{pwn_env_path}) is not encrypted! Use PWN::Vault.create(file: '#{pwn_env_path}', decryptor_file: '#{pwn_env_path}.decryptor') to encrypt it." unless is_encrypted pwn_dec_path = opts[:pwn_dec_path] ||= "#{pwn_env_path}.decryptor" raise "PWN Decryptor (#{pwn_dec_path}) does not exist!" unless File.exist?(pwn_dec_path) pwn_decryptor = YAML.load_file(pwn_dec_path, symbolize_names: true) key = opts[:key] ||= pwn_decryptor[:key] ||= ENV.fetch('PWN_DECRYPTOR_KEY') key = PWN::Plugins::AuthenticationHelper.mask_password(prompt: 'Decryption Key') if key.nil? iv = opts[:iv] ||= pwn_decryptor[:iv] ||= ENV.fetch('PWN_DECRYPTOR_IV') iv = PWN::Plugins::AuthenticationHelper.mask_password(prompt: 'Decryption IV') if iv.nil? env = PWN::Plugins::Vault.dump( file: pwn_env_path, key: key, iv: iv ) valid_ai_engines = PWN::AI.help.reject { |e| e.downcase == :introspection }.map(&:downcase) engine = env[:ai][:active].to_s.downcase.to_sym raise "ERROR: Unsupported AI Engine: #{engine} in #{pwn_env_path}. Supported AI Engines:\n#{valid_ai_engines.inspect}" unless valid_ai_engines.include?(engine) key = env[:ai][engine][:key] oauth_access = nil if engine == :grok oauth = env[:ai][engine][:oauth] ||= {} oauth_access = oauth[:bearer_token] if oauth[:bearer_token] && !oauth[:bearer_token].to_s.match?(/optional/i) && !oauth[:bearer_token].to_s.empty? end if key.nil? && oauth_access.nil? key = PWN::Plugins::AuthenticationHelper.mask_password( prompt: "#{engine} API Key (or configure oauth:bearer_token in pwn-vault for xAI SuperGrok subscriptions)" ) env[:ai][engine][:key] = key end model = env[:ai][engine][:model] system_role_content = env[:ai][engine][:system_role_content] # Reset the ai response history on env refresh env[:ai][engine][:response_history] = { id: '', object: '', model: model, usage: {}, choices: [ { role: 'system', content: system_role_content } ] } # These two lines should be immutable for the session env[:driver_opts] = { pwn_env_path: pwn_env_path, pwn_dec_path: pwn_dec_path } # Make pwn-ai aware of the skills folder in pwn_env parent (before freeze) env[:pwn_skills_path] = pwn_skills_path if defined?(pwn_skills_path) PWN::Config.load_skills(pwn_skills_path: pwn_skills_path) if defined?(pwn_skills_path) # pwn-ai agent: memory, sessions, cron paths (before freeze) env[:pwn_memory_path] = PWN::Memory::MEMORY_FILE if defined?(PWN::Memory) PWN::Memory.load if defined?(PWN::Memory) env[:pwn_sessions_path] = PWN::Sessions.sessions_dir if defined?(PWN::Sessions) env[:pwn_cron_path] = PWN::Cron.cron_dir if defined?(PWN::Cron) # Assign the refreshed env to PWN::Env PWN.send(:remove_const, :Env) if PWN.const_defined?(:Env) PWN.const_set(:Env, env.freeze) # Redact sensitive artifacts from PWN::Env and store in PWN::EnvRedacted env_redacted = redact_sensitive_artifacts(config: env) PWN.send(:remove_const, :EnvRedacted) if PWN.const_defined?(:EnvRedacted) PWN.const_set(:EnvRedacted, env_redacted.freeze) Pry.config.refresh_pwn_env = false if defined?(Pry) puts "[*] PWN::Env loaded via: #{pwn_env_path}\n" rescue StandardError => e raise e end |