{"id":15,"date":"2011-03-20T22:47:00","date_gmt":"2011-03-20T22:47:00","guid":{"rendered":"http:\/\/www.somethingsomethingsecurity.com\/?p=15"},"modified":"2011-03-20T22:47:00","modified_gmt":"2011-03-20T22:47:00","slug":"active-defense-for-web-server-part-3","status":"publish","type":"post","link":"http:\/\/www.somethingsomethingsecurity.com\/?p=15","title":{"rendered":"Active Defense for web server &#8211; Part 3"},"content":{"rendered":"<p>The following is based on my experiences and (limited) knowledge. I am not an expert in anything, nor will I likely ever be one. My hope is that this might help someone, somewhere, sometime. If nothing else, it might be a good start for discussion.<\/p>\n<p><strong>Preamble<\/strong><br \/>This series is for meant for educational use only, and is intended to be used in a lab environment. These have not been tested in the real world and may cause more problems then they help. It will by no means be an in depth discussion.<\/p>\n<p><strong>Background<\/strong><br \/>As mentioned before we will be creating a simple WAF to actively defend against offensive attacks. We are still laying the groundwork for our scenario, this time by taking a look at blocking traffic.<\/p>\n<p><strong>Process<\/strong><br \/>Please note, I won&#8217;t go into a lot of details in these posts. There is a lot of information out there on these topics presented by people much smarter then me.<\/p>\n<p>The main thing we will want to do with our simple web application firewall is to block traffic we suspect as malicious. The usual way to do this is with a firewall.<\/p>\n<p>Unfortunately, the Windows firewall included in Windows 2003 is rather simple and does not make a distinction between inbound and outbound traffic. <\/p>\n<p>Lucky for us, IPSec does<\/p>\n<p>There is a great demo and explanation\u00a0of how\u00a0to setup a policy\u00a0by\u00a0John Strand here<br \/><a href=\"http:\/\/www.youtube.com\/watch?v=amHaBmOlfgE\">http:\/\/www.youtube.com\/watch?v=amHaBmOlfgE<\/a><\/p>\n<p>As with most things Windows, there are many ways to setup an IPSec policy. You can use the snap in as shown above, via group policy templates, with the command line or even in the registry (under HKEY_LOCAL_MACHINE\\SOFTWARE\\Policies\\Microsoft\\Windows\\IPSec). In addition, there is a dedicated tool, the IPSec Policy Agent, IPSeccmd.exe. IPSeccmd.exe is part of Windows XP Service Pack 2 support tools. We will use command line.<\/p>\n<p>First need to create an IPSec Policy.<br \/><span>netsh ipsec static add policy name=&#8221;Simple WAF&#8221; description=&#8221;Simple WAF&#8221; assign=no<\/span><br \/>This creates a Policy named Simple WAF.<\/p>\n<p><span>netsh ipsec static add filterlist name=&#8221;Banned IPs&#8221; description=&#8221;Simple WAF Banned IPs&#8221;<\/span><br \/>This creates a filter list that we will add the attacking ip&#8217;s to.<\/p>\n<p><span>netsh ipsec static add filteraction name=Block description=&#8221;Blocks Traffic&#8221; action=block<\/span><br \/>Here we create a Block action. <\/p>\n<p><span>netsh ipsec static add filter filterlist=&#8221;Banned IPs&#8221; srcaddr=X.X.X.X dstaddr=The.web.server.ip description=&#8221;Banned IPs&#8221; protocol=any srcport=0 dstport=80<\/span><br \/>This will add an IP address to our banned IPs filter so we can test.<\/p>\n<p><span>netsh ipsec static add rule name=&#8221;Banned IP Rule&#8221; policy=&#8221;Simple WAF&#8221; filterlist=&#8221;Banned IPs&#8221; kerberos=no filteraction=Block<\/span><\/p>\n<p>This rule definition ties together the policy, the filter and the action<\/p>\n<p>Now, let&#8217;s check it out using the snap-in.<br \/>To get to the IPSec MMC Snap-in click on <span>Start | Settings | Control Panel | Administrative Tools | Local Security Policy<\/span>or<span> Start | Run |<span> type<\/span> secpol.msc | OK<\/span><\/p>\n<p>Now play a game of search and click, and see if you can find the screens that match up with screen shot below.<\/p>\n<p><\/p>\n<div><a href=\"https:\/\/lh4.googleusercontent.com\/-hyjAwJVL4L8\/TYZ-Qb50KPI\/AAAAAAAAAAY\/d5fgsiQ7QNg\/s1600\/ipsecS.jpg\" imageanchor=\"1\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" height=\"201\" r6=\"true\" src=\"https:\/\/lh4.googleusercontent.com\/-hyjAwJVL4L8\/TYZ-Qb50KPI\/AAAAAAAAAAY\/d5fgsiQ7QNg\/s320\/ipsecS.jpg\" width=\"320\"><\/a><\/div>\n<p>Once you have verified the rule, right click on it, select assign, and try to access port 80 from the test box you added to the Banned IPs. <\/p>\n<p>You could do something similar using IPSec in Windows 2008, but it is much easier to use the Windows 2008 firewall. <\/p>\n<p>Again, there are many ways to do this. We will run a simple command from the command line<br \/><span>netsh advfirewall firewall add rule name=&#8221;Bad IPs&#8221; protocol=TCP dir=in localport=80 remoteip=x.x.x.x action=block<\/span><br \/>This command creates a new rule called Bad IPs, and blocks access to port 80 from the ip listed in remoteip.<br \/>See <a href=\"http:\/\/www.windowsnetworking.com\/articles_tutorials\/Configure-Windows-2008-Advanced-Firewall-NETSH-CLI.html\">http:\/\/www.windowsnetworking.com\/articles_tutorials\/Configure-Windows-2008-Advanced-Firewall-NETSH-CLI.html<\/a>\u00a0for some more examples and instuctions on how to use the netsh command to manage the firewall.<\/p>\n<p><strong>Next Steps<\/strong><br \/>A very quick intro to logparser and a very simple script to use it to look for and then block attackers.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The following is based on my experiences and (limited) knowledge. I am not an expert in anything, nor will I likely ever be one. My hope is that this might help someone, somewhere, sometime. If nothing else, it might be a good start for discussion. PreambleThis series is for meant for educational use only, and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,9],"tags":[],"class_list":["post-15","post","type-post","status-publish","format-standard","hentry","category-blue","category-iis"],"_links":{"self":[{"href":"http:\/\/www.somethingsomethingsecurity.com\/index.php?rest_route=\/wp\/v2\/posts\/15","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.somethingsomethingsecurity.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.somethingsomethingsecurity.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.somethingsomethingsecurity.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.somethingsomethingsecurity.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=15"}],"version-history":[{"count":0,"href":"http:\/\/www.somethingsomethingsecurity.com\/index.php?rest_route=\/wp\/v2\/posts\/15\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.somethingsomethingsecurity.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=15"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.somethingsomethingsecurity.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=15"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.somethingsomethingsecurity.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=15"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}