From 0105308f31776b5f40a44c079bc37e29ee5088ce Mon Sep 17 00:00:00 2001 From: ankurp151 <128740715+ankurp151@users.noreply.github.com> Date: Tue, 8 Oct 2024 19:15:26 +0530 Subject: [PATCH 1/9] Add files via upload --- entities/plugin.go | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 entities/plugin.go diff --git a/entities/plugin.go b/entities/plugin.go new file mode 100644 index 0000000..8f5676c --- /dev/null +++ b/entities/plugin.go @@ -0,0 +1,7 @@ +package entities + +type Plugin interface { + Initialize() error + Execute() error + Cleanup() error +} \ No newline at end of file From 509c92a70a6ffc098857397b935043304a2d0341 Mon Sep 17 00:00:00 2001 From: ankurp151 <128740715+ankurp151@users.noreply.github.com> Date: Tue, 8 Oct 2024 19:16:09 +0530 Subject: [PATCH 2/9] Create plugin --- services/plugin | 1 + 1 file changed, 1 insertion(+) create mode 100644 services/plugin diff --git a/services/plugin b/services/plugin new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/services/plugin @@ -0,0 +1 @@ + From 82d112fe39db916e306fab0164daff1376313bad Mon Sep 17 00:00:00 2001 From: ankurp151 <128740715+ankurp151@users.noreply.github.com> Date: Tue, 8 Oct 2024 19:17:10 +0530 Subject: [PATCH 3/9] Delete services/plugin --- services/plugin | 1 - 1 file changed, 1 deletion(-) delete mode 100644 services/plugin diff --git a/services/plugin b/services/plugin deleted file mode 100644 index 8b13789..0000000 --- a/services/plugin +++ /dev/null @@ -1 +0,0 @@ - From 84c23e4b0b501af58311f874e5a0d12e1153f7cc Mon Sep 17 00:00:00 2001 From: ankurp151 <128740715+ankurp151@users.noreply.github.com> Date: Tue, 8 Oct 2024 19:20:29 +0530 Subject: [PATCH 4/9] Create plugin --- services/plugin | 1 + 1 file changed, 1 insertion(+) create mode 100644 services/plugin diff --git a/services/plugin b/services/plugin new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/services/plugin @@ -0,0 +1 @@ + From e3f18460a0728818e78a7a66ac3a9b1b109e0b67 Mon Sep 17 00:00:00 2001 From: ankurp151 <128740715+ankurp151@users.noreply.github.com> Date: Tue, 8 Oct 2024 19:22:22 +0530 Subject: [PATCH 5/9] Delete services/plugin --- services/plugin | 1 - 1 file changed, 1 deletion(-) delete mode 100644 services/plugin diff --git a/services/plugin b/services/plugin deleted file mode 100644 index 8b13789..0000000 --- a/services/plugin +++ /dev/null @@ -1 +0,0 @@ - From b07189603ba9114865962bae7e7dfaa99dc930ef Mon Sep 17 00:00:00 2001 From: ankurp151 <128740715+ankurp151@users.noreply.github.com> Date: Tue, 8 Oct 2024 19:24:09 +0530 Subject: [PATCH 6/9] Create network --- services/plugin/network | 1 + 1 file changed, 1 insertion(+) create mode 100644 services/plugin/network diff --git a/services/plugin/network b/services/plugin/network new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/services/plugin/network @@ -0,0 +1 @@ + From ae56dc2438323a60724809ef8e02a702eb4b41cd Mon Sep 17 00:00:00 2001 From: ankurp151 <128740715+ankurp151@users.noreply.github.com> Date: Tue, 8 Oct 2024 19:24:46 +0530 Subject: [PATCH 7/9] Add files via upload --- services/plugin/loader.go | 44 ++++++++++++++++++++++++++++++++++++++ services/plugin/manager.go | 43 +++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 services/plugin/loader.go create mode 100644 services/plugin/manager.go diff --git a/services/plugin/loader.go b/services/plugin/loader.go new file mode 100644 index 0000000..deff386 --- /dev/null +++ b/services/plugin/loader.go @@ -0,0 +1,44 @@ +package services + +import ( + "plugin" + "path/filepath" + "CHAOS/entities" +) + +type PluginLoader struct {} + +func (pl *PluginLoader) LoadPlugins(pluginDir string) ([]entities.Plugin, error) { + var plugins []entities.Plugin + + files, err := filepath.Glob(filepath.Join(pluginDir, "*.so")) + if err != nil { + return nil, err + } + + for _, file := range files { + p, err := plugin.Open(file) + if err != nil { + return nil, err + } + + symPlugin, err := p.Lookup("Plugin") + if err != nil { + return nil, err + } + + var plug entities.Plugin + plug, ok := symPlugin.(entities.Plugin) + if !ok { + return nil, fmt.Errorf("unexpected type from module symbol") + } + + if err := plug.Initialize(); err != nil { + return nil, err + } + + plugins = append(plugins, plug) + } + + return plugins, nil +} \ No newline at end of file diff --git a/services/plugin/manager.go b/services/plugin/manager.go new file mode 100644 index 0000000..ed6f90c --- /dev/null +++ b/services/plugin/manager.go @@ -0,0 +1,43 @@ +package services + +import ( + "CHAOS/entities" +) + +type PluginManager struct { + Plugins []entities.Plugin + Loader *PluginLoader +} + +func NewPluginManager() *PluginManager { + return &PluginManager{ + Loader: &PluginLoader{}, + } +} + +func (pm *PluginManager) LoadPlugins(pluginDir string) error { + plugins, err := pm.Loader.LoadPlugins(pluginDir) + if err != nil { + return err + } + pm.Plugins = plugins + return nil +} + +func (pm *PluginManager) ExecutePlugins() error { + for _, p := range pm.Plugins { + if err := p.Execute(); err != nil { + return err + } + } + return nil +} + +func (pm *PluginManager) CleanupPlugins() error { + for _, p := range pm.Plugins { + if err := p.Cleanup(); err != nil { + return err + } + } + return nil +} \ No newline at end of file From f73b50b6f4405ce2450979f8a8363c16631cc1d6 Mon Sep 17 00:00:00 2001 From: ankurp151 <128740715+ankurp151@users.noreply.github.com> Date: Tue, 8 Oct 2024 19:25:31 +0530 Subject: [PATCH 8/9] Create network --- web/plugin/network | 1 + 1 file changed, 1 insertion(+) create mode 100644 web/plugin/network diff --git a/web/plugin/network b/web/plugin/network new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/web/plugin/network @@ -0,0 +1 @@ + From ddaf1c9cd6fd659f77bfeae5f0c7351f319a678c Mon Sep 17 00:00:00 2001 From: ankurp151 <128740715+ankurp151@users.noreply.github.com> Date: Tue, 8 Oct 2024 19:25:55 +0530 Subject: [PATCH 9/9] Add files via upload --- web/plugin/sample_plugin.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 web/plugin/sample_plugin.go diff --git a/web/plugin/sample_plugin.go b/web/plugin/sample_plugin.go new file mode 100644 index 0000000..ea82ade --- /dev/null +++ b/web/plugin/sample_plugin.go @@ -0,0 +1,23 @@ +package main + +import "fmt" + +type SamplePlugin struct{} + +func (p *SamplePlugin) Initialize() error { + fmt.Println("Sample plugin initialized") + return nil +} + +func (p *SamplePlugin) Execute() error { + fmt.Println("Sample plugin executed") + return nil +} + +func (p *SamplePlugin) Cleanup() error { + fmt.Println("Sample plugin cleaned up") + return nil +} + +// This is important! Go plugins must export a variable named "Plugin" +var Plugin SamplePlugin \ No newline at end of file