Bash 'printf' equivalent for command prompt?

梦想与她 提交于 2019-12-06 00:49:44

问题


I'm looking to pipe some String input to a small C program in Windows's command prompt. In bash I could use

$ printf "AAAAA\x86\x08\x04\xed" | ./program

Essentially, I need something to escape those hexadecimal numbers in command prompt.

Is there an equivalent or similar command for printf in command prompt/powershell?

Thanks


回答1:


In PowerShell, you would do it this way:

"AAAAA{0}{1}{2}{3}" -f 0x86,0x08,0x04,0xed | ./program



回答2:


I recently came up with the same question myself and decided that for someone developing Windows exploits it is worth installing cygwin :)

Otherwise one could build a small C program mimicking printf's functionality:

#include <string.h>

int main(int argc, char *argv[])
{
    int i;
    char tmp[3];

    tmp[2] = '\0';

    if (argc > 1) {
        for (i = 2; i < strlen(argv[1]); i += 4) {
            strncpy(tmp, argv[1]+i, 2);
            printf("%c", (char)strtol(tmp, NULL, 16));
        }
    }
    else {
        printf("USAGE: printf.exe SHELLCODE\n");
        return 1;
    }

    return 0;
}

The program only handles "\xAB\xCD" strings, but it shouldn't be difficult to extend it to handle "AAAAA\xAB\xCD" strings if one needs it.



来源:https://stackoverflow.com/questions/5290074/bash-printf-equivalent-for-command-prompt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!