@@ -68,18 +68,6 @@ def parse_service_accept(self, m):
68
68
return valid_key
69
69
70
70
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
-
83
71
class RemoteCredentials ():
84
72
85
73
def __init__ (
@@ -109,8 +97,13 @@ def parser_arguments(cls):
109
97
plugin_group .add_argument (
110
98
'--remote-host' ,
111
99
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)'
114
107
)
115
108
plugin_group .add_argument (
116
109
'--auth-username' ,
@@ -123,21 +116,46 @@ def parser_arguments(cls):
123
116
help = 'password for remote authentication'
124
117
)
125
118
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
-
134
119
plugin_group .add_argument (
135
120
'--hide-credentials' ,
136
121
dest = 'auth_hide_credentials' ,
137
122
action = 'store_true' ,
138
123
help = 'do not log credentials (usefull for presentations)'
139
124
)
140
125
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
+
141
159
def __init__ (self , session ) -> None :
142
160
super ().__init__ ()
143
161
self .session = session
@@ -148,26 +166,20 @@ def get_remote_host_credentials(
148
166
password : Optional [str ] = None ,
149
167
key = None
150
168
) -> 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 :])
157
169
if self .session .proxyserver .transparent :
158
170
return RemoteCredentials (
159
171
username = self .args .auth_username or username ,
160
172
password = self .args .auth_password or password ,
161
173
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 ]
164
176
)
165
177
return RemoteCredentials (
166
178
username = self .args .auth_username or username ,
167
179
password = self .args .auth_password or password ,
168
180
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
171
183
)
172
184
173
185
@classmethod
0 commit comments