57 #define SSH_CONFIG_DEFAULT_HASSH false
59 #define SSH_CONFIG_DEFAULT_ENCRYPTION_BYPASS ENCRYPTION_HANDLING_TRACK_ONLY
61 static int SSHRegisterPatternsForProtocolDetection(
void)
64 IPPROTO_TCP,
ALPROTO_SSH,
"SSH-", 4, 0, STREAM_TOSERVER) < 0) {
68 IPPROTO_TCP,
ALPROTO_SSH,
"SSH-", 4, 0, STREAM_TOCLIENT) < 0) {
76 return SCSshTxGetLogCondition(tx);
83 const char *proto_name =
"ssh";
87 if (SSHRegisterPatternsForProtocolDetection() < 0)
92 const char *strval = NULL;
93 if (
SCConfGet(
"app-layer.protocols.ssh.hassh", &strval) != 1) {
95 }
else if (strcmp(strval,
"auto") == 0) {
110 if (encryption_node != NULL && encryption_node->
val != NULL) {
111 if (strcmp(encryption_node->
val,
"full") == 0) {
112 encryption_bypass = ENCRYPTION_HANDLING_FULL;
113 }
else if (strcmp(encryption_node->
val,
"track-only") == 0) {
114 encryption_bypass = ENCRYPTION_HANDLING_TRACK_ONLY;
115 }
else if (strcmp(encryption_node->
val,
"bypass") == 0) {
116 encryption_bypass = ENCRYPTION_HANDLING_BYPASS;
122 if (encryption_bypass) {
123 SCLogConfig(
"ssh: bypass on the start of encryption enabled");
124 SCSshEnableBypass(encryption_bypass);
129 SCRegisterSshParser();
142 static int SSHParserTestUtilCheck(
const char *protoexp,
const char *softexp,
void *tx, uint8_t
flags) {
145 const uint8_t *software = NULL;
149 printf(
"Version string not parsed correctly return: ");
153 printf(
"Version string not parsed correctly NULL: ");
157 if (p_len != strlen(protoexp)) {
158 printf(
"Version string not parsed correctly length: ");
161 if (memcmp(
protocol, protoexp, strlen(protoexp)) != 0) {
162 printf(
"Version string not parsed correctly: ");
166 if (softexp != NULL) {
167 if (SCSshTxGetSoftware(tx,
flags, &software, &s_len) != 1)
169 if (software == NULL)
171 if (s_len != strlen(softexp)) {
172 printf(
"Software string not parsed correctly length: ");
175 if (memcmp(software, softexp, strlen(softexp)) != 0) {
176 printf(
"Software string not parsed correctly: ");
184 static int SSHParserTest01(
void)
187 uint8_t sshbuf[] =
"SSH-2.0-MySSHClient-0.5.1\n";
188 uint32_t sshlen =
sizeof(sshbuf) - 1;
192 memset(&f, 0,
sizeof(f));
193 memset(&ssn, 0,
sizeof(ssn));
196 f.
proto = IPPROTO_TCP;
202 STREAM_TOSERVER | STREAM_EOF, sshbuf, sshlen);
208 void *tx = SCSshStateGetTx(ssh_state, 0);
210 FAIL_IF(SCSshTxGetAlStateProgress(tx, STREAM_TOSERVER) != SshStateBannerDone);
211 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOSERVER));
222 static int SSHParserTest02(
void)
226 uint8_t sshbuf[] =
"SSH-2.0-MySSHClient-0.5.1 some comments...\n";
227 uint32_t sshlen =
sizeof(sshbuf) - 1;
231 memset(&f, 0,
sizeof(f));
232 memset(&ssn, 0,
sizeof(ssn));
235 f.
proto = IPPROTO_TCP;
241 STREAM_TOSERVER | STREAM_EOF, sshbuf, sshlen);
243 printf(
"toclient chunk 1 returned %" PRId32
", expected 0: ", r);
248 if (ssh_state == NULL) {
249 printf(
"no ssh state: ");
252 void *tx = SCSshStateGetTx(ssh_state, 0);
254 if (SCSshTxGetAlStateProgress(tx, STREAM_TOSERVER) != SshStateBannerDone) {
255 printf(
"Client version string not parsed: ");
258 if (SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOSERVER))
273 static int SSHParserTest03(
void)
277 uint8_t sshbuf[] =
"SSH-2.0 some comments...\n";
278 uint32_t sshlen =
sizeof(sshbuf) - 1;
282 memset(&f, 0,
sizeof(f));
283 memset(&ssn, 0,
sizeof(ssn));
286 f.
proto = IPPROTO_TCP;
292 STREAM_TOSERVER | STREAM_EOF, sshbuf, sshlen);
294 printf(
"toclient chunk 1 returned %" PRId32
", expected != 0: ", r);
299 if (ssh_state == NULL) {
300 printf(
"no ssh state: ");
303 void *tx = SCSshStateGetTx(ssh_state, 0);
305 if (SCSshTxGetAlStateProgress(tx, STREAM_TOSERVER) == SshStateBannerDone) {
306 printf(
"Client version string parsed? It's not a valid string: ");
309 const uint8_t *dummy = NULL;
310 uint32_t dummy_len = 0;
311 if (SCSshTxGetProtocol(tx, STREAM_TOSERVER, &dummy, &dummy_len) != 0)
313 if (SCSshTxGetSoftware(tx, STREAM_TOSERVER, &dummy, &dummy_len) != 0)
326 static int SSHParserTest04(
void)
330 uint8_t sshbuf[] =
"SSH-2.0-MySSHClient-0.5.1\n";
331 uint32_t sshlen =
sizeof(sshbuf) - 1;
335 memset(&f, 0,
sizeof(f));
336 memset(&ssn, 0,
sizeof(ssn));
339 f.
proto = IPPROTO_TCP;
345 STREAM_TOCLIENT | STREAM_EOF, sshbuf, sshlen);
347 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
352 if (ssh_state == NULL) {
353 printf(
"no ssh state: ");
356 void *tx = SCSshStateGetTx(ssh_state, 0);
358 if (SCSshTxGetAlStateProgress(tx, STREAM_TOCLIENT) != SshStateBannerDone) {
359 printf(
"Client version string not parsed: ");
362 if (SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOCLIENT))
377 static int SSHParserTest05(
void)
381 uint8_t sshbuf[] =
"SSH-2.0-MySSHClient-0.5.1 some comments...\n";
382 uint32_t sshlen =
sizeof(sshbuf) - 1;
386 memset(&f, 0,
sizeof(f));
387 memset(&ssn, 0,
sizeof(ssn));
390 f.
proto = IPPROTO_TCP;
396 STREAM_TOCLIENT | STREAM_EOF, sshbuf, sshlen);
398 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
403 if (ssh_state == NULL) {
404 printf(
"no ssh state: ");
407 void *tx = SCSshStateGetTx(ssh_state, 0);
409 if (SCSshTxGetAlStateProgress(tx, STREAM_TOCLIENT) != SshStateBannerDone) {
410 printf(
"Client version string not parsed: ");
413 if (SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOCLIENT))
427 static int SSHParserTest06(
void)
431 uint8_t sshbuf[] =
"SSH-2.0 some comments...\n";
432 uint32_t sshlen =
sizeof(sshbuf) - 1;
436 memset(&f, 0,
sizeof(f));
437 memset(&ssn, 0,
sizeof(ssn));
440 f.
proto = IPPROTO_TCP;
446 STREAM_TOCLIENT | STREAM_EOF, sshbuf, sshlen);
448 printf(
"toserver chunk 1 returned %" PRId32
", expected != 0: ", r);
454 if (ssh_state == NULL) {
455 printf(
"no ssh state: ");
458 void *tx = SCSshStateGetTx(ssh_state, 0);
460 if (SCSshTxGetAlStateProgress(tx, STREAM_TOCLIENT) == SshStateBannerDone) {
461 printf(
"Client version string parsed? It's not a valid string: ");
464 const uint8_t *dummy = NULL;
465 uint32_t dummy_len = 0;
466 if (SCSshTxGetProtocol(tx, STREAM_TOCLIENT, &dummy, &dummy_len) != 0)
468 if (SCSshTxGetSoftware(tx, STREAM_TOCLIENT, &dummy, &dummy_len) != 0)
480 #define MAX_SSH_TEST_SIZE 512
482 static int SSHParserTest07(
void)
492 memset(&
tv, 0x00,
sizeof(
tv));
500 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
503 f->
proto = IPPROTO_TCP;
508 p->
proto = IPPROTO_TCP;
512 for (
int i=0; i<2; i++) {
514 seq += strlen(sshbufs[i]);
520 void *tx = SCSshStateGetTx(ssh_state, 0);
521 FAIL_IF(SCSshTxGetAlStateProgress(tx, STREAM_TOSERVER) != SshStateBannerDone);
523 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOSERVER));
533 static int SSHParserTest08(
void)
543 memset(&
tv, 0x00,
sizeof(
tv));
551 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
554 f->
proto = IPPROTO_TCP;
559 p->
proto = IPPROTO_TCP;
563 for (
int i=0; i<3; i++) {
565 seq += strlen(sshbufs[i]);
571 void *tx = SCSshStateGetTx(ssh_state, 0);
572 FAIL_IF(SCSshTxGetAlStateProgress(tx, STREAM_TOSERVER) != SshStateBannerDone);
574 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOSERVER));
583 static int SSHParserTest09(
void)
593 memset(&
tv, 0x00,
sizeof(
tv));
601 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
604 f->
proto = IPPROTO_TCP;
609 p->
proto = IPPROTO_TCP;
613 for (
int i=0; i<2; i++) {
615 seq += strlen(sshbufs[i]);
621 void *tx = SCSshStateGetTx(ssh_state, 0);
622 FAIL_IF(SCSshTxGetAlStateProgress(tx, STREAM_TOCLIENT) != SshStateBannerDone);
624 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOCLIENT));
634 static int SSHParserTest10(
void)
644 memset(&
tv, 0x00,
sizeof(
tv));
652 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
655 f->
proto = IPPROTO_TCP;
660 p->
proto = IPPROTO_TCP;
664 for (
int i=0; i<3; i++) {
666 seq += strlen(sshbufs[i]);
672 void *tx = SCSshStateGetTx(ssh_state, 0);
673 FAIL_IF(SCSshTxGetAlStateProgress(tx, STREAM_TOCLIENT) != SshStateBannerDone);
675 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOCLIENT));
685 static int SSHParserTest11(
void)
689 uint8_t sshbuf1[] =
"SSH-2.0-MySSHClient-0.5.1\r\n";
690 uint32_t sshlen1 =
sizeof(sshbuf1) - 1;
691 uint8_t sshbuf2[] = { 0x00, 0x00, 0x00, 0x03, 0x01, 21, 0x00};
692 uint32_t sshlen2 =
sizeof(sshbuf2);
696 memset(&f, 0,
sizeof(f));
697 memset(&ssn, 0,
sizeof(ssn));
700 f.
proto = IPPROTO_TCP;
706 STREAM_TOSERVER, sshbuf1, sshlen1);
708 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
714 printf(
"toserver chunk 2 returned %" PRId32
", expected 0: ", r);
719 if (ssh_state == NULL) {
720 printf(
"no ssh state: ");
723 void *tx = SCSshStateGetTx(ssh_state, 0);
724 if (SCSshTxGetFlags(tx, STREAM_TOSERVER) != SshStateFinished) {
725 printf(
"Didn't detect the msg code of new keys (ciphered data starts): ");
728 if (SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOSERVER))
741 static int SSHParserTest12(
void)
745 uint8_t sshbuf1[] =
"SSH-2.0-MySSHClient-0.5.1\r\n";
746 uint32_t sshlen1 =
sizeof(sshbuf1) - 1;
747 uint8_t sshbuf2[] = { 0x00, 0x00, 0x00, 0x03,0x01, 17, 0x00};
748 uint32_t sshlen2 =
sizeof(sshbuf2);
749 uint8_t sshbuf3[] = { 0x00, 0x00, 0x00, 0x03,0x01, 21, 0x00};
750 uint32_t sshlen3 =
sizeof(sshbuf3);
754 memset(&f, 0,
sizeof(f));
755 memset(&ssn, 0,
sizeof(ssn));
758 f.
proto = IPPROTO_TCP;
764 STREAM_TOSERVER, sshbuf1, sshlen1);
766 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
772 printf(
"toserver chunk 2 returned %" PRId32
", expected 0: ", r);
778 printf(
"toserver chunk 3 returned %" PRId32
", expected 0: ", r);
783 if (ssh_state == NULL) {
784 printf(
"no ssh state: ");
787 void *tx = SCSshStateGetTx(ssh_state, 0);
788 if (SCSshTxGetFlags(tx, STREAM_TOSERVER) != SshStateFinished) {
789 printf(
"Didn't detect the msg code of new keys (ciphered data starts): ");
792 if (SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOSERVER))
805 static int SSHParserTest13(
void)
813 uint8_t sshbuf1[] =
"SSH-2.0-MySSHClient-0.5.1\r\n";
814 uint8_t sshbuf2[] = { 0x00, 0x00, 0x00, 0x02, 0x01, 17};
815 uint8_t sshbuf3[] = { 0x00, 0x00, 0x00, 0x02, 0x01, 21};
817 uint8_t* sshbufs[3] = {sshbuf1, sshbuf2, sshbuf3};
818 uint32_t sshlens[3] = {
sizeof(sshbuf1) - 1,
sizeof(sshbuf2),
sizeof(sshbuf3)};
820 memset(&
tv, 0x00,
sizeof(
tv));
828 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
831 f->
proto = IPPROTO_TCP;
836 p->
proto = IPPROTO_TCP;
840 for (
int i=0; i<3; i++) {
848 void *tx = SCSshStateGetTx(ssh_state, 0);
849 FAIL_IF(SCSshTxGetFlags(tx, STREAM_TOSERVER) != SshStateFinished);
851 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOSERVER));
861 static int SSHParserTest14(
void)
869 uint8_t sshbuf1[] =
"SSH-2.0-MySSHClient-0.5.1\r\n";
870 uint8_t sshbuf2[] = { 0x00, 0x00, 0x00, 0x10, 0x01, 17, 0x00};
871 uint8_t sshbuf3[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
872 uint8_t sshbuf4[] = { 0x09, 0x10, 0x11, 0x12, 0x13, 0x00};
874 uint8_t sshbuf5[] = { 0x00, 0x00, 0x02, 0x01, 21};
876 uint8_t* sshbufs[5] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4, sshbuf5};
877 uint32_t sshlens[5] = {
sizeof(sshbuf1) - 1,
sizeof(sshbuf2),
sizeof(sshbuf3),
sizeof(sshbuf4),
sizeof(sshbuf5)};
879 memset(&
tv, 0x00,
sizeof(
tv));
887 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
890 f->
proto = IPPROTO_TCP;
895 p->
proto = IPPROTO_TCP;
899 for (
int i=0; i<5; i++) {
907 void *tx = SCSshStateGetTx(ssh_state, 0);
908 FAIL_IF(SCSshTxGetFlags(tx, STREAM_TOSERVER) != SshStateFinished);
910 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOSERVER));
920 static int SSHParserTest15(
void)
928 uint8_t sshbuf1[] =
"SSH-2.0-MySSHClient-0.5.1\r\n";
929 uint8_t sshbuf2[] = { 0x00, 0x00, 0x00, 0x10, 0x01, 17, 0x00};
930 uint8_t sshbuf3[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
931 uint8_t sshbuf4[] = { 0x09, 0x10, 0x11, 0x12, 0x13, 0x00};
932 uint8_t sshbuf5[] = { 0x00, 0x00, 0x02, 0x01, 20, 0x00, 0x00, 0x00, 0x02, 0x01, 21};
934 uint8_t* sshbufs[5] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4, sshbuf5};
935 uint32_t sshlens[5] = {
sizeof(sshbuf1) - 1,
sizeof(sshbuf2),
sizeof(sshbuf3),
sizeof(sshbuf4),
sizeof(sshbuf5)};
937 memset(&
tv, 0x00,
sizeof(
tv));
945 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
948 f->
proto = IPPROTO_TCP;
953 p->
proto = IPPROTO_TCP;
957 for (
int i=0; i<5; i++) {
965 void *tx = SCSshStateGetTx(ssh_state, 0);
966 FAIL_IF(SCSshTxGetFlags(tx, STREAM_TOSERVER) != SshStateFinished);
968 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOSERVER));
978 static int SSHParserTest16(
void)
986 uint8_t sshbuf1[] =
"SSH-";
987 uint8_t sshbuf2[] =
"2.0-MySSHClient-0.5.1\r\n";
988 uint8_t sshbuf3[] = { 0x00, 0x00, 0x00, 0x03,0x01, 21, 0x00};
990 uint8_t* sshbufs[3] = {sshbuf1, sshbuf2, sshbuf3};
991 uint32_t sshlens[3] = {
sizeof(sshbuf1) - 1,
sizeof(sshbuf2) - 1,
sizeof(sshbuf3)};
993 memset(&
tv, 0x00,
sizeof(
tv));
1001 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
1004 f->
proto = IPPROTO_TCP;
1009 p->
proto = IPPROTO_TCP;
1013 for (
int i=0; i<3; i++) {
1021 void *tx = SCSshStateGetTx(ssh_state, 0);
1022 FAIL_IF(SCSshTxGetFlags(tx, STREAM_TOCLIENT) != SshStateFinished);
1024 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOCLIENT));
1034 static int SSHParserTest17(
void)
1042 uint8_t sshbuf1[] =
"SSH-";
1043 uint8_t sshbuf2[] =
"2.0-MySSHClient-0.5.1\r\n";
1044 uint8_t sshbuf3[] = { 0x00, 0x00, 0x00, 0x03, 0x01, 17, 0x00};
1045 uint8_t sshbuf4[] = { 0x00, 0x00, 0x00, 0x03, 0x01, 21, 0x00};
1047 uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
1048 uint32_t sshlens[4] = {
sizeof(sshbuf1) - 1,
sizeof(sshbuf2) - 1,
sizeof(sshbuf3),
sizeof(sshbuf4)};
1050 memset(&
tv, 0x00,
sizeof(
tv));
1058 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
1061 f->
proto = IPPROTO_TCP;
1066 p->
proto = IPPROTO_TCP;
1070 for (
int i=0; i<4; i++) {
1078 void *tx = SCSshStateGetTx(ssh_state, 0);
1079 FAIL_IF(SCSshTxGetFlags(tx, STREAM_TOCLIENT) != SshStateFinished);
1081 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOCLIENT));
1091 static int SSHParserTest18(
void)
1099 uint8_t server1[] =
"SSH-2.0-OpenSSH_4.7p1 Debian-8ubuntu3\r\n";
1100 uint8_t sshbuf1[] =
"SSH-";
1101 uint8_t sshbuf2[] =
"2.0-MySSHClient-0.5.1\r\n";
1102 uint8_t server2[] = { 0x00, 0x00, 0x00, 0x03, 0x01, 21, 0x00 };
1103 uint8_t sshbuf3[] = { 0x00, 0x00, 0x00, 0x03, 0x01, 21, 0x00 };
1106 memset(&
tv, 0x00,
sizeof(
tv));
1114 uint8_t* sshbufs[5] = {server1, sshbuf1, sshbuf2, server2, sshbuf3};
1115 uint32_t sshlens[5] = {
sizeof(server1) - 1,
sizeof(sshbuf1) - 1,
sizeof(sshbuf2) -1,
sizeof(server2) - 1,
sizeof(sshbuf3)};
1116 bool sshdirs[5] = {
true,
false,
false,
true,
false};
1118 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
1121 f->
proto = IPPROTO_TCP;
1126 p->
proto = IPPROTO_TCP;
1129 uint32_t seqcli = 2;
1130 uint32_t seqsrv = 2;
1131 for (
int i=0; i<5; i++) {
1134 seqsrv += sshlens[i];
1138 seqcli += sshlens[i];
1145 void *tx = SCSshStateGetTx(ssh_state, 0);
1146 FAIL_IF(SCSshTxGetFlags(tx, STREAM_TOCLIENT) != SshStateFinished);
1158 static int SSHParserTest19(
void)
1166 uint8_t sshbuf1[] =
"SSH-";
1167 uint8_t sshbuf2[] =
"2.0-";
1168 uint8_t sshbuf3[] =
"abcdefghijklmnopqrstuvwxyz"
1169 "abcdefghijklmnopqrstuvwxyz"
1170 "abcdefghijklmnopqrstuvwxyz"
1171 "abcdefghijklmnopqrstuvwxyz"
1172 "abcdefghijklmnopqrstuvwxyz"
1173 "abcdefghijklmnopqrstuvwxyz"
1174 "abcdefghijklmnopqrstuvwxyz"
1175 "abcdefghijklmnopqrstuvwxyz"
1176 "abcdefghijklmnopqrstuvwxyz"
1178 uint8_t sshbuf4[] = { 0x00, 0x00, 0x00, 0x03, 0x01, 21, 0x00};
1180 uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
1181 uint32_t sshlens[4] = {
sizeof(sshbuf1) - 1,
sizeof(sshbuf2) - 1,
sizeof(sshbuf3) - 1,
sizeof(sshbuf4)};
1183 memset(&
tv, 0x00,
sizeof(
tv));
1191 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
1194 f->
proto = IPPROTO_TCP;
1199 p->
proto = IPPROTO_TCP;
1203 for (
int i=0; i<4; i++) {
1211 void *tx = SCSshStateGetTx(ssh_state, 0);
1212 FAIL_IF(SCSshTxGetFlags(tx, STREAM_TOCLIENT) != SshStateFinished);
1214 sshbuf3[
sizeof(sshbuf3) - 2] = 0;
1215 FAIL_IF(SSHParserTestUtilCheck(
"2.0", (
char *)sshbuf3, tx, STREAM_TOCLIENT));
1226 static int SSHParserTest20(
void)
1234 uint8_t sshbuf1[] =
"SSH-";
1235 uint8_t sshbuf2[] =
"2.0-";
1236 uint8_t sshbuf3[] =
"abcdefghijklmnopqrstuvwxyz"
1237 "abcdefghijklmnopqrstuvwxyz"
1238 "abcdefghijklmnopqrstuvwxyz"
1239 "abcdefghijklmnopqrstuvwxyz"
1240 "abcdefghijklmnopqrstuvwxyz"
1241 "abcdefghijklmnopqrstuvwxyz"
1242 "abcdefghijklmnopqrstuvwxyz"
1243 "abcdefghijklmnopqrstuvwxyz"
1244 "abcdefghijklmnopqrstuvwxyz"
1246 uint8_t sshbuf4[] = {
'a',
'b',
'c',
'd',
'e',
'f',
'\r',
1247 0x00, 0x00, 0x00, 0x06, 0x01, 21, 0x00, 0x00, 0x00};
1249 uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
1250 uint32_t sshlens[4] = {
sizeof(sshbuf1) - 1,
sizeof(sshbuf2) - 1,
sizeof(sshbuf3) - 1,
sizeof(sshbuf4) - 1};
1252 memset(&
tv, 0x00,
sizeof(
tv));
1260 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
1263 f->
proto = IPPROTO_TCP;
1268 p->
proto = IPPROTO_TCP;
1272 for (
int i=0; i<4; i++) {
1280 void *tx = SCSshStateGetTx(ssh_state, 0);
1281 FAIL_IF(SCSshTxGetFlags(tx, STREAM_TOCLIENT) != SshStateFinished);
1283 FAIL_IF(SSHParserTestUtilCheck(
"2.0", NULL, tx, STREAM_TOCLIENT));
1294 static int SSHParserTest21(
void)
1302 uint8_t sshbuf1[] =
"SSH-";
1303 uint8_t sshbuf2[] =
"2.0-";
1304 uint8_t sshbuf3[] =
"abcdefghijklmnopqrstuvwxyz"
1305 "abcdefghijklmnopqrstuvwxyz"
1306 "abcdefghijklmnopqrstuvwxyz"
1307 "abcdefghijklmnopqrstuvwxyz"
1308 "abcdefghijklmnopqrstuvwxyz"
1309 "abcdefghijklmnopqrstuvwxyz"
1310 "abcdefghijklmnopqrstuvwxyz"
1311 "abcdefghijklmnopqrstuvwxyz"
1312 "abcdefghijklmnopqrstuvwxy";
1313 uint8_t sshbuf4[] = {
'l',
'i',
'b',
's',
's',
'h',
'\r',
1314 0x00, 0x00, 0x00, 0x06, 0x01, 21, 0x00, 0x00, 0x00};
1316 uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
1317 uint32_t sshlens[4] = {
sizeof(sshbuf1) - 1,
sizeof(sshbuf2) - 1,
sizeof(sshbuf3) - 1,
sizeof(sshbuf4)};
1319 memset(&
tv, 0x00,
sizeof(
tv));
1327 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
1330 f->
proto = IPPROTO_TCP;
1335 p->
proto = IPPROTO_TCP;
1339 for (
int i=0; i<4; i++) {
1347 void *tx = SCSshStateGetTx(ssh_state, 0);
1348 FAIL_IF(SCSshTxGetFlags(tx, STREAM_TOCLIENT) != SshStateFinished);
1350 FAIL_IF(SSHParserTestUtilCheck(
"2.0", NULL, tx, STREAM_TOCLIENT));
1361 static int SSHParserTest22(
void)
1369 uint8_t sshbuf1[] =
"SSH-";
1370 uint8_t sshbuf2[] =
"2.0-";
1371 uint8_t sshbuf3[] = {
1372 'l',
'i',
'b',
's',
's',
'h',
'\r',
1374 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01, 17,
1375 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00, 0x00,
1376 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00,
1379 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01, 17,
1380 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00, 0x00,
1381 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00,
1384 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01, 17,
1385 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00, 0x00,
1386 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00,
1389 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01, 17,
1390 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00, 0x00,
1391 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00,
1394 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01, 17,
1395 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00, 0x00,
1396 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00,
1399 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01, 17,
1400 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00, 0x00,
1401 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01, 21, 0x00,
1405 uint8_t *sshbufs[3] = { sshbuf1, sshbuf2, sshbuf3 };
1406 uint32_t sshlens[3] = {
sizeof(sshbuf1) - 1,
sizeof(sshbuf2) - 1,
sizeof(sshbuf3) - 1 };
1408 memset(&
tv, 0x00,
sizeof(
tv));
1416 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
1419 f->
proto = IPPROTO_TCP;
1424 p->
proto = IPPROTO_TCP;
1428 for (
int i = 0; i < 3; i++) {
1430 &
tv, ra_ctx, &ssn.
server,
seq, sshbufs[i], sshlens[i]) == -1);
1438 void *tx = SCSshStateGetTx(ssh_state, 0);
1439 FAIL_IF(SCSshTxGetFlags(tx, STREAM_TOCLIENT) != SshStateFinished);
1441 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"libssh", tx, STREAM_TOCLIENT));
1451 static int SSHParserTest23(
void)
1455 uint8_t sshbuf[] =
"SSH-2.0\r-MySSHClient-0.5.1\n";
1456 uint32_t sshlen =
sizeof(sshbuf) - 1;
1460 memset(&f, 0,
sizeof(f));
1461 memset(&ssn, 0,
sizeof(ssn));
1464 f.
proto = IPPROTO_TCP;
1470 STREAM_TOSERVER | STREAM_EOF, sshbuf, sshlen);
1472 printf(
"toclient chunk 1 returned 0 expected non null: ");
1486 static int SSHParserTest24(
void)
1490 uint8_t sshbuf[] =
"SSH-2.0-\rMySSHClient-0.5.1\n";
1491 uint32_t sshlen =
sizeof(sshbuf) - 1;
1495 memset(&f, 0,
sizeof(f));
1496 memset(&ssn, 0,
sizeof(ssn));
1499 f.
proto = IPPROTO_TCP;
1505 STREAM_TOSERVER | STREAM_EOF, sshbuf, sshlen);
1507 printf(
"toclient chunk 1 returned %" PRId32
", expected 0: ", r);
1512 if (ssh_state == NULL) {
1513 printf(
"no ssh state: ");
1516 void *tx = SCSshStateGetTx(ssh_state, 0);
1517 if (SCSshTxGetFlags(tx, STREAM_TOSERVER) != SshStateBannerDone) {
1518 printf(
"Didn't detect the msg code of new keys (ciphered data starts): ");
1521 if (SSHParserTestUtilCheck(
"2.0", NULL, tx, STREAM_TOSERVER))
1534 static int SSHParserTest25(
void)
1537 uint8_t sshbuf[] =
"\n";
1538 uint32_t sshlen =
sizeof(sshbuf) - 1;
1543 memset(&f, 0,
sizeof(f));
1544 memset(&ssn, 0,
sizeof(ssn));
1547 f.
proto = IPPROTO_TCP;
1553 STREAM_TOSERVER | STREAM_EOF, sshbuf, sshlen);
1558 void *tx = SCSshStateGetTx(ssh_state, 0);
1559 FAIL_IF(SCSshTxGetFlags(tx, STREAM_TOSERVER) == SshStateBannerDone);
1560 const uint8_t *dummy = NULL;
1561 uint32_t dummy_len = 0;
1562 FAIL_IF(SCSshTxGetSoftware(tx, STREAM_TOCLIENT, &dummy, &dummy_len) != 0);
1581 UtRegisterTest(
"SSHParserTest07 - ToServer 2 chunks", SSHParserTest07);
1582 UtRegisterTest(
"SSHParserTest08 - ToServer 3 chunks", SSHParserTest08);
1583 UtRegisterTest(
"SSHParserTest09 - ToClient 2 chunks", SSHParserTest09);
1584 UtRegisterTest(
"SSHParserTest10 - ToClient 3 chunks", SSHParserTest10);
1585 UtRegisterTest(
"SSHParserTest11 - ToClient 4 chunks", SSHParserTest11);
1586 UtRegisterTest(
"SSHParserTest12 - ToClient 4 chunks", SSHParserTest12);
1587 UtRegisterTest(
"SSHParserTest13 - ToClient 4 chunks", SSHParserTest13);
1588 UtRegisterTest(
"SSHParserTest14 - ToClient 4 chunks", SSHParserTest14);