kasza smashing the_jars

87
Sm shing the J rs Anthony Kasza Sr. Threat Researcher Palo Alto Networks

Upload: pacsecjp

Post on 16-Apr-2017

155 views

Category:

Internet


0 download

TRANSCRIPT

Page 1: Kasza smashing the_jars

Sm shing the J rs

Anthony Kasza

Sr. Threat Researcher

Palo Alto Networks

Page 2: Kasza smashing the_jars
Page 3: Kasza smashing the_jars

About Me

@AnthonyKasza

Enterprise securityMalware communicationsDNS transaction classifiersThreat techniques

CTF challenge author:- PAN LabyREnth- FIRST DRG

Page 4: Kasza smashing the_jars

Presentation Overview

• Introduction• Intro to java, jars, and

java based threats

• Java Threats• Current threat landscape

• Defensive Techniques• Analysis and detection

techniques

• Demo• Unpacking, deobfuscating, reading

Page 5: Kasza smashing the_jars

Java Basics

• Rich ecosystem• JVM vs JDK vs JRE• Often used to teach OOP• Compiles to bytecode• Similar to Python• Simple to disassemble

• Architecture agnostic• Cross platform JDK

JRE

Dev  toolsJRE  lib  source

JVM

Libraries

Page 6: Kasza smashing the_jars

Reverse Engineering Spectrum of Tribulations

Simple

Remote Service(Blind)

Source Code Delphi

Java

.NET

C++C

Difficult

Page 7: Kasza smashing the_jars

JAR (Java ARchive) Basics

• JAR vs Zip format • Contents are

called resources

• Class files• Header 0xCAFEBABE• Constant pools

• Manifest• META-INF/MANIFEST.MF• Key: Values

• Similar to HTTP headers

JAR

manifest

a.class b.class

c.class d.class

a.jpg b.ico a.png

Page 8: Kasza smashing the_jars

Java RAT Basics• Various levels of maturity • E.g. BlueBanana vs Adzok vs jSocket

• Most are kits/builders• stub Jars

• Many use common libraries

• VirusTotal detections are often inaccurate• jRat != Jacksbot (aka jRat)• IMO too many RATs are detected as jRat

• Frutas != Adwind != Jsocket != etc.• Or does it?

• IMO too many RATs are detected as Adwind

Page 9: Kasza smashing the_jars

Other Java Threats• Banload and other droppers / downloaders• Java Ransomware • PoC on Github [37]• From what I can tell, written by two high school

students• Not distributed ITW

• jbd – bind shell in java• https://scoperchiatore.wordpress.com/java-

backdoor/

• Javafog – APT Java backdoor

Page 10: Kasza smashing the_jars

A Brief Tangent: Javafog

• Identified by Kaspersky• Malicious Jar which beaconed to

same domain as Icefog samples

• Windows specific• Targeted? • But then why Java?

Page 11: Kasza smashing the_jars

A Brief Tangent: Javafog

Not cross platform

Icefog domain name

Page 12: Kasza smashing the_jars

Common Libraries• java.util.prefs – persistence mechanism• Windows: registry• Linux: hidden files in user’s home/ dir• OSX: ~/Library/Preferences/

• Commonly (mis)used libraries• Sigar• Bridj• Slf4j• JNA / JNI [35]• jnativehook• Kryonet• webcam-capture [36]

• Runtime.getRuntime().exec()• E.g. Javafog

Page 13: Kasza smashing the_jars

Adversary Types

• Opportunistic actors• Forum skiddies and phishing/spam

• Financially motivated actors• Banking users in Brazil (banload) [40]• Bank systems in Singapore (adwind) [11]

• Actors targeting something specific• PackRat – CitizenLab, Dec 2015 (Adzok, AlienSpy)

• Latin American [13]• JavaFog – Kaspersky, Jan 2014• Manul campaign – EFF, 2016 (jRat) [34]

Page 14: Kasza smashing the_jars

Someone name something that comes

in a jar

Page 15: Kasza smashing the_jars

Things That Come in Jars

Page 16: Kasza smashing the_jars

Things That Come in JarsFrutasAdwindUnrecomAlienSpyjSocketjBifrostAdzokBlueBananaCrimsonjCagejFectjRATjSpyOS  CelestialQuaverseQuarallaxOmniRATRatty

