__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

[email protected]: ~ $
#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-2.0
#
# Test the "inc" interpreter.
#
# See include/uapi/linux/securebits.h, include/uapi/linux/fcntl.h and
# samples/check-exec/inc.c
#
# Copyright © 2024 Microsoft Corporation

set -u -e -o pipefail

EXPECTED_OUTPUT="1"
exec 2>/dev/null

DIR="$(dirname $(readlink -f "$0"))"
source "${DIR}"/../kselftest/ktap_helpers.sh

exec_direct() {
	local expect="$1"
	local script="$2"
	shift 2
	local ret=0
	local out

	# Updates PATH for `env` to execute the `inc` interpreter.
	out="$(PATH="." "$@" "${script}")" || ret=$?

	if [[ ${ret} -ne ${expect} ]]; then
		echo "ERROR: Wrong expectation for direct file execution: ${ret}"
		return 1
	fi
	if [[ ${ret} -eq 0 && "${out}" != "${EXPECTED_OUTPUT}" ]]; then
		echo "ERROR: Wrong output for direct file execution: ${out}"
		return 1
	fi
}

exec_indirect() {
	local expect="$1"
	local script="$2"
	shift 2
	local ret=0
	local out

	# Script passed as argument.
	out="$("$@" ./inc "${script}")" || ret=$?

	if [[ ${ret} -ne ${expect} ]]; then
		echo "ERROR: Wrong expectation for indirect file execution: ${ret}"
		return 1
	fi
	if [[ ${ret} -eq 0 && "${out}" != "${EXPECTED_OUTPUT}" ]]; then
		echo "ERROR: Wrong output for indirect file execution: ${out}"
		return 1
	fi
}

exec_stdin_reg() {
	local expect="$1"
	local script="$2"
	shift 2
	local ret=0
	local out

	# Executing stdin must be allowed if the related file is executable.
	out="$("$@" ./inc -i < "${script}")" || ret=$?

	if [[ ${ret} -ne ${expect} ]]; then
		echo "ERROR: Wrong expectation for stdin regular file execution: ${ret}"
		return 1
	fi
	if [[ ${ret} -eq 0 && "${out}" != "${EXPECTED_OUTPUT}" ]]; then
		echo "ERROR: Wrong output for stdin regular file execution: ${out}"
		return 1
	fi
}

exec_stdin_pipe() {
	local expect="$1"
	shift
	local ret=0
	local out

	# A pipe is not executable.
	out="$(cat script-exec.inc | "$@" ./inc -i)" || ret=$?

	if [[ ${ret} -ne ${expect} ]]; then
		echo "ERROR: Wrong expectation for stdin pipe execution: ${ret}"
		return 1
	fi
}

exec_argument() {
	local expect="$1"
	local ret=0
	shift
	local out

	# Script not coming from a file must not be executed.
	out="$("$@" ./inc -c "$(< script-exec.inc)")" || ret=$?

	if [[ ${ret} -ne ${expect} ]]; then
		echo "ERROR: Wrong expectation for arbitrary argument execution: ${ret}"
		return 1
	fi
	if [[ ${ret} -eq 0 && "${out}" != "${EXPECTED_OUTPUT}" ]]; then
		echo "ERROR: Wrong output for arbitrary argument execution: ${out}"
		return 1
	fi
}

exec_interactive() {
	exec_stdin_pipe "$@"
	exec_argument "$@"
}

ktap_test() {
	ktap_test_result "$*" "$@"
}

ktap_print_header
ktap_set_plan 28

# Without secbit configuration, nothing is changed.

ktap_print_msg "By default, executable scripts are allowed to be interpreted and executed."
ktap_test exec_direct 0 script-exec.inc
ktap_test exec_indirect 0 script-exec.inc

ktap_print_msg "By default, executable stdin is allowed to be interpreted."
ktap_test exec_stdin_reg 0 script-exec.inc

