コード例 #1
0
ファイル: server.c プロジェクト: tismith/command-server
static void handle_command(char* request, int sock) {
    int i = 0;
    int handled = 0;
    if (DEBUG) fprintf(stderr, "NUM_COMMANDS is %ld, command is %s\n", NUM_COMMANDS, request);
    for (i = 0; i < NUM_COMMANDS; i++) {
        if (strcmp(request, command_defs[i].request) == 0) {
            switch(command_defs[i].type) {
            case builtin:
                handle_builtin(request, &command_defs[i], sock);
                handled = 1;
                break;
#ifdef USE_LUA
            case lua:
                handle_lua(request, &command_defs[i], sock);
                handled = 1;
                break;
#endif
            case shell:
                handle_shell(request, &command_defs[i], sock);
                handled = 1;
                break;
            default:
                fprintf(stderr, "Unknown command type for %s\n", command_defs[i].request);
                break;
            }
        }
    }

    if (!handled) {
        write(sock, UNKNOWN_COMMAND, strlen(UNKNOWN_COMMAND));
    }

}
コード例 #2
0
ファイル: client.c プロジェクト: pamartn/Tiny-Rat
// INTERACT WITH USER AND SERVER IN ORDER TO CHOOSE ACTION
void interact(int socket) {
	printf("---MENU---\n1: SHELL\n2: SCREENSHOT\n3: UPDATE\n---FIN---\n");
	
	char *input;
	int choix = 0; 
	int i;
	// GET INPUT FROM USER AND TRANSFORM IT TO AN INT
	while(choix == 0) {
		input = read_input();
		for(i = 0; i < 4; i++)
			if(strchr(input, i + '0') != NULL)
				choix = i;
	}
	// TELL TO SERVER OUR CHOICE			
	write(socket, input, BUF_SIZE); 
	free(input); 
	
	switch(choix) {
		case 1 : 
			handle_shell(socket);
		break;
		case 2: 
			get_screenshot(socket);
		break;
		case 3:
			send_update(socket);
		break;
	}
	// WE'RE DONE, BYE
	close(socket);
}
コード例 #3
0
ファイル: cockpithandlers.c プロジェクト: arilivigni/cockpit
gboolean
cockpit_handler_default (CockpitWebServer *server,
                         const gchar *path,
                         GHashTable *headers,
                         CockpitWebResponse *response,
                         CockpitHandlerData *data)
{
  CockpitWebService *service;
  const gchar *remainder = NULL;
  gboolean resource;

  path = cockpit_web_response_get_path (response);
  g_return_val_if_fail (path != NULL, FALSE);

  resource = g_str_has_prefix (path, "/cockpit/") ||
             g_str_has_prefix (path, "/cockpit+") ||
             g_str_equal (path, "/cockpit");

  // Check for auth
  service = cockpit_auth_check_cookie (data->auth, path, headers);

  /* Stuff in /cockpit or /cockpit+xxx */
  if (resource)
    {
      cockpit_web_response_skip_path (response);
      remainder = cockpit_web_response_get_path (response);

      if (!remainder)
        {
          cockpit_web_response_error (response, 404, NULL, NULL);
          return TRUE;
        }
      else if (g_str_has_prefix (remainder, "/static/"))
        {
          cockpit_branding_serve (service, response, path, remainder + 8,
                                  data->os_release, data->branding_roots);
          return TRUE;
        }
    }

  if (resource)
    {
      if (g_str_equal (remainder, "/login"))
        {
          handle_login (data, service, path, headers, response);
        }
      else
        {
          handle_resource (data, service, path, headers, response);
        }
    }
  else
    {
      handle_shell (data, service, path, headers, response);
    }

  return TRUE;
}
コード例 #4
0
ファイル: driver_command.c プロジェクト: iagox86/dnscat2
void driver_command_data_received(driver_command_t *driver, uint8_t *data, size_t length)
{
    command_packet_t *in  = NULL;
    command_packet_t *out = NULL;

    buffer_add_bytes(driver->stream, data, length);

    while((in = command_packet_read(driver->stream)))
    {
        /* TUNNEL_DATA commands are too noisy to print. */
        if(in->command_id != TUNNEL_DATA)
        {
            printf("Got a command: ");
            command_packet_print(in);
        }

        switch(in->command_id)
        {
        case COMMAND_PING:
            out = handle_ping(driver, in);
            break;

        case COMMAND_SHELL:
            out = handle_shell(driver, in);
            break;

        case COMMAND_EXEC:
            out = handle_exec(driver, in);
            break;

        case COMMAND_DOWNLOAD:
            out = handle_download(driver, in);
            break;

        case COMMAND_UPLOAD:
            out = handle_upload(driver, in);
            break;

        case COMMAND_SHUTDOWN:
            out = handle_shutdown(driver, in);
            break;

        case COMMAND_DELAY:
            out = handle_delay(driver, in);
            break;

        case TUNNEL_CONNECT:
            out = handle_tunnel_connect(driver, in);
            break;

        case TUNNEL_DATA:
            out = handle_tunnel_data(driver, in);
            break;

        case TUNNEL_CLOSE:
            out = handle_tunnel_close(driver, in);
            break;

        case COMMAND_ERROR:
            out = handle_error(driver, in);
            break;

        default:
            LOG_ERROR("Got a command packet that we don't know how to handle!\n");
            out = command_packet_create_error_response(in->request_id, 0xFFFF, "Not implemented yet!");
        }

        /* Respond if and only if an outgoing packet was created. */
        if(out)
        {
            uint8_t *data;
            size_t   length;

            if(out->command_id != TUNNEL_DATA)
            {
                printf("Response: ");
                command_packet_print(out);
            }

            data = command_packet_to_bytes(out, &length);
            buffer_add_bytes(driver->outgoing_data, data, length);
            safe_free(data);
            command_packet_destroy(out);
        }
        command_packet_destroy(in);
    }
}
コード例 #5
0
ファイル: monitor.c プロジェクト: jarulraj/postgres95
static void
do_input(FILE *ifp)
{
    int c;
    char escape;

    /*
     *  Processing user input.
     *  Basically we stuff the user input to a temp. file until
     *  an escape char. is detected, after which we switch
     *  to the appropriate routine to handle the escape.
     */

    if (ifp == stdin) {
	if (Verbose)
	    fprintf(stdout,"\nGo \n* ");
	else {
	    if (!Silent)
		fprintf(stdout, "* ");
	}
    }
    while ((c = getc(ifp)) != EOF ) {
	if ( c == '\\') {
	    /* handle escapes */
	    escape = getc(ifp);
	    switch( escape ) {
	      case 'e':
		handle_editor();
		break;
	      case 'g':
		handle_send();
		break;
	      case 'i':
		{
		    bool oldVerbose;

		    if (SingleStepMode) {
			oldVerbose = Verbose;
			Verbose = false;
		    }
		    handle_file_insert(ifp);
		    if (SingleStepMode)
			Verbose = oldVerbose;
		}
		break;
	      case 'p':
		handle_print();
		break;
	      case 'q':
		handle_exit(0);
		break;
	      case 'r':
		handle_clear();
		break;
	      case 's':
		handle_shell();
		break;
	      case 't':
		handle_print_time();
		break;
	      case 'w':
		handle_write_to_file();
		break;
	      case '?':
	      case 'h':
		handle_help();
		break;
	      case '\\':
		c = escape;
		stuff_buffer(c); 
		break;
	      case ';':
		c = escape;
		stuff_buffer(c);
		break;
	      default:
		fprintf(stderr, "unknown escape given\n");
		break;
	    } /* end-of-switch */
	    if (ifp == stdin && escape != '\\') {
		if (Verbose)
		    fprintf(stdout,"\nGo \n* ");
		else {
		    if (!Silent)
			fprintf(stdout, "* ");
		}
	    }
	} else {
	    stuff_buffer(c);
	    if (c == ';' && SemicolonIsGo) {
		handle_send();
		if (Verbose)
		    fprintf(stdout,"\nGo \n* ");
		else {
		    if (!Silent)
			fprintf(stdout, "* ");
		}
	    }
	}
    }
}