How to use the paramiko.util.log_to_file function in paramiko

To help you get started, we’ve selected a few paramiko examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Komodo / KomodoEdit / contrib / paramiko / demos / demo.py View on Github external
path = input('DSS key [%s]: ' % default_path)
        if len(path) == 0:
            path = default_path
        try:
            key = paramiko.DSSKey.from_private_key_file(path)
        except paramiko.PasswordRequiredException:
            password = getpass.getpass('DSS key password: ')
            key = paramiko.DSSKey.from_private_key_file(path, password)
        t.auth_publickey(username, key)
    else:
        pw = getpass.getpass('Password for %s@%s: ' % (username, hostname))
        t.auth_password(username, pw)


# setup logging
paramiko.util.log_to_file('demo.log')

username = ''
if len(sys.argv) > 1:
    hostname = sys.argv[1]
    if hostname.find('@') >= 0:
        username, hostname = hostname.split('@')
else:
    hostname = input('Hostname: ')
if len(hostname) == 0:
    print('*** Hostname required.')
    sys.exit(1)
port = 22
if hostname.find(':') >= 0:
    hostname, portstr = hostname.split(':')
    port = int(portstr)
github zdresearch / OWASP-Honeypot / modules / ssh / strong_password / files / ssh_listener.py View on Github external
def main():
    try:
        server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        server_socket.bind(("", SSH_PORT))
        server_socket.listen(100)
        paramiko.util.log_to_file('/root/logs/paramiko.log')

        while True:
            try:
                client_socket, client_addr = server_socket.accept()
                _thread.start_new_thread(handle_connections, (client_socket, client_addr))
            except Exception as e:
                print("ERROR: Client handling", e)

    except Exception as e:
        print("ERROR: Failed to create socket", e)
        sys.exit(1)
github paramiko / paramiko / demos / demo_simple.py View on Github external
import os
import socket
import sys
import traceback
from paramiko.py3compat import input

import paramiko

try:
    import interactive
except ImportError:
    from . import interactive


# setup logging
paramiko.util.log_to_file("demo_simple.log")
# Paramiko client configuration
UseGSSAPI = (
    paramiko.GSS_AUTH_AVAILABLE
)  # enable "gssapi-with-mic" authentication, if supported by your python installation
DoGSSAPIKeyExchange = (
    paramiko.GSS_AUTH_AVAILABLE
)  # enable "gssapi-kex" key exchange, if supported by your python installation
# UseGSSAPI = False
# DoGSSAPIKeyExchange = False
port = 22

# get hostname
username = ""
if len(sys.argv) > 1:
    hostname = sys.argv[1]
    if hostname.find("@") >= 0:
github apache / libcloud / libcloud / __init__.py View on Github external
mode = 'a'

        # Special case for /dev/stderr and /dev/stdout on Python 3.
        from libcloud.utils.py3 import PY3

        # Opening those files in append mode will throw "illegal seek"
        # exception there.
        # Late import to avoid setup.py related side affects
        if path in ['/dev/stderr', '/dev/stdout'] and PY3:
            mode = 'w'

        fo = codecs.open(path, mode, encoding='utf8')
        enable_debug(fo)

        if have_paramiko and hasattr(paramiko.util, 'log_to_file'):
            paramiko.util.log_to_file(filename=path, level=logging.DEBUG)

    # check for broken `yum install python-requests`
    if have_requests and requests.__version__ == '2.6.0':
        chardet_version = requests.packages.chardet.__version__
        required_chardet_version = '2.3.0'
        assert chardet_version == required_chardet_version, (
            'Known bad version of requests detected! This can happen when '
            'requests was installed from a source other than PyPI, e.g. via '
            'a package manager such as yum. Please either install requests '
            'from PyPI or run `pip install chardet==%s` to resolve this '
            'issue.' % required_chardet_version
        )
github DidierStevens / Beta / tcp-honeypot.py View on Github external
def TCPHoneypot(filenames, options):
    global dListeners

    oOutput = cOutput('tcp-honeypot-%s.log' % FormatTime(), True)

    for filename in filenames:
        oOutput.LineTimestamped('Exec: %s' % filename)
        execfile(filename, globals())

    if ModuleLoaded('paramiko'):
        paramiko.util.log_to_file('tcp-honeypot-ssh-%s.log' % FormatTime())

    if options.ports != '':
        oOutput.LineTimestamped('Ports specified via command-line option: %s' % options.ports)
        dListeners = {}
        for port in ParsePorts(options.ports):
            dListeners[port] = {}

    if options.extraports != '':
        oOutput.LineTimestamped('Extra ports: %s' % options.extraports)
        for port in ParsePorts(options.extraports):
            dListeners[port] = {}

    sockets = []

    for port in dListeners.keys():
        if THP_SSL in dListeners[port]:
github hagaisolo / Python-Penetration-Testing-Application / Groups / BruteForceSSH / BruteForceSSH.py View on Github external
def __init__(self, _ip, _port, _username, _passwords=True):
        threading.Thread.__init__(self)
        paramiko.util.log_to_file("Groups//BruteForceSSH//paramiko.log")
        self.IP = _ip
        self.PORT = _port
        self.username = _username
        self.passwords = _passwords
        # assign a name to the thread for better debug
        name = ("Thread %s" % attempts)
        threading.current_thread().setName(name)
        self.id = threading.current_thread().getName()

        self.ret = [0, 0]
github WesleyPeng / uiXautomation / src / main / python / taf / foundation / plugins / cli / paramiko / sshclient.py View on Github external
def _initialize(self, **kwargs):
        # Currently using username / password to perform authentication.
        # Host key file is not applied, and
        # the log file is located at %tmp% (/tmp) folder
        filename = os.path.join(
            tempfile.gettempdir(),
            'SSHClient.log'
        )
        paramiko.util.log_to_file(filename)
        self.set_missing_host_key_policy(
            paramiko.AutoAddPolicy()
        )

        self.connect(
            **kwargs
        )
github openshift / openshift-client-python / packages / new_syntax.py View on Github external
# Current thinking
# - Use model extensively. The use of dicts is just too painful syntax-wise.
# - Do not implement watch. Not targeting writing a controller and user can easy poll for changes they are
# interested in. It's technically possible if you polled channel recv_ready & read lines, but why bother with this
# complexity?
#


import openshift
import logging
import paramiko
import traceback

logging.getLogger("paramiko").setLevel(logging.DEBUG)
paramiko.util.log_to_file("paramiko.log")

with openshift.tracking() as t:

    with openshift.client_host(hostname="54.147.205.250", username="root", auto_add_host=True):

        with openshift.project("jmp-test-3"):

            try:

                openshift.selector('all').delete(ignore_not_found=True)
                openshift.selector('secrets/test-secret').delete(ignore_not_found=True)


                na_sel = openshift.new_app("https://github.com/openshift/ruby-hello-world")
                print("Created objects with new-app: {}".format(na_sel.qnames()))
                print('Found buildconfig: {}'.format(na_sel.narrow('bc').qnames()))