Skip to content

Commit

Permalink
完善邮件通知
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjinhub committed Aug 12, 2019
1 parent 12daac0 commit 6279cc3
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 809 deletions.
8 changes: 7 additions & 1 deletion admin/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@
<div class="tab-content">
<div class="tab-pane fade in active" id="home-2">
<div class="timeline-2">
<div class="time-item">
<div class="item-info">
<small class="text-muted">2019-08-12</small>
<p>发布 v0.2 版本</p>
</div>
</div>
<div class="time-item">
<div class="item-info">
<small class="text-muted">2019-08-05</small>
<p>发布第一版</p>
<p>发布 v0.1 版本</p>
</div>
</div>
<div class="time-item">
Expand Down
2 changes: 1 addition & 1 deletion admin/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<a class="nav-link dropdown-toggle arrow-none waves-effect waves-light nav-user"
data-toggle="dropdown" href="#" role="button"
aria-haspopup="false" aria-expanded="false">
<img src="/static/images/avatar.png" alt="user" class="img-circle">
<img src="/static/images/avatar.png" alt="user" class="img-circle avatarx">
</a>
<div class="dropdown-menu dropdown-menu-right dropdown-arrow profile-dropdown "
aria-labelledby="Preview">
Expand Down
40 changes: 31 additions & 9 deletions admin/setting.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@
color: #ff5d48 !important;
margin-right: 5px;
}

.label {
line-height: 11px;
}

.yes_config {
border: 1px solid #0f8ce6;
padding: 2px 5px;
border-radius: 5px;
color: #0f8ce6;
font-size: 12px;
}

.no_config {
border: 1px solid #434e56;
padding: 2px 5px;
border-radius: 5px;
color: #434e56;
font-size: 12px;
}
</style>
<div class="row">
<!-- Page-Title -->
Expand All @@ -41,13 +61,13 @@ <h4 class="page-title">系统设置</h4>
<tbody id="tableList">
{{range $i, $e := .dataList}}
<tr>
<td style="font-weight: bold;">{{$e.setting_name}} </td>
<td style="font-weight: bold;"><span class="label label-primary">{{$e.setting_name}}</span></td>
<td>{{$e.setting_dis}}</td>
<td>{{$e.update_time}}</td>
<td>{{if ne $e.info ""}}
已配置
<span class="yes_config">已配置</span>
{{else}}
未配置
<span class="no_config">未配置</span>
{{end}}
</td>
<td><input type="checkbox" id="checkbox-{{$e.id}}" data-plugin="switchery"
Expand Down Expand Up @@ -126,15 +146,17 @@ <h4 class="modal-title" id="myModalLabel">E-mail 通知设置</h4>
</div>
<div class="form-group">
<label for=""><span class="text-danger">*</span>SMTP</label>
<input type="text" class="form-control" id="alertHost" name="alertHost" placeholder="例:smtp.126.com">
<input type="text" class="form-control" id="alertHost" name="alertHost"
placeholder="例:smtp.126.com">
</div>
<div class="form-group">
<label for=""><span class="text-danger">*</span>端口</label>
<input type="number" class="form-control" id="alertPort" name="alertPort" placeholder="例:465">
</div>
<div class="form-group">
<label for=""><span class="text-danger">*</span>接收人</label>
<textarea class="form-control" id="receive" name="receive" placeholder="接收人(群发请换行)" cols="30" rows="10"></textarea>
<textarea class="form-control" id="receive" name="receive" placeholder="接收人(群发请换行)" cols="30"
rows="10"></textarea>
</div>
</div>
<div class="modal-footer">
Expand Down Expand Up @@ -179,13 +201,13 @@ <h4 class="modal-title" id="myModalLabel">E-mail 通知设置</h4>
} else if (arr.length == 2 && result.data[0].type == "login") {
$("#loginName").val(arr[0])
$("#loginPwd").val(arr[1])
}else if (arr.length>=4&&result.data[0].type=="alertMail"){
} else if (arr.length >= 4 && result.data[0].type == "alertMail") {
$("#alertEmail").val(arr[2])
$("#alertPass").val(arr[3])
$("#alertHost").val(arr[0])
$("#alertPort").val(arr[1])
var emailArr=arr.splice(4)
var content= emailArr.join("\n")
var emailArr = arr.splice(4)
var content = emailArr.join("\n")
$("#receive").text(content)
}
}
Expand Down Expand Up @@ -227,7 +249,7 @@ <h4 class="modal-title" id="myModalLabel">E-mail 通知设置</h4>
pass: $("#alertPass").val(),
host: $("#alertHost").val(),
port: $("#alertPort").val(),
receive:$("#receive").val().split(/[\s\n]/).join(","),
receive: $("#receive").val().split(/[\s\n]/).join(","),
id: $("#settingId").val()
};
console.log(params)
Expand Down
4 changes: 2 additions & 2 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static = wordPress/static # WEB 静态文件路径 注意:
url = / # WEB 访问目录,默认 / 可更改成 index.html index.asp index.php