Feb  2012

Jan  2013

Nov  2013

Oct 2014

July  2015

Sept  20122010  ?

Oct  2012

July  2013

Nov  2015

Oct  2012

Dec  2013

May  2015

Jun  2015

Nov  2015

Jun  2016

May 2016

Feb  2016

Page 17: Kasza smashing the_jars

Things That Come in JarsFrutasAdwindUnrecomAlienSpyjSocketjBifrostAdzokBlueBananaCrimsonjCagejFectjRATjSpyOS  CelestialQuaverseQuarallaxOmniRATRatty

Feb  2012

Jan  2013

Nov  2013

Oct 2014

July  2015

Sept  20122010  ?

Oct  2012

July  2013

Nov  2015

Oct  2012

Dec  2013

May  2015

Jun  2015

Nov  2015

Jun  2016

May 2016

Feb  2016

Page 18: Kasza smashing the_jars

Things That Come in JarsFrutasAdwindUnrecomAlienSpyjSocketjBifrostAdzokBlueBananaCrimsonjCagejFectjRATjSpyOS  CelestialQuaverseQuarallaxOmniRATRatty

Feb  2012

Jan  2013

Nov  2013

Oct 2014

July  2015

Sept  20122010  ?

Oct  2012

July  2013

Nov  2015

Oct  2012

Dec  2013

May  2015

Jun  2015

Feb  2016

Nov  2015

Jun  2016

May 2016

Page 19: Kasza smashing the_jars
Page 20: Kasza smashing the_jars

Frutas Lineage: Frutas

• Frutas PoC emerged early 2012 [2]• Includes a simple ASCII readable ‘config.txt’ or

‘config.xml’ file• Writes ‘frautas.lock’ file to temporary directory to

avoid concurrent executions• Became popular among Spanish speaking

criminals circa July 2012 [1]

Page 21: Kasza smashing the_jars

Frutas Lineage: Frutas

Frutas configuration files

Page 22: Kasza smashing the_jars

Frutas Lineage: Frutas

Frutas lock file

Page 23: Kasza smashing the_jars

Frutas Lineage: Frutas

Frutas Windows specific commands

Page 24: Kasza smashing the_jars

Frutas Lineage: Adwind

• Emerged early 2013 from a rebranded Frutas [3]• Subsequent variants began using obfuscation [4]• Same named resources (capital vs lower case)

• Support for Android (APK binder) introduced• Modular plugins

Page 25: Kasza smashing the_jars

Frutas Lineage: Adwind

Adwind obfuscated manifest entries

Page 26: Kasza smashing the_jars

Frutas Lineage: Adwind

Adwind obfuscated resource names

Page 27: Kasza smashing the_jars

Frutas Lineage: Unrecom

• Rebranded Adwind around late 2013 [5] [6]• UNiversal REmote COntrol Multi-platform• Adwind “acquired” by LustroSoft• Introduced LiteCoin mining plugin [7]

Page 28: Kasza smashing the_jars

Frutas Lineage: Unrecom

Unrecom server class resource name

Page 29: Kasza smashing the_jars

Frutas Lineage: AlienSpy

• Emerged Oct 2014• Improvements [3]• Sandbox detection• TLS for C2• Anti Analysis [8]• Allatori Obfuscation

Page 30: Kasza smashing the_jars

Frutas Lineage: AlienSpy

AlienSpy long resource name

Page 31: Kasza smashing the_jars

Frutas Lineage: AlienSpy

AlienSpy Allatori usage

Page 32: Kasza smashing the_jars

Frutas Lineage: AlienSpy

AlienSpy anti-analysis technique

Page 33: Kasza smashing the_jars

Frutas Lineage: jSocket• AlienSpy domain taken down after

Fidelis report (April 2015)• jSocket emerged July 2015 [10]• Similar to AlienSpy but used

subscription model (SaaS) • Kaspersky estimates Jsocket (Adwind) author

[11]:• made $200,000 per year• sold to 1,800 customers

Page 34: Kasza smashing the_jars

Frutas Lineage: jSocket

jSocket OSX obscure filenames and paths

Page 35: Kasza smashing the_jars

Frutas Lineage: jSocket

jSocket OSX plist entry

Page 36: Kasza smashing the_jars

