pax_global_header00006660000000000000000000000064125750473470014530gustar00rootroot0000000000000052 comment=c515e4354b84966d00bef87a59fe41a0def34702 shc-shc-3.8.9b/000077500000000000000000000000001257504734700132435ustar00rootroot00000000000000shc-shc-3.8.9b/.gitignore000066400000000000000000000003661257504734700152400ustar00rootroot00000000000000# Object files *.o *.ko *.obj *.elf # Precompiled Headers *.gch *.pch # Libraries *.lib *.a *.la *.lo # Shared objects (inc. Windows DLLs) *.dll *.so *.so.* *.dylib # Executables *.exe *.out *.app *.i*86 *.x86_64 *.hex # Debug files *.dSYM/ shc-shc-3.8.9b/CHANGES000066400000000000000000000075531257504734700142500ustar00rootroot00000000000000CHANGES 3.8.9b Fri, 4 Jan 2013 12:10:42 +0100 (CET) Lee Chisnall - To work as daemon. 3.8.9 Wed Apr 25 09:24:25 CEST 2012 Thanks to Giacomo Picconi for: - Fixing a long standing bug making the source not hidden. 3.8.8 Mon Nov 28 11:26:25 CEST 2012 "me". 3.8.7 Wed Feb 10 20:40:37 CET 2010 - Bug on 64bit systems with expiration dates. 3.8.6 Fri Jul 7 15:54:39 CEST 2006 Thanks to George Danchev for: - License clarification about the rc4 implementation. 3.8.5 Fri Oct 21 13:11:36 CEST 2005 Thanks to Jukka A. Ukkonen for: - Fixed untraceable() problems on FreeBSD. 3.8.4 Tue Oct 4 16:52:15 CEST 2005 Thanks to Ron McOuat for: - Fixed sma11 -d option bug. 3.8.3 Tue Jun 28 21:29:06 CEST 2005 Thanks to Jacek Kalinski for: - Fixed bug: "vfork" fails on multiprocessor systems. 3.8.2 Thu Jun 16 17:15:59 CEST 2005 Thanks to Arjen Visser for: - Fixed bug: "rlax" used after encryption. Thanks to Nalneesh Gaur for: - Read permision of the script.x exposes it to disassembling. - Group and others read permision is now removed by default. 3.8 Thu Nov 4 20:33:52 CET 2004 Fixed incorrect implementation on rc4. Hidden all the binary executable symbols but one. Expiration date and most strings are encrypted too. All the encrypted payload is now randomized. 3.7 Wed Jun 18 16:32:26 CEST 2003 Thanks to Philipp Koller for: - Removed all strings in the compiled script. - Improved program output and error messages. - The -m option allows to define the *complete* expiration message. - Updated manpage shc.1. Thanks to Bryan for: - Fix wrong $0 on ksh. 3.6 Fri Feb 21 09:40:32 CET 2003 Two new options: -D switch on Debug exec calls. -T switch off unTraceable. Bash does not need -- after -c. 3.5 Mon Jan 20 19:08:43 CET 2003 Rewrite of large strings to silence the ISO C89 compiler warnings about strings larger than 509 characters. 3.4 Tue Apr 16 17:43:12 CEST 2002 Remove "bad alignment" problem on AIX and other systems. Where exists, use /proc//as in untraceable. 3.3 Thu Jan 24 21:27:07 CET 2002 Prevent to ptrace the process. 3.2 Tue Mar 9 19:03:54 CET 1999 Find ancient pclose that must be fclose. 3.1 Tue Feb 16 21:36:59 CET 1999 Fixed a misbehavior on scripts with a in-frist-line option equal to "end of options" (i.e. #!/bin/sh -- ) (Thanks to Bernard Blundell ) Stupid GCC "warning: return type of `main' is not `int'" removed. 3.0 Tue Oct 14 14:20:52 MET DST 1997 Added a new option "-r" to force a relaxed security and so make a redistributable binary. Modified expiration day format. Now is dd/mm/yyyy. 3.0b3 Fri Jun 6 22:09:05 WET DST 1997 Yet other few bugs fixed. Output format simplified. -pedantic compilation. 3.0b2 Tue Jun 3 17:51:51 GMT 1997 Some explicit type conversions removed. Fixed the bug "END_OF_FILE" when compiling the generated code. A flush is needed before a pclose. st_blksize and st_blocks struct stat fields does not exist on SCO, both not used now. 3.0b1 Wed Feb 26 14:27:22 WET 1997 The main difference with 2.4 is that in it the script was compressed an then shuffle around, now int 3.0 the script is encripted with an inline code, so not needend any external comand to work, and been faster at startup. Other related adventage is that the only information not encripted in .x.c is an stamp, expiration date and provider email address. Something equivalent to cheksums have been used to enforced at execution that the executing shell has not been modified from the time the script was compiled. If anybody tries to change the excuting shell, .x will refuse to execute. The generated .x.c source code is now readable. shc-shc-3.8.9b/Copying000077700000000000000000000000001257504734700155762LICENSEustar00rootroot00000000000000shc-shc-3.8.9b/LICENSE000066400000000000000000000431771257504734700142640ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. {description} Copyright (C) {year} {fullname} This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. {signature of Ty Coon}, 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. shc-shc-3.8.9b/README.md000066400000000000000000000013361257504734700145250ustar00rootroot00000000000000# shc This is the public `shc` source repo, maintained by the `shc` Debian package maintainer, as the original author is not maintaining the package any more -- Details enclosed below: > From: Javier Fafián Ãlvarez @gmail.com > Date: Tue, Sep 8, 2015 at 11:11 AM > Subject: shc 3.8.9 fixed! > To: Tong Sun @cpan.org > > I get another email and he [the original author] answer me -in spanish- **he can't maintain the package any more** but he can help with some bug fixes, and it looks like he fixed it!: > > http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.9b.tgz > > Great! :) This public `shc` source repo contains the `shc` version from its first Debian release, v3.8.7, to the lastest (shc-3.8.9 & shc-3.8.9b). shc-shc-3.8.9b/makefile000066400000000000000000000037531257504734700147530ustar00rootroot00000000000000# Makefile # INSTALL_PATH = /usr/local # For SCO CFLAGS = -b elf -O -D_SVID # For IRIX CFLAGS = -xansi -fullwarn -O3 -g0 # For Solaris CFLAGS = -fast -xO4 -s -v -Xa # For HPUX CFLAGS = -Wall -O -Ae # For OSF1 CFLAGS = -w -verbose -fast -std1 -g0 # For GNU C compiler CFLAGS = -Wall # -O6 -pedantic #SHELL = /bin/sh SHCFLAGS = -v -T # Add -T option to allow binary to be traceable all: shc ask_for_test shc: shc.c $(CC) $(CFLAGS) $@.c -o $@ ask_for_test: @echo '*** ¿Do you want to probe shc with a test script?' @echo '*** Please try... make test' test: make_the_test ask_for_strings make_the_test: match.x @echo '*** Running a compiled test script!' @echo '*** It must show files with substring "sh" in your PATH...' ./match.x sh match.x: shc match @echo '*** Compiling script "match"' CFLAGS="$(CFLAGS)" ./shc $(SHCFLAGS) -f match ask_for_strings: @echo '*** ¿Do you want to see strings in the generated binary?' @echo '*** Please try... make strings' strings: make_the_strings ask_for_expiration make_the_strings: match.x @echo '*** Running: "strings -n 5 'match.x'"' @echo '*** It must show no sensible information...' strings -n 5 match.x ask_for_expiration: @echo '*** ¿Do you want to probe expiration date?' @echo '*** Please try... make expiration' expiration: til_yesterday ask_for_install til_yesterday: shc match @echo '*** Compiling "match" to expired date' CFLAGS="$(CFLAGS)" ./shc $(SHCFLAGS) -vv -e `date "+%d/%m/%Y"` -f match @echo '*** Running a compiled test script!' @echo '*** It must fail showing "./match.x: has expired!"' ./match.x ask_for_install: @echo '*** ¿Do you want to install shc?' @echo '*** Please try... make install' install: shc @echo '*** Installing shc and shc.1 on '$(INSTALL_PATH) @echo -n '*** ¿Do you want to continue? '; read ANS; case "$$ANS" in y|Y|yes|Yes|YES) ;; *) exit 1;; esac; install -c -s shc $(INSTALL_PATH)/bin/ install -c -m 644 shc.1 $(INSTALL_PATH)/man/man1/ clean: rm -f *.o *~ *.x.c cleanall: clean rm -f shc *.x shc-shc-3.8.9b/match000077500000000000000000000005201257504734700142620ustar00rootroot00000000000000#!/bin/sh # # File search script by # Usage: match [Filename] # IFS=":$IFS" for substring in $@ do for path in $PATH do for command in $path/*$substring* do if [ -f $command ] then echo $command fi done done done # Added echo "[$$] PAUSED... Hit return!" read DUMMY shc-shc-3.8.9b/pru.sh000077500000000000000000000002331257504734700144060ustar00rootroot00000000000000#! /bin/sh -x echo "$0" "$@" ps $$ ps wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww $$ cat /proc/$$/cmdline touch $0.kk read ENTER shc-shc-3.8.9b/shc.1000066400000000000000000000061001257504734700140770ustar00rootroot00000000000000.TH shc 1 "Jun 18, 2003" "shc Version 3.8" .UC 4 .SH "NAME" shc - Generic shell script compiler .SH "SYNOPSIS" .B shc [ \-\fBe\fP date ] [ \-\fBm\fP addr ] [ \-\fBi\fP iopt ] [ \-\fBx\fP cmnd ] .br [ \-\fBl\fP lopt ] [ \-\fBACDhTv\fP ] \-\fBf\fP script .SH "DESCRIPTION" .B shc creates a stripped binary executable version of the script specified with \fI\-f\fP on the command line. The binary version will get a \fI.x\fP extension appended and will usually be a bit larger in size than the original ascii code. Generated C source code is saved in a file with the extension \fI.x.c\fP If you supply an expiration date with the \fI\-e\fP option the compiled binary will refuse to run after the date specified. The message \fB"Please contact your provider"\fP will be displayed instead. This message can be changed with the \fI\-m\fP option. You can compile any kind of shell script, but you need to supply valid \fI\-i\fP, \fI\-x\fP and \fI\-l\fP options. The compiled binary will still be dependent on the shell specified in the first line of the shell code (i.e. #!/bin/sh), thus \fBshc\fP does not create completely independent binaries. \fBshc\fP itself is not a compiler such as cc, it rather encodes and encrypts a shell script and generates C source code with the added expiration capability. It then uses the system compiler to compile a stripped binary which behaves exactly like the original script. Upon execution, the compiled binary will decrypt and execute the code with the shell \fI-c\fP option. Unfortunatelly, it will not give you any speed improvement as a real C program would. \fBshc\fP's main purpose is to protect your shell scripts from modification or inspection. You can use it if you wish to distribute your scripts but don't want them to be easily readable by other people. .SH "OPTIONS" The command line options are: .TP .B -e date Expiration date in dd/mm/yyyy format [none] .TP .B -m message message to display upon expiration ["Please contact your provider"] .TP .B -f script_name File name of the script to compile .TP .B -i inline_option Inline option for the shell interpreter i.e: -e .TP .B -x comand eXec command, as a printf format i.e: exec(\\\\'%s\\\\',@ARGV); .TP .B -l last_option Last shell option i.e: -- .TP .B -r Relax security. Make a redistributable binary which executes on different systems running the same operating system. .TP .B -v Verbose compilation .TP .B -D Switch on debug exec calls .TP .B -T Allow binary to be traceable (using strace, ptrace, truss, etc.) .TP .B -C Display license and exit .TP .B -A Display abstract and exit .TP .B -h Display help and exit .SH "ENVIRONMENT VARIABLES" .TP .B CC C compiler command [cc] .TP .B CFLAGS C compiler flags [none] .SH "EXAMPLES" .SM Compile a script which can be run on other systems with the trace option enabled: example% \fBshc\fP -v -r -T -f myscript .SH "BUGS" The maximum size of the script that could be executed once compiled is limited by the operating system configuration parameter .B _SC_ARG_MAX (see .BR sysconf ( 2 )\c ) .SH "AUTHOR" Francisco Rosales .SH "REPORT BUGS TO" the author. shc-shc-3.8.9b/shc.README000066400000000000000000000030101257504734700146710ustar00rootroot00000000000000 Purpose: A generic shell script compiler. Shc takes a script, which is specified on the command line and produces C source code. The generated source code is then compiled and linked to produce a stripped binary executable. Use with care. Building: Just do a "make" Testing: Try: "make test" or: "shc -v -f match" then "match.x sh" Caveat emptor: see Copyright The results look fine to me, but I havn't used this in anger, but the author has used shc for his work widely over SunOS, Solaris and Linux, and done some testing on Irix and HPUX. We tested it on a few SMALL ksh scripts - big tasks should probably be written in C in the first place (see _SC_ARG_MAX below)! Bugs: The one (and I hope the only) limitation using shc is the _SC_ARG_MAX system configuration parameter. It limits the maximum length of the arguments to the exec function, limiting the maximum length of the runnable script of shc. !! - CHECK YOUR RESULTS CAREFULLY BEFORE USING - !! Archived at: ftp://hpux.csc.liv.ac.uk/hpux/Languages/shc-2.4a Archived by: steff@csc.liv.ac.uk Author: Francisco Rosales Garcia -------------------------------------------------------------------- Francisco Rosales García TEL: +341 336 73 80 http://www.datsi.fi.upm.es/~frosal FAX: +34 1 336 73 73 Departamento de Arquitectura y Tecnología de Sistemas Informáticos Facultad de Informática. Universidad Politécnica de Madrid. España -------------------------------------------------------------------- shc-shc-3.8.9b/shc.c000066400000000000000000000604751257504734700142000ustar00rootroot00000000000000/* shc.c */ /** * This software contains an ad hoc version of the 'Alleged RC4' algorithm, * which was anonymously posted on sci.crypt news by cypherpunks on Sep 1994. * * My implementation is a complete rewrite of the one found in * an unknown-copyright (283 characters) version picked up from: * From: allen@gateway.grumman.com (John L. Allen) * Newsgroups: comp.lang.c * Subject: Shrink this C code for fame and fun * Date: 21 May 1996 10:49:37 -0400 * And it is licensed also under GPL. */ static const char my_name[] = "shc"; static const char version[] = "Version 3.8.9b"; static const char subject[] = "Generic Script Compiler"; static const char cpright[] = "Copyright (c) 1994-2015"; static const struct { const char * f, * s, * e; } author = { "Francisco", "Rosales", "" }; static const char * copying[] = { "Copying:", "", " This program is free software; you can redistribute it and/or modify", " it under the terms of the GNU General Public License as published by", " the Free Software Foundation; either version 2 of the License, or", " (at your option) any later version.", "", " This program is distributed in the hope that it will be useful,", " but WITHOUT ANY WARRANTY; without even the implied warranty of", " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the", " GNU General Public License for more details.", "", " You should have received a copy of the GNU General Public License", " along with this program; if not, write to the Free Software", " Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.", "", " Report problems and questions to:", "", 0}; static const char * abstract[] = { "Abstract:", "", " This tool generates a stripped binary executable version", " of the script specified at command line.", "", " Binary version will be saved with a .x extension.", "", " You can specify expiration date [-e] too, after which binary will", " refuse to be executed, displaying \"[-m]\" instead.", "", " You can compile whatever interpreted script, but valid [-i], [-x]", " and [-l] options must be given.", "", 0}; static const char usage[] = "Usage: shc [-e date] [-m addr] [-i iopt] [-x cmnd] [-l lopt] [-rvDTCAh] -f script"; static const char * help[] = { "", " -e %s Expiration date in dd/mm/yyyy format [none]", " -m %s Message to display upon expiration [\"Please contact your provider\"]", " -f %s File name of the script to compile", " -i %s Inline option for the shell interpreter i.e: -e", " -x %s eXec command, as a printf format i.e: exec('%s',@ARGV);", " -l %s Last shell option i.e: --", " -r Relax security. Make a redistributable binary", " -v Verbose compilation", " -D Switch ON debug exec calls [OFF]", " -T Allow binary to be traceable [no]", " -C Display license and exit", " -A Display abstract and exit", " -h Display help and exit", "", " Environment variables used:", " Name Default Usage", " CC cc C compiler command", " CFLAGS C compiler flags", "", " Please consult the shc(1) man page.", "", 0}; #include #include #include #include #include #include #include #include #include #include #include #include #include #define SIZE 4096 static char * file; static char date[21]; static char * mail = "Please contact your provider"; static char rlax[1]; static char * shll; static char * inlo; static char * xecc; static char * lsto; static char * opts; static char * text; static int verbose; static const char DEBUGEXEC_line[] = "#define DEBUGEXEC %d /* Define as 1 to debug execvp calls */\n"; static int DEBUGEXEC_flag; static const char TRACEABLE_line[] = "#define TRACEABLE %d /* Define as 1 to enable ptrace the executable */\n"; static int TRACEABLE_flag; static const char * RTC[] = { "", "/* rtc.c */", "", "#include ", "#include ", "", "#include ", "#include ", "#include ", "#include ", "#include ", "#include ", "", "/* 'Alleged RC4' */", "", "static unsigned char stte[256], indx, jndx, kndx;", "", "/*", " * Reset arc4 stte. ", " */", "void stte_0(void)", "{", " indx = jndx = kndx = 0;", " do {", " stte[indx] = indx;", " } while (++indx);", "}", "", "/*", " * Set key. Can be used more than once. ", " */", "void key(void * str, int len)", "{", " unsigned char tmp, * ptr = (unsigned char *)str;", " while (len > 0) {", " do {", " tmp = stte[indx];", " kndx += tmp;", " kndx += ptr[(int)indx % len];", " stte[indx] = stte[kndx];", " stte[kndx] = tmp;", " } while (++indx);", " ptr += 256;", " len -= 256;", " }", "}", "", "/*", " * Crypt data. ", " */", "void arc4(void * str, int len)", "{", " unsigned char tmp, * ptr = (unsigned char *)str;", " while (len > 0) {", " indx++;", " tmp = stte[indx];", " jndx += tmp;", " stte[indx] = stte[jndx];", " stte[jndx] = tmp;", " tmp += stte[indx];", " *ptr ^= stte[tmp];", " ptr++;", " len--;", " }", "}", "", "/* End of ARC4 */", "", "/*", " * Key with file invariants. ", " */", "int key_with_file(char * file)", "{", " struct stat statf[1];", " struct stat control[1];", "", " if (stat(file, statf) < 0)", " return -1;", "", " /* Turn on stable fields */", " memset(control, 0, sizeof(control));", " control->st_ino = statf->st_ino;", " control->st_dev = statf->st_dev;", " control->st_rdev = statf->st_rdev;", " control->st_uid = statf->st_uid;", " control->st_gid = statf->st_gid;", " control->st_size = statf->st_size;", " control->st_mtime = statf->st_mtime;", " control->st_ctime = statf->st_ctime;", " key(control, sizeof(control));", " return 0;", "}", "", "#if DEBUGEXEC", "void debugexec(char * sh11, int argc, char ** argv)", "{", " int i;", " fprintf(stderr, \"shll=%s\\n\", sh11 ? sh11 : \"\");", " fprintf(stderr, \"argc=%d\\n\", argc);", " if (!argv) {", " fprintf(stderr, \"argv=\\n\");", " } else { ", " for (i = 0; i <= argc ; i++)", " fprintf(stderr, \"argv[%d]=%.60s\\n\", i, argv[i] ? argv[i] : \"\");", " }", "}", "#endif /* DEBUGEXEC */", "", "void rmarg(char ** argv, char * arg)", "{", " for (; argv && *argv && *argv != arg; argv++);", " for (; argv && *argv; argv++)", " *argv = argv[1];", "}", "", "int chkenv(int argc)", "{", " char buff[512];", " unsigned long mask, m;", " int l, a, c;", " char * string;", " extern char ** environ;", "", " mask = (unsigned long)&chkenv;", " mask ^= (unsigned long)getpid() * ~mask;", " sprintf(buff, \"x%lx\", mask);", " string = getenv(buff);", "#if DEBUGEXEC", " fprintf(stderr, \"getenv(%s)=%s\\n\", buff, string ? string : \"\");", "#endif", " l = strlen(buff);", " if (!string) {", " /* 1st */", " sprintf(&buff[l], \"=%lu %d\", mask, argc);", " putenv(strdup(buff));", " return 0;", " }", " c = sscanf(string, \"%lu %d%c\", &m, &a, buff);", " if (c == 2 && m == mask) {", " /* 3rd */", " rmarg(environ, &string[-l - 1]);", " return 1 + (argc - a);", " }", " return -1;", "}", "", "#if !TRACEABLE", "", "#define _LINUX_SOURCE_COMPAT", "#include ", "#include ", "#include ", "#include ", "#include ", "#include ", "#include ", "", "#if !defined(PTRACE_ATTACH) && defined(PT_ATTACH)", "# define PTRACE_ATTACH PT_ATTACH", "#endif", "void untraceable(char * argv0)", "{", " char proc[80];", " int pid, mine;", "", " switch(pid = fork()) {", " case 0:", " pid = getppid();", " /* For problematic SunOS ptrace */", "#if defined(__FreeBSD__)", " sprintf(proc, \"/proc/%d/mem\", (int)pid);", "#else", " sprintf(proc, \"/proc/%d/as\", (int)pid);", "#endif", " close(0);", " mine = !open(proc, O_RDWR|O_EXCL);", " if (!mine && errno != EBUSY)", " mine = !ptrace(PTRACE_ATTACH, pid, 0, 0);", " if (mine) {", " kill(pid, SIGCONT);", " } else {", /*" fprintf(stderr, \"%s is being traced!\\n\", argv0);",*/ " perror(argv0);", " kill(pid, SIGKILL);", " }", " _exit(mine);", " case -1:", " break;", " default:", " if (pid == waitpid(pid, 0, 0))", " return;", " }", " perror(argv0);", " _exit(1);", "}", "#endif /* !TRACEABLE */", "", "char * xsh(int argc, char ** argv)", "{", " char * scrpt;", " int ret, i, j;", " char ** varg;", " char * me = argv[0];", "", " stte_0();", " key(pswd, pswd_z);", " arc4(msg1, msg1_z);", " arc4(date, date_z);", " if (date[0] && (atoll(date) 1) ? ret : 0; /* Args numbering correction */", " while (i < argc)", " varg[j++] = argv[i++]; /* Main run-time arguments */", " varg[j] = 0; /* NULL terminated array */", "#if DEBUGEXEC", " debugexec(shll, j, varg);", "#endif", " execvp(shll, varg);", " return shll;", "}", "", "int main(int argc, char ** argv)", "{", "#if DEBUGEXEC", " debugexec(\"main\", argc, argv);", "#endif", "#if !TRACEABLE", " untraceable(argv[0]);", "#endif", " argv[1] = xsh(argc, argv);", " fprintf(stderr, \"%s%s%s: %s\\n\", argv[0],", " errno ? \": \" : \"\",", " errno ? strerror(errno) : \"\",", " argv[1] ? argv[1] : \"\"", " );", " return 1;", "}", 0}; static int parse_an_arg(int argc, char * argv[]) { extern char * optarg; const char * opts = "e:m:f:i:x:l:rvDTCAh"; struct tm tmp[1]; time_t expdate; int cnt, l; char ctrl; switch (getopt(argc, argv, opts)) { case 'e': memset(tmp, 0, sizeof(tmp)); cnt = sscanf(optarg, "%2d/%2d/%4d%c", &tmp->tm_mday, &tmp->tm_mon, &tmp->tm_year, &ctrl); if (cnt == 3) { tmp->tm_mon--; tmp->tm_year -= 1900; expdate = mktime(tmp); } if (cnt != 3 || expdate <= 0) { fprintf(stderr, "%s parse(-e %s): Not a valid value\n", my_name, optarg); return -1; } sprintf(date, "%lld", (long long)expdate); if (verbose) fprintf(stderr, "%s -e %s", my_name, ctime(&expdate)); expdate = atoll(date); if (verbose) fprintf(stderr, "%s -e %s", my_name, ctime(&expdate)); break; case 'm': mail = optarg; break; case 'f': if (file) { fprintf(stderr, "%s parse(-f): Specified more than once\n", my_name); return -1; } file = optarg; break; case 'i': inlo = optarg; break; case 'x': xecc = optarg; break; case 'l': lsto = optarg; break; case 'r': rlax[0]++; break; case 'v': verbose++; break; case 'D': DEBUGEXEC_flag = 1; break; case 'T': TRACEABLE_flag = 1; break; case 'C': fprintf(stderr, "%s %s, %s\n", my_name, version, subject); fprintf(stderr, "%s %s %s %s %s\n", my_name, cpright, author.f, author.s, author.e); fprintf(stderr, "%s ", my_name); for (l = 0; copying[l]; l++) fprintf(stderr, "%s\n", copying[l]); fprintf(stderr, " %s %s %s\n\n", author.f, author.s, author.e); exit(0); break; case 'A': fprintf(stderr, "%s %s, %s\n", my_name, version, subject); fprintf(stderr, "%s %s %s %s %s\n", my_name, cpright, author.f, author.s, author.e); fprintf(stderr, "%s ", my_name); for (l = 0; abstract[l]; l++) fprintf(stderr, "%s\n", abstract[l]); exit(0); break; case 'h': fprintf(stderr, "%s %s, %s\n", my_name, version, subject); fprintf(stderr, "%s %s %s %s %s\n", my_name, cpright, author.f, author.s, author.e); fprintf(stderr, "%s %s\n", my_name, usage); for (l = 0; help[l]; l++) fprintf(stderr, "%s\n", help[l]); exit(0); break; case -1: if (!file) { fprintf(stderr, "%s parse(-f): No source file specified\n", my_name); file = ""; return -1; } return 0; case ':': fprintf(stderr, "%s parse: Missing parameter\n", my_name); return -1; case '?': fprintf(stderr, "%s parse: Unknown option\n", my_name); return -1; default: fprintf(stderr, "%s parse: Unknown return\n", my_name); return -1; } return 1; } static void parse_args(int argc, char * argv[]) { int err = 0; int ret; #if 0 my_name = strrchr(argv[0], '/'); if (my_name) my_name++; else my_name = argv[0]; #endif do { ret = parse_an_arg(argc, argv); if (ret == -1) err++; } while (ret); if (err) { fprintf(stderr, "\n%s %s\n\n", my_name, usage); exit(1); } } /* 'Alleged RC4' */ static unsigned char stte[256], indx, jndx, kndx; /* * Reset arc4 stte. */ void stte_0(void) { indx = jndx = kndx = 0; do { stte[indx] = indx; } while (++indx); } /* * Set key. Can be used more than once. */ void key(void * str, int len) { unsigned char tmp, * ptr = (unsigned char *)str; while (len > 0) { do { tmp = stte[indx]; kndx += tmp; kndx += ptr[(int)indx % len]; stte[indx] = stte[kndx]; stte[kndx] = tmp; } while (++indx); ptr += 256; len -= 256; } } /* * Crypt data. */ void arc4(void * str, int len) { unsigned char tmp, * ptr = (unsigned char *)str; while (len > 0) { indx++; tmp = stte[indx]; jndx += tmp; stte[indx] = stte[jndx]; stte[jndx] = tmp; tmp += stte[indx]; *ptr ^= stte[tmp]; ptr++; len--; } } /* End of ARC4 */ /* * Key with file invariants. */ int key_with_file(char * file) { struct stat statf[1]; struct stat control[1]; if (stat(file, statf) < 0) return -1; /* Turn on stable fields */ memset(control, 0, sizeof(control)); control->st_ino = statf->st_ino; control->st_dev = statf->st_dev; control->st_rdev = statf->st_rdev; control->st_uid = statf->st_uid; control->st_gid = statf->st_gid; control->st_size = statf->st_size; control->st_mtime = statf->st_mtime; control->st_ctime = statf->st_ctime; key(control, sizeof(control)); return 0; } /* * NVI stands for Shells that complaint "Not Valid Identifier" on * environment variables with characters as "=|#:*?$ ". */ struct { char * shll; char * inlo; char * lsto; char * xecc; } shellsDB[] = { { "perl", "-e", "--", "exec('%s',@ARGV);" }, { "rc", "-c", "", "builtin exec %s $*" }, { "sh", "-c", "", "exec '%s' \"$@\"" }, /* IRIX_nvi */ { "bash", "-c", "", "exec '%s' \"$@\"" }, { "bsh", "-c", "", "exec '%s' \"$@\"" }, /* AIX_nvi */ { "Rsh", "-c", "", "exec '%s' \"$@\"" }, /* AIX_nvi */ { "ksh", "-c", "", "exec '%s' \"$@\"" }, /* OK on Solaris, AIX and Linux (THX ) */ { "tsh", "-c", "--", "exec '%s' \"$@\"" }, /* AIX */ { "ash", "-c", "--", "exec '%s' \"$@\"" }, /* Linux */ { "csh", "-c", "-b", "exec '%s' $argv" }, /* AIX: No file for $0 */ { "tcsh", "-c", "-b", "exec '%s' $argv" }, { NULL, NULL, NULL, NULL }, }; int eval_shell(char * text) { int i; char * ptr; ptr = strchr(text, (int)'\n'); if (!ptr) i = strlen(text); else i = ptr - text; ptr = malloc(i + 1); shll = malloc(i + 1); opts = malloc(i + 1); if (!ptr || !shll || !opts) return -1; strncpy(ptr, text, i); ptr[i] = '\0'; *opts = '\0'; i = sscanf(ptr, " #!%s%s %c", shll, opts, opts); if (i < 1 || i > 2) { fprintf(stderr, "%s: invalid first line in script: %s\n", my_name, ptr); return -1; } free(ptr); shll = realloc(shll, strlen(shll) + 1); ptr = strrchr(shll, (int)'/'); if (*ptr == '/') ptr++; if (verbose) fprintf(stderr, "%s shll=%s\n", my_name, ptr); for(i=0; shellsDB[i].shll; i++) { if(!strcmp(ptr, shellsDB[i].shll)) { if (!inlo) inlo = strdup(shellsDB[i].inlo); if (!xecc) xecc = strdup(shellsDB[i].xecc); if (!lsto) lsto = strdup(shellsDB[i].lsto); } } if (!inlo || !xecc || !lsto) { fprintf(stderr, "%s Unknown shell (%s): specify [-i][-x][-l]\n", my_name, ptr); return -1; } if (verbose) fprintf(stderr, "%s [-i]=%s\n", my_name, inlo); if (verbose) fprintf(stderr, "%s [-x]=%s\n", my_name, xecc); if (verbose) fprintf(stderr, "%s [-l]=%s\n", my_name, lsto); opts = realloc(opts, strlen(opts) + 1); if (*opts && !strcmp(opts, lsto)) { fprintf(stderr, "%s opts=%s : Is equal to [-l]. Removing opts\n", my_name, opts); *opts = '\0'; } else if (!strcmp(opts, "-")) { fprintf(stderr, "%s opts=%s : No real one. Removing opts\n", my_name, opts); *opts = '\0'; } if (verbose) fprintf(stderr, "%s opts=%s\n", my_name, opts); return 0; } char * read_script(char * file) { FILE * i; char * text; int cnt, l; text = malloc(SIZE); if (!text) return NULL; i = fopen(file, "r"); if (!i) return NULL; for (l = 0;;) { text = realloc(text, l + SIZE); if (!text) return NULL; cnt = fread(&text[l], 1, SIZE, i); if (!cnt) break; l += cnt; } fclose(i); text = realloc(text, l + 1); if (!text) return NULL; text[l] = '\0'; /* Check current System ARG_MAX limit. */ if (l > 0.80 * (cnt = sysconf(_SC_ARG_MAX))) { fprintf(stderr, "%s: WARNING!!\n" " Scripts of length near to (or higher than) the current System limit on\n" " \"maximum size of arguments to EXEC\", could comprise its binary execution.\n" " In the current System the call sysconf(_SC_ARG_MAX) returns %d bytes\n" " and your script \"%s\" is %d bytes length.\n", my_name, cnt, file, l); } return text; } unsigned rand_mod(unsigned mod) { /* Without skew */ unsigned rnd, top = RAND_MAX; top -= top % mod; while (top <= (rnd = rand())) continue; /* Using high-order bits. */ rnd = 1.0*mod*rnd/(1.0+top); return rnd; } char rand_chr(void) { return (char)rand_mod(1<<(sizeof(char)<<3)); } int noise(char * ptr, unsigned min, unsigned xtra, int str) { if (xtra) xtra = rand_mod(xtra); xtra += min; for (min = 0; min < xtra; min++, ptr++) do *ptr = rand_chr(); while (str && !isalnum((int)*ptr)); if (str) *ptr = '\0'; return xtra; } static int offset; void prnt_bytes(FILE * o, char * ptr, int m, int l, int n) { int i; l += m; n += l; for (i = 0; i < n; i++) { if ((i & 0xf) == 0) fprintf(o, "\n\t\""); fprintf(o, "\\%03o", (unsigned char)((i>=m) && (i=0) {prnt_array(o, msg1, "msg1", msg1_z, 0); msg1_z=done=-1; break;} case 2: if (date_z>=0) {prnt_array(o, date, "date", date_z, 0); date_z=done=-1; break;} case 3: if (shll_z>=0) {prnt_array(o, shll, "shll", shll_z, 0); shll_z=done=-1; break;} case 4: if (inlo_z>=0) {prnt_array(o, inlo, "inlo", inlo_z, 0); inlo_z=done=-1; break;} case 5: if (xecc_z>=0) {prnt_array(o, xecc, "xecc", xecc_z, 0); xecc_z=done=-1; break;} case 6: if (lsto_z>=0) {prnt_array(o, lsto, "lsto", lsto_z, 0); lsto_z=done=-1; break;} case 7: if (tst1_z>=0) {prnt_array(o, tst1, "tst1", tst1_z, 0); tst1_z=done=-1; break;} case 8: if (chk1_z>=0) {prnt_array(o, chk1, "chk1", chk1_z, 0); chk1_z=done=-1; break;} case 9: if (msg2_z>=0) {prnt_array(o, msg2, "msg2", msg2_z, 0); msg2_z=done=-1; break;} case 10: if (rlax_z>=0) {prnt_array(o, rlax, "rlax", rlax_z, 0); rlax_z=done=-1; break;} case 11: if (opts_z>=0) {prnt_array(o, opts, "opts", opts_z, 0); opts_z=done=-1; break;} case 12: if (text_z>=0) {prnt_array(o, text, "text", text_z, 0); text_z=done=-1; break;} case 13: if (tst2_z>=0) {prnt_array(o, tst2, "tst2", tst2_z, 0); tst2_z=done=-1; break;} case 14: if (chk2_z>=0) {prnt_array(o, chk2, "chk2", chk2_z, 0); chk2_z=done=-1; break;} } indx = 0; } while (!done); } while (numd+=done); fprintf(o, "/* End of data[] */;\n"); fprintf(o, "#define %s_z %d\n", "hide", 1<<12); fprintf(o, DEBUGEXEC_line, DEBUGEXEC_flag); fprintf(o, TRACEABLE_line, TRACEABLE_flag); for (indx = 0; RTC[indx]; indx++) fprintf(o, "%s\n", RTC[indx]); fflush(o); fclose(o); return 0; } int make(void) { char * cc, * cflags; char cmd[SIZE]; cc = getenv("CC"); if (!cc) cc = "cc"; cflags = getenv("CFLAGS"); if (!cflags) cflags = ""; sprintf(cmd, "%s %s %s.x.c -o %s.x", cc, cflags, file, file); if (verbose) fprintf(stderr, "%s: %s\n", my_name, cmd); if (system(cmd)) return -1; sprintf(cmd, "strip %s.x", file); if (verbose) fprintf(stderr, "%s: %s\n", my_name, cmd); if (system(cmd)) fprintf(stderr, "%s: never mind\n", my_name); sprintf(cmd, "chmod go-r %s.x", file); if (verbose) fprintf(stderr, "%s: %s\n", my_name, cmd); if (system(cmd)) fprintf(stderr, "%s: remove read permission\n", my_name); return 0; } void do_all(int argc, char * argv[]) { parse_args(argc, argv); text = read_script(file); if (!text) return; if (eval_shell(text)) return; if (write_C(file, argv)) return; if (make()) return; exit(0); } int main(int argc, char * argv[]) { putenv("LANG="); do_all(argc, argv); /* Return on error */ perror(argv[0]); exit(1); return 1; } shc-shc-3.8.9b/shc.html000066400000000000000000000107161257504734700147130ustar00rootroot00000000000000Content-type: text/html Manpage of shc

