July 21, 2023
How to Restore DataSource credentials on ColdFusion 9
Comments
(1)
July 21, 2023
How to Restore DataSource credentials on ColdFusion 9
Good ol' ColdFusion developer that has 20 years of experience with the language 
Master 8 posts
Followers: 2 people
(1)

I know that some sites still use old versions of ColdFusion, for example, ColdFusion 9. However, through my experience helping clients, it’s surprising to find that the actual number of sites running on ColdFusion is so massive.

Adobe hasn’t supported this version of ColdFusion since 12/31/2014 and those sites are usually hosted on the old versions of Windows. And Microsoft doesn’t support it too.

It generates a lot of security problems- we can’t use the newer version of Java, etc.

Adobe provides very clear migration instructions, for example: https://helpx.adobe.com/pdf/coldfusion2016-migration-guide.pdf. And most cases we can migrate sites with small code updates or without any code change.

In many cases, we are not able to make a migration. We need to copy scripts to the new hosting, setup DataSources etc.

And because we deal with very old sites often created by another developer we can have a situation when nobody has a database password.

But, if we know the ColdFusion admin password and datasource name we can retrieve all information:

<h1>ColdFusion Datasources</h1>

<cfset version=createobject(“java”,”coldfusion.server.ServiceFactory”).LicenseService.getMajorVersion()>

<cfset form. version =variables. version >

<cfif NOT isdefined(“form.adminpassword”) or (isdefined(“form.adminpassword”) AND NOT len(form.adminpassword))  or (isdefined(“form.dsn”) AND NOT len(form.dsn))>

    <cfif (isdefined(“form.adminpassword”) AND NOT len(form.adminpassword)) or  (isdefined(“form.dsn”) AND NOT len(form.dsn))>

        <font color=”#FF0000″>The password and Datasource Name cannot be empty!</font>

    <cfelse>

        <br>

    </cfif>

    <form action=”<cfoutput>#cgi.script_name#</cfoutput>” method=”post”>

        Enter the CF Admin Password: <input type=”password” name=”adminPassword”><br />

                                Enter the Datasource Name: <input type=”text” name=”dsn”><input type=”submit” value=”Submit”>

    </form><cfabort>

<cfelse>

    <cfset adminauth=createObject(‘component’,’CFIDE.adminapi.administrator’).login(‘#form.adminpassword#’)>

    <cfif NOT adminauth>

        <font color=”#FF0000″>The password was incorrect!</font><br>

        <form action=”<cfoutput>#cgi.script_name#</cfoutput>” method=”post”>

            Enter the CF Admin Password: <input type=”password” name=”adminPassword”><input type=”submit” value=”Submit”>

        </form><cfabort>

    </cfif>

</cfif>

<cfif isdefined(“form.adminpassword”) and isdefined(“form.dsn”)>

    <cfoutput>ColdFusion Verion: #variables.version#<br><br></cfoutput>

    <cfif isDefined(“variables.version”) AND variables. version LTE 9>

        <!— Create datasource object —>

        <cfset variables.datasourceObject=createobject(“java”,”coldfusion.server.ServiceFactory”).getDatasourceService().getDatasources()>

   

<table border=”1″ cellpadding=”5″ cellspacing=”0″>

            <tr bgcolor=”c0c0c0″>

                <th>Datasource</th>

                <th>UserName</th>

                <th>Password</th>

                                                                <th>Type</th>

                                                                <th>Database</th>

                                                                <th>Host</th>

            </tr>

            <cfset variables.datasource = form.dsn>

            <cfif len(variables.datasourceObject[variables.datasource][“password”])>

                <cfset variables.database =”>

                <cfset variables.host=”>

                 <cfset variables.username = variables.datasourceObject[variables.datasource][“username”]>

                <cfset variables.driver = variables.datasourceObject[variables.datasource][“driver”]>

                <cftry>

                      <cfset variables.database = variables.datasourceObject[variables.datasource].urlmap.CONNECTIONPROPS.database>

                      <cfset variables.host = variables.datasourceObject[variables.datasource].urlmap.CONNECTIONPROPS.host>

                       <cfcatch type=”any”>

                      </cfcatch>

                </cftry>

                <cfset variables.decryptedPassword = Decrypt(variables.datasourceObject[variables.datasource][“password”],generate3DesKey(“0yJ!@1$r8p0L@r1$6yJ!@1rj”),”DESede”,”Base64″)>

                <!— Output datasource information —>

                <cfoutput>

                <tr>

                    <td>#variables.datasource#</td>

                    <td>#variables.username#</td>

                    <td>#variables.decryptedPassword#</td>

                    <td>#variables.driver#</td>

                    <td>#variables.database#</td>

                    <td>#variables.host#</td>

                </tr>

                </cfoutput>

            </cfif>
        </table>

    </cfif>

</cfif>

If you have questions or need help with this, don’t hesitate to reach out to me and I’ll be happy to assist.

Hopefully this has been helpful. All the best, ColdFusion Community!

1 Comment
2023-07-28 07:19:23
2023-07-28 07:19:23

Hi Igor,

from a migration and security perspective it is always better to have a new user created with a new password

😉

Like
Add Comment