Monday, February 17, 2014

MD5 and other useful stuff in powershell

Lots of posts coming up shortly, anyway recently I was reading about how OTA updates for CyanogenMod run over plaintext HTTP and don't sign their binaries. Lame. The MD5sum it, and send that over the same plaintext channel, so trivially mitm'able, like evilgrade.

Shortly after reading this, I downloaded an update for CCleaner, which came plaintext from filehippo and decided that I should check its hash. The hash offered is MD5, which while it has collisions, my current understanding is that it takes about a day with a bunch of PS3s in a cluster to make an known good hash collide with a malicious binary. Anyway, with nothing else offered as a reasonable hash for this file, I set out to compare the known hash with the binary's hash.


Previously I've used the Microsoft File Checksum Integrity Verifier utility, but I'd rather have it more smoothly integrated into PowerShell since I'm learning that currently.


I want to find a good powershell way of doing this and here was my thought process:


PS> Get-Command -Name *md5*
--no results

PS> Get-Help *md5*
--nothing

PS> Get-Help *hash*
--nothing useful

Ok, on to the googles.
First hit for "powershell md5": http://stackoverflow.com/questions/10521061/how-to-get-a-md5-checksum-in-powershell

Bingo. A few different methods, and I tried two of them:

Method 1:
$someFilePath = "C:\foo.txt"
$md5 = new-object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
$hash = [System.BitConverter]::ToString($md5.ComputeHash([System.IO.File]::ReadAllBytes($someFilePath)))
This initially gave me an error because I used a relative path for my file (I was currently in my Downloads directory, and did ".\foo.exe" instead of the full path starting with "C:\". After fixing this, it returned a match to the hash provided by filehippo (which of course is also provided via plaintext, so...shit). 
Method 2: 
Install the Powershell Community Extensions (http://pscx.codeplex.com/), which also feature useful commands such as base64 encoding and decoding, gzip/bzip/tar/zip archive support, set/get-clipboard, tail, and get-httpresource, a nice package.
I was all set to dig into my profile and set that up, but it comes prepackages in an MSI that is pretty much a single-click install. 
Both worked.
Looked into it and I couldn't get an HTTPS connection to download the file without cert errors. Found this forum post which mentions that filehippo publishes the MD5sum, that the files are Verisign signed (good deal) and that piriform (the authors of CCleaner) and filehippo are the preferred download methods: http://forum.piriform.com/?showtopic=23834


Checking the signature:
GUI method: 
Find executable in Windows Explorer (not Internet Explorer) > right click > Properties > Select the Digital Signatures Tab > Select the only option there (Should say Piriform Ltd, which is something of a check) > Details 

At this point you see the message "This digital signature is OK" which is a level of assurance. If you wanted to, you could check out its certificate against...I'm not quite sure, but would look for a list of published code signing certificates to see if MSFT has them. Additionally, its countersigned by Symantec for a specific timestamp, which is nice, and Symantec is pretty legit, again, presumably this can be looked up, but I'm assuming that it's in the Windows Certificate Store, and can look that up to prove it as well.

Or using powershell:

PS> Get-AuthenticodeSignature .\ccsetup410.exe
SignerCertificate                        Status  Path
-----------------                        ------  ----
46EE5C92C7BCD7B2D2E937DCD1FB9FDA30D1E753 Valid   ccsetup410.exe

Wednesday, December 18, 2013

Open vSwitch

Just reading this post: http://openvswitch.org/slides/OpenStack-131107.pdf and slide 13 caught my eye.
(edit: figured out how to link directly to a page in a pdf, should work in chrome and adobe reader: http://openvswitch.org/slides/OpenStack-131107.pdf#page=13)

I'm interested if this kernel caching could be hijacked at all from a security standpoint to send further packets that appear to be part of that netflow to bypass userland Open vSwitch logic checks by continuing to ride as if they were part of the cached entry.

Should look into the logic that decides if the flow is the same as the previous. I don't expect that it could be used to route packets improperly, but should be fun to dig in to and is a good reason to learn more about Open vSwitch. Will update this at that point.

Made it to page 17: http://openvswitch.org/slides/OpenStack-131107.pdf#page=17 this as a bit more info on how the user-logic vs cached logic is applied:
"Header fields are hashed and used as an index into a set of large hash tables"
"if entry found, actions applied to packet and counters are updated."
If not: packet is sent to userspace for processing

This seems like a smart way of doing things, still need to dig into even nittier gritty.

Thursday, November 28, 2013

BacNET - I watched a ShmooCon video and here are my notes

Brad Bowers [BradBowers@digitalintercept.com]

  • Also has a good youtube channel for Arduino and Zigbee security stuff: https://www.youtube.com/user/warezjoe5


BacNET Attack Framework

  • About BacNET networks and how to attack them
  • ShmooCon Video: http://www.youtube.com/watch?v=c4LMrKEO_t0
  • Code should be hosted here, but isn't: http://www.digitalintercept.com/bacnet
    • quips about someone helping him set up a github in ihs talk (what issues could he be having?)
    • also couldn't find code on google or github
    • sent him and email to: BradBowers@digitalintercept.com asking about if the code is public, but the email bounced, but I'll find an email.

BacNET

  • All over UDP (47808)
  • No MAC address for BacNET, just IP + port
    • so holy crap spoofable (in addition to it being UDP)
  • no authentication
  • universal moreso than many proprietary SCADA devices which run behind BacNET devices
  • Used in building temperature networks, elevators, SCADA systems, HVAC, others

What's the attack surface? - He found at least 62 internet exposed devices
-this number is growing
-Let's adapt his stuff for ZMAP or another one of the "whole internet scanning" tools.
-Maybe search the Internet Census 2012 if that port was scanned (unlikely - wasn't it just the top X ports?)

BacNET Attack Framework:

  • all in python
  • lots of scapy involved
  • BacNET_arpsweep.py
    • id all devices on a network (not just BacNET)
  • BacNET_scanner.py
    • id listeners listening on UDP/47808
    • this is the BacNET port
  • BacNET_Sniff.py - will only pull in BacNET IP packets
    • throws it in scapy which lets you pick it apart
    • lots of different settings possible with that
  • BacNET_Search.py - id BacNET based on a popular search engine
  • BacNET_IAMRouter.py
    • sends BVLL packet - send me everything you have current primary BacNET gateway device
    • can act as same router
    • can act as different router
  • BacNET_Confirmed_alarm.py
    • highpriority packet
    • ignores all other traffic and does whatever this packet wants
    • sometimes causes device to crap out
  • BacNET_Spoof.py
    • allows a form of fuzzing
    • lots of stuff falls over or has unintended consequences
  • BacNET_Flood.py
    • DoS a unique device (gateway, or sensor)
    • (My addition) Attack scenario: "This temperature sensor is gone, I'm that device, you only see my traffic because I'm flooding you with my data" It's 'cool'
  • BacNET devices can be CRUSHED by the packet production capabilities of a normal laptop, gotta scale it down sometimes or accidental DoS.