Ubuntu met iptables, welke rules voor webserver

Pagina: 1
Acties:

Acties:
  • 0 Henk 'm!

Anoniem: 67691

Topicstarter
Hallo, ik heb hier een webserver op 192.168.1.1 draaien met daarop SSH2 voor SFTP uploads.
Daarvoor staat een dual NIC Ubuntu server met daarop iptables an ufw.
Ik ben de beveiliging aan het plannen en mijn plan is het volgende. Mijn vraag is, gaat dit werken? Voor SSH2 port 22, wil ik van buitenaf naar poort 4500 verbinden, vandaar die DNAT op TCP 4500. Poort 80 ga ik neit gebruiken.

Inbound (vanaf WAN):
- Allow TCP port 443 from all source IP’s (0.0.0.0)
- Allow TCP port 4500 from all source IP’s (0.0.0.0)
- Block all traffic from all source IP's (0.0.0.0)

Outbound (vanaf LAN):
- Block all NEW connections from all source IP’s (0.0.0.0).
- Allow all ESTABLISHED connections.


DNAT Rules:
- Forward traffic incoming at WAN on TCP port 4500 to IP address 192.168.1.1 at TCP port 22
- Forward traffic incoming at WAN on TCP port 443 to IP address 192.168.1.1 at TCP port 443

Acties:
  • 0 Henk 'm!

  • Kees
  • Registratie: Juni 1999
  • Laatst online: 25-05 10:24

Kees

Serveradmin / BOFH / DoC
Als je wil mailen, dns queries wil doen, of afentoe je bak wil updaten, dan is alle nieuwe conencties blocken niet heel erg handig.

"Een serveradmin, voluit een serveradministrator, is dan weer een slavenbeheerder oftewel een slavendrijver" - Rataplan


Acties:
  • 0 Henk 'm!

Anoniem: 67691

Topicstarter
Kees schreef op dinsdag 26 april 2011 @ 10:51:
Als je wil mailen, dns queries wil doen, of afentoe je bak wil updaten, dan is alle nieuwe conencties blocken niet heel erg handig.
Is puur een webserver, dus mailen is niet nodig. Updates wel, en daar heb ik waarschijnlijk wel DNS voor nodig (om bij de update server addressen te komen)

DNS is UDP 53
Updates gaan gewoon via TCP 80?

Acties:
  • 0 Henk 'm!

  • Kees
  • Registratie: Juni 1999
  • Laatst online: 25-05 10:24

Kees

Serveradmin / BOFH / DoC
Anoniem: 67691 schreef op dinsdag 26 april 2011 @ 11:17:
[...]


Is puur een webserver, dus mailen is niet nodig. Updates wel, en daar heb ik waarschijnlijk wel DNS voor nodig (om bij de update server addressen te komen)

DNS is UDP 53
Updates gaan gewoon via TCP 80?
Puur een webserver kan prima mailen hoor, bijvoorbeeld registratiemails, notificaties etc.

Updates gaan via whatever protocol je ingesteld hebt in /etc/apt/sources.list, waarbij meestal http/tcp80 gepakt wordt ja.

"Een serveradmin, voluit een serveradministrator, is dan weer een slavenbeheerder oftewel een slavendrijver" - Rataplan


Acties:
  • 0 Henk 'm!

Anoniem: 67691

Topicstarter
Kees schreef op dinsdag 26 april 2011 @ 11:40:
[...]

Puur een webserver kan prima mailen hoor, bijvoorbeeld registratiemails, notificaties etc.

Updates gaan via whatever protocol je ingesteld hebt in /etc/apt/sources.list, waarbij meestal http/tcp80 gepakt wordt ja.
Ok, dus de rest klopt? Dan ga ik daar een testbestand van maken. Wel een &*%^% werk, iptables. Bedankt!

Acties:
  • 0 Henk 'm!

Anoniem: 67691

Topicstarter
Ok, ik heb nu dus:

