Showing posts with label Security. Show all posts
Showing posts with label Security. Show all posts

Wednesday, March 11, 2015

Regular Expression

Special character
Explanation
 .
The “.” matches any single character. For example, “d.g”matches “dog”, “dig”, “dug”, and any word that contains those characters, like “daggonnit”.
(exp)
The “()” segregates characters from the surrounding characters, so that you can use other metacharacters on the subexpression. For example, “d(o|i)g” matches “dog” and “dig”, but “do|ig” matches “do” and “ig”. A subexpression can also be used with repeated quantifiers to differentiate the characters meant for repetition. For example, “12(34){3}5” matches “123434345”.
|
The “|” matches either expression it separates. For example,  “dog|cat” matches “dog” or “cat”.
?
The “?” indicates that there are 0 or 1 of the previous character. For example, “ra?ise” matches on “raise” or “rise”. Note that you must enter Ctrl+Vand then the question mark, or else the ASA CLI help function is performed instead.
    •  
The “*” indicates that there are 0, 1, or any number of the previous character. For example, “mo*se” matches on “mse”, “mose”, “moose”, and so on.Continues…
+
The “+” indicates that there is at least 1 of the previous character. For example, “mo+se” matches on “mose” and “moose”, but not “mse”
{x} or {x,}
The “{}”, with a number between the braces, indicates the previous expression is repeated at least “x” times. For example, “ab(fd){2,}e” matches “abfdfde”, “abfdfdfde”, and so on
[abc]
The “[]” matches any character in the brackets. For example, “[Rr]” matches on “R” or “r”.
[^abc]
The “[^]” matches a single character that is notcontained within the brackets. For example, “[^abc]” matches any character other than “a”, “b”, or “c”; or “[^A-Z]” matches any single character that is not an uppercase letter
[a-c]
The “[-]” matches any character in the range. For example, “[A-Z]” matches any uppercase letter. You can also mix characters and ranges: “[abcq-z]” matches “a”, “b”, “c”, and “q” through “z”. You could also write this as “[a-cq-z]”.
" abc"
The “""” preserves trailing or leading spaces in the string. For example, " secret" preserves the leading space when it looks for a match.
^
The “^” specifies the beginning of a line
\
The “\”, when used with a regular expression metacharacter, matches a literal character. For example, “\.” matches a period (“.”). This is used when you want to match on a character that is itself a metacharacter.
\r
The “\r” matches on a carriage return.
\n
The “\n” matches on a new line.
\t
The “\t” matches on a tab
\f
The “\f” matches on a form feed (new page)
\x
The “\x” matches on an ASCII character specified by the two hexadecimal digits (NN).
\NNN
The “\” matches on any ASCII character specified as octal (the three digits listed).

Reflexive ACL

- Đặc điểm:
ACLs này chỉ đc tạo bởi Extend Name ACLs không đc tạo bởi Numbering hay Standard Name ACL
- Ứng dụng:
Được sử dụng để cho phép các IP traffic từ bên ngoài của session mà khởi tạo từ bên trọng nội mạng và ngăn những IP traffic khởi tạo session từ mạng bên ngoài. ACLs này sẽ xem xét gói tin gởi ra ngoài nếu là gói khởi tạo session nó tự động thêm vào một outbound entry để cho phép traffic trả lời về. Rèflexive ACLs có thể lọc session tốt hơn thay vì chỉ ACK và RST bit như câu lệnh permit…established. Rèflexive lọc cả địa chỉ nguồn, đích, port, ACK và RST bit của gói tin. Ngoài ra, session filtering sử dụng những bộ lọc tạm thời cái mà được xóa khi một session kết thúc.

This procedure automatically permits returning traffic for symmetric flows. It will not work for “non-standard” TCP applications, which are complicated protocols such as RCP, TFTP, and H323, which open dynamic channels with no way for a router to predict their behavior.

Cách tạo Reflexive ACLs:
Ví dụ

Cau hinh R4 sao cho:
+ L0 cua R5 khong the ping duoc L0 cua R6
+ L0 cua R5 ping duoc L0 cua R6 khi R6 thuc hien ping den L0 R5


+ Cấu hình ACLs cho phép ICMP và TCP traffic cả chiều inbound và outbound nhưng chỉ cho phép nếu gói tin đầu tiên của session bắt nguồn từ mạng nội bộ. Tất cả các traffic khác sẽ bị cấm. Reflexive ACLs được gán trên interface f0/1.
+ Các bước cấu hình:

