Repository navigation
fix: WMI IEnumWbemClassObject.Next() drops final batch; method dispatch swallows errors - #2296
nullsection wants to merge 3 commits into
Conversation
Two related correctness bugs in impacket.dcerpc.v5.dcom.wmi: IEnumWbemClassObject.Next() dropped the final partial batch. Per [MS-WMI] 3.1.4.4.2, when fewer than uCount objects remain the server returns the trailing objects together with a WBEM_S_FALSE status in the same response. The generic DCERPC layer raises on that non-zero status before Next() can read apObjects, so fetching more than one row per call silently discarded the last rows (this also affects the bundled wmiquery.py and dpapidump.py). Next() now recovers those objects from the decoded packet on WBEM_S_FALSE and re-raises only when the enumeration is truly exhausted, preserving the historical end-of-iteration signal for existing callers. IWbemClassObject dynamic method dispatch (createMethods/innerMethod) swallowed ExecMethod exceptions and argument-count mismatches, logging them and returning None. A failed remote method call (e.g. Win32_Process.Create used by wmiexec.py) was therefore indistinguishable from success and only surfaced later as an opaque AttributeError on the None result. Both now propagate. Adds host-free unit tests for Next()'s partial-batch handling.
|
Anything I can do to help move things along? |
|
@nullsection Hi! for the time being, can you remove changelog changes? that's something we want to have exclusive control for now. |
|
thanks @anadrianmanrique I've reverted the change log and added some new tests. Unless I've missed something it should cover all code paths. |
|
@nullsection Thanks! I'll continue with the review process next week. Will let you know if more changes are necessary. |
|
@nullsection hey! sorry for the delayed response. Review was ready with just one little item to adjust in the code. Feel free to reopen the PR in order to have it merged. Thanks! |
Hey @anadrianmanrique, sorry it's early AM for me and I misread the merge 😅 No stress, what would you like changed? |
| if len(args) != len(methodDefinition['InParams']): | ||
| LOG.error("Function called with %d parameters instead of %d!" % (len(args), len(methodDefinition['InParams']))) | ||
| return None | ||
| # Previously this only logged and returned None, silently |
There was a problem hiding this comment.
argument validation is conditional on methodDefinition['InParams'] is not None. Methods without input parameters are represented by None, so a call such as process.GetOwner('unexpected') bypasses validation. At wmi.py:3001 (impacket/dcerpc/v5/dcom/wmi.py:3001), the wrapper sends pInParams=NULL, silently discarding the supplied argument and executing the no-argument method instead.
Please validate against zero arguments when InParams is None. Add regression coverage beside tests/SMB_RPC/test_wmi_methods.py:34 (tests/SMB_RPC/test_wmi_methods.py:34), asserting that process.GetOwner('unexpected') raises TypeError.
…ch swallows errors (fortra#2296) Upstream: fortra#2296
…ch swallows errors (fortra#2296) Upstream: fortra#2296
Summary
Fixes two correctness bugs in
impacket/dcerpc/v5/dcom/wmi.py:IEnumWbemClassObject.Next()now returns the final partial batch when the server sends objects together withWBEM_S_FALSE. It still raisesWBEM_S_FALSEwhen no objects remain, preserving the existing end-of-enumeration behavior.IWbemClassObjectmethod calls now propagateExecMethodfailures and raiseTypeErrorfor argument-count mismatches instead of silently returningNone.No changelog changes are included.
Tests
tests/SMB_RPC/test_wmi_next.pyandtests/SMB_RPC/test_wmi_methods.pyuse real remote WMI/DCOM connections and Impacket'sparse_targethelper for the standard command-line credential format. They contain no mocks and can run directly without a configuration file. They also retain the existingRemoteTestCaseconfiguration andremotemarker for pytest.The enumeration tests query the singleton
Win32_OperatingSystemclass to cover full-batch success, final partial-batch recovery, exhaustion after consuming a result, and an empty query. Requesting two objects when only one exists exercises the server's actualWBEM_S_FALSEresponse with a trailing object. A semisynchronous query for a nonexistent class verifies thatNext()propagatesWBEM_E_INVALID_CLASS.The method tests fetch the real
Win32_Processclass and verify that too few or too many arguments raiseTypeError, and that calling the instance methodGetOwner()on the class propagates the server'sWBEM_E_INVALID_METHOD_PARAMETERSerror. These tests do not create processes or modify the target. Connections and remote interfaces are cleaned up even on failure.Run directly against a Windows target:
Omit
:passwordto be prompted. Both scripts also accept the usual-hashes LMHASH:NTHASH,-no-pass,-k,-aesKey, and-dc-ipoptions, and exit nonzero if a test fails.Validation:
wmi.py; this is line coverage, not a claim of exhaustive branch coverage.F824findings in unchanged files.