DFOR510 Week13 UnknownCodeAnalysis
DFOR510 Week13 UnknownCodeAnalysis
▪ HW4 Assigned
2
3
STATIC ANALYSIS
Unknown Code Analysis
❑ Why we do it
❑ Learn the process and tools used for Static and Dynamic
Code Analysis
4
▪ Purpose:
▪ Understand the extent of a compromise
▪ If any, what damage was done
▪ Prevent similar attacks in the future
▪ Assess an attacker’s skill or threat level
▪ Identify # and type of intruders
▪ Prepare for a successful subject interview if you catch the attacker
▪ Determine the attacker’s goals and objectives
6
▪ Portable Executables (PEs)
▪ Windows platforms
▪ Magic number: MZ
7
▪ Executable & Linkable Files (ELF)
▪ Linux/UNIX OS platforms
40 bytes/section header
File header
(IMAGE_DOS_HEADER)
Magic_number
E_lfanew
PE Header
(IMAGE_NT_HEADERS)
PE Signature
Machine (32- or
64-bit)
# of sections
Timestamp
Pointer to
Symbols Table
# of Symbols
Size of Optional
Header
Characteristics
(contains flag
which indicates
if file is a DLL)
Optional Header
PE or PE+
Size of code
(.text)
ELF
Contains general
information about the file
Defines Program Segments
Looking at the
“traceroute6” binary file
ELF
Sections
14
Source Code Assembly Code
(.c file) (.s file)
Preprocessor Compiler
Object Code
(.o file)
Executable
(.exe file) Linker Assembler
Libraries
This Photo by Unknown Author is licensed under CC BY
(.dll, .so)
This Photo by Unknown Author is licensed under CC BY-SA 15
1. Record 4. Review the ASCII/Unicode
a. Full path/location of the suspicious a.‘strings’ command
file
b. The OS file was found 5.Is this a known malware?
c. MAC times a.Start with Google
b.https://www.virustotal.com*
2. Get digital fingerprint
6.Examine shared objects
3. Determine file type (e.g. PE, (dll’s/ldd’s)
a. PEView
.dll, elf, etc.) b. Dependency Walker
a.file c. PEiD
b.nm
c.Hexdump (Linux) or HexEdit 7.Source code review (if
(Windows)
available)
* Make sure that you have permission to release your code to 3rd party 16
▪‘file’ command (Linux native; ▪ nm results
Windows download from online) ▪ 1st col symbol value in hex
▪ 2nd col symbol type
▪lower case local variable
▪ ‘nm’ command – command to ▪upper case global variable
show symbols from an object file ▪ symbol types
▪ a.out is default (Assembly ▪A absolute value
OUTput file) ▪B uninitialized data section
▪ -a: all ▪C common section uninitialized
▪ nm –a bob data
▪ -l: list line numbers (may provide ▪D initialized data
▪N debug symbol
good info if program in debug
▪R read only
mode) ▪T text or code data section
▪U undefined
Or use PEiD (https://www.aldeid.com/wiki/PEiD) ▪ 3rd col symbol 17
▪ ‘strings’ command –
▪ list ASCII strings 4 characters or longer in file
▪ Win2K or later searches for Unicode (Windows)
▪ Download from Microsoft Technet (www.sysinternals.com)
18
▪ Check various sites to see if Malware has been
reported* :
▪ Google
▪ VirusTotal (VT) https://www.virustotal.com
*Must ensure you are able to share code before uploading to any online site
19
▪ Look for shared libraries or dependencies
▪ .dll’s (Windows)
▪ PEView
▪ Dependency Walker
▪ PEiD
21
▪ Some Packers to consider:
▪ UPX (Ultimate Packet for Executables) is a compression
tool for Linux executables (https://upx.github.io/)
▪ Alternate EXE Packer (http://www.alternate-
tools.com/pages/c_exepacker.php?lang=ENG)
▪ EXE Stealth Packer (http://www.webtoolmaster.com/packer.htm)
▪ And others... (https://en.wikipedia.org/wiki/Executable_compression)
22
▪ Other items to ▪ Who compiled code?
consider: ▪ Unusual Entries in the PE
▪ Altered Code
▪ Functions with Little to
▪ Compressed
▪ Encrypted
no documentation
▪ XOR ▪ Functions that don’t
▪ RC-4 belong (e.g. a network
▪ Compile Date/Time call in notepad)
▪ Compiler Used
23
QUICK CHECK 1
1. What is ‘Static Code Analysis’? 4. Which command/tool will:
❑ List the basic steps. ❑ Display ‘symbols’ in a file?
❑ What information are we ❑ List all ASCII strings (≥ 4chars)
gathering? ❑ What info are looking for?
26
Static Malware Analysis Dynamic Malware Analysis
27
1. Static Analysis 5. Run unknown code and
a. Determine hypothesis of monitor intercept system
what code does calls
2. Create “sandbox” –
a. Ensure sandbox is safe – 6. Capture snapshot of
how? infected VM
3. Take snapshot of host VM 7. Analysis results and write
up conclusions
4. Initiate tools for
observation 8. If desired, revert back to
base snapshot and rerun
malware
28
▪ Security mechanism for running untrusted code
▪ Access via website, but you may be giving up proprietary company
data
▪ Available for purchase – but expensive usually
▪ Drawbacks
▪ Will run the code without command line options
▪ May be VM detectable
▪ Code may require that certain registry keys be present
▪ If code is DLL, some export functions may not run properly
▪ Sandbox OS may not be correct for the code
▪ Generally can’t tell you what the code does 29
STEP 2: VIRTUAL ENVIRONMENT SETUP 1
VMWare Configuration
LAN Segment
Host Machine
Windows VM (victim) REMnux VM (services/network capture)
HTTP:
DNS: 60
FTP:
fakeDNS Redirect:
HTTPS:
192.168.40.3
etc,
External Network
Host Machine
Windows VM (victim)
HTTP:
DNS: 60
FTP:
Apate DNS
HTTPS:
Redirect: 127.0.0.1
etc,
External Network
31
▪ Step 2 – Use VMWare or Virtual Box to set up VM(s)
▪ 1 host system VM (base this off of your static analysis)
▪ Download necessary tools (e.g. SysInternals, Wireshark, etc.)
▪ Verify tools work (take snapshot and DO NOT RUN m.w.)
33
▪ Step 3 (cont.) –
▪ Setup Fake Network
▪ Windows or Linux based system
▪ FakeNet or ApateDNS
▪ WireShark
▪ REMnux
34
▪ Step 5 – ▪ Step 7 –
▪ Ensure Internet is ▪ Run comparative analysis of
disconnected both snapshots with RegShot
▪ Note –
▪ Execute unknown code
▪ Process changes?
▪ Observe and interact with ▪ Registry updates?
program ▪ Abnormal processes
started?
▪ Step 6 –
▪ Stop code execution ▪ Analyze network traffic
▪ Whois.com (domain lookup)
▪ RegShot – for snapshot ▪ Maxmind.com
▪ CentralOps.net (do NOT
35
click on traceroute)
▪ 05-May: HW4 Due @ 11:59PM EST
36
Static vs Dynamic Analysis
https://technical.nttsecurity.com/post/102efk4/detecting-malware-through-static-and-dynamic-techniques
https://www.deepinstinct.com/2019/10/29/malware-evasion-techniques-part-2-anti-vm-blog/
https://www.deepinstinct.com/2019/11/24/malware-evasion-techniques-part-3-anti-sandboxing/
Portable Executable Files
http://msdn.microsoft.com/en-us/library/ms809762.aspx
https://blog.kowalczyk.info/articles/pefileformat.html
https://blog.malwarebytes.com/threat-analysis/2014/05/five-pe-analysis-tools-worth-looking-at/
Linux commands
https://sourceware.org/binutils/docs/binutils/nm.html
https://www.thegeekstuff.com/2012/03/linux-nm-command/
https://sourceware.org/binutils/docs/binutils/objdump.html
https://sourceware.org/binutils/docs/binutils/strings.html#strings
37
Setting up VM Sandbox
https://medium.com/@Flying_glasses/dynamic-malware-analysis-lab-setup-613075f9423f
Text Book
* Sikorski, M. & Honig, A (2012) Practical Malware Analysis, No Starch Press Inc. (ISBN: 978-1-59327-290-6)
38