Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Shifud #549

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

frankhli843
Copy link

@frankhli843 frankhli843 commented Mar 19, 2023

Shifud

How do I run it locally

for f in plugins/*.go; do go build -buildmode=plugin -o "${f%.go}.so" "$f"; done
go run main.go

Running in docker

docker build -t shifud .
docker run -p 8080:8080 shifud

Shifud Plugin Development Guide

Shifud is a flexible network scanning tool with an extensible plugin system. This guide will help you create and integrate a new plugin into the Shifud system.

Understanding the Plugin System

Shifud uses Go's plugin package to dynamically load plugins at runtime. Plugins are compiled as shared libraries (.so files) and loaded from the plugins folder. Each plugin must implement the ScannerPlugin interface, which is defined in the shifud.go file:

type ScannerPlugin interface {
	Scan() ([]DeviceConfig, error)
}

Creating a New Plugin

  1. ** folder.** Name the file based on your plugin's functionality, e.g., http_scanner.go.
  2. ** interface.** For example:
package plugins

import (
	"example.com/Shifud/shifud"
	"fmt"
)

type HttpScanner struct{}

func (s *HttpScanner) Scan() ([]shifud.DeviceConfig, error) {
	fmt.Println("Scanning with HTTP scanner...")
	// Add your plugin logic here
	return nil, nil
}

var ScannerPlugin HttpScanner

** function.** This is where you'll add the core functionality of your plugin. The Scan() function should return a slice of DeviceConfig objects and an error if something goes wrong.

Compiling and Loading the Plugin

Compile the plugin as a shared library. Use the following command to compile your plugin:

go build -buildmode=plugin -o plugins/*.so plugins/*.go

You can also build all plugins yourself with the following command:

for f in plugins/*.go; do go build -buildmode=plugin -o "${f%.go}.so" "$f"; done

Replace your_plugin_name with the appropriate name for your plugin.
file. The LoadPlugins function in the shifud.go file handles the loading of plugins. It is called in the main.go file as follows:

err := shifud.LoadPlugins(scanner, "plugins")
if err != nil {
	fmt.Println("Error loading plugins:", err)
	os.Exit(1)
}

With these steps, your new plugin will be loaded and used by Shifud at runtime. You can create additional plugins by following the same process, and Shifud will automatically load and use them.

Testing Your Plugin

After creating and loading your plugin, run the main.go file to test your plugin's functionality. If everything is set up correctly, you should see the output of your plugin's Scan() function when Shifud runs.

@kris21he
Copy link
Contributor

@frankhli843 we'd better consist with the folder structure of existing repo. should move shifud as a subfolder under /pkg?

devices.yml Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this file check in?

var devices []shifud.DeviceConfig
var wg sync.WaitGroup

log.Println("Launching our little scanner minions! 🚀")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use pkg/logger/log.go to print shifu log

var wg sync.WaitGroup

log.Println("Launching our little scanner minions! 🚀")
for i := 1; i <= 254; i++ {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

254 to be a const?


log.Println("Launching our little scanner minions! 🚀")
for i := 1; i <= 254; i++ {
ip := fmt.Sprintf("192.168.1.%d", i)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make 192.168.1. as a const
BTW, one question, would the network always start with 192.168.1?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants