© Mike O'Leary 2019
Mike O'LearyCyber Operationshttps://doi.org/10.1007/978-1-4842-4294-0_3

3. Operational Awareness

Mike O’Leary1 
(1)
Towson, MD, USA
 

Introduction

Core to successful cyber operations is the ability to maintain the integrity and availability of computer systems and networks. The first step in this process is knowing what is occurring on defended systems and networks. Both Windows and Linux feature tools that provide information about running processes, system users, and network connections. Network traffic between systems can be captured and analyzed with tools including tcpdump and Wireshark. In this chapter, the reader will learn what live information is available to a system administrator facing a potentially compromised system or network and will find different indicators of the attacks.

Using already-present tools to analyze the behavior of a running system provides advantages in speed and flexibility. However, it comes with limitations; if an adversary has sufficient privileges on the system, they can manipulate, modify, or even control the output from these tools and mislead the defender.

Linux Tools

One of the first things an administrator wants to know are the users logged on to the system.

Determining Users Logged On to the System

Two similar commands are available to determine the users currently logged into a Linux system.

Who

One Linux command that shows the logged-on users is who; running the command on a CentOS 7.1 system as root with one user (cgauss) logged in at the console, and second user (sgermain) connecting via SSH from spica.stars.example yields the following.
[root@girtab ~]# who
cgauss   :0           2017-02-18 17:34 (:0)
cgauss   pts/0        2017-02-18 17:34 (:0)
sgermain pts/1        2017-02-18 20:08 (spica.stars.example)
When run with the switches -a and -H, it prints column headers, the system boot time, the run level at system boot, the logged-in users, their logon time, and if they logged in remotely through SSH, the IP address, or hostname of the source.
[root@girtab ~]# who -aH
NAME       LINE         TIME             IDLE    PID COMMENT  EXIT
           system boot  2017-02-18 17:32
           run-level 5  2017-02-18 17:32
cgauss   ? :0           2017-02-18 17:34   ?     3877 (:0)
cgauss   + pts/0        2017-02-18 17:34   .     4545 (:0)
sgermain + pts/1        2017-02-18 20:08   .     5706 (spica.stars.example)

W

Another command is w; when run on the same system, it yields
[root@girtab ~]# w
 20:09:51 up 49 min,  3 users,  load average: 0.00, 0.01, 0.05
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
cgauss   :0       :0               17:34   ?xdm?  60.19s  0.06s gdm-session
cgauss   pts/0    :0               17:34    7.00s  0.05s  2.55s /usr/libexe
sgermain pts/1    spica.stars.exam 20:08    1:10   0.01s  0.01s -bash

Last