shc

Section: User Commands (1)
Updated: Jun 18, 2003
Index Return to Main Contents

 

NAME

shc - Generic shell script compiler  

SYNOPSIS

shc [ -e date ] [ -m addr ] [ -i iopt ] [ -x cmnd ]
[ -l lopt ] [ -ACDhTv ] -f script  

DESCRIPTION

shc creates a stripped binary executable version of the script specified with -f on the command line.

The binary version will get a .x extension appended and will usually be a bit larger in size than the original ascii code. Generated C source code is saved in a file with the extension .x.c

If you supply an expiration date with the -e option the compiled binary will refuse to run after the date specified. The message "Please contact your provider" will be displayed instead. This message can be changed with the -m option.

You can compile any kind of shell script, but you need to supply valid -i, -x and -l options.

The compiled binary will still be dependent on the shell specified in the first line of the shell code (i.e. #!/bin/sh), thus shc does not create completely independent binaries.

shc itself is not a compiler such as cc, it rather encodes and encrypts a shell script and generates C source code with the added expiration capability. It then uses the system compiler to compile a stripped binary which behaves exactly like the original script. Upon execution, the compiled binary will decrypt and execute the code with the shell -c option. Unfortunatelly, it will not give you any speed improvement as a real C program would.

shc's main purpose is to protect your shell scripts from modification or inspection. You can use it if you wish to distribute your scripts but don't want them to be easily readable by other people.  

OPTIONS

The command line options are:
-e date
Expiration date in dd/mm/yyyy format [none]
-m message
message to display upon expiration ["Please contact your provider"]
-f script_name
File name of the script to compile
-i inline_option
Inline option for the shell interpreter i.e: -e
-x comand
eXec command, as a printf format i.e: exec(\\'%s\\',@ARGV);
-l last_option
Last shell option i.e: --
-r
Relax security. Make a redistributable binary which executes on different systems running the same operating system.
-v
Verbose compilation
-D
Switch on debug exec calls
-T
Allow binary to be traceable (using strace, ptrace, truss, etc.)
-C
Display license and exit
-A
Display abstract and exit
-h
Display help and exit
 

ENVIRONMENT VARIABLES

CC
C compiler command [cc]
CFLAGS
C compiler flags [none]
 

EXAMPLES

Compile a script which can be run on other systems with the trace option enabled:


  example% shc -v -r -T -f myscript  

BUGS

The maximum size of the script that could be executed once compiled is limited by the operating system configuration parameter _SC_ARG_MAX (see sysconf(2))  

AUTHOR

Francisco Rosales <frosal@fi.upm.es>  

REPORT BUGS TO

the author.


 

Index

NAME
SYNOPSIS
DESCRIPTION
OPTIONS
ENVIRONMENT VARIABLES
EXAMPLES
BUGS
AUTHOR
REPORT BUGS TO

This document was created by man2html, using the manual pages.
Time: 15:46:31 GMT, July 08, 2004 shc-shc-3.8.9b/test.bash000077500000000000000000000002121257504734700150570ustar00rootroot00000000000000#!/bin/bash -x echo "\$@ is $@" echo "command line: $0 $*" echo "hello world" # Added echo "[$$] PAUSED... Hit return!" read DUMMY exit 0 shc-shc-3.8.9b/test.csh000077500000000000000000000000641257504734700147240ustar00rootroot00000000000000#!/bin/csh -x echo Hello world # A comment exit 0 shc-shc-3.8.9b/test.ksh000077500000000000000000000002161257504734700147330ustar00rootroot00000000000000#! /usr/bin/ksh -x echo "\$@ is $@" echo "command line: $0 $*" echo "hello world" # Added echo "[$$] PAUSED... Hit return!" read DUMMY exit 0 shc-shc-3.8.9b/testit000077500000000000000000000001031257504734700144770ustar00rootroot00000000000000#!/bin/sh set -x echo test started ./test.bash.x echo test ended