สยามถนัดแฮก

บริการ Penetration Testing ติดต่ออีเมล pentest@sth.sh หรือ LINE @siamthanathack

Follow publication

AI จะมาแย่งงาน IT Security ได้ยังไง

“AI กำลังจะครองโลก ในอีก 20 ปี” — ไค ฟู ลี, ผู้เชี่ยวชาญด้าน AI

คำทำนายของงานที่จะถูก AI จะแย่งมนุษย์ทำ (จาก TED 2018 โดย ไค ฟู ลี)

OpenAI.com เป็นเว็บไซต์ที่เปิดมาสักพักแล้ว แต่เพิ่งเปิด Model ของ AI ที่ชื่อว่า GPT-3 ให้ใช้งาน ถ้าอ้างอิงจาก Wikipedia จะพบว่าอยู่ภายใต้บริษัท OpenAI ที่ทำธุรกิจด้าน AI และเป็นคู่แข่งโดยตรงกับ Google DeepMind รวมถึงได้รับการลงทุนจากคนดังอย่าง Elon Musk (เคยนั่งเป็นบอร์ดบริหารด้วย) และได้รับเงินลงทุน 1 พันล้าน USD จาก Microsoft

โดยสรุปสั้น ๆ แล้วเว็บ OpenAI ณ ตอนนี้ยอมให้ใครก็ได้สมัครฟรี เพื่อลอง คุย ถามคำถาม กับ AI เพื่อค้นหาคำตอบในสิ่งที่เราต้องการ ซึ่งรองรับทั้งภาษาไทยและภาษาอังกฤษ แต่จากเท่าที่ผู้เขียนลองทดสอบ ภาษาไทยยังไม่ค่อยดีนัก แต่ภาษาอังกฤษนั้นดีสุด ๆ

ลองใช้งานได้ที่

คำถามที่น่าสนใจคือ…

  • เรามี Google เอาไว้หาข้อมูลแล้ว
  • มี Wikipedia เอาไว้อ้างอิงข้อมูลแล้ว
  • มี Stackoverflow เอาไว้ค้นหาโค้ดหรือแก้ปัญหาใด ๆ แล้ว

ทำไมเรายังต้องมาถาม OpenAI อีก?

คำตอบก็คือ

  • ในหลายกรณี OpenAI สามารถหาคำตอบได้ ชัดเจนตรงกับคำถามมากกว่าถาม Google หรือคำถามอื่นที่มีคนเคยถามไว้ใน Stackoverflow
  • OpenAI มีการสอดแทรกจริยธรรมและความคิดเห็นที่ดีลงไปในคำตอบด้วย !
  • สามารถช่วยเขียนโค้ดในภาษาต่าง ๆ อย่าง PHP, C, Java, Go, Rust รวมถึงสร้างไฟล์ในรูปแบบต่าง ๆ ไม่ว่าจะเป็น Yara Rule, Dockerfile, docker-compose, ไฟล์การตั้งค่าของ Service ต่าง ๆ ใน Linux และอีกมากมาย

โดยงานต่าง ๆ ถ้าแบ่งตามไคฟูลีก็จะแบ่งเป็น

  • Repetitive
  • Routine
  • Optimizing
  • Complex
  • Creative

และงานที่ AI เก่งจะทำก็คือ Repetitive และ Routine ซึ่งได้แก่ตัวอย่างงานที่สามารถสอนคอมพิวเตอร์ด้วยข้อมูลจำนวนมาก ๆ และ ถามคอมพิวเตอร์กลับได้ อย่างที่ OpenAI ช่วยเราตอบคำถามได้นั้นเอง

มาเข้าประเด็นเรามาดูตัวอย่างการนำ OpenAI มาแย่งงาน … เอ๊ย มาช่วยงานคน IT Security กันดีกว่า

ในบทความนี้จะขอยกตัวอย่างง่าย ๆ 10 กรณีดังนี้

(สามารถกดที่ลิงก์ข้ามไปดูตัวอย่างที่สนใจได้เลย)

#1 ใช้ OpenAI ช่วยหาช่องโหว่ในโค้ด

คำถามที่ใช้:

Find the vulnerability in the following Java code:

คำตอบที่ได้:

The vulnerability in this code is that it is vulnerable to command injection. By passing in malicious values to the “report_name” parameter, an attacker can execute arbitrary commands on the system.

