This series of tutorials is aimed to share the notes taken while I was learning python for cybersecurity with the books - Black Hat Python.
這系列教學文章為學習筆記+延伸資源,旨在分享學習書籍 Black Hat Python時所思所學,也希望能幫助想了解Python和資安的大大們入門。
This tutorail has also been written in English in Medium.
Let's get started! 開始吧!
安裝 paramiko
pip install paramiko
建一個檔案叫ssh_cmd.py
# ssh_cmd.py
import paramiko
def ssh_command(ip, port, passwd, cmd):
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(ip, port=port, username=user, password=passwd)
_, stdout, stderr = client.exec_command(cmd)
output = stdout.readlines() + stderr.readlines()
if output:
for line in output:
print(line.strip())
if __name__ == '__main__':
import getpass
user = input('Username: ')
password = getpass.getpass()
ip = input('Enter server IP: ') or '192.168.1.203'
port = input('Enter port or <CR>: ') or 2222
cmd = input('Enter command or <CR>: ') or 'id'
ssh_command(ip, port, user, password, cmd)
現在我們傳送以便執行。
Reference參考資料
推薦影片
絕讚! Youtube 教學影片 | Elevate Cyber
原始碼
Github - Python For Cybersecurity | Monles