golang gorm框架的sql注入漏洞

keluda ·
老哥看下这个:https://github.com/rushteam/gosql
#2
更多评论
老哥 测试了一把,虽然日志打出来是 SELECT * FROM "test" WHERE (code = 'aaa' or '1'='1') ,但是这应该只是日志显示的问题,真正执行的where条件是 query => code args => "aaa' or '1'='1" 并没有返回数据的。 测试代码如下。 测试环境go1.14, gorm1.9.12 , postgres 12 ``` package main import ( "fmt" "github.com/jinzhu/gorm" _ "github.com/jinzhu/gorm/dialects/postgres" ) type Test struct { Code string } func main() { db, _ := gorm.Open("postgres", "host=127.0.0.1 port=60901 user=test password=123456 dbname=test sslmode=disable") db.SingularTable(true) db.LogMode(true) db.AutoMigrate(&Test{}) defer db.Close() user1 := Test{ Code: "aaa", } db.FirstOrCreate(&user1) var test Test if err := db.Where("code = ?", "aaa' or '1'='1").Find(&test).Error; err != nil { fmt.Println(err) } } ``` 执行结果 ``` (/Users/xxx/Documents/workspace/go/src/github.com/PolarPanda611/test/testgorm/main.go:25) [2020-06-27 23:01:00] [0.34ms] SELECT * FROM "test" WHERE (code = 'aaa' or '1'='1') [0 rows affected or returned ] record not found ```
#1