From: John Wood <john.wood@gmx.com>
To: kernelnewbies@kernelnewbies.org
Subject: Test if a socket accept is from external network
Date: Sun, 25 Apr 2021 13:08:41 +0200 [thread overview]
Message-ID: <20210425110841.GA15467@ubuntu> (raw)
Hi,
I'm working in a LSM to detect and mitigate fork brute force attacks
against vulnerable userspace applications. Now, to fine tuning the
detection I want to detect a network activity. To do so, I can use the
following code in the "socket_sock_rcv_skb" hook:
static int brute_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
{
if (!skb->dev || (skb->dev->flags & IFF_LOOPBACK))
return 0;
network_activity = true;
return 0;
}
This way, only external connections are taken into account. Or in other
words, the communication using local sockets are skipped. The drawback
with this approach is that the commented hook is call with every packet
received. So, I have decided to use the hook that is called only when
a connection is accepted: "socket_accept".
static int brute_socket_accept(struct socket *sock, struct socket *newsock)
{
/* I need to detect external connections */
return 0;
}
But now I don't be able to detect only external connections. Now, I don't
have access to the device (or I don't know how to do it). I have tried
with the "sock->sk->sk_bound_dev_if" member of the sock struct but its
value is always 0 for internal and external connections (at least in my
tests).
How can I detect that an external connection (using a net device) is
accepted and avoid internal network communication?
Any help would be greatly appreciated. Thanks in advance.
John Wood
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
next reply other threads:[~2021-04-25 11:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-25 11:08 John Wood [this message]
2021-04-25 12:01 ` Test if a socket accept is from external network Jeffrey Walton
2021-04-25 13:34 ` John Wood
2021-05-05 1:39 ` jim.cromie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210425110841.GA15467@ubuntu \
--to=john.wood@gmx.com \
--cc=kernelnewbies@kernelnewbies.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox