简单几行实现sliver上线提醒

准备魔改sliver去掉一些特征什么的,这里记录一下最简单实现上线消息通过企业微信机器人提醒的方式,这很简单也有很多不足还需要接着改的

protobuf中对消息Beacon和Session的定义如下,要显示的几个信息都是string类型的。

image

最好这里另外写一个消息类型(NotifyMsg),将要显示的消息字段放进去,然后这里Session和Beacon的相应部分就直接写NotifyMsg notify = 1; 这样写发送函数的时候,传参就可以直接写msg *clientpb.NotifyMsg了。不过又要重新生成proto文件了,简单一点就是直接一个个传了:

func sendMsgToBot(id, name, ip, hostname, arch, os, checkIn string) {}

机器人转发消息,用到的是一个封装好了的api:electricbubble/wecom-bot-api: 企业微信-群机器人-API (githubfast.com),这里面给了很详细的文档且支持markdown的形式发送,不过微信中不支持显示这样的类型:

8cd4bdfba07bb937b4c3b1173bb4470

所以就用最简单的text,按照他的demo来就行,如下:

func sendMsgToBot(id, name, ip, hostname, arch, os, checkIn string) {
	botKey := "8ad64........"  //这里填机器人的key 
	bot := botApi.NewWeComBot(botKey)
	message := fmt.Sprintf(
		" Karplin上线提醒\n 标识序号: %s\n 机器名称: %s\n 机器IP: %s\n 用户名: %s\n 架构: %s\n 系统版本: %s\n 上线时间: %s\n 请注意查收",
		id, name, ip, hostname, arch, os, checkIn)

	_ = bot.PushTextMessage(message)
}

机器人的key移动端和pc端都能看,自己在群聊里面建一个机器人就能看到:

image

针对session和beacon上线提醒的两个位置:

		case consts.SessionOpenedEvent:
			session := event.Session
			currentTime := time.Now().Format(time.RFC1123)
			shortID := strings.Split(session.ID, "-")[0]
			con.PrintEventInfof("Session %s %s - %s (%s) - %s/%s - %v",
				shortID, session.Name, session.RemoteAddress, session.Hostname, session.OS, session.Arch, currentTime)

			// Prelude Operator
			if prelude.ImplantMapper != nil {
				err = prelude.ImplantMapper.AddImplant(session, nil)
				if err != nil {
					con.PrintErrorf("Could not add session to Operator: %s", err)
				}
			}

			go sendMsgToBot(shortID, session.Name, session.RemoteAddress, session.Hostname, session.Arch, session.OS, currentTime)

// beacon上线
case consts.BeaconRegisteredEvent:
			beacon := &clientpb.Beacon{}
			proto.Unmarshal(event.Data, beacon)
			currentTime := time.Now().Format(time.RFC1123)
			shortID := strings.Split(beacon.ID, "-")[0]
			con.PrintEventInfof("Beacon %s %s - %s (%s) - %s/%s - %v",
				shortID, beacon.Name, beacon.RemoteAddress, beacon.Hostname, beacon.OS, beacon.Arch, currentTime)

			// Prelude Operator
			if prelude.ImplantMapper != nil {
				err = prelude.ImplantMapper.AddImplant(beacon, func(taskID string, cb func(*clientpb.BeaconTask)) {
					con.AddBeaconCallback(taskID, cb)
				})
				if err != nil {
					con.PrintEventErrorf("Could not add beacon to Operator: %s", err)
				}
			}
			echoed = true

			go sendMsgToBot(shortID, beacon.Name, beacon.RemoteAddress, beacon.Hostname, beacon.Arch, beacon.OS, currentTime)

编译完运行,开启监听后就生成session的,懒得再开一个win10就直接宿主机执行了

image

然后此时会收到企业微信机器人的提醒了,企业微信绑定了个人的微信的话,就像下面状态栏那里微信也会同时有提醒的。

901e2c1ac85833fb3ef8307ea804ca5

sliver这边也能看到信息。

image

后续这个还有很多能改进的,除了上面说的新增一个消息类型来提高复用,还可以扩展钉钉、飞书那些平台的。机器人的key也最好是从配置文件里面读,这篇只是抛砖引玉,后续再改进

posted @ 2023-12-21 17:26  lockly  阅读(155)  评论(0编辑  收藏  举报