Thursday, 29 October 2015

Useful NMAP tips

Useful options

--open will only show results for open ports.

-iL serverIP.txt will take IP input from a file and scan them

To check SSL ciphers supported by website
nmap -sT -PN -p 443 www.domain.com --script ssl-enum-ciphers.nse
nmap --script ssl-cert,ssl-enum-ciphers -p 443 www.domain.com

Windows Malware Analysis hints

These are some of the more common directories in which malware will install itself on
Microsoft Windows (multiple versions)
 %ApplicationData%\Microsoft\
 %System%\[FileName].dll
 %Program Files%\Internet Explorer\[FileName].dll
 %Program Files%\Movie Maker\[ FileName].dll
 %All Users Application Data%\[ FileName].dll
 %Temp%\[ FileName].dll
 %System%\[ FileName].tmp
 %Temp%\[ FileName].tmp

Malware will attempt to hook system and user processes in order to operate behind the
scenes and also attempt to prevent the victim from quickly identifying its activity. These are typical system and user processes affected by malware found.
 explorer.exe
 services.exe
 svchost.exe


Here are some of most common Registry locations where malware will install itself on a victim‟s computer in order
to execute and propagate.
 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\
 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\
 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\
 HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\

BOOT PROCESS
Power – When the system is switched on, power reaches the motherboard
through SMPS
BIOS – BIOS present on the motherboard is activated; Does the POST check;
then check for devices connected and passes control to the relevant device
(boot device) for the next stage of booting.
MBR – MBR of the boot device gets activated and checks for any boot loaders
or active partitions. If a boot loader is present, control is passed to it.
Else the control is passed to the active partition specified.
Active Partition BR – The boot loader of the active partition is activated
when it gets control.
MS WINDOWS
NTLDR (NT Boot Loader) in the system volume is loaded and passed the control
[SYSPART:\ntldr]

NTLDR reads the ‘boot.ini’ in C drive. If more than one OS is present, a choice is requested. Else
it continues booting from the boot partition as found in the boot.ini file. [SYSPART:\boot.ini]

Then NTDETECT from the system partition is loaded which is device detection program.
[SYSPART:\NTDETECT.COM]

It then loads NTOSKRNL (Kernel), HAL (Hardware Abstraction Layer) from the boot partitions.
[%systemroot%\system32\ntoskrnl.exe and %systemroot%\system32\hal.dll]

Then SYSTEM Hive is loaded and all boot drivers is loaded.
[%systemroot%\system32\config\system]

After that the boot loader (NTLOADER) passes control to Kernel (NTOSKRNL)
Kernel then loads the logo screen and initializes the sub-system

It then loads SMSS (Session Manager Subsystem Service) with priority 11 and passes control to it.
[%systemroot%\system32\smss.exe]

SMSS initializes the pagefile and other registry hives.

Starts the 32bit windows kernel (WIN32K.SYS)
[%systemroot%\system32\win32k.sys]

Starts CSRSS (Client Server Runtime Sub System) with priority 13.
[%systemroot%\system32\csrss.exe]

Then it starts WINLOGON with priority 13 and passes control to it.
[%systemroot%\system32\winlogon.exe]

WINLOGON then starts LSASS [Local Security Authorization Subsystem Service] with priority 9.
[%systemroot%\system32\lsass.exe]

WINLOGON then loads MSGINA (Graphical user Identification aNd Authentication), which presents the
login screen to the user.
[%systemroot%\system32\msgina.dll]

It then loads SERVICES (Services Controller) with priority 9.
[%systemroot%\system32\services.exe]

Once the user logs in, SERVICES takes control and loads all the necessary ‘automatic’ services for that user.

https://social.technet.microsoft.com/search/en-US/feed?query=windows%20server&rn=Microsoft%20Security%20Guidance&rq=site:blogs.technet.com/b/secguide/&format=RSS

Sysinternals
Process Explorer
Pink - Services
Blue - same security context as process explorer
Purple - Image is packed (malware commonly use packing/compressed)

process explorer can also check hits on virustotal.

Malware hides in common processes - rundll32.exe and svchost
It does this via an autostart or DLL injection

Sigcheck - image verification is it digitally signed
sigcheck -e -u -s c:\
recursive scan also subdirectories - scan all executables
-u only shows unsigned executables

Sigcheck can also check virustotal for hits
sigcheck -v -s -c c:\
-v : check hash on virustotal (but does not upload file if hash is not present
-c csv output

-vs together submits the sample to virustotal
-----
If you don't have direct access to the internet, you'll need to specify a proxy. Unfortunately, it won't take IE's proxy setting, you'll need to set it via netsh:

backup your settings:
netsh winhttp show proxy

set the proxy
netsh winhttp set proxy :

Don't forget to reset your proxy settings when you are done:
netsh winhttp reset proxy (or the appropriate command from your backup)
-----
Check all unsigned images especially in \Windows and \Users\\Appdata

Listdlls - scan running processes for unsigned DLLs
listdlls -u




Well-Known Domain-Relative RIDs
Description
500 Administrator
501 Guest
502 Krbtgt
512 Domain Admins
513 Domain Users
514 Domain Guests
515 Domain Computers
516 Domain Controllers
544 Built-In Administrators
545 Built-In Users
546 Built-In Guests

One possible use case is using the domain admins RID for detecting domain admins activity using a SIEM

Snort signature - points to remember

Some things to remember when trying to figure out why a IDS signature triggered

flowbits:isset,file.pdf - Check if snort has received sufficient data to know that it is looking at a pdf file.

Offset - where to start
Depth - how deep
Distance -
Within -
GET /content/downloads/....
content:"GET"; depth:3; content:"downloads"; distance:10; within:9 (search for downlaods 10 bytes after GET but within 9 bytes)
http://blog.joelesler.net/2010/03/offset-depth-distance-and-within.html
 

PCAP analysis things to remember

This helps during analysing pcap files - Some of these from http://www.malware-traffic-analysis.net/.

To find hostnames and mac addresses search for DCHP messages

tcpdump -nnA -s0 -r exercise.pcap 'src host 192.168.10.10 && arp'

Finding User Agent and OS
tcpdump -nnA -s0 -r exercise.pcap 'src host 192.168.10.10 &&dst port 80' | grep -A5 -B5 User | tail -5

User Agent - Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko
OS - Windows NT 6.1 = Windows 7

Using Wireshark = display filters to show all http requests
http.request

and only to a destination IP highlighted in Snort
http.request && ip.addr==10.10.10.10