Skip to content

Exception when setting boolean option False or integer 0 value in Module Option #39

Open

Description

@tterletskyy

Description

Sploitkit throws an exception when setting the boolean value False or integer 0 for Module Option. When setting True it works correctly.
Sploitkit version: sploitkit==0.6.0
Python version: 3.12+

Exceptions

% python -B main.py
Traceback (most recent call last):
  File ".../main.py", line 28, in <module>
    main()
  File ".../main.py", line 23, in main
    test.config['SEND_PAYLOAD'] = False
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File ".../venv_macos31244/lib/python3.12/site-packages/sploitkit/core/components/config.py", line 481, in __setitem__
    return c.__setitem__(key, value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../venv_macos31244/lib/python3.12/site-packages/sploitkit/core/components/config.py", line 67, in __setitem__
    key = self._setkey(key, value)
          ^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../venv_macos31244/lib/python3.12/site-packages/sploitkit/core/components/config.py", line 159, in _setkey
    raise ValueError(f"Invalid value '{value}' for key '{key.name}'")
ValueError: Invalid value 'False' for key 'SEND_PAYLOAD'

############################################################################################

Traceback (most recent call last):
  File ".../main.py", line 28, in <module>
    main()
  File ".../main.py", line 23, in main
    test.config['SEND_PAYLOAD'] = 0
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File ".../venv_macos31244/lib/python3.12/site-packages/sploitkit/core/components/config.py", line 481, in __setitem__
    return c.__setitem__(key, value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../venv_macos31244/lib/python3.12/site-packages/sploitkit/core/components/config.py", line 67, in __setitem__
    key = self._setkey(key, value)
          ^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../venv_macos31244/lib/python3.12/site-packages/sploitkit/core/components/config.py", line 159, in _setkey
    raise ValueError(f"Invalid value '{value}' for key '{key.name}'")
ValueError: Invalid value '0' for key 'SEND_PAYLOAD'

Code

from pprint import pprint

from sploitkit import Config, Module, Option


class TestModule(Module):
    config = Config(
        {
            Option(
                name='SEND_PAYLOAD',
                description='Boolean or integer value',
                required=True,
            ): None,
        }
    )

    def run(self, *args, **kwargs) -> None:
        pprint(dict(self.config))


def main() -> None:
    test = TestModule()
    test.config['SEND_PAYLOAD'] = False # or 0
    test.run()


if __name__ == '__main__':
    main()

Activity

  1. dhondta commented on Sep 28, 2024

    @dhondta
    Owner

    Hi @tterletskyy !
    Thank you for reporting.
    Given your setting, you shall use the following :

    class TestModule(Module):
        config = Config(
            {
                Option(
                    name='SEND_PAYLOAD',
                    description='Boolean or integer value',
                    required=True,
                    transform=lambda s, v: str(v).lower() in ["true", "1"],                # this will ensure the boolean value
                    validate=lambda s, v: str(v).lower() in ["false", "true", "0", "1"],   # defines the set of values that can serve as a boolean
                ): None,
            }
        )
    [...]

    A bit ugly however ; this implementation does not pre-define some data types yet.

  2. self-assigned this
    on Sep 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

help wantedExtra attention is needed

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions