该函数从粘贴到具有标题的pastebin上的python脚本中py_0001
,获取到执行try: except:
时抛出错误的信息SyntaxError: unexpected character after line continuation character
如果您复制的值script_
并将其声明为字符串变量,则它会执行而不会出现任何错误
该功能正常运行,直到到达错误处理部分
def get_script():
''' grabs python script from pastebin '''
reg_ = r'[a-zA-Z0-9]*\">py_0001'
resp = requests.get(url='https://pastebin.com/u/'+usr_name)
path = re.findall(reg_ , str(resp.content) , re.MULTILINE)
url2 = "https://pastebin.com/raw/"+ str(path[0]).replace('">py_0001' , '')
resp2 = requests.get(url2)
script_ = str(resp2.content)[2:-1]
print (script_)
try:
exec(script_)
except:
print ("3rr0r")
这是pastebin上粘贴的输出
import os\r\nimport time \r\nimport random \r\n \r\ndef fun_9991():\r\n ## a simple code example to test \r\n for i in range (0 , 10 ):\r\n print ( " loop count {} , random number is {} , time is {} ".format(i , random.randrange(10) , int(time.time()/1000)))\r\n print ("loop reached the end")\r\n \r\n \r\nif __name__ == "__main__":\r\n fun_9991()\r\n\r\n\r\n
您的问题是调用str()
一个字节对象。永远不要调用str()
bytes对象将其转换为字符串,因为它的行为类似于repr()
。只需使用[2:-1]仅会删除引号,而不会撤消转义其他特殊字符。
你可以这样做:
script_ = resp2.content.decode('utf-8')
或这个:
script_ = resp2.text
而且,从互联网执行随机代码是一个非常糟糕的主意。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句