Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



Forgot your password?
typodupeerror
×
Perl Programming

'Protecting' Perl Code? 106

An anonymous reader asks: "Ok, so here is the scenario: my company has some software that is used internally and it is written in Perl. We now need to put this code on a server that has 'public' access (it's a university machine). We provide root access to the system for the purpose of learning, but we need to keep the code from being viewed or edited. Is there anything to do besides the 'perl2exe' and the ActiveState compiler? How effective are those really at protecting code?"
This discussion has been archived. No new comments can be posted.

'Protecting' Perl Code?

Comments Filter:
  • by Cyclone66 ( 217347 ) on Thursday November 10, 2005 @11:56PM (#14004787) Homepage Journal
    CHMOD?
    • There's this funny thing about root access...
      • Maybe the university should have a fundraiser and put their important data on a computer where everyone doesn't have root? THEN... CHMOD!
        Or he could try a Perl obfuscator. I never used one for Perl though.
        • by Johnno74 ( 252399 ) on Friday November 11, 2005 @12:05AM (#14004845)
          "Or he could try a Perl obfuscator"

          People have written perl obfuscators? Why? I've never seen perl code that needed an obfuscator.
        • by SanityInAnarchy ( 655584 ) <ninja@slaphack.com> on Friday November 11, 2005 @01:17AM (#14005229) Journal
          The problem with Perl is that it's an interpreted language. That is, you need an interpreter to read the code and then run it. And if the perl binary can read the code, then so can you.

          An obfuscator could work, but then someone could easily nuke the program, or just generally mess with it.

          Honestly, I think it's a retarded idea to begin with. First, drop ALL the root access, no excuses. Add stuff back in with Sudo as needed, giving each command careful review. Then, rewrite your app to work with suidperl, and run that with setuid root, or with sudo.

          That's the technical answer. But honestly, why are you afraid of them looking at your code?
          • The problem with Perl is that it's an interpreted language. That is, you need an interpreter to read the code and then run it. And if the perl binary can read the code, then so can you.

            The bazillions of cracks out there for games and applications written in C++ imply, to me, that this problem is not limited to interpreted languages.

            If your computer can run something - anything - then it can be deciphered by any sufficiently motivated human, period. There is only one "solution" in sight for those who are de
      • Comment removed based on user account deletion
        • Two thoughts.

          The first, root can remount the filesystem.

          The second, I've actually never seen ONLY execute. I've seen disallowing only execute though.
          • Comment removed based on user account deletion
            • How about placing the code on a tightly controlled system and making it available to the insecure system via NFS? The root squash setting should prevent the root users from accessing it and you can set execute-only permissions for the other users.
              • What about when the code is downloaded to the local machine for execution?

                So, I write a hacked version of NFS. I take allowed machine off the network (since I'm root). I clone its mac, I have its SSH keys (since I'm root), I set up with identical IPs and what not. My hacked version of NFS downloads the code and now I have it.

                I don't see a way that they can do this aside from obfuscation, with modern technology. Even crypto requires the file to be decrypted to execute (something that I attended a talk on
        • in order to execute a file, you have to be able to read it from the disk.
          • However, on many systems, the +r bit need not be set. If only +x is set, you can execute the program, but not cat or gdb it. Remember that executing a program is something that involves the OS reading the file, not some program running on the behalf of the user who wants to execute the program.
            • That's true for object code executables. I don't think it's true for interpreted languages like Perl.
              • You're right. (Tested on OS X.)

                But you can write a setuid/setgid program in C and have that C program exec the perl interpreter as a user/group that can read the script. Assuming your wrapper is properly coded (I've gotten root on a large server due to the wrapper using gets...), you should achieve the desired effect. This technique doesn't apply to this article, though, because the person you're trying to hide stuff from is root. Root can install a rootkit (heh) and bypass any protections he wants to.
  • Dr. Greene once said (Score:3, Interesting)

    by Anonymous Coward on Thursday November 10, 2005 @11:58PM (#14004800)
    You could scambling the code un-readable uncompiled.

    One of my professors told me a story about how he once worked with a guy that mantained a project. To help keep his job he would always submit the code scrambled with all names of variables and functions seemingly meaningless. He showed him this one day and asked, "How can you read this?" He said, "I can't. I write the code, put the source through a filter program and then submit the result. If they need someone to fix it or read it or improve it, they will have to go through me." This was back in the early 80's.
  • by mkavanagh2 ( 776662 ) on Friday November 11, 2005 @12:00AM (#14004812)
    ..and it's called "Perl". You don't need to do anything at all for your code to be unreadable.
    • OK, but that doesn't mean you CAN'T take explicit action to make it even MORE unreadable.

      #!/usr/bin/perl

      use strict;
      use warnings;

      ($,,$",$_,@_)=reverse qw(164 163 165 112),",\n",split '','\ ';

      my $music='Art';
      my($swing,$rock)=q
      s/hacker/performer/; # another creator of art...
      my $blues=~/^.(\w+).*#\s(\w+)/;
      my $jazz=substr((grep m($music)=>qx($^X$,-v))[$[],$?,scalar @_);
      my $pop=eval qq("\\@_");

      print $pop, $rock, $jazz, $swing;
      print;
  • by bcat24 ( 914105 )
    Nobody can read it anyway!

    But seriously, if you provide root access to the system, what good is a Perl obfuscator/encryptor/compiler going to do? Nothing can really stop someone with a will and enough free time from decrypting the code.
  • by klui ( 457783 ) on Friday November 11, 2005 @12:01AM (#14004819)
    If it's for learning and people have root, why put it on this server if you don't want people to learn from it?? Still want to do it? Move this perl code to another box and call it via RPC.
  • My first though was it isn't possible. After all, it's root. Root is supposed to be able to do anything.

    My second though was permissions. Why do the students need root access? Couldn't you make some new account that had permissions to do anything but access that one directory?

    My last thought is a sandbox (or I think the BSD concept of a Jail is the same idea). If you were to run Linux on Linux (Xen, or just some other sandbox, maybe even chroot) then you could give them root, while keeping them out of the true root.

    It's a tough situation. Does it really have to be on that server? You can't stick it on a new server your company buys for the purpose and donates (what is more important, My last idea (a bit extreme, I would think) would be to modify the Perl interpreter to run the perl code through a decryption algorithm first (so the source on disk would be encrypted so it couldn't be read). With open source software, there is no reason this isn't possible (would hurt performance though).

    Does Perl support some kind of tolkenizing? When you run a Python script you get the .pyo (I think) file that is basically the cached compiled Python byte code. Can you do that with Perl? It isn't perfect (can be disassembled back into Perl, but without variable names, etc) but it is better than plain text.

    • Perl is already Tolkienized -- just look at the start of every source file!

      More seriously, you can save the internal representation, but it's easy for someone skilled to turn that back in to mostly-readable source code. You don't even lose the variable names; Perl keeps them around. (For globals, you have to -- you always have to do a symbol lookup. Lexicals don't have symbolic access; the compiler turns these into indexes into pads attached to the internal representations of code objects. However, th

      • by rpresser ( 610529 )
        Perl is already Tolkienized -- just look at the start of every source file!

        What, do you have to run it on a Tolkien Ring network instead of Ethernet?

        "One Ring to rule them all,
          One Ring to find them,
          One Ring to bring them all
          And in the darkness bind them."
    • <blockquote>My last idea (a bit extreme, I would think) would be to modify the Perl interpreter to run the perl code through a decryption algorithm first (so the source on disk would be encrypted so it couldn't be read). With open source software, there is no reason this isn't possible (would hurt performance though). Does Perl support some kind of tolkenizing?</blockquote>

      <p>Yeah, this is called a source filter. There are a large number of them on the CPAN. They're all done for fun-rel
  • "We leave our doors open, but how can we stop people from stealing things?"

    I'd re-consider allowing such open access to root.
  • Closed Source? (Score:1, Insightful)

    by Unordained ( 262962 )
    It occurs to me that asking a bunch of pro-open-source geeks how to best maintain control over closed-source code in an sub-ideal environment is perhaps not the best idea ever. In fact, I would suggest that you double-check any answers you get here, as, for all you know, they're purposefully sub-par solutions designed to lull you into a false sense of security so the code can be more easily nabbed.
    • That's nonsense, don't listen to this guy.

      Look, just to show how nice we are, why don't you upload it to my FTP server, give me the root password and IP of this machine, and I'll take care of the rest.

  • Those dudes had a fairly nasty pack/unpack decryption sequence in their pay webmail system that I never got around to cracking. If those tards figured it out surely someone else can.

    Beyond that, make the perl script on the box be a wraper that lwp's a request to your box and spits out the output as a cgi.
    • Re:ADJE webmail (Score:2, Insightful)

      by jonadab ( 583620 )
      > Those dudes had a fairly nasty pack/unpack decryption sequence in their pay webmail system
      > that I never got around to cracking.

      A student who knows Perl and has a long weekend on his hands can buzz through that sort of thing with ease, or a student with a bit less Perl knowledge could post it on the Perlmonks Obfuscated Code section and claim it's "unbreakable", practically guaranteeing it would be broken within fifteen minutes. (Deobfuscation is a recreational activity for some people, and obfusca
  • by dondelelcaro ( 81997 ) <don@donarmstrong.com> on Friday November 11, 2005 @12:16AM (#14004906) Homepage Journal
    This is such a frequently asked question that there's even a faq in the documentation that is distributed in almost every single perl distribution.

    perldoc -q 'hide the source'

    If that's not simple enough, then see the thread on perlmonks.org about it. [perlmonks.org]

    If you still think that obfuscating the source code is going to gain your company anything, then I doubt anyone really wants to see your code at all. (You don't happen to work for Blackboard, do you?)

  • Re Viewing - me thinks this fool is trying to implement security by obscurity. Why else this silly request?

    Re Editing - of course if you have root access you can edit *anything*. Of course if you turn it into a binary, they won't be able to directly edit it, but they could reverse engineer it, re-create it, and edit that. Why stop them? Me thinks this fool wants security by obscurity.

  • The method for protecting your code from being copied is called "copyright". Really, that's the whole reason for the existence of copyright.
  • Re-examine your need (Score:4, Informative)

    by orkysoft ( 93727 ) <orkysoft@m y r e a l b ox.com> on Friday November 11, 2005 @12:35AM (#14005003) Journal
    If you are giving root access to the machine to students, you do not need to put your preciousss perl application on the same machine. In fact, you need to NOT put it there, because even if you obfuscate it, encrypt it, or compile it, it's possible to reverse the process. Obfuscated code can be analyzed and understood, plus it's going to take some real talent and time if you want to do it right, so it's expensive. Encrypted code needs to be decrypted before it can be executed. Compiled code can be decompiled.

    You might use something like a BSD Jail or some other kind of server virtualization, so it merely looks like your software is on another machine. If it is really important that this program remains your dirty little secret, don't put it on a machine which you don't control. Really.

    But if you really want to put it on the same machine, try compiling it into a binary, and not draw any attention to it, to avoid people getting curious about it. Still, if someone finds it and takes enough of an interest in it, all bets are off.
    • But if you really want to put it on the same machine, try compiling it into a binary, and not draw any attention to it, to avoid people getting curious about it.

      Considering the fact that we're discussing it on /., I think we can safely assume that's no longer an option...
  • Is like giving teenager boys whiskey and car keys. I think P.J. O'Rourke said it first about politicians and money...
  • ...no one will understand it anyway.

    How much safer can it get?

    Gregor
  • by croddy ( 659025 )
    if you need to prevent them from altering it, that's easy. put it on read-only media (a CD, not just mount -o ro).

    if you want to give them root and prevent them definitively from reading it, you're going to need to come up with a better plan.

    with a debugger (which i presume they'll have and understand, since these are obviously CS students of some flavor) they'll be able to attach to the process with an all-seeing-eye, so running it on the system where they've got root is just not what you want.

    depend

    • "if you need to prevent them from altering it, that's easy. put it on read-only media (a CD, not just mount -o ro)." If the student is root they can copy the script to another mounted filesystem and edit it all they want.
      • >If the student is root they can copy
        >the script to another mounted filesystem
        >and edit it all they want.

        But, at least then they can't modify the original copy, which in some interpretations is what the article poster is actually worried about. (Not my own interpretation.)

        At least, they can't modify the original copy once you've use epoxy and some kind of watermark to keep them from simply replacing it with a similar looking CD.

        At least, until they replace the system's CD drive with an loop device
  • Just a quick question... what are these students supposedly learning from this script anyway?

    If it was a systems program, well it probably wouldn't have been written in perl, lets be honest.

    AI? If the students can't learn about the algorithm, it's not much use.

    Theory? What will you prove about a black box perl script?
  • by monkeyserver.com ( 311067 ) on Friday November 11, 2005 @01:05AM (#14005174) Homepage Journal
    It sounds like you're a bit confused, if the people are supposed to have access to learn, then why are you denying them access to learn from this script. It sounds like you really just shouldn't have this script on there, as was said before, you should move it elsewhere and call it remotely.

    But MOST IMPORTANTLY, I wouldn't put anything of value or importance onto a machine where uni students have root access. If you remote call, whose to say they won't break the call, if you obfuscate, whose to say that they won't just break the script or delete or replace it. It just seems silly...

    Perhaps you should give them access to a root-like group, then not put this file in that group. I think you problem is that you want more complex permissions then you've relegated yourself to having.
    • I'm thinking that it's a black box script that provides an example. The students are then probbly supposed to make their own that does the same. In this case it might actually work with heavy obfuscation, because the simple requirement of well-commented submissions will defeat any deparsing/-compiling attempts.
  • GrSecurity (Score:4, Informative)

    by BusDriver ( 34906 ) <tim@muppetz.com> on Friday November 11, 2005 @01:10AM (#14005198) Homepage
    Why don't you install yourself a nice Kernel with grsecurity [grsecurity.net].

    Using it's permissions system, you can allow root to login and do whatever you'd like, you but can set grsec so that only certain other groups/systems are able to view/run etc your perl code.

    The permissions system is very configurable and it's a steep learning curve with not a real lot of documentation. But playing with it for a few days should get you all figured out.

    Using grsec it's possible to allow root to login and really do zero damage, it's a great system. I don't think any Linux box should be allowed on the 'net without this patch! There are other systems (SeLinux) that offer the same sort of thing, so if GrSec isn't quite what you need be sure to look at the others.

    Using a system like this means all those "they have root forget about it" isn't true anymore, you can configure it so root can do very little damage to the working system, but still have access to edit all those files the normal pleb user accounts can't.

    Tim
    • LIDS (Score:2, Informative)

      by alder ( 31602 )
      Alternatively you can try LIDS [lids.org]. One of the many features of LIDS is ACLs that are applicable to root as well. Configuring LIDS [lids.org] section of their FAQ gives a number of interesting examples of putting a heavy "lid" on access to the system, while keeping it useable.
  • by miu ( 626917 )
    If you have embeded passwords or hostnames in the app then there is nothing you can realistically do to protect that info. If you are trying to keep thieving students from stealing your code and calling their own then copyright is probably a better answer. We don't even know what the code does, is it possible to host it on a protected machine and run it via cgi or any other rmi?
  • Root can do anything. If you don't want people to have write access to your perl script, then don't give them root access! Think about it. Even if you used something like perl2exe, root could simply delete your script, and replace it with something that did something nasty. Do you really want that? No.
  • by Kawahee ( 901497 )
    You provide access to it for learning purposes, but don't want anybody to view it? Just put it inside a password protected archive or something.
  • I think you want Perl Packager [cpan.org] with the --filter option...there are a few filters that can be used with that (specifically PAR::Filter::Bleach), but if one of these won't work, then I'm afraid you are asking for something that simply doesn't exist...no security through obscurity and all of that...
  • Does the script have to run fully on the unsecured box? If not, then you may be able to break it into two pieces. Run the user interface locally have it call a second script on a secure machine. This may be a simple as ssh or as complex as a full blow client server app depending on your needs. The principle is to perform all "interesting" processing on a remote machine that is secure.
  • a) download perl source
    b) in perl source, modify all control symbols to other control symbols. e.g. "-" treated as "+", "+" treated as "@", etc.
    c) make a script to modify your code's control symbols with the same mapping and obfuscate all variable names to randomly generated ones
    d) run the obfuscated script on obfuscated perl

    by the time they'll decode everything that version of your code will be outdated :)
    • You've got to be kidding, a substitution cipher? Any CS student who can't break that in five minutes is in serious need of a counsellor to tell him to change majors. That's third-grade puzzle-book stuff you're talking about.

      And, quite aside from that, modifying perl is completely unnecessary for that; anyone who knows much Perl could do it trivially with a source filter.
  • This sounds like such a BAD setup: security through obscurity (in Perl?!), basic inability to understand root. After all, if hackers can reverse-engineer DVD software to decrypt all movies, your Perl script doesn't stand a chance. And I bet you're putting a password in it!!

    But assuming you know what you're talking about, it's an interesting puzzle.

    Read-only as root? Mount a write-protected media. CD, floppy, USB dongle. Some hard drives let you set a write-protect jumper. Or you could go with that mod
  • If you must provide root, how about using a system like SELinux that provides "mandatory access control" that root can't override? Then you can lock the kiddies out of messing with anything that could wreck the machine, while leaving them free rein in everything else.
  • by korbatz ( 160895 )
    1) implement soap interface to your program,
    2) put it on secure machine (without "public" accounts)
    3) write client to use your "web service" and put it on university server.
    4) done
  • A lot of people have recommended not giving the students root access. How about just limiting their admin priviliges using sudo? If you're using Linux then you could use SELinux or systrace on OpenBSD to limit what root can do.
  • A memory dump of a running process that is using Perl Dev Kit produced DLLs will also show the embedded Perl code. This happened with the PDK I used a year back. Memory dump was created by Visual Studio 2003 after attaching to the process.
  • Try using Module::Crypt, it just entered CPAN few weeks ago! I've tested it, it works well.

    #!/usr/bin/perl -w

    use strict;
    use lib '/home/vservers/modules';
    use Module::Crypt;

      CryptModule(
            name => 'NCM::Crypttest',
            file => '/home/vservers/crypttest/maedls.at/Crypttest.pm',

      );

     
  • Best protection (Score:3, Interesting)

    by Tux2000 ( 523259 ) <<ed.nekof.todhsals> <ta> <rednaxela>> on Friday November 11, 2005 @04:13AM (#14005922) Homepage Journal

    The best protection for any kind of application you hand over to a customer is a clear license agreement stating what is allowed and what not, together with a good lawyer. It is probably the best way to make the lawyer write the license agreement together with you.

    Just as a good hint for you and your customer(s), you may digitally sign your code with a private key (using PGP or similar). Refuse any kind of support when the signature validation fails, i.e. the code is modified. Think of it as a "warranty void if seal broken" in code. Don't check the signature in the code, this is just stupid. The first step of modifying your code would be to remove the signature checker. The signature checker is a separate application on your computer(s) that you do not give away. It may be just a simple shell script using PGP and your public key.

    Don't even think about encrypting your code, this is plain stupid. Your application needs to know how to decrypt the code, and the decryption engine must be unencrypted to run. So with a minimal modification of the decryption engine, your customer can read your code anyway. A binary decryption engine (XS in Perl) is not directly readable, but it makes the job just a little bit harder. There are decompilers out there.

    Tux2000 <- gave away 100.000 lines of code to paying customers, multiple times

  • It's in the FAQ (Score:4, Insightful)

    by merlyn ( 9918 ) on Friday November 11, 2005 @06:41AM (#14006430) Homepage Journal
    How does something that is answered in the PerlFAQ [cpan.org] make it to a slashdot question?

    [boggle]

  • Yet another Ask Slashdot submission with not enough information about your circumstances or reasoning to offer any kind of truly insightful response... except perhaps this one.

    - What does the code do? Why is it important it is protected?
    - Do these students actually need root access, or is it just management laziness on your/your companies/the universities part?
    - Would these students actually care enough to bother doing anything with this code?
    - Have you considered a jail/sandbox/some kind of secure system e
  • by Ender Ryan ( 79406 ) <MONET minus painter> on Friday November 11, 2005 @08:46AM (#14006970) Journal
    What the hell? That's the stupidest fucking thing I've ever heard. You allow root access, but you want to "protect" code running on the machine? What the fuck?

    You're as bad as all the damn proprietary software vendors who try to prevent people from examining their compiled code in a hex editor or decompiling it.

    Why do you want to do this? Is the code proprietary? Does the code contain security sensitive information?

    If the latter, then jeez, that's just plain piss poor design. In the case of the former, just put a license warning in the code. It's impossible to "protect" overall design and algorithms anyway.

    You can obfuscate the code of course, but really, that's just an exercise in futility.

  • by n9hmg ( 548792 )
    The only non-stupid reason this MUST be on the machine is that it is required that these users be permitted to run it, on this machine.
    If it is on the machine, root shall be able to read it. If it is possible to execute it, the method of easily decrypting it is present on the machine.
    Place it on another machine, executeable only through a network interface, thus making your program itself purely a "black box".

    Example 1: Your program is an encryptor, and it takes a key and a data file.
    The interface c
  • The only way to do what you want is for the script in question to actually live on another box, and you provide a proxy that calls into the other box and runs the script remotely. (i.e. "rsh otherhost -l restricted-account /real/path/to command")

    If they have root on that system, they can read anything on that system, and that's the end of it. You can hide it/obfuscate it N different ways, but they're all fixable -- in order to run it on that box, the perl text (or some equivalent transformation) has to

  • Aren't there true compilers for Perl?
  • You could use this module [cpan.org] to convert your code to Morse code.

    :wq
  • It can't really be done. You can make it harder, but never bulletproof.

    You can use Filter::decrypt or similar to encrypt the source, but if someone's really determined, they can you the B:: modules to look at the opcodes and convert it back to Perl.
  • Root for learning is a great idea but these days give people their own virtual machines. Bochs, User-Mode Linux, and a variety of other solutions are out there.

    Besides, most students have PCs and they can install Linux on their boxes if they want to. Maybe you can negotiate a university license for VMWare or MS's VirtualPC so they can have both MS-Windows and Linux up concurrently in their own dorms.
  • I just posted on comp.lang.python asking about available protection schemes for python code

    Python obfuscation thread at comp.lang.python [google.co.uk]


    petantik.blogsome.com [blogsome.com] - A Lucid Look at Reality
  • Lateral Thinking (Score:2, Informative)

    Give them root on a XEN machine, not the primary box. Allow them to access you perl code in whatever fashion it was intended.
  • But Acme::Bleach [cpan.org] and Acme::Eyedrops [cpan.org] can at least make it a pain in the ass to work out what it's doing.

    However it could be copied verbatim and it would still work.

    As with all other things perl, see CPAN [cpan.org] and perlmonks [perlmonks.org] for more information.

    - Paul
  • man perlcc

    This however only applies for .pl not for .pm (as far as I can see).
    But no one can stop you from including all your pm's into one .pl file..
    Ugly but usable.

    I've never gotten the perlcc to binary (only to bytecode) to work with modules.

  • Acme::DonMartin [cpan.org] is the way to go.

    "The first time you run a program under Acme::DonMartin, your source code is magically transformed into Don Martin cartoon sound effects. [...] This can also be construed as a security feature. It is expected that a hacker will be laughing too hard to be able to recover the source code."
  • There are no options besides obfuscation. Consider the following:

    1. perlcc to compiled code doesn't work for compiling to C for most of code (and generates 5-10Mb of C code that compiles for 10 minutes by gcc) and result doesn't work almost all of the time. Output of 'perlcc -B' can be reversed using B::Deparse..

    2. ActiveState PerlApp just extracts all your project's files to a temporary directory during execution of your "compiled" code. Just copy them from there, with all comments and documentation. S

Genetics explains why you look like your father, and if you don't, why you should.

Working...