Skip to content

Commit e288dc4

Browse files
added dedicated arguments for port, user and password instead of a single argument
1 parent c9fd3e0 commit e288dc4

File tree

1 file changed

+44
-32
lines changed

1 file changed

+44
-32
lines changed

ssh_proxy_server/authentication.py

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,6 @@ def parse_service_accept(self, m):
6868
return valid_key
6969

7070

71-
def validate_remote_host(remote_host):
72-
if re.match(r"[^\:]+(:[0-9]{5})?", remote_host):
73-
return remote_host
74-
raise argparse.ArgumentTypeError('remot host must be in format hostname:port')
75-
76-
77-
def validate_honeypot(remote_host):
78-
if re.match(r"[^\:]+:[^@]+@[^\:]+(:[0-9]{5})?", remote_host):
79-
return remote_host
80-
raise argparse.ArgumentTypeError('honeypot address must be in format username:password@hostname:port')
81-
82-
8371
class RemoteCredentials():
8472

8573
def __init__(
@@ -109,8 +97,13 @@ def parser_arguments(cls):
10997
plugin_group.add_argument(
11098
'--remote-host',
11199
dest='remote_host',
112-
type=validate_remote_host,
113-
help='remote host to connect to (format remote_host:remote_port, default 127.0.0.1:22)'
100+
help='remote host to connect to (default 127.0.0.1)'
101+
)
102+
plugin_group.add_argument(
103+
'--remote-port',
104+
type=int,
105+
dest='remote_port',
106+
help='remote port to connect to (default 22)'
114107
)
115108
plugin_group.add_argument(
116109
'--auth-username',
@@ -123,21 +116,46 @@ def parser_arguments(cls):
123116
help='password for remote authentication'
124117
)
125118

126-
plugin_group.add_argument(
127-
'--fallback-host',
128-
dest='fallback_host',
129-
required='--enable-auth-fallback' in sys.argv,
130-
type=validate_honeypot,
131-
help='fallback host for the honeypot (format username:password@hostname:port)'
132-
)
133-
134119
plugin_group.add_argument(
135120
'--hide-credentials',
136121
dest='auth_hide_credentials',
137122
action='store_true',
138123
help='do not log credentials (usefull for presentations)'
139124
)
140125

126+
honeypot_group = cls.parser().add_argument_group('Authentication Fallback')
127+
honeypot_group.add_argument(
128+
'--enable-auth-fallback',
129+
action='store_true',
130+
default=False,
131+
help="use a honeypot if no agent was forwarded to login with publickey auth "
132+
)
133+
honeypot_group.add_argument(
134+
'--fallback-host',
135+
dest='fallback_host',
136+
required='--enable-auth-fallback' in sys.argv,
137+
help='fallback host for the honeypot'
138+
)
139+
honeypot_group.add_argument(
140+
'--fallback-port',
141+
dest='fallback_port',
142+
type=int,
143+
default=22,
144+
help='fallback port for the honeypot'
145+
)
146+
honeypot_group.add_argument(
147+
'--fallback-username',
148+
dest='fallback_username',
149+
required='--enable-auth-fallback' in sys.argv,
150+
help='username for the honeypot'
151+
)
152+
honeypot_group.add_argument(
153+
'--fallback-password',
154+
dest='fallback_password',
155+
required='--enable-auth-fallback' in sys.argv,
156+
help='password for the honeypot'
157+
)
158+
141159
def __init__(self, session) -> None:
142160
super().__init__()
143161
self.session = session
@@ -148,26 +166,20 @@ def get_remote_host_credentials(
148166
password: Optional[str] = None,
149167
key=None
150168
) -> RemoteCredentials:
151-
remote_host = None
152-
remote_port = None
153-
if self.args.remote_host:
154-
if ':' in self.args.remote_host:
155-
remote_host = self.args.remote_host[:self.args.remote_host.rfind(':')]
156-
remote_port = int(self.args.remote_host[self.args.remote_host.rfind(':') + 1:])
157169
if self.session.proxyserver.transparent:
158170
return RemoteCredentials(
159171
username=self.args.auth_username or username,
160172
password=self.args.auth_password or password,
161173
key=key,
162-
host=remote_host or self.session.socket_remote_address[0],
163-
port=remote_port or self.session.socket_remote_address[1]
174+
host=self.args.remote_host or self.session.socket_remote_address[0],
175+
port=self.args.remote_port or self.session.socket_remote_address[1]
164176
)
165177
return RemoteCredentials(
166178
username=self.args.auth_username or username,
167179
password=self.args.auth_password or password,
168180
key=key,
169-
host=remote_host or '127.0.0.1',
170-
port=remote_port or 22
181+
host=self.args.remote_host or '127.0.0.1',
182+
port=self.args.remote_port or 22
171183
)
172184

173185
@classmethod

0 commit comments

Comments
 (0)