Regex for Cisco IOS Firewall/IP Inspection Sessions

Cisco devices running IOS come with a feature called CBAC which can be configured to allow return traffic back into a network while maintaining a deny ip any any ACL on the external interface. In times past this was achieved through reflexive ACLs, using the established keyword in the ACL, or in some cases allowing in all traffic destined to ports grater than 1024.

IOS Firewall overcomes this by providing Layer 3 to 7 inspection on outgoing traffic and allowing return traffic back into the network.

The show ip inspect session command displays the list of current sessions, similar to the output below.

Session 66AF9CEC (>(116.50.x.x:8081) tcp SIS_OPEN
Session 66AF8BDC (>(74.125.x.x:5222) tcp SIS_OPEN
Session 691B75A8 (>(74.125.x.x:443) https SIS_OPEN
Session 691B1D80 (>(107.23.x.x:443) https SIS_OPEN
Session 66B02844 (>(116.50.x.x:8081) tcp SIS_OPEN
Session 66B03F04 (>(116.50.x.x:8081) tcp SIS_OPEN
Session 68CA82C4 (>(216.151.x.x:119) tcp SIS_OPEN
Session 66B063FC (>(216.151.x.x:119) tcp SIS_OPEN
Session 66AFD01C (>(206.16.x.x:443) https SIS_OPEN
Session 66B00074 (>(138.99.x.x:4569) udp SIS_OPEN
Session 66B00BD4 (>(74.125.x.x:5222) tcp SIS_OPEN
Session 691B6A48 (>(17.158.x.x:443) https SIS_OPEN
Session 66AFFAC4 (>(74.125.x.x:5222) tcp SIS_OPEN

The following regex will isolate the second IP address in the above output. When IP inspection is applied on the external interface in the outbound direction the second IP address will correspond with the external resource being accessed.

I’ve seen shorter versions but none seem to work well with the Python regular expression implementation. Not having a strong regex background, the real challenge was creating an expression that would skip the first IP address and only match the second. This was accomplished by using a negative lookahead.

Once the external IP is isolated it can be used with other tools such as GeoIP lookups (why are there so many connections from that host going to Russia?).

If you enjoyed this post consider sharing it on , , , or , and .