Kunpeng 简易入门指南
正文
go get -d github.com/opensec-cn/kunpeng
cd $GOPATH/src/github.com/opensec-cn/kunpeng
直接修改 $GOPATH 项目中的 main.go 入口文件。
构建单个扫描任务
package main
import "C" // required
import (
"encoding/json"
"fmt"
"github.com/opensec-cn/kunpeng/config"
"github.com/opensec-cn/kunpeng/plugin"
_ "github.com/opensec-cn/kunpeng/plugin/go"
_ "github.com/opensec-cn/kunpeng/plugin/json"
"github.com/opensec-cn/kunpeng/util"
"github.com/opensec-cn/kunpeng/web"
)
var VERSION string
type greeting string
func (g greeting) Check(taskJSON string) []map[string]interface{} {
var task plugin.Task
json.Unmarshal([]byte(taskJSON), &task)
return plugin.Scan(task)
}
func (g greeting) GetPlugins() []map[string]interface{} {
return plugin.GetPlugins()
}
func (g greeting) SetConfig(configJSON string) {
config.Set(configJSON)
}
func (g greeting) ShowLog() {
config.SetDebug(true)
}
func (g greeting) GetVersion() string {
return VERSION
}
func (g greeting) StartBuffer() {
util.Logger.StartBuffer()
}
func (g greeting) GetLog(sep string) string {
return util.Logger.BufferContent(sep)
}
//export StartWebServer
func StartWebServer(bindAddr *C.char) {
go web.StartServer(C.GoString(bindAddr))
}
//export Check
func Check(task *C.char) *C.char {
util.Logger.Info(C.GoString(task))
var m plugin.Task
err := json.Unmarshal([]byte(C.GoString(task)), &m)
if err != nil {
util.Logger.Error(err.Error())
return C.CString("[]")
}
util.Logger.Info(m)
result := plugin.Scan(m)
if len(result) == 0 {
return C.CString("[]")
}
b, err := json.Marshal(result)
if err != nil {
util.Logger.Error(err.Error())
return C.CString("[]")
}
return C.CString(string(b))
}
//export GetPlugins
func GetPlugins() *C.char {
var result string
plugins := plugin.GetPlugins()
b, err := json.Marshal(plugins)
if err != nil {
util.Logger.Error(err.Error())
return C.CString("[]")
}
result = string(b)
return C.CString(result)
}
//export SetConfig
func SetConfig(configJSON *C.char) {
config.Set(C.GoString(configJSON))
}
//export ShowLog
func ShowLog() {
config.SetDebug(true)
}
//export GetVersion
func GetVersion() *C.char {
return C.CString(VERSION)
}
//export StartBuffer
func StartBuffer() {
util.Logger.StartBuffer()
}
//export GetLog
func GetLog(sep *C.char) *C.char {
return C.CString(util.Logger.BufferContent(C.GoString(sep)))
}
var Greeter greeting
func main() {
// Start Web API server
// bindAddr := "0.0.0.0:38080"
// web.StartServer(bindAddr)
configJSON := "{\"timeout\":\"10\"}"
config.Set(configJSON)
config.Debug = true
var nullString []string
taskOneMeta := plugin.TaskMeta{
System: "web",
PathList: nullString,
FileList: nullString,
PassList: nullString,
}
taskOne := plugin.Task{
Type: "web",
Netloc: "http://192.168.32.129:20000/memoindex.action",
Target: "all",
Meta: taskOneMeta,
}
fmt.Println("Starting TEST Task.")
result := plugin.Scan(taskOne)
line := "========================================================================================================\n"
fmt.Println(line)
for _, v := range result {
//fmt.Printf("key: %s\nvalue:%v\n", k, v)
//fmt.Println(v)
for key, val := range v {
fmt.Printf("[key]: %s\n[value]:\n%s\n", key,val)
fmt.Println(line)
}
}
}
Leave a Reply