5

I install the module scapy for python 2.6 and when I import this module I get this warning:

WARNING: can't import layer ipsec: 'module' object has no attribute 'IPPROTO_AH'

I looked in the socket attributes and i didnt find the 'IPPROTO_AH' attribute In addition, i tried to edit the module ipsec.py and find way to replace IPPROTO_AH with something else but then i got WARNING WITH IPPROTO_ESP !

I tried edit lines in ipsec.py such as:

    overload_fields = {
    IP: {'proto': IPTest},
    IPv6: {'nh': IPTest},
    IPv6ExtHdrHopByHop: {'nh': socket.IPPROTO_AH},
    IPv6ExtHdrDestOpt: {'nh': socket.IPPROTO_AH},
    IPv6ExtHdrRouting: {'nh': socket.IPPROTO_AH},}

bind_layers(IP, AH, proto=socket.IPPROTO_AH)
bind_layers(IPv6, AH, nh=socket.IPPROTO_AH)

how can i fix this ?

ElGavilan
  • 6,610
  • 16
  • 27
  • 36
yosi doran
  • 53
  • 1
  • 1
  • 3
  • Why did you added `IPPROTO_AH` from `socket` if `socket` doesn't have it? Also what is the platform/OS that you run python on? – CristiFati Jun 01 '15 at 18:46
  • i didnt add this . i got this module when I installed the scapy module and I didnt write any code there . My platform is windows 7. – yosi doran Jun 01 '15 at 18:58
  • Ok i did some more digging, i have a python2.4.4 version and `socket.IPPROTO_ESP` is 50 while `socket.IPPROTO_AH` is 51. I also checked python3.4.3, but it doesn't have them. – CristiFati Jun 01 '15 at 19:31
  • wow man Thanks !! I will try to replace this attribute with their value . – yosi doran Jun 01 '15 at 19:33

1 Answers1

6

I think I have it... it's not a clean solution, but it will do the trick. I've seen it in other ScaPy files...
All you need to do is edit ipsec.py, look for the line import socket, and just under it, add these conditionals:

if not hasattr(socket, "IPPROTO_ESP"):
    socket.IPPROTO_ESP = 50
if not hasattr(socket, "IPPROTO_AH"):
    socket.IPPROTO_AH = 51

Reference: [IETF.DataTracker]: (RFC 2292) Advanced Sockets API for IPv6 - IPv6 Next Header Values.
In Ubuntu, their definitions can typically be found in /usr/include/netinet/in.h (or /usr/include/linux/in.h).

As I mentioned in one of the comments, I tested using Python 2.7.10 on a variety of OSes (Linuxes, Sol, AIX, HP-UX, OSX) and the values seem to be consistent.
On Win, they don't exist. Seems like MS removed them from WinSock2.h between (VStudio) v2005 and v2010, but they are back (same values) since v2012 (ws2def.h - for XP and above).

In Python 3(.8), they seem to be present (checked on Nix (Ubuntu) and Win).

CristiFati
  • 38,250
  • 9
  • 50
  • 87
  • lol I rewrite all this module .. and this works (replace all the "socket.IPPROTO_AH" and "socket.IPPROTO_ESP" with their value)!! Thank you !! – yosi doran Jun 01 '15 at 19:48
  • 1
    I'd still recommend to check first if `socket` has them and if not then define them instead of replacing their occurrences with their values, because if you would like to run the code with another python installed on another machine with a different Windows version where those constant might have different values (although this wouldn't be very likely) the code won't work. – CristiFati Jun 01 '15 at 19:55
  • I also did a test using Python2.7.10 on a variety of OSes (Linux, Solaris, AIX, HP-UX, OSX) and the values seem to be consistent, while on Win they don't exist. Seems like MS removed them from `WinSock2.h` between (VStudio) 2k5 and 2k10. – CristiFati Oct 21 '15 at 19:21