Inbound (vanaf WAN):
- Allow TCP port 443 from all source IP’s (0.0.0.0)
- Allow TCP port 4500 from all source IP’s (0.0.0.0)
- Allow TCP port 80, ESTABLISHED connections from all source IP's (0.0.0.0)
- Allow UDP port 53, ESTABLISHED connections from all source IP's (0.0.0.0)
- Block all traffic from all source IP's (0.0.0.0)

Outbound (vanaf LAN):
- Allow TCP port 80, NEW connections from 192.168.1.1
- Allow UDP port 53, NEW connections from 192.168.1.1
- Block all NEW connections from all source IP’s (0.0.0.0).
- Allow all ESTABLISHED connections.


DNAT Rules:
- Forward traffic incoming at WAN on TCP port 4500 to IP address 192.168.1.1 at TCP port 22
- Forward traffic incoming at WAN on TCP port 443 to IP address 192.168.1.1 at TCP port 443

Klopt dit zo? Heb het hele established en new connections verhaal is nieuw voor mij, maar door dit te gebruiken krijg ik wel de beste beveiliging.

Acties:
  • 0 Henk 'm!

  • CAPSLOCK2000
  • Registratie: Februari 2003
  • Laatst online: 24-05 23:32

CAPSLOCK2000

zie teletekst pagina 888

Zou je geen ssh naar je firewall toelaten zodat je het ding op afstand kan beheren?

This post is warranted for the full amount you paid me for it.


Acties:
  • 0 Henk 'm!

Anoniem: 67691

Topicstarter
CAPSLOCK2000 schreef op donderdag 28 april 2011 @ 19:09:
Zou je geen ssh naar je firewall toelaten zodat je het ding op afstand kan beheren?
Ja kan erbij ja, maar het gaat mij om of established en new connections kloppen

Acties:
  • 0 Henk 'm!

  • TrailBlazer
  • Registratie: Oktober 2000
  • Laatst online: 18-05 22:28

TrailBlazer

Karnemelk FTW

nee de established hebben als source poort 53 of 80. Bovendien established bestaat niet echt op UDP tenzij je protocol inspectie gaat doen. De firewall houdt bij welke uitgaande DNS queries er zijn gedaan en staat alleen maar toe dat het antwoord op die DNS query terugkomt. ESTABLISHED houd enkel in dat het alle SYN only pakketten tegenhoudt.

Acties:
  • 0 Henk 'm!

Anoniem: 67691

Topicstarter
DNAT:
- Forward traffic incoming at WAN on TCP port 4500 to IP address 192.168.1.1 at TCP port 22
- Forward traffic incoming at WAN on TCP port 80 to IP address 192.168.1.1 at TCP port 80

Inbound (vanaf WAN):
- Allow all RELATED and ESTABLISHED connections from all source IP’s (0.0.0.0)
- Allow TCP destination port 80 from all source IP’s (0.0.0.0)
- Allow TCP destination port 4500 from 203.208.67.5
- Allow TCP destination port 22 from 203.208.67.5
- Deny all traffic from everywhere (0.0.0.0)

Outbound (vanaf LAN):
- Allow all RELATED and ESTABLISHED connections to all destination IP’s
- Allow destination TCP port 80 from 192.168.1.1 (for updates)
- Allow destination UDP port 53 from 192.168.1.1 (for the DNS client)
- Deny all NEW connections from all source IP’s (0.0.0.0).
- Deny all traffic to everywhere (0.0.0.0)

De firewall rules op de webserver zijn:

Inbound:
- Allow all NEW connections on TCP destination port 80 from 192.168.1.254
- Allow all NEW connections on TCP destination port 22 from 192.168.1.254 (for uploads and management)
- Allow all RELATED and ESTABLISHED connections

Outbound:
- Allow all RELATED and ESTABLISHED connections
- Allow all NEW connections on destination UDP port 53
- Allow all NEW connections on destination TCP port 80
- Deny all traffic to anywhere (0.0.0.0)

