Protecting Python source

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alan Sheehan

    #1

    Protecting Python source

    Hi pythonistas,

    I am looking for methods of deploying applications with end users so
    that the python code is tamper proof. What are my options ?

    I understand I can supply .pyc or .pyo files but they can easily be
    reverse engineered I am told.

    Is it possible to load the scripts from zip files where the zip files
    are password protected ?

    Any other ideas ?

    Many thanks,

    Alan
  • Gerhard Haering

    #2
    Re: Protecting Python source

    On Fri, Nov 26, 2004 at 07:01:27AM -0800, Alan Sheehan wrote:[color=blue]
    > Hi pythonistas,
    >
    > I am looking for methods of deploying applications with end users so
    > that the python code is tamper proof. [...][/color]

    To get more meaningful answers, please expand on what exactly you mean with
    "tamper proof". What is the attacker scenario? Are there passwords for external
    systems embedded in the Python source code, or what's the deal about it?

    -- Gerhard

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (GNU/Linux)

    iD8DBQFBp0eqdIO 4ozGCH14RAoqDAJ 4ub7NKq7fTd+28o KG6rtLxWsP+WgCg mFZQ
    UQlXTe8qpcUKITz GhegBdXo=
    =7/id
    -----END PGP SIGNATURE-----

    Comment

    • Nick Coghlan

      #3
      Re: Protecting Python source

      Alan Sheehan wrote:[color=blue]
      > Hi pythonistas,
      >
      > I am looking for methods of deploying applications with end users so
      > that the python code is tamper proof. What are my options ?
      >
      > I understand I can supply .pyc or .pyo files but they can easily be
      > reverse engineered I am told.[/color]

      If all you want to prevent is casual user tinkering, just shipping compiled
      bytecode is probably enough. (yes it *can* be decompiled, but a casual user
      isn't going to bother, any more than they bother disassembling standard binaries).

      For slightly greater obfuscation, push the key parts you wish to obscure into a
      C/C++ extension module.

      There's nothing to be done to stop the determined cracker, though, as anyone who
      can effectively reverse engineer pure C++ programs is going to be able to figure
      out how to interpret .pyc files pretty quickly.
      [color=blue]
      > Is it possible to load the scripts from zip files where the zip files
      > are password protected ?[/color]

      Since the interpreter needs to read your zipfile, there are potential problems
      with that. I believe it could be done, though. You'd need a C extension module
      which knew the password and installed a custom import hook to handle opening the
      zip file. And disassembling the extension module would also give an attacker
      the password, thus allowing them access to the zipfile.

      So, as Gerhard said, it really depends on what you mean by "tamper proof".

      Cheers,
      Nick.

      Comment

      • Thomas Heller

        #4
        Re: Protecting Python source

        adsheehan@eirco m.net (Alan Sheehan) writes:
        [color=blue]
        > Hi pythonistas,
        >
        > I am looking for methods of deploying applications with end users so
        > that the python code is tamper proof. What are my options ?
        >
        > I understand I can supply .pyc or .pyo files but they can easily be
        > reverse engineered I am told.
        >
        > Is it possible to load the scripts from zip files where the zip files
        > are password protected ?
        >
        > Any other ideas ?[/color]

        For py2exe created distributions, the simplest and imo most effective
        thing is to specify a different extension for the source archive, maybe
        app.lib instead of library.zip. This way, there's at least no hint that
        is is a zip archive.

        For passwords, aren't there lots of zipfile password crackers out there?
        And even in a password protected zipfile you are still able to see the
        filenames iirc, and unless that has changed.

        Thomas

        Comment

        • Josef Meile

          #5
          Re: Protecting Python source

          > I am looking for methods of deploying applications with end users so[color=blue]
          > that the python code is tamper proof. What are my options ?
          >
          > I understand I can supply .pyc or .pyo files but they can easily be
          > reverse engineered I am told.[/color]
          You could try to obfuscate the code with the pyobfuscate package. The
          scripts will be easy to reverse, but difficult to understand. I haven't
          tried it because I haven't had this need, but it shoul work:



          Regards,
          Josef

          Comment

          • RCS

            #6
            Re: Protecting Python source

            Alan Sheehan wrote:
            [color=blue]
            > Hi pythonistas,
            >
            > I am looking for methods of deploying applications with end users so
            > that the python code is tamper proof. What are my options ?[/color]

            An interesting question is, what makes your source code so innovative as
            to mandate this tamper proof thing?

            Just wondering.

            QXX




            Comment

            • Alex Martelli

              #7
              Re: Protecting Python source

              Alan Sheehan <adsheehan@eirc om.net> wrote:
              [color=blue]
              > Hi pythonistas,
              >
              > I am looking for methods of deploying applications with end users so
              > that the python code is tamper proof. What are my options ?[/color]

              Like for any other language, the code you distribute _can_ be
              decompiled, analyzed, studied, and modified, by any attacker determined
              enough to bypass the technical and legal barriers. If your code is
              worth protecting, then it's worth attacking.

              Like for any other language, a solid solution is to put crucial parts of
              your application on a server that is entirely under your control,
              accessed by the rest of the application (the part that you distribute)
              via any distributed processing technology -- Corba, XML-RPC, pyro,
              whatever. The pluses and minuses are obvious: your application will run
              only with network access (which is more and more widely available but
              not yet universal); OTOH, you can exert fine control on who and when can
              access the crucial parts (by subscription, pay per use, whatever
              business model you fancy). It's the only approach that can be made as
              solid as the server you use, which is _very_ solid. Even burning some
              algorithms into a dedicated chip is less robust, since chips _do_ get
              reverse engineered / decompiled too.

              If all you want is to make the barriers as high as reasonably feasible,
              crypted archives with a dedicated pyrex-coded module to decrypt and make
              them accessible to the main program is one way. Legal barriers however
              tend to work better than technical ones, which may be perceived as
              interesting challenges and stimulate attacks. Note that just about any
              piece of software that's widespread, whatever language and protection
              scheme it may have used, is available in cracked form in the `warez'
              circuits. Go server-side as much as you can, and rely on the awesome
              coercive powers of the state for the rest -- "go legal, young man".


              Alex

              Comment

              • Armin Steinhoff

                #8
                Re: Protecting Python source

                Alan Sheehan wrote:[color=blue]
                > Hi pythonistas,
                >
                > I am looking for methods of deploying applications with end users so
                > that the python code is tamper proof. What are my options ?
                >
                > I understand I can supply .pyc or .pyo files but they can easily be
                > reverse engineered I am told.
                >
                > Is it possible to load the scripts from zip files where the zip files
                > are password protected ?
                >
                > Any other ideas ?[/color]

                Use Pyrex in order to convert the critical parts to C modules ...

                Regards

                Armin


                [color=blue]
                >
                > Many thanks,
                >
                > Alan[/color]

                Comment

                • Peter Maas

                  #9
                  Re: Protecting Python source

                  RCS schrieb:[color=blue][color=green]
                  >> I am looking for methods of deploying applications with end users so
                  >> that the python code is tamper proof. What are my options ?[/color]
                  >
                  >
                  > An interesting question is, what makes your source code so innovative as
                  > to mandate this tamper proof thing?[/color]

                  I can think of 3 reasons to prevent tampering:

                  - You need money and want to sell your software on a "per seat" basis.

                  - You don't want customers to fiddle with your code and then innocently
                  call for support and demand "bug fixes" for free.

                  - Your customer demands closed source because the code contains trade
                  secrets.

                  Protecting source has nothing to do with innovation. It's about making
                  money.

                  --
                  -------------------------------------------------------------------
                  Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0
                  E-mail 'cGV0ZXIubWFhc0 BtcGx1c3IuZGU=\ n'.decode('base 64')
                  -------------------------------------------------------------------

                  Comment

                  • Craig Ringer

                    #10
                    Re: Protecting Python source

                    On Mon, 2004-11-29 at 18:04, Peter Maas wrote:
                    [color=blue]
                    > I can think of 3 reasons to prevent tampering:
                    >
                    > - You need money and want to sell your software on a "per seat" basis.[/color]

                    If you mean that you therefore must add built-in copy-protection, then
                    sure. Users will always get around it if they really want to, so
                    tamper-resistance is probably closer to the truth, but it'll slow them
                    down.

                    On the other hand, one can license software per-seat quite effectively
                    without software enforcement, or with only informative software
                    enforcement ("By the way, you appear to be over your seat count."). In
                    many cases this is good enough - the user can always crack / steal your
                    software, tamper resistant or not (witness: the games industry), and
                    code without copy protection is a LOT friendly.

                    For example, my employer currently relies on software that has a dongle.
                    The software manufacturer has gone out of business, so if that dongle
                    dies we're in trouble, as development of a replacement is moving slowly.
                    In future, if we're given the choice between a product that's superior
                    in price or functionality but has opressive copy protection and one
                    that's more limited or more expensive, but has no software enforcement
                    of copy protection, we'll buy the inferior or overpriced one.

                    We're quite capable of monitoring our own license compliance. Those who
                    aren't are also generally quite capable of 'fixing' the software, tamper
                    resistant or not, so I really don't see the point.
                    [color=blue]
                    > - You don't want customers to fiddle with your code and then innocently
                    > call for support and demand "bug fixes" for free.[/color]

                    There, what you really want is tamper-evident code not tamper-proof
                    code. That's quite a bit more practical IMO, and may be a good place to
                    look at digital signing.
                    [color=blue]
                    > - Your customer demands closed source because the code contains trade
                    > secrets.[/color]

                    My understanding is that that's never guaranteed safe, no? Or are
                    restrictions against reverse engineering now commonly enforcable?

                    --
                    Craig Ringer

                    Comment

                    • Peter Maas

                      #11
                      Re: Protecting Python source

                      Craig Ringer schrieb:[color=blue]
                      > On Mon, 2004-11-29 at 18:04, Peter Maas wrote:
                      >
                      >[color=green]
                      >>I can think of 3 reasons to prevent tampering:[/color][/color]
                      [...][color=blue]
                      > My understanding is that that's never guaranteed safe, no? Or are
                      > restrictions against reverse engineering now commonly enforcable?[/color]

                      It's not guaranteed but if protection works in 99.9% of all instal-
                      lations it makes sense, at least if you are not producing highly
                      visible software like Windows.

                      Reverse engineering may be possible but in most cases it is a huge
                      effort. Think of the samba project which builds Windows server
                      software by analyzing network packets and this is probably easier
                      than to analyze machine code.

                      If the "reverse engineering" argument boils down to "protecting source
                      doesn't make sense" then why does Microsoft try so hard to protect
                      its sources?

                      --
                      -------------------------------------------------------------------
                      Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0
                      E-mail 'cGV0ZXIubWFhc0 BtcGx1c3IuZGU=\ n'.decode('base 64')
                      -------------------------------------------------------------------

                      Comment

                      • Grant Edwards

                        #12
                        Re: Protecting Python source

                        On 2004-11-29, Peter Maas <peter@somewher e.com> wrote:
                        [color=blue]
                        > If the "reverse engineering" argument boils down to "protecting source
                        > doesn't make sense" then why does Microsoft try so hard to protect
                        > its sources?[/color]

                        To avoid embarassment.

                        --
                        Grant Edwards grante Yow! Why don't you
                        at ever enter and CONTESTS,
                        visi.com Marvin?? Don't you know
                        your own ZIPCODE?

                        Comment

                        • Dave Reed

                          #13
                          Re: Protecting Python source

                          On Monday 29 November 2004 14:13, Grant Edwards wrote:[color=blue]
                          > On 2004-11-29, Peter Maas <peter@somewher e.com> wrote:
                          >[color=green]
                          > > If the "reverse engineering" argument boils down to "protecting[/color][/color]
                          source[color=blue][color=green]
                          > > doesn't make sense" then why does Microsoft try so hard to protect
                          > > its sources?[/color]
                          >
                          > To avoid embarassment.[/color]

                          +1 QOTW

                          Comment

                          • Marco Aschwanden

                            #14
                            Re: Protecting Python source

                            +1 QOTW

                            Comment

                            • Peter Maas

                              #15
                              Re: Protecting Python source

                              Grant Edwards schrieb:[color=blue]
                              > On 2004-11-29, Peter Maas <peter@somewher e.com> wrote:[color=green]
                              >>If the "reverse engineering" argument boils down to "protecting source
                              >>doesn't make sense" then why does Microsoft try so hard to protect
                              >>its sources?[/color]
                              >
                              >
                              > To avoid embarassment.[/color]

                              :) This cannot be the whole truth otherwise they wouldn't release
                              embarrasing binaries.

                              --
                              -------------------------------------------------------------------
                              Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0
                              E-mail 'cGV0ZXIubWFhc0 BtcGx1c3IuZGU=\ n'.decode('base 64')
                              -------------------------------------------------------------------

                              Comment

                              Working...