Compare commits

..

100 Commits

Author SHA1 Message Date
renovate[bot]
12eee45448
[dependencies] Update golangci/golangci-lint-action action to v8 2025-05-29 05:02:01 +00:00
世界
06393297ba
documentation: Bump version 2025-05-29 12:13:43 +08:00
世界
7ec73b2ed9
Fix dns.client_subnet ignored 2025-05-29 12:13:43 +08:00
世界
59a0534935
documentation: Minor fixes 2025-05-29 12:13:43 +08:00
世界
589e82e580
Fix tailscale forward 2025-05-29 11:31:38 +08:00
世界
921788c68c
Minor fixes 2025-05-29 11:31:38 +08:00
世界
26c53bae0c
Update quic-go to v0.52.0 2025-05-29 11:31:37 +08:00
世界
1c52b006b7
Add SSM API service 2025-05-29 11:31:37 +08:00
世界
09a13daa23
Add resolved service and DNS server 2025-05-29 11:31:37 +08:00
世界
d82ad7fedc
Add DERP service 2025-05-29 11:31:37 +08:00
世界
8402221ba1
Add service component type 2025-05-29 11:31:36 +08:00
世界
2944239794
Fix tproxy tcp control 2025-05-29 11:31:36 +08:00
愚者
042b8ff82b
release: Fix build tags for android
Signed-off-by: 愚者 <11926619+FansChou@users.noreply.github.com>
2025-05-29 11:31:36 +08:00
世界
25814fe21f
prevent creation of bind and mark controls on unsupported platforms 2025-05-29 11:31:36 +08:00
PuerNya
123262b186
documentation: Fix description of reject DNS action behavior 2025-05-29 11:31:36 +08:00
Restia-Ashbell
548b6de50d
Fix TLS record fragment 2025-05-29 11:31:36 +08:00
世界
06b1193d4a
Add missing accept_routes option for Tailscale 2025-05-29 11:31:36 +08:00
世界
b03b545603
Add TLS record fragment support 2025-05-29 11:31:36 +08:00
世界
7506a29726
release: Update Go to 1.24.3 2025-05-29 11:31:35 +08:00
世界
25c1c62f0c
Fix set edns0 client subnet 2025-05-29 11:31:35 +08:00
世界
5500b89995
Update minor dependencies 2025-05-29 11:31:35 +08:00
世界
d8e3f3a60b
Update certmagic and providers 2025-05-29 11:31:35 +08:00
世界
222dfe8901
Update protobuf and grpc 2025-05-29 11:31:35 +08:00
世界
fa7637c193
Add control options for listeners 2025-05-29 11:31:34 +08:00
世界
0771862d49
Update quic-go to v0.51.0 2025-05-29 11:31:34 +08:00
世界
6ecbb9bcc3
Update utls to v1.7.2 2025-05-29 11:31:34 +08:00
世界
0f8fd06113
Handle EDNS version downgrade 2025-05-29 11:31:33 +08:00
世界
c1096c16ea
documentation: Fix anytls padding scheme description 2025-05-29 11:31:33 +08:00
安容
e00a962b44
Report invalid DNS address early 2025-05-29 11:31:33 +08:00
世界
88e652ea7e
Fix wireguard listen_port 2025-05-29 11:31:33 +08:00
世界
3c1db46a56
clash-api: Add more meta api 2025-05-29 11:31:33 +08:00
世界
35aebbd0d9
Fix DNS lookup 2025-05-29 11:31:32 +08:00
世界
a5d93d5e76
Fix fetch ECH configs 2025-05-29 11:31:32 +08:00
reletor
a3072de986
documentation: Minor fixes 2025-05-29 11:31:32 +08:00
caelansar
196d3f504d
Fix callback deletion in UDP transport 2025-05-29 11:31:32 +08:00
世界
ee94b071ea
documentation: Try to make the play review happy 2025-05-29 11:31:31 +08:00
世界
ee97743179
Fix missing handling of legacy domain_strategy options 2025-05-29 11:31:31 +08:00
世界
a6242b71b0
Improve local DNS server 2025-05-29 11:31:31 +08:00
anytls
d50b61fe4a
Update anytls
Co-authored-by: anytls <anytls>
2025-05-29 11:31:31 +08:00
世界
c29687000e
Fix DNS dialer 2025-05-29 11:31:30 +08:00
世界
0dfcb02301
release: Skip override version for iOS 2025-05-29 11:31:30 +08:00
iikira
0105ba6abc
Fix UDP DNS server crash
Signed-off-by: iikira <i2@mail.iikira.com>
2025-05-29 11:31:30 +08:00
ReleTor
b0737a64a8
Fix fetch ECH configs 2025-05-29 11:31:29 +08:00
世界
19ccb5177c
Allow direct outbounds without domain_resolver 2025-05-29 11:31:29 +08:00
世界
8236e8e7c1
Fix Tailscale dialer 2025-05-29 11:31:29 +08:00
dyhkwong
3320273dc1
Fix DNS over QUIC stream close 2025-05-29 11:31:29 +08:00
anytls
2af1ff50af
Update anytls
Co-authored-by: anytls <anytls>
2025-05-29 11:31:28 +08:00
Rambling2076
3c33b68945
Fix missing with_tailscale in Dockerfile
Signed-off-by: Rambling2076 <Rambling2076@proton.me>
2025-05-29 11:31:27 +08:00
世界
1268016b69
Fail when default DNS server not found 2025-05-29 11:31:27 +08:00
世界
714288d9a7
Update gVisor to 20250319.0 2025-05-29 11:31:27 +08:00
世界
4d8a730041
Explicitly reject detour to empty direct outbounds 2025-05-29 11:31:27 +08:00
世界
613947c2cb
Add netns support 2025-05-29 11:31:26 +08:00
世界
770ed26bd7
Add wildcard name support for predefined records 2025-05-29 11:31:26 +08:00
世界
429421f790
Remove map usage in options 2025-05-29 11:31:26 +08:00
世界
c7583322fd
Fix unhandled DNS loop 2025-05-29 11:31:26 +08:00
世界
9a2397e335
Add wildcard-sni support for shadow-tls inbound 2025-05-29 11:31:26 +08:00
k9982874
0110b5b7a3
Add ntp protocol sniffing 2025-05-29 11:31:04 +08:00
世界
d10b1c2f61
option: Fix marshal legacy DNS options 2025-05-29 11:29:59 +08:00
世界
8d9d1018bd
Make domain_resolver optional when only one DNS server is configured 2025-05-29 11:29:59 +08:00
世界
74da3ab5da
Fix DNS lookup context pollution 2025-05-29 11:29:59 +08:00
世界
08aff5e91f
Fix http3 DNS server connecting to wrong address 2025-05-29 11:29:59 +08:00
Restia-Ashbell
d345d0f9c9
documentation: Fix typo 2025-05-29 11:29:59 +08:00
anytls
1083a2dc4c
Update sing-anytls
Co-authored-by: anytls <anytls>
2025-05-29 11:29:59 +08:00
k9982874
a8f545f999
Fix hosts DNS server 2025-05-29 11:29:59 +08:00
世界
6fa07d175c
Fix UDP DNS server crash 2025-05-29 11:29:59 +08:00
世界
06eeb2a646
documentation: Fix missing ip_accept_any DNS rule option 2025-05-29 11:29:59 +08:00
世界
bd7a2a0a23
Fix anytls dialer usage 2025-05-29 11:29:58 +08:00
世界
e7a36bec01
Move predefined DNS server to rule action 2025-05-29 11:29:58 +08:00
世界
1d14183641
Fix domain resolver on direct outbound 2025-05-29 11:29:58 +08:00
Zephyruso
d923ef0f45
Fix missing AnyTLS display name 2025-05-29 11:29:58 +08:00
anytls
d3bd7d28e8
Update sing-anytls
Co-authored-by: anytls <anytls>
2025-05-29 11:29:58 +08:00
Estel
c20997b8a5
documentation: Fix typo
Signed-off-by: Estel <callmebedrockdigger@gmail.com>
2025-05-29 11:29:57 +08:00
TargetLocked
31ff14c6fd
Fix parsing legacy DNS options 2025-05-29 11:29:57 +08:00
世界
52519ec11b
Fix DNS fallback 2025-05-29 11:29:57 +08:00
世界
59da1edf75
documentation: Fix missing hosts DNS server 2025-05-29 11:29:57 +08:00
anytls
093ed494f0
Add MinIdleSession option to AnyTLS outbound
Co-authored-by: anytls <anytls>
2025-05-29 11:29:57 +08:00
ReleTor
955ec36005
documentation: Minor fixes 2025-05-29 11:29:57 +08:00
libtry486
5287e0c27f
documentation: Fix typo
fix typo