Ok, dit hierboven heb ik nu... moet ik met iptables eigenlijk wel die bovenste 2 allows ingeven (TCP 443 en 4500) aangezien ik die via DNAT naar binnen forward?
DNS heb ik nu doorgelaten, ongeacht de connection state, aangezien dit UDP is.

Klopt dit zo? Kan iemand hier even advies op geven? Alvast bedankt!

[ Voor 67% gewijzigd door Anoniem: 67691 op 08-05-2011 12:46 ]


Acties:
  • 0 Henk 'm!

Anoniem: 67691

Topicstarter
Anoniem: 67691 schreef op woensdag 04 mei 2011 @ 13:39:
DNAT:
- Forward traffic incoming at WAN on TCP port 4500 to IP address 192.168.1.1 at TCP port 22
- Forward traffic incoming at WAN on TCP port 80 to IP address 192.168.1.1 at TCP port 80

Inbound (vanaf WAN):
- Allow all RELATED and ESTABLISHED connections from all source IP’s (0.0.0.0)
- Allow TCP destination port 80 from all source IP’s (0.0.0.0)
- Allow TCP destination port 4500 from 203.208.67.5
- Allow TCP destination port 22 from 203.208.67.5
- Deny all traffic from everywhere (0.0.0.0)

Outbound (vanaf LAN):
- Allow all RELATED and ESTABLISHED connections to all destination IP’s
- Allow destination TCP port 80 from 192.168.1.1 (for updates)
- Allow destination UDP port 53 from 192.168.1.1 (for the DNS client)
- Deny all NEW connections from all source IP’s (0.0.0.0).
- Deny all traffic to everywhere (0.0.0.0)

De firewall rules op de webserver zijn:

Inbound:
- Allow all NEW connections on TCP destination port 80 from 192.168.1.254
- Allow all NEW connections on TCP destination port 22 from 192.168.1.254 (for uploads and management)
- Allow all RELATED and ESTABLISHED connections

Outbound:
- Allow all RELATED and ESTABLISHED connections
- Allow all NEW connections on destination UDP port 53
- Allow all NEW connections on destination TCP port 80
- Deny all traffic to anywhere (0.0.0.0)

Ok, dit hierboven heb ik nu... moet ik met iptables eigenlijk wel die bovenste 2 allows ingeven (TCP 443 en 4500) aangezien ik die via DNAT naar binnen forward?
DNS heb ik nu doorgelaten, ongeacht de connection state, aangezien dit UDP is.

Klopt dit zo? Kan iemand hier even advies op geven? Alvast bedankt!
niemand?

Acties:
  • 0 Henk 'm!

  • TrailBlazer
  • Registratie: Oktober 2000
  • Laatst online: 18-05 22:28

TrailBlazer

Karnemelk FTW

doe eens gewoon iptables -nvL en iptables -nvL -t nat dat lees voor mij in ieder geval een heel stuk makkelijker.

Acties:
  • 0 Henk 'm!

Anoniem: 67691

Topicstarter
TrailBlazer schreef op zondag 08 mei 2011 @ 12:49:
doe eens gewoon iptables -nvL en iptables -nvL -t nat dat lees voor mij in ieder geval een heel stuk makkelijker.
heb het er nog niet in gezet... wilde eerst een beetje commentaar... is redelijk nieuw op deze manier voor me

Acties:
  • 0 Henk 'm!

  • TrailBlazer
  • Registratie: Oktober 2000
  • Laatst online: 18-05 22:28

TrailBlazer

Karnemelk FTW

dat zal best alleen het lezen van de config is een stuk makkelijker voor me dan een beschrijving van die config. Anyway de inbound van de webserver is niet goed.
Allow all NEW connections on TCP destination port 80 from 192.168.1.254
Allow all NEW connections on TCP destination port 22 from 192.168.1.254 (for uploads and management)
de source is namelijk niet gewijzigd naar het inside IP van de firewall met je huidige config.

