Discussion:
Problems in converting SIP object to string
Sushant Hiray
2014-09-28 21:16:14 UTC
Permalink
Hi all,

I'm attaching a small tcpdump pcap file. I'm sending a SIP REGISTER request
from a client and trying to parse it with scapy.

Here is what I've done till now.
pkts = rdpcap('one.pcap')
type(pkts[0][3])
<class 'sip.SIP'>
str(pkts[0][3])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/scapy/packet.py", line 261,
in __str__
return self.build()
File "/usr/local/lib/python2.7/dist-packages/scapy/packet.py", line 319,
in build
p = self.do_build()
File "/usr/local/lib/python2.7/dist-packages/scapy/packet.py", line 307,
in do_build
self = self.__iter__().next()
StopIteration

Can anyone suggest what the issue might be? Since I'm not able to convert
it to string, I'm not able to parse the internal fields such as username.
Or is there any better way to do the same?

Thanks,
Sushant Hiray,
Senior Undergrad CSE,
IIT Bombay
Steve Barnes
2014-09-29 04:22:37 UTC
Permalink
Post by Sushant Hiray
Hi all,
I'm attaching a small tcpdump pcap file. I'm sending a SIP REGISTER
request from a client and trying to parse it with scapy.
Here is what I've done till now.
pkts = rdpcap('one.pcap')
type(pkts[0][3])
<class 'sip.SIP'>
str(pkts[0][3])
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/scapy/packet.py", line
261, in __str__
return self.build()
File "/usr/local/lib/python2.7/dist-packages/scapy/packet.py", line
319, in build
p = self.do_build()
File "/usr/local/lib/python2.7/dist-packages/scapy/packet.py", line
307, in do_build
self = self.__iter__().next()
StopIteration
Can anyone suggest what the issue might be? Since I'm not able to
convert it to string, I'm not able to parse the internal fields such
as username.
Or is there any better way to do the same?
Thanks,
Sushant Hiray,
Senior Undergrad CSE,
IIT Bombay
---------------------------------------------------------------------
You are trying to work too far down in the packet:

In [4]: type(first)
Out[4]: scapy.layers.l2.Ether

In [5]: print first
ᅵT ᅵᅵᅵEbᅵG@<ᅵᅵ
ᅵᅵ
ᅵ"3ᅵᅵNLᅵREGISTER sip:ims.hom SIP/2.0
Via: SIP/2.0/UDP 10.3.160.214:5060;rport;branch=z9hG4bK1810502643
Route: <sip:pcscf.ims.hom;lr>
From: <sip:***@ims.hom>;tag=772965378
To: <sip:***@ims.hom>
Call-ID: 194108923
CSeq: 1 REGISTER
Contact:
<sip:***@10.3.160.214:5060;line=dacd9635beb0d31>;+sip.instance="<urn:uuid:309b7720-474c-11e4-955c-6ddd4f8d4915>"

Authorization: Digest username="***@ims.hom", realm="ims.hom", nonce="
", uri="sip:ims.hom", response=" "
Max-Forwards: 70
User-Agent: eXosip/3.3.0
Expires: 600000
Supported: path
Supported: gruu
Content-Length: 0

so first convert to a string then parse.

Gadget/Steve
Sushant Hiray
2014-09-30 16:17:53 UTC
Permalink
Thanks a lot Steve. It solved the issue.

Regards,
Sushant

Sushant Hiray,
Senior Undergrad CSE,
IIT Bombay
Post by Sushant Hiray
Hi all,
I'm attaching a small tcpdump pcap file. I'm sending a SIP REGISTER
request from a client and trying to parse it with scapy.
Here is what I've done till now.
pkts = rdpcap('one.pcap')
type(pkts[0][3])
<class 'sip.SIP'>
str(pkts[0][3])
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/scapy/packet.py", line 261,
in __str__
return self.build()
File "/usr/local/lib/python2.7/dist-packages/scapy/packet.py", line 319,
in build
p = self.do_build()
File "/usr/local/lib/python2.7/dist-packages/scapy/packet.py", line 307,
in do_build
self = self.__iter__().next()
StopIteration
Can anyone suggest what the issue might be? Since I'm not able to
convert it to string, I'm not able to parse the internal fields such as
username.
Or is there any better way to do the same?
Thanks,
Sushant Hiray,
Senior Undergrad CSE,
IIT Bombay
---------------------------------------------------------------------
type(first)
scapy.layers.l2.Ether
In [5]: print first
ᅵᅵ
ᅵ"3ᅵᅵNLᅵREGISTER sip:ims.hom
SIP/2.0
Via: SIP/2.0/UDP 10.3.160.214:5060;rport;branch=z9hG4bK1810502643
<sip:pcscf.ims.hom;lr>
194108923
CSeq: 1
REGISTER
realm="ims.hom", nonce=" ", uri="sip:ims.hom", response="
"
70
eXosip/3.3.0
600000
path
gruu
Content-Length: 0
so first convert to a string then parse.
Gadget/Steve
Continue reading on narkive:
Loading...