ก่อนหน้านี้เราเคยพูดถึงการเขียน Yara Rule เพื่อรองรับการเขียน rule ใน IDS/IPS หรือ APT หรือ Antivirus สมัยใหม่ไปแล้ว ซึ่งหลักการสำคัญของ Yara คือเราต้องเข้าใจถึงลักษณะ pattern ของไฟล์ที่เราต้องการตรวจจับแบบ Unique (แบบไม่เหมือนใคร) ไม่งั้นจะกลายเป็นเกิด false positive จำนวนมากแทนได้ นั่นคือที่มาของการใช้งาน YarGen

YarGen เป็นเครื่องมือสำหรับการสร้าง Signature และ Yara Rule จากคำ (string) ที่พบใน Malware ซึ่ง string ที่ถูกสร้างขึ้นจะไม่มีการซ้ำกับคำที่เป็นคำทั่วไป (goodware files). ตัว YarGen มีการเก็บไว้ทั้งส่วนของ string ของไฟล์ทั่วไปและ opcode database ของไฟล์ที่ถูก pack หรือ zip มาด้วย อีกทั้งหากเราต้องการ include blacklist คำ string ที่จะยกเว้นการสร้างเพิ่มเติม สามารถทำได้โดยการแก้ไข strings.xml ที่ได้รับ port จาก PEStudio อีกด้วย

Requirement: เครื่องที่จะลงและใช้งาน YarGen ได้จำเป็นต้องมี RAM อย่างน้อย 4GB (6GB หากมีการสร้าง rule ที่มี opcode ด้วย)

วิธีการติดตั้งมีดังนี้

1. Clone Git

2. ติดตั้ง dependency package

3. Clone Binarly-SDK

4. Install Binarly-SDK

5. หากต้องการ update ใช้เป็น

6. ทดสอบใช้งาน

ใช้ goodware strings database ที่ให้มาและทำการ scan malware directory “X:\MAL” จากนั้นสร้าง rule ต่างๆไว้ในไฟล์ yargen_rules.yar

python yarGen.py -m X:\MAL\Case1401

โดยปกติ yarGen จะใช้ top 20 strings ที่เจอมาเป็น score แล้วนำมาทำเป็น string สำหรับการสร้าง rule แต่หากเราต้องการแสดง score ของ string แต่ละตัวใช้เป็น –score เพิ่มเข้าไปด้วย

python yarGen.py --score -m X:\MAL\Case1401

ใช้ string ที่มี score ขั้นต่ำตามที่เรากำหนดเท่านั้นในการสร้าง rule โดยใช้ option -z

python yarGen.py --score -z 5 -m X:\MAL\Case1401

กำหนดชื่อของผู้เขียน rule และ reference โดยใช้ -a และ -r ตามลำดับ และ output Yara Rule ออกมาเป็น case441.yar

python yarGen.py -a "Florian Roth" -r "http://goo.gl/c2qgFx" -m /opt/mal/case_441 -o case441.yar

สร้าง opcode rule

python yarGen.py --opcodes -a "Florian Roth" -r "http://goo.gl/c2qgFx" -m /opt/mal/case33 -o rules33.yar

เอาคำใดๆที่ตรงกับใน database ของคำที่เจอปกติออกจาก rule

python yarGen.py --excludegood -m /opt/mal/case_441

แสดง debugging output

python yarGen.py --debug -m /opt/mal/case_441

สร้าง database ของคำปกติ ทั้ง opcode และ string โดยใช้ -g option

python yarGen.py -c --opcodes -g /home/user/Downloads/office2013 -i office

database ที่จะได้

  • good-strings-office.db
  • good-opcodes-office.db

Best Pratice Command Line

python yarGen.py --opcodes -a "Florian Roth" -r "Internal Reserahc" -m /opt/mal/apt_case_32 -o rules32.yar

Source:: yarGen