Compare commits

..

13 Commits
v3.14 ... v3.18

Author SHA1 Message Date
Jan Engelhardt
87189b0051 Xtables-addons 3.18 2021-03-11 17:13:17 +01:00
Jan Engelhardt
d3fb275c03 xt_pknock: fix build failure under platforms like ARM 32-bit
./arch/arm/include/asm/div64.h:24:45: note: expected "uint64_t *"
{aka "long long unsigned int *"} but argument is of type
"long unsigned int *"
   24 | static inline uint32_t __div64_32(uint64_t *n, uint32_t base)
2021-03-11 17:11:47 +01:00
Jan Engelhardt
9faa3085bb Xtables-addons 3.17 2021-02-28 17:54:20 +01:00
Jan Engelhardt
947a677ddb xt_pknock: reduce indent in the two most-recently touched functions 2021-02-28 17:53:19 +01:00
Andrew S. Johnson
42a9b5c6c3 xt_pknock: cure NULL dereference
The original patch for long division on x86 didn't take into account
the use of short circuit logic for checking if peer is NULL before
testing it. Here is a revised patch to v3.16.
2021-02-28 17:50:36 +01:00
Jan Engelhardt
3233a0ed2c Xtables-addons 3.16 2021-02-24 01:16:22 +01:00
Jan Engelhardt
97808473f9 xt_quota2: silence a compiler warning
libxt_quota2.c:73:3: warning: ‘strncpy’ specified bound 15 equals destination size [-Wstringop-truncation]
   73 |   strncpy(info->name, optarg, sizeof(info->name));
2021-02-24 01:12:28 +01:00
Andrew S. Johnson
3aa4ca3eaf xt_pknock: use do_div for long division 2021-02-24 01:10:18 +01:00
Jan Engelhardt
5104269605 Xtables-addons 3.15 2021-02-05 21:56:26 +01:00
Jan Engelhardt
4ee209416f xt_pknock: replace obsolete function get_seconds
get_seconds is removed in 5.11; its replacement ktime_get_real_seconds
is available since 3.19. The timestamps should not be affected by clock
resets, so will be switched to ktime_get_seconds.
2021-02-05 21:55:46 +01:00
Jan Engelhardt
43df040e05 xt_lscan: add --mirai option 2021-02-05 18:58:55 +01:00
Jan Engelhardt
f59a4eb9d9 xt_lscan: extend info struct to support more flags (without size change) 2021-01-20 02:50:01 +01:00
Jan Engelhardt
a238253509 xt_ECHO: support new function signature of security_skb_classify_flow 2021-01-20 02:44:25 +01:00
10 changed files with 92 additions and 30 deletions

View File

@@ -1,4 +1,4 @@
AC_INIT([xtables-addons], [3.14])
AC_INIT([xtables-addons], [3.18])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
@@ -57,7 +57,7 @@ if test -n "$kbuilddir"; then
echo "WARNING: Version detection did not succeed. Continue at own luck.";
else
echo "$kmajor.$kminor.$kmicro.$kstable in $kbuilddir";
if test "$kmajor" -gt 5 -o "$kmajor" -eq 5 -a "$kminor" -gt 10; then
if test "$kmajor" -gt 5 -o "$kmajor" -eq 5 -a "$kminor" -gt 11; then
echo "WARNING: That kernel version is not officially supported yet. Continue at own luck.";
elif test "$kmajor" -eq 5 -a "$kminor" -ge 0; then
:

View File

@@ -1,3 +1,25 @@
v3.18 (2021-03-11)
==================
- xt_pknock: fix a build failure on ARM 32-bit
v3.17 (2021-02-28)
==================
- xt_pknock: cure a NULL deref
v3.16 (2021-02-24)
==================
- xt_pknock: build fix for ILP32 targets
v3.15 (2021-02-05)
==================
- xt_ECHO: support new function signature of security_skb_classify_flow
- xt_lscan: add --mirai option
- Support for Linux 5.11
v3.14 (2020-11-24)
==================
- DELUDE, ECHO, TARPIT: use actual tunnel socket (ip_route_me_harder).

View File

