Closed JohnLaTwC closed 3 years ago
I'm curious, especially from your earlier tweet, are you using any specific toolchain in your checks, or manual verification?
Just let me know when your done finding new things and I'll get them fixed :)
(ps: I'm off work for the next 2.5 weeks starting tomorrow so depending on when you say your done may be a slower turn around then last time)
Code review only and findstr when I find a pattern. Obviously it's not perfect as some of these issues escaped me the first time around.
Alright cool. I think no process is perfect, as I threw scan-build, cppcheck and manual runs with dr.memory at all of these now and obviously some things still get missed 😂
Thanks again though, the help is appreciated.
I think this concludes my review. Thanks for the efforts looking into the issues I've flagged so far!
Issue 1
wmi_query always returns S_OK even on failure cases.
I am not sure this leads to any bugs, but it may not be the developer's intent.
See the implementation of
Wmi_Finalize
always returnsS_OK
:https://github.com/trustedsec/CS-Situational-Awareness-BOF/blob/9dfb0524cbebe15bd6805b50c8e8b77075df0229/src/SA/wmi_query/entry.c#L92
https://github.com/trustedsec/CS-Situational-Awareness-BOF/blob/9dfb0524cbebe15bd6805b50c8e8b77075df0229/src/common/wmi.c#L584
Issue 2
OpenSCManagerA
andenumerate_services
return win32 errors, not HRESULT so error code should be checked againstERROR_SUCCESS
I am not sure this leads to any bugs, but it may not be the developer's intent.
https://github.com/trustedsec/CS-Situational-Awareness-BOF/blob/0fb0bb9cec045909e992d49ed407e8f895cecfd9/src/SA/sc_enum/entry.c#L424
Issue 3
enumerate_loaded_drivers()
leaks memory in early returnhttps://github.com/trustedsec/CS-Situational-Awareness-BOF/blob/0fb0bb9cec045909e992d49ed407e8f895cecfd9/src/SA/driversigs/entry.c#L187 https://github.com/trustedsec/CS-Situational-Awareness-BOF/blob/0fb0bb9cec045909e992d49ed407e8f895cecfd9/src/SA/driversigs/entry.c#L202
Issue 4
SCM handle must be closed with
CloseServiceHandle
notCloseHandle
https://github.com/trustedsec/CS-Situational-Awareness-BOF/blob/0fb0bb9cec045909e992d49ed407e8f895cecfd9/src/SA/driversigs/entry.c#L224
Issue 5
Registry handle needs to be closed with
RegCloseKey
notCloseHandle
https://github.com/trustedsec/CS-Situational-Awareness-BOF/blob/0fb0bb9cec045909e992d49ed407e8f895cecfd9/src/SA/driversigs/entry.c#L219
Issue 6
I am not sure the effect here but I wanted to flag it. There are mismatches between the count of elements and the number of elements in calls to
antiStringResolve
https://github.com/trustedsec/CS-Situational-Awareness-BOF/blob/9dfb0524cbebe15bd6805b50c8e8b77075df0229/src/SA/sc_qc/entry.c#L17
https://github.com/trustedsec/CS-Situational-Awareness-BOF/blob/9dfb0524cbebe15bd6805b50c8e8b77075df0229/src/SA/sc_enum/entry.c#L46
https://github.com/trustedsec/CS-Situational-Awareness-BOF/blob/9dfb0524cbebe15bd6805b50c8e8b77075df0229/src/SA/sc_query/entry.c#L14
antiStringResolve
will callva_arg
on the extra argument and I am not sure the result.Issue 7
Reg_EnumKey
loop missing a call tointFree
onitem
. It frees the memory of the item contents (val->keypath
,val->hreg
), but not the item itself.https://github.com/trustedsec/CS-Situational-Awareness-BOF/blob/0fb0bb9cec045909e992d49ed407e8f895cecfd9/src/SA/reg_query/entry.c#L334
Issue 8
Copy Paste error leads to incorrect initialization. It doesn't cause a bug because the buffer size matches.
https://github.com/trustedsec/CS-Situational-Awareness-BOF/blob/0fb0bb9cec045909e992d49ed407e8f895cecfd9/src/SA/whoami/entry.c#L132