Để tìm hiểu ý nghĩa của một số kiểu dữ liệu trong MFC, theo tôi nói chính xác hơn là kiểu dữ liệu mới trong Win32, bạn tìm tài liệu lập trình C for Wins mà đọc.
Bạn có thể tìm ebook "Programming Windows by Charles Petzold" để tham khảo thêm.
Thân!
void _tmain[ int argc, TCHAR *argv[] ]
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory[ &si, sizeof[si] ];
si.cb = sizeof[si];
ZeroMemory[ &pi, sizeof[pi] ];
if[ argc != 2 ]
{
printf["Usage: %s [cmdline]\n", argv[0]];
return;
}
// Start the child process.
if[ !CreateProcess[ NULL, // No module name [use command line]
argv[1], // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ] // Pointer to PROCESS_INFORMATION structure
]
{
printf[ "CreateProcess failed [%d]\n", GetLastError[] ];
return;
}
// Wait until child process exits.
WaitForSingleObject[ pi.hProcess, INFINITE ];
// Close process and thread handles.
CloseHandle[ pi.hProcess ];
CloseHandle[ pi.hThread ];
}
bạn có thể tham khảo ở MSDN
còn các kiểu dữ liệu là gì bạn cũng lên MSDN đọc dể hiểu hơn
ví dụ DWORD là kiểu hex, HWND là handle cửa sổ ,....
ví dụ DWORD là kiểu hex
kiểu hex là gì hả bạn, mình mới tập lập trình trên windows nên không rõ lắm
Ừ, em cũng không biết kiểu hex là gì.
Trình em thấp, em chỉ biết, trên Win32:
DWORD = HWND = WPARAM = HANDLE = HCURSOR = H...gì đó = số nguyên 4byte hết.
HEX không phải là 1 kiểu dữ liệu mà nó chỉ là 1 dạng biểu diễn của số [hệ số]. Còn DWORD mới là 1 kiểu dữ liệu. Chẳng hạn như hệ số 10 [thập phân], hệ số 2 [nhị phân],... Hex là hệ số thập lục có giá trị biểu diễn từ 0-F.
Bạn tamthanh0424 chắc là dùng từ không chính xác thôi.
vBulletin® Version 4.2.2, Copyright © 2022 vBulletin Solutions, Inc. All rights reserved. Administer by Kevin Hoang
trên trang chủ của nó hiện có 2 softwares 39$ một em ... thằng này nó code bằng Microsoft Visual C++ 6.0 , đoạn mã hóa khá dài và lung tung , đáng lý tớ cho nó cái patch nhưng thấy nó so sánh nhiều chỗ và phương châm là tìm real serial nên sẽ phân tích đoạn mã hóa của nó vậy ...
dùng OllyDbg tìm đến thông báo lỗi "Registration failed!" , dịch chuyển lên một đoạn khá dài và ta đặt breakpoint như sau ...
CODE
00412720 . 57 PUSH EDI =>đặt breakpoint
.......... ở đây có một số dòng ..........
00412732 . 8B46 5C MOV EAX,DWORD PTR DS:[ESI+5C] =>đưa chuỗi name vào eax
00412735 . 8B68 F8 MOV EBP,DWORD PTR DS:[EAX-8] =>đưa chiều dài chuỗi name vào ebp
00412738 . 83FD 02 CMP EBP,2 =>so sánh với 2
0041273B . 7D 16 JGE SHORT DVD2DIVX.00412753 =>nếu nhỏ hơn 2 thì bắn nag "Please input correct User Name!"
0041273D . 33C0 XOR EAX,EAX
.......... ở đây có một số dòng ..........
00412752 . C3 RETN
00412753 > 8B5E 60 MOV EBX,DWORD PTR DS:[ESI+60] =>đưa chuỗi serial vào ebx
00412756 . 8B53 F8 MOV EDX,DWORD PTR DS:[EBX-8] =>đưa chiều dài chuỗi serial vào edx
00412759 . 83FA 08 CMP EDX,8 =>so sánh với 8
0041275C . 7D 16 JGE SHORT DVD2DIVX.00412774 =>nếu nhỏ hơn 8 thì bắn nag "Please input correct Registration Code!"
0041275E . 33C0 XOR EAX,EAX
.......... ở đây có một số dòng ..........
00412773 . C3 RETN
thằng này nó mã hóa 2 ký tự đầu tiên của chuỗi name 4 lần ... tính tổng hex của chuỗi name rồi mã hóa tiếp ... sau đó so sánh với 5 ký tự đầu tiên của chuỗi serial nhập vào ... nếu đúng thì bắn nag "Registration has succeeded!" ...
đây là challenge đầu tiên trong mảng cracking của rootme. Vì thế chương trình khá đơn giản, chủ yếu nhắm mục đích làm quen với chủ đề reverse này.
Solution
Đầu tiên, chương trình nạp vào 1 đoạn string từ biến
test eax, eax
jnz short loc_804871E
6.push ebp
mov ebp, esp
push ecx
sub esp, 24h
mov [esp + s2], a123456789
Biến này chứa đoạn string 123456789. Tiếp theo, chương trình in ra màn hình một số đoạn string ban đầu
mov dword ptr [esp], offset s ; "#######################################"...
call _puts
mov dword ptr [esp], offset Bienvennue dans ce challenge "...
call _puts
mov dword ptr [esp], offset asc_80488CC ; "#######################################"...
call _puts
mov dword ptr [esp], offset aVeuillezEntrer ; "Veuillez entrer le mot de passe :"
call _printf
Tiếp theo là đọc dữ liệu người dùng nhập vào
mov eax, [ebp + s1]
mov [esp], eax
call getString
Lưu kết quả trong
test eax, eax
jnz short loc_804871E
7 vào test eax, eax
jnz short loc_804871E
8mov [ebp + s1], eax
So sánh 2 string người dùng nhập vào với string trong biến
test eax, eax
jnz short loc_804871E
6mov eax, [ebp + s2]
mov [esp + 4], eax
mov eax, [ebp + s1]
mov [esp], eax
call _strcmp
Nếu kết quả trả về khác 0 thì in ra thông báo fail
test eax, eax
jnz short loc_804871E
mov dword ptr [esp], offset aDommageEssayeE ; "Dommage, essaye encore une fois."
call _puts
Nếu đúng thì in ra thông báo success cùng mật khẩu
mov eax, [ebp+s2]
mov [esp+4], eax
mov dword ptr [esp], offset aBienJoueVousPo ; "Bien joue, vous pouvez valider l'epreuv"...
call _printf
Như vậy, để in ra thông báo chúc mừng, cần giá trị nhập vào tương ứng với giá trị của biến
test eax, eax
jnz short loc_804871E
6.Flag
123456789
ELF x86 - Basic
Đây là một bài tiếp theo vẫn rất đơn giản để làm quen mảng này.
Solution
Đầu tiên, chương trình lưu 2 biến local là
mov dword ptr [esp], offset aDommageEssayeE ; "Dommage, essaye encore une fois."
call _puts
1 và mov dword ptr [esp], offset aDommageEssayeE ; "Dommage, essaye encore une fois."
call _puts
2.push ebp
mov ebp, esp
push ecx
sub esp, 24h
mov [ebp+var_C], offset aJohn ; "john"
mov [ebp+var_10], offset aTheRipper ; "the ripper"
Tiếp theo, chương trình in ra một số thông báo chào mừng và yêu cầu người dùng nhập username
mov dword ptr [esp], offset asc_80A6B2C ; "#######################################"...
call puts
mov dword ptr [esp], offset aBienvennueDans ; "## Bienvennue dans ce challenge "...
call puts
mov dword ptr [esp], offset asc_80A6BAC ; "#######################################"...
call puts
mov dword ptr [esp], offset aUsername ; "username: "
call printf
Giá trị này được lưu vào 1 biến local của hàm và được so sánh với giá trị
mov dword ptr [esp], offset aDommageEssayeE ; "Dommage, essaye encore une fois."
call _puts
1.mov dword ptr [esp], offset s ; "#######################################"...
call _puts
mov dword ptr [esp], offset Bienvennue dans ce challenge "...
call _puts
mov dword ptr [esp], offset asc_80488CC ; "#######################################"...
call _puts
mov dword ptr [esp], offset aVeuillezEntrer ; "Veuillez entrer le mot de passe :"
call _printf
0Nếu sai thì in ra Bad username
mov dword ptr [esp], offset s ; "#######################################"...
call _puts
mov dword ptr [esp], offset Bienvennue dans ce challenge "...
call _puts
mov dword ptr [esp], offset asc_80488CC ; "#######################################"...
call _puts
mov dword ptr [esp], offset aVeuillezEntrer ; "Veuillez entrer le mot de passe :"
call _printf
1mov dword ptr [esp], offset s ; "#######################################"...
call _puts
mov dword ptr [esp], offset Bienvennue dans ce challenge "...
call _puts
mov dword ptr [esp], offset asc_80488CC ; "#######################################"...
call _puts
mov dword ptr [esp], offset aVeuillezEntrer ; "Veuillez entrer le mot de passe :"
call _printf
2Nếu đúng thì sẽ yêu cầu người dùng nhập password
mov dword ptr [esp], offset s ; "#######################################"...
call _puts
mov dword ptr [esp], offset Bienvennue dans ce challenge "...
call _puts
mov dword ptr [esp], offset asc_80488CC ; "#######################################"...
call _puts
mov dword ptr [esp], offset aVeuillezEntrer ; "Veuillez entrer le mot de passe :"
call _printf
3Sau đó so sánh giá trị này với biến
mov dword ptr [esp], offset aDommageEssayeE ; "Dommage, essaye encore une fois."
call _puts
2mov dword ptr [esp], offset s ; "#######################################"...
call _puts
mov dword ptr [esp], offset Bienvennue dans ce challenge "...
call _puts
mov dword ptr [esp], offset asc_80488CC ; "#######################################"...
call _puts
mov dword ptr [esp], offset aVeuillezEntrer ; "Veuillez entrer le mot de passe :"
call _printf
4Nếu sai thì in ra Bad password
mov dword ptr [esp], offset s ; "#######################################"...
call _puts
mov dword ptr [esp], offset Bienvennue dans ce challenge "...
call _puts
mov dword ptr [esp], offset asc_80488CC ; "#######################################"...
call _puts
mov dword ptr [esp], offset aVeuillezEntrer ; "Veuillez entrer le mot de passe :"
call _printf
5mov dword ptr [esp], offset s ; "#######################################"...
call _puts
mov dword ptr [esp], offset Bienvennue dans ce challenge "...
call _puts
mov dword ptr [esp], offset asc_80488CC ; "#######################################"...
call _puts
mov dword ptr [esp], offset aVeuillezEntrer ; "Veuillez entrer le mot de passe :"
call _printf
6Nếu đúng thì in ra flag
mov dword ptr [esp], offset s ; "#######################################"...
call _puts
mov dword ptr [esp], offset Bienvennue dans ce challenge "...
call _puts
mov dword ptr [esp], offset asc_80488CC ; "#######################################"...
call _puts
mov dword ptr [esp], offset aVeuillezEntrer ; "Veuillez entrer le mot de passe :"
call _printf
7Flag
Flag: 987654321
PE x86 - 0 protection
Tiếp theo 2 bài đơn giản trên là một bài phức tạp hơn 1 tí tẹo.
Solution
Đầu tiên, ta có 1 file
mov dword ptr [esp], offset aDommageEssayeE ; "Dommage, essaye encore une fois."
call _puts
5. Chạy thử file này với input bất kì, ta cósearch thử Wrong password trong source code asm, ta thấy nó được gọi tại
đoạn mã này được gọi tại hàm
Dựa theo mã asm, đầu tiên
mov dword ptr [esp], offset s ; "#######################################"...
call _puts
mov dword ptr [esp], offset Bienvennue dans ce challenge "...
call _puts
mov dword ptr [esp], offset asc_80488CC ; "#######################################"...
call _puts
mov dword ptr [esp], offset aVeuillezEntrer ; "Veuillez entrer le mot de passe :"
call _printf
8sẽ kiểm tra độ dài của input string phải bằng 7. Tiếp theo, các đoạn mã có dạng
mov dword ptr [esp], offset s ; "#######################################"...
call _puts
mov dword ptr [esp], offset Bienvennue dans ce challenge "...
call _puts
mov dword ptr [esp], offset asc_80488CC ; "#######################################"...
call _puts
mov dword ptr [esp], offset aVeuillezEntrer ; "Veuillez entrer le mot de passe :"
call _printf
9là đoạn mã so sánh từng kí tự trong input string với một kí tự cho trước [như
mov dword ptr [esp], offset aDommageEssayeE ; "Dommage, essaye encore une fois."
call _puts
6 ở s[0]]. Theo đó, các kí tự của string lần lượt phải làmov eax, [ebp + s1]
mov [esp], eax
call getString
0Nếu không thoả mãn các điều kiện trên, sẽ in ra wrong input. Ngược lại, nếu input string thoả mãn các điều kiện chương trình sẽ in ra dòng chúc mừng "Gratz man
có thể tạo giả mã C cho chương trình đơn giản như sau:
mov eax, [ebp + s1]
mov [esp], eax
call getString
1Vậy input string cần tìm sẽ là
Flag
mov eax, [ebp + s1]
mov [esp], eax
call getString
2ELF C++ - 0 protection
Tiếp theo sẽ là một bài khác cũng ở mức cơ bản, mục tiêu là sử dụng các công cụ debug để hiểu hơn về chương trình.
Solution
Đầu tiên, bài cho chúng ta 1 file
mov dword ptr [esp], offset aDommageEssayeE ; "Dommage, essaye encore une fois."
call _puts
7. Thực thi file với input bất kì, ta có:Tìm kiếm output này trong source code asm, ta có đoạn code in ra nó là
mov eax, [ebp + s1]
mov [esp], eax
call getString
3Đoạn code này được nhảy tới từ đoạn
Theo đó, nếu kết quả của hàm
mov dword ptr [esp], offset aDommageEssayeE ; "Dommage, essaye encore une fois."
call _puts
8 là 0 thì sẽ in ra Incorrect password, ngược lại sẽ in ra Congratz. ...OK, xem thử trong hàm
mov dword ptr [esp], offset aDommageEssayeE ; "Dommage, essaye encore une fois."
call _puts
8, ta cómov eax, [ebp + s1]
mov [esp], eax
call getString
4Có thể thấy hàm này sẽ so sánh 2 tham số truyền vào dựa trên hàm
mov eax, [ebp+s2]
mov [esp+4], eax
mov dword ptr [esp], offset aBienJoueVousPo ; "Bien joue, vous pouvez valider l'epreuv"...
call _printf
0. Trong các tham số truyền vào, 1 tham số là input string, tham số còn lại là string có sẵn của chương trình. Ta chỉ cần tìm xem string nào được truyền vào hàm này để giải được bài nàySử dụng gdb debug file, đặt breakpoint tại địa chỉ mà hàm này được gọi là
mov eax, [ebp+s2]
mov [esp+4], eax
mov dword ptr [esp], offset aBienJoueVousPo ; "Bien joue, vous pouvez valider l'epreuv"...
call _printf
1có thể thấy, tham số cần tìm sẽ được trỏ bởi
mov eax, [ebp+s2]
mov [esp+4], eax
mov dword ptr [esp], offset aBienJoueVousPo ; "Bien joue, vous pouvez valider l'epreuv"...
call _printf
2 -> test eax, eax
jnz short loc_804871E
7 -> mem ["Here_you_have_to_understand_a_little_C++_stuffs"]Vậy string cần tìm sẽ là Here_you_have_to_understand_a_little_C++_stuffs.
Flag
mov eax, [ebp + s1]
mov [esp], eax
call getString
5PE DotNet - 0 protection
Bài này là một bài cơ bản nhất để làm quen với reverse .NET
Solution
Đầu tiên, chương trình cung cấp cho ta 1 file
mov eax, [ebp+s2]
mov [esp+4], eax
mov dword ptr [esp], offset aBienJoueVousPo ; "Bien joue, vous pouvez valider l'epreuv"...
call _printf
4. Thực thi file này sẽ hiển thị một form với 1 trường input và 1 button mov eax, [ebp+s2]
mov [esp+4], eax
mov dword ptr [esp], offset aBienJoueVousPo ; "Bien joue, vous pouvez valider l'epreuv"...
call _printf
5Khi clicj vào form với input bất kì, ta sẽ có một thông báo sai mật khẩu
Ở bài này, mình dùng DotPeek của JetBrain để decompile source code của file này
Thử tìm kiếm Bad password trong source code, ta thấy nó được xử lý trong
mov eax, [ebp+s2]
mov [esp+4], eax
mov dword ptr [esp], offset aBienJoueVousPo ; "Bien joue, vous pouvez valider l'epreuv"...
call _printf
6. Ở đây, khi click vào button mov eax, [ebp+s2]
mov [esp+4], eax
mov dword ptr [esp], offset aBienJoueVousPo ; "Bien joue, vous pouvez valider l'epreuv"...
call _printf
5[button1] sẽ gọi tới hàm