Okay so I've figured this out.
It's a vulnerability with your DB access and querystring/form data manipulation, which allows a hacker to inject SQL code into your DB. I know this doesn't sound like it could cause someone alter files, but it's quite elaborate.
In the "master" DB on a MS SQL server, there's an extended stored procedure called "xp_cmdshell" which allows SQL to perform cmd line instructions. Apparently it's a stored procedure that's required for replication and a number of other things.
So... what do they do? They send through a series of commands in the form of http requests to create a .vbs script in your c: root. This .vbs script is just a downloader which saves the result to the C-drive. This is how they can download their trojan to your computer. They then run this trojan, which then is basically a rootkit. I didn't go into how the trojan exactly works but Ewido picked it up, which is a relief. They use the trojan to run commands and insert code into your pages. It's quite sneaky, as it can even get around the acls (I'd tried setting "deny" permissions on the change action on files which were being changed)
So how do you fix the problem? Fix your initial Database logins to not have dbo or sa access to the DB server. Lock down your DB access. There's a heap of writeup's on how to do this. Also, fix your DB requests so that you replace single quotes ' with double single quotes ''
replace(vString, "'", "'')
FWIW, the trojan executables are downloaded from
NB88
this is an very small example of what the page requests look like. This example will just delete any boot.vbs script and create the first line in a new file.
Code:
page.asp?id=2';exec%20master.dbo.xp_cmdshell%20'del%20C:\boot.vbs'
page.asp?id=2';exec%20master.dbo.xp_cmdshell%20'echo%20on%20error%20Resume%20Next%20%20%20%20%20%20%20%20%20%20%20%20>>%20C:\boot.vbs';exec%20master.dbo.sp_dropextendedproc%20'xp_cmdshell'