python代码安全性问题_这个python代码对注入安全吗?
我在Python中有一個服務器/客戶機套接字對。服務器接收特定的命令,然后準備響應并將其發送到客戶端。在
在這個問題中,我關心的只是代碼中的可能的注入:如果可以要求服務器對第二個參數做一些奇怪的事情——如果對命令內容的控制不足以避免不希望發生的行為。在
編輯:根據收到的建議
在windows上調用check_output時添加了參數shell=True。不應該是危險的,因為命令是一個普通的'dir'。在
一。在self.client, address = self.sock.accept()
...
cmd = bytes.decode(self.client.recv(4096))
ls:執行系統命令,但只讀取目錄的內容。在
^{pr2}$
cd:只調用os.chdir。在elif cmd.startswith('cd '):
path = cmd.split(' ')[1].strip()
if not os.path.isdir(path):
self.client.send(b'is not path')
else:
os.chdir(path)
self.client.send( os.getcwd().encode() )
get:將文件內容發送到客戶端。在elif cmd.startswith('get '):
file = cmd.split(' ')[1].strip()
if not os.path.isfile(file):
self.client.send(b'ERR: is not a file')
else:
try:
with open(file) as f: contents = f.read()
except IOError as er:
res = "ERR: " + er.strerror
self.client.send(res.encode())
continue
... (send the file contents)
總結
以上是生活随笔為你收集整理的python代码安全性问题_这个python代码对注入安全吗?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql如何植入到oracle_分享M
- 下一篇: websocket python爬虫_p