brutal_test.go 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. package main
  2. import (
  3. "net/netip"
  4. "testing"
  5. C "github.com/sagernet/sing-box/constant"
  6. "github.com/sagernet/sing-box/option"
  7. "github.com/sagernet/sing-shadowsocks/shadowaead_2022"
  8. "github.com/gofrs/uuid/v5"
  9. )
  10. func TestBrutalShadowsocks(t *testing.T) {
  11. method := shadowaead_2022.List[0]
  12. password := mkBase64(t, 16)
  13. startInstance(t, option.Options{
  14. Inbounds: []option.Inbound{
  15. {
  16. Type: C.TypeMixed,
  17. Tag: "mixed-in",
  18. MixedOptions: option.HTTPMixedInboundOptions{
  19. ListenOptions: option.ListenOptions{
  20. Listen: option.NewListenAddress(netip.IPv4Unspecified()),
  21. ListenPort: clientPort,
  22. },
  23. },
  24. },
  25. {
  26. Type: C.TypeShadowsocks,
  27. ShadowsocksOptions: option.ShadowsocksInboundOptions{
  28. ListenOptions: option.ListenOptions{
  29. Listen: option.NewListenAddress(netip.IPv4Unspecified()),
  30. ListenPort: serverPort,
  31. },
  32. Method: method,
  33. Password: password,
  34. Multiplex: &option.InboundMultiplexOptions{
  35. Enabled: true,
  36. Brutal: &option.BrutalOptions{
  37. Enabled: true,
  38. UpMbps: 100,
  39. DownMbps: 100,
  40. },
  41. },
  42. },
  43. },
  44. },
  45. Outbounds: []option.Outbound{
  46. {
  47. Type: C.TypeDirect,
  48. },
  49. {
  50. Type: C.TypeShadowsocks,
  51. Tag: "ss-out",
  52. ShadowsocksOptions: option.ShadowsocksOutboundOptions{
  53. ServerOptions: option.ServerOptions{
  54. Server: "127.0.0.1",
  55. ServerPort: serverPort,
  56. },
  57. Method: method,
  58. Password: password,
  59. Multiplex: &option.OutboundMultiplexOptions{
  60. Enabled: true,
  61. Protocol: "smux",
  62. Padding: true,
  63. Brutal: &option.BrutalOptions{
  64. Enabled: true,
  65. UpMbps: 100,
  66. DownMbps: 100,
  67. },
  68. },
  69. },
  70. },
  71. },
  72. Route: &option.RouteOptions{
  73. Rules: []option.Rule{
  74. {
  75. DefaultOptions: option.DefaultRule{
  76. Inbound: []string{"mixed-in"},
  77. Outbound: "ss-out",
  78. },
  79. },
  80. },
  81. },
  82. })
  83. testSuit(t, clientPort, testPort)
  84. }
  85. func TestBrutalTrojan(t *testing.T) {
  86. _, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
  87. password := mkBase64(t, 16)
  88. startInstance(t, option.Options{
  89. Inbounds: []option.Inbound{
  90. {
  91. Type: C.TypeMixed,
  92. Tag: "mixed-in",
  93. MixedOptions: option.HTTPMixedInboundOptions{
  94. ListenOptions: option.ListenOptions{
  95. Listen: option.NewListenAddress(netip.IPv4Unspecified()),
  96. ListenPort: clientPort,
  97. },
  98. },
  99. },
  100. {
  101. Type: C.TypeTrojan,
  102. TrojanOptions: option.TrojanInboundOptions{
  103. ListenOptions: option.ListenOptions{
  104. Listen: option.NewListenAddress(netip.IPv4Unspecified()),
  105. ListenPort: serverPort,
  106. },
  107. Users: []option.TrojanUser{{Password: password}},
  108. Multiplex: &option.InboundMultiplexOptions{
  109. Enabled: true,
  110. Brutal: &option.BrutalOptions{
  111. Enabled: true,
  112. UpMbps: 100,
  113. DownMbps: 100,
  114. },
  115. },
  116. TLS: &option.InboundTLSOptions{
  117. Enabled: true,
  118. ServerName: "example.org",
  119. CertificatePath: certPem,
  120. KeyPath: keyPem,
  121. },
  122. },
  123. },
  124. },
  125. Outbounds: []option.Outbound{
  126. {
  127. Type: C.TypeDirect,
  128. },
  129. {
  130. Type: C.TypeTrojan,
  131. Tag: "ss-out",
  132. TrojanOptions: option.TrojanOutboundOptions{
  133. ServerOptions: option.ServerOptions{
  134. Server: "127.0.0.1",
  135. ServerPort: serverPort,
  136. },
  137. Password: password,
  138. Multiplex: &option.OutboundMultiplexOptions{
  139. Enabled: true,
  140. Protocol: "yamux",
  141. Padding: true,
  142. Brutal: &option.BrutalOptions{
  143. Enabled: true,
  144. UpMbps: 100,
  145. DownMbps: 100,
  146. },
  147. },
  148. TLS: &option.OutboundTLSOptions{
  149. Enabled: true,
  150. ServerName: "example.org",
  151. CertificatePath: certPem,
  152. },
  153. },
  154. },
  155. },
  156. Route: &option.RouteOptions{
  157. Rules: []option.Rule{
  158. {
  159. DefaultOptions: option.DefaultRule{
  160. Inbound: []string{"mixed-in"},
  161. Outbound: "ss-out",
  162. },
  163. },
  164. },
  165. },
  166. })
  167. testSuit(t, clientPort, testPort)
  168. }
  169. func TestBrutalVMess(t *testing.T) {
  170. user, _ := uuid.NewV4()
  171. startInstance(t, option.Options{
  172. Inbounds: []option.Inbound{
  173. {
  174. Type: C.TypeMixed,
  175. Tag: "mixed-in",
  176. MixedOptions: option.HTTPMixedInboundOptions{
  177. ListenOptions: option.ListenOptions{
  178. Listen: option.NewListenAddress(netip.IPv4Unspecified()),
  179. ListenPort: clientPort,
  180. },
  181. },
  182. },
  183. {
  184. Type: C.TypeVMess,
  185. VMessOptions: option.VMessInboundOptions{
  186. ListenOptions: option.ListenOptions{
  187. Listen: option.NewListenAddress(netip.IPv4Unspecified()),
  188. ListenPort: serverPort,
  189. },
  190. Users: []option.VMessUser{{UUID: user.String()}},
  191. Multiplex: &option.InboundMultiplexOptions{
  192. Enabled: true,
  193. Brutal: &option.BrutalOptions{
  194. Enabled: true,
  195. UpMbps: 100,
  196. DownMbps: 100,
  197. },
  198. },
  199. },
  200. },
  201. },
  202. Outbounds: []option.Outbound{
  203. {
  204. Type: C.TypeDirect,
  205. },
  206. {
  207. Type: C.TypeVMess,
  208. Tag: "ss-out",
  209. VMessOptions: option.VMessOutboundOptions{
  210. ServerOptions: option.ServerOptions{
  211. Server: "127.0.0.1",
  212. ServerPort: serverPort,
  213. },
  214. UUID: user.String(),
  215. Multiplex: &option.OutboundMultiplexOptions{
  216. Enabled: true,
  217. Protocol: "h2mux",
  218. Padding: true,
  219. Brutal: &option.BrutalOptions{
  220. Enabled: true,
  221. UpMbps: 100,
  222. DownMbps: 100,
  223. },
  224. },
  225. },
  226. },
  227. },
  228. Route: &option.RouteOptions{
  229. Rules: []option.Rule{
  230. {
  231. DefaultOptions: option.DefaultRule{
  232. Inbound: []string{"mixed-in"},
  233. Outbound: "ss-out",
  234. },
  235. },
  236. },
  237. },
  238. })
  239. testSuit(t, clientPort, testPort)
  240. }
  241. func TestBrutalVLESS(t *testing.T) {
  242. user, _ := uuid.NewV4()
  243. startInstance(t, option.Options{
  244. Inbounds: []option.Inbound{
  245. {
  246. Type: C.TypeMixed,
  247. Tag: "mixed-in",
  248. MixedOptions: option.HTTPMixedInboundOptions{
  249. ListenOptions: option.ListenOptions{
  250. Listen: option.NewListenAddress(netip.IPv4Unspecified()),
  251. ListenPort: clientPort,
  252. },
  253. },
  254. },
  255. {
  256. Type: C.TypeVLESS,
  257. VLESSOptions: option.VLESSInboundOptions{
  258. ListenOptions: option.ListenOptions{
  259. Listen: option.NewListenAddress(netip.IPv4Unspecified()),
  260. ListenPort: serverPort,
  261. },
  262. Users: []option.VLESSUser{{UUID: user.String()}},
  263. Multiplex: &option.InboundMultiplexOptions{
  264. Enabled: true,
  265. Brutal: &option.BrutalOptions{
  266. Enabled: true,
  267. UpMbps: 100,
  268. DownMbps: 100,
  269. },
  270. },
  271. TLS: &option.InboundTLSOptions{
  272. Enabled: true,
  273. ServerName: "google.com",
  274. Reality: &option.InboundRealityOptions{
  275. Enabled: true,
  276. Handshake: option.InboundRealityHandshakeOptions{
  277. ServerOptions: option.ServerOptions{
  278. Server: "google.com",
  279. ServerPort: 443,
  280. },
  281. },
  282. ShortID: []string{"0123456789abcdef"},
  283. PrivateKey: "UuMBgl7MXTPx9inmQp2UC7Jcnwc6XYbwDNebonM-FCc",
  284. },
  285. },
  286. },
  287. },
  288. },
  289. Outbounds: []option.Outbound{
  290. {
  291. Type: C.TypeDirect,
  292. },
  293. {
  294. Type: C.TypeVLESS,
  295. Tag: "ss-out",
  296. VLESSOptions: option.VLESSOutboundOptions{
  297. ServerOptions: option.ServerOptions{
  298. Server: "127.0.0.1",
  299. ServerPort: serverPort,
  300. },
  301. UUID: user.String(),
  302. TLS: &option.OutboundTLSOptions{
  303. Enabled: true,
  304. ServerName: "google.com",
  305. Reality: &option.OutboundRealityOptions{
  306. Enabled: true,
  307. ShortID: "0123456789abcdef",
  308. PublicKey: "jNXHt1yRo0vDuchQlIP6Z0ZvjT3KtzVI-T4E7RoLJS0",
  309. },
  310. UTLS: &option.OutboundUTLSOptions{
  311. Enabled: true,
  312. },
  313. },
  314. Multiplex: &option.OutboundMultiplexOptions{
  315. Enabled: true,
  316. Protocol: "h2mux",
  317. Padding: true,
  318. Brutal: &option.BrutalOptions{
  319. Enabled: true,
  320. UpMbps: 100,
  321. DownMbps: 100,
  322. },
  323. },
  324. },
  325. },
  326. },
  327. Route: &option.RouteOptions{
  328. Rules: []option.Rule{
  329. {
  330. DefaultOptions: option.DefaultRule{
  331. Inbound: []string{"mixed-in"},
  332. Outbound: "ss-out",
  333. },
  334. },
  335. },
  336. },
  337. })
  338. testSuit(t, clientPort, testPort)
  339. }