HFish/core/rpc/client/client.go
SanJin b97dae897a ~ 上钩列表分页优化
~ 上钩列表支持批量删除
~ 上钩列表长度展示
~ 上钩列表支持集群筛选
~ 集群页面支持删除
~ 改用 IPIP 本地库获取地理信息
~ 支持 WebHook Api 通知
~ 提供获取上钩列表 API
~ WEB,暗网蜜罐 API 移到各种服务上,抛开 Admin
~ 修复暗网蜜罐使用问题
~ 修复集群取 IP 错误问题
~ SSH 高交互支持
2019-08-25 01:00:42 +08:00

106 lines
2.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package client
import (
"HFish/utils/log"
"HFish/utils/conf"
"HFish/core/rpc/core"
"strings"
)
// 上报状态结构
type Status struct {
AgentIp string
AgentName string
Web, Deep, Ssh, Redis, Mysql, Http, Telnet, Ftp string
}
// 上报结果结构
type Result struct {
AgentIp string
AgentName string
Type string
ProjectName string
SourceIp string
Info string
Id string // 数据库ID更新用 0 为新插入数据
}
func createClient() (*rpc.Client, string, bool) {
rpcAddr := conf.Get("rpc", "addr")
client, conn, err := rpc.Dial("tcp", rpcAddr)
ipArr := strings.Split(conn.LocalAddr().String(), ":")
if err != nil {
log.Pr("RPC", "127.0.0.1", "连接 RPC Server 失败")
return client, "", false
}
return client, ipArr[0], true
}
func reportStatus(rpcName string, ftpStatus string, telnetStatus string, httpStatus string, mysqlStatus string, redisStatus string, sshStatus string, webStatus string, darkStatus string) {
client, addr, boolStatus := createClient()
if boolStatus {
defer client.Close()
status := Status{
addr,
rpcName,
webStatus,
darkStatus,
sshStatus,
redisStatus,
mysqlStatus,
httpStatus,
telnetStatus,
ftpStatus,
}
var reply string
err := client.Call("HFishRPCService.ReportStatus", status, &reply)
if err != nil {
log.Pr("RPC", "127.0.0.1", "上报服务状态失败", err)
}
}
}
func ReportResult(typex string, projectName string, sourceIp string, info string, id string) string {
// projectName 只有 WEB 才需要传项目名 其他协议空即可
// id 0 为 新插入数据,非 0 都是更新数据
// id 非 0 的时候 sourceIp 为空
client, addr, boolStatus := createClient()
if boolStatus {
defer client.Close()
rpcName := conf.Get("rpc", "name")
result := Result{
addr,
rpcName,
typex,
projectName,
sourceIp,
info,
id,
}
var reply string
err := client.Call("HFishRPCService.ReportResult", result, &reply)
if err != nil {
log.Pr("RPC", "127.0.0.1", "上报上钩结果失败")
}
return reply
}
return ""
}
func Start(rpcName string, ftpStatus string, telnetStatus string, httpStatus string, mysqlStatus string, redisStatus string, sshStatus string, webStatus string, darkStatus string) {
reportStatus(rpcName, ftpStatus, telnetStatus, httpStatus, mysqlStatus, redisStatus, sshStatus, webStatus, darkStatus)
}