2016-05-07 12:42:31 +02:00
|
|
|
; ssh.asm - SSH client for KolibriOS
|
|
|
|
;
|
2024-03-06 21:22:01 +01:00
|
|
|
; Copyright (C) 2015-2024 Jeffrey Amelynck
|
2016-05-07 12:42:31 +02:00
|
|
|
;
|
|
|
|
; This program is free software: you can redistribute it and/or modify
|
|
|
|
; it under the terms of the GNU General Public License as published by
|
|
|
|
; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
; (at your option) any later version.
|
|
|
|
;
|
|
|
|
; This program is distributed in the hope that it will be useful,
|
|
|
|
; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
; GNU General Public License for more details.
|
|
|
|
;
|
|
|
|
; You should have received a copy of the GNU General Public License
|
|
|
|
; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
format binary as ""
|
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
__DEBUG__ = 1
|
|
|
|
__DEBUG_LEVEL__ = 2 ; 1: Everything, including sensitive information, 2: Debugging, 3: Errors only
|
2016-05-07 12:42:31 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
BUFFERSIZE = 64*1024 ; Must be at least 32K according rfc4253#section-6.1
|
|
|
|
PACKETSIZE = 32*1024 ; Must be at least 32K according rfc4253#section-6.1
|
|
|
|
MAX_BITS = 8192
|
2016-05-07 12:42:31 +02:00
|
|
|
|
|
|
|
DH_PRIVATE_KEY_SIZE = 256
|
2021-08-11 22:59:10 +02:00
|
|
|
MAX_INPUT_LENGTH = 255
|
2021-08-02 20:40:01 +02:00
|
|
|
MAX_USERNAME_LENGTH = 256
|
|
|
|
MAX_PASSWORD_LENGTH = 256
|
|
|
|
MAX_HOSTNAME_LENGTH = 4096
|
|
|
|
MAX_PUBLIC_KEY_SIZE = 4096
|
2016-05-07 12:42:31 +02:00
|
|
|
|
|
|
|
use32
|
|
|
|
|
|
|
|
db 'MENUET01' ; signature
|
|
|
|
dd 1 ; header version
|
|
|
|
dd start ; entry point
|
|
|
|
dd i_end ; initialized size
|
2017-06-11 13:06:56 +02:00
|
|
|
dd mem+65536 ; required memory
|
|
|
|
dd mem+65536 ; stack pointer
|
2016-08-10 18:20:49 +02:00
|
|
|
dd params ; parameters
|
2016-05-07 12:42:31 +02:00
|
|
|
dd 0 ; path
|
|
|
|
|
|
|
|
include '../../macros.inc'
|
2016-08-10 18:20:49 +02:00
|
|
|
;include '../../struct.inc'
|
2016-05-07 12:42:31 +02:00
|
|
|
purge mov,add,sub
|
|
|
|
include '../../proc32.inc'
|
|
|
|
include '../../dll.inc'
|
|
|
|
include '../../debug-fdo.inc'
|
|
|
|
include '../../network.inc'
|
2021-10-15 02:52:46 +02:00
|
|
|
include '../../develop/libraries/libcrash/libcrash.inc'
|
2016-05-07 12:42:31 +02:00
|
|
|
|
|
|
|
; macros for network byte order
|
|
|
|
macro dd_n op {
|
|
|
|
dd 0 or (((op) and 0FF000000h) shr 24) or \
|
|
|
|
(((op) and 000FF0000h) shr 8) or \
|
|
|
|
(((op) and 00000FF00h) shl 8) or \
|
|
|
|
(((op) and 0000000FFh) shl 24)
|
|
|
|
}
|
|
|
|
|
|
|
|
macro dw_n op {
|
|
|
|
dw 0 or (((op) and 0FF00h) shr 8) or \
|
|
|
|
(((op) and 000FFh) shl 8)
|
|
|
|
}
|
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
macro str string {
|
|
|
|
local .start, .stop
|
|
|
|
|
|
|
|
dd_n (.stop-.start)
|
|
|
|
|
|
|
|
.start db string
|
|
|
|
.stop:
|
|
|
|
}
|
|
|
|
|
2016-08-10 18:20:49 +02:00
|
|
|
proc dump_hex _ptr, _length
|
|
|
|
if __DEBUG_LEVEL__ <= 1
|
|
|
|
pushad
|
|
|
|
|
|
|
|
mov esi, [_ptr]
|
|
|
|
mov ecx, [_length]
|
|
|
|
.next_dword:
|
|
|
|
lodsd
|
|
|
|
bswap eax
|
2021-07-20 22:14:53 +02:00
|
|
|
DEBUGF 1,'%x', eax
|
2016-08-10 18:20:49 +02:00
|
|
|
loop .next_dword
|
|
|
|
DEBUGF 1,'\n'
|
|
|
|
|
|
|
|
popad
|
|
|
|
end if
|
2021-07-20 22:14:53 +02:00
|
|
|
ret
|
2016-08-10 18:20:49 +02:00
|
|
|
endp
|
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
macro DEBUGM l, s, m {
|
|
|
|
if __DEBUG__
|
|
|
|
DEBUGF l, s
|
|
|
|
if l >=__DEBUG_LEVEL__
|
|
|
|
stdcall mpint_print, m
|
|
|
|
end if
|
|
|
|
end if
|
|
|
|
}
|
2016-08-10 18:20:49 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
include 'mpint.inc'
|
|
|
|
include 'seed.inc'
|
|
|
|
include 'random.inc'
|
2016-08-10 18:20:49 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
include 'sshlib.inc'
|
2016-08-10 18:20:49 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
include 'sshlib_mcodes.inc'
|
|
|
|
include 'sshlib_transport.inc'
|
2024-03-06 21:22:01 +01:00
|
|
|
include 'sshlib_transport_hmac.inc'
|
2024-03-09 21:05:21 +01:00
|
|
|
include 'sshlib_transport_hmac_etm.inc'
|
2024-03-06 21:22:01 +01:00
|
|
|
include 'sshlib_transport_polychacha.inc'
|
2021-08-02 20:40:01 +02:00
|
|
|
include 'sshlib_connection.inc'
|
|
|
|
include 'sshlib_dh_gex.inc'
|
|
|
|
include 'sshlib_host.inc'
|
|
|
|
include 'sshlib_channel.inc'
|
|
|
|
include 'sshlib_userauth.inc'
|
2017-06-11 13:06:56 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
include 'encodings.inc' ; Unfortunately, we dont have UTF-8 capable console yet :(
|
2016-08-10 18:20:49 +02:00
|
|
|
|
2016-05-07 12:42:31 +02:00
|
|
|
start:
|
|
|
|
mcall 68, 11 ; Init heap
|
|
|
|
|
2016-08-10 18:20:49 +02:00
|
|
|
DEBUGF 2, "SSH: Loading libraries\n"
|
2016-05-07 12:42:31 +02:00
|
|
|
stdcall dll.Load, @IMPORT
|
|
|
|
test eax, eax
|
2021-08-02 20:40:01 +02:00
|
|
|
jnz main.fail
|
2016-05-07 12:42:31 +02:00
|
|
|
|
2016-08-10 18:20:49 +02:00
|
|
|
DEBUGF 2, "SSH: Init PRNG\n"
|
2021-07-21 12:53:13 +02:00
|
|
|
call create_seed
|
2016-05-07 12:42:31 +02:00
|
|
|
call init_random
|
|
|
|
|
2016-08-10 18:20:49 +02:00
|
|
|
DEBUGF 2, "SSH: Init Console\n"
|
2016-05-07 12:42:31 +02:00
|
|
|
invoke con_start, 1
|
2021-08-04 10:41:16 +02:00
|
|
|
invoke con_init, 80, 25, 80, 250, title
|
2016-05-07 12:42:31 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
cmp byte[params], 0
|
|
|
|
jne main.connect
|
2016-05-07 12:42:31 +02:00
|
|
|
|
|
|
|
main:
|
|
|
|
invoke con_cls
|
|
|
|
; Welcome user
|
2021-08-02 20:40:01 +02:00
|
|
|
invoke con_write_asciiz, str1a
|
|
|
|
.prompt:
|
|
|
|
invoke con_write_asciiz, str1b
|
|
|
|
; Reset window title
|
|
|
|
invoke con_set_title, title
|
|
|
|
; Write prompt
|
2016-05-07 12:42:31 +02:00
|
|
|
invoke con_write_asciiz, str2
|
|
|
|
; read string
|
2021-08-02 20:40:01 +02:00
|
|
|
mov esi, params
|
|
|
|
invoke con_gets, esi, MAX_HOSTNAME_LENGTH
|
2016-05-07 12:42:31 +02:00
|
|
|
; check for exit
|
|
|
|
test eax, eax
|
2021-08-02 20:40:01 +02:00
|
|
|
jz .done
|
2016-05-07 12:42:31 +02:00
|
|
|
cmp byte[esi], 10
|
2021-08-02 20:40:01 +02:00
|
|
|
jz .done
|
2016-05-07 12:42:31 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
.connect:
|
|
|
|
stdcall sshlib_connect, ssh_con, params
|
|
|
|
cmp eax, 0
|
|
|
|
jg .prompt
|
|
|
|
jl .error
|
2021-07-20 22:14:53 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
.login:
|
|
|
|
mcall 68, 12, (MAX_USERNAME_LENGTH + MAX_PASSWORD_LENGTH)
|
2016-05-07 12:42:31 +02:00
|
|
|
test eax, eax
|
2021-08-02 20:40:01 +02:00
|
|
|
jz .done ; ERR_NOMEM
|
|
|
|
mov esi, eax
|
|
|
|
lea edi, [eax + MAX_USERNAME_LENGTH]
|
2016-08-10 18:20:49 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
; Get username
|
2021-07-20 22:14:53 +02:00
|
|
|
invoke con_write_asciiz, str12
|
2021-08-02 20:40:01 +02:00
|
|
|
invoke con_gets, esi, MAX_USERNAME_LENGTH
|
2021-07-20 22:14:53 +02:00
|
|
|
test eax, eax
|
2021-08-02 20:40:01 +02:00
|
|
|
;; jz .con_closed_must_clear
|
2021-07-20 22:14:53 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
; Get password
|
|
|
|
invoke con_write_asciiz, str13a
|
|
|
|
invoke con_gets, edi, MAX_PASSWORD_LENGTH
|
2021-07-20 22:14:53 +02:00
|
|
|
test eax, eax
|
2021-08-02 20:40:01 +02:00
|
|
|
;; jz .con_closed_must_clear
|
|
|
|
invoke con_write_asciiz, str13b
|
2021-07-20 22:14:53 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
; Authenticate
|
|
|
|
stdcall sshlib_userauth_password, ssh_con, esi, edi
|
|
|
|
; Clear and free username and password
|
|
|
|
.clear:
|
2021-07-20 22:14:53 +02:00
|
|
|
push eax
|
2021-08-02 20:40:01 +02:00
|
|
|
mov edx, edi
|
2021-07-20 22:14:53 +02:00
|
|
|
xor eax, eax
|
2021-08-02 20:40:01 +02:00
|
|
|
mov ecx, (MAX_USERNAME_LENGTH + MAX_PASSWORD_LENGTH)/4
|
|
|
|
rep stosd
|
2021-07-20 22:14:53 +02:00
|
|
|
mcall 68, 13, edx
|
|
|
|
pop eax
|
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
cmp eax, 0
|
|
|
|
jg .login ; Authentication failed
|
|
|
|
jl .error ; An error occured
|
2016-08-10 18:20:49 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
; Open a channel
|
|
|
|
stdcall sshlib_chan_open, ssh_con
|
|
|
|
cmp eax, 0
|
|
|
|
jg .prompt ; Authentication failed
|
|
|
|
jl .error ; An error occured
|
2016-05-07 12:42:31 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
; Start console input handler thread without deactivating the current window
|
|
|
|
; Get active window ID
|
2016-05-07 12:42:31 +02:00
|
|
|
mcall 18, 7
|
|
|
|
push eax
|
2021-08-02 20:40:01 +02:00
|
|
|
; Create thread
|
2024-03-06 21:22:01 +01:00
|
|
|
mcall 51, 1, con_in_thread, mem + 2048
|
2021-08-02 20:40:01 +02:00
|
|
|
; Activate window with given ID
|
2016-05-07 12:42:31 +02:00
|
|
|
pop ecx
|
|
|
|
mcall 18, 3
|
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
.loop:
|
|
|
|
invoke con_get_flags
|
|
|
|
test eax, 0x200 ; console window closed?
|
|
|
|
jnz .con_closed
|
2016-05-07 12:42:31 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
stdcall sshlib_msg_handler, ssh_con, 0
|
2016-08-10 18:20:49 +02:00
|
|
|
cmp eax, 0
|
2021-08-02 20:40:01 +02:00
|
|
|
jle .check_err
|
2016-05-07 12:42:31 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
cmp [ssh_con.rx_buffer.message_code], SSH_MSG_CHANNEL_DATA
|
2016-08-10 18:20:49 +02:00
|
|
|
jne .dump
|
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
mov eax, dword[ssh_con.rx_buffer.message_code+5]
|
2016-08-10 18:20:49 +02:00
|
|
|
bswap eax
|
2016-05-07 12:42:31 +02:00
|
|
|
DEBUGF 1, 'SSH: got %u bytes of data !\n', eax
|
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
lea esi, [ssh_con.rx_buffer.message_code+5+4]
|
|
|
|
lea edx, [esi+eax]
|
|
|
|
lea edi, [ssh_con.rx_buffer]
|
|
|
|
@@:
|
|
|
|
call get_byte_utf8
|
|
|
|
stosb
|
|
|
|
cmp esi, edx
|
|
|
|
jb @r
|
|
|
|
xor al, al
|
|
|
|
stosb
|
|
|
|
|
|
|
|
lea esi, [ssh_con.rx_buffer]
|
|
|
|
DEBUGF 3, 'SSH msg: %s\n', esi
|
|
|
|
|
2016-08-10 18:20:49 +02:00
|
|
|
invoke con_write_asciiz, esi
|
2021-08-02 20:40:01 +02:00
|
|
|
jmp .loop
|
2016-08-10 18:20:49 +02:00
|
|
|
|
|
|
|
.dump:
|
2021-08-02 20:40:01 +02:00
|
|
|
DEBUGF 3, "SSH: Unsupported message: "
|
|
|
|
lea esi, [ssh_con.rx_buffer.message_code]
|
2016-05-07 12:42:31 +02:00
|
|
|
mov ecx, eax
|
|
|
|
pusha
|
2021-08-02 20:40:01 +02:00
|
|
|
@@:
|
2016-05-07 12:42:31 +02:00
|
|
|
lodsb
|
2021-08-02 20:40:01 +02:00
|
|
|
DEBUGF 3, "%x ", eax:2
|
2016-05-07 12:42:31 +02:00
|
|
|
dec ecx
|
|
|
|
jnz @r
|
|
|
|
popa
|
2021-08-02 20:40:01 +02:00
|
|
|
DEBUGF 3, "\n"
|
|
|
|
jmp .loop
|
|
|
|
|
|
|
|
.check_err:
|
|
|
|
jz .err_conn_closed
|
|
|
|
cmp ebx, EWOULDBLOCK
|
|
|
|
je .loop
|
|
|
|
jmp .err_sock
|
|
|
|
|
|
|
|
.con_closed:
|
|
|
|
; Send close message on the active channel
|
|
|
|
stdcall sshlib_send_packet, ssh_con, ssh_msg_channel_close, ssh_msg_channel_close.length, 0
|
|
|
|
jmp .done
|
|
|
|
|
|
|
|
.error:
|
|
|
|
|
|
|
|
; TODO: proper cleanup after error
|
|
|
|
|
|
|
|
cmp eax, SSHLIB_ERR_NOMEM
|
|
|
|
je .done
|
|
|
|
cmp eax, SSHLIB_ERR_SOCKET
|
|
|
|
je .err_sock
|
|
|
|
cmp eax, SSHLIB_ERR_PROTOCOL
|
|
|
|
je .err_proto
|
|
|
|
cmp eax, SSHLIB_ERR_HOSTNAME
|
|
|
|
je .err_hostname
|
|
|
|
cmp eax, SSHLIB_ERR_HKEY_VERIFY_FAIL
|
|
|
|
je .err_hostkey_fail
|
|
|
|
cmp eax, SSHLIB_ERR_HKEY_SIGNATURE
|
|
|
|
je .err_hostkey_signature
|
|
|
|
cmp eax, SSHLIB_ERR_HKEY_PUBLIC_KEY
|
|
|
|
je .err_hostkey
|
2016-05-07 12:42:31 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
jmp .done
|
2016-08-10 18:20:49 +02:00
|
|
|
|
2021-07-20 22:14:53 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
.err_proto:
|
|
|
|
; lea eax, [ssh_con.rx_buffer]
|
|
|
|
; int3
|
2016-05-07 12:42:31 +02:00
|
|
|
invoke con_write_asciiz, str7
|
2021-08-02 20:40:01 +02:00
|
|
|
jmp .prompt
|
2016-05-07 12:42:31 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
.err_sock:
|
2016-05-07 12:42:31 +02:00
|
|
|
invoke con_write_asciiz, str6
|
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
mov eax, str14
|
|
|
|
cmp ebx, ETIMEDOUT
|
|
|
|
je .err_sock_detail
|
|
|
|
mov eax, str15
|
|
|
|
cmp ebx, ECONNREFUSED
|
|
|
|
je .err_sock_detail
|
|
|
|
mov eax, str16
|
|
|
|
cmp ebx, ECONNRESET
|
|
|
|
je .err_sock_detail
|
|
|
|
mov eax, str17
|
|
|
|
.err_sock_detail:
|
|
|
|
invoke con_write_asciiz, eax
|
|
|
|
jmp .prompt
|
2016-05-07 12:42:31 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
.err_hostname:
|
2016-05-07 12:42:31 +02:00
|
|
|
invoke con_write_asciiz, str10
|
2021-08-02 20:40:01 +02:00
|
|
|
jmp .prompt
|
2016-05-07 12:42:31 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
.err_conn_closed:
|
2016-05-07 12:42:31 +02:00
|
|
|
invoke con_write_asciiz, str11
|
2021-08-02 20:40:01 +02:00
|
|
|
jmp .prompt
|
|
|
|
|
|
|
|
.err_hostkey:
|
|
|
|
invoke con_write_asciiz, str19
|
|
|
|
jmp .prompt
|
|
|
|
|
|
|
|
.err_hostkey_signature:
|
|
|
|
invoke con_write_asciiz, str20
|
|
|
|
jmp .prompt
|
|
|
|
|
|
|
|
.err_hostkey_fail:
|
|
|
|
invoke con_write_asciiz, str21
|
|
|
|
jmp .prompt
|
2016-05-07 12:42:31 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
.done:
|
2016-05-07 12:42:31 +02:00
|
|
|
invoke con_exit, 1
|
2021-08-02 20:40:01 +02:00
|
|
|
.exit:
|
2016-08-10 18:20:49 +02:00
|
|
|
DEBUGF 3, "SSH: Exiting\n"
|
2021-08-02 20:40:01 +02:00
|
|
|
mcall close, [ssh_con.socketnum]
|
|
|
|
.fail:
|
2016-05-07 12:42:31 +02:00
|
|
|
mcall -1
|
|
|
|
|
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
proc sshlib_callback_connecting, con_ptr, connstring_sz
|
2016-05-07 12:42:31 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
invoke con_write_asciiz, str3
|
|
|
|
mov eax, [con_ptr]
|
|
|
|
lea eax, [eax+sshlib_connection.hostname_sz]
|
|
|
|
invoke con_write_asciiz, eax
|
|
|
|
invoke con_write_asciiz, str8
|
|
|
|
invoke con_write_asciiz, [connstring_sz]
|
|
|
|
invoke con_write_asciiz, str9
|
2016-05-07 12:42:31 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
ret
|
|
|
|
endp
|
2021-07-20 22:14:53 +02:00
|
|
|
|
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
proc sshlib_callback_hostkey_problem, con_ptr, problem_type, hostkey_sz
|
2021-07-20 22:14:53 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
cmp [problem_type], SSHLIB_HOSTKEY_PROBLEM_UNKNOWN
|
|
|
|
je .unknown
|
|
|
|
cmp [problem_type], SSHLIB_HOSTKEY_PROBLEM_MISMATCH
|
|
|
|
je .mismatch
|
2021-07-20 22:14:53 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
mov eax, -1
|
2021-07-20 22:14:53 +02:00
|
|
|
ret
|
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
.unknown:
|
|
|
|
invoke con_write_asciiz, str22
|
|
|
|
jmp .ask
|
|
|
|
|
|
|
|
.mismatch:
|
|
|
|
invoke con_write_asciiz, str23
|
|
|
|
; jmp .ask
|
|
|
|
.ask:
|
2021-08-04 10:41:16 +02:00
|
|
|
invoke con_write_asciiz, str24a
|
|
|
|
invoke con_write_asciiz, [hostkey_sz]
|
|
|
|
invoke con_write_asciiz, str24b
|
2021-08-02 20:40:01 +02:00
|
|
|
.getansw:
|
|
|
|
invoke con_getch2
|
|
|
|
or al, 0x20 ; convert to lowercase
|
|
|
|
cmp al, 'a'
|
|
|
|
je .accept
|
|
|
|
cmp al, 'c'
|
|
|
|
je .once
|
|
|
|
cmp al, 'x'
|
|
|
|
je .refuse
|
|
|
|
jmp .getansw
|
|
|
|
|
|
|
|
.accept:
|
|
|
|
mov eax, SSHLIB_HOSTKEY_ACCEPT
|
|
|
|
ret
|
|
|
|
.once:
|
|
|
|
mov eax, SSHLIB_HOSTKEY_ONCE
|
|
|
|
ret
|
|
|
|
.refuse:
|
|
|
|
mov eax, SSHLIB_HOSTKEY_REFUSE
|
2021-07-20 22:14:53 +02:00
|
|
|
ret
|
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
endp
|
2021-07-20 22:14:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
align 16
|
|
|
|
con_in_thread:
|
|
|
|
|
|
|
|
.loop:
|
|
|
|
; TODO: check if channel is still open somehow
|
|
|
|
|
2021-08-11 22:59:10 +02:00
|
|
|
invoke con_get_input, keyb_input, MAX_INPUT_LENGTH
|
2021-08-02 20:40:01 +02:00
|
|
|
test eax, eax
|
|
|
|
jz .no_input
|
|
|
|
|
2021-08-11 22:59:10 +02:00
|
|
|
mov ecx, eax
|
|
|
|
mov esi, keyb_input
|
|
|
|
mov edi, ssh_msg_channel_data.data
|
|
|
|
call recode_to_utf8
|
|
|
|
|
|
|
|
lea eax, [edi - ssh_msg_channel_data.data]
|
|
|
|
lea ecx, [edi - ssh_msg_channel_data]
|
2021-08-02 20:40:01 +02:00
|
|
|
bswap eax
|
|
|
|
mov [ssh_msg_channel_data.len], eax
|
|
|
|
stdcall sshlib_send_packet, ssh_con, ssh_msg_channel_data, ecx, 0
|
|
|
|
cmp eax, 0
|
|
|
|
jle .exit
|
|
|
|
|
|
|
|
.no_input:
|
|
|
|
invoke con_get_flags
|
|
|
|
test eax, 0x200 ; con window closed?
|
|
|
|
jz .loop
|
|
|
|
|
|
|
|
.exit:
|
|
|
|
mcall -1
|
|
|
|
|
2021-07-20 22:14:53 +02:00
|
|
|
|
2016-05-07 12:42:31 +02:00
|
|
|
; data
|
2021-08-02 20:40:01 +02:00
|
|
|
title db 'Secure Shell',0
|
|
|
|
str1a db 'SSHv2 client for KolibriOS',10,0
|
|
|
|
str1b db 10,'Please enter URL of SSH server (hostname:port)',10,0
|
|
|
|
str2 db '> ',0
|
|
|
|
str3 db 'Connecting to ',0
|
|
|
|
str4 db 10,0
|
|
|
|
str6 db 10, 27, '[2J',27,'[mA network error has occured.',10,0
|
|
|
|
str7 db 10, 27, '[2J',27,'[mAn SSH protocol error has occured.',10,0
|
|
|
|
str8 db ' (',0
|
|
|
|
str9 db ')',10,0
|
|
|
|
str10 db 'Host does not exist.',10,10,0
|
|
|
|
str11 db 10, 27, '[2J',27,'[mThe remote host closed the connection.',10,0
|
|
|
|
str12 db 'Login as: ',0
|
|
|
|
str13a db 'Password: ', 27, '[?25l', 27, '[30;40m', 0
|
|
|
|
str13b db 10, 27, '[?25h', 27, '[0m', 27, '[2J', 0
|
|
|
|
str14 db 'The connection timed out',10,0
|
|
|
|
str15 db 'The connection was refused',10,0
|
|
|
|
str16 db 'The connection was reset',10,0
|
|
|
|
str17 db 'No details available',10,0
|
|
|
|
;str18 db 'User authentication failed',10,0;;;;
|
|
|
|
str19 db "The remote host's public key is invalid.", 10, 0
|
|
|
|
str20 db "The remote host's signature is invalid.", 10, 0
|
|
|
|
str21 db "The remote host failed to verify it's own public key.", 10, 0
|
|
|
|
str22 db "The host key for the server was not found in the cache.", 10
|
|
|
|
db "There is no guarantee to the servers identity !",10, 0
|
|
|
|
|
|
|
|
str23 db "The host key provided by the host does not match the cached one.", 10
|
|
|
|
db "This may indicate that the remote server has been compromised!", 10, 0
|
|
|
|
|
2021-08-04 10:41:16 +02:00
|
|
|
str24a db 10, "The remote host key is: ", 10, 0
|
|
|
|
str24b db 10, 10, "If you trust this host, press A to accept and store the (new) key.", 10
|
2021-08-02 20:40:01 +02:00
|
|
|
db "Press C to connect to the host but don't store the (new) key.", 10
|
|
|
|
db "Press X to abort.", 10, 0
|
|
|
|
|
2016-05-07 12:42:31 +02:00
|
|
|
|
|
|
|
ssh_ident_ha:
|
2021-08-02 20:40:01 +02:00
|
|
|
dd_n (ssh_msg_ident.length-2)
|
|
|
|
ssh_msg_ident:
|
2024-03-10 19:38:46 +01:00
|
|
|
db "SSH-2.0-KolibriOS_SSH_0.12",13,10
|
2021-08-02 20:40:01 +02:00
|
|
|
.length = $ - ssh_msg_ident
|
|
|
|
|
2016-05-07 12:42:31 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
ssh_msg_kex:
|
2016-05-07 12:42:31 +02:00
|
|
|
db SSH_MSG_KEXINIT
|
|
|
|
.cookie:
|
|
|
|
rd 4
|
|
|
|
.kex_algorithms:
|
2024-03-09 21:05:21 +01:00
|
|
|
str "diffie-hellman-group-exchange-sha256"
|
2016-05-07 12:42:31 +02:00
|
|
|
.server_host_key_algorithms:
|
2024-03-09 21:05:21 +01:00
|
|
|
str "rsa-sha2-512,rsa-sha2-256" ;ssh-rsa,ssh-dss
|
2016-05-07 12:42:31 +02:00
|
|
|
.encryption_algorithms_client_to_server:
|
2024-03-10 19:38:46 +01:00
|
|
|
str "chacha20-poly1305@openssh.com,aes256-ctr,aes256-cbc" ;aes192-ctr,aes192-cbc,aes128-ctr,aes128-cbc ?
|
2016-05-07 12:42:31 +02:00
|
|
|
.encryption_algorithms_server_to_client:
|
2024-03-10 19:38:46 +01:00
|
|
|
str "chacha20-poly1305@openssh.com,aes256-ctr,aes256-cbc" ;aes192-ctr,aes192-cbc,aes128-ctr,aes128-cbc ?
|
2016-05-07 12:42:31 +02:00
|
|
|
.mac_algorithms_client_to_server:
|
2024-03-10 19:38:46 +01:00
|
|
|
str "hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha2-256,hmac-sha2-512"
|
2016-05-07 12:42:31 +02:00
|
|
|
.mac_algorithms_server_to_client:
|
2024-03-10 19:38:46 +01:00
|
|
|
str "hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha2-256,hmac-sha2-512"
|
2016-05-07 12:42:31 +02:00
|
|
|
.compression_algorithms_client_to_server:
|
2024-03-09 21:05:21 +01:00
|
|
|
str "none" ;zlib ?
|
2016-05-07 12:42:31 +02:00
|
|
|
.compression_algorithms_server_to_client:
|
2024-03-09 21:05:21 +01:00
|
|
|
str "none" ;zlib ?
|
2016-05-07 12:42:31 +02:00
|
|
|
.languages_client_to_server:
|
2021-08-02 20:40:01 +02:00
|
|
|
str ""
|
2016-05-07 12:42:31 +02:00
|
|
|
.languages_server_to_client:
|
2021-08-02 20:40:01 +02:00
|
|
|
str ""
|
2016-05-07 12:42:31 +02:00
|
|
|
.first_kex_packet_follows:
|
|
|
|
db 0
|
|
|
|
.reserved:
|
|
|
|
dd_n 0
|
2021-08-02 20:40:01 +02:00
|
|
|
.length = $ - ssh_msg_kex
|
2016-05-07 12:42:31 +02:00
|
|
|
|
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
ssh_msg_gex_req:
|
2016-05-07 12:42:31 +02:00
|
|
|
db SSH_MSG_KEX_DH_GEX_REQUEST
|
2021-07-20 22:14:53 +02:00
|
|
|
dd_n 4096/4 ; DH GEX min
|
|
|
|
dd_n 4096/2 ; DH GEX number of bits
|
|
|
|
dd_n 4096 ; DH GEX Max
|
2021-08-02 20:40:01 +02:00
|
|
|
.length = $ - ssh_msg_gex_req
|
2016-05-07 12:42:31 +02:00
|
|
|
|
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
ssh_msg_new_keys:
|
2016-05-07 12:42:31 +02:00
|
|
|
db SSH_MSG_NEWKEYS
|
2021-08-02 20:40:01 +02:00
|
|
|
.length = $ - ssh_msg_new_keys
|
2016-05-07 12:42:31 +02:00
|
|
|
|
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
ssh_msg_request_service:
|
2016-08-10 18:20:49 +02:00
|
|
|
db SSH_MSG_SERVICE_REQUEST
|
2021-08-02 20:40:01 +02:00
|
|
|
str "ssh-userauth" ; Service name
|
|
|
|
.length = $ - ssh_msg_request_service
|
|
|
|
|
|
|
|
|
|
|
|
ssh_msg_channel_open:
|
2016-08-10 18:20:49 +02:00
|
|
|
db SSH_MSG_CHANNEL_OPEN
|
2021-08-02 20:40:01 +02:00
|
|
|
str "session"
|
|
|
|
dd_n 0 ; Sender channel
|
|
|
|
dd_n BUFFERSIZE ; Initial window size
|
|
|
|
dd_n PACKETSIZE ; maximum packet size
|
|
|
|
.length = $ - ssh_msg_channel_open
|
|
|
|
|
|
|
|
|
|
|
|
ssh_msg_channel_close:
|
|
|
|
db SSH_MSG_CHANNEL_CLOSE
|
2016-08-10 18:20:49 +02:00
|
|
|
dd_n 0 ; Sender channel
|
2021-08-02 20:40:01 +02:00
|
|
|
.length = $ - ssh_msg_channel_close
|
2016-08-10 18:20:49 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
|
|
|
|
ssh_msg_channel_request:
|
2016-08-10 18:20:49 +02:00
|
|
|
db SSH_MSG_CHANNEL_REQUEST
|
|
|
|
dd_n 0 ; Recipient channel
|
2021-08-02 20:40:01 +02:00
|
|
|
str "pty-req"
|
2016-08-10 18:20:49 +02:00
|
|
|
db 1 ; Bool: want reply
|
2021-08-02 20:40:01 +02:00
|
|
|
str "xterm"
|
2016-08-10 18:20:49 +02:00
|
|
|
dd_n 80 ; terminal width (rows)
|
|
|
|
dd_n 25 ; terminal height (rows)
|
2021-08-02 20:40:01 +02:00
|
|
|
dd_n 80*8 ; terminal width (pixels)
|
|
|
|
dd_n 25*16 ; terminal height (pixels)
|
2016-08-10 18:20:49 +02:00
|
|
|
|
|
|
|
dd_n 0 ; list of supported opcodes
|
2021-08-02 20:40:01 +02:00
|
|
|
.length = $ - ssh_msg_channel_request
|
|
|
|
|
2016-08-10 18:20:49 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
ssh_msg_shell_request:
|
2016-08-10 18:20:49 +02:00
|
|
|
db SSH_MSG_CHANNEL_REQUEST
|
|
|
|
dd_n 0 ; Recipient channel
|
2021-08-02 20:40:01 +02:00
|
|
|
str "shell"
|
2016-08-10 18:20:49 +02:00
|
|
|
db 1 ; Bool: want reply
|
2021-08-02 20:40:01 +02:00
|
|
|
.length = $ - ssh_msg_shell_request
|
|
|
|
|
2016-08-10 18:20:49 +02:00
|
|
|
|
2021-08-02 20:40:01 +02:00
|
|
|
ssh_msg_channel_data:
|
2016-08-10 18:20:49 +02:00
|
|
|
db SSH_MSG_CHANNEL_DATA
|
|
|
|
dd_n 0 ; Sender channel
|
2021-08-02 20:40:01 +02:00
|
|
|
.len dd ?
|
2021-08-11 22:59:10 +02:00
|
|
|
.data rb 4*MAX_INPUT_LENGTH + 1
|
2021-08-02 20:40:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
ssh_msg_channel_window_adjust:
|
|
|
|
db SSH_MSG_CHANNEL_WINDOW_ADJUST
|
|
|
|
dd_n 0 ; Sender channel
|
|
|
|
.wnd dd ?
|
|
|
|
.length = $ - ssh_msg_channel_window_adjust
|
2016-08-10 18:20:49 +02:00
|
|
|
|
2016-05-07 12:42:31 +02:00
|
|
|
|
2016-08-10 18:20:49 +02:00
|
|
|
include_debug_strings
|
2016-05-07 12:42:31 +02:00
|
|
|
|
|
|
|
align 4
|
|
|
|
@IMPORT:
|
|
|
|
|
|
|
|
library network, 'network.obj', \
|
2016-08-10 18:20:49 +02:00
|
|
|
console, 'console.obj', \
|
2021-08-04 10:41:16 +02:00
|
|
|
libcrash, 'libcrash.obj', \
|
|
|
|
libini, 'libini.obj'
|
2016-05-07 12:42:31 +02:00
|
|
|
|
|
|
|
import network, \
|
|
|
|
getaddrinfo, 'getaddrinfo', \
|
|
|
|
freeaddrinfo, 'freeaddrinfo', \
|
|
|
|
inet_ntoa, 'inet_ntoa'
|
|
|
|
|
|
|
|
import console, \
|
|
|
|
con_start, 'START', \
|
|
|
|
con_init, 'con_init', \
|
|
|
|
con_write_asciiz, 'con_write_asciiz', \
|
|
|
|
con_exit, 'con_exit', \
|
|
|
|
con_gets, 'con_gets', \
|
|
|
|
con_cls, 'con_cls', \
|
|
|
|
con_getch2, 'con_getch2', \
|
2021-08-02 20:40:01 +02:00
|
|
|
con_get_flags, 'con_get_flags', \
|
|
|
|
con_set_title, 'con_set_title', \
|
|
|
|
con_get_input, 'con_get_input'
|
2016-05-07 12:42:31 +02:00
|
|
|
|
2016-08-10 18:20:49 +02:00
|
|
|
import libcrash, \
|
2024-03-09 21:05:21 +01:00
|
|
|
crash.init, "lib_init", \
|
|
|
|
crash.hash, "crash_hash", \
|
|
|
|
crash.mac, "crash_mac", \
|
|
|
|
crash.crypt, "crash_crypt", \
|
|
|
|
crash.hash_oneshot, "crash_hash_oneshot", \
|
|
|
|
crash.mac_oneshot, "crash_mac_oneshot", \
|
|
|
|
crash.crypt_oneshot, "crash_crypt_oneshot", \
|
|
|
|
\
|
|
|
|
crc32.init, "crc32_init", \
|
|
|
|
crc32.update, "crc32_update", \
|
|
|
|
crc32.finish, "crc32_finish", \
|
|
|
|
crc32.oneshot, "crc32_oneshot", \
|
|
|
|
md5.init, "md5_init", \
|
|
|
|
md5.update, "md5_update", \
|
|
|
|
md5.finish, "md5_finish", \
|
|
|
|
md5.oneshot, "md5_oneshot", \
|
|
|
|
sha1.init, "sha1_init", \
|
|
|
|
sha1.update, "sha1_update", \
|
|
|
|
sha1.finish, "sha1_finish", \
|
|
|
|
sha1.oneshot, "sha1_oneshot", \
|
|
|
|
sha2_224.init, "sha2_224_init", \
|
|
|
|
sha2_224.update, "sha2_224_update", \
|
|
|
|
sha2_224.finish, "sha2_224_finish", \
|
|
|
|
sha2_224.oneshot, "sha2_224_oneshot", \
|
|
|
|
sha2_256.init, "sha2_256_init", \
|
|
|
|
sha2_256.update, "sha2_256_update", \
|
|
|
|
sha2_256.finish, "sha2_256_finish", \
|
|
|
|
sha2_256.oneshot, "sha2_256_oneshot", \
|
|
|
|
sha2_384.init, "sha2_384_init", \
|
|
|
|
sha2_384.update, "sha2_384_update", \
|
|
|
|
sha2_384.finish, "sha2_384_finish", \
|
|
|
|
sha2_384.oneshot, "sha2_384_oneshot", \
|
|
|
|
sha2_512.init, "sha2_512_init", \
|
|
|
|
sha2_512.update, "sha2_512_update", \
|
|
|
|
sha2_512.finish, "sha2_512_finish", \
|
|
|
|
sha2_512.oneshot, "sha2_512_oneshot", \
|
|
|
|
sha3_224.init, "sha3_224_init", \
|
|
|
|
sha3_224.update, "sha3_224_update", \
|
|
|
|
sha3_224.finish, "sha3_224_finish", \
|
|
|
|
sha3_224.oneshot, "sha3_224_oneshot", \
|
|
|
|
sha3_256.init, "sha3_256_init", \
|
|
|
|
sha3_256.update, "sha3_256_update", \
|
|
|
|
sha3_256.finish, "sha3_256_finish", \
|
|
|
|
sha3_256.oneshot, "sha3_256_oneshot", \
|
|
|
|
sha3_384.init, "sha3_384_init", \
|
|
|
|
sha3_384.update, "sha3_384_update", \
|
|
|
|
sha3_384.finish, "sha3_384_finish", \
|
|
|
|
sha3_384.oneshot, "sha3_384_oneshot", \
|
|
|
|
sha3_512.init, "sha3_512_init", \
|
|
|
|
sha3_512.update, "sha3_512_update", \
|
|
|
|
sha3_512.finish, "sha3_512_finish", \
|
|
|
|
sha3_512.oneshot, "sha3_512_oneshot", \
|
|
|
|
\
|
|
|
|
poly1305.init, "poly1305_init", \
|
|
|
|
poly1305.update, "poly1305_update", \
|
|
|
|
poly1305.finish, "poly1305_finish", \
|
|
|
|
poly1305.oneshot, "poly1305_oneshot", \
|
|
|
|
hmac_sha2_256.init, "hmac_sha2_256_init", \
|
|
|
|
hmac_sha2_256.update, "hmac_sha2_256_update", \
|
|
|
|
hmac_sha2_256.finish, "hmac_sha2_256_finish", \
|
|
|
|
hmac_sha2_256.oneshot, "hmac_sha2_256_oneshot", \
|
|
|
|
hmac_sha2_512.init, "hmac_sha2_512_init", \
|
|
|
|
hmac_sha2_512.update, "hmac_sha2_512_update", \
|
|
|
|
hmac_sha2_512.finish, "hmac_sha2_512_finish", \
|
|
|
|
hmac_sha2_512.oneshot, "hmac_sha2_512_oneshot", \
|
|
|
|
\
|
|
|
|
chacha20.init, "chacha20_init", \
|
|
|
|
chacha20.update, "chacha20_update", \
|
|
|
|
chacha20.finish, "chacha20_finish", \
|
|
|
|
chacha20.oneshot, "chacha20_oneshot", \
|
2024-03-06 21:22:01 +01:00
|
|
|
aes256ctr.init, "aes256ctr_init", \
|
|
|
|
aes256ctr.update, "aes256ctr_update", \
|
|
|
|
aes256ctr.finish, "aes256ctr_finish", \
|
|
|
|
aes256ctr.oneshot, "aes256ctr_oneshot", \
|
2024-03-09 21:05:21 +01:00
|
|
|
aes256cbc.init, "aes256cbc_init", \
|
|
|
|
aes256cbc.update, "aes256cbc_update", \
|
|
|
|
aes256cbc.finish, "aes256cbc_finish", \
|
|
|
|
aes256cbc.oneshot, "aes256cbc_oneshot"
|
2016-05-07 12:42:31 +02:00
|
|
|
|
2021-08-04 10:41:16 +02:00
|
|
|
import libini, \
|
|
|
|
ini_get_str, 'ini_get_str', \
|
|
|
|
ini_set_str, 'ini_set_str'
|
|
|
|
|
2016-05-07 12:42:31 +02:00
|
|
|
IncludeIGlobals
|
|
|
|
|
|
|
|
i_end:
|
|
|
|
|
|
|
|
IncludeUGlobals
|
|
|
|
|
2024-03-06 21:22:01 +01:00
|
|
|
align 16
|
2021-08-02 20:40:01 +02:00
|
|
|
params rb MAX_HOSTNAME_LENGTH
|
2016-05-07 12:42:31 +02:00
|
|
|
|
2024-03-06 21:22:01 +01:00
|
|
|
align 16
|
2021-08-02 20:40:01 +02:00
|
|
|
ssh_con sshlib_connection
|
2024-03-06 21:22:01 +01:00
|
|
|
|
|
|
|
align 16
|
2021-08-02 20:40:01 +02:00
|
|
|
ssh_chan sshlib_channel
|
2016-05-07 12:42:31 +02:00
|
|
|
|
2021-08-11 22:59:10 +02:00
|
|
|
keyb_input rb MAX_INPUT_LENGTH
|
|
|
|
|
2016-05-07 12:42:31 +02:00
|
|
|
mem:
|