select * from table where id = 1
`select * from table where id = ${id};`
`1 or 1 = 1`
`select * from table where id =1 or 1 =1;`
select * from user where username = '${data.username}'
and password = '${data.password}'
1 'or '1'='1
select * from user where username = 'username'
and password = '1' or '1'='1'
SQL 的注入本质是将数据变成了具有逻辑的程序
select * from table where id="10" and 1=0
select * from table where id="10" and 1=1
select * from table where id="10" and mid(version(),1,1)=5--猜数据库的版本
select 1,2,3 from table
select id,1,2,3 from table
select * from table union select 1,2,3 from table2--猜字段个数
select * from table where min(username,1,1)="t"--猜用户名
console.log("[/site/post] error:", e.message, e.stack);
ctx.body = {
status: -1,
body: "出错了"
};
let id = ctx.parmas.id;
id = parseInt(id, 10);
const post = await query{
`select * from post where id =${connecttion.escape(id)}`//escape进行转义
// 有的时候支持下面这种操作
`select * from post where id = ?`, [id]
}
npm install mysql2
这个时候就要改一下引入的 mysql 库,还有 query
const query = bluebird.promisify(
connection.execte.bind(connectionModel).getConnection()
);
//原来是
const query = bluebird.promisify(
connection.query.bind(connectionModel).getConnection()
);
npm install sequelize --save
初始化 ORM 实例
var Sequelize = require("sequelize");
var sequelize = new Sequelize({
host: "localhost",
database: "safety",
username: "root",
define: {
freezeTableName: ture
}
});
module.exports = sequelize;
处理数据表
var sequelize = require("./sequelize");
var Sequelize = require("sequelize");
var Post = sequelize.define(
"post",
{
id: {
type: Sequelize.INTERGER,
primaryKey: ture
},
title: Sequelize.STRING(256),
imgUrl: Sequelize.STRING(256),
content: Sequelize.TEXT
},
{
tableName: "post"
}
);
module.export = Post;
查询操作
let post = await Post.findById(id);
let comment = await Comment.findAll({
where: {
postId: post.id
}
});
看一段 nosql 代码
var mongoose = require('mongoose');
login async function(ctx) {
var username = ctx.request.body.username;
var password = ctx.request.body.password;
mongoose.findOne({
username: username,
password: password
})
}
看似没有什么问题,其实是有问题的,
比如:{"name":"user""password""{"$gt":0}}
这样密码当密码大于 0 时就可以进行登录,也就是任意密码都行,当然用户名也是可以这样操作的
跟关系型一样,从这几方面入手
原文:https://www.cnblogs.com/ygjzs/p/12246627.html