Signed-off-by: libtry486 <89328481+libtry486@users.noreply.github.com>
2025-05-29 11:29:57 +08:00
Alireza Ahmadi
6337660aa3
Fix Outbound deadlock 2025-05-29 11:29:56 +08:00
世界
a0677f0fc2
documentation: Fix AnyTLS doc 2025-05-29 11:29:56 +08:00
anytls
e3157a1a08
Add AnyTLS protocol 2025-05-29 11:29:56 +08:00
世界
c251af9008
Migrate to stdlib ECH support 2025-05-29 11:29:55 +08:00
世界
7c240ea0bd
Add fallback local DNS server for iOS 2025-05-29 11:29:55 +08:00
世界
252d9e2e9c
Get darwin local DNS server from libresolv 2025-05-29 11:29:55 +08:00
世界
e54fce5d35
Improve resolve action 2025-05-29 11:29:55 +08:00
世界
d5f605c844
Add back port hopping to hysteria 1 2025-05-29 11:29:54 +08:00
xchacha20-poly1305
0c618d751c
Remove single quotes of raw Moziila certs 2025-05-29 11:29:54 +08:00
世界
31d9d3abc8
Add Tailscale endpoint 2025-05-29 11:29:53 +08:00
世界
e2487e44f8
Build legacy binaries with latest Go 2025-05-29 11:29:53 +08:00
世界
17689c8895
documentation: Remove outdated icons 2025-05-29 11:29:53 +08:00
世界
567fd9f684
documentation: Certificate store 2025-05-29 11:29:53 +08:00
世界
9c8ab6ceac
documentation: TLS fragment 2025-05-29 11:29:53 +08:00
世界
75298736bd
documentation: Outbound domain resolver 2025-05-29 11:29:53 +08:00
世界
951490fdde
documentation: Refactor DNS 2025-05-29 11:29:52 +08:00
世界
8775bc012e
Add certificate store 2025-05-29 11:29:52 +08:00
世界
ad4ffc0808
Add TLS fragment support 2025-05-29 11:29:52 +08:00
世界
d12a838b8e
refactor: Outbound domain resolver 2025-05-29 11:29:52 +08:00
世界
ce8be9da99
refactor: DNS 2025-05-29 11:29:51 +08:00
世界
e981e3329a
Bump version 2025-05-27 14:30:07 +08:00
世界
83cf5f5c6a
Fix ws closed error message 2025-05-27 14:30:07 +08:00
11 changed files with 148 additions and 15 deletions

