anti anti virus continued
play

anti-anti-virus (continued) 1 logistics: TRICKY HW assignment out - PowerPoint PPT Presentation

anti-anti-virus (continued) 1 logistics: TRICKY HW assignment out infecting an executable 2 last time anti-virus: heuristic: malware messing up executables? key idea: wrong segment of executable? switching segments of the executable?


  1. attacking virtualization patience looking for unpacked virus in VM …or other malicious activity when are you done looking? not hard if virtualization uses “slow” implementation slow? maybe allows more inspection of program (e.g. switching segments, newly written code) malware solution: don’t infect consistently 30 malware solution: take too long

  2. attacking virtualization patience looking for unpacked virus in VM …or other malicious activity when are you done looking? malware solution: take too long not hard if virtualization uses “slow” implementation slow? maybe allows more inspection of program (e.g. switching segments, newly written code) 30 malware solution: don’t infect consistently

  3. probability if (randomNumber() == 4) { unpackAndRunEvilCode(); } antivirus emulator: randomNumber() == 3 looks clean! real execution #1: randomNumber() == 2 no infection! randomNumber() == 4 infect! … 31 real execution # N :

  4. signatures in RAM on disk decrypter “encrypted” code in memory (after a while) decrypter decrypted code ( good signature ) 32

  5. changing bodies “decrypting” a virus body gives body for “signature” “just” need to run decrypter how about avoiding static signatures entirely versus polymorphic — only change “decrypter” 33 called metamorphic

  6. metamorphic versus polymorphic big change in difficulty polymorphic: can have “template” with blanks could have been doing this with polymorphic, but probably not 34 metamorphic: probably “understand” machine code

  7. example: changing bodies pop %edx swap register numbers w/table lookup locate register number bits every instruction changes mov %esi, 0x1118(%esi,%eax,4) mov (%eax), %esi add $0x88, %eax mov $0xC, %edi mov %ebp, %esi mov $0x4h, %ebx pop %eax mov %ebx, 0x1118(%esi,%eax,4) mov (%edx), %ebx add $0x88, %edx mov $0xC, %eax mov %ebp, %esi mov $0x4h, %edi 35 likely with machine code parser!

  8. example: changing bodies pop %edx in addition to running VM to decrypt but harder to write/slower to match still has good signatures mov %esi, 0x1118(%esi,%eax,4) mov (%eax), %esi add $0x88, %eax mov $0xC, %edi mov %ebp, %esi mov $0x4h, %ebx pop %eax mov %ebx, 0x1118(%esi,%eax,4) mov (%edx), %ebx add $0x88, %edx mov $0xC, %eax mov %ebp, %esi mov $0x4h, %edi 35 with alternatives for each possible register selection

  9. case study: Evol via Lakhatia et al, “Are metamorphic viruses really invincible?”, Virus Bulletin, Jan 2005. “mutation engine” run as part of propagating the virus disassemble instr. lengths transform relocate code code 36

  10. case study: Evol via Lakhatia et al, “Are metamorphic viruses really invincible?”, Virus Bulletin, Jan 2005. “mutation engine” run as part of propagating the virus disassemble instr. lengths transform relocate code code 37

  11. Evol instruction lengths sounds really complicated? instruction prefjxes, ModRM byte parsing, … big table of opcodes? virus only handles instructions it has: about 61 opcodes, 32 of them identifjed by fjrst four bits (opcode 0x7 x – conditional jump) no prefjxes, no fmoating point only %reg or $constant or offset(%reg) 38

  12. case study: Evol via Lakhatia et al, “Are metamorphic viruses really invincible?”, Virus Bulletin, Jan 2005. “mutation engine” run as part of propagating the virus disassemble instr. lengths transform relocate code code 39

  13. Evol transformations some stufg left alone example: mov %eax, 8(%ebp) push %ecx mov %ebp, %ecx add $0x12, %ecx pop %ecx uses more stack space — save temporary Lakhotia et al., “Are metamorphic viruses really invincible?”, Virus Bulletin, Jan 2005 40 static or random one of N transformations mov %eax, − 0xa(%ecx) code gets bigger each time

  14. case study: Evol via Lakhatia et al, “Are metamorphic viruses really invincible?”, Virus Bulletin, Jan 2005. “mutation engine” run as part of propagating the virus disassemble instr. lengths transform relocate code code 41

  15. mutation with relocation table mapping old to new locations list of number of bytes generated by each transformation list of locations references in original record relative ofgset in jump record absolute ofgset in original 42

  16. 29+1 (jne1+1) xor1 (9) relocation example 29 -- inc 11 26 -- dec 14 9 10 jne table from transformation address loc orig. target new target xor1 (20) relocation actions 21 xor mov ... 5 mov ... 0x9: xor %rax, (%rbx) inc %rbx dec %rcx jne 0x9 orig. loc new loc addr 10 -- -- mov 7 13 -- mov 9 20 43

  17. 29+1 (jne1+1) xor1 (9) relocation example 29 -- inc 11 26 -- dec 14 9 10 jne table from transformation address loc orig. target new target xor1 (20) relocation actions 21 xor mov ... 5 mov ... 0x9: xor %rax, (%rbx) inc %rbx dec %rcx jne 0x9 orig. loc new loc addr 10 -- -- mov 7 13 -- mov 9 20 43

  18. relocation example 14 21 -- inc 11 26 -- dec 29 mov ... 9 jne table from transformation address loc orig. target new target xor1 (20) relocation actions 10 xor -- addr mov ... 0x9: xor %rax, (%rbx) inc %rbx dec %rcx jne 0x9 orig. loc new loc 5 20 10 -- mov 7 13 -- mov 9 43 29+1 (jne1+1) xor1 (9)

  19. mutation engines tools for writing polymorphic viruses tedious work to build state-machine-based detector ((almost) a regular expression to match it after any transform) apparently done manually automatable? malware authors use until reliably detected 44 best: no constant bytes, no “no-op” instructions

  20. fancier mutation can do mutation on generic machine code “just” need full disassembler hope machine code not written to rely on machien code sizes, etc. 45 identify both instruction lengths and addresses hope to identify tables of function pointers, etc.

  21. fancier mutation also an infection technique no “cavity” needed — create one obviously tricky to implement need to fjx all executable headers what if you misparse assembly? what if you miss a function pointer? example: Simile virus 46

  22. antiantivirus already covered: break disassemblers — with packers break VMs/emulators break debuggers make analysis harder break antivirus software itself “retrovirus” 47

  23. antiantivirus already covered: break disassemblers — with packers break VMs/emulators break debuggers make analysis harder break antivirus software itself “retrovirus” 48

  24. diversion: debuggers we’ll care about two pieces of functionality: breakpoints debugger gets control when certain code is reached single-step debugger gets control after a single instruction runs 49

  25. diversion: debuggers we’ll care about two pieces of functionality: breakpoints debugger gets control when certain code is reached single-step debugger gets control after a single instruction runs 50

  26. implementing breakpoints idea: change movq %rax, %rdx addq %rbx, %rdx // BREAKPOINT HERE subq 0(%rsp), %r8 ... into movq %rax, %rdx jmp debugger_code subq 0(%rsp), %r8 ... problem: jmp might be bigger than addq ? 51

  27. implementing breakpoints idea: change movq %rax, %rdx addq %rbx, %rdx // BREAKPOINT HERE subq 0(%rsp), %r8 ... into movq %rax, %rdx jmp debugger_code subq 0(%rsp), %r8 ... problem: jmp might be bigger than addq ? 51

  28. int 3 x86 breakpoint instruction: int 3 Why 3? fourth entry in table of handlers one byte instruction encoding: CC has copy of original somewhere invokes handler setup by OS debugger can ask OS to be run by handler or changes pointer to handler directly on old OSes 52 debugger modifjes code to insert breakpoint

  29. int 3 handler kind of exception handler recall: exception handler = way for CPU to run OS code x86 CPU saves registers, PC for debugger x86 CPU has easy to way to resume debugged code from handler 53

  30. detecting int 3 directly (1) checksum running code mycode: ... movq $0, %rbx movq $mycode, %rax loop : addq (%rax), %rbx addq $8, %rax cmpq $endcode, %rax jl loop cmpq %rbx, $EXPECTED_VALUE jne debugger_found ... endcode: 54

  31. detecting int 3 directly (2) query the “handler” for int 3 old OSs only; today: cannot set directly modern OSs: ask if there’s a debugger attached …or try to attach as debugger yourself doesn’t work — debugger present, probably does work — broke any debugger? // Windows API function! if (IsDebuggerPresent()) { 55

  32. modern debuggers int 3 is the oldest x86 debugging mechanism modern x86: 4 “breakpoint” registers (DR0–DR3) contain address of program instructions need more than 4? sorry processor triggers exception when address reached 4 extra registers + comparators in CPU? fmag to invoke debugger if debugging registers used enables nested debugging 56

  33. diversion: debuggers we’ll care about two pieces of functionality: breakpoints debugger gets control when certain code is reached single-step debugger gets control after a single instruction runs 57

  34. implementing single-stepping (1) set a breakpoint on the following instruction? STOPPED HERE jmpq *0x1234(%rax,%rbx,8) // but what about then jmp to addq ... subq 8(%rsp), % 58 movq %rax, %rdx transformed to ... subq 8(%rsp), %r8 movq %rax, %rdx addq %rbx, %rdx // ←− STOPPED HERE subq 0(%rsp), %r8 // ←− SINGLE STEP TO HERE addq %rbx, %rdx // ←− STOPPED HERE int 3 // ←− SINGLE STEP TO HERE

  35. implementing single-stepping (1) set a breakpoint on the following instruction? STOPPED HERE jmpq *0x1234(%rax,%rbx,8) // but what about then jmp to addq ... subq 8(%rsp), % 58 movq %rax, %rdx transformed to ... subq 8(%rsp), %r8 movq %rax, %rdx addq %rbx, %rdx // ←− STOPPED HERE subq 0(%rsp), %r8 // ←− SINGLE STEP TO HERE addq %rbx, %rdx // ←− STOPPED HERE int 3 // ←− SINGLE STEP TO HERE

  36. implementing single-stepping (2) typically hardware support for single stepping x86: int 1 handler (second entry in table) x86: TF fmag: execute handler after every instruction …except during handler (whew!) 59

  37. Defeating single-stepping try to install your own int 1 handler (if OS allows) try to clear TF? would take efgect on following instruction …if debugger doesn’t reset it 60

  38. unstealthy debuggers is a debugger installed? unlikely on Windows, maybe ignore those machines is a debugger process running (don’t check if it’s tracing you) … 61

  39. confusing debuggers “broken” executable formats e.g., recall ELF: segments and sections corrupt sections — program still works overlapping segments/sections — program still works use the stack pointer not for the stack stack trace? 62

  40. antiantivirus already covered: break disassemblers — with packers break VMs/emulators break debuggers make analysis harder break antivirus software itself “retrovirus” 63

  41. terminology semistealth / stealth — hide from system tunneling virus — evades behavior-blocking e.g. detection of modifying system fjles retrovirus — directly attacks/disables antivirus software 64

  42. attacking antivirus (1) how does antivirus software scan new fjles? how does antivirus software detect bad behavior? register handlers with OS/applications — new fjles, etc. 65

  43. hooking and malware hooking — getting a ‘hook’ into (OS) operations e.g. creating new fjles, opening fjle monitoring or changing/stopping behavior used by antivirus and malware: stealth virus — hide virus program from normal I/O, etc. tunneling virus — skip over antivirus’s hook retrovirus — break antivirus’s hook 66

  44. stealth /* in virus: */ int OpenFile( const char *filename, ...) { if (strcmp(filename, "infected.exe") == 0) { return RealOpenFile("clean.exe", ...); } else { return RealOpenFile(filename, ...); } } 67

  45. stealth ideas override “get fjle modifjcation time” (infected fjles) override “get fjles in directory” (infected fjles) override “read fjle” (infected fjles) but not “execute fjle” override “get running processes” 68

  46. tunneling ideas use the “real” write/etc. function not wrapper from antivirus software fjnd write/etc. function antivirus software “forgot” to hook 69

  47. retrovirus ideas empty antivirus signature list kill antivirus process, remove “hooks” delete antivirus software, replace with dummy executable … 70

  48. hooking mechanisms hooking — getting a ‘hook’ to run on (OS) operations e.g. creating new fjles ideal mechanism: OS support less ideal mechanism: change library loading e.g. replace ‘open’, ‘fopen’, etc. in libraries less ideal mechanism: replace OS exception (system call) handlers very OS version dependent 71

  49. hooking mechanisms hooking — getting a ‘hook’ to run on (OS) operations e.g. creating new fjles less ideal mechanism: change library loading e.g. replace ‘open’, ‘fopen’, etc. in libraries less ideal mechanism: replace OS exception (system call) handlers very OS version dependent 72 ideal mechanism: OS support

  50. 73

  51. hooking mechanisms hooking — getting a ‘hook’ to run on (OS) operations e.g. creating new fjles ideal mechanism: OS support e.g. replace ‘open’, ‘fopen’, etc. in libraries less ideal mechanism: replace OS exception (system call) handlers very OS version dependent 74 less ideal mechanism: change library loading

  52. changing library loading e.g. install new library — or edit loader, but … not everything uses library functions what if your wrapper doesn’t work exactly the same? problem both for malware and anti-virus! 75

  53. hooking mechanisms hooking — getting a ‘hook’ to run on (OS) operations e.g. creating new fjles ideal mechanism: OS support less ideal mechanism: change library loading e.g. replace ‘open’, ‘fopen’, etc. in libraries call) handlers very OS version dependent 76 less ideal mechanism: replace OS exception (system

  54. changing exception handlers? mechanism on DOS track what old exception handler does “tunneling” technique — fjnd the original, call it instead 77

  55. other holes in behavior blocking if in library: don’t use library function e.g. copy of “clean” library e.g. statically linked generally: multiple ways to do things? like VM problem: was something missed? e.g.. fjle modifjcations blocked? just acccess the disk directly 78

  56. attacking antivirus (2) mechanisms other than hooking just directly modify it example: IDEA.6155 modifjes database of scanned fjles preserve checksums example: HybrisF preserved CRC32 checksums of infected fjles some AV software won’t scan again 79

  57. not just hiding/interfering our model of malware — runs when triggered reality: sometimes keep on running evade active detection spread to new programs/fjles as created/run 80 call resident

  58. spreading in memory hook to hide virus fjle not just hiding virus — propogate! example: infect any new fjles example: reinfect “repaired” fjles 81

  59. armored viruses “encrypted” viruses not strong encryption — key is there! self-changing viruses: encrypted oligiomorphic polymorphic metamorphic 82

  60. anti-debugging, tunnelling, etc. anti-debugging/virtualisation/goat evade various “run it and check” techniques tunnelling stealth “hook” system operations (like antivirus) hide modifjed fjles, malware processes, etc. retrovirus deliberately break antivirus software memory residence infect running OS/programs, not just fjles antivirus needs to kill running virus code 83 evade behavior-blocking/detection

  61. real signatures: ClamAV ClamAV: open source email scanning software signature types: hash of fjle hash of contents of segment of executable built-in executable, archive fjle parser fjxed string basic regular expressions wildcards, character classes, alternatives more complete regular expressions including features that need more than state machines meta-signatures: match if other signatures match icon image fuzzy-matching 84

  62. anti-virus techniques last time: signature-based detection regular expression-like matching snippets of virus(-like) code heuristic detection look for “suspicious” things behavior-based detection look for virus activity not explicitly mentioned: producing signatures manual? analysis not explicitly mentioned: “disinfection” manual? analysis 85

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend