daeuniverse / dae

eBPF-based Linux high-performance transparent proxy solution.
GNU Affero General Public License v3.0
2.62k stars 165 forks source link

fix: cannot sniff tls fragments #555

Open mzz2017 opened 1 week ago

mzz2017 commented 1 week ago

Background

Under special circumstances, TCP TLS client hello may be sent in multiple fragments. The current dae will always use the first fragment for sniffing, which will cause the failed integrity check of TLS client hello and failed sniffing.

0.5.1 and previous versions, for some reasons, multiple skb will be merged and read by dae. After 0.6.0, due to the introduction of interface dae0, skb is read separately, exposing this issue.

This PR will support multiple reads within the sniffing_timeout time to obtain a complete client hello and to sniff domain name from it.

Checklist

Full Changelogs

Issue Reference

Related #509

Test Result

umlka commented 1 week ago

Actions 里面拿的 PR Build (Preview)版本

panic: close of nil channel
goroutine 137 [running]:
github.com/daeuniverse/dae/component/sniffing.(*Sniffer).SniffUdp(0xc00218b340)
        github.com/daeuniverse/dae/component/sniffing/sniffer.go:172 +0x16d
github.com/daeuniverse/dae/control.(*ControlPlane).handlePkt(0xc000878480, 0xc000136508, {0xc005ddc000, 0x4ce, 0x800}, {{{0xc0021d3f40?, 0x452826?}, 0xc000128048?}, 0x2?}, {{{0x2607f8b040070815, ...}, ...}, ...}, ...)
        github.com/daeuniverse/dae/control/udp.go:111 +0xb35
github.com/daeuniverse/dae/control.(*ControlPlane).Serve.func5.1()
        github.com/daeuniverse/dae/control/control_plane.go:795 +0x393
github.com/daeuniverse/dae/control.(*UdpTaskPool).convoy(0xc00086c870?, 0xc0015e0390)
        github.com/daeuniverse/dae/control/udp_task_pool.go:58 +0x23
created by github.com/daeuniverse/dae/control.(*UdpTaskPool).EmitTask in goroutine 42
        github.com/daeuniverse/dae/control/udp_task_pool.go:86 +0x289
dae.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
dae.service: Failed with result 'exit-code'.
dae.service: Consumed 7.472s CPU time.
wanlce commented 1 week ago

daed 编译此PR版

name= policy=fixed qtype=AAAA
Jun 20 09:01:20 Blade15Pro daed[1366]: panic: close of nil channel
Jun 20 09:01:20 Blade15Pro daed[1366]: goroutine 1307 [running]:
Jun 20 09:01:20 Blade15Pro daed[1366]: github.com/daeuniverse/dae/component/sniffing.(*Sniffer).SniffUdp(0xc001289ad0)
Jun 20 09:01:20 Blade15Pro daed[1366]:         github.com/daeuniverse/dae@v0.2.0/component/sniffing/sniffer.go:172 +0x16d
Jun 20 09:01:20 Blade15Pro daed[1366]: github.com/daeuniverse/dae/control.(*ControlPlane).handlePkt(0xc0014d6c60, 0xc00008a710, {0xc00220d000, 0x4e2, 0x800}, {{{0xc002d55f40?, 0x454a26?}, 0xc000012048?}, 0x2?}, {{{0x0, ...}, ...}, ...}, ...)
Jun 20 09:01:20 Blade15Pro daed[1366]:         github.com/daeuniverse/dae@v0.2.0/control/udp.go:111 +0xb35
Jun 20 09:01:20 Blade15Pro daed[1366]: github.com/daeuniverse/dae/control.(*ControlPlane).Serve.func5.1()
Jun 20 09:01:20 Blade15Pro daed[1366]:         github.com/daeuniverse/dae@v0.2.0/control/control_plane.go:795 +0x393
Jun 20 09:01:20 Blade15Pro daed[1366]: github.com/daeuniverse/dae/control.(*UdpTaskPool).convoy(0xc003428678?, 0xc0029c3290)
Jun 20 09:01:20 Blade15Pro daed[1366]:         github.com/daeuniverse/dae@v0.2.0/control/udp_task_pool.go:58 +0x23
Jun 20 09:01:20 Blade15Pro daed[1366]: created by github.com/daeuniverse/dae/control.(*UdpTaskPool).EmitTask in goroutine 1154
Jun 20 09:01:20 Blade15Pro daed[1366]:         github.com/daeuniverse/dae@v0.2.0/control/udp_task_pool.go:86 +0x289
Jun 20 09:01:20 Blade15Pro systemd[1]: daed.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
dae-prow[bot] commented 4 days ago

❌ Your branch is currently out-of-sync to main. No worry, I will fix it for you.

mzz2017 commented 4 days ago

@umlka @wanlce Thanks so much for your testing. I tried to fix it in https://github.com/daeuniverse/dae/pull/555/commits/704a7ccc8ac7449085bf4f475df46b011b27b54b. Could you please test it again?

umlka commented 4 days ago

@umlka @wanlce Thanks so much for your testing. I tried to fix it in 704a7cc. Could you please test it again?

现在测试没有panic了