LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 01-26-2006, 09:47 AM   #1
SPo2
Member
 
Registered: Jun 2005
Posts: 88

Rep: Reputation: 15
How to hide or unexpose source codes.


Hi,

How do one prevent their source code (say a PERL program), from being exposed ?

THanks
 
Old 01-26-2006, 11:18 AM   #2
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD
Posts: 2,004

Rep: Reputation: 304Reputation: 304Reputation: 304Reputation: 304
Use a compiled language (C, C++, Java, etc.) PERL is interpreted at startup, therefor readable by anyone able to run the program. There are PERL compilers available. I don't use them so I can't comment on their abilities.
 
Old 01-26-2006, 09:50 PM   #3
frob23
Senior Member
 
Registered: Jan 2004
Location: Roughly 29.467N / 81.206W
Distribution: Ubuntu, FreeBSD, NetBSD
Posts: 1,449

Rep: Reputation: 47
Code:
chmod 711 /path/to/perl.script
This will set it as -rwx--x--x which means the owner can read and write it, but everyone else can only execute it.
 
Old 01-26-2006, 10:48 PM   #4
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD
Posts: 2,004

Rep: Reputation: 304Reputation: 304Reputation: 304Reputation: 304
Quote:
Originally Posted by frob23
...but everyone else can only execute it.
Execute bit only will not work for PERL scripts. You need to be able to read them too. PERL scripts are interpreted at startup. Unlike a compiled program that can be run with only the execute bit.

Same thing for a shell script. Execute permission alone is not good enough.
 
Old 01-27-2006, 09:34 AM   #5
SPo2
Member
 
Registered: Jun 2005
Posts: 88

Original Poster
Rep: Reputation: 15
Smile

Ok Thanks, i try both, + a compiler.
 
Old 01-27-2006, 05:26 PM   #6
frob23
Senior Member
 
Registered: Jan 2004
Location: Roughly 29.467N / 81.206W
Distribution: Ubuntu, FreeBSD, NetBSD
Posts: 1,449

Rep: Reputation: 47
http://www.cit.gu.edu.au/~anthony/in...adable.scripts

Try this if you want to still be able to edit the script in place (without tricks).

http://www.linuxsecurity.com/content/view/117920/

This is a cool little program as well but I believe it only works with shell scripts and not perl. It create a C program which is the same as your shell script, and encrypts it as well. You can then make it unreadable or not (the user won't be able to decipher it either way).

EDIT: Please see next message for a howto (as linux disallows setgid shell scripts). This behavior is not constant across all Unix and Unix-like operating systems... which is why I was sure the first version worked -- it just doesn't work on Linux, or BSD for that matter but that's another story of me being boneheaded.

Last edited by frob23; 01-27-2006 at 06:18 PM.
 
Old 01-27-2006, 06:34 PM   #7
frob23
Senior Member
 
Registered: Jan 2004
Location: Roughly 29.467N / 81.206W
Distribution: Ubuntu, FreeBSD, NetBSD
Posts: 1,449

Rep: Reputation: 47
Okay, we have a shell, perl, or any other script which can be directly executed /usr/local/noreading/foobar for this example which we don't want our users to be able to read.

First add a group for it, add a line like what follows to /etc/group:
Code:
noreading:*:23005:
Note, the number 23005 can be any number you want as long as it is not already in use. The same with the group name.

Then create a C program, which will do nothing but call our script.
Code:
#include <unistd.h>
#include <errno.h>

int main(int argc, char *argv[]) {
        char filename[]="/usr/local/noreading/foobar";
        execl(filename,filename,NULL);
        return errno;
}
Then compile the script:
Code:
gcc -o runfoobar runfoobar.c
Be sure to switch the runfoobar parts with the name of your file and intended program name.

Move the program to where you want. Then type:
Code:
chgrp noreading /usr/local/noreading/foobar runfoobar
chmod 2755 runfoobar
chmod 750 /usr/local/noreading/foobar
Remember to change all the names and values for what is actually on your system. I placed the example file in a directory which isn't on the default path. So you could have the same name for both the shell script and the binary program which calls it. Just make sure you type in the complete path.

This does not currently pass any arguments. You can add arguments by editing the execl(...) line to something like:
Code:
execv(filename,&argv[0]);
This will pass all the arguments to the script. Note, if your script does not need or expect arguments... use the first method.

Last edited by frob23; 01-27-2006 at 06:47 PM.
 
Old 01-28-2006, 05:09 AM   #8
SPo2
Member
 
Registered: Jun 2005
Posts: 88

Original Poster
Rep: Reputation: 15


Thanks, so much for your sharing of information.....

Although i dont know anything abt C, but i will try to follow ur advise as much as possible.

 
Old 01-28-2006, 01:21 PM   #9
frob23
Senior Member
 
Registered: Jan 2004
Location: Roughly 29.467N / 81.206W
Distribution: Ubuntu, FreeBSD, NetBSD
Posts: 1,449

Rep: Reputation: 47
Follow the steps as best you can (you only need to change the path in the C program to point to the actual script). If you need help, or have a problem, just ask.

It is one of the easiest ways. Once you have the wrapper program in place (the compiled C code), you can edit the script all you want.

Edit: And since you don't know anything about C, this is by far the easiest way to make the scripts unreadable. Much easier than actually porting them to C or another compiled language. You don't need to know C at all here, just drop the full path to the script in the above code and compile it with the command given.

Last edited by frob23; 01-28-2006 at 03:47 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
source codes from different directories crizcroz Programming 5 05-13-2005 06:50 AM
Error when building source codes... darkarcon2015 Linux - Software 4 12-21-2004 11:39 PM
where should I install source codes jaakkop Linux - Software 4 11-12-2004 10:24 AM
installing source codes minm Linux - Newbie 4 09-15-2004 03:03 PM
source codes eltongeoff Linux - Newbie 3 12-07-2003 05:17 PM


All times are GMT -5. The time now is 10:39 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration