Koozali.org: home of the SME Server

[SOLVED ]How to ban some external IPs on forwarded ports?

Offline M3kk

  • 18
  • +0/-0
[SOLVED ]How to ban some external IPs on forwarded ports?
« on: July 15, 2015, 05:51:21 PM »
Hello,

I have a problem.. I have an SME as Gateway, i have 1 WAN, 1 LAN. I have a port forward to a client PC (RDP). Some time ago two ips are abusing the Client with RD Brute forcer, so i would like to ban them by sme side. How i can do it?

PS: Yes, the IPs are the same, i just need to know how i can ban/drop them even if the port fwd rule is alive for other external ips.

Thank you in advice.
« Last Edit: July 16, 2015, 03:58:05 PM by M3kk »

Offline Stefano

  • *
  • 10,839
  • +2/-0
Re: How to ban some external ips?
« Reply #1 on: July 15, 2015, 06:05:06 PM »
hi

first of all I suggest you not to expose RDC on WAN but use a VPN.. once VPN tunnel is up, you can safely connect to RDC

anyway, take a look at http://wiki.contribs.org/Fail2ban

Offline M3kk

  • 18
  • +0/-0
Re: How to ban some external ips?
« Reply #2 on: July 15, 2015, 06:08:43 PM »
Unfortunatelly i must use this method (RDP port forward to an internatl client).
I tried this method, but i think this is only for non forwarded ports..

I will take a look on Fail2Ban, not sure if it will work with c custom port, or only with the SSH, and only on the SME, and not on a forwarded port to a client.
« Last Edit: July 15, 2015, 06:17:40 PM by M3kk »

Offline Stefano

  • *
  • 10,839
  • +2/-0
Re: How to ban some external ips?
« Reply #3 on: July 15, 2015, 06:14:00 PM »
I guess we're talking about RDP, and I guess it's already protected by certificates..

anyway, take a look here http://serverfault.com/questions/568381/fail2ban-for-windows-2008-rdp

you need something acting on windows' side

Offline M3kk

  • 18
  • +0/-0
Re: How to ban some external ips?
« Reply #4 on: July 15, 2015, 06:18:01 PM »
Yes, sorry, RDP :).

So i cant block that IPs from SME side?

I want something like this, iptables ban externap ip, on a concrete port.. So the externap ip cant go after the SME on that port..
« Last Edit: July 15, 2015, 06:56:31 PM by M3kk »

Offline Daniel B.

  • *
  • 1,699
  • +0/-0
    • Firewall Services, la sécurité des réseaux
Re: How to ban some external ips?
« Reply #5 on: July 15, 2015, 07:20:16 PM »
You won't be able to automatically ban IP if they are brut forcing the RDP service: SME only sees a raw TCP stream and won't look at the content. But you can manually ban IP from the SME itself. You can do this either through a custom template, or if you run smeserver-fail2ban, you can manually add bans:

Code: [Select]
db fail2ban set badguy1 ban BanTimestamp $(date +%s) UnbanTimestamp $(($(date +%s)+3600)) Host 12.13.14.15
db fail2ban set badguy2 ban BanTimestamp $(date +%s) UnbanTimestamp $(($(date +%s)+604800)) Host 21.22.23.24
signal-event fail2ban-update

With this example, 21.22.23.24 will be banned for 1 week and 12.13.14.15 for 1 hour. If you wan't a permanent ban, just set UnbanTimestamp to some huge number like 9999999999999999 and it'll never be unbanned (well, not until you replace your server and at this time, we'll probably be using IPv159 anyway ;-))
C'est la fin du monde !!! :lol:

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: How to ban some external ips?
« Reply #6 on: July 15, 2015, 08:45:25 PM »
Add an AllowHosts entry to your portforwarding rule. See:

http://bugs.contribs.org/show_bug.cgi?id=2379
« Last Edit: July 15, 2015, 08:49:16 PM by CharlieBrady »

Offline Stefano

  • *
  • 10,839
  • +2/-0
Re: How to ban some external ips?
« Reply #7 on: July 15, 2015, 10:04:35 PM »
it's in the FAQ:

http://wiki.contribs.org/SME_Server:Documentation:FAQ:Section05#Additional_information_on_customizing_iptables

better link FAQ's page rather than bugzilla..

BTW, we have so many features that sometimes we forgot them at all :-)

Offline M3kk

  • 18
  • +0/-0
Re: How to ban some external ips?
« Reply #8 on: July 15, 2015, 10:25:47 PM »
As i said, i tried like this: http://wiki.contribs.org/Firewall#Block_incoming_IP_address . The ip addres apprears in the "iptables -L INPUT -v -n", but its  not banned, due the port is forwarded to a client PC, so basically the ip is banned form the SME, not from the clients too.. I wanted to block manually the ip from the SME, and from the forwards too..

Offline Daniel B.

  • *
  • 1,699
  • +0/-0
    • Firewall Services, la sécurité des réseaux
Re: How to ban some external ips?
« Reply #9 on: July 15, 2015, 10:28:13 PM »
Use the FORWARD table instead of the INPUT one
C'est la fin du monde !!! :lol:

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: How to ban some external ips?
« Reply #10 on: July 16, 2015, 04:19:04 AM »
it's in the FAQ:

http://wiki.contribs.org/SME_Server:Documentation:FAQ:Section05#Additional_information_on_customizing_iptables

better link FAQ's page rather than bugzilla..

The wiki documentation doesn't refer to portforwarding entries, only to services.

The required syntax for OP to use is in the bugzilla entry, in the Verification.

Offline M3kk

  • 18
  • +0/-0
Re: How to ban some external ips?
« Reply #11 on: July 16, 2015, 09:29:52 AM »
Use the FORWARD table instead of the INPUT one

So in the custom template file i use "/sbin/iptables -A FORWARD -s ipaddress -j DROP" instead of "/sbin/iptables -A INPUT -s ipaddress -j DROP". Is that enough, or i need to use other switches? Ty.

LE: Yes, the "/sbin/iptables -A FORWARD -s ipaddress -j DROP" did the trick, TY :). Can marked as [SOLVED].
« Last Edit: July 16, 2015, 09:50:46 AM by M3kk »

Offline Stefano

  • *
  • 10,839
  • +2/-0
Re: How to ban some external ips?
« Reply #12 on: July 16, 2015, 01:00:28 PM »
The wiki documentation doesn't refer to portforwarding entries, only to services.

The required syntax for OP to use is in the bugzilla entry, in the Verification.

ok.. I see that bug is still open..
is this a feature available?
if so, we need to wikify it


[edit: I need vacations..]
« Last Edit: July 16, 2015, 01:07:40 PM by Stefano »