Module: PWN::Plugins::REPL::IRC

Defined in:
lib/pwn/plugins/repl/irc.rb

Overview

pwn-irc REPL mode.

Class Method Summary collapse

Class Method Details

.add_commandsObject



12
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
# File 'lib/pwn/plugins/repl/irc.rb', line 12

def self.add_commands
  Pry::Commands.create_command 'pwn-irc' do
    description 'IRC viewport onto a PWN::AI::Agent::Swarm (deprecated as multi-agent transport).'

    # pwn-irc is now a THIN OBSERVER over PWN::AI::Agent::Swarm.
    # The old inspircd/weechat block spun up N text-only .chat bots
    # per nick — that bypassed tools, Memory, Skills, Learning,
    # Metrics and Extrospection. Multi-agent now lives in
    # PWN::AI::Agent::Swarm (agent_ask / agent_debate / agent_broadcast
    # from inside pwn-ai). This command just bridges a swarm's
    # bus.jsonl into an IRC channel so you can watch in weechat and
    # type `@red enumerate ports on 10.0.0.5` to route into Swarm.ask.
    def process
      host = '127.0.0.1'
      port = 6667
      chan = '#pwn'

      unless PWN::Plugins::Sock.check_port_in_use(server_ip: host, port: port)
        puts "          pwn-irc is now an optional viewport onto PWN::AI::Agent::Swarm.\n          Multi-agent no longer requires IRC:\n\n            pwn-ai\n            \u00BB agent_list\n            \u00BB agent_debate(names: %w[red blue], topic: '...', rounds: 3)\n\n          or from Ruby:\n            PWN::AI::Agent::Swarm.debate(names: %w[red blue], topic: '...')\n\n          Personas: \#{PWN::AI::Agent::Swarm::AGENTS_FILE}\n          Bus     : ~/.pwn/swarm/<swarm_id>/bus.jsonl\n\n          (Start inspircd on \#{host}:\#{port} if you still want the weechat view.)\n        MIGRATE\n        return\n      end\n\n      personas = PWN::AI::Agent::Swarm.personas\n      if personas.empty?\n        puts \"No personas defined in \#{PWN::AI::Agent::Swarm::AGENTS_FILE} \u2014 \" \\\n             'use PWN::AI::Agent::Swarm.spawn or agent_spawn from pwn-ai.'\n        return\n      end\n\n      swarm  = PWN::AI::Agent::Swarm.create(topic: 'pwn-irc bridge')\n      sid    = swarm[:swarm_id]\n      bus    = swarm[:bus]\n      ui     = ENV.fetch('USER', 'human')\n      bridge = 'swarmbot'\n\n      irc = PWN::Plugins::IRC.connect(host: host.to_s, port: port.to_s, nick: bridge)\n      PWN::Plugins::IRC.join(irc_obj: irc, nick: bridge, chan: chan)\n      PWN::Plugins::IRC.privmsg(\n        irc_obj: irc, nick: bridge, chan: chan,\n        message: \"*** swarm \#{sid} bridged | personas: \#{personas.keys.join(', ')} \" \\\n                 \"| say '@<persona> <request>' | tailing \#{bus}\"\n      )\n\n      # bus.jsonl \u2192 #pwn\n      tailer = Thread.new do\n        seen = File.exist?(bus) ? File.foreach(bus).count : 0\n        loop do\n          lines = File.exist?(bus) ? File.readlines(bus) : []\n          lines[seen..].to_a.each do |l|\n            m = JSON.parse(l, symbolize_names: true)\n            PWN::Plugins::IRC.privmsg(\n              irc_obj: irc, nick: bridge, chan: chan,\n              message: \"[\#{m[:from]}\u2192\#{m[:to]}] \#{m[:content].to_s.tr(\"\\n\", ' ')[0, 400]}\"\n            )\n          rescue StandardError\n            next\n          end\n          seen = lines.length\n          sleep 1\n        end\n      end\n\n      # #pwn '@persona ...' \u2192 Swarm.ask\n      listener = Thread.new do\n        PWN::Plugins::IRC.listen(irc_obj: irc) do |raw|\n          next unless raw.to_s.split[1] == 'PRIVMSG'\n\n          body = raw.to_s.split(' :', 2).last.to_s\n          from = raw.to_s.split('!').first.to_s.delete_prefix(':')\n          m    = body.match(/@(\\w+)\\s+(.+)/)\n          next unless m && personas.key?(m[1].to_sym)\n\n          begin\n            PWN::AI::Agent::Swarm.ask(\n              name: m[1], request: m[2], swarm_id: sid, from: from\n            )\n          rescue StandardError => e\n            PWN::Plugins::IRC.privmsg(\n              irc_obj: irc, nick: bridge, chan: chan,\n              message: \"[error] \#{m[1]}: \#{e.class}: \#{e.message[0, 200]}\"\n            )\n          end\n        end\n      end\n\n      if File.exist?('/usr/bin/weechat')\n        cmds = [\n          \"/server add pwn \#{host}/\#{port} -notls\", '/connect pwn',\n          \"/wait 3 /allserv /nick \#{ui}\", \"/wait 4 /join -server pwn \#{chan}\"\n        ].join(';')\n        system('/usr/bin/weechat', '--run-command', \"'\#{cmds}'\")\n      else\n        puts \"Bridging swarm \#{sid} on #\#{chan} (weechat not found \u2014 use any IRC client). Ctrl-C to stop.\"\n        listener.join\n      end\n    ensure\n      tailer&.kill\n      listener&.kill\n      PWN::Plugins::IRC.quit(irc_obj: irc) if defined?(irc) && irc\n    end\n  end\nend\n"

.authorsObject

Author(s)

0day Inc. [email protected]



132
133
134
135
136
# File 'lib/pwn/plugins/repl/irc.rb', line 132

public_class_method def self.authors
  "AUTHOR(S):
    0day Inc. <[email protected]>
  "
end

.helpObject

Display usage for this module.



140
141
142
143
144
145
146
147
148
149
# File 'lib/pwn/plugins/repl/irc.rb', line 140

public_class_method def self.help
  puts "USAGE:
    # Register the pwn-irc Pry command.
    #{self}.add_commands

    # Print the AUTHOR(S) string for this module.
    #{self}.authors
  "
  constants.sort
end