The list of recent logins can be found with the last command.
[root@girtab ~]# last
sgermain pts/1        spica.stars.exam Sat Feb 18 20:08   still logged in
sgermain pts/1        spica.stars.exam Sat Feb 18 17:34 - 17:34  (00:00)
cgauss   pts/0        :0               Sat Feb 18 17:34   still logged in
cgauss   :0           :0               Sat Feb 18 17:34   still logged in
(unknown :0           :0               Sat Feb 18 17:34 - 17:34  (00:00)
... Output Deleted ...

The data for w and who is stored in the file /var/run/utmp while the historical data for last comes from /var/log/wtmp. Many attackers with privileged access to a system clobber one or more of these files when trying to retain access.

Aureport

A look at the history of the logons to a system can be provided by the command aureport. This tool is not included in the default installation for every distribution; for example, on Ubuntu systems, it needs to be installed with the command
jmaxwell@siegena:~$ sudo apt-get install auditd
On an OpenSuSE system, the corresponding installation command is
menklent:~ # zypper install audit
Once installed, aureport with the flag -au provides data about authentication attempts.
[root@girtab ~]# aureport -au
Authentication Report
============================================
# date time acct host term exe success event
============================================
1. 01/14/2017 10:09:34 gdm ? :0 /usr/libexec/gdm-session-worker yes 348
2. 01/14/2017 11:09:15 gdm ? :0 /usr/libexec/gdm-session-worker yes 352
... Output Deleted ...
67. 02/18/2017 17:34:25 root ? pts/0 /usr/bin/su yes 400
68. 02/18/2017 17:34:38 sgermain 10.0.2.28 ? /usr/sbin/sshd yes 409
69. 02/18/2017 17:34:38 sgermain 10.0.2.28 ? /usr/sbin/sshd yes 410
70. 02/18/2017 17:34:38 sgermain 10.0.2.28 ssh /usr/sbin/sshd yes 413
71. 02/18/2017 20:08:41 sgermain 10.0.2.28 ? /usr/sbin/sshd yes 487
72. 02/18/2017 20:08:41 sgermain 10.0.2.28 ? /usr/sbin/sshd yes 488
73. 02/18/2017 20:08:41 sgermain 10.0.2.28 ssh /usr/sbin/sshd yes 491
There are several useful flags to aureport; for example, to see the failed logins from the current day, a user can run
[root@girtab ~]# aureport -au --failed --start today
Authentication Report
============================================
# date time acct host term exe success event
============================================
1. 02/18/2017 17:17:52 sgermain 10.0.2.28 ssh /usr/sbin/sshd no 456
2. 02/18/2017 17:18:03 sgermain 10.0.2.28 ssh /usr/sbin/sshd no 487
3. 02/18/2017 17:19:01 sgermain 10.0.2.28 ssh /usr/sbin/sshd no 537
4. 02/18/2017 17:19:05 sgermain 10.0.2.28 ssh /usr/sbin/sshd no 551

Determining User Activity

It is also important that the administrator know the activities of the users on the system.

Not all user accounts belong to humans; Linux systems use specialized system accounts for various processes. Generally, these system accounts have user id (UID) numbers less than 500, while user accounts corresponding to humans have UID numbers beginning with 500 or 1000, depending on the distribution and release. To find the UID given an account name, a user can use the id command.
[egalois@sabik ~]$ id egalois
uid=500(egalois) gid=500(egalois) groups=500(egalois)
To find the username given a UID, a user can use getent.
[egalois@sabik ~]$ getent passwd 500
egalois:x:500:500:Evariste Galois:/home/egalois:/bin/bash

History

The history command provides a list of the Bash shell commands run by the current user. Data for the history command is stored in the file ~/.bash_history, relative to the home directory of the user, and it can be manipulated and modified by the user (or root).

GNU Accounting Tools

The GNU accounting tools provide another way to determine the users that are or have been on the system as well as providing information about past executed commands. On CentOS systems, it is typically installed by default but not running, as can be verified1 by running
[root@girtab ~]# systemctl status psacct
psacct.service - Kernel process accounting
   Loaded: loaded (/usr/lib/systemd/system/psacct.service; disabled)
   Active: inactive (dead)
Start the service and ensure that it starts on system boot with the commands
[root@girtab ~]# systemctl start psacct
[root@girtab ~]# systemctl enable psacct
ln -s '/usr/lib/systemd/system/psacct.service' '/etc/systemd/system/multi-user.target.wants/psacct.service'

OpenSuSE, Ubuntu, and Mint systems do not install the GNU accounting tools, but they are available with the name acct. They can be installed with zypper (OpenSuSE) or apt (Mint/Ubuntu). Ubuntu and Mint systems start the service after subsequent reboots automatically; on OpenSuSE, this must be enabled manually.

One of the commands provided by the GNU accounting utilities is ac, which shows the amount of time users have spent connected to the system. The -d flag separates the data by date, and the -p by person, so to determine connect time by person by day run.
[root@girtab ~]# ac -dp
        (unknown)                            0.08
Jan 14  total        0.08
        (unknown)                            0.06
        cgauss                              36.32
Jan 15  total       36.38
        (unknown)                            0.01
        cgauss                               1.91
Feb  4  total        1.93
        sgermain                             1.05
        (unknown)                            0.04
        cgauss                               7.02
Feb 18  total        8.11
        (unknown)                            0.03
        cgauss                               0.04
Today   total        0.06

These numbers depend on timing made by the system. If the system is virtualized, and the system is, for example, reverted from a snapshot, then these values may be misleading or confusing.

GNU accounting tools track the last time a command was run. Running lastcomm with a command name like ls shows who ran that command and when.
[root@girtab ~]# lastcomm ls
ls                     root     pts/0      0.00 secs Sat Feb 18 20:55
ls                     cgauss   pts/0      0.00 secs Sat Feb 18 20:55
ls                     root     __         0.00 secs Sat Feb 18 20:53
ls                     root     __         0.00 secs Sat Feb 18 20:53
... Output Deleted ...
When run with a username, like sgermain, lastcomm shows the commands run by that user.
[root@girtab ~]# lastcomm sgermain
gedit                  sgermain pts/1      0.00 secs Sat Feb 18 21:15
dbus-launch            sgermain pts/1      0.00 secs Sat Feb 18 21:15
bash              F    sgermain pts/1      0.00 secs Sat Feb 18 21:15
bash              F    sgermain pts/1      0.00 secs Sat Feb 18 21:15
... Output Deleted ...

Determining the State of the System

Sometimes the administrator wants to know the current state of the system, including determining which processes are running or which network connections have been made.

Top

The top command provides a real-time list of processes running on the system; here is a representative result on a quiet system.
top - 21:16:39 up 23 min,  3 users,  load average: 0.38, 0.15, 0.14
Tasks: 161 total,   4 running, 157 sleeping,   0 stopped,   0 zombie
%Cpu(s):  2.5 us,  0.0 sy,  0.0 ni, 97.5 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  1017160 total,    97768 free,   484064 used,   435328 buff/cache
KiB Swap:  1679356 total,  1679356 free,        0 used.   365424 avail Mem
  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
 3078 cgauss    20   0 1575340 222172  39496 S  1.5 21.8   0:19.85 gnome-sh
 1889 root      20   0  236424  53564   7852 R  0.5  5.3   0:04.91 Xorg
    1 root      20   0   59596   6960   3964 S  0.0  0.7   0:01.04 systemd
    2 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kthreadd
    3 root      20   0       0      0      0 S  0.0  0.0   0:00.00 ksoftirq
    5 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kworker/
    6 root      20   0       0      0      0 S  0.0  0.0   0:00.03 kworker/
    7 root      rt   0       0      0      0 S  0.0  0.0   0:00.00 migratio
    8 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcu_bh
    9 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/0
   10 root      20   0       0      0      0 S  0.0  0.0   0:00.50 rcu_sche
   11 root      20   0       0      0      0 R  0.0  0.0   0:00.25 rcuos/0
   12 root      rt   0       0      0      0 S  0.0  0.0   0:00.00 watchdog
   13 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 khelper

The processes are listed in order, with the processes using the most CPU listed at the top. When a system is slow or sluggish due to a heavy load, this is the place to start diagnosing the problem.

Ps

The ps command is used to determine the processes running on a system. This tool comes with a wide range of flags to customize the output. To see the processes currently running sorted by PID, as root run ps with the flags aux.
[root@girtab ~]# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.6  59596  6960 ?        Ss   20:52   0:01 /usr/lib/s
root         2  0.0  0.0      0     0 ?        S    20:52   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    20:52   0:00 [ksoftirqd
root         5  0.0  0.0      0     0 ?        S<   20:52   0:00 [kworker/0
root         6  0.0  0.0      0     0 ?        S    20:52   0:00 [kworker/u
root         7  0.0  0.0      0     0 ?        S    20:52   0:00 [migration
root         8  0.0  0.0      0     0 ?        S    20:52   0:00 [rcu_bh]
root         9  0.0  0.0      0     0 ?        S    20:52   0:00 [rcuob/0]
root        10  0.0  0.0      0     0 ?        S    20:52   0:00 [rcu_sched
... Output Deleted...
When run with the flag --forest, the command ps returns the process structure, showing which process spawned another.
[root@girtab ~]# ps ax --forest
  PID TTY      STAT   TIME COMMAND
    2 ?        S      0:00 [kthreadd]
    3 ?        S      0:00  \_ [ksoftirqd/0]
... Output Deleted ...
 4048 ?        Sl     0:02 /usr/libexec/gnome-terminal-server
 4051 ?        S      0:00  \_ gnome-pty-helper
 4052 pts/0    Ss     0:00  \_ bash
 4088 pts/0    S      0:00      \_ su -
 4095 pts/0    S      0:00          \_ -bash
 4485 pts/0    R+     0:00              \_ ps ax --forest

Netstat

One command to determine what ports are open on a Linux is netstat. Linux and Unix systems have two kinds of ports - network ports and Unix sockets. Unix sockets are used for communication by different processes on the same system, so in general we are uninterested in those; however, both sorts of ports are reported by netstat.

The netstat tool has several useful flags, including:
  • -v Be verbose

  • -n Use numeric values for ports, rather than names

  • -A inet (or –inet) Show only IPv4 connections

  • -A inet6 (or –inet6) Show only IPv6 connections

  • -x Show only Unix sockets

  • -t Show only TCP (v4/v6)

  • -u Show only UDP (v4/v6)

  • -p Show the PID for that connection

  • -l Show listening sockets (not shown by default)

  • -a Show listening and open sockets

  • -r Show routing table

To find out what is listening on the system, a good set of flags is
[root@girtab ~]# netstat -nlpv --inet
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address  Foreign Address State   PID/Program name
tcp        0      0 0.0.0.0:22     0.0.0.0:*       LISTEN  1360/sshd
tcp        0      0 127.0.0.1:631  0.0.0.0:*       LISTEN  3083/cupsd
tcp        0      0 127.0.0.1:25   0.0.0.0:*       LISTEN  2515/master
tcp        0      0 127.0.0.1:6010 0.0.0.0:*       LISTEN  4254/sshd: sgerm
udp        0      0 0.0.0.0:123    0.0.0.0:*               626/chronyd
udp        0      0 0.0.0.0:5353   0.0.0.0:*               631/avahi-daemon
udp        0      0 0.0.0.0:44830  0.0.0.0:*               631/avahi-daemon
udp        0      0 127.0.0.1:323  0.0.0.0:*               626/chronyd

This provides a verbose list listening TCP and UDP ports in numerical form along with the PID of the process that opened the port.

Lsof

The tool lsof can be used to determine what resources are being used and by which process. Resources include network sockets but can also include devices like a USB drive or files. For example, the current or listening IPv4 connections can be shown with
[root@girtab ~]# lsof -i4
COMMAND    PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
chronyd    626   chrony    1u  IPv4  14305      0t0  UDP *:ntp
chronyd    626   chrony    3u  IPv4  14307      0t0  UDP localhost:323
avahi-dae  631    avahi   12u  IPv4  15901      0t0  UDP *:mdns
avahi-dae  631    avahi   13u  IPv4  15902      0t0  UDP *:44830
sshd      1360     root    3u  IPv4  19379      0t0  TCP *:ssh (LISTEN)
master    2515     root   13u  IPv4  20615      0t0  TCP localhost:smtp (LISTEN)
cupsd     3083     root   12u  IPv4  24990      0t0  TCP localhost:ipp (LISTEN)
sshd      4250     root    3u  IPv4  33805      0t0  TCP Girtab.stars.example:ssh->Spica.
                                                          stars.example:38411 (ESTABLISHED)
sshd      4254 sgermain    3u  IPv4  33805      0t0  TCP Girtab.stars.example:ssh->Spica.
                                                          stars.example:38411 (ESTABLISHED)
sshd      4254 sgermain   10u  IPv4  33983      0t0  TCP localhost:x11-ssh-offset (LISTEN)

In addition to the listening ports, this shows an active SSH connection from girtab.stars.example.

To determine the resources used by a selected PID, specify the PID with the -p flag. For example, the previous shows an SSH connection for sgermain using PID 4254; to examine this process, the administrator runs the following.
[root@girtab ~]# lsof -p 4254
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
      Output information may be incomplete.
COMMAND  PID     USER   FD   TYPE  DEVICE SIZE/OFF     NODE NAME
sshd    4254 sgermain  cwd    DIR  253,1     4096      128 /
sshd    4254 sgermain  rtd    DIR  253,1     4096      128 /
sshd    4254 sgermain  txt    REG  253,1   815432 38281903 /usr/sbin/sshd
sshd    4254 sgermain  DEL    REG  0,4               33868 /dev/zero
... Output Deleted ...
sshd    4254 sgermain  mem    REG  253,1   164336 33887955 /usr/lib64/ld-2.17.so
sshd    4254 sgermain  DEL    REG  0,4               33829 /dev/zero
sshd    4254 sgermain    0u   CHR  1,3        0t0     4558 /dev/null
sshd    4254 sgermain    1u   CHR  1,3        0t0     4558 /dev/null
sshd    4254 sgermain    2u   CHR  1,3        0t0     4558 /dev/null
sshd    4254 sgermain    3u  IPv4  33805      0t0      TCP Girtab.stars.example:ssh->Spica.                                                            stars.example:38411 (ESTABLISHED)
... Output Deleted ...
To determine the resources used by a user, instead specify the user name with the -u flag.
[root@girtab ~]# lsof -u sgermain
COMMAND   PID     USER   FD  TYPE  DEVICE SIZE/OFF     NODE NAME
sshd     4254 sgermain  cwd   DIR   253,1     4096      128 /
sshd     4254 sgermain  rtd   DIR   253,1     4096      128 /
sshd     4254 sgermain  txt   REG   253,1   815432 38281903 /usr/sbin/sshd
sshd     4254 sgermain  DEL   REG     0,4             33868 /dev/zero
... Output Deleted ...
bash     4258 sgermain  255u   CHR  136,1      0t0        4 /dev/pts/1
gedit    4343 sgermain  cwd    DIR  253,1     4096 19301951 /home/sgermain
gedit    4343 sgermain  rtd    DIR  253,1     4096      128 /
gedit    4343 sgermain  txt    REG  253,1   606176 19016217 /usr/bin/gedit
gedit    4343 sgermain  mem    REG  253,1   333632 50633441 /usr/share/font
... Output Deleted ...

Here the data shows that the user sgermain is apparently using gedit on PID 4343.

The /proc Directory

A great deal of information is available about a PID through the system’s /proc directory. That directory contains subdirectories for each running PID. Consider the PID 4343 from the previous example.
[root@girtab ~]# cd /proc/4343
[root@girtab 4343]# ls
attr            cpuset    limits        ns             root        syscall
autogroup       cwd       loginuid      numa_maps      sched       task
auxv            environ   maps          oom_adj        sessionid   uid_map
cgroup          exe       mem           oom_score      smaps       wchan
clear_refs      fd        mountinfo     oom_score_adj  stack
cmdline         fdinfo    mounts        pagemap        stat
comm            gid_map   mountstats    personality    statm
coredump_filter io        net           projid_map     status
The command line used to start the process is contained in /proc/4343/cmdline, where the arguments are separated by null bytes. To show the complete command line, use cat with the -v option to show the non-printing null characters.
[root@girtab 4343]# cat -v cmdline
gedit^@testdoc^@
The file /proc/4343/cwd is a symbolic link pointing to the process’s current working directory.
[root@girtab 4343]# ls -l /proc/4343/cwd
lrwxrwxrwx. 1 sgermain sgermain 0 Feb 18 21:25 /proc/4343/cwd -> /home/sgermain
The link /proc/4343/exe points to the process’s executable.
[root@girtab 4343]# ls -l /proc/4343/exe
lrwxrwxrwx. 1 sgermain sgermain 0 Feb 18 21:25 /proc/4343/exe -> /usr/bin/gedit
The directory /proc/3355/fd contains symbolic links to the file descriptors opened by the process.
[root@girtab 4343]# ls -l /proc/4343/fd
total 0
lrwx------. 1 sgermain sgermain 64 Feb 18 21:20 0 -> /dev/pts/1
lrwx------. 1 sgermain sgermain 64 Feb 18 21:20 1 -> /dev/pts/1
lrwx------. 1 sgermain sgermain 64 Feb 18 21:20 10 -> anon_inode:[eventfd]
lrwx------. 1 sgermain sgermain 64 Feb 18 21:20 11 -> socket:[34963]
lr-x------. 1 sgermain sgermain 64 Feb 18 21:20 12 -> anon_inode:inotify
lrwx------. 1 sgermain sgermain 64 Feb 18 21:20 13 -> anon_inode:[eventfd]
lr-x------. 1 sgermain sgermain 64 Feb 18 21:20 14 -> /proc/4343/mounts
lrwx------. 1 sgermain sgermain 64 Feb 18 21:18 2 -> /dev/pts/1
lrwx------. 1 sgermain sgermain 64 Feb 18 21:20 3 -> socket:[34830]
lrwx------. 1 sgermain sgermain 64 Feb 18 21:20 4 -> socket:[34900]
lrwx------. 1 sgermain sgermain 64 Feb 18 21:20 5 -> anon_inode:[eventfd]
lrwx------. 1 sgermain sgermain 64 Feb 18 21:20 6 -> anon_inode:[eventfd]
lrwx------. 1 sgermain sgermain 64 Feb 18 21:20 7 -> socket:[34942]
lrwx------. 1 sgermain sgermain 64 Feb 18 21:20 8 -> anon_inode:[eventfd]
lrwx------. 1 sgermain sgermain 64 Feb 18 21:20 9 -> socket:[34954]

Detect: Java JAX-WS Remote Code Execution

Chapter 2 showed how to run the Java Applet JAX-WS Remote Code Execution attack against a Linux target running Java 7. Configure and run the attack, say against a CentOS 6.0 64-bit system running Firefox and Java 7 Update 0; for the payload use Java Meterpreter running through reverse HTTPS, connecting back to the attacker on port 443. Interact with the target and start a shell.

After the successful attack, on the victim’s system, a check of logged-in users by root shows nothing out of the ordinary; the who command shows
[root@sirius ~]# who
pfermat  tty1         2014-07-31 12:13 (:0)
pfermat  pts/0        2014-07-31 12:13 (:0.0)
enoether pts/1        2014-07-31 13:15 (10.0.2.18)
pfermat  pts/2        2014-07-31 14:12 (:0.0)
A check of the process list with ps aux shows little out of the ordinary, save for a few lines near the end.
[root@sirius ~]# ps aux
USER     PID %CPU %MEM    VSZ   RSS TTY   STAT START TIME COMMAND
root       1  0.0  0.1  19244  1372 ?     Ss   12:12 0:00 /sbin/init
... Output Deleted ...
pfermat 3443  0.0  0.0 105356   828 pts/2 S+   15:00 0:00 /usr/bin/less -is
pfermat 3521  0.0  4.3 1112392 44556 ?    Sl   15:16 0:01
                                /usr/java/jre1.7.0/bin/java -D__jvm_launched=11036
pfermat 3578  0.1  5.3 1076568 54544 ?    Sl   15:16 0:03
                                /usr/java/jre1.7.0/bin/java -classpath /tmp/~spawn
pfermat 3615  0.0  0.1 106012  1088 ?     S    15:17 0:00 /bin/bash
pfermat 3640  0.0  0.1 106012  1160 ?     S    15:18 0:00 /bin/bash
postfix 4012  0.0  0.2  62052  2680 ?     S    15:33 0:00 pickup -l -t fifo -u
root    4490  0.0  0.1 107968  1048 pts/0 R+   15:50 0:00 ps aux
Here the combination of Java and Bash shells catches the eye. When ps --forest is run to make the relationships between processes more explicit, it becomes suspicious.
[root@sirius ~]# ps ax --forest
PID  TTY      STAT TIME COMMAND
  2  ?        S    0:00 [kthreadd]
  3  ?        S    0:00  \_ [migration/0]
... Output Deleted ...
3230 ?        S    0:00 /bin/sh /usr/lib64/firefox-3.6/run-mozilla.sh /usr
3257 ?       Sl    0:50  \_ /usr/lib64/firefox-3.6/firefox
3521 ?       Sl    0:01      \_ /usr/java/jre1.7.0/bin/java -D__jvm_launch
3339 ?        S    0:00 /usr/libexec/gvfsd-computer --spawner :1.7 /org/gt
3578 ?       Sl    0:03 /usr/java/jre1.7.0/bin/java -classpath /tmp/~spawn
3615 ?        S    0:00  \_ /bin/bash
3640 ?        S    0:00  \_ /bin/bash

This shows a Firefox process (3230) spawned a Java process (3521), which seems normal enough. On the other hand, why is another Java process (3578) unrelated apparently to Firefox spawning a pair of Bash shells2 (3615, 3640)?

A check of the network connections with netstat shows
[root@sirius ~]# netstat -ant
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address          Foreign Address       State
tcp        0      0 0.0.0.0:47434          0.0.0.0:*             LISTEN
tcp        0      0 0.0.0.0:111            0.0.0.0:*             LISTEN
tcp        0      0 0.0.0.0:22             0.0.0.0:*             LISTEN
tcp        0      0 127.0.0.1:631          0.0.0.0:*             LISTEN
tcp        0      0 127.0.0.1:25           0.0.0.0:*             LISTEN
tcp        0      0 10.0.2.10:22           10.0.2.18:53059       ESTABLISHE
tcp        1      0 10.0.2.10:47326        184.29.105.107:80     CLOSE_WAIT
tcp        0      0 :::111                 :::*                  LISTEN
tcp        0      0 :::22                  :::*                  LISTEN
tcp        0      0 ::1:631                :::*                  LISTEN
tcp        0      0 :::45348               :::*                  LISTEN
tcp       38      0 ::ffff:10.0.2.10:47851 ::ffff:10.0.2.248:443 CLOSE_WAIT

The victim is located at 10.0.2.10, and the SSH connection to port 22 from 10.0.2.18 seen earlier is noted. Also noticed is what appears to be an HTTP connection to the site 184.29.105.107; a lookup of the IP address shows that it is named a184-29-105-107.deploy.static.akamaitechnologies.com. Nothing in this suggests anything malicious, at least not yet. On the other hand, the last line is perplexing - it appears to be using stateless translation between IPv4 and IPv6 to connect to 10.0.2.248, yet the system is on a network that was not configured to support IPv6.

A pair of lsof commands are run, one to see what is happening on IPv4 and one on IPv6. The command on IPv4 returns
[root@sirius ~]# lsof -i4
COMMAND    PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
rpcbind   1116      rpc    6u  IPv4  10952      0t0  UDP *:sunrpc
rpcbind   1116      rpc    7u  IPv4  10956      0t0  UDP *:867
rpcbind   1116      rpc    8u  IPv4  10957      0t0  TCP *:sunrpc (LISTEN)
avahi-dae 1162    avahi   13u  IPv4  11310      0t0  UDP *:mdns
avahi-dae 1162    avahi   14u  IPv4  11311      0t0  UDP *:46358
rpc.statd 1199  rpcuser    5u  IPv4  11533      0t0  UDP *:951
rpc.statd 1199  rpcuser    8u  IPv4  11539      0t0  UDP *:45430
rpc.statd 1199  rpcuser    9u  IPv4  11543      0t0  TCP *:47434 (LISTEN)
cupsd     1270     root    7u  IPv4  11765      0t0  TCP
                                                localhost.localdomain:ipp (LISTEN)
cupsd     1270     root    9u  IPv4  11768      0t0  UDP *:ipp
sshd      1505     root    3u  IPv4  12540      0t0  TCP *:ssh (LISTEN)
master    1581     root   12u  IPv4  12735      0t0  TCP
                                               localhost.localdomain:smtp (LISTEN)
clock-app 2253  pfermat   21u  IPv4  29829      0t0  TCP
                                          sirius.stars.example:47326->a184-29-105-
                        107.deploy.static.akamaitechnologies.com:http (CLOSE_WAIT)
sshd      2538     root    3u  IPv4  19562      0t0  TCP
                           sirius.stars.example:ssh->10.0.2.18:53059 (ESTABLISHED)
sshd      2543 enoether    3u  IPv4  19562      0t0  TCP
                           sirius.stars.example:ssh->10.0.2.18:53059 (ESTABLISHED)
This clarifies the role of the connection on port 80 to akamaitechnologies.com; it appears related to the clock. The command on IPv6 returns
[root@sirius ~]# lsof -i6
COMMAND    PID    USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
rpcbind   1116     rpc    9u  IPv6  10959      0t0  UDP *:sunrpc
rpcbind   1116     rpc   10u  IPv6  10961      0t0  UDP *:867
rpcbind   1116     rpc   11u  IPv6  10962      0t0  TCP *:sunrpc (LISTEN)
rpc.statd 1199 rpcuser   10u  IPv6  11547      0t0  UDP *:38959
rpc.statd 1199 rpcuser   11u  IPv6  11551      0t0  TCP *:45348 (LISTEN)
cupsd     1270    root    6u  IPv6  11764      0t0  TCP
                                                 sirius.stars.example:ipp (LISTEN)
sshd      1505    root    4u  IPv6  12545      0t0  TCP *:ssh (LISTEN)
java      3578 pfermat   11u  IPv6  30835      0t0  TCP
                         sirius.stars.example:40519->10.0.2.248:https (CLOSE_WAIT)

This affirms that the connection out to 10.0.2.248 is suspicious, as 3578 is the Java PID that already seemed out of the ordinary.

Run lsof on the suspicious process (3578) and the two child processes (3615, 3640).
[root@sirius ~]# lsof -p 3578
COMMAND  PID    USER  FD TYPE             DEVICE SIZE/OFF    NODE NAME
java    3578 pfermat cwd  DIR              253,0     4096  783371 /home/pfermat
java    3578 pfermat rtd  DIR              253,0     4096       2 /
java    3578 pfermat txt  REG              253,0     7622   12137
                                                       /usr/java/jre1.7.0/bin/java
java    3578 pfermat mem  REG              253,0   150672  151350
                                                                 /lib64/ld-2.12.so
java    3578 pfermat mem  REG              253,0    22536  151353
                                                              /lib64/libdl-2.12.so
... Output Deleted ...
java    3578 pfermat   9u unix 0xffff880010100cc0     0t0   27197 socket
java    3578 pfermat  10r REG              253,0   196220   12321
                                    /usr/java/jre1.7.0/lib/ext/sunjce_provider.jar
java    3578 pfermat  11u IPv6              30941     0t0     TCP
                         sirius.stars.example:59888->10.0.2.248:https (CLOSE_WAIT)
java    3578 pfermat  12r REG              253,0    24427  407859
                                   /tmp/jar_cache7965704024406646245.tmp (deleted)
java    3578 pfermat  13u unix 0xffff8800101006c0     0t0   27206 socket
java    3578 pfermat  15r REG              253,0    38782  407860
                                   /tmp/jar_cache1325341554883442176.tmp (deleted)
java    3578 pfermat  16w FIFO                0,8     0t0   27252 pipe
... Output Deleted ...

Much of what is shown is standard; for example, Java libraries have been loaded into memory. There is the IPv6 connection that appears to be running between IPv4 addresses; there also appears to be a pair of deleted temporary files that were in /tmp that are named jar_cache(long-number).tmp.

The results for the child PIDs 3615 and 3640 both are much smaller and show nothing of interest.
[root@sirius ~]# lsof -p 3640
COMMAND  PID    USER  FD  TYPE DEVICE SIZE/OFF    NODE NAME
bash    3640 pfermat cwd   DIR  253,0     4096  783371 /home/pfermat
bash    3640 pfermat rtd   DIR  253,0     4096       2 /
bash    3640 pfermat txt   REG  253,0   943248  653081 /bin/bash
bash    3640 pfermat mem   REG  253,0   150672  151350 /lib64/ld-2.12.so
bash    3640 pfermat mem   REG  253,0    22536  151353 /lib64/libdl-2.12.so
bash    3640 pfermat mem   REG  253,0  1838296  151351 /lib64/libc-2.12.so
bash    3640 pfermat mem   REG  253,0   138280  151385 /lib64/libtinfo.so.5.7
bash    3640 pfermat mem   REG  253,0 99158752 1046749
                                                    /usr/lib/locale/locale-archive
bash    3640 pfermat mem   REG  253,0    26050 1047005
                                              /usr/lib64/gconv/gconv-modules.cache
bash    3640 pfermat   0r FIFO    0,8      0t0   27302 pipe
bash    3640 pfermat   1w FIFO    0,8      0t0   27303 pipe
bash    3640 pfermat   2w FIFO    0,8      0t0   27304 pipe
The command line for the two child PIDs are the same and similarly uninteresting.
[root@sirius ~]# cat -v /proc/3640/cmdline
/bin/bash^@
However, the PID for the parent process tells us immediately that it is likely related to a Metasploit attack.
[root@sirius ~]# cat -v /proc/3578/cmdline
/usr/java/jre1.7.0/bin/java^@-classpath^@/tmp/~spawn5215661374666879790.tmp.dir^@metasploit.Payload^@
A check of the /tmp directory shows that the oddly named directory still exists, with a Java class that should be analyzed in more detail.
[root@sirius tmp]# ls -al -R /tmp/~spawn1963638874784095284.tmp.dir/
/tmp/~spawn1963638874784095284.tmp.dir/:
total 12
drwxrwxr-x.  3 pfermat pfermat 4096 Jul 31 15:16 .
drwxrwxrwt. 30 root    root    4096 Aug  5 09:51 ..
drwxrwxr-x.  2 pfermat pfermat 4096 Jul 31 15:16 metasploit
/tmp/~spawn1963638874784095284.tmp.dir/metasploit:
total 12
drwxrwxr-x. 2 pfermat pfermat 4096 Jul 31 15:16 .
drwxrwxr-x. 3 pfermat pfermat 4096 Jul 31 15:16 ..
-rw-rw-r--. 1 pfermat pfermat 1309 Jul 31 15:16 PayloadTrustManager.class
A check of the files opened by this process shows a pair of deleted files.
[root@sirius ~]# ls -l /proc/3578/fd
total 0
lr-x------. 1 pfermat pfermat 64 Jul 31 15:16 0 -> pipe:[27173]
l-wx------. 1 pfermat pfermat 64 Jul 31 15:16 1 -> pipe:[27174]
lr-x------. 1 pfermat pfermat 64 Jul 31 15:23 10 ->
                                    /usr/java/jre1.7.0/lib/ext/sunjce_provider.jar
lrwx------. 1 pfermat pfermat 64 Jul 31 15:23 11 -> socket:[31713]
lr-x------. 1 pfermat pfermat 64 Jul 31 15:23 12 ->
                                   /tmp/jar_cache7965704024406646245.tmp (deleted)
lrwx------. 1 pfermat pfermat 64 Jul 31 15:23 13 -> socket:[27206]
lr-x------. 1 pfermat pfermat 64 Jul 31 15:23 15 ->
                                   /tmp/jar_cache1325341554883442176.tmp (deleted)
l-wx------. 1 pfermat pfermat 64 Jul 31 15:23 16 -> pipe:[27252]
lr-x------. 1 pfermat pfermat 64 Jul 31 15:23 17 -> pipe:[27253]
l-wx------. 1 pfermat pfermat 64 Jul 31 15:23 18 -> pipe:[27302]
lr-x------. 1 pfermat pfermat 64 Jul 31 15:23 19 -> pipe:[27254]
l-wx------. 1 pfermat pfermat 64 Jul 31 15:16 2 -> pipe:[27175]
lr-x------. 1 pfermat pfermat 64 Jul 31 15:23 20 -> pipe:[27303]
lr-x------. 1 pfermat pfermat 64 Jul 31 15:23 22 -> pipe:[27304]
l-wx------. 1 pfermat pfermat 64 Jul 31 15:16 3 -> /usr/java/jre1.7.0/lib/rt.jar
lr-x------. 1 pfermat pfermat 64 Jul 31 15:16 4 -> /usr/java/jre1.7.0/lib/jsse.jar
lr-x------. 1 pfermat pfermat 64 Jul 31 15:23 5 -> /dev/random
lr-x------. 1 pfermat pfermat 64 Jul 31 15:16 6 -> /dev/urandom
lr-x------. 1 pfermat pfermat 64 Jul 31 15:16 7 -> /usr/java/jre1.7.0/lib/jce.jar
lr-x------. 1 pfermat pfermat 64 Jul 31 15:16 8 ->
                                              /usr/java/jre1.7.0/lib/ext/sunec.jar
lrwx------. 1 pfermat pfermat 64 Jul 31 15:23 9 -> socket:[27197]
These are the same deleted files jar_cache(long-number).tmp noted earlier through lsof. Though the files have been deleted from their original location in /tmp, they can still be accessed through the link in /proc. Copy these and the Java class noted earlier to a convenient location for further analysis.
[root@sirius ~]# mkdir quarantine
[root@sirius quarantine]# cp /tmp/~spawn1963638874784095284.tmp.dir/metasploit/PayloadTrustManager.class ./quarantine/
[root@sirius ~]# cp /proc/3578/fd/12 ./quarantine/sample_1
[root@sirius ~]# cp /proc/3578/fd/15 ./quarantine/sample_2
[root@sirius ~]# cd ./quarantine/
[root@sirius quarantine]# ls -l
total 68
-rw-r--r--. 1 root root  1309 Jul 31 16:40 PayloadTrustManager.class
-rw-r--r--. 1 root root 24427 Jul 31 16:40 sample_1
-rw-r--r--. 1 root root 38782 Jul 31 16:40 sample_2

An attacker that writes files to a target system runs the risk that these files will be detected by the defender, and subsequently analyzed.

Detect: Firefox XCS Code Execution

Chapter 2 showed how to attack Firefox directly with the Firefox 5.0 - 15.0.1 __exposedProps__ XCS Code Execution attack. Configure the attack using the default JavaScript XPCOM shell running on the default port (TCP/4444) for the payload. Visit the malicious web page with a vulnerable Ubuntu 12.04 desktop system using the vulnerable (and default) Firefox 14.0.1, and obtain a session on the target.

After the successful attack, listing the users on the system shows just the single logged-in user.
dhilbert@betelgeuse:~$ w
 09:38:05 up 40 min,  2 users,  load average: 0.00, 0.01, 0.05
USER     TTY   FROM LOGIN@ IDLE  JCPU  PCPU WHAT
dhilbert tty7       08:57 40:13  7.96s 0.10s gnome-session --session=ubuntu
dhilbert pts/0 :0   09:01  0.00s 0.23s 0.00s w
A check of the process list with ps aux shows little out of the ordinary.
dhilbert@betelgeuse:~$ sudo ps aux
USER      PID %CPU %MEM    VSZ   RSS TTY   STAT START   TIME COMMAND
root        1  0.0  0.1   3516  1980 ?     Ss   08:57   0:00 /sbin/init
root        2  0.0  0.0      0     0 ?     S    08:57   0:00 [kthreadd]
... Output Deleted ...
dhilbert 1757  0.2  6.4 380096 65980 ?     Sl   09:00   0:05
                                                          /usr/lib/firefox/firefox
dhilbert 1775  0.0  0.3  36092  3936 ?     Sl   09:00   0:00
                                  /usr/lib/at-spi2-core/at-spi-bus-launcher
dhilbert 1816  0.1  1.5  90012 16404 ?     Sl   09:01   0:03 gnome-terminal
dhilbert 1825  0.0  0.0   2384   756 ?     S    09:01   0:00 gnome-pty-helper
dhilbert 1826  0.0  0.3   7204  3660 pts/0 Ss   09:01   0:00 bash
root     2129  0.0  0.0      0     0 ?     S    09:30   0:00 [kworker/0:0]
root     2131  0.0  0.0      0     0 ?     S    09:35   0:00 [kworker/0:2]
root     2135  0.0  0.0      0     0 ?     S    09:40   0:00 [kworker/0:1]
root     2140  0.0  0.1   5808  1716 pts/0 S+   09:45   0:00 sudo ps aux
root     2141  0.0  0.1   4928  1168 pts/0 R+   09:45   0:00 ps aux
Checking with --forest also shows nothing unusual.
dhilbert@betelgeuse:~$ sudo ps ax --forest
 PID TTY      STAT START   TIME COMMAND
   2 ?        S    08:57   0:00 [kthreadd]
   3 ?        S    08:57   0:00  \_ [ksoftirqd/0]
... Output Deleted ...
1757 ?        Sl   09:00   0:05 /usr/lib/firefox/firefox
1775 ?        Sl   09:00   0:00 /usr/lib/at-spi2-core/at-spi-bus-launcher
1816 ?        Sl   09:01   0:03 gnome-terminal
1825 ?        S    09:01   0:00  \_ gnome-pty-helper
1826 pts/0    Ss   09:01   0:00  \_ bash
2157 pts/0    S+   09:48   0:00      \_ sudo ps aux --forest
2158 pts/0    R+   09:48   0:00          \_ ps aux --forest
Check the network connections with netstat.
dhilbert@betelgeuse:~$ sudo netstat -antp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address   Foreign Address  State      PID/Program
tcp        0      0 127.0.0.1:631   0.0.0.0:*        LISTEN     767/cupsd
tcp        1      0 10.0.2.18:59813 91.189.89.144:80 CLOSE_WAIT
                                                               1567/ubuntu-geoip-p
tcp        0      0 10.0.2.18:59911 10.0  .2.249:4444  ESTABLISHED  1757/firefox
tcp6       0      0 ::1:631         :::*             LISTEN     767/cupsd
The lsof command includes the hostnames for the remote connections.
dhilbert@betelgeuse:~$ sudo lsof -i4
COMMAND    PID     USER FD   TYPE DEVICE SIZE/OFF NODE NAME
cupsd      767     root  9u  IPv4   8063      0t0  TCP localhost:ipp (LISTEN)
avahi-dae  772    avahi 12u  IPv4   8099      0t0  UDP *:mdns
avahi-dae  772    avahi 14u  IPv4   8101      0t0  UDP *:55226
ubuntu-ge 1567 dhilbert  7u  IPv4  11001      0t0  TCP
                 betelgeuse.local:59813->mistletoe.canonical.com:http (CLOSE_WAIT)
firefox   1757 dhilbert 57u  IPv4  11954      0t0  TCP
                             betelgeuse.local:59911->10.0.2.249:4444 (ESTABLISHED)

There are two connections of interest. The first (1567) runs on HTTP and appears to be a connection from a local Ubuntu named service to a host at Canonical, the makers of Ubuntu. The second connection (1757) is much more suspicious; it is a browser making an outbound connection to a host on TCP/4444, which is known to be the default port for many Metasploit payloads.

A closer inspection of the Firefox process (1757) is clearly warranted. The lsof command shows a collection of libraries loaded into memory, access by Firefox to an SQLite database, and the network connection.
dhilbert@betelgeuse:~$ sudo lsof -p 1757
lsof: WARNING: can't stat() fuse.gvfs-fuse-daemon file system /home/dhilbert/.gvfs
      Output information may be incomplete.
COMMAND  PID     USER  FD   TYPE DEVICE SIZE/OFF    NODE NAME
firefox 1757 dhilbert cwd    DIR    8,1     4096 1058150 /home/dhilbert
firefox 1757 dhilbert rtd    DIR    8,1     4096       2 /
firefox 1757 dhilbert txt    REG    8,1    79304  656653
                                                          /usr/lib/firefox/firefox
firefox 1757 dhilbert mem    REG    8,1   341072 1177869
                         /usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif-Bold.ttf
firefox 1757 dhilbert mem    REG    8,1  1360484  658045 /usr/lib/i386-
                                                        linux-gnu/libxml2.so.2.7.8
firefox 1757 dhilbert mem    REG    8,1   333616 1177892
                         /usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-B.ttf
firefox 1757 dhilbert mem    REG    8,1   423508  656662
                                                    /usr/lib/firefox/libnssckbi.so
... Output Deleted ...
firefox 1757 dhilbert  50u   REG    8,1   131200 1059576
                /home/dhilbert/.mozilla/firefox/gmjvy063.default/places.sqlite-wal
firefox 1757 dhilbert  51w  FIFO    0,8      0t0   13815 pipe
firefox 1757 dhilbert  53ur  REG    8,1   425984 1059580
                    /home/dhilbert/.mozilla/firefox/gmjvy063.default/addons.sqlite
firefox 1757 dhilbert  54uw  REG    8,1   425984 1058855
                /home/dhilbert/.mozilla/firefox/gmjvy063.default/extensions.sqlite
firefox 1757 dhilbert  55u   REG    8,1   262720 1060192 /home/dhilbert/
                       .mozilla/firefox/gmjvy063.default/extensions.sqlite-journal
firefox 1757 dhilbert  57u  IPv4  11954      0t0     TCP
                             betelgeuse.local:59911->10.0.2.249:4444 (ESTABLISHED)
A check of the data in /proc for this process shows nothing unusual. For example, the process was started with the default arguments
dhilbert@betelgeuse:~$ sudo cat -v /proc/1757/cmdline
/usr/lib/firefox/firefox^@
Although the process has 57 open file descriptors, nothing stands out; most of the opened files are in the user’s Firefox configuration directory.
dhilbert@betelgeuse:~$ sudo ls -l /proc/1757/fd
total 0
lr-x------ 1 dhilbert dhilbert 64 Aug  1 09:00 0 -> /dev/null
... Output Deleted ...
lr-x------ 1 dhilbert dhilbert 64 Aug  1 09:00 25 ->
               /home/dhilbert/.mozilla/firefox/gmjvy063.default/permissions.sqlite
lr-x------ 1 dhilbert dhilbert 64 Aug  1 09:00 26 ->
                 /home/dhilbert/.mozilla/firefox/gmjvy063.default/downloads.sqlite
... Output Deleted ...

Because Firefox is a web browser, outbound network connections from it are expected. Had the attacker selected a more appropriate port (e.g., TCP/443) for the payload, then the analysis of the network connections would have shown nothing of interest. The JavaScript payload runs within Firefox, so this attack created no new processes to arouse the suspicion of the defender. This brief analysis of the Firefox process itself shows nothing out of the ordinary. Taken together, this attack is much less detectable than the first example. On the other hand, the stealth comes at a cost, as the attacker is trapped in the Firefox process. Once Firefox is terminated, the attacker loses access to the system.

Windows Tools

As was the case for Linux systems, it is critical that Windows administrators can determine who is logged on to a system.

Determining Users Logged On to the System

One way to determine the users logged on to a system is to use one of the tools from the Sysinternals suite. The Windows Sysinternals Suite is a collection of 70 tools that are invaluable to a Windows system administrator. The tools can be downloaded in a group from https://docs.microsoft.com/en-us/sysinternals/downloads/sysinternals-suite ; they can also be downloaded individually.

PsLoggedon

One useful Sysinternals tool is PsLoggedon, which lists the users currently logged on to a system.
C:UsersFelix Klein>c:SysinternalsSuitepsloggedon.exe /accepteula
PsLoggedon v1.34 - See who's logged on
Copyright (C) 2000-2010 Mark Russinovich
Sysinternals - www.sysinternals.com
Users logged on locally:
     8/2/2014 11:40:26 AM       INTERAMNIAFelix Klein
No one is logged on via resource shares.

Most Sysinternals programs have an end-user license agreement that needs to be accepted before the program will complete; the flag /accepteula accepts the agreement automatically.

Wmic Query to Determine Logged-On Users

The built-in tool wmic can be used to list the currently logged-on users; run the query
C:UsersFelix Klein>wmic computersystem get name, username
Name        UserName
INTERAMNIA  INTERAMNIAFelix Klein

LogonSessions

The Sysinternals tool logonsessions, run as an administrator, lists the logon sessions on the system.
c:SysinternalsSuite>logonsessions.exe /p /accepteula
LogonSessions v1.4 - Lists logon session information
Copyright (C) 2004-2016 Mark Russinovich
Sysinternals - www.sysinternals.com
[0] Logon session 00000000:000003e7:
    User name:    PLUTODRAKE$
    Auth package: Negotiate
    Logon type:   (none)
    Session:      0
    Sid:          S-1-5-18
    Logon time:   3/21/2018 2:21:04 PM
    Logon server:
    DNS Domain:   pluto.test
    UPN:          [email protected]
      496: winlogon.exe
      552: lsass.exe
      612: svchost.exe
      848: svchost.exe
      932: svchost.exe
     1164: VBoxService.exe
     1552: spoolsv.exe
     1748: svchost.exe
     1816: svchost.exe
     3640: SearchIndexer.exe
     4556: SearchProtocolHost.exe
     4628: SearchFilterHost.exe
... Ouptput Deleted ...
[7] Logon session 00000000:00027176:
    User name:    PLUTOgverdi
    Auth package: Kerberos
    Logon type:   Interactive
    Session:      1
    Sid:          S-1-5-21-2712758988-2974005575-3302443488-1118
    Logon time:   3/21/2018 10:22:21 AM
    Logon server: OORT
    DNS Domain:   PLUTO.TEST
    UPN:          [email protected]
     2640: sihost.exe
     2712: svchost.exe
     2812: taskhostw.exe
     2948: explorer.exe
     2976: RuntimeBroker.exe
     3296: ShellExperienceHost.exe
     3464: SearchUI.exe
     3940: backgroundTaskHost.exe
     4048: VBoxTray.exe
     2248: MSASCuiL.exe
     3832: backgroundTaskHost.exe
     4008: backgroundTaskHost.exe
     3304: SkypeHost.exe
     4996: OneDrive.exe
[8] Logon session 00000000:0006477c:
    User name:    PLUTOjbach
    Auth package: Kerberos
    Logon type:   CachedInteractive
    Session:      1
    Sid:          S-1-5-21-2712758988-2974005575-3302443488-1103
    Logon time:   3/21/2018 10:23:50 AM
    Logon server: OORT
    DNS Domain:   PLUTO.TEST
    UPN:          [email protected]
     4612: cmd.exe
     4620: conhost.exe
     5796: logonsessions.exe

Here the /p switch provides information about the process(es) running in each session. This program was run on the Windows 10-1607 system drake on the domain PLUTO; the non-administrator user PLUTOgverdi was logged on to the system. To run logonsessions.exe, that user started an administrator command prompt as the domain administrator PLUTOjbach. The computer account PLUTODRAKE$ is seen to have started the winlogon.exe process as well as some services, including one for VirtualBox. The user PLUTOgverdi is seen to be logged on to the system and is running explorer.exe among other processes. The domain administrator PLUTOjbach has started a command prompt (4612) and run the logonsessions.exe program (5796). Omitted from this output are the result from some service accounts.

Determining the State of the System

Just like on Linux, an administrator of a Windows system can examine the processes running on the system as well as the system’s network connections.

Tasklist

The command tasklist lists the processes running on a Windows system, including their name and PID.
C:UsersAdministrator>tasklist
Image Name                    PID Session Name        Session#    Mem Usage
========================= ======= ================ =========== ============
System Idle Process             0 Services                   0         20 K
System                          4 Services                   0        260 K
smss.exe                      244 Services                   0        948 K
csrss.exe                     340 Services                   0      3,284 K
csrss.exe                     404 Console                    1     10,916 K
wininit.exe                   412 Services                   0      3,412 K
winlogon.exe                  440 Console                    1      5,372 K
services.exe                  504 Services                   0      6,228 K
lsass.exe                     512 Services                   0      7,928 K
svchost.exe                   600 Services                   0      7,180 K
VBoxService.exe               632 Services                   0      4,680 K
svchost.exe                   692 Services                   0      5,052 K
... Output Deleted ...
Processes named svchost.exe are used to run Windows services. The list of running services is available with the /svc flag.
C:UsersAdministrator>tasklist /svc
Image Name                PID Services
==================== ======== ============================================
System Idle Process         0 N/A
System                      4 N/A
smss.exe                  244 N/A
csrss.exe                 340 N/A
csrss.exe                 404 N/A
wininit.exe               412 N/A
winlogon.exe              440 N/A
services.exe              504 N/A
lsass.exe                 512 SamSs
svchost.exe               600 BrokerInfrastructure, DcomLaunch, LSM,
                                 PlugPlay, Power
VBoxService.exe           632 VBoxService
svchost.exe               692 RpcEptMapper, RpcSs
svchost.exe               764 Dhcp, EventLog, lmhosts
dwm.exe                   796 N/A
svchost.exe               840 gpsvc, iphlpsvc, LanmanServer, ProfSvc,
                                 Schedule, SENS, ShellHWDetection, Themes,
                                 Winmgmt
svchost.exe               872 EventSystem, FontCache, netprofm, nsi,
                                 RemoteRegistry, WinHttpAutoProxySvc
svchost.exe               988 CryptSvc, Dnscache, LanmanWorkstation,
                                 NlaSvc, WinRM
svchost.exe               744 BFE, DPS, MpsSvc
spoolsv.exe              1096 Spooler
svchost.exe              1144 TrkWks, UALSVC
... Output Deleted ...

Sc

Attackers have recognized the value of using svchost.exe as a cover for their malware; any process named svchost.exe without corresponding Windows services should be treated as suspicious. The sc command can be used to provide the description of a service.

To find the description of TrkWks from PID 1144 above, run
C:UsersAdministrator>sc qdescription TrkWks
[SC] QueryServiceConfig2 SUCCESS
SERVICE_NAME: TrkWks
DESCRIPTION:  Maintains links between NTFS files within a computer or across computers in a network.
Extended information about the state of a service can be found with
C:UsersAdministrator>sc queryex TrkWks
SERVICE_NAME: TrkWks
        TYPE               : 20  WIN32_SHARE_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0
        PID                : 1144
        FLAGS              :

Task Manager

Windows Task Manager (Figure 3-1) displays the running processes in a graphical tool. It can be started with the keyboard shortcut CTRL+SHIFT+ESC; it is also one of the options available on a running system after pressing CTRL+ALT+DELETE on a logged-in system.
../images/333712_2_En_3_Chapter/333712_2_En_3_Fig1_HTML.jpg
Figure 3-1

A comparison of Task Manager on Windows 7 (left) and Windows 10 (right)

Process Explorer

The Sysinternals tool Process Explorer (procexp.exe) (Figure 3-2) when run as administrator provides a more feature-rich tool to manage running processes. Process Explorer color codes the process name by the process type.
  • Green: New processes

  • Red: Deleted processes

  • Gray-Blue: Processes run by the same user running Process Explorer

  • Pink: Services

  • Gray: Suspended processes

  • Purple: Packed processes, meaning that it is compressed or encrypted. Though some legitimate processes are packed (e.g., IrfanView, a common image viewer), some malware also uses this technique.

  • Yellow: .NET processes, or DLLs that have been rebased in memory

  • Brown: Jobs

  • Teal: Immersive processes; these are only found on Windows 8, Windows Server 2012, and later operating systems.

../images/333712_2_En_3_Chapter/333712_2_En_3_Fig2_HTML.jpg
Figure 3-2

Process Explorer on Windows 8.1

Process Explorer can verify that processes on the system are running with verified signatures; from the Options menu select Verify Image Signatures. An additional column is shown; if the application is signed, then the publisher is listed. Though many legitimate applications are signed, not all are.

Process Explorer can submit the hashes of running processes to VirusTotal for analysis. VirusTotal, available at https://www.virustotal.com/en/ , checks the submission against different antivirus tools. When VirusTotal is used with Process Explorer (navigate Options ➤ VirusTotal.com ➤ Check VirusTotal.com), a new column appears in the display indicating the number of antivirus products that considered the file malicious and the total number of antivirus products checked. Clicking on the hyperlink in that column takes the user to the corresponding web page on VirusTotal.com.

Double-clicking on any process brings up a dialog box with the properties of that process (Figure 3-3).
../images/333712_2_En_3_Chapter/333712_2_En_3_Fig3_HTML.jpg
Figure 3-3

Process Explorer on Windows 8.1 examining a process

One tab provides information about the image, including the file name, its version, its current working directory, and its parent process. The administrator can use the “Bring to Front” button to have the process appear as the top application on the Desktop. The TCP/IP tab lists all active network connections for the process. Other tabs provide information about process execution, performance, disk and network, running threads, and the environment variables for the process. The strings tab lists the text strings that occur either in the image or in memory.

Process Explorer can replace Task Manager; from the Process Explorer main menu, navigate Options ➤ Replace Task Manager.

An open source tool that provides many of the features of Process Explorer is Process Hacker, available at http://processhacker.sourceforge.net .

Process Monitor

The Sysinternals tool Process Monitor (procmon.exe) records input and output for processes, including file access, network access, and registry access. Content data is not recorded, though the process stack is. Process Monitor captures an enormous amount of data on a running system: far too much to be analyzed live. The events recorded by Process Monitor can be saved for later analysis; this subsequent analysis can even be done on a different system.

Netstat

Windows systems have a program named netstat to determine the state of the network connections on the system. Though it is like the Linux tool, the command-line switches are different. To use netstat to show the listening ports, use the /a switch; to have the ports displayed in numeric form, use /n; and to include the PID of the process that opened the port, use /o.
C:UsersFelix Klein>netstat /ano
Active Connections
  Proto  Local Address          Foreign Address        State           PID
  TCP    0.0.0.0:135            0.0.0.0:0              LISTENING       696
  TCP    0.0.0.0:445            0.0.0.0:0              LISTENING       4
  TCP    0.0.0.0:5357           0.0.0.0:0              LISTENING       4
  TCP    0.0.0.0:49152          0.0.0.0:0              LISTENING       380
  TCP    0.0.0.0:49153          0.0.0.0:0              LISTENING       784
... Output Deleted ...
  UDP    [::]:60876             *:*                                    1284
  UDP    [::1]:1900             *:*                                    1284
  UDP    [::1]:56500            *:*                                    1284
  UDP    [fe80::fc48:a613:ee25:557%11]:1900  *:*                       1284
  UDP    [fe80::fc48:a613:ee25:557%11]:56499  *:*                      1284
The name of the process that opened the connection is available with the /b switch, though this requires an Administrator level command prompt. The /f switch displays the name rather than the IP address for destinations. The /p flag filters the results by protocols; for example, to see just TCP listening ports on IPv6, run
C:UsersFelix Klein>netstat /a /p TCPv6
Active Connections
  Proto  Local Address          Foreign Address        State
  TCP    [::]:135               Interamnia:0           LISTENING
  TCP    [::]:445               Interamnia:0           LISTENING
  TCP    [::]:5357              Interamnia:0           LISTENING
  TCP    [::]:49152             Interamnia:0           LISTENING
  TCP    [::]:49153             Interamnia:0           LISTENING
  TCP    [::]:49154             Interamnia:0           LISTENING
  TCP    [::]:49155             Interamnia:0           LISTENING
  TCP    [::]:49156             Interamnia:0           LISTENING

TCPView

The Sysinternals tool TCPView (tcpview.exe) (Figure 3-4) provides a graphical way to view network connections on the system. Each connection is color coded: new in green, recently closed in red, and connections that have recently changed state in yellow.
../images/333712_2_En_3_Chapter/333712_2_En_3_Fig4_HTML.jpg
Figure 3-4

TCPView on Windows 8.1

Right-clicking on an entry in TCPView brings up a context menu that allows the user to determine the properties of the process that started the connection; it also allows the user to run a whois query on the connection’s destination.

Detect: MS13-055 CAnchorElement

Chapter 2 showed how to run the MS13-055 CAnchorElement attack against Internet Explorer 8 on a Windows 7 system running with Java 6 installed. Run the attack, using the Meterpreter payload and reverse HTTPS.

After the (successful) attack, listing the users on the system shows nothing out of the ordinary.
C:UsersHermann Weyl>wmic computersystem get username,name
Name    UserName
DAVIDA  DAVIDAHermann Weyl
Running logonsessions and including information about the processes yields one interesting artifact - the user appears to be running a copy of notepad.exe, yet the application is not seen on the desktop.
C:Windowssystem32>c:SysInternalsSuitelogonsessions.exe /accepteula /p
... Output Deleted ...
[6] Logon session 00000000:0001a1d0:
    User name:    DAVIDAHermann Weyl
    Auth package: NTLM
    Logon type:   Interactive
    Session:      1
    Sid:          S-1-5-21-1951036906-3806809855-451517158-1000
    Logon time:   8/3/2014 1:35:12 PM
    Logon server: DAVIDA
    DNS Domain:
    UPN:
      272: taskhost.exe
      380: dwm.exe
      688: explorer.exe
     1236: VBoxTray.exe
     2676: iexplore.exe
     2724: iexplore.exe
     1592: notepad.exe
     1656: cmd.exe
     2728: conhost.exe
The notepad process also appears in tasklist.
C:Windowssystem32>tasklist
Image Name                   PID Session Name        Session#    Mem Usage
======================= ======== ================ =========== ============
System Idle Process            0 Services                   0         12 K
System                         4 Services                   0        544 K
... Output Deleted ...
explorer.exe                 688 Console                    1     34,512 K
VBoxTray.exe                1236 Console                    1      4,816 K
SearchIndexer.exe            264 Services                   0      9,560 K
wmpnetwk.exe                1936 Services                   0      2,324 K
svchost.exe                 2496 Services                   0     14,012 K
iexplore.exe                2676 Console                    1     20,984 K
iexplore.exe                2724 Console                    1     20,588 K
audiodg.exe                 1660 Services                   0     13,600 K
notepad.exe                 1592 Console                    1     11,344 K
cmd.exe                     1656 Console                    1      2,216 K
conhost.exe                 2728 Console                    1      4,024 K
cmd.exe                     3564 Console                    1      2,336 K
conhost.exe                 3380 Console                    1      4,072 K
tasklist.exe                1868 Console                    1      3,996 K
WmiPrvSE.exe                1860 Services                   0      4,604 K
Process Explorer (Figure 3-5) notes the notepad process; unusually, it is running as a child process for Internet Explorer. Double-click on the notepad.exe process; from the Image tab, use the button to “Bring to Front”; this should bring the window(s) used by that process to the top of the Desktop. This fails, with a message, stating that “No visible windows found for this process.” Together, this is quite suspicious.
../images/333712_2_En_3_Chapter/333712_2_En_3_Fig5_HTML.jpg
Figure 3-5

Process Explorer after a successful MS13-055 attack on Internet Explorer using the Meterpreter payload with reverse HTTPS

On the other hand, the image has a valid signature from Microsoft, and VirusTotal raises no warnings. This combination of behaviors is expected; as noted in Chapter 2, Metasploit injects its code into running processes and spawned the notepad process to ensure its survival if Internet Explorer is closed. Since the original notepad.exe on the disk is unchanged, its signature remains valid, even though it was modified after it began running.

A check of the TCP/IP resources used by the notepad process or either of the two parent Internet Explorer processes does not show any connections; neither does TCPView. Downloading a large file (say 50 MB) from Meterpreter is enough that TCPView notes the connection but then only fleetingly.

If the attacker uses the shell command from within Meterpreter to open a command prompt on the target, other artifacts become available for analysis. A new cmd.exe process spawns, with notepad.exe as the parent. Moreover, the connection between the systems now appears, both in TCPView and in netstat.
C:Windowssystem32>netstat /ano
Active Connections
  Proto  Local Address          Foreign Address        State           PID
  TCP    0.0.0.0:135            0.0.0.0:0              LISTENING       704
  TCP    0.0.0.0:445            0.0.0.0:0              LISTENING       4
  TCP    0.0.0.0:5357           0.0.0.0:0              LISTENING       4
  TCP    0.0.0.0:49152          0.0.0.0:0              LISTENING       384
  TCP    0.0.0.0:49153          0.0.0.0:0              LISTENING       792
  TCP    0.0.0.0:49154          0.0.0.0:0              LISTENING       860
  TCP    0.0.0.0:49155          0.0.0.0:0              LISTENING       472
  TCP    0.0.0.0:49156          0.0.0.0:0              LISTENING       480
  TCP    10.0.2.101:139         0.0.0.0:0              LISTENING       4
  TCP    10.0.2.101:50515       10.0.2.251:443         CLOSE_WAIT      1592
  TCP    [::]:135               [::]:0                 LISTENING       704
... Output Deleted ...

The PID (1592) for the connection back to the attacker (10.0.2.251, TCP/443) is the PID for notepad.exe, not the command prompt.

This network connection remains, even if the attacker backgrounds the shell in Meterpreter, or even backgrounds the entire session.

In this example, the defender did not so much detect the MS 13-055 CAnchorElement attack, but rather detected the activities of the attacker once they were on the system. The notepad.exe process (PID 1592) as a child of an iexplore.exe process (PID 2724) was the first anomaly. If the attacker spawns a shell, then the notepad.exe process makes an outbound network connection, providing a second anomaly. This is one reason why attackers take care to manage what artifacts they leave on the system.

Detect: Adobe Flash Player Shader Buffer Overflow

Suppose an attacker uses the Adobe Flash Player Shader Buffer Overflow attack against the default version of Flash included as the plugin for Internet Explorer 10 in Windows 8. This attack is launched in the same way as other attacks shown in Chapter 2.

After a successful attack, listing the users on the system shows nothing out of the ordinary, and the logonsessions command shows only Internet Explorer and its Flash Player plugin running.
C:Windowssystem32>wmic computersystem get name, username
Name    UserName
EUROPA  EUROPAPierre Laplace
C:Windowssystem32>c:SysinternalsSuitelogonsessions.exe /accepteula /p
...Output Deleted ...
[8] Logon session 00000000:0004c5e9:
    User name:    EUROPAPierre Laplace
    Auth package: NTLM
    Logon type:   Interactive
    Session:      1
    Sid:          S-1-5-21-1376277872-1374384255-2552460128-1001
    Logon time:   8/3/2014 3:10:43 PM
    Logon server: EUROPA
    DNS Domain:
    UPN:
     1952: taskhostex.exe
       72: explorer.exe
     2076: iexplore.exe
     2124: iexplore.exe
     2228: VBoxTray.exe
     2296: FlashUtil_ActiveX.exe
Similarly, tasklist shows only the usual set of applications, including Internet Explorer and the Flash plugin.
C:Windowssystem32>tasklist
Image Name                    PID Session Name        Session#    Mem Usage
======================== ======== ================ =========== ============
System Idle Process             0 Services                   0         20 K
System                          4 Services                   0        660 K
... Output Deleted ...
explorer.exe                   72 Console                    1     51,584 K
iexplore.exe                 2076 Console                    1     22,992 K
iexplore.exe                 2124 Console                    1     60,184 K
VBoxTray.exe                 2228 Console                    1      5,972 K
FlashUtil_ActiveX.exe        2296 Console                    1      6,688 K
audiodg.exe                  2756 Services                   0      8,160 K
cmd.exe                      2928 Console                    1      2,360 K
conhost.exe                  2936 Console                    1      5,924 K
tasklist.exe                 2012 Console                    1      5,160 K
WmiPrvSE.exe                 2424 Services                   0      5,336 K
Process Explorer (Figure 3-6) shows a pair of Internet Explorer processes; the second (2124) is a child of the first (2076). It also shows a new instance of svchost.exe, running the Flash Player Plugin. These applications are running with verified signatures and without being flagged by VirusTotal.
../images/333712_2_En_3_Chapter/333712_2_En_3_Fig6_HTML.jpg
Figure 3-6

Process Explorer after a successful Adobe Flash Player Shader Buffer Overflow Attack on Windows 8 using the Meterpreter payload with reverse HTTPS

The connection to the attacker’s system is difficult to detect. In general, it does not appear in the TCP/IP tab of the processes in Process Explorer; it does not appear in TCPView; and it does not appear in netstat, unless the attacker is making extensive use of the connection between the systems at that moment. Downloading a large file, for example, is sufficient for the connection to briefly appear. The connections are not associated with the Flash plugin, but instead associated with the child Internet Explorer process (PID 2124).

If the attacker leaves Meterpreter and starts a Windows command shell on the target using the Meterpreter shell command, then two new processes are spawned: a conhost.exe whose parent is cmd.exe whose parent is the child Internet Explorer process. Even then, unless the attacker is actively and extensively using the network, the connection does not appear in TCPView.

The original attack did not spawn a second process, making its detection on the target more difficult. On the other hand, if the Internet Explorer process is killed, the attacker loses their connection.

Network Tools

In a physical network, hardware taps and span ports can be used to send copies of network traffic to one or more sensors. For a smaller test network consisting of virtual machines running on the same virtualization solution (VMWare or VirtualBox), then the virtualization tools can be used. On VMWare Workstation with a Windows host, any guest network card in promiscuous mode can see all the traffic on its virtual network. In VirtualBox, a virtual network adapter can be placed in promiscuous mode only if allowed by the network settings for the adapter. To view or update the settings, navigate the VirtualBox main menu for the guest through Devices ➤ Network ➤ Network Settings. Select the adapter, and from the Advanced Menu, configure promiscuous mode (Figure 1-3).

Tcpdump

To capture packets on a Linux host for later analysis, use tcpdump. This tool is installed by default on most Linux distributions, including the distributions described in Chapter 1. To use tcpdump to capture packets to a file, say traffic, run (as root)
arcturus:~ # tcpdump -w traffic
Of course, if this runs sufficiently long, the file becomes quite large. To ensure that the destination file does not grow indefinitely, specify the size of the file (in MB) with the -C option. This does not stop the capture though; subsequent data is stored in the file traffic1, then traffic2, and so on. Now though the individual file sizes remain fixed, the process still attempts to fill the entire disk. The -W option is used to rotate the output through the specified number of rotating files. Consider the command
arcturus:~ # tcpdump -C 100 -W 5 -w traffic

This collects network traffic and stores the results in traffic0 until it collects 100 MB of data; then it stores the results in traffic1 until it fills, on through traffic4. When the last file fills, the original traffic0 is be overwritten with new data, and so on.

Wireshark

Wireshark is an excellent tool used to analyze captured packets. It is possible to use tcpdump to do so, but tcpdump lacks a graphical user interface. It is also possible to use Wireshark directly to capture packets, and this is often reasonable for small captures to help debug a network problem.

Wireshark is not installed by default on most Linux systems. The installation method varies with the distribution:
  • CentOS: yum install wireshark-gnome

  • OpenSuSE: zypper install wireshark

  • Ubuntu/Mint: apt-get install wireshark

A Windows installer is available from the Wireshark page at https://www.wireshark.org/download.html . That page also has links to older versions of Wireshark.

To analyze multiple packet capture files, they must first be merged. The simplest way to do so is to drag and drop the files into Wireshark. Wireshark does have the ability to merge two packet capture files (navigate the main menu through File ➤ Merge), but this only functions on two files at a time, and one must already be saved.

The default Wireshark display (Figure 3-7) breaks into three panes. The top pane provides a column-based list of the received frames/packets; the middle pane summarizes the details of the frame/packet broken down by component; the bottom pane is the raw data from the frame/packet.
../images/333712_2_En_3_Chapter/333712_2_En_3_Fig7_HTML.jpg
Figure 3-7

Wireshark 1.4.6 on OpenSuSE 12.1

The highlighted frame of Figure 3-7, number 11, is an Ethernet frame containing a UDP packet from the Google nameserver at 8.8.8.8 returning with the results of a DNS query.

Packets and frames in the list are color coded by type. Additional columns can be included in the list; one particularly useful column is the absolute time that the packet was received. Right-click on the column headers and select Column Preferences. Select Add; for the Field Type select Absolute Time and give the column a name.

The Statistics entry in the main menu provides an entry point for tools that summarize the properties of the packet capture. For example, Protocol Hierarchy (Figure 3-8) breaks down the packets by type.
../images/333712_2_En_3_Chapter/333712_2_En_3_Fig8_HTML.jpg
Figure 3-8

Protocol Hierarchy Statistics from Wireshark 1.4.6 on OpenSuSE 12.1

Wireshark collects packets into conversations that have the same endpoints. To view the TCP conversations, navigate the main menu through Statistics ➤ Conversation List ➤ TCP (IPv4 & IPv6) (Figure 3-9). The Follow Stream button shows the content of the conversation in a range of formats, including ASCII.
../images/333712_2_En_3_Chapter/333712_2_En_3_Fig9_HTML.jpg
Figure 3-9

TCP Conversations from Wireshark 1.4.6 on OpenSuSE 12.1

This just scratches the surface of what can be done with Wireshark; see the Notes and References section for some excellent resources to learn more.

Detect: Java JAX-WS Remote Code Execution

Chapter 2 demonstrated how to attack a Mint 13 system running Firefox 12.0 and Java 7 Update 5 with the Java Applet JAX-WS Remote Code Execution attack. Set up a Kali offensive system and a Mint 13 target; also set up a Linux system running tcpdump to capture the packets sent between the attacker and the target. Run the attack using the Java Meterpreter payload running through a reverse HTTPS connecting back to the attacker on TCP/443. Use Meterpreter to interact with the victim system to ensure that some interesting network traffic is generated.

Open the resulting packet capture (Figure 3-10) in Wireshark and examine the list of conversations. One set of conversations goes from the victim to the attacker on TCP/8080 (http-alt); this is the request that spawned the attack. Second and far more numerous are conversations starting from the victim going to the attacker on TCP/443 (https); this is how the attacker interacts with the victim.
../images/333712_2_En_3_Chapter/333712_2_En_3_Fig10_HTML.jpg
Figure 3-10

Conversations between attacker and victim of Java Applet JAX-WS Remote Code Execution Attack using Java Meterpreter through reverse HTTPS. Note the relative start times. Screenshot from Wireshark 1.10.14 on CentOS 7.3-1611.

Following the stream for the initial conversation shows that the attacker served a .jar file with an apparently randomly generated name.
GET /bob/ HTTP/1.1
Host: 10.0.2.2:8080
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:12.0) Gecko/20100101 Firefox/12.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
HTTP/1.1 200 OK
Content-Type: text/html
Connection: Keep-Alive
Server: Apache
Content-Length: 119
<html><head></head><body><applet archive="dPBEvO.jar" code="Exploit.class" width="1" height="1"></applet></body></html>
Analysis of the second conversation on TCP/8080 shows the victim receiving what appears to be a Metasploit payload.
GET /bob/dPBEvO.jar HTTP/1.1
accept-encoding: pack200-gzip, gzip
content-type: application/x-java-archive
User-Agent: Mozilla/4.0 (Linux 3.2.0-23-generic) Java/1.7.0_05
Host: 10.0.2.2:8080
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
HTTP/1.1 200 OK
Content-Type: application/octet-stream
Connection: Keep-Alive
Server: Apache
Content-Length: 7886
PK........+LxL................metasploit.dat....C0...w..^.H<0...)..E..........|m.bkB..{.t.Y..*."i.f......@$."5........5.....IF..........S..B.
......`a#R...?^.e.'.N.I*.m..&$....t.2...........E.q.W.&...PK........+LxL................metasploit/PK........+LxLp{-.N...A!......metasploit/Payload.class...x..........`......KNE..x4.
... Output Deleted ...

The conversations on TCP/443 are more difficult to understand. As expected, the content is encrypted, and following the stream provides no useful data.

Though the traffic is encrypted, the TLS handshake shows unusual behavior. Open the TLSv1 Server Hello packet and examine the data for the certificate’s issuer (Figure 3-11).
../images/333712_2_En_3_Chapter/333712_2_En_3_Fig11_HTML.jpg
Figure 3-11

Examining the certificate issuer for the Java JAX-WS Remote Code Execution attack. Screenshot from Wireshark 1.10.14 on CentOS 7.3-1611.

In this example, the common name of the certificate issuer is “ytkrqnwt,” which appears random.

Considering the different HTTPS conversations together as a group, two facts stand out. The victim communicates with the attacker in bursts, each using a different source port. This explains why the connections were so difficult to notice during the host-based analysis. The timing of the connection attempts from the victim to the attacker is also suspicious. Examining the relative start time for the connections, they appear to go out from the victim roughly every 10 seconds (Figure 3-10).

Notes and References

The current runlevel of a Linux system can be found with the command runlevel.

One of the columns in the output from w command is the TTY for each user. There are physical devices, represented by ttyn for some number n; and slave pseudo-terminals, represented by pts/n for some number n. Although a tty was originally meant to refer to a single physical device, on modern Linux systems, the same physical hardware is usually bound to each available tty. Each time a new Bash shell is started, a new slave pseudo-terminal is created.

A user physically at a Linux system can change the tty that they use. If a graphical user interface is started, press CTRL+ALT+F8. Then to change to tty1 press ALT+F1, to change to tty2 press ALT+F2, and so on. For more information, read the manual page for console; the manual pages for tty and pts provide additional information.

On Windows, hit the F7 button at a command prompt to get a history of the commands run in a command prompt.

Microsoft explains that “A logon session is a computing session that begins when a user authentication is successful and ends when the user logs off of the system.” See https://docs.microsoft.com/en-us/windows/desktop/SecAuthN/lsa-logon-sessions for more details.

In the context of Process Explorer, a Windows Job is a collection of processes managed together. Take a look at https://docs.microsoft.com/en-us/windows/desktop/ProcThread/job-objects for details.

Windows servers open many ports for a wide range of services. Fortunately, Microsoft has a guide to the different ports and services available at http://support.microsoft.com/kb/832017 .

Wireshark installation packages contain WinPcap, which is a (required) packet capture library for Windows. Older versions of Wireshark ship with older versions of WinPcap, and some are sufficiently old that they do not run on Windows 8 or later. It is possible to install WinPcap separately from Wireshark using versions that do run on Windows 8. WinPcap is available at http://www.winpcap.org/install/ .

The private keys used to generate the Meterpreter SSL certificate are available on the attacker’s machine. Khr0x40sh shows how to locate the keys and use them to decode the SSL encrypted traffic in Wireshark at http://khr0x40sh.wordpress.com/2013/06/25/exporting-runtime-private-key-for-msfs-meterpreter-reverse-tcp-and-https/ .

For a broad introduction to the Sysinternals tool suite, try the book
  • Troubleshooting with the Windows Sysinternals Tools, 2nd ed., Mark Russinovich and Aaron Margosis. Microsoft Press, October 2016.

There is an excellent tutorial for the Sysinternals suite available online at http://www.howtogeek.com/school/sysinternals-pro .

There are several good books on Wireshark, including
  • Practical Packet Analysis, 3rd ed., Chris Sanders. No Starch Press, March 2017.

  • The Wireshark Field Guide: Analyzing and Troubleshooting Network Traffic, Robert Shimonski. Syngress, May 2013.

  • Instant Wireshark Starter, Abhinav Singh. Packt Publishing, January 2013.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.116.159