Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzy committed Aug 13, 2012
2 parents 7152928 + 9efb9f6 commit d76c882
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
13 changes: 12 additions & 1 deletion ovizart/api/serializer.py
Expand Up @@ -21,6 +21,8 @@ def to_json(self, data, options=None):
if flow['protocol'] == "http": if flow['protocol'] == "http":
# get the start and end time for this flow # get the start and end time for this flow
start, end = self.get_start_end(flow) start, end = self.get_start_end(flow)
if not start:
continue
type, description = self.get_http_info(flow) type, description = self.get_http_info(flow)
tmp = dict() tmp = dict()
tmp['flow_id'] = flow['id'] tmp['flow_id'] = flow['id']
Expand All @@ -36,6 +38,8 @@ def to_json(self, data, options=None):


if flow['protocol'] == "dns": if flow['protocol'] == "dns":
start, end = self.get_start_end(flow) start, end = self.get_start_end(flow)
if not start:
continue
type, description = self.get_dns_info(flow) type, description = self.get_dns_info(flow)
tmp = dict() tmp = dict()
tmp['flow_id'] = flow['id'] tmp['flow_id'] = flow['id']
Expand All @@ -51,6 +55,8 @@ def to_json(self, data, options=None):


if flow['protocol'] == "smtp": if flow['protocol'] == "smtp":
start, end = self.get_start_end(flow) start, end = self.get_start_end(flow)
if not start:
continue
type, description = self.get_smtp_info(flow) type, description = self.get_smtp_info(flow)
tmp = dict() tmp = dict()
tmp['flow_id'] = flow['id'] tmp['flow_id'] = flow['id']
Expand All @@ -66,6 +72,8 @@ def to_json(self, data, options=None):


if flow['protocol'] == "unknown": if flow['protocol'] == "unknown":
start, end = self.get_start_end(flow) start, end = self.get_start_end(flow)
if not start:
continue
type, description = "unknown", "" type, description = "unknown", ""
tmp = dict() tmp = dict()
tmp['flow_id'] = flow['id'] tmp['flow_id'] = flow['id']
Expand Down Expand Up @@ -95,7 +103,10 @@ def from_json(self, content):
# TODO: for udp, packet details are not saved # TODO: for udp, packet details are not saved
def get_start_end(self, flow): def get_start_end(self, flow):
packets = PacketDetails.objects.filter(src_ip=flow['src_ip'], sport=flow['sport'], dst_ip=flow['dst_ip'], dport=flow['dport']).order_by('timestamp') packets = PacketDetails.objects.filter(src_ip=flow['src_ip'], sport=flow['sport'], dst_ip=flow['dst_ip'], dport=flow['dport']).order_by('timestamp')
return packets[0].timestamp, packets[len(packets)-1].timestamp if packets:
return packets[0].timestamp, packets[len(packets)-1].timestamp
else:
return False, False




def get_http_info(self, flow): def get_http_info(self, flow):
Expand Down
11 changes: 9 additions & 2 deletions ovizart/modules/traffic/parser/udp/dns/handler.py
Expand Up @@ -39,15 +39,22 @@ def get_flow_ips(self, **args):
for ts, buf in p_read_handler.get_reader(): for ts, buf in p_read_handler.get_reader():
udp = udp_handler.read_udp(ts, buf) udp = udp_handler.read_udp(ts, buf)
if udp: if udp:
self.flow_li.append([udp_handler.src_ip, udp_handler.sport, udp_handler.dst_ip, udp_handler.dport, udp_handler.timestamp]) try:
dns = dpkt.dns.DNS(udp.data) dns = dpkt.dns.DNS(udp.data)
self.flow_li.append([udp_handler.src_ip, udp_handler.sport, udp_handler.dst_ip, udp_handler.dport, udp_handler.timestamp])
except IndexError:
continue #dpkt is not properly handling
self.dns_li.append(dns) self.dns_li.append(dns)
return self.flow_li return self.flow_li


def save_request_response(self, **args): def save_request_response(self, **args):
index = 0 index = 0
for msg in self.dns_li: for msg in self.dns_li:
if msg.rcode == dpkt.dns.DNS_RCODE_NOERR: if msg.rcode == dpkt.dns.DNS_RCODE_NOERR:
try:
msg.qd[0].type
except:
continue
if msg.qd[0].type in REQUEST_FLAGS.keys(): if msg.qd[0].type in REQUEST_FLAGS.keys():
detail = self.flow_li[index] detail = self.flow_li[index]
flow_detail = FlowDetails.objects.get(src_ip=detail[0], sport=int(detail[1]), dst_ip=detail[2], dport=int(detail[3]), protocol="dns", timestamp = detail[4]) flow_detail = FlowDetails.objects.get(src_ip=detail[0], sport=int(detail[1]), dst_ip=detail[2], dport=int(detail[3]), protocol="dns", timestamp = detail[4])
Expand Down

0 comments on commit d76c882

Please sign in to comment.