Giter Site home page Giter Site logo

robotframework-scapylibrary's Introduction

Scapy Robot Framework Library

Introduction

Scapy Robot Framework Library provide keywords to do network operations through Scapy.

Functionality

  • Expose scapy layers as keywords to Robot Framework
  • Expose functions in scapy.all as keywords to Robot Framework
  • Create/send/receive packets
  • Open/Save pcap file (not supported yet)

Keyword Documentation

Keywords

Generate Scapy Layer Documentation

  • User could generate scapy layer documentation with below command.
python -m ScapyLibrary.layerDoc Scapy.html

Example

ICMP Ping Example

*** Settings ***
Library    ScapyLibrary

*** Test Cases ***
Send And Receive, Return Reply
    Create ICMP Packet
    Send And Get Reply

*** Keywords ***
Create ICMP Packet
    ${ip}     IP      dst=192.168.1.1
    ${icmp}    ICMP
    ${PACKET}    Compose Packet    ${ip}    ${icmp}
    Log Packets    ${PACKET}
    Set Test Variable    ${PACKET}

Send And Get Reply
    ${reply}    Send And Receive At Layer3    ${PACKET}    timeout=${10}
    Log Packets    ${reply[0]}
    ${reply}       Send And Receive At Layer3    ${PACKET}    timeout=${10}    return_send=${True}
    Log Packets    ${reply[0][0]}
    Log Packets    ${reply[0][1]}
    ${reply}    ${unanswered}    Send And Receive At Layer3    ${PACKET}    timeout=${10}    return_send=${True}    return_unanswer=${True}
    Log Packets    ${reply[0][0]}
    Log Packets    ${reply[0][1]}
    Should Be Equal As Integers    ${unanswered.__len__()}    0

robotframework-scapylibrary's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

robotframework-scapylibrary's Issues

Importing test library 'ScapyLibrary' failed: ImportError: cannot import name NPCAP_PATH

Hello friend,

I tried to use the library, I installed it on py2.7 but ride does not recognize it, the RIDE log says:

Importing test library 'ScapyLibrary' failed: ImportError: cannot import name NPCAP_PATH

I also tried to run the example test without using ride and robot does not find the keywords, when I run it it says:

C:\Users\b.jccd>robot C:\Users\b.jccd\Documents\Programas\Robot\scapy.robot
[ WARN ] No pcap provider available ! pcap won't be used
[ WARN ] import scapy failed, please check whether scapy is installed
[ ERROR ] Error in file 'C:\Users\b.jccd\Documents\Programas\Robot\scapy.robot': Importing test library 'ScapyLibrary' failed: ImportError: cannot import name NPCAP_PATH
Traceback (most recent call last):
  File "c:\users\b.jccd\documents\programas\python\lib\site-packages\ScapyLibrary\__init__.py", line 7, in <module>
    from ScapyLibrary.keywords.layers import LayersWrapper
  File "c:\users\b.jccd\documents\programas\python\lib\site-packages\ScapyLibrary\keywords\layers.py", line 8, in <module>
    from ScapyLibrary.utils._scapy import scapylib
  File "c:\users\b.jccd\documents\programas\python\lib\site-packages\ScapyLibrary\utils\_scapy.py", line 35, in <module>
    raise err
PYTHONPATH:
  C:\Users\b.jccd\Documents\Programas\Python\Scripts\robot.exe
  C:\Windows\SYSTEM32\python27.zip
  c:\users\b.jccd\documents\programas\python\DLLs
  c:\users\b.jccd\documents\programas\python\lib
  c:\users\b.jccd\documents\programas\python\lib\plat-win
  c:\users\b.jccd\documents\programas\python\lib\lib-tk
  c:\users\b.jccd\documents\programas\python
  c:\users\b.jccd\documents\programas\python\lib\site-packages
  c:\users\b.jccd\documents\programas\python\lib\site-packages\win32
  c:\users\b.jccd\documents\programas\python\lib\site-packages\win32\lib
  c:\users\b.jccd\documents\programas\python\lib\site-packages\Pythonwin
==============================================================================
Scapy
==============================================================================
Send And Receive, Return Reply                                        | FAIL |
No keyword with name 'IP' found.
------------------------------------------------------------------------------
Scapy                                                                 | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
Output:  C:\Users\b.jccd\output.xml
Log:     C:\Users\b.jccd\log.html
Report:  C:\Users\b.jccd\report.html

I installed on c:\users\b.jccd\documents\programas\python\lib\site-packages, I don't know why it doesn't find it
I don't know what to do, contact me for further information about this bug/error

Best Regards

Send And Receive At Layer2 example

