KANAL Mod


Author: David Zimmer
Date: 09.04.16 - 4:27am



I use the krypto analyzer plugin KANAL by Snaker allot. Its a small dll plugin that was designed to work with the PeID packer identifier. It is so handy that I actually use it in MAP and have an option to launch it on the file hash form.

One feature that I always wished it had, was the ability to copy all of the results to the clipboard. I poked around inside v2.7 a little bit, and it turns out if you right click on and entry it will copy the offset. Thats cool, but I want the whole thing text and all

I was not able to find the source to it, but with a couple small tweaks I was able to get what I wanted. Here's how.

First its upx compressed, so unpack it. Then open it up in reshacker and check out the dialog resource. Here I edited the script to include a new line
CONTROL "C&opy", 1022, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP,
 83, 112, 45, 13 , 0x00020000
This adds a copy button to the center of the form. Perfect. click the compile resource button and then save. The form now has a new button on it.

Now we need to handle the button events since KANAL knows nothing about it. We can do this through subclassing. Since the plugin is an in process dll we do not have to do anything funny, just subclass the form and watch for WM_COMMAND messages.

Before we get to the next step, we need to back track a second. PeID uses a cdecl api for its plugins. VB6 only has native support for stdcall. The first trick is actually just to launch the plugin. We have to build a small asm thunk in a RWE memory allocation and then call it using CallWindowProc

push asm(), "B8 " & lng2Hex(lpfn)    'B8 90807000    MOV EAX,708090
push asm(), "FF D0"                  'FFD0           CALL EAX
push asm(), "83 C4 " & Hex(argSize)  '83 C4 XX       add esp, XX     'cleanup args
push asm(), "C2 10 00"               'C2 10 00       retn 10h        'cleanup our callwindowproc args
Now KANAL uses a modal dialog and VB6 is single threaded. So once we launch it execution does not return back to our VB6 code until the dialog closes. In order to get around this, just before we launch the plugin we start up a timer.

Below is the timer proc which scans for the KANAL window and subclasses it. Below that you can also see how we handle the subclass message. When we receive the BN_CLICKED and our button ID in wParam, then we find the treeview child window on the form, and extract the treeview contents using the winapi.

Dim kanal As CWindow

Private Sub Timer2_Timer()
        
    Dim c As Collection
    Dim w As Cwindow
    
    'Debug.Print "Timer2"
    
    If Timer2.Tag = 3 Then
        Timer2.enabled = False
        Exit Sub
    End If
    
    Timer2.Tag = Timer2.Tag + 1 '3 attempts...
    
    Set c = ChildWindows()
    For Each w In c
        If VBA.Left(w.Caption, 5) = "KANAL" Then
            'Debug.Print Now & " - found kanal window attaching to " & w.hwnd & " (" & Hex(w.hwnd) & " )"
            Set kanal = w
            subclass.AttachMessage w.hwnd, WM_COMMAND
            'Debug.Print "Disabling timer now..."
            Timer2.enabled = False
            Exit Sub
        End If
    Next
    
End Sub

Private Sub subclass_MessageReceived(hwnd As Long, wMsg As Long, wParam As Long, lParam As Long, ...
        
        Dim c2 As Collection, wTv As Cwindow, tmp As String
        
        'we hooked WM_COMMAND for the kanal window
        'we are looking for BN_Clicked in the hiword of wParam and our button id (1022) in the low word
        'since bn_clicked = 0 we are going to take a shortcut and just look for 1022 in wparam
        
        'Debug.Print Now & " - received WM_COMMAND message for hwnd " & hwnd & " wParam = " & wParam
        
        If wParam = 1022 Then 'our new copy button
            If kanal Is Nothing Then Exit Sub
            If kanal.isValid Then
                Set wTv = kanal.FindChild("SysTreeView32")
                If wTv.isValid Then
                     Set c2 = wTv.CopyRemoteTreeView()
                     tmp = ColToStr(c2)
                     Clipboard.Clear
                     Clipboard.SetText tmp
                     'kanal.CloseWindow
                     MsgBox "Saved " & Len(tmp) & " bytes!", vbInformation
                End If
            End If
        End If

End Sub


while the code looks pretty concise and compact, there is actually allot going on behind the scenes in all of the library functions. Its all open source though so feel free to wade through it.

Turns out it was wasnt to bad to add this wish list feature even without the source code to the plugin. Software re-engineering is fun ;)






Comments: (1)

On 09.13.16 - 12:22pm Dave wrote:
doh! it turns out my version of Kanal is old and he has added an export button now!. To make it even worse, I looked in VT and v2.9 was first seen in 2007! Holy crap how time flies.

I might switch to using v2.9 in MAP, but I will probably leave this post up since its a fun technique. If the code is taken out of MAP, you can still find it in commit ee0189

 
Leave Comment:
Name:
Email: (not shown)
Message: (Required)
Math Question: 82 + 99 = ? followed by the letter: Z 



About Me
More Blogs
Main Site
Posts: (year)
2023 (4)
     Yara Workbench Automation
     VS linker versions
     IDA decompiler comments
     DispCallFunc
2022 (5)
     VB6 Implements
     VB6 Stubs BS
     VB6 TypeInfo
     VB6 VTable Layout
     Yara isPCode rule
2021 (2)
     rtcTypeName
     VB6 Gosub
2020 (5)
     AutoIT versions
     IDA JScript 2
     Using VB6 Obj files from C
     Yara Corrupt Imports
     Yara Undefined values
2019 (6)
     Yara WorkBench
     SafeArrayGetVartype
     vb6 API and call backs
     PrintFile
     ImpAdCallNonVirt
     UConnect Disable Cell Modem
2017 (5)
     IDA python over IPC
     dns wildcard blocking
     64bit IDA Plugins
     anterior lines
     misc news/updates
2016 (4)
     KANAL Mod
     Decoders again
     CDO.Message Breakpoints
     SysAnalyzer Updates
2015 (5)
     SysAnalyzer and Site Updates
     crazy decoder
     ida js w/dbg
     flash patching #2
     JS Graphing
2014 (5)
     Delphi IDA Plugin
     scdbg IDA integration
     API Hash Database
     Winmerge plugin
     IDACompare Updates
2013 (9)
     Guest Post @ hexblog
     TCP Stream Reassembly
     SysAnalyzer Updates
     Apilogger Video
     Shellcode2Exe trainer
     scdbg updates
     IDA Javascript w/IDE
     Rop Analysis II
     scdbg vrs ROP
2012 (13)
     flash patching
     x64 Hooks
     micro hook
     jmp api+5 *2
     SysAnalyzer Updates
     InjDll runtime config
     C# Asm/Dsm Library
     Shellcode Hook Detection
     Updates II
     findDll
     Java Hacking
     Windows 8
     Win7 x64
2011 (19)
     Graphing ideas
     .Net Hacking
     Old iDefense Releases
     BootLoaders
     hll shellcode
     ActionScript Tips
     -patch fu
     scdbg ordinal lookup
     scdbg -api mode
     Peb Module Lists
     scdbg vrs Process Injection
     GetProcAddress Scanner
     scdbg fopen mode
     scdbg findsc mode
     scdbg MemMonitor
     demo shellcodes
     scdbg download
     api hashs redux
     Api hash gen
2010 (11)
     Retro XSS Chat Codes
     Exe as DLL
     Olly Plugins
     Debugging Explorer
     Attach to hidden process
     JS Refactoring
     Asm and Shellcode in CSharp
     Fancy Return Address
     PDF Stream Dumper
     Malcode Call API by Hash
     WinDbg Cheat Sheet
2009 (1)
     GPG Automation