Question

Here is a snippet from my code. For some reason it simply won't print out the second line saying "Cracking took 10 seconds" or whatever, but this first bit saying Password Found: does work... Why?

def connect(host, user, password, release):
    global Found
    global Fails
    global startTime

    try:
        s = pxssh.pxssh()
        s.login(host, user, password)
        print '[+] Password Found: ' + password
        print 'Cracking the password took' + datetime.now()-startTime + 'seconds.'
    Found = True

    except Exception, e:
        if 'read_nonblocking' in str(e):
        Fails += 1
            time.sleep(5)
            connect(host, user, password, False)
    elif 'synchronize with original prompt' in str(e):
        time.sleep(1)
        connect(host, user, password, False)
Was it helpful?

Solution

You are trying to concatenate two different things (datetime and str), try converting the datetime to str as:

def connect(host, user, password, release):
    global Found
    global Fails
    global startTime

    try:
        s = pxssh.pxssh()
        s.login(host, user, password)
        print '[+] Password Found: ' + password
        print 'Cracking the password took' + str(datetime.now()-startTime) + 'seconds.'
        Found = True

    except Exception, e:
        if 'read_nonblocking' in str(e):
            Fails += 1
            time.sleep(5)
            connect(host, user, password, False)
        elif 'synchronize with original prompt' in str(e):
            time.sleep(1)
            connect(host, user, password, False)

Moreover, you shouldn't trap all kind Exception, just those you need.

OTHER TIPS

The issue is probably that you haven't set startTime, but you masked it by over-broad exception handling. Either remove the try/except, select some other exception to trap, or simply include a bare raise command in your exception handler and you should see a NameError because of the absence of initialization. Fix that and your code has more of a chance.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top