|
|
21fd01 |
From 1694606e12d8950b003ff86248883732ef05e00c Mon Sep 17 00:00:00 2001
|
|
|
21fd01 |
From: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
|
|
|
21fd01 |
Date: Fri, 19 Jun 2020 11:59:33 +0200
|
|
|
21fd01 |
Subject: [PATCH] tests: Add test for CVE-2019-14889
|
|
|
21fd01 |
|
|
|
21fd01 |
The test checks if a command appended to the file path is not executed.
|
|
|
21fd01 |
|
|
|
21fd01 |
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
|
|
|
21fd01 |
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
|
|
|
21fd01 |
---
|
|
|
21fd01 |
tests/client/torture_scp.c | 84 ++++++++++++++++++++++++++++++++++++++
|
|
|
21fd01 |
1 file changed, 84 insertions(+)
|
|
|
21fd01 |
|
|
|
21fd01 |
diff --git a/tests/client/torture_scp.c b/tests/client/torture_scp.c
|
|
|
21fd01 |
index 8f080af3..59a00bae 100644
|
|
|
21fd01 |
--- a/tests/client/torture_scp.c
|
|
|
21fd01 |
+++ b/tests/client/torture_scp.c
|
|
|
21fd01 |
@@ -37,6 +37,7 @@
|
|
|
21fd01 |
#define BUF_SIZE 1024
|
|
|
21fd01 |
|
|
|
21fd01 |
#define TEMPLATE BINARYDIR "/tests/home/alice/temp_dir_XXXXXX"
|
|
|
21fd01 |
+#define ALICE_HOME BINARYDIR "/tests/home/alice"
|
|
|
21fd01 |
|
|
|
21fd01 |
struct scp_st {
|
|
|
21fd01 |
struct torture_state *s;
|
|
|
21fd01 |
@@ -540,6 +541,86 @@ static void torture_scp_upload_newline(void **state)
|
|
|
21fd01 |
fclose(file);
|
|
|
21fd01 |
}
|
|
|
21fd01 |
|
|
|
21fd01 |
+static void torture_scp_upload_appended_command(void **state)
|
|
|
21fd01 |
+{
|
|
|
21fd01 |
+ struct scp_st *ts = NULL;
|
|
|
21fd01 |
+ struct torture_state *s = NULL;
|
|
|
21fd01 |
+
|
|
|
21fd01 |
+ ssh_session session = NULL;
|
|
|
21fd01 |
+ ssh_scp scp = NULL;
|
|
|
21fd01 |
+
|
|
|
21fd01 |
+ FILE *file = NULL;
|
|
|
21fd01 |
+
|
|
|
21fd01 |
+ char buf[1024];
|
|
|
21fd01 |
+ char *rs = NULL;
|
|
|
21fd01 |
+ int rc;
|
|
|
21fd01 |
+
|
|
|
21fd01 |
+ assert_non_null(state);
|
|
|
21fd01 |
+ ts = *state;
|
|
|
21fd01 |
+
|
|
|
21fd01 |
+ assert_non_null(ts->s);
|
|
|
21fd01 |
+ s = ts->s;
|
|
|
21fd01 |
+
|
|
|
21fd01 |
+ session = s->ssh.session;
|
|
|
21fd01 |
+ assert_non_null(session);
|
|
|
21fd01 |
+
|
|
|
21fd01 |
+ assert_non_null(ts->tmp_dir_basename);
|
|
|
21fd01 |
+ assert_non_null(ts->tmp_dir);
|
|
|
21fd01 |
+
|
|
|
21fd01 |
+ /* Upload a file path with a command appended */
|
|
|
21fd01 |
+
|
|
|
21fd01 |
+ /* Append a command to the file path */
|
|
|
21fd01 |
+ snprintf(buf, BUF_SIZE, "%s"
|
|
|
21fd01 |
+ "/;touch hack",
|
|
|
21fd01 |
+ ts->tmp_dir);
|
|
|
21fd01 |
+
|
|
|
21fd01 |
+ /* When writing the file_name must be the directory name */
|
|
|
21fd01 |
+ scp = ssh_scp_new(session, SSH_SCP_WRITE | SSH_SCP_RECURSIVE,
|
|
|
21fd01 |
+ buf);
|
|
|
21fd01 |
+ assert_non_null(scp);
|
|
|
21fd01 |
+
|
|
|
21fd01 |
+ rc = ssh_scp_init(scp);
|
|
|
21fd01 |
+ assert_ssh_return_code(session, rc);
|
|
|
21fd01 |
+
|
|
|
21fd01 |
+ /* Push directory where the new file will be copied */
|
|
|
21fd01 |
+ rc = ssh_scp_push_directory(scp, ";touch hack", 0755);
|
|
|
21fd01 |
+ assert_ssh_return_code(session, rc);
|
|
|
21fd01 |
+
|
|
|
21fd01 |
+ /* Try to push file */
|
|
|
21fd01 |
+ rc = ssh_scp_push_file(scp, "original", 8, 0644);
|
|
|
21fd01 |
+ assert_ssh_return_code(session, rc);
|
|
|
21fd01 |
+
|
|
|
21fd01 |
+ rc = ssh_scp_write(scp, "original", 8);
|
|
|
21fd01 |
+ assert_ssh_return_code(session, rc);
|
|
|
21fd01 |
+
|
|
|
21fd01 |
+ /* Leave the directory */
|
|
|
21fd01 |
+ rc = ssh_scp_leave_directory(scp);
|
|
|
21fd01 |
+ assert_ssh_return_code(session, rc);
|
|
|
21fd01 |
+
|
|
|
21fd01 |
+ /* Cleanup */
|
|
|
21fd01 |
+ ssh_scp_close(scp);
|
|
|
21fd01 |
+ ssh_scp_free(scp);
|
|
|
21fd01 |
+
|
|
|
21fd01 |
+ /* Make sure the command was not executed */
|
|
|
21fd01 |
+ snprintf(buf, BUF_SIZE, ALICE_HOME "/hack");
|
|
|
21fd01 |
+ file = fopen(buf, "r");
|
|
|
21fd01 |
+ assert_null(file);
|
|
|
21fd01 |
+
|
|
|
21fd01 |
+ /* Open the file and check content */
|
|
|
21fd01 |
+ snprintf(buf, BUF_SIZE, "%s"
|
|
|
21fd01 |
+ "/;touch hack/original",
|
|
|
21fd01 |
+ ts->tmp_dir);
|
|
|
21fd01 |
+
|
|
|
21fd01 |
+ file = fopen(buf, "r");
|
|
|
21fd01 |
+ assert_non_null(file);
|
|
|
21fd01 |
+
|
|
|
21fd01 |
+ rs = fgets(buf, 1024, file);
|
|
|
21fd01 |
+ assert_non_null(rs);
|
|
|
21fd01 |
+ assert_string_equal(buf, "original");
|
|
|
21fd01 |
+
|
|
|
21fd01 |
+ fclose(file);
|
|
|
21fd01 |
+}
|
|
|
21fd01 |
+
|
|
|
21fd01 |
int torture_run_tests(void)
|
|
|
21fd01 |
{
|
|
|
21fd01 |
int rc;
|
|
|
21fd01 |
@@ -559,6 +640,9 @@ int torture_run_tests(void)
|
|
|
21fd01 |
cmocka_unit_test_setup_teardown(torture_scp_upload_newline,
|
|
|
21fd01 |
session_setup,
|
|
|
21fd01 |
session_teardown),
|
|
|
21fd01 |
+ cmocka_unit_test_setup_teardown(torture_scp_upload_appended_command,
|
|
|
21fd01 |
+ session_setup,
|
|
|
21fd01 |
+ session_teardown),
|
|
|
21fd01 |
};
|
|
|
21fd01 |
|
|
|
21fd01 |
ssh_init();
|
|
|
21fd01 |
--
|
|
|
21fd01 |
2.26.2
|
|
|
21fd01 |
|