58
common/sniff/ntp.go Normal file
View File

@ -0,0 +1,58 @@
package sniff
import (
"context"
"encoding/binary"
"os"
"github.com/sagernet/sing-box/adapter"
C "github.com/sagernet/sing-box/constant"
)
func NTP(ctx context.Context, metadata *adapter.InboundContext, packet []byte) error {
// NTP packets must be at least 48 bytes long (standard NTP header size).
pLen := len(packet)
if pLen < 48 {
return os.ErrInvalid
}
// Check the LI (Leap Indicator) and Version Number (VN) in the first byte.
// We'll primarily focus on ensuring the version is valid for NTP.
// Many NTP versions are used, but let's check for generally accepted ones (3 & 4 for IPv4, plus potential extensions/customizations)
firstByte := packet[0]
li := (firstByte >> 6) & 0x03 // Extract LI
vn := (firstByte >> 3) & 0x07 // Extract VN
mode := firstByte & 0x07 // Extract Mode
// Leap Indicator should be a valid value (0-3).
if li > 3 {
return os.ErrInvalid
}
// Version Check (common NTP versions are 3 and 4)
if vn != 3 && vn != 4 {
return os.ErrInvalid
}
// Check the Mode field for a client request (Mode 3). This validates it *is* a request.
if mode != 3 {
return os.ErrInvalid
}
// Check Root Delay and Root Dispersion. While not strictly *required* for a request,
// we can check if they appear to be reasonable values (not excessively large).
rootDelay := binary.BigEndian.Uint32(packet[4:8])
rootDispersion := binary.BigEndian.Uint32(packet[8:12])
// Check for unreasonably large root delay and dispersion. NTP RFC specifies max values of approximately 16 seconds.
// Convert to milliseconds for easy comparison. Each unit is 1/2^16 seconds.
if float64(rootDelay)/65536.0 > 16.0 {
return os.ErrInvalid
}
if float64(rootDispersion)/65536.0 > 16.0 {
return os.ErrInvalid
}
metadata.Protocol = C.ProtocolNTP
return nil
}