Frutas Lineage: jBifrost

• Minor feature improvements from jSocket [38]• Controller can tell if user is typing

• Serialized decryption keys in implants

Page 37: Kasza smashing the_jars

Frutas Lineage: jBifrost

jBifrost vs jSocket controller UI Images taken from Fortinet blog [38]

Page 38: Kasza smashing the_jars

Adzok (aka Adsocks)• Emerged 2010ish

(0.7.0 was around in January of 2011) [12]

• Free version used by PackRat group [13]• Open Source [14], Free, and Pro Versions• Still active:• Sold online from Boliva [15]• Twitter profile’s latest tweet was July 2015) [16]

• Similarities to Frutas• Creates lock file• Free version is Windows only• Similar XML configuration file elements

Page 39: Kasza smashing the_jars

Adzok (aka Adsocks)

Adzok Free only runs on Windows

Page 40: Kasza smashing the_jars

Adzok (aka Adsocks)

Adzok Free configuration file

Page 41: Kasza smashing the_jars

Adzok (aka Adsocks)

Adzok lock file

Page 42: Kasza smashing the_jars

Adzok (aka Adsocks)

Adzok homepage

Page 43: Kasza smashing the_jars

BlueBanana• Emerged September 2012• Obfuscated• Encoded strings• Class file names

• Beacons with a configured password in its first data packet• No longer developed

Page 44: Kasza smashing the_jars

BlueBanana

BlueBanana password beaconing on OSX

Page 45: Kasza smashing the_jars

BlueBanana

BlueBanana greetz

Page 46: Kasza smashing the_jars

Crimson• Oldest forum post I could find was dated Oct 2012

[17]• The builder’s “about” section claims December 2013

• Encrypted communications• AES• Blowfish• DES• Triple DES

• Drops settings files into one of:• sqlite database ‘Psettings.db’ – v1.2.3• base64 encoded ‘settings.properties’ – v1.3.0• No file dropped – v2.1.0

Page 47: Kasza smashing the_jars

Crimson

Crimson dropping a sqlite db on OSX

Page 48: Kasza smashing the_jars

Crimson

Crimson debugging out on Windows

Page 49: Kasza smashing the_jars

Crimson

Crimson debugging out on OSX

Page 50: Kasza smashing the_jars

jCage

• Emerged July 2013• Makes use of jnativehook lib• Seems to be focused on Windows systems • I could not find a sample which executed on OSX

Page 51: Kasza smashing the_jars

jCage

jCage searching for AV products on Windows

Page 52: Kasza smashing the_jars

jCage

jCage Windows specific shutdown command

Page 53: Kasza smashing the_jars

qRat (Qarallax/Quaverse)• Emerged May 2015• Three stage JAR loader [20]• SaaS model (similar to jSocket)

• Used a hardcoded IPv4 and domains

• Only runs on windows

• A second version in the wild [32] recently• Downloads auxiliary Jars from qarallax[.]com• Runs on Macs too!• Used to compromise US Visa applicants in Switzerland

over Skype [33] – 6 June 2016

Page 54: Kasza smashing the_jars

qRat (Qarallax/Quaverse)

qRat v1 not running on OSX

Page 55: Kasza smashing the_jars

qRat (Qarallax/Quaverse)

qRat v2 randomly named and hidden Jar on OSX

Page 56: Kasza smashing the_jars

jRat (aka Jacksbot)• Emerge Oct 2012• Portions are open sourced by redpoins0n• Plugins, scripts, uninstaller, and auxiliary tools• https://github.com/java-rat

• Again, not everything is jRat• Persists using [19]• OSX: a LaunchAgent plist• Linux: ~/.config/autostart• Windows: Registry run key

Page 57: Kasza smashing the_jars

jRat (aka Jacksbot)

jRat plist file for persistence on OSX

Page 58: Kasza smashing the_jars

jFect

• Emerged Nov 2015• Heavily obfuscated• IRC or HTTP communications• LaunchAgent plist for persistence on OSX• Just like every other Java RAT

Page 59: Kasza smashing the_jars

jFect

jFect C2 over IRC on Windows

Page 60: Kasza smashing the_jars

jFect

jFect C2 over HTTP on OSX

Page 61: Kasza smashing the_jars

jFect

