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 rs_ssh_tx_get_log_condition(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) {
104 rs_ssh_enable_hassh();
109 rs_ssh_register_parser();
123 static int SSHParserTestUtilCheck(
const char *protoexp,
const char *softexp,
void *tx, uint8_t
flags) {
126 const uint8_t *software = NULL;
129 if (rs_ssh_tx_get_protocol(tx, &
protocol, &p_len,
flags) != 1) {
130 printf(
"Version string not parsed correctly return: ");
134 printf(
"Version string not parsed correctly NULL: ");
138 if (p_len != strlen(protoexp)) {
139 printf(
"Version string not parsed correctly length: ");
142 if (memcmp(
protocol, protoexp, strlen(protoexp)) != 0) {
143 printf(
"Version string not parsed correctly: ");
147 if (softexp != NULL) {
148 if (rs_ssh_tx_get_software(tx, &software, &s_len,
flags) != 1)
150 if (software == NULL)
152 if (s_len != strlen(softexp)) {
153 printf(
"Software string not parsed correctly length: ");
156 if (memcmp(software, softexp, strlen(softexp)) != 0) {
157 printf(
"Software string not parsed correctly: ");
165 static int SSHParserTest01(
void)
169 uint8_t sshbuf[] =
"SSH-2.0-MySSHClient-0.5.1\n";
170 uint32_t sshlen =
sizeof(sshbuf) - 1;
174 memset(&f, 0,
sizeof(f));
175 memset(&ssn, 0,
sizeof(ssn));
183 STREAM_TOSERVER | STREAM_EOF, sshbuf, sshlen);
185 printf(
"toclient chunk 1 returned %" PRId32
", expected 0: ", r);
190 if (ssh_state == NULL) {
191 printf(
"no ssh state: ");
195 void * tx = rs_ssh_state_get_tx(ssh_state, 0);
196 if ( rs_ssh_tx_get_alstate_progress(tx, STREAM_TOSERVER) != SshStateBannerDone ) {
197 printf(
"Client version string not parsed: ");
201 if (SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOSERVER))
216 static int SSHParserTest02(
void)
220 uint8_t sshbuf[] =
"SSH-2.0-MySSHClient-0.5.1 some comments...\n";
221 uint32_t sshlen =
sizeof(sshbuf) - 1;
225 memset(&f, 0,
sizeof(f));
226 memset(&ssn, 0,
sizeof(ssn));
234 STREAM_TOSERVER | STREAM_EOF, sshbuf, sshlen);
236 printf(
"toclient chunk 1 returned %" PRId32
", expected 0: ", r);
241 if (ssh_state == NULL) {
242 printf(
"no ssh state: ");
245 void * tx = rs_ssh_state_get_tx(ssh_state, 0);
247 if ( rs_ssh_tx_get_alstate_progress(tx, STREAM_TOSERVER) != SshStateBannerDone ) {
248 printf(
"Client version string not parsed: ");
251 if (SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOSERVER))
266 static int SSHParserTest03(
void)
270 uint8_t sshbuf[] =
"SSH-2.0 some comments...\n";
271 uint32_t sshlen =
sizeof(sshbuf) - 1;
275 memset(&f, 0,
sizeof(f));
276 memset(&ssn, 0,
sizeof(ssn));
284 STREAM_TOSERVER | STREAM_EOF, sshbuf, sshlen);
286 printf(
"toclient chunk 1 returned %" PRId32
", expected != 0: ", r);
291 if (ssh_state == NULL) {
292 printf(
"no ssh state: ");
295 void * tx = rs_ssh_state_get_tx(ssh_state, 0);
297 if ( rs_ssh_tx_get_alstate_progress(tx, STREAM_TOSERVER) == SshStateBannerDone ) {
298 printf(
"Client version string parsed? It's not a valid string: ");
301 const uint8_t *dummy = NULL;
302 uint32_t dummy_len = 0;
303 if (rs_ssh_tx_get_protocol(tx, &dummy, &dummy_len, STREAM_TOSERVER) != 0)
305 if (rs_ssh_tx_get_software(tx, &dummy, &dummy_len, STREAM_TOSERVER) != 0)
318 static int SSHParserTest04(
void)
322 uint8_t sshbuf[] =
"SSH-2.0-MySSHClient-0.5.1\n";
323 uint32_t sshlen =
sizeof(sshbuf) - 1;
327 memset(&f, 0,
sizeof(f));
328 memset(&ssn, 0,
sizeof(ssn));
336 STREAM_TOCLIENT | STREAM_EOF, sshbuf, sshlen);
338 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
343 if (ssh_state == NULL) {
344 printf(
"no ssh state: ");
347 void * tx = rs_ssh_state_get_tx(ssh_state, 0);
349 if ( rs_ssh_tx_get_alstate_progress(tx, STREAM_TOCLIENT) != SshStateBannerDone ) {
350 printf(
"Client version string not parsed: ");
353 if (SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOCLIENT))
368 static int SSHParserTest05(
void)
372 uint8_t sshbuf[] =
"SSH-2.0-MySSHClient-0.5.1 some comments...\n";
373 uint32_t sshlen =
sizeof(sshbuf) - 1;
377 memset(&f, 0,
sizeof(f));
378 memset(&ssn, 0,
sizeof(ssn));
386 STREAM_TOCLIENT | STREAM_EOF, sshbuf, sshlen);
388 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
393 if (ssh_state == NULL) {
394 printf(
"no ssh state: ");
397 void * tx = rs_ssh_state_get_tx(ssh_state, 0);
399 if ( rs_ssh_tx_get_alstate_progress(tx, STREAM_TOCLIENT) != SshStateBannerDone ) {
400 printf(
"Client version string not parsed: ");
403 if (SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOCLIENT))
417 static int SSHParserTest06(
void)
421 uint8_t sshbuf[] =
"SSH-2.0 some comments...\n";
422 uint32_t sshlen =
sizeof(sshbuf) - 1;
426 memset(&f, 0,
sizeof(f));
427 memset(&ssn, 0,
sizeof(ssn));
435 STREAM_TOCLIENT | STREAM_EOF, sshbuf, sshlen);
437 printf(
"toserver chunk 1 returned %" PRId32
", expected != 0: ", r);
443 if (ssh_state == NULL) {
444 printf(
"no ssh state: ");
447 void * tx = rs_ssh_state_get_tx(ssh_state, 0);
449 if ( rs_ssh_tx_get_alstate_progress(tx, STREAM_TOCLIENT) == SshStateBannerDone ) {
450 printf(
"Client version string parsed? It's not a valid string: ");
453 const uint8_t *dummy = NULL;
454 uint32_t dummy_len = 0;
455 if (rs_ssh_tx_get_protocol(tx, &dummy, &dummy_len, STREAM_TOCLIENT) != 0)
457 if (rs_ssh_tx_get_software(tx, &dummy, &dummy_len, STREAM_TOCLIENT) != 0)
470 #define MAX_SSH_TEST_SIZE 512
472 static int SSHParserTest07(
void)
482 memset(&
tv, 0x00,
sizeof(
tv));
490 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
493 f->
proto = IPPROTO_TCP;
498 p->
proto = IPPROTO_TCP;
502 for (
int i=0; i<2; i++) {
504 seq += strlen(sshbufs[i]);
510 void * tx = rs_ssh_state_get_tx(ssh_state, 0);
511 FAIL_IF( rs_ssh_tx_get_alstate_progress(tx, STREAM_TOSERVER) != SshStateBannerDone );
513 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOSERVER));
523 static int SSHParserTest08(
void)
533 memset(&
tv, 0x00,
sizeof(
tv));
541 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
544 f->
proto = IPPROTO_TCP;
549 p->
proto = IPPROTO_TCP;
553 for (
int i=0; i<3; i++) {
555 seq += strlen(sshbufs[i]);
561 void * tx = rs_ssh_state_get_tx(ssh_state, 0);
562 FAIL_IF( rs_ssh_tx_get_alstate_progress(tx, STREAM_TOSERVER) != SshStateBannerDone );
564 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOSERVER));
573 static int SSHParserTest09(
void)
583 memset(&
tv, 0x00,
sizeof(
tv));
591 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
594 f->
proto = IPPROTO_TCP;
599 p->
proto = IPPROTO_TCP;
603 for (
int i=0; i<2; i++) {
605 seq += strlen(sshbufs[i]);
611 void * tx = rs_ssh_state_get_tx(ssh_state, 0);
612 FAIL_IF( rs_ssh_tx_get_alstate_progress(tx, STREAM_TOCLIENT) != SshStateBannerDone );
614 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOCLIENT));
624 static int SSHParserTest10(
void)
634 memset(&
tv, 0x00,
sizeof(
tv));
642 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
645 f->
proto = IPPROTO_TCP;
650 p->
proto = IPPROTO_TCP;
654 for (
int i=0; i<3; i++) {
656 seq += strlen(sshbufs[i]);
662 void * tx = rs_ssh_state_get_tx(ssh_state, 0);
663 FAIL_IF( rs_ssh_tx_get_alstate_progress(tx, STREAM_TOCLIENT) != SshStateBannerDone );
665 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOCLIENT));
675 static int SSHParserTest11(
void)
679 uint8_t sshbuf1[] =
"SSH-2.0-MySSHClient-0.5.1\r\n";
680 uint32_t sshlen1 =
sizeof(sshbuf1) - 1;
681 uint8_t sshbuf2[] = { 0x00, 0x00, 0x00, 0x03, 0x01, 21, 0x00};
682 uint32_t sshlen2 =
sizeof(sshbuf2);
686 memset(&f, 0,
sizeof(f));
687 memset(&ssn, 0,
sizeof(ssn));
695 STREAM_TOSERVER, sshbuf1, sshlen1);
697 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
703 printf(
"toserver chunk 2 returned %" PRId32
", expected 0: ", r);
708 if (ssh_state == NULL) {
709 printf(
"no ssh state: ");
712 void * tx = rs_ssh_state_get_tx(ssh_state, 0);
713 if ( rs_ssh_tx_get_flags(tx, STREAM_TOSERVER) != SshStateFinished ) {
714 printf(
"Didn't detect the msg code of new keys (ciphered data starts): ");
717 if (SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOSERVER))
730 static int SSHParserTest12(
void)
734 uint8_t sshbuf1[] =
"SSH-2.0-MySSHClient-0.5.1\r\n";
735 uint32_t sshlen1 =
sizeof(sshbuf1) - 1;
736 uint8_t sshbuf2[] = { 0x00, 0x00, 0x00, 0x03,0x01, 17, 0x00};
737 uint32_t sshlen2 =
sizeof(sshbuf2);
738 uint8_t sshbuf3[] = { 0x00, 0x00, 0x00, 0x03,0x01, 21, 0x00};
739 uint32_t sshlen3 =
sizeof(sshbuf3);
743 memset(&f, 0,
sizeof(f));
744 memset(&ssn, 0,
sizeof(ssn));
752 STREAM_TOSERVER, sshbuf1, sshlen1);
754 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
760 printf(
"toserver chunk 2 returned %" PRId32
", expected 0: ", r);
766 printf(
"toserver chunk 3 returned %" PRId32
", expected 0: ", r);
771 if (ssh_state == NULL) {
772 printf(
"no ssh state: ");
775 void * tx = rs_ssh_state_get_tx(ssh_state, 0);
776 if ( rs_ssh_tx_get_flags(tx, STREAM_TOSERVER) != SshStateFinished ) {
777 printf(
"Didn't detect the msg code of new keys (ciphered data starts): ");
780 if (SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOSERVER))
793 static int SSHParserTest13(
void)
801 uint8_t sshbuf1[] =
"SSH-2.0-MySSHClient-0.5.1\r\n";
802 uint8_t sshbuf2[] = { 0x00, 0x00, 0x00, 0x02, 0x01, 17};
803 uint8_t sshbuf3[] = { 0x00, 0x00, 0x00, 0x02, 0x01, 21};
805 uint8_t* sshbufs[3] = {sshbuf1, sshbuf2, sshbuf3};
806 uint32_t sshlens[3] = {
sizeof(sshbuf1) - 1,
sizeof(sshbuf2),
sizeof(sshbuf3)};
808 memset(&
tv, 0x00,
sizeof(
tv));
816 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
819 f->
proto = IPPROTO_TCP;
824 p->
proto = IPPROTO_TCP;
828 for (
int i=0; i<3; i++) {
836 void * tx = rs_ssh_state_get_tx(ssh_state, 0);
837 FAIL_IF( rs_ssh_tx_get_flags(tx, STREAM_TOSERVER) != SshStateFinished );
839 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOSERVER));
849 static int SSHParserTest14(
void)
857 uint8_t sshbuf1[] =
"SSH-2.0-MySSHClient-0.5.1\r\n";
858 uint8_t sshbuf2[] = { 0x00, 0x00, 0x00, 0x10, 0x01, 17, 0x00};
859 uint8_t sshbuf3[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
860 uint8_t sshbuf4[] = { 0x09, 0x10, 0x11, 0x12, 0x13, 0x00};
862 uint8_t sshbuf5[] = { 0x00, 0x00, 0x02, 0x01, 21};
864 uint8_t* sshbufs[5] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4, sshbuf5};
865 uint32_t sshlens[5] = {
sizeof(sshbuf1) - 1,
sizeof(sshbuf2),
sizeof(sshbuf3),
sizeof(sshbuf4),
sizeof(sshbuf5)};
867 memset(&
tv, 0x00,
sizeof(
tv));
875 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
878 f->
proto = IPPROTO_TCP;
883 p->
proto = IPPROTO_TCP;
887 for (
int i=0; i<5; i++) {
895 void * tx = rs_ssh_state_get_tx(ssh_state, 0);
896 FAIL_IF( rs_ssh_tx_get_flags(tx, STREAM_TOSERVER) != SshStateFinished );
898 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOSERVER));
908 static int SSHParserTest15(
void)
916 uint8_t sshbuf1[] =
"SSH-2.0-MySSHClient-0.5.1\r\n";
917 uint8_t sshbuf2[] = { 0x00, 0x00, 0x00, 0x10, 0x01, 17, 0x00};
918 uint8_t sshbuf3[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
919 uint8_t sshbuf4[] = { 0x09, 0x10, 0x11, 0x12, 0x13, 0x00};
920 uint8_t sshbuf5[] = { 0x00, 0x00, 0x02, 0x01, 20, 0x00, 0x00, 0x00, 0x02, 0x01, 21};
922 uint8_t* sshbufs[5] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4, sshbuf5};
923 uint32_t sshlens[5] = {
sizeof(sshbuf1) - 1,
sizeof(sshbuf2),
sizeof(sshbuf3),
sizeof(sshbuf4),
sizeof(sshbuf5)};
925 memset(&
tv, 0x00,
sizeof(
tv));
933 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
936 f->
proto = IPPROTO_TCP;
941 p->
proto = IPPROTO_TCP;
945 for (
int i=0; i<5; i++) {
953 void * tx = rs_ssh_state_get_tx(ssh_state, 0);
954 FAIL_IF( rs_ssh_tx_get_flags(tx, STREAM_TOSERVER) != SshStateFinished );
956 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOSERVER));
966 static int SSHParserTest16(
void)
974 uint8_t sshbuf1[] =
"SSH-";
975 uint8_t sshbuf2[] =
"2.0-MySSHClient-0.5.1\r\n";
976 uint8_t sshbuf3[] = { 0x00, 0x00, 0x00, 0x03,0x01, 21, 0x00};
978 uint8_t* sshbufs[3] = {sshbuf1, sshbuf2, sshbuf3};
979 uint32_t sshlens[3] = {
sizeof(sshbuf1) - 1,
sizeof(sshbuf2) - 1,
sizeof(sshbuf3)};
981 memset(&
tv, 0x00,
sizeof(
tv));
989 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
992 f->
proto = IPPROTO_TCP;
997 p->
proto = IPPROTO_TCP;
1001 for (
int i=0; i<3; i++) {
1009 void * tx = rs_ssh_state_get_tx(ssh_state, 0);
1010 FAIL_IF( rs_ssh_tx_get_flags(tx, STREAM_TOCLIENT) != SshStateFinished );
1012 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOCLIENT));
1022 static int SSHParserTest17(
void)
1030 uint8_t sshbuf1[] =
"SSH-";
1031 uint8_t sshbuf2[] =
"2.0-MySSHClient-0.5.1\r\n";
1032 uint8_t sshbuf3[] = { 0x00, 0x00, 0x00, 0x03, 0x01, 17, 0x00};
1033 uint8_t sshbuf4[] = { 0x00, 0x00, 0x00, 0x03, 0x01, 21, 0x00};
1035 uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
1036 uint32_t sshlens[4] = {
sizeof(sshbuf1) - 1,
sizeof(sshbuf2) - 1,
sizeof(sshbuf3),
sizeof(sshbuf4)};
1038 memset(&
tv, 0x00,
sizeof(
tv));
1046 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
1049 f->
proto = IPPROTO_TCP;
1054 p->
proto = IPPROTO_TCP;
1058 for (
int i=0; i<4; i++) {
1066 void * tx = rs_ssh_state_get_tx(ssh_state, 0);
1067 FAIL_IF( rs_ssh_tx_get_flags(tx, STREAM_TOCLIENT) != SshStateFinished );
1069 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"MySSHClient-0.5.1", tx, STREAM_TOCLIENT));
1079 static int SSHParserTest18(
void)
1087 uint8_t server1[] =
"SSH-2.0-OpenSSH_4.7p1 Debian-8ubuntu3\r\n";
1088 uint8_t sshbuf1[] =
"SSH-";
1089 uint8_t sshbuf2[] =
"2.0-MySSHClient-0.5.1\r\n";
1090 uint8_t server2[] = { 0x00, 0x00, 0x00, 0x03, 0x01, 21, 0x00 };
1091 uint8_t sshbuf3[] = { 0x00, 0x00, 0x00, 0x03, 0x01, 21, 0x00 };
1094 memset(&
tv, 0x00,
sizeof(
tv));
1102 uint8_t* sshbufs[5] = {server1, sshbuf1, sshbuf2, server2, sshbuf3};
1103 uint32_t sshlens[5] = {
sizeof(server1) - 1,
sizeof(sshbuf1) - 1,
sizeof(sshbuf2) -1,
sizeof(server2) - 1,
sizeof(sshbuf3)};
1104 bool sshdirs[5] = {
true,
false,
false,
true,
false};
1106 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
1109 f->
proto = IPPROTO_TCP;
1114 p->
proto = IPPROTO_TCP;
1117 uint32_t seqcli = 2;
1118 uint32_t seqsrv = 2;
1119 for (
int i=0; i<5; i++) {
1122 seqsrv += sshlens[i];
1126 seqcli += sshlens[i];
1133 void * tx = rs_ssh_state_get_tx(ssh_state, 0);
1134 FAIL_IF( rs_ssh_tx_get_flags(tx, STREAM_TOCLIENT) != SshStateFinished );
1146 static int SSHParserTest19(
void)
1154 uint8_t sshbuf1[] =
"SSH-";
1155 uint8_t sshbuf2[] =
"2.0-";
1156 uint8_t sshbuf3[] =
"abcdefghijklmnopqrstuvwxyz"
1157 "abcdefghijklmnopqrstuvwxyz"
1158 "abcdefghijklmnopqrstuvwxyz"
1159 "abcdefghijklmnopqrstuvwxyz"
1160 "abcdefghijklmnopqrstuvwxyz"
1161 "abcdefghijklmnopqrstuvwxyz"
1162 "abcdefghijklmnopqrstuvwxyz"
1163 "abcdefghijklmnopqrstuvwxyz"
1164 "abcdefghijklmnopqrstuvwxyz"
1166 uint8_t sshbuf4[] = { 0x00, 0x00, 0x00, 0x03, 0x01, 21, 0x00};
1168 uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
1169 uint32_t sshlens[4] = {
sizeof(sshbuf1) - 1,
sizeof(sshbuf2) - 1,
sizeof(sshbuf3) - 1,
sizeof(sshbuf4)};
1171 memset(&
tv, 0x00,
sizeof(
tv));
1179 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
1182 f->
proto = IPPROTO_TCP;
1187 p->
proto = IPPROTO_TCP;
1191 for (
int i=0; i<4; i++) {
1199 void * tx = rs_ssh_state_get_tx(ssh_state, 0);
1200 FAIL_IF( rs_ssh_tx_get_flags(tx, STREAM_TOCLIENT) != SshStateFinished );
1202 sshbuf3[
sizeof(sshbuf3) - 2] = 0;
1203 FAIL_IF(SSHParserTestUtilCheck(
"2.0", (
char *)sshbuf3, tx, STREAM_TOCLIENT));
1214 static int SSHParserTest20(
void)
1222 uint8_t sshbuf1[] =
"SSH-";
1223 uint8_t sshbuf2[] =
"2.0-";
1224 uint8_t sshbuf3[] =
"abcdefghijklmnopqrstuvwxyz"
1225 "abcdefghijklmnopqrstuvwxyz"
1226 "abcdefghijklmnopqrstuvwxyz"
1227 "abcdefghijklmnopqrstuvwxyz"
1228 "abcdefghijklmnopqrstuvwxyz"
1229 "abcdefghijklmnopqrstuvwxyz"
1230 "abcdefghijklmnopqrstuvwxyz"
1231 "abcdefghijklmnopqrstuvwxyz"
1232 "abcdefghijklmnopqrstuvwxyz"
1234 uint8_t sshbuf4[] = {
'a',
'b',
'c',
'd',
'e',
'f',
'\r',
1235 0x00, 0x00, 0x00, 0x06, 0x01, 21, 0x00, 0x00, 0x00};
1237 uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
1238 uint32_t sshlens[4] = {
sizeof(sshbuf1) - 1,
sizeof(sshbuf2) - 1,
sizeof(sshbuf3) - 1,
sizeof(sshbuf4) - 1};
1240 memset(&
tv, 0x00,
sizeof(
tv));
1248 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
1251 f->
proto = IPPROTO_TCP;
1256 p->
proto = IPPROTO_TCP;
1260 for (
int i=0; i<4; i++) {
1268 void * tx = rs_ssh_state_get_tx(ssh_state, 0);
1269 FAIL_IF( rs_ssh_tx_get_flags(tx, STREAM_TOCLIENT) != SshStateFinished );
1271 FAIL_IF(SSHParserTestUtilCheck(
"2.0", NULL, tx, STREAM_TOCLIENT));
1282 static int SSHParserTest21(
void)
1290 uint8_t sshbuf1[] =
"SSH-";
1291 uint8_t sshbuf2[] =
"2.0-";
1292 uint8_t sshbuf3[] =
"abcdefghijklmnopqrstuvwxyz"
1293 "abcdefghijklmnopqrstuvwxyz"
1294 "abcdefghijklmnopqrstuvwxyz"
1295 "abcdefghijklmnopqrstuvwxyz"
1296 "abcdefghijklmnopqrstuvwxyz"
1297 "abcdefghijklmnopqrstuvwxyz"
1298 "abcdefghijklmnopqrstuvwxyz"
1299 "abcdefghijklmnopqrstuvwxyz"
1300 "abcdefghijklmnopqrstuvwxy";
1301 uint8_t sshbuf4[] = {
'l',
'i',
'b',
's',
's',
'h',
'\r',
1302 0x00, 0x00, 0x00, 0x06, 0x01, 21, 0x00, 0x00, 0x00};
1304 uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
1305 uint32_t sshlens[4] = {
sizeof(sshbuf1) - 1,
sizeof(sshbuf2) - 1,
sizeof(sshbuf3) - 1,
sizeof(sshbuf4)};
1307 memset(&
tv, 0x00,
sizeof(
tv));
1315 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
1318 f->
proto = IPPROTO_TCP;
1323 p->
proto = IPPROTO_TCP;
1327 for (
int i=0; i<4; i++) {
1335 void * tx = rs_ssh_state_get_tx(ssh_state, 0);
1336 FAIL_IF( rs_ssh_tx_get_flags(tx, STREAM_TOCLIENT) != SshStateFinished );
1338 FAIL_IF(SSHParserTestUtilCheck(
"2.0", NULL, tx, STREAM_TOCLIENT));
1349 static int SSHParserTest22(
void)
1357 uint8_t sshbuf1[] =
"SSH-";
1358 uint8_t sshbuf2[] =
"2.0-";
1359 uint8_t sshbuf3[] = {
1360 'l',
'i',
'b',
's',
's',
'h',
'\r',
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,
1366 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,
1372 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,
1378 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,
1384 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,
1390 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, 17, 0x00, 0x00, 0x00, 0x00,
1396 0x00, 0x00, 0x00, 0x06, 0x01, 21, 0x00, 0x00, 0x00, 0x00,
1400 uint8_t* sshbufs[3] = {sshbuf1, sshbuf2, sshbuf3};
1401 uint32_t sshlens[3] = {
sizeof(sshbuf1) - 1,
sizeof(sshbuf2) - 1,
sizeof(sshbuf3) - 1};
1403 memset(&
tv, 0x00,
sizeof(
tv));
1411 f =
UTHBuildFlow(AF_INET,
"1.1.1.1",
"2.2.2.2", 1234, 2222);
1414 f->
proto = IPPROTO_TCP;
1419 p->
proto = IPPROTO_TCP;
1423 for (
int i=0; i<3; i++) {
1431 void * tx = rs_ssh_state_get_tx(ssh_state, 0);
1432 FAIL_IF( rs_ssh_tx_get_flags(tx, STREAM_TOCLIENT) != SshStateFinished );
1434 FAIL_IF(SSHParserTestUtilCheck(
"2.0",
"libssh", tx, STREAM_TOCLIENT));
1444 static int SSHParserTest23(
void)
1448 uint8_t sshbuf[] =
"SSH-2.0\r-MySSHClient-0.5.1\n";
1449 uint32_t sshlen =
sizeof(sshbuf) - 1;
1453 memset(&f, 0,
sizeof(f));
1454 memset(&ssn, 0,
sizeof(ssn));
1462 STREAM_TOSERVER | STREAM_EOF, sshbuf, sshlen);
1464 printf(
"toclient chunk 1 returned 0 expected non null: ");
1478 static int SSHParserTest24(
void)
1482 uint8_t sshbuf[] =
"SSH-2.0-\rMySSHClient-0.5.1\n";
1483 uint32_t sshlen =
sizeof(sshbuf) - 1;
1487 memset(&f, 0,
sizeof(f));
1488 memset(&ssn, 0,
sizeof(ssn));
1496 STREAM_TOSERVER | STREAM_EOF, sshbuf, sshlen);
1498 printf(
"toclient chunk 1 returned %" PRId32
", expected 0: ", r);
1503 if (ssh_state == NULL) {
1504 printf(
"no ssh state: ");
1507 void * tx = rs_ssh_state_get_tx(ssh_state, 0);
1508 if ( rs_ssh_tx_get_flags(tx, STREAM_TOSERVER) != SshStateBannerDone ) {
1509 printf(
"Didn't detect the msg code of new keys (ciphered data starts): ");
1512 if (SSHParserTestUtilCheck(
"2.0", NULL, tx, STREAM_TOSERVER))
1525 static int SSHParserTest25(
void)
1528 uint8_t sshbuf[] =
"\n";
1529 uint32_t sshlen =
sizeof(sshbuf) - 1;
1534 memset(&f, 0,
sizeof(f));
1535 memset(&ssn, 0,
sizeof(ssn));
1543 STREAM_TOSERVER | STREAM_EOF, sshbuf, sshlen);
1548 void * tx = rs_ssh_state_get_tx(ssh_state, 0);
1549 FAIL_IF( rs_ssh_tx_get_flags(tx, STREAM_TOSERVER) == SshStateBannerDone );
1550 const uint8_t *dummy = NULL;
1551 uint32_t dummy_len = 0;
1552 FAIL_IF (rs_ssh_tx_get_software(tx, &dummy, &dummy_len, STREAM_TOCLIENT) != 0);
1571 UtRegisterTest(
"SSHParserTest07 - ToServer 2 chunks", SSHParserTest07);
1572 UtRegisterTest(
"SSHParserTest08 - ToServer 3 chunks", SSHParserTest08);
1573 UtRegisterTest(
"SSHParserTest09 - ToClient 2 chunks", SSHParserTest09);
1574 UtRegisterTest(
"SSHParserTest10 - ToClient 3 chunks", SSHParserTest10);
1575 UtRegisterTest(
"SSHParserTest11 - ToClient 4 chunks", SSHParserTest11);
1576 UtRegisterTest(
"SSHParserTest12 - ToClient 4 chunks", SSHParserTest12);
1577 UtRegisterTest(
"SSHParserTest13 - ToClient 4 chunks", SSHParserTest13);
1578 UtRegisterTest(
"SSHParserTest14 - ToClient 4 chunks", SSHParserTest14);