본문 바로가기

교육 및 자격증/KISA : YARA기반 정규 표현식 활용

Yara 실습

728x90

 

1.  아래 문장에서 숫자만 인식되도록 작성 = \d or [0-9]
AB12CD34EF56GH78IJ90

2. 아래 문장에서 영문, 숫자, 언더바를 제외한 모든 문자를 인식하는 표현식 작성 = [^A-z0-9] or \W
가A나B다C라D마E123456

3. 아래 문장에서 공백을 제외한 모든 문자를 인식 = [A-z0-9-/:\.] or \S
     2023/05/28 11:57:33 GET 200 http://coresec.co.kr
----2023/05/28 11:57:33 GET 200 https://www.coresec.co.kr/_login
  2023/05/28 11:57:33 POST 200 https://coresec.co.kr/api/login

4. 아래 문자 라인에서 ball과 balls 라인만 인식하기 = balls?[^es] or balls?$
ball
balls
ballses
ballseses

5. 아래 문장에서 마지막 문자가 ce로 끝나는 단어를 모두 인식하기 = \S*ce\b
ice miss erase voice cheese chess cell

 

6. 아래 문장에서 s가 2개 이상 존재하는 문장을 수량자를 이용하여 인식하기 = .+SS. or .+S{2,}.

 

서비스종료 [불만 : SSSSSS]
서버롤백 [불만 : SSSS]
긴급점검 [불만 : SSS]
연장점검 [불만 : SS]
임시점검 [불만 : S]
정기점검 [불만 : A]
잠수패치 [불만 : B] 

 

7. 아래 문장에서 중간 글자를 기준으로 앞 뒤가 동일한 단어를 인식하기 = (.[마|러|디].) or (.)[마|러|디]\1 or (.)\S\1
토마토 토기 기러기 기오 오디오

 

응용

1. 아래 전화번호에서 대한민국 전화번호만 인식되도록 작성 = 0[1-6]{1,2}-\d{3,4}-\d{4}

 

서울특별시 02-2416-5421
미국 1-800-225-5726
경기도 031-341-2145
인천광역시 032-248-3154
강원도 033-248-7316
충청남도 041-318-3148
대전광역시042-422-3978
일본 0120-01-0930
충청북도 043-9721-3458
세종특별자치시 044-751-3491
부산광역시 051-333-6424
울산광역시 052-218-9710
대구광역시053-747-3180
경상북도 053-048-7203
경상남도 055-710-4806
전라남도 061-879-3181
광주광역시 061-413-7908
전라북도 063-413-8410
제주특별자치도 064-050-3189
미국 1-800-438-8446

 

2. 아래 데이터에서 010으로 시작하는 휴대전화 번호를 모두 인식하기 = \b010[\-\.]\d{4}[\-\.]\d{4}[^\-\.]

 

010-4352-0117
011-3597-2197
010-5487-5152-0154-3244-115
019-5248-6782
010-5792-3182
0010-0011-0110-0110-1101-0010-1011
010-32-421-8422
010-8876-2167
010.2957.2498
010.168.052.026
192.168.21.15

 

3. 유효한 이메일 주소가 포함된 라인을 모두 인식하기 = ^[\w\.\+\-]+@[\w\.\-]+$

 

<유효한 이메일 주소>
prettyandsimple@example.com
very. common@example.com
disposable.style.email.with+symbol@example.com
other.email-with-dash@example.com
x@example.com
example-indeed@strange-example.com
example@localhost example@s.solutions
user@localserver

 

<유효하지 않은 이메일 주소>
Abc.example.com
A@b@c@example.com
just"not"right@example.com
this is"not\allowed@example.com
this\ still\"not\ \allowed@example.com

4.  URL을 포함한 HTML 태그를 모두 인식하기
<div id="gnb-menu">
<div>Title</div>
<p class="naver-h" id="naver-h">
<a href="https://section.cafe.naver.com">7</a>
<img src="https://cafe.pstatic.net/cafe4/ico-blank.gif" width="1" height="10" alt="" class="tcol-c"></img>
</p>
<div id="button_town_cafe" class="town-cafe">
<a href="https://cafe.naver.com/ca-fe/home/town" target="_blank">0|£</a>
<img
src="https://cafe.pstatic.net/cafe4/ico-blank.gif" width="1" height="10" alt=""
class="tcol-c"></img>
</div>
<div id="button_join_cafe" class="join-cafe off">
<a href="#"></a>
<a href="#"><img id="joincafeimg" src="https://cafe.pstatic.net/cafe4/hidden.gif" width="13" height="13" alt="7||||" class="btn-join down-gnb"></a>
<img src="https://cafe.pstatic.net/cafe4/ico-blank.gif" width="1" height="10" alt="" class="tcol-c"></img>
</div>
<div id="button_mynews_alarm" class="chatting-cafe">
<a href="#" class="link_chatting"></a>
<img src="https://cafe.pstatic.net/cafe4/ico-blank.gif" width="1" height="10" alt="" class="tcol-c"></img>
</div>
<div id="button_mynews_activity" class="chatting-cafe mynews-cafe off">
<a href="#" class="link_chatting"></a>
<img src="https://cafe.pstatic.net/cafe4/ico-blank.gif" width="1" height="10" alt="" class="tcol-c"></img>
</div>
<div id="layer_mynews_activity" class="cc_layer_mynews" style="display: none"> <div class="cc_mynews_header">
<h2 class="title"></h2>
</div>
<div class="cc_mynews_content">
<div class="cc_mynews_none" style="display: none">
<strong class="title">4.</strong>
<p class="txt">가입한 카페의 활동 알림과 댓글알림을<br>이곳에서 모아볼 수 있어요.</p> </div>
<div class="cc_mynews_area" style="display: none">
<span class="blind"> 30.</span>
<ul class="cc_mynews_list">
<li id="_mynews_notice_tooltip">
<div class="cc_mynews_notice">
<p class="notice_txt">
수 있어요.
<span class="icon_option"></span> HE
</p>
<!-- [D] .btn_close 클릭 시 공지 레이어는 미노출되게 해주세요~ --> <button id="_btn_hide_mynews_notice" type="button"
class="btn_close"><span class="blind">| |</span></button>
</div>
</li>
</ul>
</div>
</div>
</div>