CVE-2015-10044 (Go, published 2023-01-15T10:15Z)
Description: value: A vulnerability classified as critical was found in gophergala sqldump. This vulnerability affects unknown code. The manipulation leads to sql injection. The patch is identified as 76db54e9073b5248b8863e71a63d66a32d567d21. It is recommended to apply a patch to fix this issue. VDB-218350 is the identifier assigned to this vulnerability.
Severity: nan (CVSS v3 base score: 9.8)
Weakness: CWE-89 \u2014 Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data.
Repository: https://github.com/gophergala/sqldump
Files changed:
README.md
auth.go
aux.go
dump.go
sqldump.go
Commit message: Protection against sql injection doesnt work with ? for table. Using HTMLEscapeString instead


Vulnerable code:
    sudo mysqladmin --defaults-file=/etc/mysql/debian.cnf create gotestdb
    sudo mysql --defaults-file=/etc/mysql/debian.cnf -e "GRANT ALL PRIVILEGES  ON gotestdb.*  TO 'go_user'@'localhost' IDENTIFIED BY 'mypassword'  WITH GRANT OPTION;"
    mysql -p"mypassword" -u go_user gotestdb -e 'create table posts (title varchar(64) default null, start date default null);'
    mysql -p"mypassword" -u go_user gotestdb -e 'insert into posts values("hello","2015-01-01");'
    mysql -p"mypassword" -u go_user gotestdb -e 'insert into posts values("more","2015-01-03");'
    mysql -p"mypassword" -u go_user gotestdb -e 'insert into posts values("end","2015-01-23");'
    mysql -p"mypassword" -u go_user gotestdb -B -e 'select * from posts;'
. output in tables
/* no Credentials management needed
func getCredentials(request *http.Request) (userName string, password string) {
	if cookie, err := request.Cookie("Credentials"); err == nil {
		if err = cookieHandler.Decode("Credentials", cookie.Value, &cookieValue); err == nil {
	return userName, password
func setCredentials(userName string, pw string, w http.ResponseWriter) {
	if encoded, err := cookieHandler.Encode("Credentials", value); err == nil {
			Name:  "Credentials",
		Name:   "Credentials",
		setCredentials(user, pass, w)
   <label for="user">User name</label><input type="text" id="user" name="user">
   <label for="password">Password</label><input type="password" id="password" name="password">
func dsn(user string, pw string, db string) string {
 * turn into generic functions
	user, pw := getCredentials(r)
	conn, err := sql.Open("mysql", dsn(user, pw, database))
	user, pw := getCredentials(r)
	conn, err := sql.Open("mysql", dsn(user, pw, database))
	user, pw := getCredentials(r)
	conn, err := sql.Open("mysql", dsn(user, pw, database))
	statement, err := conn.Prepare("select * from ?")
	rows, err := statement.Query(table)
	user, pw := getCredentials(r)
	conn, err := sql.Open("mysql", dsn(user, pw, database))
	statement, err := conn.Prepare("select * from ?")
	rows, err := statement.Query(table)
var host = "localhost"
var port = "3306"
	u, _ := getCredentials(r)
	if u != "" {
		fmt.Fprintln(w, "<h1>", u, "</h1>")

Fixed code:
    sudo mysqladmin --defaults-file=/etc/mysql/debian.cnf create galadb
    sudo mysql --defaults-file=/etc/mysql/debian.cnf -e "GRANT ALL PRIVILEGES  ON galadb.*  TO 'galagopher'@'localhost' IDENTIFIED BY 'mypassword'  WITH GRANT OPTION;"
    mysql -p"mypassword" -u galagopher galadb -e 'create table posts (title varchar(64) default null, start date default null);'
    mysql -p"mypassword" -u galagopher galadb -e 'insert into posts values("hello","2015-01-01");'
    mysql -p"mypassword" -u galagopher galadb -e 'insert into posts values("more","2015-01-03");'
    mysql -p"mypassword" -u galagopher galadb -e 'insert into posts values("end","2015-01-23");'
    mysql -p"mypassword" -u galagopher galadb -B -e 'select * from posts;'
- output in tables
- menu line
/* no session management needed
func getCredentials(request *http.Request) (userName string, password string, host string, port string) {
	if cookie, err := request.Cookie("Datasource"); err == nil {
		if err = cookieHandler.Decode("Datasource", cookie.Value, &cookieValue); err == nil {
			host = cookieValue["host"]
			port = cookieValue["port"]
	return userName, password, host, port
func setCredentials( w http.ResponseWriter, userName string, pw string, host string, port string) {
		"host": host,
		"port": port,
	if encoded, err := cookieHandler.Encode("Datasource", value); err == nil {
			Name:  "Datasource",
		Name:   "Datasource",
	host := request.FormValue("host")
	port := request.FormValue("port")
		setCredentials(w, user, pass, host, port)
   <label for="user">User name</label><input type="text" id="user" name="user"><br>
   <label for="password">Password</label><input type="password" id="password" name="password"><br>
   <label for="host">Host</label><input type="text" id="host" name="host" value="localhost"><br>
   <label for="port">Port</label><input type="text" id="port" name="port" value="3306"><br>
func dsn(user string, pw string, host string, port string, db string) string {
 * turn into more generic functions for printing into tables
	"text/template"
	user, pw, h , p := getCredentials(r)
	conn, err := sql.Open("mysql", dsn(user, pw, h, p, database))
	user, pw, h, p := getCredentials(r)
	conn, err := sql.Open("mysql", dsn(user, pw, h, p, database))
	user, pw, h, p := getCredentials(r)
	conn, err := sql.Open("mysql", dsn(user, pw, h, p, database))
	statement, err := conn.Prepare("select * from " + template.HTMLEscapeString(table))
	rows, err := statement.Query()
	user, pw, h, p := getCredentials(r)
	conn, err := sql.Open("mysql", dsn(user, pw, h, p, database))
	statement, err := conn.Prepare("select * from " + template.HTMLEscapeString(table))
	rows, err := statement.Query()
	user , _ , host , port := getCredentials(r)
	if user != "" {
		fmt.Fprintln(w, "<p>", user + "@" + host + ":" + port, "</p>")