hansmach1ne / LFImap

Local File Inclusion discovery and exploitation tool
Apache License 2.0
194 stars 29 forks source link

Move global `args` to a class/object/non-global #66

Closed nrathaus closed 1 week ago

nrathaus commented 2 weeks ago

At the moment the constant calling to: from src.utils.arguments import args

Is causing the code to have complexity that makes it impossible to:

  1. Write additional code without causing a dependency issue (this is visible when debugging/running unit-tests)
  2. Warnings shown when args is accessed as it doesn't know which arguments exist/don't exist
  3. No type checking when accessing the variables stored inside args
  4. Multiple times args = parser.parse_args() code is called and parameters are init

I suggest to move the arguments.py code so that is not all sitting in the 'global' rather inside a class, init once when the code starts, stores the variables inside a dict rather than args or inside self values of this class, pass this newly created class around to whoever needs it or still use it as a global (but prevent its init from being called on every import)

nrathaus commented 2 weeks ago

This code change will also allow writing unit-test, today you cannot call this: src.attacks.rfi.test_rfi('http://localhost:4280/vulnerabilities/fi/?page=PWN', post='')

To preform a test, as it uses args which are coming from parsing the cmdline, which doesn't exist in unitest

nrathaus commented 2 weeks ago

I can provide a PR for these changes (moving args into a class, and fixing all the code that accesses that information)

hansmach1ne commented 1 week ago

@nrathaus Yeah, agreed on this. It would be nice if we can write simple tests like this? You can create a PR if you have the time, I will review it and hopefully merge it, if everything checks out! Thanks again!

nrathaus commented 1 week ago

I created a PR https://github.com/hansmach1ne/LFImap/pull/97

There are some conflicts due to my branch not being in sync with yours when I created it

I tried to fix most of them to make it easier to compare the changes

hansmach1ne commented 1 week ago

https://github.com/hansmach1ne/LFImap/pull/98