Esempio n. 1
0
int
mta_send (mu_message_t msg)
{
  size_t n;
  char buffer[512];    
  mu_stream_t stream = NULL;
  size_t off = 0, line;
  char *value;

  value = from_address ();
  if (value)
    {
      fprintf (diag, "ENVELOPE FROM: %s\n", value);
      free (value);
    }
  
  value = address_email_string (recipients);
  fprintf (diag, "ENVELOPE TO: %s\n", value);
  free (value);

  mu_message_get_stream (msg, &stream);
  line = 0;
  fprintf (diag, "%4lu: ", (unsigned long) line);
  while (mu_stream_read (stream, buffer, sizeof buffer - 1, off, &n) == 0
	 && n != 0)
    {
      size_t i;

      for (i = 0; i < n; i++)
	{
	  fputc (buffer[i], diag);
	  if (buffer[i] == '\n')
	    {
	      line++;
	      fprintf (diag, "%4lu: ", (unsigned long) line);
	    }
	}
      off += n;
    }
  fprintf (diag, "\nEND OF MESSAGE\n");
  fflush (diag);
  return 0;
}
Esempio n. 2
0
void OutputReceivedMessage(const Hekate::Protobuf::Proto::Server::HekateMessage &msg)
{
    if (!msg.has_hook_info())
    {
        std::cerr << "Missing Hekate -> client message.\n";
        exit(-1);
    }

    if (msg.hook_info().has_send())
    {
        auto hookmsg = msg.hook_info().send();
        std::cout << "Socket: 0x" << std::hex << hookmsg.socket() << std::endl;
        std::cout << "Buffer: ";
        PrintHexBuffer(hookmsg.buffer().c_str(), hookmsg.length());
        std::cout << "Length: 0x" << std::hex << hookmsg.length() << std::endl;
    }
    else if (msg.hook_info().has_sendto())
    {
        auto hookmsg = msg.hook_info().sendto();
        std::cout << "Socket: 0x" << std::hex << hookmsg.socket() << std::endl;
        std::cout << "Buffer: ";
        PrintHexBuffer(hookmsg.buffer().c_str(), hookmsg.length());
        std::cout << "Length: 0x" << std::hex << hookmsg.length() << std::endl;
        std::cout << "to struct address: 0x" << std::hex << hookmsg.to_address() << std::endl;
        std::cout << "to address length: 0x" << std::hex << hookmsg.to_length() << std::endl;
    }
    else if (msg.hook_info().has_wsasend())
    {
        auto hookmsg = msg.hook_info().wsasend();
        std::cout << "Socket: 0x" << std::hex << hookmsg.socket() << std::endl;
        for (int i = 0; i < hookmsg.count(); ++i)
        {
            std::cout << "Buffer #" << i << std::endl;
            PrintHexBuffer(hookmsg.buffers(i).c_str(), hookmsg.buffer_size(i));
        }
        std::cout << "Count: 0x" << std::hex << hookmsg.count() << std::endl;
        std::cout << "Bytes sent address: 0x" << std::hex << hookmsg.bytes_sent_address() << std::endl;
        std::cout << "Flags: 0x" << std::hex << hookmsg.flags() << std::endl;
        std::cout << "Overlapped address: 0x" << std::hex << hookmsg.overlapped_address() << std::endl;
        std::cout << "Overlapped routine address: 0x" << std::hex << hookmsg.overlapped_routine_address() << std::endl;
    }
    else if (msg.hook_info().has_wsasendto())
    {
        auto hookmsg = msg.hook_info().wsasendto();
        std::cout << "Socket: 0x" << std::hex << hookmsg.socket() << std::endl;
        for (int i = 0; i < hookmsg.count(); ++i)
        {
            std::cout << "Buffer #" << i << std::endl;
            PrintHexBuffer(hookmsg.buffers(i).c_str(), hookmsg.buffer_size(i));
        }
        std::cout << "Count: 0x" << std::hex << hookmsg.count() << std::endl;
        std::cout << "Bytes sent address: 0x" << std::hex << hookmsg.bytes_sent_address() << std::endl;
        std::cout << "Flags: 0x" << std::hex << hookmsg.flags() << std::endl;
        std::cout << "to struct address: 0x" << std::hex << hookmsg.to_address() << std::endl;
        std::cout << "to struct length: 0x" << std::hex << hookmsg.to_length() << std::endl;
        std::cout << "Overlapped address: 0x" << std::hex << hookmsg.overlapped_address() << std::endl;
        std::cout << "Overlapped routine address: 0x" << std::hex << hookmsg.overlapped_routine_address() << std::endl;

    }
    else if (msg.hook_info().has_recv())
    {
        auto hookmsg = msg.hook_info().recv();
        std::cout << "Socket: 0x" << std::hex << hookmsg.socket() << std::endl;
        std::cout << "Buffer: ";
        std::cout << "Buffer address: " << hookmsg.buffer() << std::endl;
        std::cout << "Length: 0x" << std::hex << hookmsg.length() << std::endl;
    }
    else if (msg.hook_info().has_recvfrom())
    {
        auto hookmsg = msg.hook_info().recvfrom();
        std::cout << "Socket: 0x" << std::hex << hookmsg.socket() << std::endl;
        std::cout << "Buffer: ";
        std::cout << "Buffer address: " << hookmsg.buffer() << std::endl;
        std::cout << "Length: 0x" << std::hex << hookmsg.length() << std::endl;
        std::cout << "from struct address: 0x" << std::hex << hookmsg.from_address() << std::endl;
        std::cout << "from length address: 0x" << std::hex << hookmsg.from_length_address() << std::endl;
    }
    else if (msg.hook_info().has_wsarecv())
    {
        auto hookmsg = msg.hook_info().wsarecv();
        std::cout << "Socket: 0x" << std::hex << hookmsg.socket() << std::endl;
        for (int i = 0; i < hookmsg.count(); ++i)
        {
            std::cout << "Buffer #" << i << std::endl;
            std::cout << "Buffer address: " << hookmsg.buffers(i) << std::endl;
        }
        std::cout << "Count: 0x" << std::hex << hookmsg.count() << std::endl;
        std::cout << "Bytes received address: 0x" << std::hex << hookmsg.bytes_received_address() << std::endl;
        std::cout << "Flags address: 0x" << std::hex << hookmsg.flags_address() << std::endl;
        std::cout << "Overlapped address: 0x" << std::hex << hookmsg.overlapped_address() << std::endl;
        std::cout << "Overlapped routine address: 0x" << std::hex << hookmsg.overlapped_routine_address() << std::endl;
    }
    else if (msg.hook_info().has_wsarecvfrom())
    {
        auto hookmsg = msg.hook_info().wsarecvfrom();
        std::cout << "Socket: 0x" << std::hex << hookmsg.socket() << std::endl;
        for (int i = 0; i < hookmsg.count(); ++i)
        {
            std::cout << "Buffer #" << i << std::endl;
            std::cout << "Buffer address: " << hookmsg.buffers(i) << std::endl;
        }
        std::cout << "Count: 0x" << std::hex << hookmsg.count() << std::endl;
        std::cout << "Bytes received address: 0x" << std::hex << hookmsg.bytes_received_address() << std::endl;
        std::cout << "Flags address: 0x" << std::hex << hookmsg.flags_address() << std::endl;
        std::cout << "from struct address: 0x" << std::hex << hookmsg.from_address() << std::endl;
        std::cout << "from struct length: 0x" << std::hex << hookmsg.from_length_address() << std::endl;
        std::cout << "Overlapped address: 0x" << std::hex << hookmsg.overlapped_address() << std::endl;
        std::cout << "Overlapped routine address: 0x" << std::hex << hookmsg.overlapped_routine_address() << std::endl;
    }
    else if(msg.has_acknowledge())
    {
        std::cout << "Received acknowledge message from server." << std::endl;
        std::cout << "Code: " << msg.acknowledge().debug_response_id() << std::endl;
    }
    else if (msg.hook_info().has_filter_message())
    {
        auto filtermsg = msg.hook_info().filter_message();
        std::cout << "Received filter hit message." << std::endl;
        std::cout << "Filter hit id: 0x" << std::hex << filtermsg.filter_id() << std::endl;
        if (filtermsg.broken())
        {
            std::cout << "Application is currently in a paused state." << std::endl;
        }
    }
    else
    {
        std::cerr << "Received unknown/empty message from server." << std::endl;
    }
}
Esempio n. 3
0
void
make_tmp (FILE *input, const char *from, char **tempfile)
{
  time_t t;
  int fd = mu_tempfile (NULL, tempfile);
  FILE *fp;
  char *buf = NULL;
  size_t n = 0;
  int line;
  
  if (fd == -1 || (fp = fdopen (fd, "w+")) == NULL)
    {
      mu_error ("%s: unable to open temporary file", progname);
      exit (1);
    }

  line = 0;
  while (getline (&buf, &n, input) > 0)
    {
      int len = strlen (buf);
      if (len >= 2 && buf[len - 2] == '\r')
	{
	  buf[len - 2] = '\n';
	  buf[len - 1] = 0;
	}
	  
      line++;
      if (line == 1)
	{
	  if (memcmp (buf, "From ", 5))
	    {
	      char *from = from_address ();
	      if (from)
		{
		  time (&t);
		  fprintf (fp, "From %s %s", from, ctime (&t));
		  free (from);
		}
	      else
		{
		  mu_error ("%s: can't determine sender address", progname);
		  exit (1);
		}
	    }
	}
      else if (!memcmp (buf, "From ", 5))
	fputc ('>', fp);

      if (dot && buf[0] == '.' &&
	       ((buf[1] == '\r' && buf[2] == '\n') || (buf[1] == '\n')))
	break;
      
      if (fputs (buf, fp) == EOF)
	{
	  mu_error ("%s: temporary file write error", progname);
	  fclose (fp);
	  exit (1);
	}
    }
  
  if (buf && strchr (buf, '\n') == NULL)
    putc ('\n', fp);

  putc ('\n', fp);
  free (buf);

  fclose (fp);
}