这是可行的:我用它来注入使用不可打印的ascii字符(如空字节)的攻击字符串.
使用Python 3的示例:
inject_string.py
import ctypes
import time
import subprocess
import binascii
if __name__ =="__main__":
response = "Y"
p = subprocess.Popen("echo.bat", stdin = subprocess.PIPE)
time.sleep(2)
p.stdin.write(bytes(response, 'ascii')) #Answer the question
print("injected string :", response)
echo.bat
@ECHO OFF
:choice
set /P c=Do you want to continue [Y/N]?
if /I "%c%" EQU "Y" goto :yes
if /I "%c%" EQU "N" goto :no
goto :choice
:yes
echo "User has typed yes"
goto :continue
:no
echo "User has typed no"
:continue
pause
Output
python inject_string.py
Do you want to continue [Y/N]?injected string : Y
"User has typed yes"