[deep]
status = 1 # 是否启动 暗网 1 启动 0 关闭, 启动 API 后 方可上报结果
status = 0 # 是否启动 暗网 1 启动 0 关闭, 启动 API 后 方可上报结果
addr = 0.0.0.0:9002 # 暗网 WEB 启动地址
template = deep/html # 暗网 WEB 模板路径
index = index.html # 暗网 WEB 首页文件
Expand All @@ -48,5 +48,5 @@ status = 0 # 是否启动 Telnet 1 启动 0
addr = 0.0.0.0:23 # Telnet 服务端地址 注意端口冲突

[ftp]
status = 0 # 是否启动 Ftp 1 启动 0 关闭
status = 1 # 是否启动 Ftp 1 启动 0 关闭
addr = 0.0.0.0:21 # Ftp 服务端地址 注意端口冲突
35 changes: 35 additions & 0 deletions core/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,36 @@ import (
"HFish/core/dbUtil"
"time"
"HFish/utils/ip"
"strings"
"HFish/utils/send"
"strconv"
)

func alert(title string, agent string, ipx string, infox string) {
sql := `select status,info from hfish_setting where type = "alertMail"`
isAlertStatus := dbUtil.Query(sql)

status := strconv.FormatInt(isAlertStatus[0]["status"].(int64), 10)

// 判断是否启用通知
if status == "1" {
info := isAlertStatus[0]["info"]
config := strings.Split(info.(string), "&&")

text := `
<div><b>Hi,上钩了!</b></div>
<div><b><br /></b></div>
<div><b>集群名称:</b>` + agent + `</div>
<div><b>攻击IP:</b>` + ipx + `</div>
<div><b>上钩内容:</b>` + infox + `</div>
<div><br /></div>
<div><span style="color: rgb(128, 128, 128); font-size: 10px;">(HFish 自动发送)</span></div>
`

send.SendMail(config[4:], "[HFish]提醒你,"+title+"有鱼上钩!", text, config)
}
}

// 上报 集群 状态
func ReportAgentStatus(agentName string, agentIp string, webStatus string, deepStatus string, sshStatus string, redisStatus string, mysqlStatus string, httpStatus string, telnetStatus string, ftpStatus string) {
sql := `
Expand Down Expand Up @@ -46,26 +74,30 @@ 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"))
go alert("WEB", agent, ipx, info)
}

// 上报 暗网 WEB
func ReportDeepWeb(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, "DEEP", projectName, agent, ipx, ipInfo, info, time.Now().Format("2006-01-02 15:04:05"))
go alert("DEEP", agent, ipx, info)
}

// 上报 SSH
func ReportSSH(ipx string, agent 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, "SSH", "SSH蜜罐", agent, ipx, ipInfo, info, time.Now().Format("2006-01-02 15:04:05"))
go alert("SSH", agent, ipx, info)
}

// 上报 Redis
func ReportRedis(ipx string, agent string, info string) int64 {
ipInfo := ip.Get(ipx)
sql := `INSERT INTO hfish_info(type,project_name,agent,ip,ip_info,info,create_time) values(?,?,?,?,?,?,?);`
go alert("REDIS", agent, ipx, info)
return dbUtil.Insert(sql, "REDIS", "Redis蜜罐", agent, ipx, ipInfo, info, time.Now().Format("2006-01-02 15:04:05"))
}

Expand All @@ -79,6 +111,7 @@ func ReportUpdateRedis(id string, info string) {
func ReportMysql(ipx string, agent string, info string) int64 {
ipInfo := ip.Get(ipx)
sql := `INSERT INTO hfish_info(type,project_name,agent,ip,ip_info,info,create_time) values(?,?,?,?,?,?,?);`
go alert("MYSQL", agent, ipx, info)
return dbUtil.Insert(sql, "MYSQL", "Mysql蜜罐", agent, ipx, ipInfo, info, time.Now().Format("2006-01-02 15:04:05"))
}

Expand All @@ -93,12 +126,14 @@ func ReportFTP(ipx string, agent 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, "FTP", "FTP蜜罐", agent, ipx, ipInfo, info, time.Now().Format("2006-01-02 15:04:05"))
go alert("FTP", agent, ipx, info)
}

// 上报 Telnet
func ReportTelnet(ipx string, agent string, info string) int64 {
ipInfo := ip.Get(ipx)
sql := `INSERT INTO hfish_info(type,project_name,agent,ip,ip_info,info,create_time) values(?,?,?,?,?,?,?);`
go alert("TELNET", agent, ipx, info)
return dbUtil.Insert(sql, "TELNET", "Telnet蜜罐", agent, ipx, ipInfo, info, time.Now().Format("2006-01-02 15:04:05"))
}

Expand Down
Binary file modified db/hfish.db
Binary file not shown.
7 changes: 7 additions & 0 deletions error/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,10 @@ func ErrLoginFail() map[string]interface{} {
"msg": "账号密码不正确",
}
}

func ErrEmailFail() map[string]interface{} {
return gin.H{
"code": 1003,
"msg": "邮箱未启用",
}
}
Loading

0 comments on commit 6279cc3

Please sign in to comment.