CVE-2023-33965 (published 2023-06-01T15:15Z)

Brook is a cross-platform programmable network tool. The `tproxy` server is vulnerable to a drive-by command injection. An attacker may fool a victim into visiting a malicious web page which will trigger requests to the local `tproxy` service leading to remote code execution. A patch is available in version 20230606.

CVSS v3 base score: 8.8, HIGH (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-78
cwe_name: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
description: The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component.
extended_description: 
		   This weakness can lead to a vulnerability in environments in which the attacker does not have direct access to the operating system, such as in web applications. Alternately, if the weakness occurs in a privileged program, it could allow the attacker to specify commands that normally would not be accessible, or to call alternate commands with privileges that the attacker does not have. The problem is exacerbated if the compromised process does not follow the principle of least privilege, because the attacker-controlled commands may run with special system privileges that increases the amount of damage.
            There are at least two subtypes of OS command injection:
               
				 The application intends to execute a single, fixed program that is under its own control. It intends to use externally-supplied inputs as arguments to that program. For example, the program might use system("nslookup [HOSTNAME]") to run nslookup and allow the user to supply a HOSTNAME, which is used as an argument. Attackers cannot prevent nslookup from executing. However, if the program does not remove command separators from the HOSTNAME argument, attackers could place the separators into the arguments, which allows them to execute their own program after nslookup has finished executing.
				 The application accepts an input that it uses to fully select which program to run, as well as which commands to use. The application simply redirects this entire command to the operating system. For example, the program might use "exec([COMMAND])" to execute the [COMMAND] that was supplied by the user. If the COMMAND is under attacker control, then the attacker can execute arbitrary commands or programs. If the command is being executed using functions like exec() and CreateProcess(), the attacker might not be able to combine multiple commands together in the same line.
               
            From a weakness standpoint, these variants represent distinct programmer errors. In the first variant, the programmer clearly intends that input from untrusted parties will be part of the arguments in the command to be executed. In the second variant, the programmer does not intend for the command to be accessible to any untrusted party, but the programmer probably has not accounted for alternate ways in which malicious attackers can provide input.
         
         

Fix information:
repo_url: https://github.com/txthinking/brook
commit_details: repo_url: https://github.com/txthinking/brook
author: txthinking
author_date: 2023-02-14 12:32:27+08:00
msg: tproxy web auth
repository: repo_url: https://github.com/txthinking/brook
repo_name: txthinking/brook
description: A cross-platform programmable network tool
repo_language: Go
owner: txthinking
file_changes: filename: main.go
change_type: ModificationType.MODIFY
diff: @@ -975,7 +975,7 @@ func main() {
 				if err != nil {
 					return err
 				}
-				s, err := brook.NewQUICServer(":"+p, c.String("password"), h, c.Int("tcpTimeout"), c.Int("udpTimeout"), c.String("blockDomainList"), c.String("blockCIDR4List"), c.String("blockCIDR6List"), c.Int64("updateListInterval"), c.StringSlice("blockGeoIP"), c.Bool("withoutBrookProtocol"))
+				s, err := brook.NewQUICServer(":"+p, c.String("password"), h, c.Int("tcpTimeout"), c.Int("udpTimeout"), c.Bool("withoutBrookProtocol"))
 				if err != nil {
 					return err
 				}
@@ -1437,7 +1437,7 @@ func main() {
 				},
 				&cli.BoolFlag{
 					Name:  "enableIPv6",
-					Usage: "Your local and server must support IPv6 both",
+					Usage: "deprecated",
 				},
 				&cli.BoolFlag{
 					Name:  "doNotRunScripts",
@@ -1514,7 +1514,55 @@ func main() {
 					lock := &sync.Mutex{}
 					m := http.NewServeMux()
 					m.Handle("/", http.FileServer(http.FS(web)))
+					m.HandleFunc("/hasp", func(w http.ResponseWriter, r *http.Request) {
+						lock.Lock()
+						defer lock.Unlock()
+						_, err := os.Stat("/tmp/.brook.web.password")
+						if os.IsNotExist(err) {
+							w.Write([]byte("no"))
+							return
+						}
+						w.Write([]byte("yes"))
+					})
+					m.HandleFunc("/setp", func(w http.ResponseWriter, r *http.Request) {
+						lock.Lock()
+						defer lock.Unlock()
+						_, err := os.Stat("/tmp/.brook.web.password")
+						if !os.IsNotExist(err) {
+							http.Error(w, "file exsits", 500)
+							return
+						}
+						err = ioutil.WriteFile("/tmp/.brook.web.password", []byte(r.FormValue("p")), 0600)
+						if err != nil {
+							http.Error(w, err.Error(), 500)
+							return
+						}
+						w.WriteHeader(200)
+					})
+					m.HandleFunc("/authp", func(w http.ResponseWriter, r *http.Request) {
+						lock.Lock()
+						defer lock.Unlock()
+						b, err := ioutil.ReadFile("/tmp/.brook.web.password")
+						if err != nil {
+							http.Error(w, err.Error(), 500)
+							return
+						}
+						if string(b) != r.FormValue("p") {
+							http.Error(w, "web ui password wrong", 500)
+							return
+						}
+						w.WriteHeader(200)
+					})
 					m.HandleFunc("/start", func(w http.ResponseWriter, r *http.Request) {
+						b, err := ioutil.ReadFile("/root/.brook.web.password")
+						if err != nil {
+							http.Error(w, err.Error(), 500)
+							return
+						}
+						if string(b) != r.FormValue("p") {
+							http.Error(w, "web ui password wrong", 500)
+							return
+						}
 						s, err := os.Executable()
 						if err != nil {
 							http.Error(w, err.Error(), 500)
@@ -1523,7 +1571,6 @@ func main() {
 						lock.Lock()
 						defer lock.Unlock()
 						cmd = exec.Command("/bin/sh", "-c", s+" tproxy "+r.FormValue("args"))
-						log.Println(s + " tproxy " + r.FormValue("args"))
 						done := make(chan byte)
 						defer close(done)
 						errch := make(chan error)
@@ -1552,6 +1599,15 @@ func main() {
 						}
 					})
 					m.HandleFunc("/stop", func(w http.ResponseWriter, r *http.Request) {
+						b, err := ioutil.ReadFile("/root/.brook.web.password")
+						if err != nil {
+							http.Error(w, err.Error(), 500)
+							return
+						}
+						if string(b) != r.FormValue("p") {
+							http.Error(w, "web ui password wrong", 500)
+							return
+						}
 						lock.Lock()
 						defer lock.Unlock()
 						if cmd == nil {
@@ -1565,6 +1621,15 @@ func main() {
 						w.Write([]byte("disconnected"))
 					})
 					m.HandleFunc("/status", func(w http.ResponseWriter, r *http.Request) {
+						b, err := ioutil.ReadFile("/tmp/.brook.web.password")
+						if err != nil {
+							http.Error(w, err.Error(), 500)
+							return
+						}
+						if string(b) != r.FormValue("p") {
+							http.Error(w, "web ui password wrong", 500)
+							return
+						}
 						lock.Lock()
 						defer lock.Unlock()
 						if cmd == nil {

programming_language: Go
filename: index.html
change_type: ModificationType.MODIFY
diff: @@ -35,15 +35,36 @@
                             bypassDomainList: localStorage.getItem("bypassDomainList") ?? "",
                             bypassCIDR4List: localStorage.getItem("bypassCIDR4List") ?? "",
                             bypassCIDR6List: localStorage.getItem("bypassCIDR6List") ?? "",
+                            bypassGeoIP: localStorage.getItem("bypassGeoIP") ?? "",
                             blockDomainList: localStorage.getItem("blockDomainList") ?? "",
-                            enableIPv6: localStorage.getItem("enableIPv6") ? true : false,
+                            disableA: localStorage.getItem("disableA") ? true : false,
+                            disableAAAA: localStorage.getItem("disableAAAA") ? true : false,
+                            hasp: false,
+                            localhasp: false,
+                            p: "",
                             status: "disconnected",
                             ing: false,
                         };
                     },
                     async created() {
                         try {
-                            var r = await fetch("/status");
+                            var r = await fetch("/hasp");
+                            if (r.status != 200) {
+                                throw await r.text();
+                            }
+                            if((await r.text()) == "yes"){
+                                this.hasp = true;
+                            }
+                            if(!this.hasp){
+                                return;
+                            }
+                            if(localStorage.getItem("p")){
+                                this.localhasp = true;
+                            }
+                            if(!this.localhasp){
+                                return;
+                            }
+                            var r = await fetch(`/status?p=${encodeURIComponent(localStorage.getItem('p'))}`);
                             if (r.status != 200) {
                                 throw await r.text();
                             }
@@ -53,6 +74,41 @@
                         }
                     },
                     methods: {
+                        async setp() {
+                            try {
+                                if (!this.p.trim()) {
+                                    return;
+                                }
+                                this.ing = true;
+                                var r = await fetch(`/setp?p=${encodeURIComponent(this.p.trim())}`);
+                                if (r.status != 200) {
+                                    throw await r.text();
+                                }
+                                location.reload();
+                                this.ing = false;
+                            } catch (e) {
+                                alert(`${e}`);
+                                this.ing = false;
+                            }
+                        },
+                        async authp() {
+                            try {
+                                if (!this.p.trim()) {
+                                    return;
+                                }
+                                this.ing = true;
+                                var r = await fetch(`/authp?p=${encodeURIComponent(this.p.trim())}`);
+                                if (r.status != 200) {
+                                    throw await r.text();
+                                }
+                                localStorage.setItem("p", this.p.trim());
+                                location.reload();
+                                this.ing = false;
+                            } catch (e) {
+                                alert(`${e}`);
+                                this.ing = false;
+                            }
+                        },
                         async start() {
                             try {
                                 this.ing = true;
@@ -105,19 +161,43 @@
                                 } else {
                                     localStorage.setItem("bypassCIDR6List", "");
                                 }
+                                if (
+                                    this.bypassGeoIP &&
+                                    this.bypassGeoIP
+                                        .split(",")
+                                        .map((v) => v.trim())
+                                        .filter((v) => v).length
+                                ) {
+                                    this.bypassGeoIP
+                                        .split(",")
+                                        .map((v) => v.trim())
+                                        .filter((v) => v)
+                                        .forEach((v) => {
+                                            s += ` --bypassGeoIP '${v}'`;
+                                        });
+                                    localStorage.setItem("bypassGeoIP", this.bypassGeoIP);
+                                } else {
+                                    localStorage.setItem("bypassGeoIP", "");
+                                }
                                 if (this.blockDomainList) {
                                     s += ` --blockDomainList '${this.blockDomainList}'`;
                                     localStorage.setItem("blockDomainList", this.blockDomainList);
                                 } else {
                                     localStorage.setItem("blockDomainList", "");
                                 }
-                                if (this.enableIPv6) {
-                                    s += ` --enableIPv6`;
-                                    localStorage.setItem("enableIPv6", "true");
+                                if (this.disableA) {
+                                    s += ` --disableA`;
+                                    localStorage.setItem("disableA", "true");
                                 } else {
-                                    localStorage.setItem("enableIPv6", "");
+                                    localStorage.setItem("disableA", "");
                                 }
-                                var r = await fetch(`/start?args=${encodeURIComponent(s)}`);
+                                if (this.disableAAAA) {
+                                    s += ` --disableAAAA`;
+                                    localStorage.setItem("disableAAAA", "true");
+                                } else {
+                                    localStorage.setItem("disableAAAA", "");
+                                }
+                                var r = await fetch(`/start?args=${encodeURIComponent(s)}&p=${encodeURIComponent(localStorage.getItem('p'))}`);
                                 if (r.status != 200) {
                                     throw await r.text();
                                 }
@@ -131,7 +211,7 @@
                         async stop() {
                             try {
                                 this.ing = true;
-                                var r = await fetch(`/stop`);
+                                var r = await fetch(`/stop?p=${encodeURIComponent(localStorage.getItem('p'))}`);
                                 if (r.status != 200) {
                                     throw await r.text();
                                 }
@@ -153,7 +233,7 @@
             <h1>Brook</h1>
             <p>brook tproxy</p>
         </header>
-        <main>
+        <main v-if="hasp && localhasp">
             <p>
                 <label>--link brook link</label><br />
                 <input v-model="link" placeholder="brook://..." />
@@ -174,6 +254,14 @@
                 <label>--dnsForBypass DNS server for resolving domains in bypass list</label><br />
                 <input v-model="dnsForBypass" placeholder="223.5.5.5:53" />
             </p>
+            <p>
+                <label>--disableA Disable A query</label><br />
+                <input type="checkbox" v-model="disableA" />
+            </p>
+            <p>
+                <label>--disableAAAA Disable AAAA query</label><br />
+                <input type="checkbox" v-model="disableAAAA" />
+            </p>
             <p>
                 <label>--bypassDomainList Suffix match mode</label><br />
                 <input v-model="bypassDomainList" placeholder="/path/to/local/file/example_domain.txt" />
@@ -187,17 +275,33 @@
                 <input v-model="bypassCIDR6List" placeholder="/path/to/local/file/example_cidr6.txt" />
             </p>
             <p>
-                <label>--blockDomainList Suffix match mode</label><br />
-                <input v-model="blockDomainList" placeholder="/path/to/local/file/example_domain.txt" />
+                <label>--bypassGeoIP Bypass IP by Geo country code, such as CN</label><br />
+                <input v-model="bypassGeoIP" placeholder="ZZ,CN" />
             </p>
             <p>
-                <label>--enableIPv6 Your local and server must support IPv6</label><br />
-                <input type="checkbox" v-model="enableIPv6" />
+                <label>--blockDomainList Suffix match mode</label><br />
+                <input v-model="blockDomainList" placeholder="/path/to/local/file/example_domain.txt" />
             </p>
             <p v-if="ing"><button disabled>Waiting...</button></p>
             <p v-if="!ing && status == 'disconnected'"><button v-on:click="start">Connect</button></p>
             <p v-if="!ing && status =='connected'"><button v-on:click="stop">Disconnect</button></p>
         </main>
+        <main v-if="!hasp">
+            <p>
+                <label>Set password for web UI</label><br />
+                <input v-model="p" />
+            </p>
+            <p v-if="ing"><button disabled>Waiting...</button></p>
+            <p v-if="!ing"><button v-on:click="setp">Save</button></p>
+        </main>
+        <main v-if="hasp && !localhasp">
+            <p>
+                <label>Auth web UI</label><br />
+                <input v-model="p" />
+            </p>
+            <p v-if="ing"><button disabled>Waiting...</button></p>
+            <p v-if="!ing"><button v-on:click="authp">Auth</button></p>
+        </main>
         <footer>
             <p><a href="https://txthinking.com">txthinking.com</a> | <a href="https://github.com/txthinking">github.com/txthinking</a> | <a href="https://talks.txthinking.com">blog</a> | <a href="https://youtube.com/txthinking">youtube</a> | <a href="https://t.me/brookgroup">telegram</a> | <a href="https://t.me/txthinking_news">news</a></p>
         </footer>

programming_language: HTML
filename: quicserver.go
change_type: ModificationType.MODIFY
diff: @@ -45,7 +45,7 @@ type QUICServer struct {
 	UDPServerConnFactory UDPServerConnFactory
 }
 
-func NewQUICServer(addr, password, domain string, tcpTimeout, udpTimeout int, blockDomainList, blockCIDR4List, blockCIDR6List string, updateListInterval int64, blockGeoIP []string, withoutbrook bool) (*QUICServer, error) {
+func NewQUICServer(addr, password, domain string, tcpTimeout, udpTimeout int, withoutbrook bool) (*QUICServer, error) {
 	if err := limits.Raise(); err != nil {
 		Log(&Error{"when": "try to raise system limits", "warning": err.Error()})
 	}

programming_language: Go
filename: streamclient.go
change_type: ModificationType.MODIFY
diff: @@ -94,7 +94,7 @@ func NewStreamClient(network string, password []byte, src string, server net.Con
 	}
 	binary.BigEndian.PutUint32(c.WB[2+16:2+16+4], uint32(i))
 	copy(c.WB[2+16+4:2+16+4+len(dst)], dst)
-	if err := c.WriteL(4 + len(dst)); err != nil {
+	if err := c.Write(4 + len(dst)); err != nil {
 		x.BP12.Put(c.cn)
 		x.BP2048.Put(c.WB)
 		return nil, err
@@ -150,7 +150,7 @@ func (c *StreamClient) Exchange(local net.Conn) error {
 					return
 				}
 			}
-			l, err := c.ReadL()
+			l, err := c.Read()
 			if err != nil {
 				return
 			}
@@ -169,14 +169,14 @@ func (c *StreamClient) Exchange(local net.Conn) error {
 		if err != nil {
 			return nil
 		}
-		if err := c.WriteL(l); err != nil {
+		if err := c.Write(l); err != nil {
 			return nil
 		}
 	}
 	return nil
 }
 
-func (c *StreamClient) WriteL(l int) error {
+func (c *StreamClient) Write(l int) error {
 	binary.BigEndian.PutUint16(c.WB[:2], uint16(l))
 	c.ca.Seal(c.WB[:0], c.cn, c.WB[:2], nil)
 	NextNonce(c.cn)
@@ -188,7 +188,7 @@ func (c *StreamClient) WriteL(l int) error {
 	return nil
 }
 
-func (c *StreamClient) ReadL() (int, error) {
+func (c *StreamClient) Read() (int, error) {
 	if _, err := io.ReadFull(c.Server, c.RB[:2+16]); err != nil {
 		return 0, err
 	}

programming_language: Go