Step 1: Tạo một Extend name ACLs để cho phép các traffic đi ra ngoài Internet

ip access-list extended LOCAL
 permit udp any any eq rip
 permit icmp any any reflect STA

Step 2: Tạo một Extend name ACLs để chứa Reflexive ACLs tự động được tạo ra khi có gói outbound match với Name ACLs ở bước 1.

ip access-list extended INTERNET
 permit udp any any eq rip
 evaluate STA
 deny   ip any any log

Step 3: Gán các name ACLs cho interface

interface fasthernet0/1
 ip address 204.12.1.4 255.255.255.0
 ip access-group OUTBOUND in

interface Serial0/0
 ip address 155.1.45.4 255.255.255.0
 ip access-group INTERNET in


#ip reflexive-list timeout {seconds}  - Changes global timeout value for temporary reflexive ACEs


TEST:
thuc hien ping tu R5 toi L0 R6.


Ping L0 R5 tu R6 voi source L0.


Kiem tra R4:


 R4 tao ra mot access-list cho phep L0 R5 ping toi L0 R6. trong khoang thoi gian "time left"

5.6. Time-based ACLs
  • Đặc điểm: chức năng tương tự extended ACLs, nhưng chúng cho phép điều khiển truy cập dựa vào thời gian
  • Ứng dụng: Dùng để lọc gói tin dựa vào nhiều thông tin như Exended ACLs và dựa vào cả thông tin về thời gian.
  • Cách tạo Time-based ACLs:
Ví dụ: Thiết lập ACLs cho phép một kết nối Telnet được cho phép từ inside network tới the outside network vào Monday, Wednesday, and Friday trong suốt giờ hành chánh.
+ Các bước cấu hình:
Step 1. Định nghĩa khoảng thời gian để thi hành ACLs và đặt cho nó một cái tên.(khoảng thời gian này phụ thuộc vào giờ hệ thống trên router, chức năng này làm việc tốt với sự đồng bộ thời gian của giao thức Network Time Protocol (NTP) nhưng lúc này đồng hồ của router không được sử dụng. )
Step 2. Áp dụng khoảng thời gian này cho ACLs
Step 3. ÁP dụng ACL cho interface.


Standard ACL

Standard ACLs only allow you to match source IP addresses based on “base” IP address and wildcard mask. Because of that “aggregate” behavior, standard ACLs are commonly configured at network nodes close to the “protected” object. One very common task is finding a required “base” IP address and wildcard mask pair based on set of requirements. Let us look at three different examples to illustrate how they could be solved.

Ví dụ 1: Configure the IP/Wildcard Mask pair to match IP addresses in subnets 155.1.Y.0/24 where Y is an even number and is greater than or equal to 1 and less than or equal to 6.

Bước 1:
2=00000010
4=00000100
6=00000110

Bước 2: Tìm "bit vector"  so sánh với các giá trị, những bit nào thay đổi thì cho bằng 1, bit không thay đổi cho bằng 0.
=>          m=0000110=6
Đây chính là wildcard mask cho giá trị octet thứ 3 thỏa mãn: 0.0.6.255

Bước 3: Tìm "base" dùng thuật toán AND.

=>       2 AND 4 AND 6 AND = 0
 Là giá trị bit thứ 3. 155.1.0.0

Kết quả access-list cần tìm : permit 155.1.0.0 0.0.6.255

Ví dụ 2: Configure the IP/Wildcard Mask pair to match IP addresses in subnets 155.1.Y.0/24 where Y is an odd number and is greater than or equal to 1 and less than or equal to 6.

Bước 1:
1=00000001
3=00000011
5=00000101

Bước 2: Tìm "bit vector"  so sánh với các giá trị, những bit nào thay đổi thì cho bằng 1, bit không thay đổi cho bằng 0.
=>          m=0000110=6
Đây chính là wildcard mask cho giá trị octet thứ 3 thỏa mãn: 0.0.6.255

Bước 3: Tìm "base" dùng thuật toán AND.

=>       1 AND 3 AND 5 AND = 1
 Là giá trị bit thứ 3. 155.1.1.0


Kết quả access-list cần tìm : permit 155.1.1.0 0.0.6.255