decode 已经被编码的 uri 参数到表格,超过 max_args(默认为100) 指定的参数个数,err为 "truncated",max_args 设置为 0 代表不限制。
1 2 3 4 5 6 7 8 9 10 11
location = /test { content_by_lua_block { local args,err = ngx.decode_args("foo=3&b+r=hello+world") for k,v in pairs(args) do ngx.say(k, ":",v) end } } [root@192 ~]# curl localhost/test b r:hello world foo:3
location = /test { content_by_lua_block { local b = ngx.hmac_sha1("i am key", "i am str") ngx.say(ngx.encode_base64(b)) } } [root@192 ~]# curl localhost/test SRq/4jXNjh5+wk020o23knh4wls=
location = /test { content_by_lua_block { local args = ngx.req.get_uri_args() local str = "select * from user where name = " local res = str.."'"..args.name.."'" ngx.say(res) } } #正常 curl localhost/test?name=freecls
#select * from user where name = 'freecls' #注入 curl "localhost/test?name=freecls' or '1'='1"
#select * from user where name = 'freecls' or '1'='1'
下面我们利用该函数来转义引号。
1 2 3 4 5 6 7 8 9 10 11 12 13
location = /test { content_by_lua_block { local args = ngx.req.get_uri_args() args.name = ngx.quote_sql_str(args.name) local str = "select * from user where name = " local res = str..args.name ngx.say(res) } } [root@192 ~]# curl "localhost/test?name=freecls' or '1'='1" select * from user where name = 'freecls\' or \'1\'=\'1'