[System.Diagnostics.Conditional("DEBUG")]
Archive for July, 2007
Smarter Debug Code With Conditional Compilation
July 18th, 2007 by Sameer | No Comments | Filed in .NET articles70GB of Files Uploaded Because of a Trojan Virus
July 17th, 2007 by Sameer | No Comments | Filed in HostingThe name ‘trojan’ came from a historical concept known as a ‘Trojan Horse’. It was actually a giant wooden horse that was given as a gift to some town or castle, but in reality it was not a gift but had soldiers inside it who jumped out and attacked and ramsacked the town or castle. This word has now come to mean a program that gets inside and attacks your computer! It could be an innocent looking software that you install that has this on it.
Recently I was dealing with a server that was compromised by the Trojan Wollf Virus…
According to Symantec, "Backdoor.Wollf.16 is a Backdoor Trojan Horse that installs itself as a server and allows unauthorized access to an infected computer.."
According to Sophos, it:
- Allows others to access the computer
- Steals information
- Downloads code from the internet
- Records keystrokes
- Installs itself in the Registry
Now.. the hacker who gained access to the serve,r he managed to upload some 70GB of personal files – apps, warez, mp3s, illegally copied movies, etc on this server
Take a look for yourself! Backdoor uploaded files (331kb)
Here is a snippet:
Directory of C:\System Volume Information\catalog.wci\bin\DVDR
06/03/2007 10:54 AM <DIR> .
06/03/2007 10:54 AM <DIR> ..
05/26/2007 10:01 AM <DIR> Borat.2006.PAL.MULTISUBS.DVDR-RUSH
06/03/2007 03:40 AM <DIR> FaTz
06/03/2007 01:25 PM <DIR> Heroes.S01.INTERNAL.HDTV.XviD-SCT
05/26/2007 01:56 PM <DIR> Smokin.Aces.PAL.NORDIC.DVDR-RUSH
05/26/2007 11:22 AM <DIR> The.Fountain.2006.PAL.PROPER.MULTISUBS.DVDR-SSB
0 File(s) 0 bytes
I created this list from command prompt by typing "dir /s > output.txt"
These were uploaded to a dedicated windows machine that had its Windows Update set to "automatically download but let me choose when to install"
I cleaned it up with the following steps:
- Never turn off Automatic Windows update unless you are going to watch it like a Hawk
- If you are infected with a trojan, check your hard disk for large files as you may have been used as a file server
- Install Microsoft Defender
- Install Spybot Search & Destroy
- Install Lavasoft Adaware
- Install ClamWin (will only search) or AVG antivirus (AVG cannot be used for free on servers though)
- Download Mcafee Stinger, a free tool to clean viruses from your machine
- Run Microsoft Malicious Software Removal Tool
- Make sure your Windows Firewall is enabled, or better yet, get ZoneAlarm or some other software firewall
Any comments?
Using DISTINCT in Aggregate Functions
July 5th, 2007 by Sameer | No Comments | Filed in SQLBy Ashiq Alibhai
Note: This article applies to T-SQL; it may or may not work on other varients of SQL.
Many of us are familiar with T-SQL aggregate functions–COUNT, SUM, AVG, MIN, and MAX. However, one often-neglected feature is that you can use these with the DISTINCT keyword.
Imagine you have the following SQL:
CREATE TABLE #TEMP (
VAL INT)
INSERT INTO #TEMP
VALUES (1)
INSERT INTO #TEMP
VALUES (1)
INSERT INTO #TEMP
VALUES (1)
INSERT INTO #TEMP
VALUES (2)
INSERT INTO #TEMP
VALUES (3)
INSERT INTO #TEMP
VALUES (3)
INSERT INTO #TEMP
VALUES (7)
SELECT COUNT(VAL),
COUNT(DISTINCT (VAL))
FROM #TEMP
…will give you the results 7 and 4. Similarly, SUM(DISTINCT(val)) will give you 13 while the non-distinct gives you 18.
Note that while MIN and MAX are also DISTINCTable, doing so doesn’t really add any additional value.
Sql Injections and Securing Clipshare Vulnerabilities
July 2nd, 2007 by Sameer | 6 Comments | Filed in HostingTags: Clipshare, PHPNuke, SQL Injection, SQL Injection Vulnerability
Just last week I was informed that two Clipshare (Youtube clone) sites were hacked. The culprit was a SQL injection vulnerability in the code. This article will explain a creative way of securing your site without really fixing the underlying code.
What is a SQL Injection and how do you fix it?
It means that the code was executing code that looked like this:
ExecuteSQL("Select salary from employees where ID = $_GET['id']");
Where $_GET['id'] means the querystring parameter ID which is passed in as follows:
http://www.yoursite.com/index.php?id=5
However, because we are not "sanitizing" the data before sending it to the sql server, someone can load the URL:
http://www.yoursite.com/index.php?id=5 OR 1=1 (or http encoded as http://www.yoursite.com/index.php?id=5%20OR%201=1
What that means is the SQL statement that will be executed is
ExecuteSQL("Select salary from employees where ID = 5 OR 1=1");
When you say that to the database, return salaries for employees if 1=1 (which is always), thus it will return all records for all employees
Even worse can be done, such as when you are checking a login and password, we had a live site that executed the following SQL and checked if the user and password was correct if a record was returned:
string sql = 'select * from users where login = ' + login + ' and password = ' + password;
(C#)
you could put the login as "admin –" and anything for the password, and the password part was commented out and it would load the following:
select * from users where login = admin – and password = asidasdsad
the – indicates that the rest is a comment and should be ignored by the SQL server, thus it will only execute:
select * from users where login = admin
Now the ClipShare software is full of these vulnerabilities. To fix them (in PHP), you have to call mysql_real_escape_string() on your querystring and form post variables.
So if we have
ExecuteSQL("Select salary from employees where ID = $_GET['id']");
you can change this to:
ExecuteSQL("Select salary from employees where ID = ‘ + mysql_real_escape_string($_GET['id']));
If you want to fix it, you can try to see if there is an upgrade that resolves these problems. If you have heavily modified the script, or you cannot upgrade, this might not be an option.
You can try to fix it yourself, but I looked like every single page was vulnerable.
How to fix your Clipshare software the easy way!
There is another solution that is stronger. This is not the 100% foolproof solution, but it is an easy way to fix it without having to fix your entire bad codeset. What you can do is change the actual database table name from ‘adminusers’ which everyone knows, to something like ‘purpleadmins’. It doesn’t fix the underlying problem (the door is still wide open), but the wallet is hidden somewhere else in the house and nobody can find it, even if they can get in.
Here is how you can do it.
It’s been about a year and this method has worked extremely well and my vulnerable PHP Nuke installation (version 7.1) has not been hacked again yet!
This also worked on two clipshare installations.
First you have to execute some SQL code to change the table name.
1) Rename your column (MySQL code)
ALTER TABLE oldAdminTableName RENAME newAdminTableName;
2) Then you have to execute a search and replace on the actual PHP code.
This will only work if you have the full source code (Some applications such as whois.cart are encoded and you cannot see the source code). To replace in files you can run the following Linux command:
perl -e "s/SEARCH/REPLACE/g;" -pi.save $(find ./*.php -type f)
3) To verify that it actually worked, search for files (linux again)
find . -name "*.c" -exec grep -i "find me" {} /dev/null \;
References:


