HFish/core/report/report.go

89 lines
3.1 KiB
Go
Raw Normal View History

2019-08-07 13:16:23 +08:00
package report
import (
"HFish/core/dbUtil"
"time"
"HFish/utils/ip"
2019-08-07 13:16:23 +08:00
)
2019-08-10 18:26:43 +08:00
// 上报 集群 状态
func ReportAgentStatus(agentName string, agentIp string, webStatus string, deepStatus string, sshStatus string, redisStatus string, mysqlStatus string, httpStatus string, telnetStatus string) {
sql := `
INSERT INTO hfish_colony (
agent_name,
agent_ip,
web_status,
deep_status,
ssh_status,
redis_status,
mysql_status,
http_status,
telnet_status,
last_update_time
)
VALUES
(?,?,?,?,?,?,?,?,?,?);
`
id := dbUtil.Insert(sql, agentName, agentIp, webStatus, deepStatus, sshStatus, redisStatus, mysqlStatus, httpStatus, telnetStatus, time.Now().Format("2006-01-02 15:04:05"))
// 如果 ID 等于0 代表 该数据以及存在
if id == 0 {
sql := `
UPDATE hfish_colony
SET agent_ip = ?, web_status = ?, deep_status = ?, ssh_status = ?, redis_status = ?, mysql_status = ?, http_status = ?, telnet_status = ?, last_update_time =?
WHERE
agent_name =?;
`
dbUtil.Update(sql, agentIp, webStatus, deepStatus, sshStatus, redisStatus, mysqlStatus, httpStatus, telnetStatus, time.Now().Format("2006-01-02 15:04:05"), agentName)
}
}
2019-08-07 13:16:23 +08:00
// 上报 WEB
2019-08-10 18:26:43 +08:00
func ReportWeb(projectName string, agent string, ipx string, info string) {
ipInfo := ip.Get(ipx)
sql := `INSERT INTO hfish_info(type,project_name,agent,ip,ip_info,info,create_time) values(?,?,?,?,?,?,?);`
dbUtil.Insert(sql, "WEB", projectName, agent, ipx, ipInfo, info, time.Now().Format("2006-01-02 15:04:05"))
}
// 上报 暗网 WEB
func ReportDeepWeb(projectName string, agent string, ipx string, info string) {
ipInfo := ip.Get(ipx)
2019-08-10 18:26:43 +08:00
sql := `INSERT INTO hfish_info(type,project_name,agent,ip,ip_info,info,create_time) values(?,?,?,?,?,?,?);`
dbUtil.Insert(sql, "DEEP", projectName, agent, ipx, ipInfo, info, time.Now().Format("2006-01-02 15:04:05"))
2019-08-07 13:16:23 +08:00
}
// 上报 SSH
2019-08-10 18:26:43 +08:00
func ReportSSH(ipx string, agent string, info string) {
ipInfo := ip.Get(ipx)
2019-08-10 18:26:43 +08:00
sql := `INSERT INTO hfish_info(type,project_name,agent,ip,ip_info,info,create_time) values(?,?,?,?,?,?,?);`
dbUtil.Insert(sql, "SSH", "SSH钓鱼", agent, ipx, ipInfo, info, time.Now().Format("2006-01-02 15:04:05"))
2019-08-07 13:16:23 +08:00
}
// 上报 Redis
2019-08-10 18:26:43 +08:00
func ReportRedis(ipx string, agent string, info string) int64 {
ipInfo := ip.Get(ipx)
2019-08-10 18:26:43 +08:00
sql := `INSERT INTO hfish_info(type,project_name,agent,ip,ip_info,info,create_time) values(?,?,?,?,?,?,?);`
return dbUtil.Insert(sql, "REDIS", "Redis钓鱼", agent, ipx, ipInfo, info, time.Now().Format("2006-01-02 15:04:05"))
2019-08-07 13:16:23 +08:00
}
// 更新 Redis 操作
2019-08-10 18:26:43 +08:00
func ReportUpdateRedis(id string, info string) {
2019-08-07 13:16:23 +08:00
sql := `UPDATE hfish_info SET info = info||? WHERE id = ?;`
dbUtil.Update(sql, info, id)
}
// 上报 Mysql
2019-08-10 18:26:43 +08:00
func ReportMysql(ipx string, agent string, info string) int64 {
ipInfo := ip.Get(ipx)
2019-08-10 18:26:43 +08:00
sql := `INSERT INTO hfish_info(type,project_name,agent,ip,ip_info,info,create_time) values(?,?,?,?,?,?,?);`
return dbUtil.Insert(sql, "MYSQL", "Mysql钓鱼", agent, ipx, ipInfo, info, time.Now().Format("2006-01-02 15:04:05"))
2019-08-07 13:16:23 +08:00
}
// 更新 Redis 操作
2019-08-10 18:26:43 +08:00
func ReportUpdateMysql(id string, info string) {
2019-08-07 13:16:23 +08:00
sql := `UPDATE hfish_info SET info = info||? WHERE id = ?;`
dbUtil.Update(sql, info, id)
}