Client can't access IIS FTP Server

Post new topic   Reply to topic    DD-WRT Forum Index -> Advanced Networking
Goto page 1, 2  Next
Author Message
seanvree
DD-WRT User


Joined: 09 Sep 2015
Posts: 92

PostPosted: Fri Aug 12, 2016 4:56    Post subject: Client can't access IIS FTP Server Reply with quote
R7000
Firmware: DD-WRT v3.0-r30370M kongac (08/10/16)

I'm running a IIS FTP server from a Windows 10 enterprise box. Windows firewall is disabled.

problem is that clients can't connect to the FTP server thru the router (aka if I type the router's IP or the WAN address.

Error from client is the following:


Status: Connecting to 71.197.148.35:8889...
Status: Connection established, waiting for welcome message...
Status: Insecure server, it does not support FTP over TLS.
Status: Logged in
Status: Retrieving directory listing...
Status: Server sent passive reply with unroutable address. Using server address instead.
Command: LIST
Response: 150 Opening BINARY mode data connection.
Error: The data connection could not be established: ECONNREFUSED - Connection refused by server


I CAN connect if I connect to it if I use the Windows Box's assigned IP address.

I've opened TCP and UDP ports 8889 in DDWRT and forwarded to the windows IIS Box. Data ports (5000-6000 are also open and configured in IIS).

I can do an open port check using the WAN address and it's open.

I'm not completely sure it's a DDWRT problem, but I wanted to rule it out.

Firewall commands:

---------------------

