ANSSI-FR / tabi

BGP Hijack Detection
Other
110 stars 37 forks source link

TypeError: can only compare to a set #1

Closed nagarjung closed 7 years ago

nagarjung commented 7 years ago
python detect_hijacks.py -c rrc01 -i mabo \
    --rpki-roa-file roa.csv \
    --irr-ro-file routes.csv \
    --irr-mnt-file maintainers.csv \
    --irr-org-file organisations.csv \
    ../../{bview,updates}.*.gz

Running hijack detection tool is throwing the error :

Traceback (most recent call last):

File "detect_hijacks.py", line 81, in <module>
    for conflict in detect_hijacks(**kwargs):
  File "build/bdist.linux-x86_64/egg/tabi/emulator.py", line 146, in detect_hijacks
  File "build/bdist.linux-x86_64/egg/tabi/annotate.py", line 163, in annotate_if_roa
  File "build/bdist.linux-x86_64/egg/tabi/annotate.py", line 222, in annotate_roa_announce
TypeError: can only compare to a set 
nagarjung commented 7 years ago

@guedou @nv-anssi : could you please help me on this ?

ghost commented 7 years ago

Hello Nagarjung,

We are not able to reproduce your error. What version of Python do you run?

Nicolas

nagarjung commented 7 years ago

@nv-anssi : I run python 2.7.6, which version is required to run this tool. FYI, I am not running the tool inside virtualenv. I am running on host machine with python 2.7.6

nagarjung commented 7 years ago

Hi @nv-anssi : After debugging a bit, I could able to point out the issue

https://github.com/ANSSI-FR/tabi/blob/master/tabi/annotate.py

line 222

if asn in node.data and int(prefix.split("/")[1]) <= node.data[asn]:

-> if asn in node.data and int(prefix.split("/")[1]) <= node.data[asn]:
(Pdb) asn in node.data
True
(Pdb) int(prefix.split("/")[1])
19
(Pdb) node.data[asn]
set(['apnic'])

(Pdb) n
TypeError: 'can only compare to a set'
ghost commented 7 years ago

The value in node.data[asn] is unexpected. It should be an integer. Could you check that your roa.csv file is correct (same as the one in the repository)?

nagarjung commented 7 years ago

Yes the roa.csv file is same as in the repository.

16079,194.209.159.0/24,24,True
16078,80.89.147.0/24,24,True
35545,185.42.222.0/24,24,True
16071,212.234.194.0/24,24,True
35238,77.203.169.0/24,24,True
35238,78.113.119.0/24,24,True

Yes the comparision int(prefix.split("/")[1]) <= node.data[asn] is throwing an error.

May be problem with data insertion ?

nagarjung commented 7 years ago

@nv-anssi : Finally caught the issue.

https://github.com/ANSSI-FR/tabi/blob/master/tabi/emulator.py

line 136

funcs.append(partial(annotate_if_roa, ro_rad_tree))

I think wrong object ro_rad_tree is passed, instead the object should have been roa_rad_tree

funcs.append(partial(annotate_if_roa, roa_rad_tree))