View Single Post
Old Sep 1st, 2004, 10:10 AM   #6
ckocabiyik1980
Newbie
 
Join Date: Aug 2004
Posts: 5
Rep Power: 0 ckocabiyik1980 is on a distinguished road
Thanks for the helps, but i learnt that not every card supports an electronic serial number generation. I found an easy way to obtain the HDD serial number and use it for authentication.And i just wrote a simple program to implement "ls -l" command with HDD authentication. The code is below. Please send comments. Can this code be hacked easily?

[/code]/*
This program will print the folder contents of the program's working directory,
only on an authorized HDD. It will check the serial number of the HDD for this
purpose. In a matching case, it will call the UNIX system function "ls" to list
the folder contents. In the mismatch case, it will give an error message. and
exit. This program executes truely for HDDs havin' 8 character serial numbers like
Seagate HDDs, but can easily be edited to apply to other HDDs.

Second version of this program may be a "TRUE" or "FALSE" returning
program using UNIX sockets to communicate with another code.
*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>

int main(void)
{
FILE *fp; // File pointer for the file generated with "hdparm" system command
int c,j,k,i=0; // General counter variables
char hddparam[BUFSIZ]; // Array to hold the contents of the file
char hddsn[10]; // Array to hold the current disk's serial number (first 8 chars for this version)
char name[11]; // Array to hold the "SerialNo=" text string fetched from the file
char unique[]="ABCDEFGH"; // Required HDD serial number for the program to be executed

// Get HDD parameters to a text file under app's running dir
system("hdparm -i /dev/hda >hddsn.txt");

// Open the file to read
fp=fopen("hddsn.txt","r");

// If file cannot be opened, give error and exit
if(fp==NULL)
{
perror("File cannot be opened!\n");
exit(EXIT_FAILURE);
}

// Get HDD parameters from the generated file into a buffer
while((c=fgetc(fp))!=EOF)
{
hddparam[i]=c;
i++;
}

// Close the file
fclose(fp);

// Remove the file
system("rm -f hddsn.txt");

// Write serial no to the screen and decide what to do
for(i=0;i<strlen(hddparam);i++)
{
// Try to catch clues for the text "SerialNo=" in the buffer
if(hddparam[i]=='S')
{
if((hddparam[i+1]=='e')&&(hddparam[i+6]=='N')&&(hddparam[i+7]=='o')&&(hddparam[i+8]=='='))
{
// Clues are catched, get the string into an array
for(j=i,k=0;j<=i+8;j++,k++)
{
name[k]=hddparam[j];
}

// If the text is "SerialNo=", we are at the right point
if(strcmp(name,"SerialNo=")==0)
{
// Print the text
//printf("%s\n\n",name);

// Get 8 characters following "SerialNo=" from the buffer
// This is the unique HDD serial no for Seagate HDD's
// Not all disks have 8 character serial numbers, so the code
// will change if the system will be installed on a different
// HDD having a serial no in a different format
for(j=i+9,k=0;j<=i+16;j++,k++)
{
hddsn[k]=hddparam[j];
}

// Compare the serial number of the current HDD with the one
// that is unique for my system. Upon match print folder contents
if(strcmp(hddsn,unique)==0)
{
printf("Printing folder contents;\n");
system("ls -l --color");

// Exit
return 0;
}

// This part of the code will be executed if the HDD serial numbers
// don't match
else
{
printf("Error with the code;\n");
printf("**You are not allowed to see the folder contents on this machine**\n");

//Exit
return 0;
}

// Print the serial numbers of current disk and the authorized disk
//printf("This disk:\t%s\n",hddsn);
//printf("Required disk:\t%s\n",unique);
}
}
}
}
}[code]
ckocabiyik1980 is offline   Reply With Quote