จะเห็นว่า OpenAI รู้จักช่องโหว่หลาย ๆ อย่างเป็นอย่างดี แต่หลาย ๆ คนก็อาจจะเถียงว่า เพราะ Command Injection เป็นช่องโหว่เก่าที่รู้กันนานแล้ว ทำแบบนี้ใช้ Source Code Scanner ทั่วไปก็อาจจะสามารถหาได้เช่นกัน งั้นมาดูตัวอย่างถัดไป

#2 ใช้ OpenAI ช่วยหาช่องโหว่ใน Smart Contract

คราวนี้เราย้ายจาก Playground มาเป็น Chat บ้าง

คำถามที่ใช้:

Find the vulnerability in the following Smart Contract:

contract EtherStore {
mapping(address => uint) public balances;

function deposit() public payable {
balances[msg.sender] += msg.value;
}

function withdraw() public {
uint bal = balances[msg.sender];
require(bal > 0);

(bool sent, ) = msg.sender.call{value: bal}("");
require(sent, "Failed to send Ether");

balances[msg.sender] = 0;
}

// Helper function to check the balance of this contract
function getBalance() public view returns (uint) {
return address(this).balance;
}
}

ปรากฏว่าได้คำตอบคือ:

เจอสิ่งที่อาจจะเป็นช่องโหว่ 4 ช่องโหว่ใน Smart Contract !!

  1. เจอว่าใครก็สามารถสร้าง Smart Contract มาเรียก withdraw() ได้ และแนะนำให้มีการ Allowlist ไว้เฉพาะ Contract Owner อันนี้อาจจะ False Positive แต่ก็เป็นคำแนะนำและตัวอย่างที่ดีว่า AI ไม่รู้บริบทของ Smart Contract นี้ว่าใคร ๆ ก็ควรเรียก withdraw() ได้

2. เจอว่ามีช่องโหว่ Reentrancy !! อันนี้ของจริง และเป็นที่คาดหวังไว้ว่าจะเจอ คือสามารถโดน Smart Contract อื่นมา ถอนเงินมากกว่าที่ฝากเอาไว้ได้ แถมแนะนำวิธีแก้ไขให้ด้วย

และ 2 ช่องโหว่สุดท้ายที่พบคือ

3. Smart Contract นี้ไม่ได้จำกัดจำนวนเงิน (Ether) ที่ฝากได้โดยผู้ใช้งาน ทำให้ Smart Contract อาจจะ Gas หมดได้ พร้อมแนะนำตัวอย่างโค้ดวิธีตรวจสอบไว้ให้ด้วย สุดเกิ๊น

4. และสุดท้ายเจอช่องโหว่ Business Logic หรือเป็นปัญหาเล็ก ๆ ว่าฟังก์ชัน getBalance() จะตอบกลับจำนวนเงินของ Contract เองที่อาจจะมาจากอย่างอื่น นอกเหนือจากเงินที่ฝากโดยผู้ใช้งานที่เรียกฟังก์ชัน deposit() เข้ามา

กราบ.. OpenAI

#3 ใช้ OpenAI ช่วยหาช่องโหว่ใน Config โปรแกรม

คำถามที่ใช้:

Find the security issue in the following Nginx config:

server {
listen 80;
server_name localhost;
root /var/www/html;

location ~* \.(gif|jpg|jpeg|png|css|js)$ {
expires 28d;
}

location / {
alias /var/www/html/$uri;
}
}

คำตอบที่ได้!!:

The security issue in this Nginx config is that the “location” directive is not properly configured. The “alias” directive is used instead of the “root” directive for the location / block, which could lead to directory traversal attacks if an attacker is able to craft a malicious URL.

คือ OpenAI รู้ว่า Nginx config นี้มีช่องโหว่ Path Traversal จากการใช้ alias Directive ! ว้าวซ่า

หลังจากลองใช้หาช่องโหว่กันไปแล้วต่อไปลอง ขอคำปรึกษาพี่ OpenAI บ้าง

#4 ใช้ OpenAI ช่วยให้คำปรึกษาด้าน Security

คำถามที่ใช้:

I want to design a secure server-to-server API, what subjects that I have to be careful to avoid security issues.

(ต้องการจะออกแบบ API แบบใช้งานระหว่างเซิร์ฟเวอร์ด้วยกันเอง มีเรื่องอะไรต้องระมัดระวังบ้างด้านความปลอดภัย?)

คำตอบที่ได้:

