windows Bash 'printf' 等价于命令提示符?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5290074/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bash 'printf' equivalent for command prompt?
提问by Calum Murray
I'm looking to pipe some String input to a small C program in Windows's command prompt. In bash I could use
我希望将一些字符串输入通过管道传输到 Windows 命令提示符中的一个小 C 程序。在 bash 我可以使用
$ 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?
printf
在命令提示符/powershell 中是否有等效或类似的命令?
Thanks
谢谢
采纳答案by Keith Hill
In PowerShell, you would do it this way:
在 PowerShell 中,您可以这样做:
"AAAAA{0}{1}{2}{3}" -f 0x86,0x08,0x04,0xed | ./program
回答by golem
I recently came up with the same question myself and decided that for someone developing Windows exploits it is worth installing cygwin :)
我最近自己提出了同样的问题,并决定对于开发 Windows 漏洞的人来说,安装 cygwin 是值得的:)
Otherwise one could build a small C program mimicking printf
's functionality:
否则,可以构建一个模仿printf
功能的小型 C 程序:
#include <string.h>
int main(int argc, char *argv[])
{
int i;
char tmp[3];
tmp[2] = '##代码##';
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.
该程序仅处理“\xAB\xCD”字符串,但如果需要,将其扩展为处理“AAAAA\xAB\xCD”字符串应该不难。