* Test if a socket accept is from external network
@ 2021-04-25 11:08 John Wood
2021-04-25 12:01 ` Jeffrey Walton
0 siblings, 1 reply; 4+ messages in thread
From: John Wood @ 2021-04-25 11:08 UTC (permalink / raw)
To: kernelnewbies
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Test if a socket accept is from external network
2021-04-25 11:08 Test if a socket accept is from external network John Wood
@ 2021-04-25 12:01 ` Jeffrey Walton
2021-04-25 13:34 ` John Wood
2021-05-05 1:39 ` jim.cromie
0 siblings, 2 replies; 4+ messages in thread
From: Jeffrey Walton @ 2021-04-25 12:01 UTC (permalink / raw)
To: John Wood; +Cc: kernelnewbies
On Sun, Apr 25, 2021 at 7:09 AM John Wood <john.wood@gmx.com> wrote:
>
> 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. ...
> How can I detect that an external connection (using a net device) is
> accepted and avoid internal network communication?
One caveat that may (or may not) apply...
Systemd opens sockets for services even when a service is disabled. It
could appear that a system is accepting traffic even when the service
is unavailable.
Jeff
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Test if a socket accept is from external network
2021-04-25 12:01 ` Jeffrey Walton
@ 2021-04-25 13:34 ` John Wood
2021-05-05 1:39 ` jim.cromie
1 sibling, 0 replies; 4+ messages in thread
From: John Wood @ 2021-04-25 13:34 UTC (permalink / raw)
To: Jeffrey Walton, kernelnewbies; +Cc: John Wood
Hi,
On Sun, Apr 25, 2021 at 08:01:55AM -0400, Jeffrey Walton wrote:
> On Sun, Apr 25, 2021 at 7:09 AM John Wood <john.wood@gmx.com> wrote:
> >
> > 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. ...
> > How can I detect that an external connection (using a net device) is
> > accepted and avoid internal network communication?
>
> One caveat that may (or may not) apply...
>
> Systemd opens sockets for services even when a service is disabled. It
> could appear that a system is accepting traffic even when the service
> is unavailable.
But if the service is unavailable it will not accept connections. I hope.
If we use the socket_accept LSM hook it will not be called under this
scenario.
John Wood
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Test if a socket accept is from external network
2021-04-25 12:01 ` Jeffrey Walton
2021-04-25 13:34 ` John Wood
@ 2021-05-05 1:39 ` jim.cromie
1 sibling, 0 replies; 4+ messages in thread
From: jim.cromie @ 2021-05-05 1:39 UTC (permalink / raw)
To: noloader; +Cc: John Wood, kernelnewbies
On Sun, Apr 25, 2021 at 6:02 AM Jeffrey Walton <noloader@gmail.com> wrote:
>
> On Sun, Apr 25, 2021 at 7:09 AM John Wood <john.wood@gmx.com> wrote:
> >
> > 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. ...
> > How can I detect that an external connection (using a net device) is
> > accepted and avoid internal network communication?
>
> One caveat that may (or may not) apply...
>
> Systemd opens sockets for services even when a service is disabled. It
> could appear that a system is accepting traffic even when the service
> is unavailable.
>
> Jeff
>
this is interesting, it lets systemd add a tarpit to stall those SYN
connections.
But maybe bpf will do this soon.
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-05-05 1:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-25 11:08 Test if a socket accept is from external network John Wood
2021-04-25 12:01 ` Jeffrey Walton
2021-04-25 13:34 ` John Wood
2021-05-05 1:39 ` jim.cromie
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).