473,382 Members | 1,329 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Impacket and packet sniffing

16
Hi All

I have found the simple script that sniffs ICMP packets using Impacket and pcapy. At the moment it is capturing the packet header and data, I was just wondering if anyone knows a way to get it to capture the packet headers only?
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/python
  2. ### sniffer
  3. import pcapy
  4. from impacket.ImpactDecoder import *
  5.  
  6. def recv_pkts(hdr, data):
  7.     x = EthDecoder().decode(data)
  8.     print x
  9.  
  10. def get_int():
  11.     devs = pcapy.findalldevs()
  12.     i=0
  13.     for eth in devs:
  14.         print " %d - %s" %(i,devs[i])
  15.         i+=1
  16.     sel=input(" Select interface: ")
  17.     dev=devs[sel]
  18.     return dev
  19.  
  20. dev = get_int()
  21. p = pcapy.open_live(dev, 1500, 0, 100)
  22. p.setfilter('icmp')
  23. print "Listening on eth: net=%s, mask=%s\n" % (p.getnet(), p.getmask())
  24. p.loop(-1, recv_pkts) 
Thanks
Aug 1 '07 #1
3 8459
bartonc
6,596 Expert 4TB
Hi All

I have found the simple script that sniffs ICMP packets using Impacket and pcapy. At the moment it is capturing the packet header and data, I was just wondering if anyone knows a way to get it to capture the packet headers only?
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/python
  2. ### sniffer
  3. import pcapy
  4. from impacket.ImpactDecoder import *
  5.  
  6. def recv_pkts(hdr, data):
  7.     x = EthDecoder().decode(data)
  8.     print x
  9.  
  10. def get_int():
  11.     devs = pcapy.findalldevs()
  12.     i=0
  13.     for eth in devs:
  14.         print " %d - %s" %(i,devs[i])
  15.         i+=1
  16.     sel=input(" Select interface: ")
  17.     dev=devs[sel]
  18.     return dev
  19.  
  20. dev = get_int()
  21. p = pcapy.open_live(dev, 1500, 0, 100)
  22. p.setfilter('icmp')
  23. print "Listening on eth: net=%s, mask=%s\n" % (p.getnet(), p.getmask())
  24. p.loop(-1, recv_pkts) 
Thanks
I think I see what's going on here:
On line 24, the loop() function gets the recv_pkts() function (defined on line 6) as its second argument. That makes the (hdr, data) arguments required. All you have to do is not use the data in YOUR recv_pkts() function:
Expand|Select|Wrap|Line Numbers
  1. def recv_pkts(hdr, data):
  2.     ##  x = EthDecoder().decode(data)
  3.     print hdr
Aug 1 '07 #2
T00l
16
Hi, Thanks for the reply, I have done as suggested and it does now appear to only be reading the headers, however they are in the format as shown below and not printing the actual header data, any ideas why?

C:\scripts>python tcp.py
0 - \Device\NPF_GenericDialupAdapter
1 - \Device\NPF_{60B0D7E9-10AC-46F6-8528-A40D066DFF72}
2 - \Device\NPF_{62E01695-B732-41F6-9F22-A9B92D20E3F2}
3 - \Device\NPF_{0650A74D-212C-4E76-89A1-E4D4F18EA3DE}
Select interface: 2
Listening on eth: net=80.42.47.246, mask=255.255.255.255

<Pkthdr object at 0x00B1A530>
<Pkthdr object at 0x00B1A530>
<Pkthdr object at 0x00B1A530>
<Pkthdr object at 0x00B1A530>
<Pkthdr object at 0x00B1A530>
<Pkthdr object at 0x00B1A530>
<Pkthdr object at 0x00B1A530>
<Pkthdr object at 0x00B1A530>
<Pkthdr object at 0x00B1A530>
<Pkthdr object at 0x00B1A530>
<Pkthdr object at 0x00B1A530>
<Pkthdr object at 0x00B1A530>
<Pkthdr object at 0x00B1A530>

Many Thanks
Aug 2 '07 #3
T00l
16
Hi, Thanks for the reply, I have done as suggested and it does now appear to only be reading the headers, however they are in the format as shown below and not printing the actual header data, any ideas why?

C:\scripts>python tcp.py
0 - \Device\NPF_GenericDialupAdapter
1 - \Device\NPF_{60B0D7E9-10AC-46F6-8528-A40D066DFF72}
2 - \Device\NPF_{62E01695-B732-41F6-9F22-A9B92D20E3F2}
3 - \Device\NPF_{0650A74D-212C-4E76-89A1-E4D4F18EA3DE}
Select interface: 2
Listening on eth: net=80.42.47.246, mask=255.255.255.255

<Pkthdr object at 0x00B1A530>
<Pkthdr object at 0x00B1A530>
<Pkthdr object at 0x00B1A530>
<Pkthdr object at 0x00B1A530>
<Pkthdr object at 0x00B1A530>
<Pkthdr object at 0x00B1A530>
<Pkthdr object at 0x00B1A530>
<Pkthdr object at 0x00B1A530>
<Pkthdr object at 0x00B1A530>
<Pkthdr object at 0x00B1A530>
<Pkthdr object at 0x00B1A530>
<Pkthdr object at 0x00B1A530>
<Pkthdr object at 0x00B1A530>

Many Thanks

I've been playing around with this a bit more and it looks like it isn't just icking up the headers but is displaying an error for each packet receieved. I've tried to modify the code as below

def recv_pkts(hdr, data):
x = IPDecoder(hdr)
print x

But getting the following error

Traceback (most recent call last):
File "tcp.py", line 25, in <module>
p.loop(-1, recv_pkts)
File "tcp.py", line 8, in recv_pkts
x = IPDecoder(hdr)
TypeError: __init__() takes exactly 1 argument (2 given)

Anyone got any ideas?

Thanks
Aug 5 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: ias0nas | last post by:
Hello, I have been using Impacket to produce some packets, but unfortunatelly it does not provide functionality for changing the sequence number of a packet and leaves it to 0. Is it possible...
2
by: billiejoex | last post by:
Hi all. I'm using pcapy module to sniff some ICMP packets. I would like to modify this source: http://www.google.it/search?hl=it&q=pcapy&btnG=Cerca+con+Google&meta= and visualize only the DATA...
2
by: Anony | last post by:
Hi All, I used raw socket to sniff packet data. Now it can sniff only incoming packet, not outgoing data anymore. I don't know if it's due to the installation of XP SP2, firewall or other...
0
by: Nuno Magalhaes | last post by:
Why does C# only supports LAN packet sniffing? Should I have to use WinPCap if I want to capture the outgoing packets on xp pro also? Why this limitation? Here's the source for capturing the...
4
by: Dusan Micuch | last post by:
Hi, What's best way for Watching my Packet TCP and UDP ? Socket ? Some external DLL ? What I need to use for build programs like this? I want measure data on specific or anyone port at Real Time....
1
by: anton07 | last post by:
im a final year undergrad student..and i want to develop a packet sniffing software..but ive got no idea about what software's to use..hope i can get some help here..thanks so much.. or if there's...
3
by: nexus024 | last post by:
I am trying to write a program that will continuously sniff eth0 for a specific UDP packet thats being sent to a specific destination IP, alter the data of the packet, and finally transmit it to the...
1
by: sangith | last post by:
Hi, I tried the packet capture module program. I did a file transfer using ftp from this host to another server. But when I ran the program, it was just hanging off and it did not print the...
1
by: Ken Fine | last post by:
I have been investigating programmatically downloading FLV content from various sites ("video scraping"??) Many interactive GUI tools do this, such as the Orbit downloader. At the heart of them...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.