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

kern: capture https plaintext failed with boringssl TLS 1.3 on android #271 #279

Merged
merged 13 commits into from
Dec 10, 2022
Prev Previous commit
Next Next commit
remove libPthread shared-object lib.
Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
  • Loading branch information
cfc4n committed Dec 10, 2022
commit 1252dff78ff905a68dd63a57c047bfae2ea147c8
1 change: 0 additions & 1 deletion cli/cmd/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func init() {
opensslCmd.PersistentFlags().StringVar(&gc.Curlpath, "wget", "", "wget file path, default: /usr/bin/wget. (Deprecated)")
opensslCmd.PersistentFlags().StringVar(&nc.Firefoxpath, "firefox", "", "firefox file path, default: /usr/lib/firefox/firefox. (Deprecated)")
opensslCmd.PersistentFlags().StringVar(&nc.Nsprpath, "nspr", "", "libnspr44.so file path, will automatically find it from curl default.")
opensslCmd.PersistentFlags().StringVar(&oc.Pthread, "pthread", "", "libpthread.so file path, use to hook connect to capture socket FD.will automatically find it from curl. (Deprecated)")
opensslCmd.PersistentFlags().StringVar(&goc.Path, "gobin", "", "path to binary built with Go toolchain.")
opensslCmd.PersistentFlags().StringVarP(&oc.Write, "write", "w", "", "write the raw packets to file as pcapng format.")
opensslCmd.PersistentFlags().StringVarP(&oc.Ifname, "ifname", "i", "", "(TC Classifier) Interface name on which the probe will be attached.")
Expand Down
6 changes: 3 additions & 3 deletions user/config/config_openssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ package config
// 最终使用openssl参数
type OpensslConfig struct {
eConfig
Curlpath string `json:"curlPath"` //curl的文件路径
Openssl string `json:"openssl"`
Pthread string `json:"pThread"` // /lib/x86_64-linux-gnu/libpthread.so.0
Curlpath string `json:"curlPath"` //curl的文件路径
Openssl string `json:"openssl"`
//Pthread string `json:"pThread"` // /lib/x86_64-linux-gnu/libpthread.so.0
Write string `json:"write"` // Write the raw packets to file rather than parsing and printing them out.
Ifname string `json:"ifName"` // (TC Classifier) Interface name on which the probe will be attached.
Port uint16 `json:"port"` // capture port
Expand Down
11 changes: 1 addition & 10 deletions user/config/config_openssl_androidgki.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

const (
DEFAULT_OPENSSL_PATH = "/apex/com.android.conscrypt/lib64/libssl.so"
DEFAULT_LIBC_PATH = "/apex/com.android.runtime/lib64/bionic/libc.so"
//DEFAULT_LIBC_PATH = "/apex/com.android.runtime/lib64/bionic/libc.so"

DEFAULT_IFNAME = "wlan0"
)
Expand All @@ -43,15 +43,6 @@ func (this *OpensslConfig) Check() error {
this.Openssl = DEFAULT_OPENSSL_PATH
}

if this.Pthread != "" || len(strings.TrimSpace(this.Pthread)) > 0 {
_, e := os.Stat(this.Pthread)
if e != nil {
return e
}
} else {
this.Pthread = DEFAULT_LIBC_PATH
}

if this.Ifname == "" || len(strings.TrimSpace(this.Ifname)) == 0 {
this.Ifname = DEFAULT_IFNAME
}
Expand Down
81 changes: 2 additions & 79 deletions user/config/config_openssl_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
package config

import (
"debug/elf"
"errors"
"fmt"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -54,73 +52,9 @@ func (this *OpensslConfig) checkOpenssl() error {
return nil
}

func (this *OpensslConfig) checkConnect() error {
var sharedObjects = []string{
"libpthread.so.0", // ubuntu 21.04 server
"libc.so.6", // ubuntu 21.10 server
"libc.so", // Android
}

var funcName = ""
var found bool
for _, so := range sharedObjects {
pthreadSoPath, e := getDynPathByElf(this.Curlpath, so)
if e != nil {
_, e = os.Stat(X86_BINARY_PREFIX)
prefix := X86_BINARY_PREFIX
if e != nil {
prefix = OTHERS_BINARY_PREFIX
}
this.Pthread = filepath.Join(prefix, so)
_, e = os.Stat(this.Pthread)
if e != nil {
// search all of sharedObjects
//return e
continue
}
} else {
this.Pthread = pthreadSoPath
}

_elf, e := elf.Open(this.Pthread)
if e != nil {
//return e
continue
}

dynamicSymbols, err := _elf.DynamicSymbols()
if err != nil {
//return err
continue
}

//
for _, sym := range dynamicSymbols {
if sym.Name != "connect" {
continue
}
//fmt.Printf("\tsize:%d, name:%s, offset:%d\n", sym.Size, sym.Name, 0)
funcName = sym.Name
found = true
break
}

// if found
if found && funcName != "" {
break
}
}

//如果没找到,则报错。
if !found || funcName == "" {
return errors.New(fmt.Sprintf("cant found 'connect' function to hook in files::%v", sharedObjects))
}
return nil
}

func (this *OpensslConfig) Check() error {
this.IsAndroid = false
var checkedOpenssl, checkedConnect bool
var checkedOpenssl bool
// 如果readline 配置,且存在,则直接返回。
if this.Openssl != "" || len(strings.TrimSpace(this.Openssl)) > 0 {
_, e := os.Stat(this.Openssl)
Expand All @@ -142,19 +76,11 @@ func (this *OpensslConfig) Check() error {
this.Curlpath = "/usr/bin/curl"
}

if this.Pthread != "" || len(strings.TrimSpace(this.Pthread)) > 0 {
_, e := os.Stat(this.Pthread)
if e != nil {
return e
}
checkedConnect = true
}

if this.Ifname == "" || len(strings.TrimSpace(this.Ifname)) == 0 {
this.Ifname = DEFAULT_IFNAME
}

if checkedConnect && checkedOpenssl {
if checkedOpenssl {
return nil
}

Expand All @@ -169,8 +95,5 @@ func (this *OpensslConfig) Check() error {
}
}

if !checkedConnect {
return this.checkConnect()
}
return nil
}
7 changes: 1 addition & 6 deletions user/module/probe_openssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func (this *MOpenSSLProbe) constantEditor() []manager.ConstantEditor {
}

func (this *MOpenSSLProbe) setupManagersUprobe() error {
var binaryPath, libPthread, sslVersion string
var binaryPath, sslVersion string
sslVersion = this.conf.(*config.OpensslConfig).SslVersion
sslVersion = strings.ToLower(sslVersion)
switch this.conf.(*config.OpensslConfig).ElfType {
Expand All @@ -296,17 +296,12 @@ func (this *MOpenSSLProbe) setupManagersUprobe() error {
}
}

libPthread = this.conf.(*config.OpensslConfig).Pthread
if libPthread == "" {
libPthread = "/lib/x86_64-linux-gnu/libpthread.so.0"
}
_, err := os.Stat(binaryPath)
if err != nil {
return err
}

this.logger.Printf("%s\tHOOK type:%d, binrayPath:%s\n", this.Name(), this.conf.(*config.OpensslConfig).ElfType, binaryPath)
this.logger.Printf("%s\tlibPthread so Path:%s\n", this.Name(), libPthread)
this.logger.Printf("%s\tlHook masterKey function:%s\n", this.Name(), this.masterHookFunc)

this.bpfManager = &manager.Manager{
Expand Down