Do you have any working Send And Receive At Layer2 example? I was trying to use it to srp an ARP packet similar to scapy commands below;

arp1=Ether(dst='ff:ff:ff:ff:ff:ff')/ARP(pdst='192.168.1.0/28')
srp(arp1, iface="eno7")

Thanks,
David

'FAILED', u'ScapyLibrary', AttributeError("'UserErrorHandler' object has no attribute 'library'",)

With the following python libs, create a project on ride. I add libs as ftplibrary, selenium2library are ok, but add ScapyLibrary failed.
python 2.7.13
robotframework 3.1.1
robotframework-ftplibrary 1.6
robotframework-ride 1.7.3
robotframework-ScapyLibrary 0.1.4
robotframework-selenium2library 3.0.0
scapy 2.4.2

('FAILED', u'ScapyLibrary', AttributeError("'UserErrorHandler' object has no attribute 'library'",))
20190521 14:49:40.633 [WARN]: Importing test library "ScapyLibrary" failed

Traceback (most recent call last):
'UserErrorHandler' object has no attribute 'library'
File "E:\Python27\lib\site-packages\robotide\spec\librarymanager.py", line 87, in _fetch_keywords
return get_import_result(path, library_args)
File "E:\Python27\lib\site-packages\robotide\spec\libraryfetcher.py", line 32, in get_import_result
) for kw in lib.handlers]

AttributeError: _name

[ ERROR ] Error in file '/home/ubuntu/development/testcases/test.robot': Initializing test library 'ScapyLibrary' with no arguments failed: AttributeError: _name
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/robotframework_ScapyLibrary-devel-py2.7.egg/ScapyLibrary/__init__.py", line 20, in __init__
    _base.__init__(self)
  File "/usr/local/lib/python2.7/dist-packages/robotframework_ScapyLibrary-devel-py2.7.egg/ScapyLibrary/keywords/layers.py", line 16, in __init__
    self._init_layers()
  File "/usr/local/lib/python2.7/dist-packages/robotframework_ScapyLibrary-devel-py2.7.egg/ScapyLibrary/keywords/layers.py", line 78, in _init_layers
    if protocol._name is None:
  File "/usr/local/lib/python2.7/dist-packages/scapy/base_classes.py", line 192, in __getattr__
    raise AttributeError(attr)

Keyword with same name defined multiple times

With the following python libs, I'm facing this error on a fresh installation too.
robotframework 3.1.1
robotframework-debuglibrary 1.1.4
robotframework-requests 0.5.0
robotframework-ScapyLibrary 0.1.4
robotframework-scplibrary 1.2.0
scapy 2.4.2

[ WARN ] No route found for IPv6 destination :: (no default route?)
[ WARN ] CARP overwrites VRRP !
[ ERROR ] Loading module scapy.layers.cansocket_python_can
[ WARN ] [bgp.py] use_2_bytes_asn: True
[ WARN ] temp solution
[ ERROR ] Error in test library 'ScapyLibrary': Creating keyword 'Dns Get Str' failed: Keyword with same name defined multiple times.
[ ERROR ] Error in test library 'ScapyLibrary': Creating keyword 'IE ChargingID' failed: Keyword with same name defined multiple times.
[ ERROR ] Error in test library 'ScapyLibrary': Creating keyword 'IE APNRestriction' failed: Keyword with same name defined multiple times.
[ ERROR ] Error in test library 'ScapyLibrary': Creating keyword 'Raw' failed: Keyword with same name defined multiple times.
[ ERROR ] Error in test library 'ScapyLibrary': Creating keyword 'PPP' failed: Keyword with same name defined multiple times.

AttributeError: 'module' object has no attribute "IE_Base"

Hi

I did pip install,
Now while importing I'm getting this error.

import ScapyLibrary
Traceback (most recent call last):
File "", line 1, in
File "C:\Python27\lib\site-packages\ScapyLibrary_init_.py", line 7, in
from ScapyLibrary.keywords.layers import LayersWrapper
File "C:\Python27\lib\site-packages\ScapyLibrary\keywords\layers.py", line 8,
in
from ScapyLibrary.utils._scapy import scapylib
File "C:\Python27\lib\site-packages\ScapyLibrary\utils_scapy.py", line 31, in

scapylib.load_contrib(mod) File "C:\Python27\lib\site-packages\scapy\main.py", line 83, in load_contrib __import__("scapy.contrib." + name) File "C:\Python27\lib\site-packages\scapy\contrib\gtp_v2.py", line 120, in class IE_IPv4(gtp.IE_Base): AttributeError: 'module' object has no attribute 'IE_Base' >>>

