Git Product home page Git Product logo

cs-remote-ops-bof's People

Contributors

0xbad53c avatar benivegna avatar darkoperator avatar evanmcbroom avatar freefirex avatar johnlatwc avatar leebaird avatar paulwhitings2 avatar ridter avatar robertdiep avatar rosettapwn avatar s4ntiagop avatar snus-b avatar tw1sm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cs-remote-ops-bof's Issues

killit_end() leaks duplicated handle

Issue 1 correctness issue when checking to close handle

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;
        }

Issue 2 Duplicated handle leak at function exit

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.

how can i use schtaskscreate command ?

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>

delete_regkey() closes the wrong handle in function cleanup resulting in a leaked registry handle

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;
	}

ADVAPI32$RegCloseKey(rootkey);

Handle leak in suspendresume BOF due to failure to close token handle

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, &currentTokenHandle);   <<< must close currentTokenHandle
...
	if(getCurrentToken)
	{
		if (!SetPrivilege(currentTokenHandle, "SeDebugPrivilege", FALSE))
		{
			internal_printf("[+] SeDebugPrivilege Disabled!\n");
		}
+		KERNEL32$CloseHandle(currentTokenHandle);
	}
...
};

sc_create bug

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.

security bug: createTask calls VariantInit on uninitialized VARIANT in error cases

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.

OLEAUT32$VariantClear(&Vsddl);

Similar issue in deleteTask():

OLEAUT32$VariantClear(&Vserver);

Similar issue in stopTask():

OLEAUT32$VariantClear(&Vserver);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.