ktap_print_msg "By default, non-executable scripts are allowed to be interpreted, but not directly executed."
# We get 126 because of direct execution by Bash.
ktap_test exec_direct 126 script-noexec.inc
ktap_test exec_indirect 0 script-noexec.inc

ktap_print_msg "By default, non-executable stdin is allowed to be interpreted."
ktap_test exec_stdin_reg 0 script-noexec.inc

ktap_print_msg "By default, interactive commands are allowed to be interpreted."
ktap_test exec_interactive 0

# With only file restriction: protect non-malicious users from inadvertent errors (e.g. python ~/Downloads/*.py).

ktap_print_msg "With -f, executable scripts are allowed to be interpreted and executed."
ktap_test exec_direct 0 script-exec.inc ./set-exec -f --
ktap_test exec_indirect 0 script-exec.inc ./set-exec -f --

ktap_print_msg "With -f, executable stdin is allowed to be interpreted."
ktap_test exec_stdin_reg 0 script-exec.inc ./set-exec -f --

ktap_print_msg "With -f, non-executable scripts are not allowed to be executed nor interpreted."
# Direct execution of non-executable script is alwayse denied by the kernel.
ktap_test exec_direct 1 script-noexec.inc ./set-exec -f --
ktap_test exec_indirect 1 script-noexec.inc ./set-exec -f --

ktap_print_msg "With -f, non-executable stdin is allowed to be interpreted."
ktap_test exec_stdin_reg 0 script-noexec.inc ./set-exec -f --

ktap_print_msg "With -f, interactive commands are allowed to be interpreted."
ktap_test exec_interactive 0 ./set-exec -f --

# With only denied interactive commands: check or monitor script content (e.g. with LSM).

ktap_print_msg "With -i, executable scripts are allowed to be interpreted and executed."
ktap_test exec_direct 0 script-exec.inc ./set-exec -i --
ktap_test exec_indirect 0 script-exec.inc ./set-exec -i --

ktap_print_msg "With -i, executable stdin is allowed to be interpreted."
ktap_test exec_stdin_reg 0 script-exec.inc ./set-exec -i --

ktap_print_msg "With -i, non-executable scripts are allowed to be interpreted, but not directly executed."
# Direct execution of non-executable script is alwayse denied by the kernel.
ktap_test exec_direct 1 script-noexec.inc ./set-exec -i --
ktap_test exec_indirect 0 script-noexec.inc ./set-exec -i --

ktap_print_msg "With -i, non-executable stdin is not allowed to be interpreted."
ktap_test exec_stdin_reg 1 script-noexec.inc ./set-exec -i --

ktap_print_msg "With -i, interactive commands are not allowed to be interpreted."
ktap_test exec_interactive 1 ./set-exec -i --

# With both file restriction and denied interactive commands: only allow executable scripts.

ktap_print_msg "With -fi, executable scripts are allowed to be interpreted and executed."
ktap_test exec_direct 0 script-exec.inc ./set-exec -fi --
ktap_test exec_indirect 0 script-exec.inc ./set-exec -fi --

ktap_print_msg "With -fi, executable stdin is allowed to be interpreted."
ktap_test exec_stdin_reg 0 script-exec.inc ./set-exec -fi --

ktap_print_msg "With -fi, non-executable scripts are not allowed to be interpreted nor executed."
# Direct execution of non-executable script is alwayse denied by the kernel.
ktap_test exec_direct 1 script-noexec.inc ./set-exec -fi --
ktap_test exec_indirect 1 script-noexec.inc ./set-exec -fi --

ktap_print_msg "With -fi, non-executable stdin is not allowed to be interpreted."
ktap_test exec_stdin_reg 1 script-noexec.inc ./set-exec -fi --

ktap_print_msg "With -fi, interactive commands are not allowed to be interpreted."
ktap_test exec_interactive 1 ./set-exec -fi --

ktap_finished

Filemanager

Name Type Size Permission Actions
Makefile File 1.93 KB 0644
check-exec-tests.sh File 6.38 KB 0755
Filemanager