Browse Tag: sed

sed and newlines

sed’s really bad when it comes to newlines — and especially so on OSX. This snippet works quite well for “multiline” sedding:

test:
poops1
        poop
butts1
        butt

cat test |sed -e ':a' -e 'N' -e '$!ba' -e 's/s1\n        /s1, /g' 

output:
poops1, poop
butts1, butt

Removing 1-liner malware code in webpages

More and more client workstations are being infected with keyloggers and trojans. In addition to stealing your WoW username and password (oh noes, my purpz!), they also have been stealing FTP logins.

This has manifested itself in the linux server world by seemingly legit users logging in over FTP, downloading a file, then uploading it a few seconds later with 100-ish bytes appended. A look at xferlog reveals this behavior, usually against a regex of pages (index.*, default.*, etc), and the connecting IP will often be foreign. A look at the secure log will reveal that the password was not brute-forced; rather, it was known.

The real solution is to change all passwords and force the end user to reformat their computer, since they’re infected and do not realize it. Alas, this is not quite practical (though if someone could invent a remote formatter, I’ll give you $10 for it). Rather, advise the end user of the situation and suggest reformatting — or, at the very least, using a collection of anti-spyware, anti-virus, and anti-everything software on their workstation. Change the affected user’s password.

To clean up the leftover malicious code that was appended, find out the exact string (usually a `tail index.php’ will reveal it) — it’s often a <JavaScript> line or an <iframe>. Copy the string completely and we’ll just sed it out:

[code lang=”bash”]sed -i “s#