Netatalk
là một open-source linux deamon, cung cấp POSIX-compliant *NIX/ * BSD hệ thống có khả năng chia sẻ các tập tin với các máy tính Apple Macintonsh.
Apple Filing Protocol
là giao thức mạng độc quyền của Apple để phân phối file qua mạng. Đây là sự thay thế của Apple cho các giao thức Server Message Block (SMB) và Network File System (NFS).
"Netatalk is a free, open-source implementation of the Apple Filing Protocol
. It allows Unix-like operating system to serve as file server for Macintosh
computers. Historically (until release 3.0) Netatalk
implemented the AppleTalk
protocol suite, allowing Unix-like operating systems to serve also as print and time servers for Apple Macintosh computers"
Hiểu một cách đơn giản,
Netatalk
là một ứng dụng giúp chúng ta chia sẻ file qua mạng giữa hệ thốngUbuntu
và hệ thốngMacOS
bằng cách cung cấp cùng giao thứcAFP
For Ubuntu18.04 (Linux ubuntu 4.15.0-20-generic #21-Ubuntu SMP Tue Apr 24 06:16:15 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
)
Download source of this version
Extract source
Compile and install
Start service
Check open port of service
Change afp.conf follow challenge gives us
config of this challenge
setup
After start netatalk service, the execute file programming will be placed /usr/local/sbin
For debugger, I used to gdb-pwndbg
Start, I attach to process afpd
with highest privilege sudo
And then
After search google, I found that bug in dsi_opensess.c
link
Source code from libatalk/dsi/dsi_opensess.c
Tại sao lại có lỗi ở đây? Nếu chúng ta có thể control được commands
thì khi đó ta có thể ghi đè được các trường sau attn_quantum
—> heap overflow
dsi_opensession()
được gọi khi nào?Khi một package DSI được gửi đến server, nó sẽ được parser theo một struct sau:
Trường commands
sẽ có một vài giá trị mà client có thể sử dụng để gọi đến những ứng dụng cấp từ server của netatalk
như bảng dưới đây:
Vậy nên, nếu chúng ta request một dsi package
với commands==4
thì khi đó trên server netatalk
sẽ đi vào hàm dsi_opensession.c
Chương trình sử dụng multi-proess
handling khi client request, mỗi client khi request đến chương trình sẽ fork()
một sub-process.
Với mỗi client khi request tới server, yêu cầu mở một session mới:
Chương trình sẽ gọi đến hàm dsi_start
để mở một sub-process
Sử dụng data request từ client, server parse theo struct qua hàm sau:
Hàm dsi_stream_receive
sẽ đọc data truyền vào một block
sau đó parse vào dsi_header
, clientID
, cmdlen
và commands
Để đảm bảo data được copy vào dsi->commands
không bị overflow, chương trình sẽ lấy giá trị nhỏ hơn của dsi->header.dsi_len
và dsi->server_quantum
. Mà giá trị define bạn đầu của servquant
như sau:
Vậy nên dsi_len
trong pakage mà ta request đến server phải có giá trị >32000
Struct của DSI block
:
Struct của DSI
:
Trong hàm dsi_opensession()
:
Để đến được dòng code vulnerability
thì dsi->command[i++]
phải là DSI_ATTNQUANT
Theo define:
Debugging
Bug & fixbug
After that
Thật không may, chúng ta chỉ có OOB write với địa chỉ đã biết, và file afpd
còn enable PIE
fork() —> memory unchange —> disable ASRL
Relationship between fork() with runtimeASLR
Ngâm cứu-ing :<
Some informations about Netatalk
Data Stream Interface - Wikipedia
Explained attack by author 0xddaa
Hitcon ctf 2019 pwn 371 netatalk
Out of bound write
Others
struct - Interpret bytes as packed binary data - Python 3.9.5 documentation
Đặt break point tại line xx trong file c