示例#1
0
void sc_action_process(struct sc_action *sa) {
	sc_action_debug_print(sa);

	int haskey = 1;

	BUFFER *buffer = buffer_new();

	buffer_write_u8(buffer,(uint8_t)sa->m_shellcode->nspace);
	switch (sa->m_shellcode->nspace) {
	case sc_bindfiletransfer:
	case sc_bindshell:
		buffer_write_u8(buffer, sc_port);
		buffer_write_u16(buffer,htons((uint16_t)sa->m_action.m_bind.m_localport));

		if ( haskey ) {
			buffer_write_u8(buffer,sc_key);
			buffer_write_u32(buffer,htonl((uint32_t)sa->m_action.m_bind.m_key));
		}
		break;

	case sc_connectbackfiletransfer:
	case sc_connectbackshell:
		buffer_write_u8(buffer,sc_host);
		buffer_write_u32(buffer,htonl((uint16_t)sa->m_action.m_connectback.m_remotehost));
		buffer_write_u8(buffer,sc_port);
		buffer_write_u16(buffer,htons((uint16_t)sa->m_action.m_connectback.m_remoteport));
		if ( haskey )
		{
			buffer_write_u8(buffer,sc_key);
			buffer_write_u32(buffer,htonl((uint32_t)sa->m_action.m_connectback.m_key));
		}
		connectback(sa, haskey);
		break;

	case sc_execute:
		buffer_write_u8(buffer,sc_command);
		buffer_write_u8(buffer,strlen(sa->m_action.m_execute.m_command));
		buffer_write_string(buffer,sa->m_action.m_execute.m_command);
		break;

	case sc_url:
		buffer_write_u8(buffer,sc_uri);
		buffer_write_u8(buffer,strlen(sa->m_action.m_url.m_link));
		buffer_write_string(buffer,sa->m_action.m_url.m_link);
		break;

	default:
		break;
	}

//	int size = buffer_write_size_get(buffer);

	// send here

	buffer_free(buffer);

	return;
}
int bvlc_message_encode(bvlc_message_t *message, buffer_t *buf)
{
  // make sure the message has been initialized
  if(message->function == 255)
    return 0;

  int ret = 1
    && buffer_write_u8(buf, BVLC_MAGIC_BYTE)
    && buffer_write_u8(buf, message->function);

  if(ret) {
    switch(message->function) {
      case BVLC_FUNCTION_RESULT:
        ret = bvlc_result_encode(&message->result, buf);
        break;
      case BVLC_FUNCTION_WRITE_BDT:
        ret = bvlc_write_bdt_encode(&message->write_bdt, buf);
        break;
      case BVLC_FUNCTION_READ_BDT:
        ret = bvlc_read_bdt_encode(&message->read_bdt, buf);
        break;
      case BVLC_FUNCTION_READ_BDT_ACK:
        ret = bvlc_read_bdt_ack_encode(&message->read_bdt_ack, buf);
        break;
      case BVLC_FUNCTION_FORWARDED_NPDU:
        ret = bvlc_forwarded_npdu_encode(&message->forwarded_npdu, buf);
        break;
      case BVLC_FUNCTION_REGISTER_FD:
        ret = bvlc_register_fd_encode(&message->register_fd, buf);
        break;
      case BVLC_FUNCTION_READ_FDT:
        ret = bvlc_read_fdt_encode(&message->read_fdt, buf);
        break;
      case BVLC_FUNCTION_READ_FDT_ACK:
        ret = bvlc_read_fdt_ack_encode(&message->read_fdt_ack, buf);
        break;
      case BVLC_FUNCTION_DELETE_FDT_ENTRY:
        ret = bvlc_delete_fdt_entry_encode(&message->delete_fdt_entry, buf);
        break;
      case BVLC_FUNCTION_DISTRIBUTE_BROADCAST:
        ret = bvlc_distribute_broadcast_encode(&message->distribute_broadcast, buf);
        break;
      case BVLC_FUNCTION_ORIGINAL_UNICAST:
        ret = bvlc_original_unicast_encode(&message->original_unicast, buf);
        break;
      case BVLC_FUNCTION_ORIGINAL_BROADCAST:
        ret = bvlc_original_broadcast_encode(&message->original_broadcast, buf);
        break;
      default:
        ret = 0;
        break;
    }
  }

  return ret;
}
示例#3
0
static void
encode_dname(query_type *q, domain_type *domain)
{
	while (domain->parent && query_get_dname_offset(q, domain) == 0) {
		query_put_dname_offset(q, domain, buffer_position(q->packet));
		DEBUG(DEBUG_NAME_COMPRESSION, 2,
		      (LOG_INFO, "dname: %s, number: %lu, offset: %u\n",
		       dname_to_string(domain_dname(domain), NULL),
		       (unsigned long) domain->number,
		       query_get_dname_offset(q, domain)));
		buffer_write(q->packet, dname_name(domain_dname(domain)),
			     label_length(dname_name(domain_dname(domain))) + 1U);
		domain = domain->parent;
	}
	if (domain->parent) {
		DEBUG(DEBUG_NAME_COMPRESSION, 2,
		      (LOG_INFO, "dname: %s, number: %lu, pointer: %u\n",
		       dname_to_string(domain_dname(domain), NULL),
		       (unsigned long) domain->number,
		       query_get_dname_offset(q, domain)));
		assert(query_get_dname_offset(q, domain) <= MAX_COMPRESSION_OFFSET);
		buffer_write_u16(q->packet,
				 0xc000 | query_get_dname_offset(q, domain));
	} else {
		buffer_write_u8(q->packet, 0);
	}
}
示例#4
0
static void
hex_to_string(buffer_type *output, const uint8_t *data, size_t size)
{
	static const char hexdigits[] = {
		'0', '1', '2', '3', '4', '5', '6', '7',
		'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
	};
	size_t i;

	buffer_reserve(output, size * 2);
	for (i = 0; i < size; ++i) {
		uint8_t octet = *data++;
		buffer_write_u8(output, hexdigits[octet >> 4]);
		buffer_write_u8(output, hexdigits[octet & 0x0f]);
	}
}
示例#5
0
文件: options.c 项目: LTD-Beget/nsd
static void
marshal_u8(struct buffer* b, uint8_t v)
{
	buffer_reserve(b, 1);
	buffer_write_u8(b, v);
}