ook heb je helemaal geen nat outbound. Hier onder staan mijn rules en ik doe op de postrouting vanaf twee subnets nog een MASQUERADE (source nat) naar het adres op de uitgaande interface eth0.2
code:
1
2
3
4
5
6
epia:~# iptables -nvL POSTROUTING -t nat
Chain POSTROUTING (policy ACCEPT 81160 packets, 9738K bytes)
 pkts bytes target     prot opt in     out     source               destination
 77301 6149K MASQUERADE  all  --  *      eth0.2  192.168.3.0/24       0.0.0.0/0
18557  906K MASQUERADE  all  --  *      eth0.2  192.168.4.0/24       0.0.0.0/0
epia:~#

[ Voor 38% gewijzigd door TrailBlazer op 08-05-2011 20:42 ]


Acties:
  • 0 Henk 'm!

Anoniem: 67691

Topicstarter
TrailBlazer schreef op zondag 08 mei 2011 @ 20:39:
dat zal best alleen het lezen van de config is een stuk makkelijker voor me dan een beschrijving van die config. Anyway de inbound van de webserver is niet goed.

[...]

de source is namelijk niet gewijzigd naar het inside IP van de firewall met je huidige config.

ook heb je helemaal geen nat outbound. Hier onder staan mijn rules en ik doe op de postrouting vanaf twee subnets nog een MASQUERADE (source nat) naar het adres op de uitgaande interface eth0.2
code:
1
2
3
4
5
6
epia:~# iptables -nvL POSTROUTING -t nat
Chain POSTROUTING (policy ACCEPT 81160 packets, 9738K bytes)
 pkts bytes target     prot opt in     out     source               destination
 77301 6149K MASQUERADE  all  --  *      eth0.2  192.168.3.0/24       0.0.0.0/0
18557  906K MASQUERADE  all  --  *      eth0.2  192.168.4.0/24       0.0.0.0/0
epia:~#
Ok bedankt... is ie zo beter...? Zo ja, ga ik 'm vertalen in iptables (wat voor mij helemaal nieuw is, ondanks heel wat firewall ervaring)

SNAT (MASQUERADE):
- Replace all source IP addresses, to 1 external IP address for all outgoing traffic

DNAT:
- Forward traffic incoming at WAN on TCP port 4500 to IP address 192.168.1.1 at TCP port 22
- Forward traffic incoming at WAN on TCP port 80 to IP address 192.168.1.1 at TCP port 80

Inbound (vanaf WAN):
- Allow all RELATED and ESTABLISHED connections from all source IP’s (0.0.0.0)
- Allow TCP destination port 80 from all source IP’s (0.0.0.0)
- Allow TCP destination port 4500 from 203.208.67.5
- Allow TCP destination port 22 from 203.208.67.5
- Deny all traffic from everywhere (0.0.0.0)

Outbound (vanaf LAN):
- Allow all RELATED and ESTABLISHED connections to all destination IP’s
- Allow destination TCP port 80 from 192.168.1.1 (for updates)
- Allow destination UDP port 53 from 192.168.1.1 (for the DNS client)
- Deny all NEW connections from all source IP’s (0.0.0.0).
- Deny all traffic to everywhere (0.0.0.0)

De firewall rules op de webserver zijn:

Inbound:
- Allow all NEW connections on TCP destination port 80 from everywhere (0.0.0.0)
- Allow all NEW connections on TCP destination port 22 from 203.208.67.5 (for uploads and management)
- Allow all RELATED and ESTABLISHED connections

Outbound:
- Allow all RELATED and ESTABLISHED connections
- Allow all NEW connections on destination UDP port 53
- Allow all NEW connections on destination TCP port 80
- Deny all traffic to anywhere (0.0.0.0)

Acties:
  • 0 Henk 'm!

  • TrailBlazer
  • Registratie: Oktober 2000
  • Laatst online: 18-05 22:28

TrailBlazer

Karnemelk FTW

ziet er wel aardig uit zo

Acties:
  • 0 Henk 'm!

Anoniem: 67691

Topicstarter
ok, klaar dan!
bedankt, nu gaat het echte werk beginnen
Pagina: 1