Wednesday, March 20, 2013

Flow Diagnostic (fortigate)

-->
In these next series of posts, I will go over some basic diagnostic  methods for netscreen, fortigate and cisco ASA. As firewall admins, we need to know how to aid in t-shooting. Blindly changing rules, rebooting, and host of other steps are typically a hail mary and accomplish nothing.


1st up,

Flow diagnostic  on the Fortigates series are simple. 


Why we do this is mainly to trouble-shoot L3/L4 fwpolicies rules. And to validate what’s being hit and the policy-id involved, any nat'ing or if encryption is taking place.



First  check the debug  options , too see if any one left something running or to clear any post debugs sessions;


SomeFWFGT01 # diag debug info

debug output:                       disable

console timestamp:   disable

console no user log message:           disable

CLI debug level:        3


if anything is set you might want to clear it;


diag debug reset



2nd, we what to set up debug to be enabled before we start;



SomeFWFGT01 # diag debug enable



SomeFWFGT01 #


Third, we want to set up the flow diagnostic and similar to my flow diag with netscreens,  we have  filters options in the FortiOS;



SomeFWFGT01 # diag debug flow

filter     trace packet with filter

filter6    trace packet with ipv6 filter

show       whether to display trace on console

trace      start/stop trace



SomeFWFGT01 # diag debug flow filter

addr      ip address

clear     clear filter

daddr     dest ip address

dport     destination port

negate    inverse filter

port      port

proto     protocol number

saddr     source ip address

sport     source port

vd        index of virtual domain



note: filter6 are for ipv6 filters

Here I’m going to be very specific,  and place a flow filter for the google dns server
8.8.8.8 and port 53

 diag debug flow filter daddr 8.8.8.8
diag debug flow filter dport 53


Third, Now that we have the flow filter-set. We need to tell the firewall to display the traces on the console




SomeFWFGT01 # diag debug flow show console enable

show trace messages on console

And lastly, we start the trace;



SomeFWFGT01 # diag debug flow  trace start 1000


 NOTE: The above says to start , and display the  1st 1K traces


Now when interesting traffic matches our filter we will get a trace;

SomeFWFGT01 # id=36871 trace_id=217 msg="vd-root received a packet(proto=17, 10.10.100.9:46883->8.8.8.8:53) from WEB_NET01."
id=36871 trace_id=217 msg="allocate a new session-301981cb"
id=36871 trace_id=217 msg="find a route: gw-192.0.2.1 via EXT_NET01"
id=36871 trace_id=217 msg="find SNAT: IP-192.0.2.2, port-30639"
id=36871 trace_id=217 msg="Allowed by Policy-10: SNAT"
id=36871 trace_id=217 msg="SNAT 10.10.100.9->192.0.2.2:30639"
id=36871 trace_id=217 msg="run helper-dns-udp(dir=original)"
id=36871 trace_id=218 msg="vd-root received a packet(proto=17, 10.10.100.9:52631->8.8.8.8:53) from WEB_NET01."
id=36871 trace_id=218 msg="allocate a new session-30198221"
id=36871 trace_id=218 msg="find a route: gw-192.0.2.1 via EXT_NET01"
id=36871 trace_id=218 msg="find SNAT: IP-192.0.2.2, port-40219"
id=36871 trace_id=218 msg="Allowed by Policy-10: SNAT"
id=36871 trace_id=218 msg="SNAT 10.10.100.9->192.0.2.2:40219"
id=36871 trace_id=218 msg="run helper-dns-udp(dir=original)"
id=36871 trace_id=219 msg="vd-root received a packet(proto=17, 10.10.100.9:51360->8.8.8.8:53) from WEB_NET01."
id=36871 trace_id=219 msg="allocate a new session-3019827d"
id=36871 trace_id=219 msg="find a route: gw-192.0.2.1 via EXT_NET01"
id=36871 trace_id=219 msg="find SNAT: IP-192.0.2.2, port-26668"
id=36871 trace_id=219 msg="Allowed by Policy-10: SNAT"
id=36871 trace_id=219 msg="SNAT 10.10.100.9->192.0.2.2:26668"
id=36871 trace_id=219 msg="run helper-dns-udp(dir=original)"
id=36871 trace_id=220 msg="vd-root received a packet(proto=17, 10.10.100.9:45227->8.8.8.8:53) from WEB_NET01."
id=36871 trace_id=220 msg="allocate a new session-3019ab4d"
id=36871 trace_id=220 msg="find a route: gw-192.0.2.1 via EXT_NET01"
id=36871 trace_id=220 msg="find SNAT: IP-192.0.2.2, port-45095"
id=36871 trace_id=220 msg="Allowed by Policy-10: SNAT"
id=36871 trace_id=220 msg="SNAT 10.10.100.9->192.0.2.2:45095"
id=36871 trace_id=220 msg="run helper-dns-udp(dir=original)"
id=36871 trace_id=221 msg="vd-root received a packet(proto=17, 10.10.100.9:59618->8.8.8.8:53) from WEB_NET01."
id=36871 trace_id=221 msg="allocate a new session-3019ab63"
id=36871 trace_id=221 msg="find a route: gw-192.0.2.1 via EXT_NET01"
id=36871 trace_id=221 msg="find SNAT: IP-192.0.2.2, port-47214"
id=36871 trace_id=221 msg="Allowed by Policy-10: SNAT"
id=36871 trace_id=221 msg="SNAT 10.10.100.9->192.0.2.2:47214"
id=36871 trace_id=221 msg="run helper-dns-udp(dir=original)"



