Try   HackMD
tags: note

Just take a look

ELDAR

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Đầu tiên là em đọc sơ qua file Makefile thì chỉ biết sơ là nó hướng dẫn sử dụng.

serial:
	gcc -shared -o libserial.so serial.c
run:
	./eldar
clean:
	rm libserial.so > /dev/null

Còn về file serial.c chỉ có 1 dòng char serial[] = ""; và lúc đầu đề có nói là không cần ghi bất kì thứ gì khác ngoài serial vào file nên em cũng không quan tâm file này nữa.

Còn về eldar em chạy thử thì nó bị lỗi:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Em quên mất là cái hướng dẫn nên là làm theo thì chạy được:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Mở eldar trong ida:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Đoạn code thì khá đơn giản, còn fail thì khi em xref không có chổ nào ref ngoài main.

Dể điền serial thì mình phải điền vào chổ file serial.c và make file lại rồi mới run.

Em thử setup và debug bằng remote linux thử:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Không thấy đoạn check nên em tìm thử trong string trước xem có gì đặc biệt không? và hình như là không:v

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Quay lại tab IDA view-A tìm kiếm thì em thấy chổ section LOAD nó có load mấy cái khá kì lạ và khá nhiều:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Em thử search ELF_rela trên mạng thì mới biết nó là elf_relocation và tìm thấy được cái struct của nó, và khá chắc đoạn này vừa load vừa chạy và check cái serial của mình:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Sau một hồi ngồi lâu search gg nhưng tới đây em cũng không biết cái đoạn đó nó chạy kiểu gì nên là em tạm thời bài này em chỉ xem tới đây, sau khi làm ra bài js thì cũng hết gần hết giờ nên em cũng chưa xem bài này nhiều lắm, tạm thời next qua bài tiếp theo. Rồi em sẽ tìm hiểu và làm bài này theo task của anh.

MIXED

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Vì là lúc đầu em chỉ xem sơ qua rồi sau đó em mất thời gian với bài js safe 4.0 khá nhiều nên là mấy bài sau này em chỉ lướt sơ qua

Thì đầu tiên thì em nghe nói là bài này dùng custom python nên là file pyc mà đề cho dùng tool để decompyle chắc chắc không ra, em đọc thử file patch:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Em thấy rất nhiều đoạn def_op, em nghĩ là define opcode sẽ làm lệnh gì và mấy cái này sẽ được modify vào opcode_map.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Ban đầu em nghĩ là lấy bytecode từ file x.pyc nhưng mà sau một hồi lâu tra gg em thấy không khả thi lắm, không được nên là em vẫn chưa làm tiếp bài này.

Và em cũng làm mấy bài rev với python bytecode nên là cũng hiểu chút chút nhưng mà tiếc là lúc đó em chỉ coi sơ qua để sau này có làm lại hoặc đọc wu sẽ dễ hiểu hơn và nắm bắt.

REVER

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Thì bài này lại là bài javascript nhưng có vẻ khó hơn nhiều:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Em thấy đáng chú ý chắc là có cái file data.png và file ca.js, còn về phần file art.js em nghĩ nó chỉ là phần đồ họa của web nên cũng chưa có nhiều manh mối, nên tạm thời bỏ qua file này, file index.html cũng tương tự:

<body> <div id="container"> <p id="title"> REV<span class="rev">RE</span> </p> <p id="motto"> We live in a twilight world. There are no flags at dusk. </p> <p id="content"> <input id="flag" value="CTF{FlagGoesHere}"> <button id="go">Go.</button><br> <progress id="progress" value="0" max="6"></progress><br> <span id="result"></span> <div style="visibility: hidden;"> <canvas id="canvas" width="1024" height="1024"></canvas> </div> </p> </div> </div> <div id="background"> <canvas id="background-canvas" width="1024" height="1024"></canvas> </div> <script src="art.js"></script> <script src="ca.js"></script> </body>

Còn về phần ca.js thì mở ra em thấy CHARSET và em thử ref xem:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Về đoạn này thì em nghĩ nó sẽ liên quan đến cái file data,png:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Còn đoạn này thì nó load luôn cái data.png để compare với cái gì đó:

compare() { const img = new Image; img.onload = (e) => { const c = document.createElement("canvas"); c.width = this.size[0]; c.height = this.size[1]; const ctx = c.getContext("2d"); ctx.drawImage(img, 0, 0); const one = ctx.getImageData(0, 0, this.size[0], this.size[1]).data; const two = this.get(); const check = (one, two) => { for (let i = 0; i < this.size[1]; ++i) { for (let j = 0; j < this.size[0]; ++j) { for (let c = 0; c < 4; ++c) { const o = one[4 * (i * this.size[0] + j) + c]; const t = two[4 * ((this.size[1] - i - 1) * this.size[0] + j) + c]; if (o != t) { return false; } } } } return true; } document.getElementById('result').innerText = check(one, two) ? 'Success!' : 'Fail.'; }; img.src = 'data.png'; }

Hàm main thì cũng dễ hiểu nên em cũng lướt sơ, chỉ biết là nó gọi tới thằng setstagestart của BCD:

let sim = null; const progress = document.getElementById('progress'); function start() { document.getElementById('go').addEventListener('click', (e) => { const flag = document.getElementById('flag').value; const res = document.getElementById('result'); if (flag.replace(/[0-9A-Za-z\{\}\?\!\_\.]/gi, '') !== '') { res.innerText = 'Wrong format.'; return; } if (sim !== null) { return; } sim = new BCA(document.getElementById('canvas')); sim.setState(flag); sim.start(); }); } start();

Nó load cái canvas tại đây:

setStage() có vẻ như nó chỉ là hàm là nó tạo buffer dựa trên cái charset và từng kí tự của flag lúc nãy mình có thấy.

setState(f) { const size = this.size[0] * this.size[1]; const buf = new Uint32Array(size); for (let i = 0; i < size; i++) { buf[i] = 0; } for (let dy = 0; dy < 16; ++dy) { let px = 64 + 32 * dy; for (let p = 0; p < f.length; ++p) { let py = 64 + 32 * dy; for (const line of Object.values(CHARSET[f[p]])) { for (let i = 0; i < 5; ++i) { if ((line & (1 << (4 - i))) != 0) { buf[py * this.size[1] + px + i] = 0xffffff; } } py++; } px += 6; } } return this.set(buf); }

Và có vẻ như sau khi nhận flag và ghi buffer thì nó sẽ so sánh với data có sẵn, rồi từ đó dưa ra kết quả qua element result và thông báo kết quả của flag.

Tạm thời thì flow bài này em chỉ hiểu sơ đến đây.

WHITE CUBE

Có vẻ bài này là bài khó nhất ở đây (theo như số lượt solve)

Đề nó cho mình 2 file flag.encWhitecube.exe:

flag.enc thì cũng không có gì đặc biệt:

Thử check Whitecube.exe trong DiE và mở bằng IDA:

Có rất nhiều hàm và chủ yếu là mấy cái hàm lạ lạ nhưng mà em để ý chủ yếu có mấy cái hàm nó sẽ gọi 1 api cụ thể và không làm gì thêm phức tạp, thậm chí nó chỉ có tác dụng return 0, và em thấy là file này nó có load thư viện opengl32.dll:

Em thử đặt breakpoint và chạy thì nó như này

Sau 1 hồi trace thì nó trace tới exit và thoát luôn

Và bài này thì cũng như các bài kia, em chưa làm kĩ nên là chỉ có overview tới đây thôi, sắp tới em sẽ làm bài eldar và tham khảo kĩ hơn các bài này.