@@ -24,6 +24,7 @@ static const struct option lscan_mt_opts[] = {
{.name = "synscan", .has_arg = false, .val = 's'},
{.name = "cnscan", .has_arg = false, .val = 'c'},
{.name = "grscan", .has_arg = false, .val = 'g'},
{.name = "mirai", .has_arg = false, .val = 'm'},
{NULL},
};
@@ -35,7 +36,8 @@ static void lscan_mt_help(void)
" --stealth Match TCP Stealth packets\n"
" --synscan Match TCP SYN scans\n"
" --cnscan Match TCP Connect scans\n"
" --grscan Match Banner Grabbing scans\n");
" --grscan Match Banner Grabbing scans\n"
" --mirai Match TCP scan with ISN = dest. IP\n");
}
static int lscan_mt_parse(int c, char **argv, int invert,
@@ -45,16 +47,19 @@ static int lscan_mt_parse(int c, char **argv, int invert,
switch (c) {
case 'c':
info->match_cn = true;
info->match_fl3 |= LSCAN_FL3_CN;
return true;
case 'g':
info->match_gr = true;
info->match_fl4 |= LSCAN_FL4_GR;
return true;
case 'm':
info->match_fl1 |= LSCAN_FL1_MIRAI;
return true;
case 's':
info->match_syn = true;
info->match_fl2 |= LSCAN_FL2_SYN;
return true;
case 'x':
info->match_stealth = true;
info->match_fl1 |= LSCAN_FL1_STEALTH;
return true;
}
return false;
@@ -68,14 +73,16 @@ static void lscan_mt_save(const void *ip, const struct xt_entry_match *match)
{
const struct xt_lscan_mtinfo *info = (const void *)(match->data);
if (info->match_stealth)
if (info->match_fl1 & LSCAN_FL1_STEALTH)
printf(" --stealth ");
if (info->match_syn)
if (info->match_fl2 & LSCAN_FL2_SYN)
printf(" --synscan ");
if (info->match_cn)
if (info->match_fl3 & LSCAN_FL3_CN)
printf(" --cnscan ");
if (info->match_gr)
if (info->match_fl4 & LSCAN_FL4_GR)
printf(" --grscan ");
if (info->match_fl1 & LSCAN_FL1_MIRAI)
printf(" --mirai ");
}
static void lscan_mt_print(const void *ip,

View File

@@ -27,6 +27,11 @@ warranted single-direction data flows, usually bulk data transfers such as
FTP DATA connections or IRC DCC. Grab Scan Detection should only be used on
ports where a protocol runs that is guaranteed to do a bidirectional exchange
of bytes.
.TP
\fB\-\-mirai\fP
Match if the TCP ISN is equal to the IPv4 destination address; this is used
by the devices in the Mirai botnet as a form of TCP SYN scan, so you will
have to explicitly specify --syn for the rule.
.PP
NOTE: Some clients (Windows XP for example) may do what looks like a SYN scan,
so be advised to carefully use xt_lscan in conjunction with blocking rules,

View File

@@ -70,7 +70,7 @@ quota_mt2_parse(int c, char **argv, int invert, unsigned int *flags,
/* zero termination done on behalf of the kernel module */
xtables_param_act(XTF_ONLY_ONCE, "quota", "--name", *flags & FL_NAME);
xtables_param_act(XTF_NO_INVERT, "quota", "--name", invert);
strncpy(info->name, optarg, sizeof(info->name));
snprintf(info->name, sizeof(info->name), "%s", optarg);
*flags |= FL_NAME;
return true;
case 'p':

View File

@@ -247,12 +247,11 @@ pknock_seq_show(struct seq_file *s, void *v)
seq_printf(s, "expir_time=%lu [secs] ", time);
}
if (peer->status == ST_ALLOWED && rule->autoclose_time != 0) {
unsigned long x = ktime_get_seconds();
unsigned long y = peer->login_sec + rule->autoclose_time * 60;
time = 0;
if (time_before(get_seconds(), peer->login_sec +
rule->autoclose_time * 60))
time = peer->login_sec +
rule->autoclose_time * 60 -
get_seconds();
if (time_before(x, y))
time = y - x;
seq_printf(s, "autoclose_time=%lu [secs] ", time);
}
seq_printf(s, "\n");
@@ -312,8 +311,12 @@ static void update_rule_gc_timer(struct xt_pknock_rule *rule)
static inline bool
autoclose_time_passed(const struct peer *peer, unsigned int autoclose_time)
{
return peer != NULL && autoclose_time != 0 && time_after(get_seconds(),
peer->login_sec + autoclose_time * 60);
unsigned long x, y;
if (peer == NULL || autoclose_time == 0)
return false;
x = ktime_get_seconds();
y = peer->login_sec + autoclose_time * 60;
return time_after(x, y);
}
/**
@@ -335,7 +338,12 @@ is_interknock_time_exceeded(const struct peer *peer, unsigned int max_time)
static inline bool
has_logged_during_this_minute(const struct peer *peer)
{
return peer != NULL && peer->login_sec / 60 == get_seconds() / 60;
uint64_t x, y;
if (peer == NULL)
return 0;
x = ktime_get_seconds();
y = peer->login_sec;
return do_div(y, 60) == do_div(x, 60);
}
/**
@@ -709,6 +717,7 @@ has_secret(const unsigned char *secret, unsigned int secret_len, uint32_t ipsrc,
unsigned int hexa_size;
int ret;
bool fret = false;
uint64_t x;
unsigned int epoch_min;
if (payload_len == 0)
@@ -727,7 +736,8 @@ has_secret(const unsigned char *secret, unsigned int secret_len, uint32_t ipsrc,
hexresult = kzalloc(hexa_size, GFP_ATOMIC);
if (hexresult == NULL)
return false;
epoch_min = get_seconds() / 60;
x = ktime_get_seconds();
epoch_min = do_div(x, 60);
ret = crypto_shash_setkey(crypto.tfm, secret, secret_len);
if (ret != 0) {
@@ -826,7 +836,7 @@ update_peer(struct peer *peer, const struct xt_pknock_mtinfo *info,
if (is_last_knock(peer, info)) {
peer->status = ST_ALLOWED;
pk_debug("ALLOWED", peer);
peer->login_sec = get_seconds();
peer->login_sec = ktime_get_seconds();
if (nl_multicast_group > 0)
msg_to_userspace_nl(info, peer, nl_multicast_group);
return true;

View File

@@ -97,7 +97,11 @@ echo_tg6(struct sk_buff *oldskb, const struct xt_action_param *par)
memcpy(&fl.daddr, &newip->daddr, sizeof(fl.daddr));
fl.fl6_sport = newudp->source;
fl.fl6_dport = newudp->dest;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 11, 0)
security_skb_classify_flow((struct sk_buff *)oldskb, flowi6_to_flowi_common(&fl));
#else
security_skb_classify_flow((struct sk_buff *)oldskb, flowi6_to_flowi(&fl));
#endif
dst = ip6_route_output(net, NULL, &fl);
if (dst == NULL || dst->error != 0) {
dst_release(dst);

View File

@@ -175,6 +175,7 @@ lscan_mt(const struct sk_buff *skb, struct xt_action_param *par)
{
const struct xt_lscan_mtinfo *info = par->matchinfo;
enum ip_conntrack_info ctstate;
const struct iphdr *iph = ip_hdr(skb);
const struct tcphdr *tcph;
struct nf_conn *ctdata;
struct tcphdr tcph_buf;
@@ -182,11 +183,14 @@ lscan_mt(const struct sk_buff *skb, struct xt_action_param *par)
tcph = skb_header_pointer(skb, par->thoff, sizeof(tcph_buf), &tcph_buf);
if (tcph == NULL)
return false;
if (info->match_fl1 & LSCAN_FL1_MIRAI && iph != NULL &&
iph->version == 4 && iph->daddr == tcph->seq)
return true;
/* Check for invalid packets: -m conntrack --ctstate INVALID */
ctdata = nf_ct_get(skb, &ctstate);
if (ctdata == NULL) {
if (info->match_stealth)
if (info->match_fl1 & LSCAN_FL1_STEALTH)
return lscan_mt_stealth(tcph);
/*
* If @ctdata is NULL, we cannot match the other scan
@@ -212,17 +216,19 @@ lscan_mt(const struct sk_buff *skb, struct xt_action_param *par)
skb_nfmark(skb) = (skb_nfmark(skb) & ~packet_mask) ^ mark_seen;
}
return (info->match_syn && ctdata->mark == mark_synscan) ||
(info->match_cn && ctdata->mark == mark_cnscan) ||
(info->match_gr && ctdata->mark == mark_grscan);
return (info->match_fl1 & LSCAN_FL1_STEALTH && ctdata->mark == mark_synscan) ||
(info->match_fl3 & LSCAN_FL3_CN && ctdata->mark == mark_cnscan) ||
(info->match_fl4 & LSCAN_FL4_GR && ctdata->mark == mark_grscan);
}
static int lscan_mt_check(const struct xt_mtchk_param *par)
{
const struct xt_lscan_mtinfo *info = par->matchinfo;
if ((info->match_stealth & ~1) || (info->match_syn & ~1) ||
(info->match_cn & ~1) || (info->match_gr & ~1)) {
if ((info->match_fl1 & ~(LSCAN_FL1_STEALTH | LSCAN_FL1_MIRAI)) ||
(info->match_fl2 & ~LSCAN_FL2_SYN) ||
(info->match_fl3 & ~LSCAN_FL3_CN) ||
(info->match_fl4 & ~LSCAN_FL4_GR)) {
printk(KERN_WARNING PFX "Invalid flags\n");
return -EINVAL;
}

View File

@@ -1,8 +1,16 @@
#ifndef _LINUX_NETFILTER_XT_LSCAN_H
#define _LINUX_NETFILTER_XT_LSCAN_H 1
enum {
LSCAN_FL1_STEALTH = 1 << 0,
LSCAN_FL1_MIRAI = 1 << 1,
LSCAN_FL2_SYN = 1 << 0,
LSCAN_FL3_CN = 1 << 0,
LSCAN_FL4_GR = 1 << 0,
};
struct xt_lscan_mtinfo {
uint8_t match_stealth, match_syn, match_cn, match_gr;
uint8_t match_fl1, match_fl2, match_fl3, match_fl4;
};
#endif /* _LINUX_NETFILTER_XT_LSCAN_H */

View File

@@ -1,4 +1,4 @@
.TH xtables-addons 8 "" "Caketime" "v3.14 (2020-11-24)"
.TH xtables-addons 8 "" "" "v3.18 (2021-03-11)"
.SH Name
Xtables-addons \(em additional extensions for iptables, ip6tables, etc.
.SH Targets