how do use ico in shellcode?

Тема в разделе "WASM.ENGLISH", создана пользователем dcskm4200, 15 июн 2007.

  1. dcskm4200

    dcskm4200 New Member

    Публикаций:
    0
    Регистрация:
    12 окт 2004
    Сообщения:
    173
    Адрес:
    China
    Код (Text):
    1.    
    2.         invoke  LoadIcon, hInstance, ID_TESTICO
    3.     invoke  SendMessage, hWnd, WM_SETICON, ICON_SMALL, eax
    a part shellcode
    Код (Text):
    1.     _xcall  [_LoadIcon], [_wc.hInstance], ID_TESTICO
    2.     _xcall  [_SendMessage], hWnd, WM_SETICON, ICON_SMALL, eax
    the above code can't work.
     
  2. W4FhLF

    W4FhLF New Member

    Публикаций:
    0
    Регистрация:
    3 дек 2006
    Сообщения:
    1.050
    Which one don't work?
     
  3. regiomontanus

    regiomontanus New Member

    Публикаций:
    0
    Регистрация:
    14 июн 2007
    Сообщения:
    2
    dcskm4200 Where is shelcode? Like dope?
     
  4. G13

    G13 New Member

    Публикаций:
    0
    Регистрация:
    24 мар 2006
    Сообщения:
    499
    dcskm4200, for instance, try this:

    Код (Text):
    1. _xcall  [_LoadIcon], 0, 32515
    If window icon changes to “yellow exclamation sign” - check availability of resources in module, pointed by [_wc.hInstance].

    Anyway, you should analyze return value of LoadIcon, to understand, what's happening when you try to load your icon. If eax!=0, you should call GetLastError an find - what's the problem it was.

    btw, why the heck you need an icon in shellcode?!? :))))
     
  5. dcskm4200

    dcskm4200 New Member

    Публикаций:
    0
    Регистрация:
    12 окт 2004
    Сообщения:
    173
    Адрес:
    China
    Hello G13,regiomontanus,W4FhLF
    thanks your response.

    every exe file has his resource which included ico. i knew how add some code(shellcode) into the exe file. but the shellcode can only use the ico that owned the exe file or the system ico(etc. IDI_APPLICATION).
    some code can change the ico of an exe file. how add an ico outside the exe is my question.
     
  6. G13

    G13 New Member

    Публикаций:
    0
    Регистрация:
    24 мар 2006
    Сообщения:
    499
    First, LoadIcon need a handle to loaded module. If module isn't loaded, we shoud fix it - by casting LoadLibrary:

    Код (Text):
    1. .data
    2. szMojuruNamae   db "module.exe",0
    3.  
    4. .code
    5. push    offset szMojuruNamae
    6. call    LoadLibrary
    7. .if eax!=0
    8.     push    eax     ; save handle in stack
    9.  
    10.     push    500     ; Icon ID in module
    11.     push    eax
    12.     call    LoadIcon
    13.  
    14.     push    eax
    15.     push    ICON_BIG    ;ICON_SMALL
    16.     push    WM_SETICON
    17.     push    hWin
    18.     call    SendMessage
    19.  
    20.     call    FreeLibrary     ;parameter is already in stack
    21.     ;.if    eax==0
    22.     ;   call    _debug
    23.     ;.endif
    24. ;.else
    25. ;   call    _debug
    26. .endif
    If external icon is in .ico, you could use LoadImage with LR_LOADFROMFILE instead.
     
  7. dcskm4200

    dcskm4200 New Member

    Публикаций:
    0
    Регистрация:
    12 окт 2004
    Сообщения:
    173
    Адрес:
    China
    Hello,G13
    by any way, thanks your response.
     
  8. dcskm4200

    dcskm4200 New Member

    Публикаций:
    0
    Регистрация:
    12 окт 2004
    Сообщения:
    173
    Адрес:
    China
    the code maybe easily change into shellcode. but it can change the Exe file's ICO which i don't need.
    where is wrong?

    Код (Text):
    1. .386
    2. .Model Flat, StdCall
    3. Option Casemap :None
    4.  
    5. include \masm32\include\windows.inc
    6. include \masm32\include\user32.inc
    7. include \masm32\include\kernel32.inc
    8.  
    9. includelib \masm32\lib\user32.lib
    10. includelib \masm32\lib\kernel32.lib
    11.  
    12. GROUPICON struct
    13. ;22 bytes
    14.     Reserved1   WORD    ?
    15.     ResourceType    WORD    ?
    16.     ImageCount  WORD    ?
    17.     _Width      BYTE    ?
    18.     _Height     BYTE    ?
    19.     Colors      BYTE    ?  
    20.     Reserved2   BYTE    ?
    21.     Planes      WORD    ?
    22.     BitsPerPixel    WORD    ?
    23.     ImageSize   DWORD   ?
    24.     ResourceID  WORD    ?
    25. GROUPICON ends
    26.  
    27. .data  
    28.     hFileIcon   dd 0
    29.     hUpdateRes  dd 0
    30.     dwFileIconSize  dd 0
    31.     szTargetExe db "mm.exe",0
    32.     szMyIcon    db "xx.ico",0
    33.  
    34. .code
    35.  
    36. MAKELANGID proc usPrimaryLanguage:USHORT, usSubLanguage:USHORT
    37.  
    38.     movzx   eax, usPrimaryLanguage
    39.     movzx   ebx, usSubLanguage
    40.     shl ebx, 10
    41.     or  eax, ebx
    42.     ret
    43.  
    44. MAKELANGID endp
    45.  
    46. InjectMainIcon proc uses ebx ecx edx esi edi lpExeFile:DWORD,lpMyIcon:DWORD
    47.     LOCAL lpBuf     :DWORD
    48.     LOCAL dwBytesTouched    :DWORD
    49.     LOCAL grDate        :GROUPICON
    50.     LOCAL LanguageId    :DWORD
    51.     LOCAL lpBufSize_22  :DWORD
    52.    
    53.     invoke  BeginUpdateResource,lpExeFile,FALSE
    54.     mov hUpdateRes,eax
    55.    
    56.     invoke  CreateFile, lpMyIcon, GENERIC_READ,FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0
    57.     test    eax,eax
    58.     js  _exit
    59.     mov hFileIcon,eax
    60.    
    61.     invoke  GetFileSize, hFileIcon, 0
    62.     mov dwFileIconSize,eax
    63.    
    64.     invoke  GlobalAlloc,GPTR,dwFileIconSize
    65.     mov lpBuf,eax
    66.    
    67.     invoke  ReadFile,hFileIcon,lpBuf,dwFileIconSize,ADDR dwBytesTouched,0
    68.     invoke  CloseHandle,hFileIcon
    69.  
    70.     invoke  MAKELANGID,LANG_ENGLISH,SUBLANG_DEFAULT
    71.     mov LanguageId,eax
    72.    
    73.     mov ebx,lpBuf
    74.     add ebx,22;sizeof GROUPICON
    75.  
    76.     mov edx,dwFileIconSize
    77.     sub edx,22;sizeof GROUPICON
    78.     mov lpBufSize_22,edx
    79.  
    80.     invoke  UpdateResource,hUpdateRes,RT_ICON,1,LanguageId,ebx,lpBufSize_22
    81.    
    82.     invoke  RtlZeroMemory,addr grDate,sizeof grDate
    83.    
    84.     mov ax,1
    85.     mov grDate.ResourceType, ax
    86.     mov grDate.ImageCount,ax
    87.    
    88.     mov al,32
    89.     mov grDate._Width,al
    90.     mov grDate._Height,al
    91.    
    92.     mov ax,2
    93.     mov grDate.Planes,ax
    94.    
    95.     mov ax,32
    96.     mov grDate.BitsPerPixel,ax
    97.    
    98.     push    lpBufSize_22
    99.     pop grDate.ImageSize
    100.    
    101.     mov ax,1
    102.     mov grDate.ResourceID,ax
    103.  
    104.     invoke  UpdateResource,hUpdateRes,RT_GROUP_ICON,1,LanguageId,addr grDate,SIZEOF grDate
    105.  
    106.     invoke  EndUpdateResource,hUpdateRes,FALSE
    107.     invoke  GlobalFree,lpBuf
    108. _exit:
    109.     ret
    110. InjectMainIcon endp
    111.  
    112. start:
    113.     invoke InjectMainIcon,addr szTargetExe,addr szMyIcon
    114.     invoke ExitProcess, 0
    115.  
    116. end start