brutal_test.go 9.3 KB

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