2019-08-07 13:16:23 +08:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"HFish/core/report"
|
|
|
|
"net/http"
|
|
|
|
"HFish/error"
|
|
|
|
"HFish/utils/conf"
|
2019-08-09 10:13:54 +08:00
|
|
|
"HFish/core/dbUtil"
|
2019-08-10 18:26:43 +08:00
|
|
|
"HFish/core/rpc/client"
|
|
|
|
"HFish/utils/is"
|
2019-09-02 19:12:46 +08:00
|
|
|
"HFish/utils/log"
|
2019-08-07 13:16:23 +08:00
|
|
|
)
|
|
|
|
|
2019-08-25 01:00:42 +08:00
|
|
|
// 上报WEB蜜罐
|
2019-08-07 13:16:23 +08:00
|
|
|
func ReportWeb(c *gin.Context) {
|
|
|
|
name := c.PostForm("name")
|
|
|
|
info := c.PostForm("info")
|
|
|
|
secKey := c.PostForm("sec_key")
|
|
|
|
ip := c.ClientIP()
|
|
|
|
|
2019-08-26 23:38:32 +08:00
|
|
|
if (ip == "::1") {
|
|
|
|
ip = "127.0.0.1"
|
|
|
|
}
|
|
|
|
|
2019-08-07 13:16:23 +08:00
|
|
|
apiSecKey := conf.Get("api", "sec_key")
|
|
|
|
|
|
|
|
if secKey != apiSecKey {
|
2019-09-02 19:12:46 +08:00
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
"code": error.ErrFailApiKeyCode,
|
|
|
|
"msg": error.ErrFailApiKeyMsg,
|
|
|
|
})
|
2019-08-07 13:16:23 +08:00
|
|
|
} else {
|
2019-08-10 18:26:43 +08:00
|
|
|
|
|
|
|
// 判断是否为 RPC 客户端
|
|
|
|
if is.Rpc() {
|
|
|
|
go client.ReportResult("WEB", name, ip, info, "0")
|
|
|
|
} else {
|
|
|
|
go report.ReportWeb(name, "本机", ip, info)
|
|
|
|
}
|
|
|
|
|
2019-09-02 19:12:46 +08:00
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
"code": error.ErrSuccessCode,
|
|
|
|
"msg": error.ErrSuccessMsg,
|
|
|
|
})
|
2019-08-10 18:26:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-25 01:00:42 +08:00
|
|
|
// 上报暗网蜜罐
|
2019-08-10 18:26:43 +08:00
|
|
|
func ReportDeepWeb(c *gin.Context) {
|
|
|
|
name := c.PostForm("name")
|
|
|
|
info := c.PostForm("info")
|
|
|
|
secKey := c.PostForm("sec_key")
|
|
|
|
ip := c.ClientIP()
|
|
|
|
|
2019-08-26 23:38:32 +08:00
|
|
|
if (ip == "::1") {
|
|
|
|
ip = "127.0.0.1"
|
|
|
|
}
|
|
|
|
|
2019-08-10 18:26:43 +08:00
|
|
|
apiSecKey := conf.Get("api", "sec_key")
|
|
|
|
|
|
|
|
if secKey != apiSecKey {
|
2019-09-02 19:12:46 +08:00
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
"code": error.ErrFailApiKeyCode,
|
|
|
|
"msg": error.ErrFailApiKeyMsg,
|
|
|
|
})
|
2019-08-10 18:26:43 +08:00
|
|
|
} else {
|
|
|
|
|
|
|
|
// 判断是否为 RPC 客户端
|
|
|
|
if is.Rpc() {
|
|
|
|
go client.ReportResult("DEEP", name, ip, info, "0")
|
|
|
|
} else {
|
2019-08-11 20:14:28 +08:00
|
|
|
go report.ReportDeepWeb(name, "本机", ip, info)
|
2019-08-10 18:26:43 +08:00
|
|
|
}
|
|
|
|
|
2019-09-02 19:12:46 +08:00
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
"code": error.ErrSuccessCode,
|
|
|
|
"msg": error.ErrSuccessMsg,
|
|
|
|
})
|
2019-08-07 13:16:23 +08:00
|
|
|
}
|
|
|
|
}
|
2019-08-09 10:13:54 +08:00
|
|
|
|
2019-08-25 15:22:37 +08:00
|
|
|
// 蜜罐插件API
|
|
|
|
func ReportPlugWeb(c *gin.Context) {
|
|
|
|
name := c.PostForm("name")
|
|
|
|
info := c.PostForm("info")
|
|
|
|
secKey := c.PostForm("sec_key")
|
|
|
|
ip := c.PostForm("ip")
|
|
|
|
|
|
|
|
apiSecKey := conf.Get("api", "sec_key")
|
|
|
|
|
|
|
|
if secKey != apiSecKey {
|
2019-09-02 19:12:46 +08:00
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
"code": error.ErrFailApiKeyCode,
|
|
|
|
"msg": error.ErrFailApiKeyMsg,
|
|
|
|
})
|
2019-08-25 15:22:37 +08:00
|
|
|
} else {
|
|
|
|
// 判断是否为 RPC 客户端
|
|
|
|
if is.Rpc() {
|
|
|
|
go client.ReportResult("PLUG", name, ip, info, "0")
|
|
|
|
} else {
|
|
|
|
go report.ReportPlugWeb(name, "本机", ip, info)
|
|
|
|
}
|
|
|
|
|
2019-09-02 19:12:46 +08:00
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
"code": error.ErrSuccessCode,
|
|
|
|
"msg": error.ErrSuccessMsg,
|
|
|
|
})
|
2019-08-25 15:22:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 获取黑名单 黑客IP 列表
|
2019-08-09 10:13:54 +08:00
|
|
|
func GetIpList(c *gin.Context) {
|
2019-09-02 19:12:46 +08:00
|
|
|
result, err := dbUtil.DB().Table("hfish_info").Fields("ip").GroupBy("ip").Get()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Pr("API", "127.0.0.1", "查询黑名单IP列表失败", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
"code": error.ErrSuccessCode,
|
|
|
|
"msg": error.ErrSuccessMsg,
|
|
|
|
"data": result,
|
|
|
|
})
|
2019-08-09 10:13:54 +08:00
|
|
|
}
|
2019-08-25 01:00:42 +08:00
|
|
|
|
2019-08-25 15:22:37 +08:00
|
|
|
// 获取钓鱼列表 API
|
2019-08-25 01:00:42 +08:00
|
|
|
func GetFishInfo(c *gin.Context) {
|
2019-09-02 19:12:46 +08:00
|
|
|
result, err := dbUtil.DB().Table("hfish_info").OrderBy("id desc").Get()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Pr("API", "127.0.0.1", "获取钓鱼列表失败", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
"code": error.ErrSuccessCode,
|
|
|
|
"msg": error.ErrSuccessMsg,
|
|
|
|
"data": result,
|
|
|
|
})
|
2019-08-25 01:00:42 +08:00
|
|
|
}
|