Skip to content
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

adding event on Redirect stdout/stdin to network connection in container #185

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

h4l0gen
Copy link
Contributor

@h4l0gen h4l0gen commented Mar 20, 2024

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind bug

/kind cleanup

/kind documentation

/kind tests

/kind feature

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area commands

/area pkg

/area events

What this PR does / why we need it:
this PR triggers rule which prevent potential reverse shell or remote code execution.
Which issue(s) this PR fixes:

Fixes #184

Special notes for your reviewer:

@poiana
Copy link

poiana commented Mar 20, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: h4l0gen
Once this PR has been reviewed and has the lgtm label, please assign fededp for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@poiana poiana requested review from FedeDP and leogr March 20, 2024 23:05
@poiana poiana added the size/M label Mar 20, 2024
@h4l0gen h4l0gen changed the title adding event on Redirect stdout/stdin to network connection in container WIP: adding event on Redirect stdout/stdin to network connection in container Apr 9, 2024
@h4l0gen
Copy link
Contributor Author

h4l0gen commented Apr 20, 2024

Hey @leogr and @FedeDP, just an attempt to redirect Stdout is enough to trigger the rule. In this event:

  • Created a listener using the TCP protocol on the container's localhost.
  • Established a client connection using a goroutine.
  • After accepting the connection, called the redirectStdout function.
  • Closed connection and client after excution.

Rule triggered successfully
image

@h4l0gen h4l0gen changed the title WIP: adding event on Redirect stdout/stdin to network connection in container adding event on Redirect stdout/stdin to network connection in container Apr 20, 2024
Comment on lines 57 to 70
func redirectStdout(conn net.Conn) error {
// Duplicate the file descriptor of the network connection
remoteFile, _ := conn.(*net.TCPConn).File()
defer remoteFile.Close()

// Duplicate the file descriptor of stdout
stdoutFile := os.Stdout.Fd()

// Redirect stdout to the network connection using dup2
if err := syscall.Dup2(int(remoteFile.Fd()), int(stdoutFile)); err != nil {
return err
}
return nil
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to me a good candidate for utils_linux.go 🤔 @FedeDP wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree @leogr !

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@h4l0gen h4l0gen May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leogr changes done. PTAL again.

Signed-off-by: h4l0gen <ks3913688@gmail.com>

redirectStdout function shifted to utils_linux.go

Signed-off-by: h4l0gen <ks3913688@gmail.com>

updated

Signed-off-by: h4l0gen <ks3913688@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

event on Redirect STDOUT/STDIN to network connection in container
4 participants