Monday, April 20, 2020

certutil downloader

certutil.exe -urlcache -split -f https://somewhere/test.exe c:\windows\temp\test.exe

dir c:\windows\temp\test.exe

bitsadmin download

bitsadmin /CREATE TestJob
bitsadmin /ADDFILE TestJob https://somewhere.com/file.exe c:\windows\temp\file.exe
bitsadmin /RESUME TestJob
bitsadmin /INFO TestJob /VERBOSE
bitsadmin /COMPLETE TestJob

dir c:\windows\temp\file.exe

bitsadmin timeout troubleshooting error

List all BITSADMIN jobs and their status

bitsadmin /LIST /ALLUSERS /VERBOSE | findstr "STATE DISPLAY"


Troubleshoot a specific job

bitsadmin /GETERROR MyJobsName

Monday, April 13, 2020

Wmic List all Processes, sort in powershell


$processes = wmic.exe process list |foreach-object {$k = $_ -split '\s+';foreach($i in $k){if($i -notmatch "\\" -and $i.endswith(".exe")){$i.tolower()}}} |sort-object|get-unique

$processes

---------------
example output
---------------
adobearm.exe
aoservice.exe
apmsgfwd.exe
apntex.exe
apoint.exe
applicationframehost.exe
... more ...




---------------
example output
---------------
$processpaths = wmic.exe process list |foreach-object {$k = $_ -split '\s+';foreach($i in $k){if($i -notmatch "\\" -and $i.endswith(".exe")){$i.tolower()}}} |sort-object|get-unique|foreach-object{get-process -name ($_ -replace ".{4}$") | select path} |foreach-object {$_.path.tolower()} |get-unique

$processpaths

---------------
example output
---------------
c:\program files (x86)\common files\adobe\arm\1.0\adobearm.exe
c:\program files\citrix\secure access client\aoservice.exe
c:\windows\system32\delltpad\apmsgfwd.exe
c:\windows\system32\delltpad\apntex.exe
c:\windows\system32\delltpad\apoint.exe
c:\windows\system32\applicationframehost.exe
c:\windows\system32\delltpad\apremote.exe
... more ...

Nullsoft Installer in IDA Pro

Just my attempt to review the start of the nullsoft installer (EasyPDfCombine)

MD5             C95772694EA68F394DAA4AC144BD40FB                                   

start
- call ds:InitCommonControls  [ initialized common controls in windows ]
- call ds:SetErrorMode (8001h) [ send critical errors to calling process, no prompt if error]
- call ds:OleInitialize   [initialize COM (component model object) library ]
- call sub_xxxxx1
        -- call ds:GetModuleHandleA [ gets handle to the KERNEL32.DLL ]
        -- call ds:LoadLibraryA [ loads KERNEL32.DLL into memory ]
        -- call ds:GetProcessAddress [ gets the address of GetDiskFreeSpaceExW method, dynamically loaded, it is not in the import table ]
- call ds:SHGetFileInfoW [ gets info like file name, attribute, ioc of file ]
- call sub_xxxxx2
        -- call ds:lstrcpynW [ makes a copy of the NSIS error message string ]
- call ds:CommandLineW [ gets the command line string for this process ]
- call sub_xxxxx2
        -- call ds:lstrcpynW [ makes a copy of the command line string  ]
