Skip to contentSkip to conversation

conntrackd: cthelper: ftp: Set match offset/len for PORT mangling

PATCH Applied Kevin Cernekee 2 participants 5 messages Sep 1, 2016 – Sep 5, 2016 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 conntrackd: cthelper: ftp: Set match offset/len for PORT mangling

Currently matchoff and matchlen are 0, so IP mangling is performed in the wrong place if NAT is used:

FTP_NAT: type 0, off 0 len 0

The resultant packet is clearly incorrect:

    0x0000:  9410 3eb8 00ab 00e0 4c68 0012 0800 4510  ..>.....Lh....E.
    0x0010:  0081 9ed9 4000 4006 cd35 646b 0370 646b  ....@[email protected]
    0x0020:  0212 0015 87c5 8cc2 de50 aa28 4842 8018  .........P.(HB..
    0x0030:  00e3 459d 0000 0101 080a e916 985e 2a3b  ..E..........^*;
    0x0040:  b82d 3530 3020 2731 3030 2c31 3037 2c32  .-500.'100,107,2
    0x0050:  2c31 382c 3134 392c 3739 504f 5254 2031  ,18,149,79PORT.1
    0x0060:  3932 2c31 3638 2c32 3534 2c32 2c31 3439  92,168,254,2,149
    0x0070:  2c37 3927 3a20 636f 6d6d 616e 6420 6e6f  ,79':.command.no
    0x0080:  7420 756e 6465 7273 746f 6f64 2e0d 0a    t.understood...

Add the missing assignments.

---
 src/helpers/ftp.c | 3 +++
 1 file changed, 3 insertions(+)
src/helpers/ftp.c +3 -0
index 24ee877..3da6e56 100644
@@ -293,6 +293,9 @@ static int ftp_find_pattern(struct pkt_buff *pkt,
 	if (!numlen)
 		return 0;
 
+	*matchoff = i;
+	*matchlen = numlen;
+
 	pr_debug("Match succeded!\n");
 	return 1;
 }
Signature · 1 line
1.9.1
#1 lore raw

PATCH 2/3 conntrackd: cthelper: ftp: Fix debug print

matchoff is relative to dataoff, i.e. matchoff=0 (as utilized by nfq_tcp_mangle_ipv4()) points to the first byte of the TCP payload.

---
 src/helpers/ftp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/helpers/ftp.c +1 -1
index 3da6e56..27ab5eb 100644
@@ -511,7 +511,7 @@ ftp_helper_cb(struct pkt_buff *pkt, uint32_t protoff,
 		goto out_update_nl;
 
 	pr_debug("conntrack_ftp: match `%.*s' (%u bytes at %u)\n",
-		 matchlen, pktb_network_header(pkt) + matchoff,
+		 matchlen, pktb_network_header(pkt) + dataoff + matchoff,
 		 matchlen, ntohl(th->seq) + matchoff);
 
 	/* We refer to the reverse direction ("!dir") tuples here,
Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH 2/3] conntrackd: cthelper: ftp: Fix debug print

Quoted 2 lines · Kevin Cernekee

matchoff is relative to dataoff, i.e. matchoff=0 (as utilized by nfq_tcp_mangle_ipv4()) points to the first byte of the TCP payload.

Also applied, thanks.

#3 lore raw

RFC 3/3 conntrackd: cthelper: ssdp: Track UPnP eventing

In reply to Kevin Cernekee

The UPnP Device Architecture spec provides a way for devices to connect back to control points, called "Eventing" (chapter 4). This sequence can look something like:

1) Outbound multicast M-SEARCH packet (dst: 1900/udp)
- Create expectation for unicast reply from <any host> to source port

2) Inbound unicast reply (there may be several of these from different devices)
- Find the device's URL, e.g.
LOCATION: http://192.168.1.123:1400/xml/device_description.xml
- Create expectation to track connections to this host:port (tcp)

3) Outbound connection to device's web server (there will be several of these)
- Watch for a SUBSCRIBE request
- Find the control point's callback URL, e.g.
CALLBACK: <http://192.168.1.124:3500/notify>
- Create expectation to open up inbound connections to this host:port

4) Inbound connection to control point's web server
- Once this is complete, the subscription should work

Add the necessary code to add expectations for each of these connections and rewrite the IP in the CALLBACK URL.

---

This needs more testing on my end, so I'm posting it as an RFC to solicit preliminary feedback.

 doc/helper/conntrackd.conf |  10 +-
 src/helpers/ssdp.c         | 400 ++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 403 insertions(+), 7 deletions(-)
doc/helper/conntrackd.conf +9 -1
index 5c07509..ec24e2a 100644
@@ -74,7 +74,15 @@ Helper {
 		QueueNum 5
 		QueueLen 10240
 		Policy ssdp {
-			ExpectMax 1
+			ExpectMax 8
+			ExpectTimeout 300
+		}
+	}
+	Type ssdp inet tcp {
+		QueueNum 5
+		QueueLen 10240
+		Policy ssdp {
+			ExpectMax 8
 			ExpectTimeout 300
 		}
 	}
src/helpers/ssdp.c +394 -6

445 lines not on this page · raw message

Signature · 1 line
1.9.1
maintainer Applied
#4 lore raw
In reply to Kevin Cernekee
Quoted 17 lines · Kevin Cernekee

Currently matchoff and matchlen are 0, so IP mangling is performed in the wrong place if NAT is used:

FTP_NAT: type 0, off 0 len 0

The resultant packet is clearly incorrect:

    0x0000:  9410 3eb8 00ab 00e0 4c68 0012 0800 4510  ..>.....Lh....E.
    0x0010:  0081 9ed9 4000 4006 cd35 646b 0370 646b  ....@[email protected]
    0x0020:  0212 0015 87c5 8cc2 de50 aa28 4842 8018  .........P.(HB..
    0x0030:  00e3 459d 0000 0101 080a e916 985e 2a3b  ..E..........^*;
    0x0040:  b82d 3530 3020 2731 3030 2c31 3037 2c32  .-500.'100,107,2
    0x0050:  2c31 382c 3134 392c 3739 504f 5254 2031  ,18,149,79PORT.1
    0x0060:  3932 2c31 3638 2c32 3534 2c32 2c31 3439  92,168,254,2,149
    0x0070:  2c37 3927 3a20 636f 6d6d 616e 6420 6e6f  ,79':.command.no
    0x0080:  7420 756e 6465 7273 746f 6f64 2e0d 0a    t.understood...
Quoted 1 line

Add the missing assignments.

Applied, thanks.