Each trace is marked with a trace_id, and the key take aways are the following;
  
    
  •   Interface dst/src ( directionality ) 
  •    Fwpolicy ID
  •     Session allocation
  •   is SNAT/DNAT  ( NAT )
  •   Allowed or Denied ( action )

As with the  netscreen, we need to remind our selves to reset the diag debug fuction to conserve on memory.

 diag debug reset

Next post will be cisco ASA and then I will wrapped up with PaloAlto series. With these last three, we have  the means to capture data  and run pcaps for exporting. I will cover that in unique post.

Ken Felix Freelance Network/Security Engineer
Kfelix at hyperfeed  <d-o-t> com

Tuesday, March 19, 2013

Debug Flow ( netscreen )

-->
In these next series of posts, I will go over some of the basic diagnostic  methods for netscreen, fortigate,  and cisco ASA. 

As a firewall admins, we need to know how to aid in the t-shooting step. Blindly changing rules, rebooting, and host of other steps,  are typically a hail mary and accomplish nothing. Don't be scared of the diagnostic or the utilities, that's built right in to HELP YOU !


1st up,

Flow diagnostic netscreen ( legacy ). 


Why we do this,  is mainly to trouble-shoot l3/l4 fwpolicies rules. And to validate what’s being hit and the policy-id that's being matched.


First  check the debug  options , too see if any one left something running or to clear any post debugs sessions;


iscreen:-> get debug
get debug
flow: basic

if anything is set you might want to clear it;

undebug all


2nd, we what to set up the flow filter(s), this I what specify to matches on, & the traffic of interest that we are expecting to  inspection or t-shoot;

iscreen:-> set ff ?
set ff ?
<return>
dst-ip               flow filter dst ip
dst-port             flow filter dst port
ip-proto             flow filter ip proto
src-ip               flow filter src ip
src-port             flow filter src port

note: you can string multiple filters on the cmd line or in one single line, ensure specific filters to drill in on the host/port/proto/etc……

Here I’m going to be very specific,  and place a flow filter for the google dns server
8.8.8.8 and port 53

note: you can remove any pre-existing filters, and should always check the filters b4 starting up a flow diagnostic


iscreen:-> set ff dst-ip 8.8.8.8  dst-port 53
set ff dst-ip 8.8.8.8  dst-port 53
filter added

Now I’m validating my filters;

iscreen:-> get ff
get ff
Flow filter based on:
id:0 dst ip 8.8.8.8 dst port 53
iscreen:->

NOTE: to remove a filter, unset ff  <“filter-id”>



Third, Now that we have the flow filter set. We need to enable the debug type. Here’s a few that my  netscreen  named iscreen supports based on the screen os version

iscreen:-> get sys
get sys
Product Name: NetScreen-NS5GT-WLAN
Serial Number: 0129012006000174, Control Number: 00000000
Hardware Version: 1010(0)-(00), FPGA checksum: 00000000, VLAN1 IP (0.0.0.0)
Software Version: 5.4.0r3a.0, Type: Firewall+VPN
Feature: AV-K
Compiled by build_master at: Wed Feb 7 19:00:24 PST 2007
Base Mac: 0012.1ebe.7b50
File Name: screenos_image, Checksum: 51863a99

