Algunos comandos usados en WinDbg # Comandos dt _peb @$peb: Muestra los detalles crudos y completos de la estructura PEB, incluyendo todos los campos en su formato original y sus valores en memoria. Es más detallado y técnico, útil para analizar cada campo individualmente. dt _peb @$peb +0x020 ProcessParameters : 0x000001ee`a9471fd0 _RTL_USER_PROCESS_PARAMETERS [+0x060] ImagePathName [Type: _UNICODE_STRING] # dt: Este es el comando Display Type en WinDbg. Se utiliza para mostrar la estructura de datos de un tipo específico en memoria. # _peb: Es el nombre de la estructura que se desea inspeccionar, en este caso, la estructura _PEB que representa el Process Environment Block de un proceso. # @$peb: Es un pseudo-registro que WinDbg usa para referirse a la dirección de la estructura PEB del proceso actual. El signo @ indica que se está utilizando un pseudo-registro, y $peb específicamente apunta al PEB del proceso depurado. # Comandos !peb: Muestra un resumen interpretado del PEB, con información organizada y presentada de manera más amigable. Es útil para una vista rápida de la información más relevante del PEB sin necesidad de navegar por cada campo de la estructura. !peb Buscar el valor de Ldr: 00007ffda39bc4c0 dt _PEB_LDR_DATA 00007ffda39bc4c0 dt _LDR_DATA_TABLE_ENTRY # !: Indica el uso de un comando de extensión en WinDbg. Las extensiones proporcionan comandos adicionales que no están directamente disponibles como comandos nativos del depurador. # peb: Es el nombre del comando de extensión específico que se utiliza para mostrar la información del PEB. # This command exists in the following forms. The second characters of the dd, dD, dw, and dW commands are case-sensitive, as are the third characters of the dyb and dyd commands. # https://learn.microsoft.com/en-us/windows-hardware/drivers/debuggercmds/d--da--db--dc--dd--dd--df--dp--dq--du--dw--dw--dyb--dyd--display-memor Command Display d This displays data in the same format as the most recent d command. If no previous d command has been issued, d has the same effect as db. Notice that d repeats the most recent command that began with d. This includes dda, ddp, ddu, dpa, dpp, dpu, dqa, dqp, dqu, dds, dps, dqs, ds, dS, dg, dl, dt, and dv, as well as the display commands on this page. If the parameters given after d are not appropriate, errors may result. da ASCII characters. Each line displays up to 48 characters. The display continues until the first null byte or until all characters in range have been displayed. All nonprintable characters, such as carriage returns and line feeds, are displayed as periods (.). db Byte values and ASCII characters. Each display line shows the address of the first byte in the line, followed by up to 16 hexadecimal byte values. The byte values are immediately followed by the corresponding ASCII values. The eighth and ninth hexadecimal values are separated by a hyphen (-). All nonprintable characters, such as carriage returns and line feeds, are displayed as periods (.). The default count is 128 bytes. dc Double-word values (4 bytes) and ASCII characters. Each display line shows the address of the first word in the line and up to eight hexadecimal word values, as well as their ASCII equivalent. The default count is 32 DWORDs (128 bytes). dd Double-word values (4 bytes).The default count is 32 DWORDs (128 bytes). dD Double-precision floating-point numbers (8 bytes). The default count is 15 numbers (120 bytes). df Single-precision floating-point numbers (4 bytes). The default count is 16 numbers (64 bytes). dp Pointer-sized values. This command is equivalent to dd or dq, depending on whether the target computer's processor architecture is 32-bit or 64-bit, respectively. The default count is 32 DWORDs or 16 quad-words (128 bytes). dq Quad-word values (8 bytes). The default count is 16 quad-words (128 bytes). du Unicode characters. Each line displays up to 48 characters. The display continues until the first null byte or until all characters in range have been displayed. All nonprintable characters, such as carriage returns and line feeds, are displayed as periods (.). dw Word values (2 bytes). Each display line shows the address of the first word in the line and up to eight hexadecimal word values. The default count is 64 words (128 bytes). dW Word values (2 bytes) and ASCII characters. Each display line shows the address of the first word in the line and up to eight hexadecimal word values. The default count is 64 words (128 bytes). dyb Binary values and byte values. The default count is 32 bytes. dyd Binary values and double-word values (4 bytes). The default count is 8 DWORDs (32 bytes). # Muestra caracteres unicode en una direccion en especifica # du
du 0x000001eea9471fd0 # This command exists in the following forms. The second characters of the ed and eD commands are case-sensitive. # https://learn.microsoft.com/en-us/windows-hardware/drivers/debuggercmds/e--ea--eb--ed--ed--ef--ep--eq--eu--ew--eza--ezu--enter-values- Command Enter e This enters data in the same format as the most recent e command. (If the most recent e command was ea, eza, eu, or ezu, the final parameter will be String and may not be omitted.) ea ASCII string (not NULL-terminated). eb Byte values. ed Double-word values (4 bytes). eD Double-precision floating-point numbers (8 bytes). ef Single-precision floating-point numbers (4 bytes). ep Pointer-sized values. This command is equivalent to ed or eq, depending on whether the target computer's processor architecture is 32-bit or 64-bit, respectively. eq Quad-word values (8 bytes). eu Unicode string (not NULL-terminated). ew Word values (2 bytes). eza NULL-terminated ASCII string. ezu NULL-terminated Unicode string. # Ejemplo 0:000> dx -r1 (*((ntdll!_UNICODE_STRING *)0x20f53f02130)) (*((ntdll!_UNICODE_STRING *)0x20f53f02130)) [Type: _UNICODE_STRING] [+0x000] Length : 0x3e [Type: unsigned short] [+0x002] MaximumLength : 0x40 [Type: unsigned short] [+0x008] Buffer : 0x20f53f02748 : "C:\Windows\System32\notepad.exe" [Type: wchar_t *] 0:000> db 0x20f53f02130 0000020f`53f02130 3e 00 40 00 00 00 00 00-48 27 f0 53 0f 02 00 00 >.@.....H'.S.... 0000020f`53f02140 30 11 f0 53 0f 02 00 00-00 00 00 00 00 00 00 00 0..S............ 0000020f`53f02150 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 0000020f`53f02160 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 0000020f`53f02170 3e 00 40 00 00 00 00 00-88 27 f0 53 0f 02 00 00 >.@......'.S.... 0000020f`53f02180 1e 00 20 00 00 00 00 00-c8 27 f0 53 0f 02 00 00 .. ......'.S.... 0000020f`53f02190 00 00 02 00 00 00 00 00-e8 27 f0 53 0f 02 00 00 .........'.S.... 0000020f`53f021a0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ Como se puede apreciar el Length está ubicado en el offset 0x000 que tiene el valor de 3e. Si queremos modificar ese valor podemos utilizar el comando eb y suministrar el valor en hexadecimal. Los valores de Length y MaximumLength en la estructura _UNICODE_STRING que ves en tu análisis de memoria con WinDbg corresponden a la longitud del nombre de archivo en caracteres Unicode (UTF-16) y la longitud máxima que el buffer puede almacenar, respectivamente. 1. Length (0x3e) Descripción: Length representa el tamaño en bytes de la cadena actualmente almacenada en el buffer. La cadena "C:\Windows\System32\notepad.exe" tiene 31 caracteres. Cada carácter en una cadena Unicode ocupa 2 bytes (ya que se utiliza UTF-16 en Windows). Por lo tanto, 31 caracteres × 2 bytes = 62 bytes. 2. MaximumLength (0x40) MaximumLength representa la capacidad máxima del buffer en bytes. Este es el tamaño total del buffer asignado para la cadena, lo cual permite que la cadena pueda crecer hasta este tamaño sin necesidad de realocar la memoria. MaximumLength generalmente se establece como un múltiplo de 2 (ya que estamos trabajando con cadenas Unicode donde cada carácter ocupa 2 bytes) y es mayor o igual a Length. Aquí, MaximumLength es 0x40, que es 64 bytes en decimal. # Ejemplo de cambiar el CommandLine de calc.exe para que sea notepad.exe 0:000> dx -r1 (*((ntdll!_UNICODE_STRING *)0x27fcd562130)) (*((ntdll!_UNICODE_STRING *)0x27fcd562130)) [Type: _UNICODE_STRING] [+0x000] Length : 0x38 [Type: unsigned short] [+0x002] MaximumLength : 0x3a [Type: unsigned short] [+0x008] Buffer : 0x27fcd562742 : "C:\Windows\System32\calc.exe" [Type: wchar_t *] 0:000> eb 0x27fcd562130 0x3e 0:000> eb 0x27fcd562130+0x002 0x40 0:000> dx -r1 (*((ntdll!_UNICODE_STRING *)0x27fcd562130)) (*((ntdll!_UNICODE_STRING *)0x27fcd562130)) [Type: _UNICODE_STRING] [+0x000] Length : 0x3e [Type: unsigned short] [+0x002] MaximumLength : 0x40 [Type: unsigned short] [+0x008] Buffer : 0x27fcd562742 : "C:\Windows\System32\calc.exe" [Type: wchar_t *] 0:000> ezu 0x27fcd562742 "C:\\Windows\\System32\\notepad.exe" 0:000> dx -r1 (*((ntdll!_UNICODE_STRING *)0x27fcd562130)) (*((ntdll!_UNICODE_STRING *)0x27fcd562130)) [Type: _UNICODE_STRING] [+0x000] Length : 0x3e [Type: unsigned short] [+0x002] MaximumLength : 0x40 [Type: unsigned short] [+0x008] Buffer : 0x27fcd562742 : "C:\Windows\System32\notepad.exe" [Type: wchar_t *]