Ejemplo n.º 1
0
def extract(folder, filename):
    http_payload = ''
    extracted_images = 1
    pcap = PcapReader(filename)
    pcap.parse()
    for packet in pcap.get_packets():
        if packet.layers[2]:
            if packet.layers[2]['Source port'] == 80 or packet.layers[2]['Destination port'] == 80:
                http_payload += str(packet.layers[2]['Data'])

    boundaries = get_payload_boundaries(http_payload)
    headers = get_http_headers_and_content(http_payload, boundaries)

    clean_name = filename.split('/')
    clean_name = clean_name[len(clean_name) - 1]
    
    if headers:
        for h in headers:
            if 'image/jpeg' in h['Content-Type']:
                image, image_type = extract_images(h, http_payload, boundaries)
                if image is not None and image_type is not None:
                    filename = '%s-pycket_%s.%s' %(clean_name, extracted_images, image_type)
                    fd = open('%s/%s' % (folder, filename), 'wb')
                    fd.write(image)
                    fd.close()
                    extracted_images += 1
    return extracted_images
Ejemplo n.º 2
0
def extract(folder, filename):
    http_payload = ''
    extracted_images = 1
    pcap = PcapReader(filename)
    pcap.parse()
    for packet in pcap.get_packets():
        if packet.layers[2]:
            if packet.layers[2]['Source port'] == 80 or packet.layers[2][
                    'Destination port'] == 80:
                http_payload += str(packet.layers[2]['Data'])

    boundaries = get_payload_boundaries(http_payload)
    headers = get_http_headers_and_content(http_payload, boundaries)

    clean_name = filename.split('/')
    clean_name = clean_name[len(clean_name) - 1]

    if headers:
        for h in headers:
            if 'image/jpeg' in h['Content-Type']:
                image, image_type = extract_images(h, http_payload, boundaries)
                if image is not None and image_type is not None:
                    filename = '%s-pycket_%s.%s' % (
                        clean_name, extracted_images, image_type)
                    fd = open('%s/%s' % (folder, filename), 'wb')
                    fd.write(image)
                    fd.close()
                    extracted_images += 1
    return extracted_images
Ejemplo n.º 3
0
 def open_pcap(self):
     fileName = QtGui.QFileDialog.getOpenFileName(self, "Open File", "/home", "Pcap files (*.pcap)")
     if fileName:
         try:
             pcap_reader = PcapReader(fileName)
             pcap_reader.parse()
             for packet in pcap_reader.get_packets():
                 self.add_packet(packet)
         except ValueError:
             QtGui.QMessageBox.information(self, "Error", "'"+fileName+"' is not a pcap file.")
         except:
             print "Unexpected error:", sys.exc_info()[0]