-
Notifications
You must be signed in to change notification settings - Fork 1
/
libsshid.asm
101 lines (78 loc) · 1.72 KB
/
libsshid.asm
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
; linuxthor
;
; simple libssh example for checking server identity
;
; exits with error if server identity not verified
; via ~/.ssh/known_hosts
;
; assemble with:
; nasm -f elf64 -o libsshid.o libsshid.asm
; gcc libsshid.o -no-pie -o libsshid -lssh
;
BITS 64
extern ssh_options_set, ssh_new, ssh_connect, ssh_disconnect
extern ssh_free, ssh_get_server_publickey, ssh_get_publickey_hash
extern ssh_key_free, ssh_is_server_known
%define SSH_OPTIONS_HOST 0
%define SSH_OK 0
%define SSH_SERVER_KNOWN_OK 1
%define SSH_SERVER_KNOWN_CHANGED 2
%define SSH_SERVER_FOUND_OTHER 3
%define SSH_SERVER_FILE_NOT_FOUND 4
%define SSH_SERVER_NOT_KNOWN 0
%define SSH_SERVER_ERROR -1
global main
main:
push rbp
mov rbp, rsp
xor eax, eax
call ssh_new
cmp rax, 0
je error
mov [ssh_sesh], rax
mov rdi, [ssh_sesh]
mov rsi, SSH_OPTIONS_HOST
mov rdx, con
xor rax, rax
call ssh_options_set
cmp rax, 0
jne error
mov rdi, [ssh_sesh]
xor rax, rax
call ssh_connect
cmp rax, SSH_OK
jne error
mov rdi, [ssh_sesh]
mov rsi, ssh_key
xor rax, rax
call ssh_get_server_publickey
cmp rax, 0
jl error
mov rdi, [ssh_key]
xor rax, rax
call ssh_key_free
cmp rax, 0
jl error
mov rdi, [ssh_sesh]
xor rax, rax
call ssh_is_server_known
cmp rax, SSH_SERVER_KNOWN_OK
jne error
mov rdi, [ssh_sesh]
xor rax, rax
call ssh_disconnect
mov rdi, [ssh_sesh]
xor rax, rax
call ssh_free
xor rax, rax
pop rbp
ret
error:
mov rax, 1
pop rbp
ret
section .data
con db '192.168.0.1',0
section .bss
ssh_sesh resq 1
ssh_key resq 1