57 #define SSH_CONFIG_DEFAULT_HASSH false
59 static int SSHRegisterPatternsForProtocolDetection(
void)
62 "SSH-", 4, 0, STREAM_TOSERVER) < 0)
67 "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 (
ConfGet(
"app-layer.protocols.ssh.hassh", &strval) != 1) {
95 }
else if (strcmp(strval,
"auto") == 0) {
109 SCRegisterSshParser();
122 static int SSHParserTestUtilCheck(
const char *protoexp,
const char *softexp,
void *tx, uint8_t
flags) {
125 const uint8_t *software = NULL;
129 printf(
"Version string not parsed correctly return: ");
133 printf(
"Version string not parsed correctly NULL: ");
137 if (p_len != strlen(protoexp)) {
138 printf(
"Version string not parsed correctly length: ");
141 if (memcmp(
protocol, protoexp, strlen(protoexp)) != 0) {
142 printf(
"Version string not parsed correctly: ");
146 if (softexp != NULL) {
147 if (SCSshTxGetSoftware(tx, &software, &s_len,
flags) != 1)
149 if (software == NULL)
151 if (s_len != strlen(softexp)) {
152 printf(
"Software string not parsed correctly length: ");
155 if (memcmp(software, softexp, strlen(softexp)) != 0) {
156 printf(
"Software string not parsed correctly: ");
164 static int SSHParserTest01(
void)
168 uint8_t sshbuf[] =
"SSH-2.0-MySSHClient-0.5.1\n";
169 uint32_t sshlen =
sizeof(sshbuf) - 1;
173 memset(&f, 0,
sizeof(f));
174 memset(&ssn, 0,
sizeof(ssn));
182 STREAM_TOSERVER | STREAM_EOF, sshbuf, sshlen);
184 printf(
"toclient chunk 1 returned %" PRId32
", expected 0: ", r);
189 if (ssh_state == NULL) {
190 printf(
"no ssh state: ");
194 void *tx = SCSshStateGetTx(ssh_state, 0);
195 if (SCSshTxGetAlStateProgress(tx, STREAM_TOSERVER) != SshStateBannerDone) {
196 printf(
"Client version string not parsed: ");
200 if (SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOSERVER))
215 static int SSHParserTest02(
void)
219 uint8_t sshbuf[] =
"SSH-2.0-MySSHClient-0.5.1 some comments...\n";
220 uint32_t sshlen =
sizeof(sshbuf) - 1;
224 memset(&f, 0,
sizeof(f));
225 memset(&ssn, 0,
sizeof(ssn));
233 STREAM_TOSERVER | STREAM_EOF, sshbuf, sshlen);
235 printf(
"toclient chunk 1 returned %" PRId32
", expected 0: ", r);
240 if (ssh_state == NULL) {
241 printf(
"no ssh state: ");
244 void *tx = SCSshStateGetTx(ssh_state, 0);
246 if (SCSshTxGetAlStateProgress(tx, STREAM_TOSERVER) != SshStateBannerDone) {
247 printf(
"Client version string not parsed: ");
250 if (SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOSERVER))
265 static int SSHParserTest03(
void)
269 uint8_t sshbuf[] =
"SSH-2.0 some comments...\n";
270 uint32_t sshlen =
sizeof(sshbuf) - 1;
274 memset(&f, 0,
sizeof(f));
275 memset(&ssn, 0,
sizeof(ssn));
283 STREAM_TOSERVER | STREAM_EOF, sshbuf, sshlen);
285 printf(
"toclient chunk 1 returned %" PRId32
", expected != 0: ", r);
290 if (ssh_state == NULL) {
291 printf(
"no ssh state: ");
294 void *tx = SCSshStateGetTx(ssh_state, 0);
296 if (SCSshTxGetAlStateProgress(tx, STREAM_TOSERVER) == SshStateBannerDone) {
297 printf(
"Client version string parsed? It's not a valid string: ");
300 const uint8_t *dummy = NULL;
301 uint32_t dummy_len = 0;
302 if (SCSshTxGetProtocol(tx, &dummy, &dummy_len, STREAM_TOSERVER) != 0)
304 if (SCSshTxGetSoftware(tx, &dummy, &dummy_len, STREAM_TOSERVER) != 0)
317 static int SSHParserTest04(
void)
321 uint8_t sshbuf[] =
"SSH-2.0-MySSHClient-0.5.1\n";
322 uint32_t sshlen =
sizeof(sshbuf) - 1;
326 memset(&f, 0,
sizeof(f));
327 memset(&ssn, 0,
sizeof(ssn));
335 STREAM_TOCLIENT | STREAM_EOF, sshbuf, sshlen);
337 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
342 if (ssh_state == NULL) {
343 printf(
"no ssh state: ");
346 void *tx = SCSshStateGetTx(ssh_state, 0);
348 if (SCSshTxGetAlStateProgress(tx, STREAM_TOCLIENT) != SshStateBannerDone) {
349 printf(
"Client version string not parsed: ");
352 if (SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOCLIENT))
367 static int SSHParserTest05(
void)
371 uint8_t sshbuf[] =
"SSH-2.0-MySSHClient-0.5.1 some comments...\n";
372 uint32_t sshlen =
sizeof(sshbuf) - 1;
376 memset(&f, 0,
sizeof(f));
377 memset(&ssn, 0,
sizeof(ssn));
385 STREAM_TOCLIENT | STREAM_EOF, sshbuf, sshlen);
387 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
392 if (ssh_state == NULL) {
393 printf(
"no ssh state: ");
396 void *tx = SCSshStateGetTx(ssh_state, 0);
398 if (SCSshTxGetAlStateProgress(tx, STREAM_TOCLIENT) != SshStateBannerDone) {
399 printf(
"Client version string not parsed: ");
402 if (SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOCLIENT))
416 static int SSHParserTest06(
void)
420 uint8_t sshbuf[] =
"SSH-2.0 some comments...\n";
421 uint32_t sshlen =
sizeof(sshbuf) - 1;
425 memset(&f, 0,
sizeof(f));
426 memset(&ssn, 0,
sizeof(ssn));
434 STREAM_TOCLIENT | STREAM_EOF, sshbuf, sshlen);
436 printf(
"toserver chunk 1 returned %" PRId32
", expected != 0: ", r);
442 if (ssh_state == NULL) {
443 printf(
"no ssh state: ");
446 void *tx = SCSshStateGetTx(ssh_state, 0);
448 if (SCSshTxGetAlStateProgress(tx, STREAM_TOCLIENT) == SshStateBannerDone) {
449 printf(
"Client version string parsed? It's not a valid string: ");
452 const uint8_t *dummy = NULL;
453 uint32_t dummy_len = 0;
454 if (SCSshTxGetProtocol(tx, &dummy, &dummy_len, STREAM_TOCLIENT) != 0)
456 if (SCSshTxGetSoftware(tx, &dummy, &dummy_len, STREAM_TOCLIENT) != 0)
469 #define MAX_SSH_TEST_SIZE 512
471 static int SSHParserTest07(
void)
481 memset(&
tv, 0x00,
sizeof(
tv));
489 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
492 f->
proto = IPPROTO_TCP;
497 p->
proto = IPPROTO_TCP;
501 for (
int i=0; i<2; i++) {
503 seq += strlen(sshbufs[i]);
509 void *tx = SCSshStateGetTx(ssh_state, 0);
510 FAIL_IF(SCSshTxGetAlStateProgress(tx, STREAM_TOSERVER) != SshStateBannerDone);
512 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOSERVER));
522 static int SSHParserTest08(
void)
532 memset(&
tv, 0x00,
sizeof(
tv));
540 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
543 f->
proto = IPPROTO_TCP;
548 p->
proto = IPPROTO_TCP;
552 for (
int i=0; i<3; i++) {
554 seq += strlen(sshbufs[i]);
560 void *tx = SCSshStateGetTx(ssh_state, 0);
561 FAIL_IF(SCSshTxGetAlStateProgress(tx, STREAM_TOSERVER) != SshStateBannerDone);
563 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOSERVER));
572 static int SSHParserTest09(
void)
582 memset(&
tv, 0x00,
sizeof(
tv));
590 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
593 f->
proto = IPPROTO_TCP;
598 p->
proto = IPPROTO_TCP;
602 for (
int i=0; i<2; i++) {
604 seq += strlen(sshbufs[i]);
610 void *tx = SCSshStateGetTx(ssh_state, 0);
611 FAIL_IF(SCSshTxGetAlStateProgress(tx, STREAM_TOCLIENT) != SshStateBannerDone);
613 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOCLIENT));
623 static int SSHParserTest10(
void)
633 memset(&
tv, 0x00,
sizeof(
tv));
641 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
644 f->
proto = IPPROTO_TCP;
649 p->
proto = IPPROTO_TCP;
653 for (
int i=0; i<3; i++) {
655 seq += strlen(sshbufs[i]);
661 void *tx = SCSshStateGetTx(ssh_state, 0);
662 FAIL_IF(SCSshTxGetAlStateProgress(tx, STREAM_TOCLIENT) != SshStateBannerDone);
664 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOCLIENT));
674 static int SSHParserTest11(
void)
678 uint8_t sshbuf1[] =
"SSH-2.0-MySSHClient-0.5.1\r\n";
679 uint32_t sshlen1 =
sizeof(sshbuf1) - 1;
680 uint8_t sshbuf2[] = { 0x00, 0x00, 0x00, 0x03, 0x01, 21, 0x00};
681 uint32_t sshlen2 =
sizeof(sshbuf2);
685 memset(&f, 0,
sizeof(f));
686 memset(&ssn, 0,
sizeof(ssn));
694 STREAM_TOSERVER, sshbuf1, sshlen1);
696 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
702 printf(
"toserver chunk 2 returned %" PRId32
", expected 0: ", r);
707 if (ssh_state == NULL) {
708 printf(
"no ssh state: ");
711 void *tx = SCSshStateGetTx(ssh_state, 0);
712 if (SCSshTxGetFlags(tx, STREAM_TOSERVER) != SshStateFinished) {
713 printf(
"Didn't detect the msg code of new keys (ciphered data starts): ");
716 if (SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOSERVER))
729 static int SSHParserTest12(
void)
733 uint8_t sshbuf1[] =
"SSH-2.0-MySSHClient-0.5.1\r\n";
734 uint32_t sshlen1 =
sizeof(sshbuf1) - 1;
735 uint8_t sshbuf2[] = { 0x00, 0x00, 0x00, 0x03,0x01, 17, 0x00};
736 uint32_t sshlen2 =
sizeof(sshbuf2);
737 uint8_t sshbuf3[] = { 0x00, 0x00, 0x00, 0x03,0x01, 21, 0x00};
738 uint32_t sshlen3 =
sizeof(sshbuf3);
742 memset(&f, 0,
sizeof(f));
743 memset(&ssn, 0,
sizeof(ssn));
751 STREAM_TOSERVER, sshbuf1, sshlen1);
753 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
759 printf(
"toserver chunk 2 returned %" PRId32
", expected 0: ", r);
765 printf(
"toserver chunk 3 returned %" PRId32
", expected 0: ", r);
770 if (ssh_state == NULL) {
771 printf(
"no ssh state: ");
774 void *tx = SCSshStateGetTx(ssh_state, 0);
775 if (SCSshTxGetFlags(tx, STREAM_TOSERVER) != SshStateFinished) {
776 printf(
"Didn't detect the msg code of new keys (ciphered data starts): ");
779 if (SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOSERVER))
792 static int SSHParserTest13(
void)
800 uint8_t sshbuf1[] =
"SSH-2.0-MySSHClient-0.5.1\r\n";
801 uint8_t sshbuf2[] = { 0x00, 0x00, 0x00, 0x02, 0x01, 17};
802 uint8_t sshbuf3[] = { 0x00, 0x00, 0x00, 0x02, 0x01, 21};
804 uint8_t* sshbufs[3] = {sshbuf1, sshbuf2, sshbuf3};
805 uint32_t sshlens[3] = {
sizeof(sshbuf1) - 1,
sizeof(sshbuf2),
sizeof(sshbuf3)};
807 memset(&
tv, 0x00,
sizeof(
tv));
815 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
818 f->
proto = IPPROTO_TCP;
823 p->
proto = IPPROTO_TCP;
827 for (
int i=0; i<3; i++) {
835 void *tx = SCSshStateGetTx(ssh_state, 0);
836 FAIL_IF(SCSshTxGetFlags(tx, STREAM_TOSERVER) != SshStateFinished);
838 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOSERVER));
848 static int SSHParserTest14(
void)
856 uint8_t sshbuf1[] =
"SSH-2.0-MySSHClient-0.5.1\r\n";
857 uint8_t sshbuf2[] = { 0x00, 0x00, 0x00, 0x10, 0x01, 17, 0x00};
858 uint8_t sshbuf3[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
859 uint8_t sshbuf4[] = { 0x09, 0x10, 0x11, 0x12, 0x13, 0x00};
861 uint8_t sshbuf5[] = { 0x00, 0x00, 0x02, 0x01, 21};
863 uint8_t* sshbufs[5] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4, sshbuf5};
864 uint32_t sshlens[5] = {
sizeof(sshbuf1) - 1,
sizeof(sshbuf2),
sizeof(sshbuf3),
sizeof(sshbuf4),
sizeof(sshbuf5)};
866 memset(&
tv, 0x00,
sizeof(
tv));
874 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
877 f->
proto = IPPROTO_TCP;
882 p->
proto = IPPROTO_TCP;
886 for (
int i=0; i<5; i++) {
894 void *tx = SCSshStateGetTx(ssh_state, 0);
895 FAIL_IF(SCSshTxGetFlags(tx, STREAM_TOSERVER) != SshStateFinished);
897 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOSERVER));
907 static int SSHParserTest15(
void)
915 uint8_t sshbuf1[] =
"SSH-2.0-MySSHClient-0.5.1\r\n";
916 uint8_t sshbuf2[] = { 0x00, 0x00, 0x00, 0x10, 0x01, 17, 0x00};
917 uint8_t sshbuf3[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
918 uint8_t sshbuf4[] = { 0x09, 0x10, 0x11, 0x12, 0x13, 0x00};
919 uint8_t sshbuf5[] = { 0x00, 0x00, 0x02, 0x01, 20, 0x00, 0x00, 0x00, 0x02, 0x01, 21};
921 uint8_t* sshbufs[5] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4, sshbuf5};
922 uint32_t sshlens[5] = {
sizeof(sshbuf1) - 1,
sizeof(sshbuf2),
sizeof(sshbuf3),
sizeof(sshbuf4),
sizeof(sshbuf5)};
924 memset(&
tv, 0x00,
sizeof(
tv));
932 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
935 f->
proto = IPPROTO_TCP;
940 p->
proto = IPPROTO_TCP;
944 for (
int i=0; i<5; i++) {
952 void *tx = SCSshStateGetTx(ssh_state, 0);
953 FAIL_IF(SCSshTxGetFlags(tx, STREAM_TOSERVER) != SshStateFinished);
955 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOSERVER));
965 static int SSHParserTest16(
void)
973 uint8_t sshbuf1[] =
"SSH-";
974 uint8_t sshbuf2[] =
"2.0-MySSHClient-0.5.1\r\n";
975 uint8_t sshbuf3[] = { 0x00, 0x00, 0x00, 0x03,0x01, 21, 0x00};
977 uint8_t* sshbufs[3] = {sshbuf1, sshbuf2, sshbuf3};
978 uint32_t sshlens[3] = {
sizeof(sshbuf1) - 1,
sizeof(sshbuf2) - 1,
sizeof(sshbuf3)};
980 memset(&
tv, 0x00,
sizeof(
tv));
988 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
991 f->
proto = IPPROTO_TCP;
996 p->
proto = IPPROTO_TCP;
1000 for (
int i=0; i<3; i++) {
1008 void *tx = SCSshStateGetTx(ssh_state, 0);
1009 FAIL_IF(SCSshTxGetFlags(tx, STREAM_TOCLIENT) != SshStateFinished);
1011 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOCLIENT));
1021 static int SSHParserTest17(
void)
1029 uint8_t sshbuf1[] =
"SSH-";
1030 uint8_t sshbuf2[] =
"2.0-MySSHClient-0.5.1\r\n";
1031 uint8_t sshbuf3[] = { 0x00, 0x00, 0x00, 0x03, 0x01, 17, 0x00};
1032 uint8_t sshbuf4[] = { 0x00, 0x00, 0x00, 0x03, 0x01, 21, 0x00};
1034 uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
1035 uint32_t sshlens[4] = {
sizeof(sshbuf1) - 1,
sizeof(sshbuf2) - 1,
sizeof(sshbuf3),
sizeof(sshbuf4)};
1037 memset(&
tv, 0x00,
sizeof(
tv));
1045 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
1048 f->
proto = IPPROTO_TCP;
1053 p->
proto = IPPROTO_TCP;
1057 for (
int i=0; i<4; i++) {
1065 void *tx = SCSshStateGetTx(ssh_state, 0);
1066 FAIL_IF(SCSshTxGetFlags(tx, STREAM_TOCLIENT) != SshStateFinished);
1068 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOCLIENT));
1078 static int SSHParserTest18(
void)
1086 uint8_t server1[] =
"SSH-2.0-OpenSSH_4.7p1 Debian-8ubuntu3\r\n";
1087 uint8_t sshbuf1[] =
"SSH-";
1088 uint8_t sshbuf2[] =
"2.0-MySSHClient-0.5.1\r\n";
1089 uint8_t server2[] = { 0x00, 0x00, 0x00, 0x03, 0x01, 21, 0x00 };
1090 uint8_t sshbuf3[] = { 0x00, 0x00, 0x00, 0x03, 0x01, 21, 0x00 };
1093 memset(&
tv, 0x00,
sizeof(
tv));
1101 uint8_t* sshbufs[5] = {server1, sshbuf1, sshbuf2, server2, sshbuf3};
1102 uint32_t sshlens[5] = {
sizeof(server1) - 1,
sizeof(sshbuf1) - 1,
sizeof(sshbuf2) -1,
sizeof(server2) - 1,
sizeof(sshbuf3)};
1103 bool sshdirs[5] = {
true,
false,
false,
true,
false};
1105 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
1108 f->
proto = IPPROTO_TCP;
1113 p->
proto = IPPROTO_TCP;
1116 uint32_t seqcli = 2;
1117 uint32_t seqsrv = 2;
1118 for (
int i=0; i<5; i++) {
1121 seqsrv += sshlens[i];
1125 seqcli += sshlens[i];
1132 void *tx = SCSshStateGetTx(ssh_state, 0);
1133 FAIL_IF(SCSshTxGetFlags(tx, STREAM_TOCLIENT) != SshStateFinished);
1145 static int SSHParserTest19(
void)
1153 uint8_t sshbuf1[] =
"SSH-";
1154 uint8_t sshbuf2[] =
"2.0-";
1155 uint8_t sshbuf3[] =
"abcdefghijklmnopqrstuvwxyz"
1156 "abcdefghijklmnopqrstuvwxyz"
1157 "abcdefghijklmnopqrstuvwxyz"
1158 "abcdefghijklmnopqrstuvwxyz"
1159 "abcdefghijklmnopqrstuvwxyz"
1160 "abcdefghijklmnopqrstuvwxyz"
1161 "abcdefghijklmnopqrstuvwxyz"
1162 "abcdefghijklmnopqrstuvwxyz"
1163 "abcdefghijklmnopqrstuvwxyz"
1165 uint8_t sshbuf4[] = { 0x00, 0x00, 0x00, 0x03, 0x01, 21, 0x00};
1167 uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
1168 uint32_t sshlens[4] = {
sizeof(sshbuf1) - 1,
sizeof(sshbuf2) - 1,
sizeof(sshbuf3) - 1,
sizeof(sshbuf4)};
1170 memset(&
tv, 0x00,
sizeof(
tv));
1178 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
1181 f->
proto = IPPROTO_TCP;
1186 p->
proto = IPPROTO_TCP;
1190 for (
int i=0; i<4; i++) {
1198 void *tx = SCSshStateGetTx(ssh_state, 0);
1199 FAIL_IF(SCSshTxGetFlags(tx, STREAM_TOCLIENT) != SshStateFinished);
1201 sshbuf3[
sizeof(sshbuf3) - 2] = 0;
1202 FAIL_IF(SSHParserTestUtilCheck(
"2.0", (
char *)sshbuf3, tx, STREAM_TOCLIENT));
1213 static int SSHParserTest20(
void)
1221 uint8_t sshbuf1[] =
"SSH-";
1222 uint8_t sshbuf2[] =
"2.0-";
1223 uint8_t sshbuf3[] =
"abcdefghijklmnopqrstuvwxyz"
1224 "abcdefghijklmnopqrstuvwxyz"
1225 "abcdefghijklmnopqrstuvwxyz"
1226 "abcdefghijklmnopqrstuvwxyz"
1227 "abcdefghijklmnopqrstuvwxyz"
1228 "abcdefghijklmnopqrstuvwxyz"
1229 "abcdefghijklmnopqrstuvwxyz"
1230 "abcdefghijklmnopqrstuvwxyz"
1231 "abcdefghijklmnopqrstuvwxyz"
1233 uint8_t sshbuf4[] = {
'a',
'b',
'c',
'd',
'e',
'f',
'\r',
1234 0x00, 0x00, 0x00, 0x06, 0x01, 21, 0x00, 0x00, 0x00};
1236 uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
1237 uint32_t sshlens[4] = {
sizeof(sshbuf1) - 1,
sizeof(sshbuf2) - 1,
sizeof(sshbuf3) - 1,
sizeof(sshbuf4) - 1};
1239 memset(&
tv, 0x00,
sizeof(
tv));
1247 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
1250 f->
proto = IPPROTO_TCP;
1255 p->
proto = IPPROTO_TCP;
1259 for (
int i=0; i<4; i++) {
1267 void *tx = SCSshStateGetTx(ssh_state, 0);
1268 FAIL_IF(SCSshTxGetFlags(tx, STREAM_TOCLIENT) != SshStateFinished);
1270 FAIL_IF(SSHParserTestUtilCheck(
"2.0", NULL, tx, STREAM_TOCLIENT));
1281 static int SSHParserTest21(
void)
1289 uint8_t sshbuf1[] =
"SSH-";
1290 uint8_t sshbuf2[] =
"2.0-";
1291 uint8_t sshbuf3[] =
"abcdefghijklmnopqrstuvwxyz"
1292 "abcdefghijklmnopqrstuvwxyz"
1293 "abcdefghijklmnopqrstuvwxyz"
1294 "abcdefghijklmnopqrstuvwxyz"
1295 "abcdefghijklmnopqrstuvwxyz"
1296 "abcdefghijklmnopqrstuvwxyz"
1297 "abcdefghijklmnopqrstuvwxyz"
1298 "abcdefghijklmnopqrstuvwxyz"
1299 "abcdefghijklmnopqrstuvwxy";
1300 uint8_t sshbuf4[] = {
'l',
'i',
'b',
's',
's',
'h',
'\r',
1301 0x00, 0x00, 0x00, 0x06, 0x01, 21, 0x00, 0x00, 0x00};
1303 uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
1304 uint32_t sshlens[4] = {
sizeof(sshbuf1) - 1,
sizeof(sshbuf2) - 1,
sizeof(sshbuf3) - 1,
sizeof(sshbuf4)};
1306 memset(&
tv, 0x00,
sizeof(
tv));
1314 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
1317 f->
proto = IPPROTO_TCP;
1322 p->
proto = IPPROTO_TCP;
1326 for (
int i=0; i<4; i++) {
1334 void *tx = SCSshStateGetTx(ssh_state, 0);
1335 FAIL_IF(SCSshTxGetFlags(tx, STREAM_TOCLIENT) != SshStateFinished);
1337 FAIL_IF(SSHParserTestUtilCheck(
"2.0", NULL, tx, STREAM_TOCLIENT));
1348 static int SSHParserTest22(
void)
1356 uint8_t sshbuf1[] =
"SSH-";
1357 uint8_t sshbuf2[] =
"2.0-";
1358 uint8_t sshbuf3[] = {
1359 'l',
'i',
'b',
's',
's',
'h',
'\r',
1361 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1362 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1363 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1364 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1365 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1367 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1368 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1369 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1370 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1371 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1373 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1374 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1375 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1376 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1377 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1379 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1380 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1381 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1382 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1383 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1385 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1386 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1387 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1388 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1389 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1391 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1392 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1393 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1394 0x00, 0x00, 0x00, 0x06, 0x01, 17, 0x00, 0x00, 0x00, 0x00,
1395 0x00, 0x00, 0x00, 0x06, 0x01, 21, 0x00, 0x00, 0x00, 0x00,
1399 uint8_t* sshbufs[3] = {sshbuf1, sshbuf2, sshbuf3};
1400 uint32_t sshlens[3] = {
sizeof(sshbuf1) - 1,
sizeof(sshbuf2) - 1,
sizeof(sshbuf3) - 1};
1402 memset(&
tv, 0x00,
sizeof(
tv));
1410 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
1413 f->
proto = IPPROTO_TCP;
1418 p->
proto = IPPROTO_TCP;
1422 for (
int i=0; i<3; i++) {
1430 void *tx = SCSshStateGetTx(ssh_state, 0);
1431 FAIL_IF(SCSshTxGetFlags(tx, STREAM_TOCLIENT) != SshStateFinished);
1433 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"libssh", tx, STREAM_TOCLIENT));
1443 static int SSHParserTest23(
void)
1447 uint8_t sshbuf[] =
"SSH-2.0\r-MySSHClient-0.5.1\n";
1448 uint32_t sshlen =
sizeof(sshbuf) - 1;
1452 memset(&f, 0,
sizeof(f));
1453 memset(&ssn, 0,
sizeof(ssn));
1461 STREAM_TOSERVER | STREAM_EOF, sshbuf, sshlen);
1463 printf(
"toclient chunk 1 returned 0 expected non null: ");
1477 static int SSHParserTest24(
void)
1481 uint8_t sshbuf[] =
"SSH-2.0-\rMySSHClient-0.5.1\n";
1482 uint32_t sshlen =
sizeof(sshbuf) - 1;
1486 memset(&f, 0,
sizeof(f));
1487 memset(&ssn, 0,
sizeof(ssn));
1495 STREAM_TOSERVER | STREAM_EOF, sshbuf, sshlen);
1497 printf(
"toclient chunk 1 returned %" PRId32
", expected 0: ", r);
1502 if (ssh_state == NULL) {
1503 printf(
"no ssh state: ");
1506 void *tx = SCSshStateGetTx(ssh_state, 0);
1507 if (SCSshTxGetFlags(tx, STREAM_TOSERVER) != SshStateBannerDone) {
1508 printf(
"Didn't detect the msg code of new keys (ciphered data starts): ");
1511 if (SSHParserTestUtilCheck(
"2.0", NULL, tx, STREAM_TOSERVER))
1524 static int SSHParserTest25(
void)
1527 uint8_t sshbuf[] =
"\n";
1528 uint32_t sshlen =
sizeof(sshbuf) - 1;
1533 memset(&f, 0,
sizeof(f));
1534 memset(&ssn, 0,
sizeof(ssn));
1542 STREAM_TOSERVER | STREAM_EOF, sshbuf, sshlen);
1547 void *tx = SCSshStateGetTx(ssh_state, 0);
1548 FAIL_IF(SCSshTxGetFlags(tx, STREAM_TOSERVER) == SshStateBannerDone);
1549 const uint8_t *dummy = NULL;
1550 uint32_t dummy_len = 0;
1551 FAIL_IF(SCSshTxGetSoftware(tx, &dummy, &dummy_len, STREAM_TOCLIENT) != 0);
1570 UtRegisterTest(
"SSHParserTest07 - ToServer 2 chunks", SSHParserTest07);
1571 UtRegisterTest(
"SSHParserTest08 - ToServer 3 chunks", SSHParserTest08);
1572 UtRegisterTest(
"SSHParserTest09 - ToClient 2 chunks", SSHParserTest09);
1573 UtRegisterTest(
"SSHParserTest10 - ToClient 3 chunks", SSHParserTest10);
1574 UtRegisterTest(
"SSHParserTest11 - ToClient 4 chunks", SSHParserTest11);
1575 UtRegisterTest(
"SSHParserTest12 - ToClient 4 chunks", SSHParserTest12);
1576 UtRegisterTest(
"SSHParserTest13 - ToClient 4 chunks", SSHParserTest13);
1577 UtRegisterTest(
"SSHParserTest14 - ToClient 4 chunks", SSHParserTest14);