BH_SCRIPT="/tmp/blocking_hosts.sh"
BH_WHITELIST="/tmp/blocking_hosts.whitelist"
logger "Download blocking hosts file and restart dnsmasq ..."
# Create whitelist. The whitelist entries will be removed from the
# hosts files, i.e. blacklist files.
cat > "$BH_WHITELIST" <<EOF
localhost\\.localdomain
local
invalid
whitelist-example\\.com
.*\\.whitelist-example\\.com
EOF
# Create download script.
cat > "$BH_SCRIPT" <<EOF
#!/bin/sh
# Function: clean_hosts_file [file ...]
clean_hosts_file() {
# The sed script cleans up the file.
# The awk script groups the hosts by ten items.
sed -e '/^127.0.0.1/b replace;
/^0.0.0.0/b replace;
:drop;
d; b;
:replace;
s/^0.0.0.0[[:space:]]*//;
s/^127.0.0.1[[:space:]]*//;
s/[[:space:]]*#.*\$//;
s/[[:space:]]*\$//;
s/[[:space:]][[:space:]]*/ /;
/^localhost\$/b drop;
/^[[:space:]]*\$/b drop;' \$* | \\
awk 'BEGIN {
# Read whitelist file.
n_whitelist = 0
while ( getline < "$BH_WHITELIST" ) {
if ( \$0 == "" ) {
break
}
else {
a_whitelist[++n_whitelist] = \$0
}
}
close("$BH_WHITELIST")
# Setup record sparator.
RS=" +"
c = 0
}
{
for ( n = 1; \$n != ""; n++ ) {
# Check whitelist.
whitelist_flag = 0
for ( w = 1; w <= n_whitelist; w++ ) {
if ( \$n ~ ( "^" a_whitelist[w] "\$" ) ) {
whitelist_flag = 1
break
}
}
if ( whitelist_flag == 0 ) {
hosts[++c] = \$n
if ( c == 10 ) {
s_hosts = "0.0.0.0"
for ( i = 1; i <= c; i++ ) {
s_hosts = s_hosts " " hosts[i]
}
print s_hosts
c = 0
}
}
}
}
END {
if ( c > 0 ) {
s_hosts = "0.0.0.0"
for ( i = 1; i <= c; i++ ) {
s_hosts = s_hosts = s_hosts " " hosts[i]
}
print s_hosts
}
}'
}
# Function: wait_for_connection
wait_for_connection() {
# Wait for an Internet connection.
# This possibly could take a long time.
while :; do
ping -c 1 -w 10 www.freebsd.org > /dev/null 2>&1 && break
sleep 10
done
}
# Set lock file.
LOCK_FILE="/tmp/blocking_hosts.lock"
# Check lock file.
if [ ! -f "\$LOCK_FILE" ]; then
sleep \$((\$\$ % 5 + 5))
[ -f "\$LOCK_FILE" ] && exit 0
echo \$\$ > "\$LOCK_FILE"
# Start downloading files.
HOSTS_FILE_NUMBER=1
[ -d "/tmp/blocking_hosts" ] || mkdir "/tmp/blocking_hosts"
for URL in "http://winhelp2002.mvps.org/hosts.txt" \\
"http://someonewhocares.org/hosts/zero/hosts" \\
"http://jansal.googlecode.com/svn/trunk/adblock/hosts" \\
"http://adblock.gjtech.net/?format=hostfile" \\
"http://www.hostsfile.org/Downloads/hosts.txt"; do
HOSTS_FILE="/tmp/blocking_hosts/hosts\`printf '%02d' \$HOSTS_FILE_NUMBER\`"
logger "Downloading \$URL ..."
REPEAT=1
while :; do
# Wait for internet connection.
wait_for_connection
START_TIME=\`date +%s\`
# Create process to download a hosts file.
wget -O - "\$URL" 2> /dev/null > "\${HOSTS_FILE}.tmp" &
WGET_PID=\$!
WAIT_TIME=\$((\$REPEAT * 10 + 20))
# Create timeout process.
( sleep \$WAIT_TIME; kill -TERM \$WGET_PID ) &
TIMEOUT_PID=\$!
wait \$WGET_PID
CURRENT_RC=\$?
kill -KILL \$TIMEOUT_PID
STOP_TIME=\`date +%s\`
if [ \$CURRENT_RC = 0 ]; then
clean_hosts_file "\${HOSTS_FILE}.tmp" > "\$HOSTS_FILE"
rm "\${HOSTS_FILE}.tmp"
break
fi
# In the case of an error: wait the remaining time.
TIME_SPAN=\$((\$STOP_TIME - \$START_TIME))
WAIT_TIME=\$((\$WAIT_TIME - \$TIME_SPAN))
[ \$WAIT_TIME -gt 0 ] && sleep \$WAIT_TIME
# Increase the number of repeats.
REPEAT=\$((\$REPEAT + 1))
[ \$REPEAT = 4 ] && break
done
HOSTS_FILE_NUMBER=\$((\$HOSTS_FILE_NUMBER + 1))
done
# Inspect downloaded hosts files.
ANY_FILE_OK=1
DNSMASQ_PARAM=""
for HOSTS_FILE in /tmp/blocking_hosts/hosts[0-9][0-9]; do
if [ -s "\$HOSTS_FILE" ]; then
ANY_FILE_OK=0
DNSMASQ_PARAM=\${DNSMASQ_PARAM:+\$DNSMASQ_PARAM }"--addn-hosts=\$HOSTS_FILE"
else
rm "\$HOSTS_FILE"
fi
done
if [ \$ANY_FILE_OK = 0 ]; then
logger "Restarting dnsmasq with additional hosts file(s) ..."
killall -TERM dnsmasq
dnsmasq --conf-file=/tmp/dnsmasq.conf \$DNSMASQ_PARAM &
fi
rm "\$LOCK_FILE"
fi
EOF
# Make it executeable.
chmod 755 "$BH_SCRIPT"
# Add crontab entry.
grep -q "$BH_SCRIPT" /tmp/crontab || echo "$(($$ % 60)) 3 * * * root $BH_SCRIPT" >>/tmp/crontab
# Execute script in background.
sh "$BH_SCRIPT" &


--------------



What should I check?
Sponsor
Per Yngve Berg
DD-WRT Guru


Joined: 13 Aug 2013
Posts: 6870
Location: Romerike, Norway

PostPosted: Sun Aug 14, 2016 14:05    Post subject: Reply with quote
FTP is an awkward protocol. It opens a second port to do the actual file transfer. so the port you opened will only transfer the commands.
seanvree
DD-WRT User


Joined: 09 Sep 2015
Posts: 92

PostPosted: Mon Aug 15, 2016 4:49    Post subject: Reply with quote
Per Yngve Berg wrote:
FTP is an awkward protocol. It opens a second port to do the actual file transfer. so the port you opened will only transfer the commands.


Yeah, I specified the "data" ports as well in IIS and opened the same ports in DDWRT port forward range. Can't figure it out.
Per Yngve Berg
DD-WRT Guru


Joined: 13 Aug 2013
Posts: 6870
Location: Romerike, Norway

PostPosted: Mon Aug 15, 2016 5:05    Post subject: Reply with quote
https://wiki.filezilla-project.org/Network_Configuration#NAT_routers


A Passive/Active Option can be set in the ftp client.
seanvree
DD-WRT User


Joined: 09 Sep 2015
Posts: 92

PostPosted: Mon Aug 15, 2016 5:43    Post subject: Reply with quote
Per Yngve Berg wrote:
https://wiki.filezilla-project.org/Network_Configuration#NAT_routers


A Passive/Active Option can be set in the ftp client.


Yeah, I can connect active, but need passive.
Mile-Lile
DD-WRT Guru


Joined: 24 Feb 2013
Posts: 1634
Location: Belgrade

PostPosted: Mon Aug 15, 2016 6:10    Post subject: Reply with quote
do

Code:
lsmod


from cli of your dd-wrt to see if you have nf_conntrack_ftp & nf_nat_ftp?

for working passive mode FTP you can use ct helpers instead of nf_conntrack_ftp & nf_nat_ftp... it is far more secure...

Code:

iptables -I INPUT -i `nvram get wan_ifname` -p tcp --dport 20 -j ACCEPT
iptables -I INPUT -i `nvram get wan_ifname` -p tcp --dport 21 -j ACCEPT
iptables -I INPUT -i `nvram get wan_ifname` -p tcp --dport 1024: -j ACCEPT
iptables -I INPUT -m helper --helper ftp -j ACCEPT
iptables -I INPUT -m conntrack --ctstate RELATED -j ACCEPT
iptables -I OUTPUT -p tcp --sport 20 -j ACCEPT
iptables -I OUTPUT -p tcp --sport 21 -j ACCEPT
iptables -I OUTPUT -p tcp --sport 1024: -j ACCEPT
iptables -t raw -I PREROUTING -p tcp --dport 20 -j CT --helper ftp
iptables -t raw -I PREROUTING -p tcp --dport 21 -j CT --helper ftp
iptables -t raw -I PREROUTING -p tcp --dport 1024: -j CT --helper ftp


another hint, if you use limit FTP access option on security tab try to disable it... there was some change in http://svn.dd-wrt.com/changeset/30145 Don't know if Kongs builds have it yet...
Mile-Lile
DD-WRT Guru


Joined: 24 Feb 2013
Posts: 1634
Location: Belgrade

PostPosted: Mon Aug 15, 2016 6:18    Post subject: Reply with quote
and one more hint:) You can use https://pyd.io/ on your r7000... web server is more secure than ftp... http://tips.desipro.de/category/dd-wrt/
Mile-Lile
DD-WRT Guru


Joined: 24 Feb 2013
Posts: 1634
Location: Belgrade

PostPosted: Mon Aug 15, 2016 6:32    Post subject: Reply with quote
Quote:
I've opened TCP and UDP ports 8889 in DDWRT and forwarded to the windows IIS Box. Data ports (5000-6000 are also open and configured in IIS).


I think that ftp is only TCP not UDP... you need to change the scripts above, according to windows ftp server and ofcourse forward those ports to iis ftp...
seanvree
DD-WRT User


Joined: 09 Sep 2015
Posts: 92

PostPosted: Mon Aug 15, 2016 6:43    Post subject: Reply with quote
Mile-Lile wrote:
do

Code:
lsmod


from cli of your dd-wrt to see if you have nf_conntrack_ftp & nf_nat_ftp?

for working passive mode FTP you can use ct helpers instead of nf_conntrack_ftp & nf_nat_ftp... it is far more secure...

Code:

iptables -I INPUT -i `nvram get wan_ifname` -p tcp --dport 20 -j ACCEPT
iptables -I INPUT -i `nvram get wan_ifname` -p tcp --dport 21 -j ACCEPT
iptables -I INPUT -i `nvram get wan_ifname` -p tcp --dport 1024: -j ACCEPT
iptables -I INPUT -m helper --helper ftp -j ACCEPT
iptables -I INPUT -m conntrack --ctstate RELATED -j ACCEPT
iptables -I OUTPUT -p tcp --sport 20 -j ACCEPT
iptables -I OUTPUT -p tcp --sport 21 -j ACCEPT
iptables -I OUTPUT -p tcp --sport 1024: -j ACCEPT
iptables -t raw -I PREROUTING -p tcp --dport 20 -j CT --helper ftp
iptables -t raw -I PREROUTING -p tcp --dport 21 -j CT --helper ftp
iptables -t raw -I PREROUTING -p tcp --dport 1024: -j CT --helper ftp




Hey, thanks for replying man! Really appreciate the help, I"m a bit of a noob when it comes to using the CLI, however, when I lsmod, I get this:

root@VreeNetgearR7000:~# lsmod
Module Size Used by
nf_nat_pptp 1584 0
nf_conntrack_pptp 3190 1 nf_nat_pptp
nf_nat_proto_gre 929 1 nf_nat_pptp
nf_conntrack_proto_gre 2783 1 nf_conntrack_pptp
des_generic 16572 0
md5 1475 0
md4 3101 0
cifs 322905 2
fscache 31017 1 cifs
msdos 5691 0
vfat 8076 1
fat 44315 2 msdos,vfat
nls_utf8 970 1
nls_iso8859_2 3530 0
nls_iso8859_1 3018 1
ip6table_filter 714 1
nls_cp437 4554 1
nf_conntrack_ipv6 5419 2
nls_cp950 98634 0
ip6_tables 9341 1 ip6table_filter
nls_cp936 120778 0
nf_log_ipv6 3660 0
nls_cp932 76938 0
nf_defrag_ipv6 13223 1 nf_conntrack_ipv6
ipcomp6 1629 0
xfrm_ipcomp 2917 1 ipcomp6
xfrm6_tunnel 2223 1 ipcomp6
xfrm6_mode_tunnel 1290 0
xfrm6_mode_transport 842 0
xfrm6_mode_ro 695 0
xfrm6_mode_beet 1290 0
ip6_tunnel 14876 0
tunnel6 1691 2 xfrm6_tunnel,ip6_tunnel
mip6 4044 0
ah6 4732 0
esp6 4855 0
xfrm_algo 3645 3 xfrm_ipcomp,ah6,esp6
sit 12696 0
ip_tunnel 10836 1 sit
tunnel4 1628 1 sit
ipv6 289732 70 nf_conntrack_ipv6,nf_defrag_ipv6,ipcomp6,xfrm6_tunnel,xfrm6_mode_tunnel,xfrm6_mode_beet,ip6_tunnel,m
ip6,ah6,esp6,sit,[permanent]
jffs2 90564 1
lzo_decompress 1764 0
lzo_compress 1892 0
lzma_decompress 8144 1 jffs2
lzma_compress 24973 1 jffs2
usbip_host 11326 0
usbip_core 4071 1 usbip_host
usblp 8828 0
usb_storage 36621 1
sr_mod 11004 0
cdrom 24207 1 sr_mod
sd_mod 23639 2
scsi_mod 82900 3 usb_storage,sr_mod,sd_mod
xhci_plat_hcd 2116 0
xhci_pci 2440 0
xhci_hcd 81647 2 xhci_plat_hcd,xhci_pci
ohci_hcd 15935 0
ehci_pci 2826 0
ehci_hcd 32871 1 ehci_pci
usbcore 120702 10 usbip_host,usblp,usb_storage,xhci_plat_hcd,xhci_pci,xhci_hcd,ohci_hcd,ehci_pci,ehci_hcd
usb_common 1589 1 usbcore
wl 4240857 0
igs 10035 1 wl
emf 13287 2 wl,igs
switch_robo 9388 0
switch_core 4866 1 switch_robo
et 42094 0
root@VreeNetgearR7000:~#

How do I apply the "CT Helpers"?
Mile-Lile
DD-WRT Guru


Joined: 24 Feb 2013
Posts: 1634
Location: Belgrade

PostPosted: Mon Aug 15, 2016 9:17    Post subject: Reply with quote
Code:
Administration/Commands/Save as Firewall


but I don't see XT_CT module on your list either...
[/code]
seanvree
DD-WRT User


Joined: 09 Sep 2015
Posts: 92

PostPosted: Mon Aug 15, 2016 19:11    Post subject: Reply with quote
Mile-Lile wrote:
Code:
Administration/Commands/Save as Firewall


but I don't see XT_CT module on your list either...
[/code]


Okay got it!, so the code you pasted above,

I need to edit the dport, sport ports to the ports I'm using, correct?! for example, I'm running my ftp on TCP 8889

so I would replace all the ports to 8889? you put 20, 21, and 1024, can I just put 8889 in all those and then erase the lines that are duplicates? I'm not suing 20, 21 or 1024.

thanks a lot
Mile-Lile
DD-WRT Guru


Joined: 24 Feb 2013
Posts: 1634
Location: Belgrade

PostPosted: Tue Aug 16, 2016 6:04    Post subject: Reply with quote
No, you need ddwrt to listen to those ports... I read your post once again... your Windows firewall is disabled... ftp is on IIS Windows?

you need:

1) paste the script I provided so that ddwrt listens on needed ftp ports
2) forward ports 20, 21 and range 1024:65565 porotocl TCP from WAN PUBLIC IP to your local IIS Windows IP... you can do it from cli/iptables but I think it is much easier to let GUI do it for you...

and read this to... just for better understanding how ftp works...
seanvree
DD-WRT User


Joined: 09 Sep 2015
Posts: 92

PostPosted: Tue Aug 16, 2016 7:04    Post subject: Reply with quote
Mile-Lile wrote:
No, you need ddwrt to listen to those ports... I read your post once again... your Windows firewall is disabled... ftp is on IIS Windows?

you need:

1) paste the script I provided so that ddwrt listens on needed ftp ports
2) forward ports 20, 21 and range 1024:65565 porotocl TCP from WAN PUBLIC IP to your local IIS Windows IP... you can do it from cli/iptables but I think it is much easier to let GUI do it for you...

and read this to... just for better understanding how ftp works...


OMG. That did it! I didn't need to use the scripts.

It was the Port Range that enabled it. However, that seems like a lot of ports to be opened, can't I just limit that to the "data ports" that IIS uses? Not sure if you're familiar with IIS.

THANK YOU!
Mile-Lile
DD-WRT Guru


Joined: 24 Feb 2013
Posts: 1634
Location: Belgrade

PostPosted: Tue Aug 16, 2016 8:04    Post subject: Reply with quote
I'm not familiar with IIS Windows... but using my logic you should raise the level of your security on your IIS Windows firewall... ddwrt will just forward traffic to IIS... you said you disabled firewall on windows?

When I ran home ftp server I had similar problems. I found out that Chrome allways use Passive client ftp mode... ddwrt by default opens only 21 port on the WAN. For working ftp I was forced to open 20,21 and 1024:65565... It was a big concern for me... I kept on reading and founded out about CT helpers... I started using them... after that, I could access to my ftp and when I did https://www.grc.com/x/ne.dll?bh0bkyd2
ports were closed... this linux netfilter Connection Tracking helpers are designed to recognize only RELATED connections after entering usr/pass on ftp server... they are designed for security reasons...
well, I hope that IIS has some sort of security too... you have to dig it on the google...
seanvree
DD-WRT User


Joined: 09 Sep 2015
Posts: 92

PostPosted: Tue Aug 16, 2016 8:53    Post subject: Reply with quote
Mile-Lile wrote:
I'm not familiar with IIS Windows... but using my logic you should raise the level of your security on your IIS Windows firewall... ddwrt will just forward traffic to IIS... you said you disabled firewall on windows?

When I ran home ftp server I had similar problems. I found out that Chrome allways use Passive client ftp mode... ddwrt by default opens only 21 port on the WAN. For working ftp I was forced to open 20,21 and 1024:65565... It was a big concern for me... I kept on reading and founded out about CT helpers... I started using them... after that, I could access to my ftp and when I did https://www.grc.com/x/ne.dll?bh0bkyd2
ports were closed... this linux netfilter Connection Tracking helpers are designed to recognize only RELATED connections after entering usr/pass on ftp server... they are designed for security reasons...
well, I hope that IIS has some sort of security too... you have to dig it on the google...


Ahh, okay, so if I use the CT helpers in DDWRT firewall, then in theory I wouldn't need to use the port range forwarding?

again, thanks so much for helping me out. Send me your paypal, I'd like to buy you a beer.
Goto page 1, 2  Next Display posts from previous:    Page 1 of 2
Post new topic   Reply to topic    DD-WRT Forum Index -> Advanced Networking All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum