volatilityfoundation / volatility3

Volatility 3.0 development
http://volatilityfoundation.org/
Other
2.65k stars 451 forks source link

pedump help message doesn't match flag #1324

Open superponible opened 11 hours ago

superponible commented 11 hours ago

Describe the bug The error messages in pedump don't match the expected arguments because of the hyphen vs underscore in kernel-module. @ikelos not sure if the error message should just be updated or the "kernel_module" argument should be changed to "kernel-module" at https://github.com/volatilityfoundation/volatility3/blob/develop/volatility3/framework/plugins/windows/pedump.py#L47, but that could affect any code that's expecting the underscore

To Reproduce Steps to reproduce the behavior:

Help shows "kernel-module"

$ python3 vol.py -c lsass.json windows.pedump -h
Volatility 3 Framework 2.11.0
usage: volatility windows.pedump.PEDump [-h] [--pid [PID [PID ...]]] --base BASE [--kernel-module]

optional arguments:
  -h, --help            show this help message and exit
  --pid [PID [PID ...]]
                        Process IDs to include (all other processes are excluded)
  --base BASE           Base address to reconstruct a PE file
  --kernel-module       Extract from kernel address space.

The output message when the command is incorrect shows "kernel_module":

$ python3 vol.py -c lsass.json windows.pedump --base 0xe685141b2080
Volatility 3 Framework 2.11.0
Progress:  100.00       PDB scanning finished
PID Process File output
ERROR    volatility3.plugins.windows.pedump: --kernel_module or --pid must be set

But if a user tried to run that way it would fail

volatility: error: unrecognized arguments: --kernel_module

As the actual argument is "kernel-module" even though the code is "kernel_module".

$ python3 vol.py -c lsass.json windows.pedump --kernel-module --base 0xc82550b80000
Volatility 3 Framework 2.11.0
Progress:  100.00       PDB scanning finished
PID Process File output

4   Kernel  PE.0x0.4.0xc82550b80000.dmp
ikelos commented 11 hours ago

That's just the error messages that the plugin spits out.

https://github.com/volatilityfoundation/volatility3/blob/a1961401d52db56f310675d8cd4af09e3d9e4139/volatility3/framework/plugins/windows/pedump.py#L230

All argparse arguments are converted from _ to - because you can't have variables with - in the middle (because of the confusion with minus) done here in the current codebase. The error messages probably should be updated not to assume command line parameters (because there ARE other UIs for the volatility library, even though everyone forgets about them). So ideally, the error messages would say Only config options kernel_module or pid should be set, not both and then it's up to the user to translate that into something for their UI. If we wanted, we could have a ConfigOptionException that gets caught by the UI and the options in it translated for the UI, but it'd be opening up a (somewhat small) can of worms to try and do all that.

So the issue at the heart of this is "config options and UI options don't necessarily match up perfectly, so requirements on config options will throw errors that might not map perfectly to the UI". Happy for suggestions of how best to fix it, but those suggestions need to be UI independent. The CLI is not special, and shouldn't get special treatment.