/* 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.7";
static const char subject[] = "Generic Script Compiler";
static const char cpright[] = "Copyright (c) 1994-2009";
static const struct { const char * f, * s, * e; }
author = { "Francisco", "Rosales", "<frosal@fi.upm.es>" };
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 <none> C compiler flags",
"",
" Please consult the shc(1) man page.",
"",
0};
#include <sys/types.h>
#include <sys/stat.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#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 <sys/stat.h>",
"#include <sys/types.h>",
"",
"#include <errno.h>",
"#include <stdio.h>",
"#include <stdlib.h>",
"#include <string.h>",
"#include <time.h>",
"#include <unistd.h>",
"",
"/* '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 : \"<null>\");",
" fprintf(stderr, \"argc=%d\\n\", argc);",
" if (!argv) {",
" fprintf(stderr, \"argv=<null>\\n\");",
" } else { ",
" for (i = 0; i <= argc ; i++)",
" fprintf(stderr, \"argv[%d]=%.60s\\n\", i, argv[i] ? argv[i] : \"<null>\");",
" }",
"}",
"#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 : \"<null>\");",
"#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 <sys/ptrace.h>",
"#include <sys/types.h>",
"#include <sys/wait.h>",
"#include <fcntl.h>",
"#include <signal.h>",
"#include <stdio.h>",
"#include <unistd.h>",
"",
"#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) {",
" k
烂在棺材里
- 粉丝: 5
- 资源: 4
最新资源
- 小说网站-JAVA-基于springBoot“西贝”小说网站的设计与实现
- 游戏分享网站-JAVA-基于springBoot“腾达”游戏分享网站的设计与实现
- 学习交流-JAVA-基于springBoot“非学勿扰”学习交流平台设计与实现
- EDAfloorplanning
- 所有课程均提供 Python 复习部分.zip
- 所有算法均在 Python 3 中实现,是 hacktoberfest2020 的一个项目 - 没有针对 hacktoberfest 2021 的问题或 PR.zip
- OpenCV的用户手册资源.zip
- 用springmvc实现的校园选课管理系统
- 我的所有 Python 代码都存储在这个文件夹中 .zip
- 以下是关于毕业设计项目开发的详细资源.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页