jFect plist file for persistence on OSX

Page 62: Kasza smashing the_jars

OmniRAT

• Emerged Nov 2015• Multi OS implant and panel support• Android control panel

• Hardcoded C2 (doesn’t use a configuration file)• Android version can spread via SMS [21]

Page 63: Kasza smashing the_jars

OmniRAT

OmniRAT hardcoded C2 IPv4 address

Page 64: Kasza smashing the_jars

OmniRAT

OmniRAT C2 beacon using Java serialization

Page 65: Kasza smashing the_jars

jSpy and OS Celestial• jSpy emerged Dec 2013, OS Celestial is likely a

second version• Open source library reuse• Similar features• Similar configuration file options• Similar configuration parsing classes• Overlap in domain builders beacon to

• jstealth.co[.]uk• jstealth[.]net

• Detectable by files it drops on Windows• Uses LaunchAgent plists for persistence on OSX

Page 66: Kasza smashing the_jars

jSpy and OS Celestial

jSpy homepage

Page 67: Kasza smashing the_jars

jSpy and OS Celestial

jSpy plist file for persistence on OSX

Page 68: Kasza smashing the_jars

Ratty

• Was actively being developed on Github [22]• Seems Windows is further developed than OSX

(further than Linux)

• Used a simple xor over its configuration file• Palo Alto Networks saw this RAT being

distributed in the wild around April 5 of this year • Disappeared from Github a few months ago

Page 69: Kasza smashing the_jars

Ratty

Ratty limited Linux support

Page 70: Kasza smashing the_jars

Ratty

Ratty distribution session data from April 2016

Page 71: Kasza smashing the_jars
Page 72: Kasza smashing the_jars

Common Java RAT Behaviors• Obfuscators, protectors, cryptors• Anti-vm and anti-analysis tricks

• Very long and random(ish) resource names

• Many AV’s cannot determine which family

• Hide Jar implant• Hidden directories or temp folders

• Persistence • Registry, startup folder, plists (KnockKnock)

• Beacon• Variable between families

Page 73: Kasza smashing the_jars

Packers, Obfuscators, Bundlers• Allatori• Zelix Klassmaster (aka Zelix aka ZKM)

• launch4j (jar to exe)• Jar Bundler (removed in OS X Mountain Lion 10.8.2)• JarToApp

• https://github.com/redpois0n/JarToApp

• jCrypt• jarProtector• jFuzzle

Page 74: Kasza smashing the_jars

JWScan and Jardiff

Page 75: Kasza smashing the_jars

Jar Deobfuscation

• Deofuscation logic is in the JAR somewhere

• Decompile class files• Search for methods wrapping strings passed to

other methods• If those methods do math manipulations on a

string, re-implement in Python

• Eclipse conditional breakpoints [23] [24] [25]• Demo to follow

Page 76: Kasza smashing the_jars

javadeobfuscator

• Automated deobfuscation for common techniques and tool [39]• Demo to follow

Page 77: Kasza smashing the_jars

Analysis Hints

OSX• OSX persistence

mechanisms [29]• Plists• Hidden files and

directories

• Dtrace and JVM hotspots• KnockKnock [31]

Windows

• Registry keys

• LNKs in Startup Folder

• Procmon

• Regshot

Page 78: Kasza smashing the_jars

Bytecode Visualizer

Page 79: Kasza smashing the_jars

Bytecode-viewer

Page 80: Kasza smashing the_jars

RATDecoders

• Github repository by kevthehermit [27]• Contains static configuration decoding scripts for

many RATs• Not just Java based ones

• Fantastic resource for building a static Intel pipeline• Combine with VirusTotal, Laikaboss [28], etc• A handful of vendors are doing this internally

Page 81: Kasza smashing the_jars

Pitfalls and Oversights

• Yara rules based on resource names work except when they don’t• Jarinjarloader is tricky • set as the main-class in a jar’s manifest• It then loads a different class

(from a URL or from itself)

• Manifest files are not required forJars to execute

Page 82: Kasza smashing the_jars

Key Take Away Items

Java RATs emerged ~2010Still not extremely popular

Their use is growing

Used by spectrum of actorsLook at the tools I mentioned, they work well

Reach out if you’re interested in collaborating or have questions

Page 83: Kasza smashing the_jars

