Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the parameter error issue of the uprobe type hook. #665

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion COMPILATION_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

# 编译方法

针对个别程序使用的openssl类库是静态编译,也可以自行修改源码实现。若函数名不在符号表里,也可以自行反编译找到函数的offset偏移地址,填写到`UprobeOffset`
针对个别程序使用的openssl类库是静态编译,也可以自行修改源码实现。若函数名不在符号表里,也可以自行反编译找到函数的offset偏移地址,填写到
`Uaddress`
属性上,进行编译。
笔者环境`ubuntu 21.04`, Linux Kernel 4.18以上通用。
**推荐使用`UBUNTU 20.04` 及以上版本的Linux测试。**
Expand Down
9 changes: 6 additions & 3 deletions pkg/event_processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package event_processor

import (
"errors"
"fmt"
"github.com/gojue/ecapture/user/event"
"io"
Expand Down Expand Up @@ -64,8 +63,9 @@ func (ep *EventProcessor) Serve() error {
case eventStruct := <-ep.incoming:
err = ep.dispatch(eventStruct)
if err != nil {
err1 := ep.Close()
return errors.Join(err, err1)
//err1 := ep.Close()
//return errors.Join(err, err1)
return err
}
case s := <-ep.outComing:
_, _ = ep.GetLogger().Write([]byte(s))
Expand Down Expand Up @@ -141,6 +141,9 @@ func (ep *EventProcessor) Write(e event.IEventStruct) {
func (ep *EventProcessor) Close() error {
ep.Lock()
defer ep.Unlock()
if ep.isClosed {
return nil
}
ep.isClosed = true
close(ep.closeChan)
close(ep.incoming)
Expand Down
2 changes: 1 addition & 1 deletion user/module/probe_bash.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (b *MBashProbe) setupManagers() {
Section: "uretprobe/bash_readline",
EbpfFuncName: "uretprobe_bash_readline",
AttachToFuncName: readlineFuncName,
//UprobeOffset: 0x8232, //若找不到 readline 函数,则使用offset偏移地址方式。
//UAddress: 0x8232, //若找不到 readline 函数,则使用offset偏移地址方式。
BinaryPath: binaryPath, // 可能是 /bin/bash 也可能是 readline.so的真实地址
},
{
Expand Down
5 changes: 2 additions & 3 deletions user/module/probe_gotls_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ func (g *GoTLSProbe) setupManagersText() error {
EbpfFuncName: readFn,
AttachToFuncName: config.GoTlsReadFunc,
BinaryPath: g.path,
//UprobeOffset: uint64(v),
UAddress: uint64(v),
UID: uid,
UAddress: uint64(v),
UID: uid,
})
}
g.bpfManagerOptions = manager.Options{
Expand Down
14 changes: 7 additions & 7 deletions user/module/probe_mysqld.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ func (m *MMysqldProbe) setupManagers() error {
Section: "uprobe/dispatch_command_57",
EbpfFuncName: "mysql57_query",
AttachToFuncName: attachFunc,
UprobeOffset: offset,
UAddress: offset,
BinaryPath: binaryPath,
},
{
Section: "uretprobe/dispatch_command_57",
EbpfFuncName: "mysql57_query_return",
AttachToFuncName: attachFunc,
UprobeOffset: offset,
UAddress: offset,
BinaryPath: binaryPath,
},
}
Expand All @@ -153,14 +153,14 @@ func (m *MMysqldProbe) setupManagers() error {
Section: "uprobe/dispatch_command_57", //TODO CHANGE to mysqld80 @CFC4N
EbpfFuncName: "mysql57_query",
AttachToFuncName: attachFunc,
UprobeOffset: offset,
UAddress: offset,
BinaryPath: binaryPath,
},
{
Section: "uretprobe/dispatch_command_57",
EbpfFuncName: "mysql57_query_return",
AttachToFuncName: attachFunc,
UprobeOffset: offset,
UAddress: offset,
BinaryPath: binaryPath,
},
}
Expand All @@ -170,14 +170,14 @@ func (m *MMysqldProbe) setupManagers() error {
Section: "uprobe/dispatch_command",
EbpfFuncName: "mysql56_query",
AttachToFuncName: attachFunc,
UprobeOffset: offset,
UAddress: offset,
BinaryPath: binaryPath,
},
{
Section: "uretprobe/dispatch_command",
EbpfFuncName: "mysql56_query_return",
AttachToFuncName: attachFunc,
UprobeOffset: offset,
UAddress: offset,
BinaryPath: binaryPath,
},
}
Expand All @@ -193,7 +193,7 @@ func (m *MMysqldProbe) setupManagers() error {
}

m.logger.Info().Str("binrayPath", binaryPath).Str("FunctionName", attachFunc).
Str("Version", versionInfo).Uint64("UprobeOffset", offset).Msg("Mysql Probe Hooked")
Str("Version", versionInfo).Uint64("UAddress", offset).Msg("Mysql Probe Hooked")
m.bpfManagerOptions = manager.Options{
DefaultKProbeMaxActive: 512,

Expand Down
6 changes: 3 additions & 3 deletions user/module/probe_openssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ const (
DefaultAddr = "0.0.0.0"
// OpenSSL the classes of BIOs
// https://github.com/openssl/openssl/blob/openssl-3.0.0/include/openssl/bio.h.in
BIO_TYPE_DESCRIPTOR = 0x0100
BIO_TYPE_SOURCE_SINK = 0x0400
BioTypeDescriptor = 0x0100
BioTypeSourceSink = 0x0400
)

type Tls13MasterSecret struct {
Expand Down Expand Up @@ -653,7 +653,7 @@ func (m *MOpenSSLProbe) Dispatcher(eventStruct event.IEventStruct) {

func (m *MOpenSSLProbe) dumpSslData(eventStruct *event.SSLDataEvent) {
// BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR = 0x0400|0x0100 = 1280
if eventStruct.Fd <= 0 && eventStruct.BioType > BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR {
if eventStruct.Fd <= 0 && eventStruct.BioType > BioTypeSourceSink|BioTypeDescriptor {
m.logger.Error().Uint32("pid", eventStruct.Pid).Uint32("fd", eventStruct.Fd).Str("address", eventStruct.Addr).Msg("SSLDataEvent's fd is 0")
//return
}
Expand Down
Loading