Example #1
0
int init_connection(char *ip,char *port,int function)
{
    int server;
    struct sockaddr_in server_addr;
    server_addr.sin_family      = AF_INET;
    server_addr.sin_addr.s_addr = inet_addr(ip);
    server_addr.sin_port        = htons(atoi(port));
    server = socket( AF_INET, SOCK_STREAM, 0 );
    if(connect( server, (struct sockaddr *) &server_addr,sizeof( server_addr ) )<0){
        perror("[E] Connect failed");
        return 1;
    }

    char *buf = malloc(100);
    memset(buf,0,100);
    sprintf(buf,"GET / HTTP/1.1\r\nHost: %s\r\nCookie: pwnginx=%s; action=%d\r\n\r\n", ip, password, function);
    full_send(server,buf,strlen(buf));
    full_recv(server,buf,9);
    if(strncmp(buf,"pwnginx",7)!=0){
        printf("[E] Cannot get banner\n");
        close(server);
        server = -1;
    }
    free(buf);
    return server;
}
Example #2
0
/**
 * This function should initialise the server,
 * and it not invoked after a re-exec.
 * 
 * @return  Non-zero on error
 */
int
initialise_server(void)
{
	int stage = 0;
	const char* const message =
		"Command: intercept\n"
		"Message ID: 0\n"
		"Length: 62\n"
		"\n"
		"Command: list-colours\n"
		"Command: get-colour\n"
		"Command: set-colour\n";

	fail_if (full_send(message, strlen(message)));
	fail_if (server_initialised() < 0);  stage++;;
	fail_if (colour_list_create(&colours, 64) < 0);  stage++;
	fail_if (mds_message_initialise(&received));

	return 0;
fail:
	xperror(*argv);
	if (stage >= 2) colour_list_destroy(&colours);
	if (stage >= 1) mds_message_destroy(&received);
	return 1;
}
Example #3
0
int IP_send(mic_tcp_pdu pk, mic_tcp_sock_addr addr)
{
    if(initialized == -1) return -1;
    if(stm == SERVER) usleep(RTT);
    if(loss_rate == 0)
    {
        mic_tcp_payload tmp = get_full_stream(pk);        
        int sent_size =  full_send(tmp);
        
        free (tmp.data);
        
        return sent_size;             
    }
    else return partial_send(get_full_stream(pk));
}
Example #4
0
/**
 * Perform a VT switch requested by the OS kernel
 * 
 * @param   leave_foreground  Whether the display is leaving the foreground
 * @return                    Zero on success, -1 on error
 */
int switch_vt(int leave_foreground)
{
  char buf[46 + 22];
  
  sprintf(buf,
	  "Command: switching-vt\n"
	  "Message ID: %" PRIu32 "\n"
	  "Status: %s\n"
	  "\n",
	  message_id,
	  leave_foreground ? "deactivating" : "activating");
  
  message_id = message_id == UINT32_MAX ? 0 : (message_id + 1);
  
  fail_if (full_send(socket_fd, buf, strlen(buf)));
  return 0;
 fail:
  return -1;
}
Example #5
0
/**
 * This function should initialise the server,
 * and it not invoked after a re-exec.
 * 
 * @return  Non-zero on error
 */
int
initialise_server(void)
{
	int stage = 0;
	const char* const message =
		"Command: intercept\n"
		"Message ID: 0\n"
		"Length: 14\n"
		"\n"
		"Command: echo\n";

	fail_if (full_send(message, strlen(message)));
	fail_if (server_initialised() < 0); stage++;
	fail_if (mds_message_initialise(&received));

	return 0;
fail:
	xperror(*argv);
	if (stage == 1)
		mds_message_destroy(&received);
	return 1;
}
Example #6
0
/**
 * This function should initialise the server,
 * and it not invoked after a re-exec.
 * 
 * @return  Non-zero on error
 */
int initialise_server(void)
{
  struct vt_mode mode;
  char* display_env;
  int primary_socket_fd;
  int stage = 0;
  const char* const message =
    "Command: intercept\n"
    "Message ID: 0\n"
    "Length: 38\n"
    "\n"
    "Command: get-vt\n"
    "Command: configure-vt\n";
  const char* const secondary_message =
    "Command: intercept\n"
    "Message ID: 0\n"
    "Priority: -4611686018427387904\n" /* −2⁶² */
    "Length: 22\n"
    "\n"
    "Command: switching-vt\n";
  
  primary_socket_fd = socket_fd;
  fail_if (connect_to_display());
  secondary_socket_fd = socket_fd;
  socket_fd = primary_socket_fd;
  
  display_env = getenv("MDS_DISPLAY");
  display_env = display_env ? strchr(display_env, ':') : NULL;
  if ((display_env == NULL) || (strlen(display_env) < 2))
    goto no_display;
  
  memset(vtfile_path, 0, sizeof(vtfile_path));
  xsnprintf(vtfile_path, "%s/%s.vt", MDS_RUNTIME_ROOT_DIRECTORY, display_env + 1);
  stage = 1;
  
  if (is_respawn == 0)
    {
      display_vt = select_vt();
      fail_if (display_vt < 0);
      display_tty_fd = vt_open(display_vt, &old_vt_stat);
      fail_if (write_vt_file() < 0);
      fail_if (vt_set_active(display_vt) < 0);
    }
  else
    {
      fail_if (read_vt_file() < 0);
      vt_is_active = (display_vt == vt_get_active());
      fail_if (vt_is_active < 0);
    }
  
  fail_if (full_send(secondary_socket_fd, secondary_message, strlen(secondary_message)));
  fail_if (full_send(socket_fd, message, strlen(message)));
  fail_if (server_initialised() < 0);
  fail_if (mds_message_initialise(&received)); stage = 2;
  
  fail_if (xsigaction(SIGRTMIN + 2, received_switch_vt) < 0);
  fail_if (xsigaction(SIGRTMIN + 3, received_switch_vt) < 0);
  vt_construct_mode(1, SIGRTMIN + 2, SIGRTMIN + 3, &mode);
  fail_if (vt_get_set_mode(display_tty_fd, 1, &mode) < 0);
  if (vt_set_exclusive(display_tty_fd, 1) < 0)
    xperror(*argv);
  
  return 0;
 no_display:
  eprint("no display has been set, how did this happen.");
  return 1;
 fail:
  xperror(*argv);
  if (stage >= 1)
    unlink(vtfile_path);
  if (display_tty_fd >= 0)
    vt_close(display_tty_fd, &old_vt_stat);
  if (stage >= 2)
    mds_message_destroy(&received);
  return 1;
}