Special Thanks

83 |    ©  2015, Palo  Alto  Networks.  

DerbyCon Organizers DerbyCon Audience

Tyler HalfpopJacob Soo

Anthony MendezKevin BreenChris Pierce

Jørgen Bøhnsdalen

Page 84: Kasza smashing the_jars

Questions?

Page 85: Kasza smashing the_jars

Demo

Page 86: Kasza smashing the_jars

References (1)[1] https://cdn.securelist.com/files/2016/02/Adwind_timeline_horizontal_final.png[2] http://www.symantec.com/connect/blogs/cross-platform-frutas-rat-builder-and-back-door[3] https://isc.sans.edu/forums/diary/Adwind+another+payload+for+botnetbased+malspam/20041/[4] https://kc.mcafee.com/resources/sites/MCAFEE/content/live/PRODUCT_DOCUMENTATION/26000/PD26278/en_US/McAfee_Labs_Threat_Advisory_Adwind.pdf[5] http://www.crowdstrike.com/blog/adwind-rat-rebranding/[6] http://blog.checkpoint.com/2016/02/24/adwind-malware-as-a-service-reincarnation/[7] http://blog.trendmicro.com/trendlabs-security-intelligence/old-java-rat-updates-includes-litecoin-plugin/[8] https://www.fidelissecurity.com/sites/default/files/FTA_1015_Alienspy_FINAL.pdf[9] https://theintercept.com/2015/08/21/inside-the-spyware-campaign-against-argentine-troublemakers-including-alberto-nisman/[10] https://www.fidelissecurity.com/sites/default/files/FTA_1019_Ratcheting_Down_on_JSocket_A_PC_and_Android_Threat_FINAL.pdf[11] https://blog.kaspersky.com/adwind-rat/11252/[12] http://cleanbytes.net/java-trojan-horses-the-new-trojan-viruses-generation[13] https://citizenlab.org/2015/12/packrat-report/[14] https://sourceforge.net/projects/adsocks/[15] http://adzok.com/[16] https://twitter.com/Adzok_[17] https://leakforums.net/thread-314078[18] http://www.javaworld.com/article/2077233/core-java/bytecode-basics.html[19] https://github.com/redpois0n/jrat-remover/tree/master/src/se/jrat/remover/removers[20] https://www.trustwave.com/Resources/SpiderLabs-Blog/Quaverse-RAT--Remote-Access-as-a-Service/

Page 87: Kasza smashing the_jars

References (2)[21] https://blog.avast.com/2015/11/05/droidjack-isnt-the-only-spying-software-out-there-avast-discovers-that-omnirat-is-currently-being-used-and-spread-by-criminals-to-gain-full-remote-co[22] https://github.com/Sogomn/Ratty[23] https://github.com/deresz/unpacking/blob/master/README.md[24] https://vimeo.com/165124535[25] https://wiki.eclipse.org/FAQ_How_do_I_set_a_conditional_breakpoint%3F[26] http://www.crowdstrike.com/blog/native-java-bytecode-debugging-without-source-code/[27] https://github.com/kevthehermit/RATDecoders[28] https://github.com/lmco/laikaboss[29] https://www.virusbulletin.com/uploads/pdf/conference/vb2014/VB2014-Wardle.pdf[30] https://securelist.com/blog/incidents/58209/the-icefog-apt-hits-us-targets-with-java-backdoor/[31] https://github.com/synack/knockknock[32] http://presumptuouscommoner.blogspot.com/2016/04/post-19-or-anyone-want-jar-of-docx.html[33] https://labsblog.f-secure.com/2016/06/07/qarallax-rat-spying-on-us-visa-applicants/[34] https://www.eff.org/files/2016/08/03/i-got-a-letter-from-the-government.pdf[35] http://blog.cobaltstrike.com/2013/08/29/how-to-inject-shellcode-from-java/[36] https://github.com/sarxos/webcam-capture[37] https://github.com/codertimo/Ransomware[38] https://blog.fortinet.com/2016/08/16/jbifrost-yet-another-incarnation-of-the-adwind-rat[39] https://github.com/java-deobfuscator/deobfuscator[40] http://researchcenter.paloaltonetworks.com/2016/03/banload-malware-affecting-brazil-exhibits-unusually-complex-infection-process/