-
Notifications
You must be signed in to change notification settings - Fork 838
/
probe_gotls_keylog.go
121 lines (106 loc) · 3.23 KB
/
probe_gotls_keylog.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright 2022 CFC4N <cfc4n.cs@gmail.com>. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package module
import (
"errors"
"github.com/cilium/ebpf"
manager "github.com/gojue/ebpfmanager"
"github.com/gojue/ecapture/user/config"
"github.com/gojue/ecapture/user/event"
"golang.org/x/sys/unix"
"math"
"strings"
)
func (g *GoTLSProbe) setupManagersKeylog() error {
var gotlsConf = g.conf.(*config.GoTLSConfig)
var buildInfo = new(strings.Builder)
for _, setting := range gotlsConf.Buildinfo.Settings {
if setting.Value == "" {
continue
}
buildInfo.WriteString(" ")
buildInfo.WriteString(setting.Key)
buildInfo.WriteString("=")
buildInfo.WriteString(setting.Value)
}
g.logger.Printf("%s\tHOOK type:Golang elf, binrayPath:%s\n", g.Name(), g.path)
g.logger.Printf("%s\tGolang buildInfo version:%s, Params: %s\n", g.Name(), gotlsConf.Buildinfo.GoVersion, buildInfo.String())
if gotlsConf.IsPieBuildMode {
// buildmode pie is enabled.
g.logger.Printf("%s\tGolang elf buildmode with pie\n", g.Name())
}
g.logger.Printf("%s\tHook masterKey function:%s, Address:%x \n", g.Name(), config.GoTlsMasterSecretFunc, gotlsConf.GoTlsMasterSecretAddr)
var (
sec string
fn string
)
if g.isRegisterABI {
sec = "uprobe/gotls_mastersecret_register"
fn = "gotls_mastersecret_register"
} else {
sec = "uprobe/gotls_mastersecret_stack"
fn = "gotls_mastersecret_stack"
}
g.bpfManager = &manager.Manager{
Probes: []*manager.Probe{
// gotls master secrets
{
Section: sec,
EbpfFuncName: fn,
AttachToFuncName: config.GoTlsMasterSecretFunc,
BinaryPath: g.path,
UID: "uprobe_gotls_master_secret",
UAddress: g.conf.(*config.GoTLSConfig).GoTlsMasterSecretAddr,
},
},
Maps: []*manager.Map{
{
Name: "mastersecret_go_events",
},
},
}
g.bpfManagerOptions = manager.Options{
DefaultKProbeMaxActive: 512,
VerifierOptions: ebpf.CollectionOptions{
Programs: ebpf.ProgramOptions{
LogSize: 2097152,
},
},
RLimit: &unix.Rlimit{
Cur: math.MaxUint64,
Max: math.MaxUint64,
},
}
if g.conf.EnableGlobalVar() {
// 填充 RewriteContants 对应map
g.bpfManagerOptions.ConstantEditors = g.constantEditor()
}
return nil
}
func (g *GoTLSProbe) initDecodeFunKeylog() error {
// master secrets map at ebpf code
MasterkeyEventsMap, found, err := g.bpfManager.GetMap("mastersecret_go_events")
if err != nil {
return err
}
if !found {
return errors.New("cant found map:mastersecret_events")
}
g.eventMaps = append(g.eventMaps, MasterkeyEventsMap)
var masterkeyEvent event.IEventStruct
// goTLS Event struct
masterkeyEvent = &event.MasterSecretGotlsEvent{}
g.eventFuncMaps[MasterkeyEventsMap] = masterkeyEvent
return nil
}