( she's old but she still puts out :) )


iscreen:-> debug ?
debug ?
admin                debug admin
adsl                 adsl soc debugging
anti-spam            anti-spam debugging
apppry               Application Proxy debugging
arp                  arp debugging
asp                  ASP debugging
asset-recovery       asset recovery debugging
auth                 user authentication debugging
autocfg              Auto config debugging
av                   anti virus scan debugging
bgp                  bgp debugging
bgroup               bgroup debugging
cav                  cavium debugging
cluster              command propagated to cluster members
cpapi                cpapi debugging
cpu-limit            CPU limit debugging
dhcp                 debug dhcp
dhcp6                dhcpv6 debugging
dialer               dialer debugging
dip                  dip debugging
dlog                 dlog debugging
dns                  dns debugging
dot1x                IEEE802.1X debug
driver               driver debugging
emweb                EmWeb debugging
filesys              Filesys debugging
fips                 fips debugging
flash                flash operating debugging
flow                 Flow level debugging
flow-tunnel          Flow Tunnel debugg

(output shorten)


We are going to do  flow and basic at that;


iscreen:-> debug flow ?
debug flow ?
all                  all flow debug
basic                basic debug
drop                 drop pak debug
dynpol               dynamic policy search debug
illegal              illegal debug
internal             internal debug
mcast                flow multicast debug
mgt                  mgt debug
mpak                 mp pak message debug
mpdiff               mp diff message debug
mperr                mp message error debug
mpgate               mp gate message debug
mpmvpn               mng over vpn message debug
mpsess               mp session message debug
mpvpn                mp vpn message debug
pak-poll             packet polling debug
self                 self debug
session              session debug
sm-skip              No pak passing to SM
spinlock             spinlock
tcp-sequence-check   tcp sequence check debug
tiny-tcp             tiny tcp debug
vlan                 vlan debug


and;


iscreen:-> debug flow basic
basic
iscreen:->


4th, Next we want to flush any existing debug buffer data;

iscreen:-> clear db
clear db


and after we craft traffic,  we review the buffer via a simple get  cmd;


iscreen:-> get db stream
get db stream

iscreen:-> get  db stream
get  db stream
****** 12514.0: <Trust/trust> packet received [62]******
  ipid = 9288(2448), @026ddc70
  packet passed sanity check.
  trust:172.16.10.24/50291->8.8.8.8/53,17<Root>
  no session found
  flow_first_sanity_check: in <trust>, out <N/A>
  chose interface trust as incoming nat if.
  flow_first_routing: in <trust>, out <N/A>
  search route to (trust, 172.16.10.24->8.8.8.8) in vr trust-vr for vsd-0/flag-0/ifp-null
  [ Dest] 12.route 8.8.8.8->192.0.2.1, to untrust
  routed (x_dst_ip 8.8.8.8) from trust (trust in 0) to untrust
  policy search from zone 2-> zone 1
 policy_flow_search  policy search nat_crt from zone 2-> zone 1
  RPC Mapping Table search returned 0 matched service(s) for (vsys Root, ip 8.8.8.8, port 53, proto 17)
  No SW RPC rule match, search HW rule
  Permitted by policy 1
  dip id = 2, 172.16.10.24/50291->192.0.2.191/2099
  choose interface untrust as outgoing phy if
  no loop on ifp untrust.
  session application type 16, name DNS, nas_id 0, timeout 60sec
ALG vector is attached
  service lookup identified service 16.
--- more ---  
  flow_first_final_check: in <trust>, out <untrust>
  existing vector list 81-3582ba0.
  Session (id:1959) created for first pak 81
  flow_first_install_session======>
  route to 192.0.2.1
  arp entry found for 192.0.2.1
  nsp2 wing prepared, ready
  cache mac in the session
  make_nsp_ready_no_resolve()
  search route to (untrust, 8.8.8.8->172.16.10.24) in vr trust-vr for vsd-0/flag-3000/ifp-trust
  [ Dest] 1.route 172.16.10.24->172.16.10.24, to trust
  route to 172.16.10.24
  flow got session.
  flow session id 1959
 flow_send_vector_, vid = 0, is_layer2_if=0
  send packet to traffic shaping queue.
  flow_ip_send: 2448:192.0.2.191->8.8.8.8,17 => untrust(62) flag 0x20000, vlan 0
 pak has mac
  Send to untrust (76)
Interface <untrust> IPv6 disabled, drop IPv6 packet.
****** 12514.0: <Untrust/untrust> packet received [78]******
  ipid = 16418(4022), @02691970
  packet passed sanity check.
  untrust:8.8.8.8/53->192.0.2.191/2099,17<Root>
  existing session found. sess token 6
  flow got session.
  flow session id 1959
  existing vector list 81-3582ba0.
 flow_send_vector_, vid = 0, is_layer2_if=0
  send packet to traffic shaping queue.
  flow_ip_send: 4022:8.8.8.8->172.16.10.24,17 => trust(78) flag 0x20000, vlan 0
 pak has mac
  Send to trust (


NOTE:  You should always clear your debug information when your done to save on memory and wasted process. Always validate this has been done.


iscreen:-> undebug all
undebug all
iscreen:-> get debug
get debug
iscreen:->


Some of the things to focus on with regards to the debug output;

·      Any Permit/Deny

·      Zone ( trust to untrust or whatever zones )

·      Interfaces involved

·      The Policy-ID # ( that's your fwpolicy or rule )

·      Src/dst-ip ( should match your filter if applied)

·      Src/Dst-Port ( should match your filter if applied )



I hope this post helps you in your on going diagnostics.

Ken Felix Freelance Network/Security Engineer
Kfelix at hyperfeed  <d-o-t> com

Monday, March 18, 2013

HTTP/HTTPs traffic generation with curl

I ran into a problem with https neg and one of my favorite http tool ( apache benchmark ). So I needed away to  generate http traffic for testing and review.

Here's a small script that uses curl;

#!/bin/bash
#
#

#rev 1.0

#  HTTP requester for traffic generation via curl
#  full http.request == HEAD
#
#  Be carefull not to flood any downwind DoS detector/WAFs, and be kind to your client sever(s)!
#
#
if [ ! $1 ]; then
            echo " Usage : http_requester.sh <delay in seconds between requests>  < The #of requests to execute> url1 url2 url3 url4 url5 "
            echo ""
            echo "Example  http_requester.sh 5 10 https://www.1example.com http://www.2example.com https://www.3example.com http://www.4example.com http://www.5example.com"
            echo ""
        echo " You can test upto 5 unique URLs & no more than 1K requests "

            exit 1
fi

#
i="0"

#

COUNTER=$2
MAX=1001

if  (( $2 >= $MAX )) ; then

        echo "   "
        echo "Please make a request range of <1000 or less"
        echo "   "
else


while [ $i -lt $COUNTER ] ;

  do  curl -k  -v --head --keepalive  -L {$3,$4,$5,$6,$7}
  echo "   "
  echo " Request # $i "
  echo "   "
  sleep $1

  echo "The request was completed, and $COUNTER http.requests was sent!"

  i=$[$i + 1]

#   let "COUNTER += 1"

done

fi

#



Ken Felix
Freelance Network/Security Engineer
kfelix a-t hyperfeed d-o-t com

Monday, March 11, 2013

How to identify a DoS flood

 
In this post, we will talk about  DoS flooding and how to recognize that your being flooded. 

An associate of mine, recently came under a small udp flood, and needed analysis to help determine that he was indeed under a small under 250megs flood. Since many years ago and  in a former past life, I ‘ve been a crafter of tcp/udp/icmp floods, so I offered my experience on how to detect these floods.

With most flooding tools, they have one flaw that’ easily picked upon. No matter how much they try to randomize their src_address, the src_ports are almost never  randomized.

Even with icmp_floods, we have some tell-tale signs of the flooding that can't  be hidden.

In my example, I will use a very common tool  ( hping ) and will show you how you can quickly identify that your being flooded.

In ALL DoS and DDoS flooding attacks, the goal is for the attacker(s) to exhaust server/network resources. This could be via bandwidth consumption, or server tcp tcb exhaustation.  Attack at Layer3/4 are typically used by most attackers, and it’s common to  spoof the sources , or if conducting a some type of reflection, we spoof some other innocent bystander address(es).

In all of these attacks, the  SRC_PORT are rarely  random and will increase in a sequence range that’s consecutive and increasing by minimum of 1. This is the flaw that allows for one to identify that a flood is happening.

In my  example, we will use tshark and the –T –e options for fields

Here’s in this case  the attacker  conducted a udp flood  towards a dns server at 192.0.2.1 ;   hping –fast -2 –rand-source ­–p 53  192.0.2.1

In the above we sent a UDP flood targeting  192.0.2.1, &  with a dest_port == 53. So if one was to monitor traffic destination to  192.0.2.1 , we will find the  src_port are increasing consecutively, but with various random sources.

( output truncated )



 tshark -r file-udp.pcap  udp -T fields -e udp.srcport  -e ip.src

Running as user "root" and group "root". This could be dangerous.

1301    9.35.49.162

1302    45.181.159.172

1303    136.26.121.252

1304    57.13.211.54

1305    201.127.52.18

1306    54.77.144.164

1307    140.145.233.186

1308    252.150.97.164

1309    212.101.20.22

1310    186.80.49.107

1311    64.48.137.160


Now let’s look at the same  style attack, but now with a tcp syn_flood. Here’s the attacker tcp flood  a web server at 192.0.2.1,  and the cmd execution, using hping the flood would be executed as such ;  hping –fast -2 –rand-source ­–p 80 192.0.2.1

And now using tshark  and fields, we would find consecutive increasing src_ports again;

( output truncated )



tshark -r file_tcp.pcap  tcp -T fields -e tcp.srcport -e ip.src

Running as user "root" and group "root". This could be dangerous.

1595    205.167.39.167

1596    12.236.13.105

1597    253.137.231.137

1598    188.34.147.67

1599    169.51.152.239

1600    21.152.7.4

1601    133.152.135.163

1602    144.36.170.54

1603    216.99.236.9

1604    61.105.135.209

1605    202.99.240.95

1606    115.13.215.41

1607    116.162.32.81

1608    116.161.142.239

1609    54.216.81.81

1610    187.133.220.9

1611    65.39.33.3

1612    1.169.67.81

1613    128.7.34.34

1614    99.0.23.126

1615    224.162.208.116

1616    250.40.105.123

1617    227.174.7.94

1618    224.39.169.65

1619    171.99.21.2

1620    242.141.67.142

1621    141.83.22.10

1622    249.159.239.140

NOTE:
You notice how in both cases, the attack has random src_address,  but the port number where not? This is the flaw in ALL L4 floods where the sources_ports are not randomized. 

So using tshark/wireshark along with  cisco flow top talkers and/or your firewall sessions monitor, can provide insight on a potential tcp/udp flood.


Now let’s look at icmp, their’s no port # , but we have other clues that a flood is happening. Look here at this output;

[kfelix@attack01:~]> tcpdump -r file.pcap -n icmp

reading from file file.pcap, link-type EN10MB (Ethernet)

05:29:01.204184 IP 193.118.93.172 > 192.0.2.1: ICMP echo request, id 60417, seq 0, length 8

05:29:02.207244 IP 213.178.131.23 > 192.0.2.1: ICMP echo request, id 60417, seq 256, length 8

05:29:03.217264 IP 227.210.11.229 > 192.0.2.1: ICMP echo request, id 60417, seq 512, length 8

05:29:04.227294 IP 105.132.157.53 > 192.0.2.1: ICMP echo request, id 60417, seq 768, length 8

05:29:05.237301 IP 99.54.225.72 > 192.0.2.1: ICMP echo request, id 60417, seq 1024, length 8

05:29:06.247296 IP 36.118.223.171 > 192.0.2.1: ICMP echo request, id 60417, seq 1280, length 8

05:29:07.257303 IP 198.223.148.121 > 192.0.2.1: ICMP echo request, id 60417, seq 1536, length 8

05:29:08.267313 IP 253.35.224.74 > 192.0.2.1: ICMP echo request, id 60417, seq 1792, length 8

05:29:09.277343 IP 201.82.75.35 > 192.0.2.1: ICMP echo request, id 60417, seq 2048, length 8



or  by using  tshark we get the following;

[kfelix@attack01:~]> tshark -r file.pcap -V icmp -T fields -e icmp.ident -e ip.src

Running as user "root" and group "root". This could be dangerous.

0xec01 193.118.93.172

0xec01 213.178.131.23

0xec01 227.210.11.229

0xec01 105.132.157.53

0xec01 99.54.225.72

0xec01 36.118.223.171

0xec01 198.223.148.121

0xec01 253.35.224.74

0xec01 201.82.75.35


I hope this post has been helpful for identifying  flood attacks, &  in either realtime or for post forensics

Ken Felix
Freelance Network/Security Engineer
kfelix  a-t hyperfeed d-o-t com

Intro: Fortigate FWF 60D firewall SOHO ( wireless )

Here's a quick review of my newly purchased  Fortigate FWF60D firewall appliance.


This series of firewall 60D are designed around the  SOHO/SMB sector. I purchased this unit due to I needed a cheap firewall to conduct my studies for  FortiOS v5.0 and my 60B which has been faithful was just not going to make it, due to  Fortinet has drop this model from any version 5.0 software.

You can find more about this series firewall at ;  http://www.fortinet.com/products/fortigate/60D.html

I purchased this unit from my local Partner "Tony Wells" of  Maxis ( secure datacom ) ; http://www.maxisnetworks.com/ who I've know now for a few years. They offer a wide range of IT services, primarily in the network and security arena. They  based in the SE-Florida  market but pretty covers a wide range of areas.

The FWF60D is a multiple port wireless model  appliance, the above link will give you the performance specifications and the available options. The 1st thing will notice is the unit has the new off whitish coloring , no standard console port {rj45} and this weird power connector.






I believe Fortinet did this to save money. They are pushing the FortiExplorer, which I didn't use on this model.  The FortiExplorer allows for quick configuration via mini-USB port. These reduction does not seem to reduce the feature capabilities.

The unit is the same size as the previous  A B C models, Here's one of my earliest  FGT60 and you will see the difference in the coloring , and the sizes are similar. This older unit btw, has been functional since I purchased it  in the late 2006s, with zero problems.




My new unit,  has 7 user ( internal ) ports , 1 dmz port, and 2 WAN ports label WAN1 & WAN2.  This option gives you a wide range of ports for your uses, and  for customization. The unit I've purchased also comes with 802.11 wifi support. This unit is a 1.5gbps thru-put model. This is not bad for a unit  that's less than $575 dollars, and pretty much has no license restriction as what one will find with a similar cisco or juniper product :)



The unit is great for a home or small office setup. The foot print is small and the unit can be wall mounted if one so desires. Here's the unit on my office desk, great for a environment where you need a security appliance such as a admin office, store kiosk, etc..... With the wifi support, you can accommodate your mobile devices from a cellphone, notebook/tablet, to a wifi enable POS terminal.




KENFWF60D # get sys status
Version: FortiWiFi-60D v5.0,build4108,130130 (GA)
Virus-DB: 16.00560(2012-10-19 08:31)
Extended DB: 1.00000(2012-10-17 15:46)
IPS-DB: 3.00249(2012-10-11 02:47)
IPS-ETDB: 0.00000(2001-01-01 00:00)
Serial-Number: FWF60D4612000140
Botnet DB: 1.00000(2012-05-28 22:51)
BIOS version: 04000010
System Part-Number: P12482-02
Log hard disk: Available
Internal Switch mode: switch
Hostname: KENFWF60D
Operation Mode: NAT
Current virtual domain: vdom11
Max number of virtual domains: 10
Virtual domains status: 10 in NAT mode, 0 in TP mode
Virtual domain configuration: enable
FIPS-CC mode: disable
Current HA mode: standalone
Branch point: 147
Release Version Information: GA
System time: Mon Mar 11 09:34:51 2013




The dashboard has not change by much and has the same old reliable feel and function. The fortinet dashboard is what make this model more superior to use  than a common Cisco 5505 imho. The ease and quickness in the WebUI interface, is something that can't be beat outside of the Fortinet community.




The unit is simple to register for support and access for UTM features such as ips signatures, avupdates, etc....It will even warn you if the unit is not registered or did not finish registering.




Stay tune for more reviews on  FortiOS version 5.0 and newly create features.

Ken Felix
Freelance Security/Network Engineer
kfelix  a-t hyperfeed d-o-t com