Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...Security breachSecurity breach
Previous
 
Next
New Post
4/15/2009 2:29 PM
Accepted Answer 

CJones:

I was recently bitten by a stupid code injection/defacement similar to yours, but it only affected the Guestbook module page, which is one of the few places where any user can leave a message, or clever JS code.  This was in DNN 4.9.2.  With DNN 4.9.3 this issue is resolved, not only they documented it, but I tested it and now the user entered text is better sanitized/encoded so that when it comes back from the DB to the browser it is not capable of executing.  I would recommend you consider upgrading to 4.9.3 if possible and your modules are compatible.  Remember to make a full backup the DNN directory and the DB before upgrading and to do testing on a staging server/PC before doing the production site.

Regarding the string search in the DB, some time ago I found the code for a stored procedure that will search all text fields in your database for a given string.  The cool thing about this is that once you create the SP, you can use it forever by calling it with the string as an input parameter.  The SP code is provided below, notice I left the credit text intact since I did not write it.  I did make some adjustments so that it works properly with SQL 2008.  Below is the code, once the SP is created you can do something like EXEC SearchAllTables '212cafe'  and it will return the table name and field name where the text is found.

Hope this helps.

         Carlos

 

USE [YOUR DNN DATABASE NAME HERE]
GO
/****** Object: StoredProcedure [dbo].[SearchAllTables] Script Date: 02/02/2009 14:20:41 ******/

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

 


CREATE PROC [dbo].[SearchAllTables]
(
@SearchStr nvarchar(100)
)
AS
BEGIN

-- Copyright © 2002 Narayana Vyas Kondreddi. All rights reserved.
-- Purpose: To search all columns of all tables for a given search string
-- Written by: Narayana Vyas Kondreddi
-- Site: http://vyaskn.tripod.com
-- Tested on: SQL Server 7.0 and SQL Server 2000
-- Date modified: 28th July 2002 22:50 GMT


CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue nvarchar(3630))

SET NOCOUNT ON

DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110)
SET @TableName = ''
SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')

WHILE @TableName IS NOT NULL
BEGIN
SET @ColumnName = ''
SET @TableName =
(
SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME))
FROM INformATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
AND QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) > @TableName
AND OBJECTPROPERTY(
OBJECT_ID(
QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)
), 'IsMSShipped'
) = 0
)

WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL)
BEGIN
SET @ColumnName =
(
SELECT MIN(QUOTENAME(COLUMN_NAME))
FROM INformATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = PARSENAME(@TableName, 2)
AND TABLE_NAME = PARSENAME(@TableName, 1)
AND DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar', 'text', 'ntext') --Added , 'text', 'ntext'
AND QUOTENAME(COLUMN_NAME) > @ColumnName
)

IF @ColumnName IS NOT NULL
BEGIN
INSERT INTO #Results
EXEC
--CRR, CAST to avoid error "Left func not allowed in NText.
(
'SELECT ''' + @TableName + '.' + @ColumnName + ''', ' + 'CAST(' + @ColumnName + ' AS Varchar(3630))' + '
FROM ' + @TableName + ' (NOLOCK) ' +
' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr2
)
PRINT 'SELECT ''' + @TableName + '.' + @ColumnName + ''', LEFT((CAST(' + @ColumnName + 'AS VARCHAR)), 3630)'
END
END
END

SELECT ColumnName, ColumnValue FROM #Results ORDER BY ColumnName
END


 

 
New Post
4/15/2009 2:30 PM
 

I had a host with the same problems today.  This was not a DNN related issue and affected many windows hosting accounts with this hostiong company.  This affected all aspx pages and standard html files through the host.

The issue appears to be resolved and all website are back to normal, but I want to know how the server(s) were compromised.

Just wanted to share that this was not isolated to you before you go hunting through SQL tables.  This must have been at the IIS level.

Charles Self
Narrow Gate Solutions
www.narrowgatesolutions.com
dotnetnuke.narrowgatesolutions.com - DNN Related Resources

 
New Post
4/15/2009 3:16 PM
 

Thanks for the tips!

Apparently the hosting provider figured out what was up.  After a few hours of the site (and SQL server) being up-and-down, the site is now back up and running and without the malicious javascript link. Hopefully they will forward some helpful info, although that is doubtful.

I wasn't able to run either of the Queries to determine WHERE the hack was placed, as the new site appears to be clean.  I ran the query anyway, but no results.

I'll get to work on preparing for an upgrade ASAP.  I'll also be changing admin/host passwords ASAP.

 
New Post
4/15/2009 5:08 PM
 

Carlos Rodriguez wrote
...Regarding the string search in the DB........The SP code is provided below, notice I left the credit text intact since I did not write it.

Carlos-
That certainly seems to be the same source as the SP I posted -- it's good to see credit for where it came from (after this I'm off to look for other handy queries from Narayana Vyas Kondreddi).  Thanks for including that with your post response.
 
I noticed that your copy seems to be missing the inclusion of the "INT" datatype for searched columns.  You might consider adding this for cases where you are searching for a USERID value (very handy when searching for user submissions in XMOD module tables).
 
Cheers!
-mamlin


esmamlin atxgeek.me
 
New Post
4/16/2009 2:33 AM
 

mamlin wrote

Heh...normally Dario is beating ME to the punch by one minute... 

Timezone matters! Anyway, it looks like I was wrong, the script was most probably injected into the page itself, not in the DB: a host fault, not a DNN/module fault.

Best regards,
Dario Rossa

 
Previous
 
Next
HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...Security breachSecurity breach


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out