Here’s a small Windows Forms application that I created to automate removal of malicious SCRIPT tags inserted into some web files. [more] (or in general - even non malicious scripts).
Of course, you can always do this manually but if we’re talking of hundreds or thousands of files, it will be one heck of a job.
The idea is to:
retrieve list of all script tags in all files in a given folder (including subfolders)
list scripts found
select the scripts to remove - ALSO, if the script contains line break, select it then click on the [View Script Detail] button. Also note that the checkedListBox is not set to check on click
set a folder to save the “cleaned” file
then process (remove the selected scripts and they will be saved on the Target Folder - retaining their folder hierarchy)
That’s it
Here’s a glimpse at the “core” code for the application. Note that I employed recursion inside of the faster, better performing stack approach for simplicity.
The complete source code can be downloaded below. Along with the output (executable).
Search a root folder (and subfolder and files) for script tags (and their contents of course):
| |
Process a root folder (and subfolder and files), check if a script marked as to be removed is found, replace it with empty string (effectively removing it) then save the file on the Target Folder:
| |
Files for Download:
ScriptRemover_Executable.zip (11.11 kb)
ScriptRemover_Source.zip (10.57 kb)
Hope this helps in one way or another and as usual, feel free to make comments/corrections. This has been haphazardly made but tried my best to make it useful and working.
Note: This has some known limitations (due to the regex expression used):
script tags has spaces like
<script>abc</script >(note that the end script tag has a space before the closing bracket)self closing script tags like
<script src="url" />
as there was no need for me to handle these cases, however should you need to handle them, feel free to drop me a message and I’ll try to help out.
By the way, Happy 2009 everyone!