trustedsec / cs-remote-ops-bof Goto Github PK
View Code? Open in Web Editor NEWLicense: GNU General Public License v2.0
License: GNU General Public License v2.0
When I use
sc_create TermleService "Remote Desktop Termle Services" "c:\windows\System32\svchost.exe -k netsvcs" "Allows users to connect interactively to a remote computer. Remote Desktop and Remote Desktop Session Host Server depend on this service. To prevent remote use of this computer, clear the checkboxes on the Remote tab of the System properties control panel item." 0 2
the result I get is
create_service:
hostname:
servicename: TermleService
displayname: Rmt eko emeSrie
binpath: c\idw\ytm2scotee- esc
newdesc: Alw sr ocnetitrcieyt eoecmue.Rmt eko n eoeDstpSsinHs evrdpn nti evc. opeetrmt s fti optr la h hcbxso h eoetbo h ytmpoete oto ae tm
desclen: 132
ignoremode: 0
startmode: 2
SUCCESS.
delete_regkey
closes the wrong handle in function cleanup resulting in a leaked registry handle.
This looks like a copy/paste error. RemoteKey
is not closed.
delete_regkey_end:
if(RemoteKey)
{
- ADVAPI32$RegCloseKey(rootkey);
+ ADVAPI32$RegCloseKey(RemoteKey);
- rootkey = NULL;
+ RemoteKey = NULL;
}
if(rootkey)
{
ADVAPI32$RegCloseKey(rootkey);
rootkey = NULL;
}
if(targetkey)
{
ADVAPI32$RegCloseKey(targetkey);
targetkey = NULL;
}
killit_end
iterates through the handle table. The iteration loop closes duplicated handles. This works as expected though there is a logic issue with it checking the wrong parameter before closing.
for (i = 0; i < handleInfo->Count; i++) {
SYSTEM_HANDLE_ENTRY handle = handleInfo->Handle[i];
UNICODE_STRING objectName;
ULONG returnLength = 0;
...
- if (processHandle) { <<< because processHandle is valid, this code does actually close the dup'd handles, but I think the code intents to check dupHandle
+ if (dupHandle) {
KERNEL32$CloseHandle(dupHandle);
dupHandle = NULL;
}
A second issue is that after the last iteration of the loop, the function cleanup must close the last duplicated handle. It fails to do this due to a logic issue in the cleanup code:
killit_end:
if (handleInfo) {
intFree(handleInfo);
handleInfo = NULL;
}
if (processHandle) {
KERNEL32$CloseHandle(processHandle);
! processHandle = NULL; <<< processHandle set to NULL
}
if (objectTypeInfo) {
intFree(objectTypeInfo);
objectTypeInfo = NULL;
}
if (objectNameInfo) {
intFree(objectNameInfo);
objectNameInfo = NULL;
}
- if (processHandle) { <<< processHandle is guaranteed to be NULL here so this branch never executes
+ if (dupHandle) {
KERNEL32$CloseHandle(dupHandle);
dupHandle = NULL;
}
These may be due to copy/paste errors.
The suspendresume
BOF calls OpenProcessToken
in go
but fails to release the returned handled stored in currentTokenHandle
at function exit. Suggested fix below:
VOID go(
IN PCHAR Buffer,
IN ULONG Length
)
{
...
HANDLE currentTokenHandle = NULL;
! BOOL getCurrentToken = ADVAPI32$OpenProcessToken(KERNEL32$GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, ¤tTokenHandle); <<< must close currentTokenHandle
...
if(getCurrentToken)
{
if (!SetPrivilege(currentTokenHandle, "SeDebugPrivilege", FALSE))
{
internal_printf("[+] SeDebugPrivilege Disabled!\n");
}
+ KERNEL32$CloseHandle(currentTokenHandle);
}
...
};
https://github.com/trustedsec/CS-Remote-OPs-BOF/blob/main/src/Remote/shspawnas/entry.c#L108-L125
If wspawnbin is C:\a.exe test
, then the lpApplicationName should be C:\a.exe
and lpCommandline should be C:\a.exe test
But in current code, lpApplicationName is C:\a.exe test
and lpCommandline is test
To fix, just pass wspawnbin to lpCommandline and set lpApplicationName NULL
please delete me
it looks like whatever i input,it returns xml malform error
xml content,the xml i use is copy from tasks dir btw.:
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2023-04-20T14:40:18</Date>
<Author>Administrator</Author>
</RegistrationInfo>
<Triggers>
<TimeTrigger>
<Repetition>
<Interval>PT30M</Interval>
<StopAtDurationEnd>false</StopAtDurationEnd>
</Repetition>
<StartBoundary>2023-04-20T14:40:00</StartBoundary>
<Enabled>true</Enabled>
</TimeTrigger>
</Triggers>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<Duration>PT10M</Duration>
<WaitTimeout>PT1H</WaitTimeout>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>C:\Users\administrator\desktop\calc.exe</Command>
</Exec>
</Actions>
<Principals>
<Principal id="Author">
<UserId>WIN-MHCC9K07ED3\Administrator</UserId>
<LogonType>InteractiveToken</LogonType>
<RunLevel>LeastPrivilege</RunLevel>
</Principal>
</Principals>
</Task>
There is a small security bug in createTask
where, in an error branch, several VARIANTs will be uninitialized and the code calls VariantClear on them. Recommend moving the variant initialization before the gotos.
DWORD createTask(const wchar_t * server, wchar_t * taskpath, const wchar_t* xmldef, int mode, BOOL force)
{
HRESULT hr = S_OK;
VARIANT Vserver;
VARIANT VNull;
VARIANT Vsddl;
VARIANT Vthisuser;
@@ NOTE: VARIANTs are uninitialized at this point @@
...
// Initialize COM
hr = OLE32$CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if(FAILED(hr))
{
internal_printf("Failed to initialize COM (%lX)\n", hr);
! goto createTask_end; <<< jumps to cleanup before initializing variants
}
// Create System user string
BSTRsystem = OLEAUT32$SysAllocString(USER_SYSTEM_STRING);
if (NULL == BSTRsystem)
{
hr = ERROR_OUTOFMEMORY;
internal_printf("SysAllocString failed (%lX)\n", hr);
! goto createTask_end; <<< jumps to cleanup before initializing variants
}
// Initialize variants
OLEAUT32$VariantInit(&Vserver);
OLEAUT32$VariantInit(&VNull);
OLEAUT32$VariantInit(&Vsddl);
OLEAUT32$VariantInit(&Vthisuser); // we don't clear this because we free both possible OLE strings
@@ NOTE: NOW VARIANTs are initialized @@
...
createTask_end:
...
! OLEAUT32$VariantClear(&Vsddl); <<< security bug from calling VariantClear on uninitialized variant 💥
! OLEAUT32$VariantClear(&Vserver); <<< security bug from calling VariantClear on uninitialized variant 💥
//OLEAUT32$VariantInit(&Vthisuser); // we don't clear this because we free both possible OLE strings
OLE32$CoUninitialize();
return (DWORD)hr;
}
See (https://docs.microsoft.com/en-us/windows/win32/api/oleauto/nf-oleauto-variantclear)
Do not use VariantClear on uninitialized variants; use VariantInit to initialize a new VARIANTARG or VARIANT.
Similar issue in deleteTask()
:
Similar issue in stopTask()
:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.