-1

我正在从 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

但是,对变量的赋值没有发生:

在此处输入图像描述

我怎样才能成功地执行这个任务?

4

1 回答 1

0

我终于写了类似的东西:

def getval(cmd):
    return eval(cmd[4:])

b = getval(conn.recvline(keepends=False))

它奏效了。这个问题仍然开放以获得更好的答案!

于 2021-10-20T04:20:52.497 回答