It is currently Sun May 19, 2013 4:38 am



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: network sessions and capture files
PostPosted: Sun May 15, 2011 10:20 am 
Offline

Joined: Sun Apr 24, 2011 7:07 pm
Posts: 6
Background

Hi.
I write a program that analyzes the packets for specific words contained therein. I need to analyze outgoing email, jabber, ICQ. If the words are found, the packet is blocked.I did it, but I have a problem with the files and sending email through the web.
Problems

Simple code:

Code:
while (Ndisapi.ReadPacket(hNdisapi, ref Request))
    {
       // some work
    switch (protocol)
    {
    //....
    case "HTTP":
       // parse packet(byte[])
       HTTP.HttpField field = HTTP.ParseHttp(ret);
       if (field != null && field.Method == HTTP.HttpMethod.POST)
       {
          // analyze packet and drop if needed
          DoWork();
       }
    }


The problem is the following. For example, I attach to email the file of 500 KB. The file will be split approximately in 340 packets. In the code above, DoWork() only for first packet will be executed.
Ok, then I need to restore session completely and pass to whole session to DoWork(). I did it. But I can't wait while session is finished, because other packet( http, arp, all packets) will be suspended (And after a couple of minutes the Internet is disconnected).
Therefore, the first question:

How to solve this problem (may be advice for design program)?

Now the email, suppose this code:

Code:
switch (protocol)
    {
    //....
    case "HTTP":
       // parse packet(byte[])
       var httpMimeMessage = Mime.Parse(ret);
       // analyze packet and drop if needed
        DoSomeWork();
       break;
    }



For example, we are looking for word "Finance". Then, if we open any website and there will be a word finance then packet is blocked.

Second question: How do I determine that this is the e-mail?

Thanks and sorry for my English.
PS. Можно на русском


Top
 Profile  
 
 Post subject: Re: network sessions and capture files
PostPosted: Mon May 16, 2011 6:02 pm 
Offline
Site Admin

Joined: Wed Jul 26, 2006 12:22 pm
Posts: 507
Не все тут просто, как минимум нужно сохранять какой-то контекст для каждой интересующей TCP сессии. Дальше есть два варианта:

1) Кешировать пакеты сессии до тех пока не будет получен весь файл. Для этого придется генерировать ACK пакеты в обратном направлении. Как только файл получен проанализировать его и отправить соответствующие пакеты по назначению. В данном случае придется самостоятельно контроллировать доставку пакетов и делать ретрансмиты если пакеты теряются.

2) Для каждой сессии сохранять ее текущее состояние и каждый следующий пакет анализировать с учетом состояния сессии. Как, например, при обнаружении метода POST сохранить контекст сессии (IP адреса и порты) и затем все пакеты проверять на принадлежность этой сессии. Если пакет принадлежит этой сессии то анализировать его с учетом того что это метод POST.

Первый метод довольно сложный и я бы его не рекомендовал, а второй вполне реально реализовать. Придется конечно реализовать анализатор интересующего протокола, чтобы для каждого пакета понимать, что он содержит и как это должно быть проанализировано.


Top
 Profile  
 
 Post subject: Re: network sessions and capture files
PostPosted: Tue May 17, 2011 3:09 pm 
Offline

Joined: Sun Apr 24, 2011 7:07 pm
Posts: 6
Спасибо за ответ. Как раз второй вариант и начал реализовывать.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

Who is online

Users browsing this forum: rav and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Theme designed by stylerbb.net © 2008
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All times are UTC + 2 hours