OpenAI แนะนำ 8 ประเด็นที่ต้องระวัง มาให้เรียบร้อยตั้งแต่ต้องมี AuthN/AuthZ มีการทำ Input Validation มีการใช้งาน API Key ทำ Rate Limiting/Logging ต้องมีการทำ Security Audit โอ้วว..

คราวนี้มาลองทำ Mobile Hacking ด้วยความช่วยเหลือจาก OpenAI กันบ้าง

#5 ใช้ OpenAI ช่วยเขียนโค้ด Frida มา Bypass Mobile Client-Side Security

คำถามที่ใช้:

Write a Frida script to bypass root detection.

คำตอบที่ได้:

Write a Frida script to bypass Android Emulator checks (AVD and Genymotion).

คำตอบที่ได้:

ของ Frida อันนี้ไม่ถูกทั้งหมด แต่สามารถใช้เป็นแนวทางหรือไอเดียได้และกดหลาย ๆ ครั้งจะได้โค้ดที่ใช้เทคนิคหลาย ๆ แบบ ที่แตกต่างกัน

ดูจากฝั่ง Red Team กันไปแล้ว ต่อมาลองฝั่ง Blue Team กันบ้าง

#6 ใช้ OpenAI ช่วยเขียน Yara Rule

คำถาม:

Write Yara rule to detect Mimikatz binary. It must be able to detect obfuscated Mimikatz binary as well.

คำตอบ:

เทพซ่า AI มีการลองทำ ASCII Encode ให้ด้วย

#7 ใช้ OpenAI ช่วยเขียน Hacking Tool

คำถาม:

write rust code to take two command line arguments which are URL and a OS path to a wordlist file, then perform web directory fuzzing using each word in the wordlist file against the user-supplied URL. The web directory fuzzing must support HTTPS and show output for only word that returns HTTP response 200.

คำตอบที่ได้:

เขียนโปรแกรมทำ Directory Fuzzing ให้เรียบร้อยตามเงื่อนไขทุกอย่าง สุด ๆ ไปเลย

#8 ใช้ OpenAI ช่วยออกโจทย์ CTF

คำถามที่ใช้:

Write a CTF web challenge in Python that has two web APIs. The first API “health_check” takes HTTP parameter url, then make an HTTP request to user-supplied url, the request sent by this API will have a secret header and value attached. In the second API “diagnostic” is accessible only with the secret header and its value, the second API is vulnerable to SQL injection vulnerability in the value of the User-Agent header. Show me full source code.

คำตอบที่ได้:

สร้างโจทย์ให้เรียบร้อย

แก้ตัวใหม่ตอนแรก น้อง OpenAI งง ๆ นะครับ มาลองดูอีกโจทย์ Crypto

คำถามที่ใช้:

Create crypto CTF challenge, with RSA, difficulty level is medium. It should be solvable with math.

คำตอบที่ได้:

แถมน้องทำเฉลยให้ด้วย

#9 ใช้ OpenAI ช่วยเขียนโค้ด Exploit

คำถามที่ใช้:

Write a padding oracle exploit code in Python, attack a webpage that takes user input from HTTP POST parameter id at the URL https://sth.sh/vuln

คำตอบที่ได้:

คำถามที่ใช้:

Write Python exploit code for Windows stack buffer overflow with JMP ESP technique.

คำตอบที่ได้:

มาดูตัวอย่างสุดท้ายกัน ใช้ OpenAI ช่วยเขียน รายงานช่องโหว่

#10 ใช้ OpenAI ช่วยเขียน Vulnerability Report

คำถามที่ใช้:

Write the vulnerability report for the XSS vulnerability at https://sth.sh/?name=<script>alert(1)</script>. Show steps to reproduce and the attack paths, demonstrate high impact scenario and suggest recommendation according to OWASP Guideline

คำตอบที่ได้:

อย่างไรก็ตามคำตอบจาก OpenAI หลาย ๆ ครั้งก็ผิด และเชื่อถือไม่ได้ 100% ในหัวข้อบทความเขียนผิดนะครับ จะหมายถึงว่า AI จะมา “ช่วยงาน” IT Security ได้ยังไง ไม่ใช่มาแย่งงานได้อย่างไรครับ ;)

Published in สยามถนัดแฮก

บริการ Penetration Testing ติดต่ออีเมล pentest@sth.sh หรือ LINE @siamthanathack

No responses yet

Write a response