brutal_test.go 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. InboundTLSOptionsContainer: option.InboundTLSOptionsContainer{
  117. TLS: &option.InboundTLSOptions{
  118. Enabled: true,
  119. ServerName: "example.org",
  120. CertificatePath: certPem,
  121. KeyPath: keyPem,
  122. },
  123. },
  124. },
  125. },
  126. },
  127. Outbounds: []option.Outbound{
  128. {
  129. Type: C.TypeDirect,
  130. },
  131. {
  132. Type: C.TypeTrojan,
  133. Tag: "ss-out",
  134. TrojanOptions: option.TrojanOutboundOptions{
  135. ServerOptions: option.ServerOptions{
  136. Server: "127.0.0.1",
  137. ServerPort: serverPort,
  138. },
  139. Password: password,
  140. Multiplex: &option.OutboundMultiplexOptions{
  141. Enabled: true,
  142. Protocol: "yamux",
  143. Padding: true,
  144. Brutal: &option.BrutalOptions{
  145. Enabled: true,
  146. UpMbps: 100,
  147. DownMbps: 100,
  148. },
  149. },
  150. OutboundTLSOptionsContainer: option.OutboundTLSOptionsContainer{
  151. TLS: &option.OutboundTLSOptions{
  152. Enabled: true,
  153. ServerName: "example.org",
  154. CertificatePath: certPem,
  155. },
  156. },
  157. },
  158. },
  159. },
  160. Route: &option.RouteOptions{
  161. Rules: []option.Rule{
  162. {
  163. DefaultOptions: option.DefaultRule{
  164. Inbound: []string{"mixed-in"},
  165. Outbound: "ss-out",
  166. },
  167. },
  168. },
  169. },
  170. })
  171. testSuit(t, clientPort, testPort)
  172. }
  173. func TestBrutalVMess(t *testing.T) {
  174. user, _ := uuid.NewV4()
  175. startInstance(t, option.Options{
  176. Inbounds: []option.Inbound{
  177. {
  178. Type: C.TypeMixed,
  179. Tag: "mixed-in",
  180. MixedOptions: option.HTTPMixedInboundOptions{
  181. ListenOptions: option.ListenOptions{
  182. Listen: option.NewListenAddress(netip.IPv4Unspecified()),
  183. ListenPort: clientPort,
  184. },
  185. },
  186. },
  187. {
  188. Type: C.TypeVMess,
  189. VMessOptions: option.VMessInboundOptions{
  190. ListenOptions: option.ListenOptions{
  191. Listen: option.NewListenAddress(netip.IPv4Unspecified()),
  192. ListenPort: serverPort,
  193. },
  194. Users: []option.VMessUser{{UUID: user.String()}},
  195. Multiplex: &option.InboundMultiplexOptions{
  196. Enabled: true,
  197. Brutal: &option.BrutalOptions{
  198. Enabled: true,
  199. UpMbps: 100,
  200. DownMbps: 100,
  201. },
  202. },
  203. },
  204. },
  205. },
  206. Outbounds: []option.Outbound{
  207. {
  208. Type: C.TypeDirect,
  209. },
  210. {
  211. Type: C.TypeVMess,
  212. Tag: "ss-out",
  213. VMessOptions: option.VMessOutboundOptions{
  214. ServerOptions: option.ServerOptions{
  215. Server: "127.0.0.1",
  216. ServerPort: serverPort,
  217. },
  218. UUID: user.String(),
  219. Multiplex: &option.OutboundMultiplexOptions{
  220. Enabled: true,
  221. Protocol: "h2mux",
  222. Padding: true,
  223. Brutal: &option.BrutalOptions{
  224. Enabled: true,
  225. UpMbps: 100,
  226. DownMbps: 100,
  227. },
  228. },
  229. },
  230. },
  231. },
  232. Route: &option.RouteOptions{
  233. Rules: []option.Rule{
  234. {
  235. DefaultOptions: option.DefaultRule{
  236. Inbound: []string{"mixed-in"},
  237. Outbound: "ss-out",
  238. },
  239. },
  240. },
  241. },
  242. })
  243. testSuit(t, clientPort, testPort)
  244. }
  245. func TestBrutalVLESS(t *testing.T) {
  246. user, _ := uuid.NewV4()
  247. startInstance(t, option.Options{
  248. Inbounds: []option.Inbound{
  249. {
  250. Type: C.TypeMixed,
  251. Tag: "mixed-in",
  252. MixedOptions: option.HTTPMixedInboundOptions{
  253. ListenOptions: option.ListenOptions{
  254. Listen: option.NewListenAddress(netip.IPv4Unspecified()),
  255. ListenPort: clientPort,
  256. },
  257. },
  258. },
  259. {
  260. Type: C.TypeVLESS,
  261. VLESSOptions: option.VLESSInboundOptions{
  262. ListenOptions: option.ListenOptions{
  263. Listen: option.NewListenAddress(netip.IPv4Unspecified()),
  264. ListenPort: serverPort,
  265. },
  266. Users: []option.VLESSUser{{UUID: user.String()}},
  267. Multiplex: &option.InboundMultiplexOptions{
  268. Enabled: true,
  269. Brutal: &option.BrutalOptions{
  270. Enabled: true,
  271. UpMbps: 100,
  272. DownMbps: 100,
  273. },
  274. },
  275. InboundTLSOptionsContainer: option.InboundTLSOptionsContainer{
  276. TLS: &option.InboundTLSOptions{
  277. Enabled: true,
  278. ServerName: "google.com",
  279. Reality: &option.InboundRealityOptions{
  280. Enabled: true,
  281. Handshake: option.InboundRealityHandshakeOptions{
  282. ServerOptions: option.ServerOptions{
  283. Server: "google.com",
  284. ServerPort: 443,
  285. },
  286. },
  287. ShortID: []string{"0123456789abcdef"},
  288. PrivateKey: "UuMBgl7MXTPx9inmQp2UC7Jcnwc6XYbwDNebonM-FCc",
  289. },
  290. },
  291. },
  292. },
  293. },
  294. },
  295. Outbounds: []option.Outbound{
  296. {
  297. Type: C.TypeDirect,
  298. },
  299. {
  300. Type: C.TypeVLESS,
  301. Tag: "ss-out",
  302. VLESSOptions: option.VLESSOutboundOptions{
  303. ServerOptions: option.ServerOptions{
  304. Server: "127.0.0.1",
  305. ServerPort: serverPort,
  306. },
  307. UUID: user.String(),
  308. OutboundTLSOptionsContainer: option.OutboundTLSOptionsContainer{
  309. TLS: &option.OutboundTLSOptions{
  310. Enabled: true,
  311. ServerName: "google.com",
  312. Reality: &option.OutboundRealityOptions{
  313. Enabled: true,
  314. ShortID: "0123456789abcdef",
  315. PublicKey: "jNXHt1yRo0vDuchQlIP6Z0ZvjT3KtzVI-T4E7RoLJS0",
  316. },
  317. UTLS: &option.OutboundUTLSOptions{
  318. Enabled: true,
  319. },
  320. },
  321. },
  322. Multiplex: &option.OutboundMultiplexOptions{
  323. Enabled: true,
  324. Protocol: "h2mux",
  325. Padding: true,
  326. Brutal: &option.BrutalOptions{
  327. Enabled: true,
  328. UpMbps: 100,
  329. DownMbps: 100,
  330. },
  331. },
  332. },
  333. },
  334. },
  335. Route: &option.RouteOptions{
  336. Rules: []option.Rule{
  337. {
  338. DefaultOptions: option.DefaultRule{
  339. Inbound: []string{"mixed-in"},
  340. Outbound: "ss-out",
  341. },
  342. },
  343. },
  344. },
  345. })
  346. testSuit(t, clientPort, testPort)
  347. }