python怎么处理输入,如何使用Python脚本为批处理文件提供输入?

这篇博客展示了如何使用Python3通过`subprocess`模块注入包含不可打印ASCII字符(如空字节)的攻击字符串。示例中,代码与批处理文件`echo.bat`交互,根据用户输入决定是否继续,并演示了如何利用Python进行输入操作。
摘要由CSDN通过智能技术生成

这是可行的:我用它来注入使用不可打印的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"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值