| ︙ | | | ︙ | |
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#define SSH_SMSG_STDERR_DATA 18
#define SSH_SMSG_SUCCESS 14
#define SSH_SMSG_FAILURE 15
#define SSH_SMSG_EXITSTATUS 20
#define SSH_MSG_IGNORE 32
#define SSH_CMSG_EXIT_CONFIRMATION 33
#define SSH_MSG_DEBUG 36
/* Coroutine mechanics for the sillier bits of the code */
#define crBegin1 static int crLine = 0;
#define crBegin2 switch(crLine) { case 0:;
#define crBegin crBegin1; crBegin2;
#define crFinish(z) } crLine = 0; return (z)
#define crFinishV } crLine = 0; return
|
>
>
>
>
>
|
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#define SSH_SMSG_STDERR_DATA 18
#define SSH_SMSG_SUCCESS 14
#define SSH_SMSG_FAILURE 15
#define SSH_SMSG_EXITSTATUS 20
#define SSH_MSG_IGNORE 32
#define SSH_CMSG_EXIT_CONFIRMATION 33
#define SSH_MSG_DEBUG 36
#define SSH_CMSG_AUTH_TIS 39
#define SSH_SMSG_AUTH_TIS_CHALLENGE 40
#define SSH_CMSG_AUTH_TIS_RESPONSE 41
#define SSH_AUTH_TIS 5
/* Coroutine mechanics for the sillier bits of the code */
#define crBegin1 static int crLine = 0;
#define crBegin2 switch(crLine) { case 0:;
#define crBegin crBegin1; crBegin2;
#define crFinish(z) } crLine = 0; return (z)
#define crFinishV } crLine = 0; return
|
| ︙ | | | ︙ | |
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
static void ssh_protocol(unsigned char *in, int inlen, int ispkt) {
int i, j, len;
unsigned char session_id[16];
unsigned char *rsabuf, *keystr1, *keystr2;
unsigned char cookie[8];
struct RSAKey servkey, hostkey;
struct MD5Context md5c;
unsigned long supported_ciphers_mask;
int cipher_type;
extern struct ssh_cipher ssh_3des;
extern struct ssh_cipher ssh_des;
extern struct ssh_cipher ssh_blowfish;
crBegin;
|
|
|
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
static void ssh_protocol(unsigned char *in, int inlen, int ispkt) {
int i, j, len;
unsigned char session_id[16];
unsigned char *rsabuf, *keystr1, *keystr2;
unsigned char cookie[8];
struct RSAKey servkey, hostkey;
struct MD5Context md5c;
static unsigned long supported_ciphers_mask, supported_auths_mask;
int cipher_type;
extern struct ssh_cipher ssh_3des;
extern struct ssh_cipher ssh_des;
extern struct ssh_cipher ssh_blowfish;
crBegin;
|
| ︙ | | | ︙ | |
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
|
MD5Init(&md5c);
i = makekey(pktin.body+8, &servkey, &keystr1);
j = makekey(pktin.body+8+i, &hostkey, &keystr2);
supported_ciphers_mask = (pktin.body[12+i+j] << 24) |
(pktin.body[13+i+j] << 16) |
(pktin.body[14+i+j] << 8) |
(pktin.body[15+i+j]);
MD5Update(&md5c, keystr2, hostkey.bytes);
MD5Update(&md5c, keystr1, servkey.bytes);
MD5Update(&md5c, pktin.body, 8);
MD5Final(session_id, &md5c);
|
|
|
|
|
>
>
>
>
>
|
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
|
MD5Init(&md5c);
i = makekey(pktin.body+8, &servkey, &keystr1);
j = makekey(pktin.body+8+i, &hostkey, &keystr2);
supported_ciphers_mask = ((pktin.body[12+i+j] << 24) |
(pktin.body[13+i+j] << 16) |
(pktin.body[14+i+j] << 8) |
(pktin.body[15+i+j]));
supported_auths_mask = ((pktin.body[16+i+j] << 24) |
(pktin.body[17+i+j] << 16) |
(pktin.body[18+i+j] << 8) |
(pktin.body[19+i+j]));
MD5Update(&md5c, keystr2, hostkey.bytes);
MD5Update(&md5c, keystr1, servkey.bytes);
MD5Update(&md5c, pktin.body, 8);
MD5Final(session_id, &md5c);
|
| ︙ | | | ︙ | |
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
|
do { crReturnV; } while (!ispkt);
while (pktin.type == SSH_SMSG_FAILURE) {
static char password[100];
static int pos;
static char c;
c_write("password: ", 10);
pos = 0;
while (pos >= 0) {
do { crReturnV; } while (ispkt);
while (inlen--) switch (c = *in++) {
case 10: case 13:
password[pos] = 0;
pos = -1;
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
|
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
|
do { crReturnV; } while (!ispkt);
while (pktin.type == SSH_SMSG_FAILURE) {
static char password[100];
static int pos;
static char c;
static int pwpkt_type;
/*
* Show password prompt, having first obtained it via a TIS
* exchange if we're doing TIS authentication.
*/
pwpkt_type = SSH_CMSG_AUTH_PASSWORD;
if (pktin.type == SSH_SMSG_FAILURE &&
cfg.try_tis_auth &&
(supported_auths_mask & (1<<SSH_AUTH_TIS))) {
pwpkt_type = SSH_CMSG_AUTH_TIS_RESPONSE;
s_wrpkt_start(SSH_CMSG_AUTH_TIS, 0);
s_wrpkt();
do { crReturnV; } while (!ispkt);
if (pktin.type != SSH_SMSG_AUTH_TIS_CHALLENGE) {
c_write("TIS authentication refused.\r\n", 29);
} else {
int challengelen = ((pktin.body[0] << 24) |
(pktin.body[1] << 16) |
(pktin.body[2] << 8) |
(pktin.body[3]));
c_write(pktin.body+4, challengelen);
}
}
if (pwpkt_type == SSH_CMSG_AUTH_PASSWORD)
c_write("password: ", 10);
pos = 0;
while (pos >= 0) {
do { crReturnV; } while (ispkt);
while (inlen--) switch (c = *in++) {
case 10: case 13:
password[pos] = 0;
pos = -1;
|
| ︙ | | | ︙ | |
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
|
default:
if (c >= ' ' && c <= '~' && pos < 40)
password[pos++] = c;
break;
}
}
c_write("\r\n", 2);
s_wrpkt_start(SSH_CMSG_AUTH_PASSWORD, 4+strlen(password));
pktout.body[0] = pktout.body[1] = pktout.body[2] = 0;
pktout.body[3] = strlen(password);
memcpy(pktout.body+4, password, strlen(password));
s_wrpkt();
memset(password, 0, strlen(password));
do { crReturnV; } while (!ispkt);
if (pktin.type == 15) {
|
|
|
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
|
default:
if (c >= ' ' && c <= '~' && pos < 40)
password[pos++] = c;
break;
}
}
c_write("\r\n", 2);
s_wrpkt_start(pwpkt_type, 4+strlen(password));
pktout.body[0] = pktout.body[1] = pktout.body[2] = 0;
pktout.body[3] = strlen(password);
memcpy(pktout.body+4, password, strlen(password));
s_wrpkt();
memset(password, 0, strlen(password));
do { crReturnV; } while (!ispkt);
if (pktin.type == 15) {
|
| ︙ | | | ︙ | |
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
|
pktout.body[i++] = (cols >> 16) & 0xFF;
pktout.body[i++] = (cols >> 8) & 0xFF;
pktout.body[i++] = cols & 0xFF;
memset(pktout.body+i, 0, 9); /* 0 pixwidth, 0 pixheight, 0.b endofopt */
s_wrpkt();
ssh_state = SSH_STATE_INTERMED;
do { crReturnV; } while (!ispkt);
if (pktin.type != SSH_MSG_SUCCESS && pktin.type != SSH_MSG_FAILURE) {
fatalbox("Protocol confusion");
} else if (pktin.type == SSH_MSG_FAILURE) {
c_write("Server refused to allocate pty\r\n", 32);
}
}
s_wrpkt_start(SSH_CMSG_EXEC_SHELL, 0);
s_wrpkt();
|
|
|
|
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
|
pktout.body[i++] = (cols >> 16) & 0xFF;
pktout.body[i++] = (cols >> 8) & 0xFF;
pktout.body[i++] = cols & 0xFF;
memset(pktout.body+i, 0, 9); /* 0 pixwidth, 0 pixheight, 0.b endofopt */
s_wrpkt();
ssh_state = SSH_STATE_INTERMED;
do { crReturnV; } while (!ispkt);
if (pktin.type != SSH_SMSG_SUCCESS && pktin.type != SSH_SMSG_FAILURE) {
fatalbox("Protocol confusion");
} else if (pktin.type == SSH_SMSG_FAILURE) {
c_write("Server refused to allocate pty\r\n", 32);
}
}
s_wrpkt_start(SSH_CMSG_EXEC_SHELL, 0);
s_wrpkt();
|
| ︙ | | | ︙ | |
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
|
pktin.type == SSH_SMSG_STDERR_DATA) {
long len = 0;
for (i = 0; i < 4; i++)
len = (len << 8) + pktin.body[i];
c_write(pktin.body+4, len);
} else if (pktin.type == SSH_MSG_DISCONNECT) {
ssh_state = SSH_STATE_CLOSED;
} else if (pktin.type == SSH_MSG_SUCCESS) {
/* may be from EXEC_SHELL on some servers */
} else if (pktin.type == SSH_MSG_FAILURE) {
/* may be from EXEC_SHELL on some servers
* if no pty is available or in other odd cases. Ignore */
} else if (pktin.type == SSH_SMSG_EXITSTATUS) {
s_wrpkt_start(SSH_CMSG_EXIT_CONFIRMATION, 0);
s_wrpkt();
} else {
fatalbox("Strange packet received: type %d", pktin.type);
|
|
|
|
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
|
pktin.type == SSH_SMSG_STDERR_DATA) {
long len = 0;
for (i = 0; i < 4; i++)
len = (len << 8) + pktin.body[i];
c_write(pktin.body+4, len);
} else if (pktin.type == SSH_MSG_DISCONNECT) {
ssh_state = SSH_STATE_CLOSED;
} else if (pktin.type == SSH_SMSG_SUCCESS) {
/* may be from EXEC_SHELL on some servers */
} else if (pktin.type == SSH_SMSG_FAILURE) {
/* may be from EXEC_SHELL on some servers
* if no pty is available or in other odd cases. Ignore */
} else if (pktin.type == SSH_SMSG_EXITSTATUS) {
s_wrpkt_start(SSH_CMSG_EXIT_CONFIRMATION, 0);
s_wrpkt();
} else {
fatalbox("Strange packet received: type %d", pktin.type);
|
| ︙ | | | ︙ | |