[ERROR] Loading module scapy.layers.cansocket_python_can

Hi, I've tried ICMP example this library with latest scapy on Rocky Linux 9.2 and got this
Python 3.9.16
Scapy 2.5.0
Robot Framework 6.1 (Python 3.9.16 on linux)

ScapyLibrary installed with pip install robotframework-ScapyLibrary

$ pip show robotframework-ScapyLibrary
Name: robotframework-ScapyLibrary
Version: 0.1.6
Summary: Scapy library for Robot Framework
Home-page: https://github.com/rainmanwy/robotframework-ScapyLibrary
Author: Wang Yang
Author-email: [email protected]
License: Apache License 2.0
Location: /usr/local/lib/python3.9/site-packages
Requires: scapy
Required-by: 
Error in file '/root/eupf/robot/EstablishSession.robot' on line 2: Initializing library 'ScapyLibrary' with no arguments failed: TypeError: can only concatenate tuple (not "str") to tuple
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/ScapyLibrary/__init__.py", line 20, in __init__
    _base.__init__(self)
  File "/usr/local/lib/python3.9/site-packages/ScapyLibrary/keywords/layers.py", line 15, in __init__
    self._init_layers()
  File "/usr/local/lib/python3.9/site-packages/ScapyLibrary/keywords/layers.py", line 80, in _init_layers
    doc = protocol._name + '\n\n'
TypeError: can only concatenate tuple (not "str") to tuple
Loading module scapy.layers.cansocket_python_can
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/scapy/main.py", line 204, in load_contrib
    importlib.import_module("scapy.contrib." + name)
  File "/usr/lib64/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/usr/local/lib/python3.9/site-packages/scapy/contrib/cansocket_python_can.py", line 29, in <module>
    from can import Message as can_Message
ModuleNotFoundError: No module named 'can'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/scapy/main.py", line 156, in _load
    mod = importlib.import_module(module)
  File "/usr/lib64/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'scapy.layers.cansocket_python_can'

Install fail

I am using python3 to install ScapyLibrary, but install fail.
The error message as follows
execfile(join(dirname(abspath(file)), 'src', 'ScapyLibrary', 'version.py'))
NameError: name 'execfile' is not defined

I think the root cause is execfile is removed in python3. Is it correct?
Could you help me to install this?
Thank you very much.

Keyword with same name defined multiple times

With the following python libs, I'm facing this error on a fresh installation too.
robotframework 3.1.1
robotframework-debuglibrary 1.1.4
robotframework-requests 0.5.0
robotframework-ScapyLibrary 0.1.4
robotframework-scplibrary 1.2.0
scapy 2.4.2

[ WARN ] No route found for IPv6 destination :: (no default route?)
[ WARN ] CARP overwrites VRRP !
[ ERROR ] Loading module scapy.layers.cansocket_python_can
[ WARN ] [bgp.py] use_2_bytes_asn: True
[ WARN ] temp solution
[ ERROR ] Error in test library 'ScapyLibrary': Creating keyword 'Dns Get Str' failed: Keyword with same name defined multiple times.
[ ERROR ] Error in test library 'ScapyLibrary': Creating keyword 'IE ChargingID' failed: Keyword with same name defined multiple times.
[ ERROR ] Error in test library 'ScapyLibrary': Creating keyword 'IE APNRestriction' failed: Keyword with same name defined multiple times.
[ ERROR ] Error in test library 'ScapyLibrary': Creating keyword 'Raw' failed: Keyword with same name defined multiple times.
[ ERROR ] Error in test library 'ScapyLibrary': Creating keyword 'PPP' failed: Keyword with same name defined multiple times.

Example fails

Hey,

The example from your readme fails here with

[ ERROR ] Error in file '/Users/jo/dev/master/robot/src/dc-wordpress/tests/dc-wordpress.robot': Initializing test library 'ScapyLibrary' with no arguments failed: TypeError: unsupported operand type(s) for +: 'member_descriptor' and 'str'
Traceback (most recent call last):
  File "/Users/jo/.virtualenvs/robot/lib/python2.7/site-packages/ScapyLibrary/__init__.py", line 20, in __init__
    _base.__init__(self)
  File "/Users/jo/.virtualenvs/robot/lib/python2.7/site-packages/ScapyLibrary/keywords/layers.py", line 16, in __init__
    self._init_layers()
  File "/Users/jo/.virtualenvs/robot/lib/python2.7/site-packages/ScapyLibrary/keywords/layers.py", line 81, in _init_layers
    doc = protocol.name + '\n\n'
Tests.Dc-Wordpress

Can you please help me to fix it?

Bye,
Jo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.