[英]Execute Command in Binary String Format in Python3
我正在從 Python 中的遠程終端連接中檢索簡單的賦值命令,並希望執行它們。 格式將類似於b = 3156
,我想使用exec()
執行它。 我的代碼:
def execbin(cmd):
exec(cmd.decode('ascii')) # decode() because recvline() gets a binary string
conn = remote(url, port) # this is from the library pwntools
execbin(conn.recvline(keepends=False)) # get the line and run it
但是,沒有發生對變量的賦值:
我怎樣才能成功地執行這個任務?
我終於寫了類似的東西:
def getval(cmd):
return eval(cmd[4:])
b = getval(conn.recvline(keepends=False))
它奏效了。 這個問題仍然開放以獲得更好的答案!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.