- call ds:GetModuleHandleW [ gets a handle to the file of this current process ]
- call sub_xxxxx3  [ arguments are Quote(") and the Command Line String ]
        -- while character is not a Quote(")
            -- call ds:CharNextW [] to move to the next character in Command line String
- call ds:CharNextW [move past the Quote(") that was just found]
- while character is not a Space (0x20)
        -- inc eax [ move to the next letter in the command line string]
- inc eax  (past Quote(" , 0x22))
- find the flag ("/S" , 0x2f53)
- find the flag ("/NCRC", 0x2f4E435243)   (note: in assembly listed CNCR (reversed)
- call sub_xxxxx2
        -- call ds:lstrcpynW [ makes a copy of the command line string  ]
- call ds:GetTempPathW [ gets path of temp folder ]
- call ds:GetWindowsDirectoryW [ gets path of windows folder ]
- call lstrcatW [ append "Temp" to the folder so c:\windows\temp ]
- call sub_xxxxx4
     -- call sub_xxxxx5   [ did not finish ]
     -- call sub_xxxxx6   [ did not finish ]
     -- call sub_xxxxx7   [ did not finish ]
     -- call ds:CreateDirectoryW
     -- call sub_xxxxx8   [ did not finish ]
- call ds:GetTempPathW [ gets path of temp folder ]
- call lstrcatW [ append the word "Low" to the temp folder ]
       note: changes it from C:\Users\x\AppData\Local to C:\Users\x\AppData\LocalLow
- call ds:SetEnvironmentVariableW [ set T to the temp folder ]
- call ds:SetEnvironmentVariableW [ set TMP to the temp folder ]
- call ds:DeleteFileW [ ]
- ... much more ...
- call lstrcatW [ append "~nsu.tmp" to the temp folder path ]
- ... more ...
- call ds:CreateDirectoryW [ create a new temp folder ]
- call ds:SetCurrentDirectoryW [ move to the newly created folder ]
- call sub_xxxxx2
- call sub_xxxxx2
- call sub_xxxxx9 [works on CurrentVersion registry and Quick Launch registry]
- call ds:DeleteFileW
- call ds:CopyFileW
- call sub_xxxxx9 [works on CurrentVersion registry and Quick Launch registry]
- call sub_xxxxx10
    -- call ds:CreateProcess
    -- call ds:CloseHandle
- call ds:CloseHandle
- ... more ...

C++ Console App in IDA Pro find Actual Main Function

In C++

XorTesting.exe

has

XorTesting.cpp

which looks like

int main(int argc, char * argv[])
{
    if ((argc == 3 && strlen(argv[1]) == 1 && argv[1][0] == '0') ||
        (argc == 2 && strlen(argv[1]) == 1 && argv[1][0] == '1'))
    {
            .... more code ....
    }
}

----------
In IDA Pro here is how to find the actual main function
----------

----------
start proc
   jmp start_0
----------

----------
start_0 proc
   push ebp
   mov ebp, esp
   call sub_xxxxx1 (just calls init functions)
   pop ebp
   return
-----------

-----------
sub_xxxxx1 proc
  push ebp
  mov ebp, esp
  call sub_xxxxx2  (security cookie check)
  call sub_xxxxx3  (initializes and then calls actual main function)
  pop ebp
  ret
-----------

-----------
sub_xxxxx3 proc
  var_44= dword ptr -44h
  var_40= dword ptr -40h
  var_3C= dword ptr -3Ch
  ... many more ...
  push ebp
  mov ebp, esp
  push 0FFFFFFFEh
  ...
  call j__initterm
  ...
  call ds:___guard_check_icall_fptr
  ...
  call j__register_threat_local_exe_atexit_callback
  add esp, 4
  loc_xxxxxx:
    call sub_xxxxx4 (will end up calling the actual main function)
    ...
    call j_exit
    ... lots more code...
------------


------------
sub_xxxxx4 proc
  var_C= dword ptr -0Ch
  var_8= dword ptr -8h
  var_4= dword ptr -4h
  push ebp
  mov ebp, esp
  ...
  call j__get_initial_narrow_environment
  ...
  call j__p___argv
  ...
  call j__p___argc
  ...
  call j__sub_xxxxx5   (will end up calling the actual main function)
  add esp, 0Ch
  mov esp, ebp
  pop ebp
  return
-------------

-------------
sub_xxxxx5 proc
  jmp sub_xxxxx6   (the ACTUAL main function code)
-------------

-------------
sub_xxxxx6 proc
  var_178= dword ptr -178h
  var_174= dword ptr -174h
  var_168= dword ptr -168h
  ... many more ...
  push ebp
  mov ebp, esp
  sub esp, 178h
  ...
  rep stosd
  mov eax, __security_cookie
  ...
  cmp [ebp+arg_0], 3       (equivalent of C++   "if argc == 3")
  ...
  call j_strlen          (equivalent of c++ 'strlen' call)
  ... rest of code ...
-------------

Xor brutexor.py Example

C++ code to xor encrypt or decrypt (below)
When compiled it builds XorTesting.exe
You can find the hardcoded value by running brutexor.py ( http://hooked-on-mnemonics.blogspot.com/p/iheartxor.html )

$> python.exe brutexor.py XorTesting.exe | findstr http

0x672f key 0x1f  http://www.google.com/happy


-----------------------
C++ code
-----------------------
#include <stdio.h>
#include <string.h>
#include <cstdlib>

int main(int argc, char * argv[])
{
    if ((argc == 3 && strlen(argv[1]) == 1 && argv[1][0] == '0') ||
        (argc == 2 && strlen(argv[1]) == 1 && argv[1][0] == '1'))
    {
        char parameter[50] = "wkkohhh1xppxsz1|pr0w~oof\0";
        char xord[50];
        int key = 31;
        if (argv[1][0] == '0')
        {
            printf("Running in 'user input(0)' mode\n\n");
            strncpy_s(parameter, argv[2], strlen(argv[2]));

            unsigned int i = 0;
            for (i = 0; i < strlen(parameter); i++)
            {
                xord[i] = parameter[i] ^ key;
            }
            xord[i] = '\0';

            printf("key   : 0x%x\n", key);
            printf("before: %s\n", parameter);
            printf("after : %s\n", xord);
        }
        else if (argv[1][0] == '1')
        {
            printf("Running in 'hardcoded value (1)' mode\n\n");

            unsigned int i = 0;
            for (i = 0; i < strlen(parameter); i++)
            {
                xord[i] = parameter[i] ^ key;
            }
            xord[i] = '\0';

            printf("key   : 0x%x\n", key);
            printf("before: %s\n", parameter);
            printf("after : %s\n", xord);
        }
    }
    else
        printf("Usage:\n  0 = user input mode\n  1 = hardcoded value mode\n\n  XorTesting.exe 0 cleartextvalue\n  XorTesting.exe 1");

    return EXIT_SUCCESS;
}