-
Notifications
You must be signed in to change notification settings - Fork 543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement mount-cgroup in Golang style #40
Conversation
Signed-off-by: kmahyyg <16604643+kmahyyg@users.noreply.github.com>
…only Signed-off-by: kmahyyg <16604643+kmahyyg@users.noreply.github.com>
Signed-off-by: kmahyyg <16604643+kmahyyg@users.noreply.github.com>
Signed-off-by: kmahyyg <16604643+kmahyyg@users.noreply.github.com>
…ountinfo Signed-off-by: kmahyyg <16604643+kmahyyg@users.noreply.github.com>
This implemented mount-cgroup exploit totally in Golang. Detailed information: - Change whole "create-mount-write" process using Golang native Unix API. - To avoid conflict, increase length of random string from 3 to 4. Tasks sub-cgroup are also in the same kind of random name. - Read mounted filesystem information from /proc/self/mountinfo, instead of /etc/mtab . - Due to the limitation of exec.Command, output redirect is implemented in another way: manually get pid and write to cgroups.proc Further enhancement: - To read the container filesystem path on the host, implement to read `superBlockOptions` of MountInfo. - To implement CVE-2022-0492 in this PR further, I modified EscapeCgroup function, so that it can be re-used for other subsystems. Chores: - `go mod tidy` Signed-off-by: kmahyyg <16604643+kmahyyg@users.noreply.github.com>
Awesome! Elegant implementation ~ more elegant than half of the code I wrote in TODO. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM~
|
||
// trigger release | ||
// sleep 2s for debug purpose | ||
addProcCmd := exec.Command("/bin/sh", "-c", "sleep 2") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why sleep here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well it need some time to read the PID of spawned /bin/sh
, And also use /bin/sh -c echo $$
then put the command stdout to cgroup.procs
will cause unknown reason error with exit code 1. So I use another way to achieve this.
You could also monitor this behaviour by adding auditd rule -a always,exit -F arch=b64 -S execve -F key=procmon
which made debug much more easier than before.
* feat(exploit/abuse_unpriv_userns.go): exploit of CVE-2022-0942 co-operate with PR #40. Signed-off-by: kmahyyg <16604643+kmahyyg@users.noreply.github.com> Reviewer: neargle
feat(exp/mount_cgroup.go): completely fix #35 in golang-style
This implemented mount-cgroup exploit totally in Golang.
Detailed information:
Tasks sub-cgroup are also in the same kind of random name.
Further enhancement:
superBlockOptions
of MountInfo.Chores:
go mod tidy