33
common/sniff/ntp_test.go Normal file
View File

@ -0,0 +1,33 @@
package sniff_test
import (
"context"
"encoding/hex"
"os"
"testing"
"github.com/sagernet/sing-box/adapter"
"github.com/sagernet/sing-box/common/sniff"
C "github.com/sagernet/sing-box/constant"
"github.com/stretchr/testify/require"
)
func TestSniffNTP(t *testing.T) {
t.Parallel()
packet, err := hex.DecodeString("1b0006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
require.NoError(t, err)
var metadata adapter.InboundContext
err = sniff.NTP(context.Background(), &metadata, packet)
require.NoError(t, err)
require.Equal(t, metadata.Protocol, C.ProtocolNTP)
}
func TestSniffNTPFailed(t *testing.T) {
t.Parallel()
packet, err := hex.DecodeString("400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
require.NoError(t, err)
var metadata adapter.InboundContext
err = sniff.NTP(context.Background(), &metadata, packet)
require.ErrorIs(t, err, os.ErrInvalid)
}

View File

@ -34,6 +34,7 @@ type Client struct {
disableCache bool
disableExpire bool
independentCache bool
clientSubnet netip.Prefix
rdrc adapter.RDRCStore
initRDRCFunc func() adapter.RDRCStore
logger logger.ContextLogger
@ -47,6 +48,7 @@ type ClientOptions struct {
DisableExpire bool
IndependentCache bool
CacheCapacity uint32
ClientSubnet netip.Prefix
RDRC func() adapter.RDRCStore
Logger logger.ContextLogger
}
@ -57,6 +59,7 @@ func NewClient(options ClientOptions) *Client {
disableCache: options.DisableCache,
disableExpire: options.DisableExpire,
independentCache: options.IndependentCache,
clientSubnet: options.ClientSubnet,
initRDRCFunc: options.RDRC,
logger: options.Logger,
}
@ -104,8 +107,12 @@ func (c *Client) Exchange(ctx context.Context, transport adapter.DNSTransport, m
return &responseMessage, nil
}
question := message.Question[0]
if options.ClientSubnet.IsValid() {
message = SetClientSubnet(message, options.ClientSubnet)
clientSubnet := options.ClientSubnet
if !clientSubnet.IsValid() {
clientSubnet = c.clientSubnet
}
if clientSubnet.IsValid() {
message = SetClientSubnet(message, clientSubnet)
}
isSimpleRequest := len(message.Question) == 1 &&
len(message.Ns) == 0 &&

View File

@ -55,6 +55,7 @@ func NewRouter(ctx context.Context, logFactory log.Factory, options option.DNSOp
DisableExpire: options.DNSClientOptions.DisableExpire,
IndependentCache: options.DNSClientOptions.IndependentCache,
CacheCapacity: options.DNSClientOptions.CacheCapacity,
ClientSubnet: options.DNSClientOptions.ClientSubnet.Build(netip.Prefix{}),
RDRC: func() adapter.RDRCStore {
cacheFile := service.FromContext[adapter.CacheFile](ctx)
if cacheFile == nil {

View File

@ -1,7 +1,11 @@
---
icon: material/new-box
icon: material/alert-decagram
---
!!! quote "Changes in sing-box 1.12.0"
:material-decagram: [servers](#servers)
!!! quote "Changes in sing-box 1.11.0"
:material-plus: [cache_capacity](#cache_capacity)

View File

@ -1,7 +1,11 @@
---
icon: material/new-box
icon: material/alert-decagram
---
!!! quote "sing-box 1.12.0 中的更改"
:material-decagram: [servers](#servers)
!!! quote "sing-box 1.11.0 中的更改"
:material-plus: [cache_capacity](#cache_capacity)

View File

@ -22,6 +22,7 @@ If enabled in the inbound, the protocol and domain name (if present) of by the c
| UDP | `dtls` | / | / |
| TCP | `ssh` | / | SSH Client Name |
| TCP | `rdp` | / | / |
| UDP | `ntp` | / | / |
| QUIC Client | Type |
|:------------------------:|:----------:|

View File

@ -22,6 +22,7 @@
| UDP | `dtls` | / | / |
| TCP | `ssh` | / | SSH 客户端名称 |
| TCP | `rdp` | / | / |
| UDP | `ntp` | / | / |
| QUIC 客户端 | 类型 |
|:------------------------:|:----------:|

View File

@ -564,6 +564,7 @@ func (r *Router) actionSniff(
sniff.UTP,
sniff.UDPTracker,
sniff.DTLSRecord,
sniff.NTP,
}
}
for {

View File

@ -379,6 +379,8 @@ func (r *RuleActionSniff) build() error {
r.StreamSniffers = append(r.StreamSniffers, sniff.SSH)
case C.ProtocolRDP:
r.StreamSniffers = append(r.StreamSniffers, sniff.RDP)
case C.ProtocolNTP:
r.PacketSniffers = append(r.PacketSniffers, sniff.NTP)
default:
return E.New("unknown sniffer: ", name)
}

View File

@ -3,6 +3,7 @@ package v2raywebsocket
import (
"context"
"encoding/base64"
"errors"
"io"
"net"
"os"
@ -61,7 +62,7 @@ func (c *WebsocketConn) Close() error {
func (c *WebsocketConn) Read(b []byte) (n int, err error) {
var header ws.Header
for {
n, err = c.reader.Read(b)
n, err = wrapWsError0(c.reader.Read(b))
if n > 0 {
err = nil
return
@ -95,7 +96,7 @@ func (c *WebsocketConn) Read(b []byte) (n int, err error) {
}
func (c *WebsocketConn) Write(p []byte) (n int, err error) {
err = wsutil.WriteMessage(c.Conn, c.state, ws.OpBinary, p)
err = wrapWsError(wsutil.WriteMessage(c.Conn, c.state, ws.OpBinary, p))
if err != nil {
return
}
@ -146,7 +147,7 @@ func (c *EarlyWebsocketConn) Read(b []byte) (n int, err error) {
return 0, c.err
}
}
return c.conn.Read(b)
return wrapWsError0(c.conn.Read(b))
}
func (c *EarlyWebsocketConn) writeRequest(content []byte) error {
@ -177,12 +178,12 @@ func (c *EarlyWebsocketConn) writeRequest(content []byte) error {
conn, err = c.dialContext(c.ctx, &c.requestURL, c.headers)
}
if err != nil {
return err
return wrapWsError(err)
}
if len(lateData) > 0 {
_, err = conn.Write(lateData)
if err != nil {
return err
return wrapWsError(err)
}
}
c.conn = conn
@ -191,7 +192,7 @@ func (c *EarlyWebsocketConn) writeRequest(content []byte) error {
func (c *EarlyWebsocketConn) Write(b []byte) (n int, err error) {
if c.conn != nil {
return c.conn.Write(b)
return wrapWsError0(c.conn.Write(b))
}
c.access.Lock()
defer c.access.Unlock()
@ -199,9 +200,9 @@ func (c *EarlyWebsocketConn) Write(b []byte) (n int, err error) {
return 0, c.err
}
if c.conn != nil {
return c.conn.Write(b)
return wrapWsError0(c.conn.Write(b))
}
err = c.writeRequest(b)
err = wrapWsError(c.writeRequest(b))
c.err = err
close(c.create)
if err != nil {
@ -212,17 +213,17 @@ func (c *EarlyWebsocketConn) Write(b []byte) (n int, err error) {
func (c *EarlyWebsocketConn) WriteBuffer(buffer *buf.Buffer) error {
if c.conn != nil {
return c.conn.WriteBuffer(buffer)
return wrapWsError(c.conn.WriteBuffer(buffer))
}
c.access.Lock()
defer c.access.Unlock()
if c.conn != nil {
return c.conn.WriteBuffer(buffer)
return wrapWsError(c.conn.WriteBuffer(buffer))
}
if c.err != nil {
return c.err
}
err := c.writeRequest(buffer.Bytes())
err := wrapWsError(c.writeRequest(buffer.Bytes()))
c.err = err
close(c.create)
return err
@ -272,3 +273,23 @@ func (c *EarlyWebsocketConn) Upstream() any {
func (c *EarlyWebsocketConn) LazyHeadroom() bool {
return c.conn == nil
}
func wrapWsError(err error) error {
if err == nil {
return nil
}
var closedErr *wsutil.ClosedError
if errors.As(err, &closedErr) {
if closedErr.Code == ws.StatusNormalClosure {
err = io.EOF
}
}
return err
}
func wrapWsError0[T any](value T, err error) (T, error) {
if err == nil {
return value, nil
}
return common.DefaultValue[T](), wrapWsError(err)
}