Skip to content

Commit

Permalink
[internal] better CLI input
Browse files Browse the repository at this point in the history
  • Loading branch information
gentilkiwi committed Jul 23, 2021
1 parent de98fa6 commit 7dab465
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
7 changes: 2 additions & 5 deletions kekeo/kekeo.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ int wmain(int argc, wchar_t * argv[])
NTSTATUS status = STATUS_SUCCESS;
int i;
#if !defined(_POWERKATZ)
size_t len;
wchar_t input[0xffff];
wchar_t input[0x4000];
#endif
mimikatz_begin();
for(i = MIMIKATZ_AUTO_COMMAND_START ; (i < argc) && (status != STATUS_FATAL_APP_EXIT) ; i++)
Expand All @@ -36,10 +35,8 @@ int wmain(int argc, wchar_t * argv[])
while ((status != STATUS_PROCESS_IS_TERMINATING) && (status != STATUS_THREAD_IS_TERMINATING))
{
kprintf(L"\n" MIMIKATZ L" # "); fflush(stdin);
if(fgetws(input, ARRAYSIZE(input), stdin) && (len = wcslen(input)) && (input[0] != L'\n'))
if (kread(input, ARRAYSIZE(input)))
{
if(input[len - 1] == L'\n')
input[len - 1] = L'\0';
kprintf_inputline(L"%s\n", input);
status = mimikatz_dispatchCommand(input);
}
Expand Down
25 changes: 25 additions & 0 deletions modules/kull_m_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,35 @@ BOOL kull_m_output_file(PCWCHAR file)
return (!file || (file && logfile));
}

// A little gift in advance from mimikatz 3
HANDLE hConsoleInput = NULL;
BOOL kull_m_cli_read(wchar_t *buffer, DWORD NumberOfChars)
{
BOOL status = FALSE;
DWORD NumberOfCharsRead;

if (ReadConsole(hConsoleInput, buffer, NumberOfChars, &NumberOfCharsRead, NULL))
{
if (NumberOfCharsRead > 2)
{
buffer[NumberOfCharsRead - 1] = L'\0';
buffer[NumberOfCharsRead - 2] = L'\0';
NumberOfCharsRead -= 2;

status = TRUE;
}
}
else PRINT_ERROR_AUTO(L"ReadConsole");

return status;
}

int previousStdOut, previousStdErr;
UINT previousConsoleOutput;
void kull_m_output_init()
{
hConsoleInput = GetStdHandle(STD_INPUT_HANDLE);

#if !defined(_POWERKATZ)
#if !defined(_WINDLL)
previousStdOut = _setmode(_fileno(stdout), _O_U8TEXT);
Expand Down
3 changes: 2 additions & 1 deletion modules/kull_m_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ void kprintf(PCWCHAR format, ...);
void kprintf_inputline(PCWCHAR format, ...);

BOOL kull_m_output_file(PCWCHAR file);

#define kread kull_m_cli_read //
BOOL kull_m_cli_read(wchar_t *buffer, DWORD NumberOfChars); //
void kull_m_output_init();
void kull_m_output_clean();

0 comments on commit 7dab465

Please sign in to comment.